### Project Setup and Dependencies Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/poisson/CMakeLists.txt Initializes the CMake project, sets the project name, and finds the required DOLFINx package. Ensure DOLFINx is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.21) set(PROJECT_NAME demo_poisson) project(${PROJECT_NAME} LANGUAGES C CXX) if(NOT TARGET dolfinx) find_package(DOLFINX REQUIRED) endif() ``` -------------------------------- ### Project Setup and Dependency Finding Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/poisson_matrix_free/CMakeLists.txt Initializes the CMake project and finds the required DOLFINX package. Ensure DOLFINX is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.21) set(PROJECT_NAME demo_poisson_matrix_free) project(${PROJECT_NAME} LANGUAGES C CXX) if(NOT TARGET dolfinx) find_package(DOLFINX REQUIRED) endif() ``` -------------------------------- ### Install DOLFINx with Spack Source: https://github.com/fenics/dolfinx/blob/main/README.md Install DOLFINx using Spack, a package manager recommended for HPC systems. This example sets up a Spack environment and installs DOLFINx with PETSc and SLEPc support. ```shell git clone https://github.com/spack/spack.git . ./spack/share/spack/setup-env.sh spack env create fenicsx-env spack env activate fenicsx-env spack install --add py-fenics-dolfinx+petsc4py+slepc4py ``` -------------------------------- ### Set Target Properties and Install Source: https://github.com/fenics/dolfinx/blob/main/python/CMakeLists.txt Configures the 'cpp' target to use the installation's RPATH and installs the target to the 'dolfinx' destination. ```cmake set_target_properties(cpp PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) install(TARGETS cpp DESTINATION dolfinx) ``` -------------------------------- ### Project Setup and DOLFINx Dependency Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/custom_kernel/CMakeLists.txt Configures the CMake project, sets the project name, and finds the DOLFINx package. Ensure DOLFINx is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.21) set(PROJECT_NAME demo_custom_kernel) project(${PROJECT_NAME} LANGUAGES C CXX) if(NOT TARGET dolfinx) find_package(DOLFINX REQUIRED) endif() ``` -------------------------------- ### Configuring and Installing pkg-config File Source: https://github.com/fenics/dolfinx/blob/main/cpp/dolfinx/CMakeLists.txt Configures the dolfinx.pc.in template to generate the dolfinx.pc file and installs it to the pkgconfig directory. ```cmake # Configure and install pkg-config file configure_file( ${DOLFINX_SOURCE_DIR}/cmake/templates/dolfinx.pc.in ${CMAKE_BINARY_DIR}/dolfinx.pc @ONLY ) install( FILES ${CMAKE_BINARY_DIR}/dolfinx.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT Development ) ``` -------------------------------- ### Install DOLFINx Python Interface Source: https://github.com/fenics/dolfinx/blob/main/python/doc/source/installation.rst Install the Python interface after the C++ library is installed. This involves checking build dependencies and then installing the package. ```bash python -m scikit_build_core.build requires | python -c "import sys, json; print(' '.join(json.load(sys.stdin)))" | xargs pip install pip install --check-build-dependencies --no-build-isolation . ``` -------------------------------- ### Install DOLFINx with Docs Dependency Source: https://github.com/fenics/dolfinx/blob/main/python/doc/README.md Install DOLFINx Python interface with the 'docs' optional dependency. This is a prerequisite for building the documentation. ```bash python -m pip install .[docs] ``` -------------------------------- ### Install DOLFINx with Debian Source: https://github.com/fenics/dolfinx/blob/main/README.md Installs DOLFINx using apt-get on Debian systems where it is available as a package. ```shell apt-get install fenicsx ``` -------------------------------- ### Project Configuration and DOLFINx Setup Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/codim_0_assembly/CMakeLists.txt Sets the minimum CMake version, project name, and languages. It finds the DOLFINx package, which is required for the project. ```cmake cmake_minimum_required(VERSION 3.21) set(PROJECT_NAME demo_codim_0_assembly) project(${PROJECT_NAME} LANGUAGES C CXX) if(NOT TARGET dolfinx) find_package(DOLFINX REQUIRED) endif() ``` -------------------------------- ### Install Python Interface with scikit-build-core Source: https://github.com/fenics/dolfinx/blob/main/README.md Install the Python interface for DOLFINx after building the C++ core. This involves installing dependencies and then the package itself. ```shell pip install scikit-build-core python -m scikit_build_core.build requires | python -c "import sys, json; print(' '.join(json.load(sys.stdin)))" | xargs pip install pip install --check-build-dependencies --no-build-isolation . ``` -------------------------------- ### Basic CMake Setup for DOLFINx Demos Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/CMakeLists.txt This snippet sets the minimum required CMake version and defines the project name for the DOLFINx demos. ```cmake cmake_minimum_required(VERSION 3.16) project(dolfinx-demos) ``` -------------------------------- ### Install Python Interface Build Requirements Source: https://github.com/fenics/dolfinx/blob/main/python/README.md Installs necessary build requirements for the DOLFINx Python interface. Ensure the C++ library is built and installed first. ```bash pip install scikit-build-core python -m scikit_build_core.build requires | python -c "import sys, json; print(' '.join(json.load(sys.stdin)))" | xargs pip install ``` -------------------------------- ### Build C++ Core with CMake Source: https://github.com/fenics/dolfinx/blob/main/README.md Build and install the C++ core of DOLFINx using CMake. Ensure you are in the `cpp/` directory before running these commands. ```shell mkdir build cd build cmake .. make install ``` -------------------------------- ### Set Installation Prefix for C++ Library Source: https://github.com/fenics/dolfinx/blob/main/python/doc/source/installation.rst Specify a custom installation prefix when building the C++ library with CMake. ```bash cmake -DCMAKE_INSTALL_PREFIX= ../ make install ``` -------------------------------- ### Build and Install DOLFINx Python Interface Source: https://github.com/fenics/dolfinx/blob/main/python/README.md Builds and installs the DOLFINx Python interface using pip. It checks for build dependencies and avoids build isolation. ```bash pip install --check-build-dependencies --no-build-isolation . ``` -------------------------------- ### Run DOLFINx Development Environment Docker Image Source: https://github.com/fenics/dolfinx/blob/main/README.md Starts a Docker container with all dependencies required to build the latest stable release of FEniCSx components. ```shell docker run -ti dolfinx/dev-env:stable ``` -------------------------------- ### Install DOLFINx with Ubuntu PPA Source: https://github.com/fenics/dolfinx/blob/main/README.md Installs FEniCSx packages from the Ubuntu PPA. This method is suitable for users on recent LTS Ubuntu versions. ```shell add-apt-repository ppa:fenics-packages/fenics apt update apt install fenicsx ``` -------------------------------- ### Install DOLFINx with Conda Source: https://github.com/fenics/dolfinx/blob/main/README.md Installs the latest release of the Python interface, including pyvista for visualization, using conda. Ensure you create and activate a new conda environment first. ```shell conda create -n fenicsx-env conda activate fenicsx-env conda install -c conda-forge fenics-dolfinx mpich pyvista # Linux and macOS ``` ```shell conda install -c conda-forge fenics-dolfinx pyvista pyamg # Windows ``` -------------------------------- ### Run DOLFINx Jupyter Lab Docker Image Source: https://github.com/fenics/dolfinx/blob/main/README.md Starts a Docker container with a Jupyter Lab environment pre-configured with the latest DOLFINx release. Access the environment via http://localhost:8888. ```shell docker run --init -ti -p 8888:8888 dolfinx/lab:stable # Access at http://localhost:8888 ``` -------------------------------- ### Set Project Name and Find DOLFINx Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/biharmonic/CMakeLists.txt Sets the project name and finds the required DOLFINx package. Ensure DOLFINx is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.21) set(PROJECT_NAME demo_biharmonic) project(${PROJECT_NAME} LANGUAGES C CXX) if(NOT TARGET dolfinx) find_package(DOLFINX REQUIRED) endif() ``` -------------------------------- ### Run Sphinx Build for HTML Documentation Source: https://github.com/fenics/dolfinx/blob/main/python/doc/README.md Execute the Sphinx build command in the documentation directory to generate HTML output. Ensure the 'dolfinx' module is importable. ```bash python -m sphinx -W -b html source/ build/html/ ``` -------------------------------- ### Build DOLFINx C++ Documentation Source: https://github.com/fenics/dolfinx/blob/main/cpp/doc/README.md Use these commands to generate the Doxygen API documentation and build the Sphinx/Breathe rendered HTML documentation. ```bash > doxygen Doxyfile > make html ``` -------------------------------- ### Define Executable and Link Libraries Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/mixed_poisson/CMakeLists.txt Defines the main executable for the demo and links it against the DOLFINx library. This step is essential for creating a runnable program. ```cmake set(CMAKE_INCLUDE_CURRENT_DIR ON) add_executable(${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/mixed_poisson.c) target_link_libraries(${PROJECT_NAME} dolfinx) ``` -------------------------------- ### Build DOLFINx C++ Library Source: https://github.com/fenics/dolfinx/blob/main/python/doc/source/installation.rst Build the C++ library using CMake. Create a build directory and run CMake and make commands. ```bash mkdir -p build/ cd build/ cmake ../ make install ``` -------------------------------- ### Explicit Constructor Example Source: https://github.com/fenics/dolfinx/blob/main/python/doc/source/styleguide_cpp.rst Make all one-argument constructors (except copy constructors) explicit to prevent unintended implicit conversions. ```c++ class Foo { explicit Foo(std::size_t i); }; ``` -------------------------------- ### Run DOLFINx Docker Image Source: https://github.com/fenics/dolfinx/blob/main/README.md Launches a Docker container with the latest stable release of DOLFINx. ```shell docker run -ti dolfinx/dolfinx:stable ``` -------------------------------- ### Define Executable and Link Libraries Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/hyperelasticity/CMakeLists.txt Defines the main executable for the demo, including the compiled UFL code, and links it against the DOLFINx library. ```cmake add_executable(${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/hyperelasticity.c) target_link_libraries(${PROJECT_NAME} dolfinx) ``` -------------------------------- ### dolfinx.fem.assemble_scalar Source: https://context7.com/fenics/dolfinx/llms.txt Assembles a zero-form (scalar) into a local float value. The result is local to the calling MPI rank; reduce with msh.comm.allreduce to get the global value. ```APIDOC ## `dolfinx.fem.assemble_scalar` — Assemble a scalar functional Assembles a zero-form (scalar) into a local float value. The result is local to the calling MPI rank; reduce with `msh.comm.allreduce` to get the global value. ```python from mpi4py import MPI import ufl from dolfinx import fem, mesh msh = mesh.create_unit_square(MPI.COMM_WORLD, 32, 32) V = fem.functionspace(msh, ("Lagrange", 1)) u = fem.Function(V) u.interpolate(lambda x: x[0] ** 2) # Compute L2 norm^2 of u M = fem.form(ufl.inner(u, u) * ufl.dx) local_val = fem.assemble_scalar(M) global_val = msh.comm.allreduce(local_val, op=MPI.SUM) print(f"||u||^2 = {global_val:.6f}") # expected: 1/3 ``` ``` -------------------------------- ### Run DOLFINx Nightly Docker Image Source: https://github.com/fenics/dolfinx/blob/main/README.md Launches a Docker container with the nightly build of DOLFINx. Use this for testing the latest development versions. ```shell docker run -ti dolfinx/dolfinx:nightly ``` -------------------------------- ### Update Version Number in DOLFINx CMakeLists.txt Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md Change the version number in the C++ CMakeLists.txt file for DOLFINx. Example shows updating to a specific minor version. ```bash In `cpp/CMakeLists.txt` change the version number e.g. `0.5.0`. ``` -------------------------------- ### Update Version Number in FFCx pyproject.toml Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md Change the version number in the pyproject.toml file for the FFCx component. This example shows updating to a specific minor version. ```bash Update the version number in `pyproject.toml`, e.g. `0.5.0`. ``` -------------------------------- ### Run DOLFINx Integration Tests with FFCx Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md Manually trigger the GitHub Action Workflow for DOLFINx tests with FFCx. Ensure the 'release' branch is used for all fields and proceed only after all tests pass. ```bash FFCx with DOLFINx: https://github.com/FEniCS/ffcx/actions/workflows/dolfinx-tests.yml ``` -------------------------------- ### Update Version Number in pyproject.toml (UFL) Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md Modify the version number in the pyproject.toml file for UFL component during the release process. Example shows a minor version bump. ```bash Update the version number in `pyproject.toml`, e.g. `2022.2.0`. ``` -------------------------------- ### Write and Read XDMF Files with DOLFINx Source: https://context7.com/fenics/dolfinx/llms.txt Demonstrates writing meshes, functions, and mesh tags to XDMF files and subsequently reading them back. Use for visualization with ParaView/VisIt. ```python from mpi4py import MPI import numpy as np from dolfinx import fem, mesh, io # --- Writing --- msh = mesh.create_unit_square(MPI.COMM_WORLD, 16, 16) V = fem.functionspace(msh, ("Lagrange", 1)) u = fem.Function(V, name="temperature") u.interpolate(lambda x: np.sin(np.pi * x[0]) * np.sin(np.pi * x[1])) with io.XDMFFile(msh.comm, "output.xdmf", "w") as xdmf: xdmf.write_mesh(msh) xdmf.write_function(u, t=0.0) # t is time stamp for time series # --- Reading --- with io.XDMFFile(MPI.COMM_WORLD, "output.xdmf", "r") as xdmf: msh2 = xdmf.read_mesh() # --- Mesh tags (subdomains) --- import ufl fdim = msh.topology.dim - 1 msh.topology.create_connectivity(fdim, msh.topology.dim) left = mesh.locate_entities_boundary(msh, fdim, lambda x: np.isclose(x[0], 0.0)) ft = mesh.meshtags(msh, fdim, left, np.ones(len(left), dtype=np.int32)) with io.XDMFFile(msh.comm, "tags.xdmf", "w") as xdmf: xdmf.write_mesh(msh) xdmf.write_meshtags(ft, msh.geometry) ``` -------------------------------- ### Run DOLFINx Development Main Branch Docker Image Source: https://github.com/fenics/dolfinx/blob/main/README.md Launches a Docker container with dependencies to build the `main` branch of FEniCSx components. This is for developers working with the latest code. ```shell docker run -ti dolfinx/dev-env:current ``` -------------------------------- ### Check PETSC Scalar Type Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/biharmonic/CMakeLists.txt Checks for PETSC complex and double-precision real types to determine the scalar type for UFL compilation. This ensures compatibility with the installed PETSc library. ```cmake include(CheckSymbolExists) set(CMAKE_REQUIRED_INCLUDES ${PETSC_INCLUDE_DIRS}) check_symbol_exists(PETSC_USE_COMPLEX petscsystypes.h PETSC_SCALAR_COMPLEX) check_symbol_exists(PETSC_USE_REAL_DOUBLE petscsystypes.h PETSC_REAL_DOUBLE) ``` -------------------------------- ### Update Version Number in FFCx CMakeLists.txt Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md If necessary, update the version number in the main CMakeLists.txt file for the FFCx component. Example shows updating to a specific minor version. ```bash If necessary, update the version number in `cmake/CMakeLists.txt`, e.g. `0.5.0`. ``` -------------------------------- ### Implementation File Layout Template Source: https://github.com/fenics/dolfinx/blob/main/python/doc/source/styleguide_cpp.rst Standard template for C++ implementation files, including copyright, license, includes, namespace usage, and class method definitions. ```c++ // Copyright (C) 2018 Foo Bar // // This file is part of DOLFINx (https://www.fenicsproject.org) // // SPDX-License-Identifier: LGPL-3.0-or-later #include using namespace dolfinx; //----------------------------------------------------------------------------- Foo::Foo() : // variable initialization here { ... } //----------------------------------------------------------------------------- Foo::~Foo() { // Do nothing } //----------------------------------------------------------------------------- ``` -------------------------------- ### Assemble Scalar Functional with dolfinx.fem.assemble_scalar Source: https://context7.com/fenics/dolfinx/llms.txt Assembles a zero-form (scalar) into a local float value. The result is local to the calling MPI rank; reduce with `msh.comm.allreduce` to get the global value. ```python from mpi4py import MPI import ufl from dolfinx import fem, mesh msh = mesh.create_unit_square(MPI.COMM_WORLD, 32, 32) V = fem.functionspace(msh, ("Lagrange", 1)) u = fem.Function(V) u.interpolate(lambda x: x[0] ** 2) # Compute L2 norm^2 of u M = fem.form(ufl.inner(u, u) * ufl.dx) local_val = fem.assemble_scalar(M) global_val = msh.comm.allreduce(local_val, op=MPI.SUM) print(f"||u||^2 = {global_val:.6f}") # expected: 1/3 ``` -------------------------------- ### Geometric Search with Bounding Box Trees in DOLFINx Source: https://context7.com/fenics/dolfinx/llms.txt Demonstrates constructing a bounding-box tree for efficient spatial queries and using it with collision detection functions to find cells containing query points for function evaluation. ```python from mpi4py import MPI import numpy as np from dolfinx import fem, mesh from dolfinx.geometry import bb_tree, compute_collisions_points, compute_colliding_cells msh = mesh.create_unit_square(MPI.COMM_WORLD, 32, 32) V = fem.functionspace(msh, ("Lagrange", 2)) u = fem.Function(V) u.interpolate(lambda x: x[0] ** 2 + x[1] ** 2) # Build tree over all cells tree = bb_tree(msh, msh.topology.dim) # Query points (shape: (num_points, 3)) query_pts = np.array([[0.25, 0.75, 0.0], [0.5, 0.5, 0.0], [0.9, 0.1, 0.0]]) # Find candidate cells candidates = compute_collisions_points(tree, query_pts) # Narrow to cells that actually contain the points colliding_cells = compute_colliding_cells(msh, candidates, query_pts) # Evaluate u at the found cells values = u.eval(query_pts, colliding_cells.array) print(values) # Expected: ~[0.625, 0.5, 0.82] ``` -------------------------------- ### Build DOLFINx Python Interface in Developer Mode Source: https://github.com/fenics/dolfinx/blob/main/python/README.md Installs the DOLFINx Python interface in developer and editable mode for active development. This mode is stricter than CMake's default Debug mode. ```bash pip -v install --check-build-dependencies --config-settings=build-dir="build" --config-settings=cmake.build-type="Developer" --config-settings=install.strip=false --no-build-isolation -e . ``` -------------------------------- ### Tagging a Release in Git Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md Use this command to create a version tag for a release. UFL does not use the 'v' prefix. ```bash git tag v0.5.0 git push --tags origin ``` -------------------------------- ### Cherry-picking Commits for Release Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md This sequence demonstrates how to check for changes on the release branch, diff them against main, and cherry-pick specific commits back onto the main branch. ```bash git checkout main git diff release git log git cherry-pick 914ae4 ``` -------------------------------- ### Adding Demo Subdirectories Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/CMakeLists.txt These commands use the 'add_demo_subdirectory' macro to include various demo subdirectories into the build. Each 'add_subdirectory' call processes the CMakeLists.txt file within the specified demo directory. ```cmake add_demo_subdirectory(biharmonic) ``` ```cmake add_demo_subdirectory(codim_0_assembly) ``` ```cmake add_demo_subdirectory(custom_kernel) ``` ```cmake add_demo_subdirectory(hyperelasticity) ``` ```cmake add_demo_subdirectory(interpolation-io) ``` ```cmake add_demo_subdirectory(interpolation_different_meshes) ``` ```cmake add_demo_subdirectory(mixed_poisson) ``` ```cmake add_demo_subdirectory(poisson) ``` ```cmake add_demo_subdirectory(poisson_matrix_free) ``` -------------------------------- ### SCOTCH Partitioning Strategy Source: https://github.com/fenics/dolfinx/blob/main/cpp/doc/source/graph.rst Enumerates the available strategies for graph partitioning using the SCOTCH library. ```APIDOC ## dolfinx::graph::scotch::strategy Enumerates the different strategies available for graph partitioning with the SCOTCH library. These strategies control how SCOTCH performs the partitioning. ``` -------------------------------- ### Executable Target and Linking Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/poisson/CMakeLists.txt Defines the main executable for the Poisson demo, including the generated C source file from FFCx, and links it against the DOLFINx library. This step compiles the C++ source and the generated C code. ```cmake set(CMAKE_INCLUDE_CURRENT_DIR ON) add_executable(${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/poisson.c) target_link_libraries(${PROJECT_NAME} dolfinx) ``` -------------------------------- ### File Name Convention Source: https://github.com/fenics/dolfinx/blob/main/python/doc/source/styleguide_cpp.rst Use camel caps for class-related files (.h, .cpp) and lower-case for utility/function files. ```c++ FooBar.h FooBar.cpp ``` -------------------------------- ### Running a Tagged Docker Container Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md Execute this command to run a Docker container with a specific version tag. Ensure the tag matches the DOLFINx version. ```bash docker run -ti dolfinx/dolfinx:v0.5.0 ``` -------------------------------- ### Low-level PETSc Assembly Loop in DOLFINx Source: https://context7.com/fenics/dolfinx/llms.txt Demonstrates a time-stepping loop using low-level PETSc assembly functions. Matrices and vectors are reassembled without reallocation. Requires PETSc backend. ```python from mpi4py import MPI import numpy as np import ufl from dolfinx import fem, mesh from dolfinx.fem.petsc import ( create_matrix, create_vector, assemble_matrix, assemble_vector, apply_lifting ) msh = mesh.create_unit_square(MPI.COMM_WORLD, 16, 16) V = fem.functionspace(msh, ("Lagrange", 1)) u, v = ufl.TrialFunction(V), ufl.TestFunction(V) f = fem.Constant(msh, 1.0) a_form = fem.form(ufl.inner(ufl.grad(u), ufl.grad(v)) * ufl.dx) L_form = fem.form(f * v * ufl.dx) fdim = msh.topology.dim - 1 facets = mesh.exterior_facet_indices(msh.topology) dofs = fem.locate_dofs_topological(V, fdim, facets) bc = fem.dirichletbc(0.0, dofs, V) # Allocate PETSc objects once A = create_matrix(a_form) b = create_vector(V) # Assembly loop (e.g., time-stepping) for step in range(3): f.value = float(step + 1) # Assemble matrix A.zeroEntries() assemble_matrix(A, a_form, bcs=[bc]) A.assemble() # Assemble RHS with b.localForm() as b_local: b_local.set(0) assemble_vector(b, L_form) apply_lifting(b, [a_form], bcs=[[bc]]) b.ghostUpdate(addv=b.InsertMode.ADD, mode=b.ScatterMode.REVERSE) bc.set(b.array_w) ``` -------------------------------- ### Run FFCx Integration Tests with Basix Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md Manually trigger the GitHub Action Workflow for FFCx tests with Basix. Ensure the 'release' branch is used for all fields and proceed only after all tests pass. ```bash Basix with FFCx: https://github.com/FEniCS/basix/actions/workflows/ffcx-tests.yml ``` -------------------------------- ### dolfinx.io.XDMFFile Source: https://context7.com/fenics/dolfinx/llms.txt Provides mesh and function I/O in XDMF/HDF5 format, compatible with ParaView and VisIt for visualization. Supports reading and writing meshes, mesh tags, and scalar/vector functions with time-stepping. ```APIDOC ## `dolfinx.io.XDMFFile` — Read/write XDMF files Provides mesh and function I/O in XDMF/HDF5 format, compatible with ParaView and VisIt for visualization. Supports reading and writing meshes, mesh tags, and scalar/vector functions with time-stepping. ```python from mpi4py import MPI import numpy as np from dolfinx import fem, mesh, io # --- Writing --- msh = mesh.create_unit_square(MPI.COMM_WORLD, 16, 16) V = fem.functionspace(msh, ("Lagrange", 1)) u = fem.Function(V, name="temperature") u.interpolate(lambda x: np.sin(np.pi * x[0]) * np.sin(np.pi * x[1])) with io.XDMFFile(msh.comm, "output.xdmf", "w") as xdmf: xdmf.write_mesh(msh) xdmf.write_function(u, t=0.0) # t is time stamp for time series # --- Reading --- with io.XDMFFile(MPI.COMM_WORLD, "output.xdmf", "r") as xdmf: msh2 = xdmf.read_mesh() # --- Mesh tags (subdomains) --- import ufl fdim = msh.topology.dim - 1 msh.topology.create_connectivity(fdim, msh.topology.dim) left = mesh.locate_entities_boundary(msh, fdim, lambda x: np.isclose(x[0], 0.0)) ft = mesh.meshtags(msh, fdim, left, np.ones(len(left), dtype=np.int32)) with io.XDMFFile(msh.comm, "tags.xdmf", "w") as xdmf: xdmf.write_mesh(msh) xdmf.write_meshtags(ft, msh.geometry) ``` ``` -------------------------------- ### Run DOLFINx Integration Tests with Basix Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md Manually trigger the GitHub Action Workflow for DOLFINx tests with Basix. Ensure the 'release' branch is used for all fields and proceed only after all tests pass. ```bash Basix with DOLFINx: https://github.com/FEniCS/basix/actions/workflows/dolfinx-tests.yml ``` -------------------------------- ### Run FEniCSx Integration Tests with UFL Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md Manually trigger the GitHub Action Workflow for FEniCSx tests with UFL. Ensure the 'release' branch is used for all fields and proceed only after all tests pass. ```bash UFL with FEniCSx: https://github.com/FEniCS/ufl/actions/workflows/fenicsx-tests.yml ``` -------------------------------- ### Enabling Testing Source: https://github.com/fenics/dolfinx/blob/main/cpp/demo/CMakeLists.txt This command enables the testing framework for the project, allowing tests to be discovered and run using CTest. ```cmake enable_testing() ``` -------------------------------- ### Apply Developer Compiler Definitions Source: https://github.com/fenics/dolfinx/blob/main/cpp/test/CMakeLists.txt Applies developer-specific preprocessor definitions to the unit tests when the 'Developer' configuration is active. ```cmake if (DEFINED DOLFINX_CXX_DEVELOPER_DEFINITIONS) target_compile_definitions( unittests PRIVATE $<$,$>:${DOLFINX_CXX_DEVELOPER_DEFINITIONS}> ) endif() ``` -------------------------------- ### Run Full Stack Integration Tests for FEniCSx Source: https://github.com/fenics/dolfinx/blob/main/RELEASE.md Manually trigger the full stack C++ integration tests for FEniCSx. Ensure the 'release' branch is used for all fields and proceed only after all tests pass. ```bash Full stack: https://github.com/FEniCS/dolfinx/actions/workflows/ccpp.yml ``` -------------------------------- ### Comment Style Source: https://github.com/fenics/dolfinx/blob/main/python/doc/source/styleguide_cpp.rst Use '//' for comments, capitalizing the first letter and omitting punctuation unless the comment spans multiple sentences. Use '///' for documentation. ```c++ // Check if connectivity has already been computed if (!connectivity.empty()) return; // Invalidate ordering mesh._ordered = false; // Compute entities if they don't exist if (topology.size(d0) == 0) compute_entities(mesh, d0); if (topology.size(d1) == 0) compute_entities(mesh, d1); // Check if connectivity still needs to be computed if (!connectivity.empty()) return; ... ```