├── .cmake-format ├── AUTHORS ├── CITATION.cff ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── COPYING ├── COPYING.LESSER ├── ChangeLog.rst ├── README.md ├── RELEASE.md ├── cpp ├── .vcpkg-overlay │ ├── README.md │ ├── intel-mpi │ │ ├── mpi-wrapper.cmake │ │ ├── portfile.cmake │ │ └── vcpkg.json │ └── mpi │ │ ├── portfile.cmake │ │ └── vcpkg.json ├── CMakeLists.txt ├── cmake │ ├── modules │ │ ├── FindKaHIP.cmake │ │ ├── FindParMETIS.cmake │ │ └── FindUFCx.cmake │ ├── post-install │ │ └── CMakeLists.txt │ ├── scripts │ │ └── generate-cmakefiles.py │ └── templates │ │ ├── DOLFINXConfig.cmake.in │ │ ├── cmake_uninstall.cmake.in │ │ ├── dolfinx.conf.in │ │ └── dolfinx.pc.in ├── demo │ ├── CMakeLists.txt │ ├── README.md │ ├── biharmonic │ │ ├── CMakeLists.txt │ │ ├── biharmonic.py │ │ └── main.cpp │ ├── codim_0_assembly │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ └── mixed_codim0.py │ ├── custom_kernel │ │ ├── CMakeLists.txt │ │ └── main.cpp │ ├── hyperelasticity │ │ ├── CMakeLists.txt │ │ ├── hyperelasticity.py │ │ └── main.cpp │ ├── interpolation-io │ │ ├── CMakeLists.txt │ │ └── main.cpp │ ├── interpolation_different_meshes │ │ ├── CMakeLists.txt │ │ └── main.cpp │ ├── mixed_poisson │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ └── mixed_poisson.py │ ├── poisson │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ └── poisson.py │ └── poisson_matrix_free │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ └── poisson.py ├── doc │ ├── Doxyfile │ ├── Makefile │ ├── README.md │ └── source │ │ ├── api.rst │ │ ├── common.rst │ │ ├── conf.py │ │ ├── demo.rst │ │ ├── fem.rst │ │ ├── geometry.rst │ │ ├── graph.rst │ │ ├── index.rst │ │ ├── io.rst │ │ ├── jupytext_process.py │ │ ├── la.rst │ │ ├── mesh.rst │ │ └── refinement.rst ├── dolfinx │ ├── CMakeLists.txt │ ├── common │ │ ├── CMakeLists.txt │ │ ├── IndexMap.cpp │ │ ├── IndexMap.h │ │ ├── MPI.cpp │ │ ├── MPI.h │ │ ├── Scatterer.h │ │ ├── Table.cpp │ │ ├── Table.h │ │ ├── TimeLogger.cpp │ │ ├── TimeLogger.h │ │ ├── Timer.h │ │ ├── defines.cpp │ │ ├── defines.h │ │ ├── dolfinx_common.h │ │ ├── dolfinx_doc.h │ │ ├── log.cpp │ │ ├── log.h │ │ ├── math.h │ │ ├── sort.h │ │ ├── timing.cpp │ │ ├── timing.h │ │ ├── types.h │ │ ├── utils.h │ │ └── version.h.in │ ├── dolfinx.h │ ├── fem │ │ ├── CMakeLists.txt │ │ ├── Constant.h │ │ ├── CoordinateElement.cpp │ │ ├── CoordinateElement.h │ │ ├── DirichletBC.cpp │ │ ├── DirichletBC.h │ │ ├── DofMap.cpp │ │ ├── DofMap.h │ │ ├── ElementDofLayout.cpp │ │ ├── ElementDofLayout.h │ │ ├── Expression.h │ │ ├── FiniteElement.cpp │ │ ├── FiniteElement.h │ │ ├── Form.h │ │ ├── Function.h │ │ ├── FunctionSpace.h │ │ ├── assemble_expression_impl.h │ │ ├── assemble_matrix_impl.h │ │ ├── assemble_scalar_impl.h │ │ ├── assemble_vector_impl.h │ │ ├── assembler.h │ │ ├── discreteoperators.h │ │ ├── dofmapbuilder.cpp │ │ ├── dofmapbuilder.h │ │ ├── dolfinx_fem.h │ │ ├── interpolate.h │ │ ├── pack.h │ │ ├── petsc.cpp │ │ ├── petsc.h │ │ ├── sparsitybuild.cpp │ │ ├── sparsitybuild.h │ │ ├── traits.h │ │ ├── utils.cpp │ │ └── utils.h │ ├── geometry │ │ ├── BoundingBoxTree.h │ │ ├── CMakeLists.txt │ │ ├── dolfinx_geometry.h │ │ ├── gjk.h │ │ └── utils.h │ ├── graph │ │ ├── AdjacencyList.h │ │ ├── CMakeLists.txt │ │ ├── dolfinx_graph.h │ │ ├── ordering.cpp │ │ ├── ordering.h │ │ ├── partition.cpp │ │ ├── partition.h │ │ ├── partitioners.cpp │ │ └── partitioners.h │ ├── io │ │ ├── ADIOS2Writers.cpp │ │ ├── ADIOS2Writers.h │ │ ├── CMakeLists.txt │ │ ├── HDF5Interface.cpp │ │ ├── HDF5Interface.h │ │ ├── VTKFile.cpp │ │ ├── VTKFile.h │ │ ├── VTKHDF.h │ │ ├── XDMFFile.cpp │ │ ├── XDMFFile.h │ │ ├── cells.cpp │ │ ├── cells.h │ │ ├── dolfinx_io.h │ │ ├── utils.h │ │ ├── vtk_utils.cpp │ │ ├── vtk_utils.h │ │ ├── xdmf_function.cpp │ │ ├── xdmf_function.h │ │ ├── xdmf_mesh.cpp │ │ ├── xdmf_mesh.h │ │ ├── xdmf_utils.cpp │ │ └── xdmf_utils.h │ ├── la │ │ ├── CMakeLists.txt │ │ ├── MatrixCSR.h │ │ ├── SparsityPattern.cpp │ │ ├── SparsityPattern.h │ │ ├── Vector.h │ │ ├── dolfinx_la.h │ │ ├── matrix_csr_impl.h │ │ ├── petsc.cpp │ │ ├── petsc.h │ │ ├── slepc.cpp │ │ ├── slepc.h │ │ └── utils.h │ ├── mesh │ │ ├── CMakeLists.txt │ │ ├── Geometry.h │ │ ├── Mesh.h │ │ ├── MeshTags.h │ │ ├── Topology.cpp │ │ ├── Topology.h │ │ ├── cell_types.cpp │ │ ├── cell_types.h │ │ ├── dolfinx_mesh.h │ │ ├── generation.h │ │ ├── graphbuild.cpp │ │ ├── graphbuild.h │ │ ├── permutationcomputation.cpp │ │ ├── permutationcomputation.h │ │ ├── topologycomputation.cpp │ │ ├── topologycomputation.h │ │ ├── utils.cpp │ │ └── utils.h │ ├── nls │ │ ├── CMakeLists.txt │ │ ├── NewtonSolver.cpp │ │ ├── NewtonSolver.h │ │ └── dolfinx_nls.h │ └── refinement │ │ ├── CMakeLists.txt │ │ ├── dolfinx_refinement.h │ │ ├── interval.h │ │ ├── option.h │ │ ├── plaza.cpp │ │ ├── plaza.h │ │ ├── refine.h │ │ ├── utils.cpp │ │ └── utils.h ├── ruff.toml ├── test │ ├── CMakeLists.txt │ ├── common │ │ ├── CIFailure.cpp │ │ ├── index_map.cpp │ │ ├── sort.cpp │ │ └── sub_systems_manager.cpp │ ├── fem │ │ ├── expr.py │ │ ├── form.cpp │ │ └── functionspace.cpp │ ├── io.cpp │ ├── main.cpp │ ├── matrix.cpp │ ├── mesh │ │ ├── branching_manifold.cpp │ │ ├── distributed_mesh.cpp │ │ ├── generation.cpp │ │ ├── read_named_meshtags.cpp │ │ └── refinement │ │ │ ├── interval.cpp │ │ │ ├── option.cpp │ │ │ └── rectangle.cpp │ ├── poisson.py │ ├── vcpkg.json │ └── vector.cpp └── vcpkg.json └── python ├── CMakeLists.txt ├── README.md ├── build-requirements.txt ├── conda-oneapi-test-env.yml ├── demo ├── conftest.py ├── data │ └── cooks_tri_mesh.xdmf ├── demo_axis.py ├── demo_biharmonic.py ├── demo_cahn-hilliard.py ├── demo_elasticity.py ├── demo_gmsh.py ├── demo_half_loaded_waveguide.py ├── demo_hdg.py ├── demo_helmholtz.py ├── demo_interpolation-io.py ├── demo_lagrange_variants.py ├── demo_mixed-poisson.py ├── demo_mixed-topology.py ├── demo_navier-stokes.py ├── demo_pml.py ├── demo_poisson.py ├── demo_poisson_matrix_free.py ├── demo_pyamg.py ├── demo_pyvista.py ├── demo_scattering_boundary_conditions.py ├── demo_static-condensation.py ├── demo_stokes.py ├── demo_tnt-elements.py ├── demo_types.py ├── pyproject.toml ├── pytest.ini └── test.py ├── doc ├── README.md └── source │ ├── api.rst │ ├── conf.py │ ├── contributing.rst │ ├── demos.rst │ ├── developer.rst │ ├── index.rst │ ├── installation.rst │ ├── jupytext_process.py │ └── styleguide_cpp.rst ├── dolfinx ├── __init__.py ├── common.py ├── fem │ ├── __init__.py │ ├── assemble.py │ ├── bcs.py │ ├── dofmap.py │ ├── element.py │ ├── forms.py │ ├── function.py │ └── petsc.py ├── geometry.py ├── graph.py ├── io │ ├── __init__.py │ ├── gmshio.py │ ├── utils.py │ └── vtkhdf.py ├── jit.py ├── la │ ├── __init__.py │ └── petsc.py ├── log.py ├── mesh.py ├── nls │ ├── __init__.py │ └── petsc.py ├── pkgconfig.py ├── plot.py ├── py.typed ├── utils.py └── wrappers │ ├── assemble.cpp │ ├── common.cpp │ ├── dolfinx.cpp │ ├── dolfinx_wrappers │ ├── MPICommWrapper.h │ ├── array.h │ ├── caster_mpi.h │ ├── caster_petsc.h │ ├── mesh.h │ ├── numpy_dtype.h │ └── pycoeff.h │ ├── fem.cpp │ ├── geometry.cpp │ ├── graph.cpp │ ├── io.cpp │ ├── la.cpp │ ├── log.cpp │ ├── mesh.cpp │ ├── petsc.cpp │ └── refinement.cpp ├── pyproject.toml ├── test ├── conftest.py ├── data │ ├── create_unit_cube_hexahedron.xdmf │ ├── create_unit_cube_tetra.xdmf │ ├── create_unit_square_quad.xdmf │ ├── create_unit_square_triangle.xdmf │ └── mesh.xdmf └── unit │ ├── __init__.py │ ├── common │ ├── test_index_map.py │ ├── test_mpi.py │ ├── test_public_api.py │ ├── test_scatterer.py │ ├── test_timer.py │ └── test_version.py │ ├── conftest.py │ ├── fem │ ├── gmsh_unit_interval.xml │ ├── test_assemble_domains.py │ ├── test_assemble_mesh_independent_form.py │ ├── test_assemble_submesh.py │ ├── test_assembler.py │ ├── test_bcs.py │ ├── test_complex_assembler.py │ ├── test_constant.py │ ├── test_custom_assembler.py │ ├── test_custom_basix_element.py │ ├── test_custom_jit_kernels.py │ ├── test_discrete_operators.py │ ├── test_dof_coordinates.py │ ├── test_dof_permuting.py │ ├── test_dofmap.py │ ├── test_element_integrals.py │ ├── test_expression.py │ ├── test_fem_pipeline.py │ ├── test_forms.py │ ├── test_function.py │ ├── test_function_space.py │ ├── test_ghost_mesh_assembly.py │ ├── test_interpolation.py │ ├── test_mixed_element.py │ ├── test_mixed_mesh_dofmap.py │ ├── test_petsc_discrete_operators.py │ ├── test_petsc_nonlinear_assembler.py │ ├── test_petsc_solver_wrappers.py │ ├── test_quadrature_elements.py │ ├── test_special_functions.py │ ├── test_symmetric_tensor.py │ ├── test_symmetry.py │ ├── test_vector_assemble.py │ ├── test_vector_function.py │ └── tetrahedron.xml │ ├── geometry │ ├── test_bounding_box_tree.py │ └── test_gjk.py │ ├── graph │ └── test_adjacencylist.py │ ├── io │ ├── test_adios2.py │ ├── test_vtk.py │ ├── test_vtkhdf.py │ ├── test_xdmf_function.py │ ├── test_xdmf_mesh.py │ ├── test_xdmf_meshdata.py │ ├── test_xdmf_meshtags.py │ └── xml_value_collection_ref.xml │ ├── la │ ├── test_matrix_csr.py │ ├── test_matrix_vector.py │ ├── test_nullspace.py │ ├── test_sparsity_pattern.py │ └── test_vector_scatter.py │ ├── mesh │ ├── test_cell.py │ ├── test_create_mixed_mesh.py │ ├── test_dual_graph.py │ ├── test_face.py │ ├── test_ghost_mesh.py │ ├── test_higher_order_mesh.py │ ├── test_manifold_point_search.py │ ├── test_mesh.py │ ├── test_mesh_partitioners.py │ ├── test_meshtags.py │ └── test_mixed_topology.py │ ├── nls │ └── test_newton.py │ └── refinement │ ├── test_interval.py │ └── test_refinement.py └── vcpkg.json /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use this software, please cite it as below." 3 | title: "DOLFINx" 4 | version: 0.9.0 5 | date-released: 2024-10-10 6 | url: "https://github.com/FEniCS/dolfinx" 7 | doi: "10.5281/zenodo.10047760" 8 | authors: 9 | - family-names: "FEniCS Project Developers" 10 | given-names: "The" 11 | preferred-citation: 12 | type: article 13 | authors: 14 | - family-names: "Baratta" 15 | given-names: "Igor A." 16 | orcid: "https://orcid.org/0000-0003-4298-2973" 17 | - family-names: "Dean" 18 | given-names: "Joseph P." 19 | orcid: "https://orcid.org/0000-0001-7499-3373" 20 | - family-names: "Dokken" 21 | given-names: "Jørgen S." 22 | orcid: "https://orcid.org/0000-0001-6489-8858" 23 | - family-names: "Habera" 24 | given-names: "Michal" 25 | orcid: "https://orcid.org/0000-0003-0604-8884" 26 | - family-names: "Hale" 27 | given-names: "Jack S." 28 | orcid: "https://orcid.org/0000-0001-7216-861X" 29 | - family-names: "Richardson" 30 | given-names: "Chris N." 31 | orcid: "https://orcid.org/0000-0003-3137-1392" 32 | - family-names: "Rognes" 33 | given-names: "Marie E." 34 | orcid: "https://orcid.org/0000-0002-6872-3710" 35 | - family-names: "Scroggs" 36 | given-names: "Matthew W." 37 | orcid: "https://orcid.org/0000-0002-4658-2443" 38 | - family-names: "Sime" 39 | given-names: "Nathan" 40 | orcid: "https://orcid.org/0000-0002-2319-048X" 41 | - family-names: "Wells" 42 | given-names: "Garth N." 43 | orcid: "https://orcid.org/0000-0001-5291-7951" 44 | doi: "10.5281/zenodo.10447666" 45 | journal: "preprint" 46 | title: "DOLFINx: the next generation FEniCS problem solving environment" 47 | year: 2023 48 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to contribute 2 | 3 | ### Reporting bugs 4 | 5 | If you find a bug in DOLFINx, please report it on the [GitHub issue 6 | tracker](https://github.com/fenics/dolfinx/issues/new?labels=bug). 7 | 8 | 9 | ### Suggesting enhancements 10 | 11 | If you want to suggest a new feature or an improvement of a current 12 | feature, you can submit this on the [issue 13 | tracker](https://github.com/fenics/dolfinx/issues). 14 | 15 | 16 | ### Submitting a pull request 17 | 18 | To contribute code DOLFINx, create a pull request. If you want to 19 | contribute, but are unsure where to start, have a look at the [issues 20 | labelled "good first 21 | issue"](https://github.com/FEniCS/dolfinx/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22). 22 | For substantial changes/contributions, please start with an issue or 23 | start a discussion on Slack. 24 | 25 | On opening a pull request, unit tests will run on GitHub CI. You can 26 | click on these in the pull request to see where (if anywhere) the tests 27 | are failing. 28 | 29 | 30 | ### Code of conduct 31 | 32 | We expect all our contributors to follow the [code of 33 | conduct](CODE_OF_CONDUCT.md). 34 | -------------------------------------------------------------------------------- /cpp/.vcpkg-overlay/README.md: -------------------------------------------------------------------------------- 1 | # vcpkg overlay port for Intel MPI 2 | 3 | This vcpkg overlay port contains scripts for installing Intel MPI on Windows 4 | (only). MSMPI, which is used by default with vcpkg, does not support the MPI3 5 | standard. Using this port requires that Intel OneAPI binaries are already 6 | installed. On Unix systems the built-in OpenMPI or MPICH ports can be used. 7 | 8 | From the root of this repository it can be activated by e.g.: 9 | 10 | cmake -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%/scripts/buildsystems/vcpkg.cmake -DVCPKG_OVERLAY_PORTS="cpp/.vcpkg-overlay" -B build-dir -S cpp/ 11 | 12 | This overlay port was adapted from the original at: 13 | 14 | https://github.com/arcaneframework/framework-ci 15 | -------------------------------------------------------------------------------- /cpp/.vcpkg-overlay/intel-mpi/mpi-wrapper.cmake: -------------------------------------------------------------------------------- 1 | get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) 2 | get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) 3 | get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) 4 | 5 | # Needed to find 'mpiexec' 6 | set(ENV{I_MPI_ROOT} "${_IMPORT_PREFIX}/tools/intel-mpi") 7 | 8 | set(MPI_C_ADDITIONAL_INCLUDE_DIRS 9 | "${_IMPORT_PREFIX}/include" 10 | CACHE STRING "MPI C additional include directories" FORCE 11 | ) 12 | set(MPI_CXX_ADDITIONAL_INCLUDE_DIRS 13 | "${_IMPORT_PREFIX}/include" 14 | CACHE STRING "MPI CXX additional include directories" FORCE 15 | ) 16 | 17 | set(MPI_C_LIB_NAMES 18 | "IMPI" 19 | CACHE STRING "MPI C lib name" FORCE 20 | ) 21 | set(MPI_CXX_LIB_NAMES 22 | "IMPI" 23 | CACHE STRING "MPI CXX lib name" FORCE 24 | ) 25 | set(MPI_IMPI_LIBRARY 26 | "${_IMPORT_PREFIX}/lib/impi.lib" 27 | CACHE STRING "MPI C/CXX libraries" FORCE 28 | ) 29 | set(MPI_ASSUME_NO_BUILTIN_MPI 30 | TRUE 31 | CACHE BOOL "" FORCE 32 | ) 33 | 34 | set(MPI_C_COMPILER 35 | "${_IMPORT_PREFIX}/tools/intel-mpi/mpicc.bat" 36 | CACHE STRING "MPI C Compiler" FORCE 37 | ) 38 | set(MPI_CXX_COMPILER 39 | "${_IMPORT_PREFIX}/tools/intel-mpi/mpicxx.bat" 40 | CACHE STRING "MPI C Compiler" FORCE 41 | ) 42 | 43 | unset(_IMPORT_PREFIX) 44 | 45 | _find_package(${ARGS}) 46 | -------------------------------------------------------------------------------- /cpp/.vcpkg-overlay/intel-mpi/portfile.cmake: -------------------------------------------------------------------------------- 1 | set(INTELMPI_VERSION "2021.12") 2 | set(SOURCE_PATH "${CURRENT_BUILDTREES_DIR}/src/intel-mpi-${INTELMPI_VERSION}") 3 | 4 | cmake_path(SET SDK_SOURCE_DIR "C:/Program Files (x86)/Intel/oneAPI") 5 | 6 | message(STATUS "Using Intel MPI source SDK at ${SDK_SOURCE_DIR}") 7 | 8 | set(SDK_SOURCE_MPI_DIR "${SDK_SOURCE_DIR}/mpi/${INTELMPI_VERSION}") 9 | 10 | set(SOURCE_INCLUDE_PATH "${SDK_SOURCE_MPI_DIR}/include") 11 | set(SOURCE_LIB_PATH "${SDK_SOURCE_MPI_DIR}/lib") 12 | set(SOURCE_DEBUG_LIB_PATH "${SDK_SOURCE_MPI_DIR}/lib/mpi/debug") 13 | set(SOURCE_BIN_PATH "${SDK_SOURCE_MPI_DIR}/bin") 14 | set(SOURCE_DEBUG_BIN_PATH "${SDK_SOURCE_MPI_DIR}/bin/mpi/debug") 15 | set(SOURCE_TOOLS_PATH "${SDK_SOURCE_MPI_DIR}/bin") 16 | set(SOURCE_LIBFABRIC_PATH "${SDK_SOURCE_MPI_DIR}/opt/mpi/libfabric/bin") 17 | 18 | # Get files in include directory 19 | file( 20 | GLOB_RECURSE SOURCE_INCLUDE_FILES 21 | LIST_DIRECTORIES TRUE 22 | "${SOURCE_INCLUDE_PATH}/*" 23 | ) 24 | 25 | # Get files in bin directory 26 | file(GLOB TOOLS_FILES "${SOURCE_TOOLS_PATH}/*.exe" "${SOURCE_TOOLS_PATH}/*.dll" 27 | "${SOURCE_TOOLS_PATH}/*.bat" 28 | ) 29 | 30 | # Install tools files 31 | file(INSTALL ${TOOLS_FILES} DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}") 32 | 33 | # Also install include files in the tools directory because the compiler 34 | # wrappers (mpicc.bat for example) needs them 35 | file(INSTALL ${SOURCE_INCLUDE_FILES} 36 | DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}/include" 37 | ) 38 | 39 | # Install include files 40 | file(INSTALL ${SOURCE_INCLUDE_FILES} 41 | DESTINATION "${CURRENT_PACKAGES_DIR}/include" 42 | ) 43 | 44 | # Install release library files 45 | file(INSTALL "${SOURCE_LIB_PATH}/impi.lib" "${SOURCE_LIB_PATH}/impicxx.lib" 46 | DESTINATION "${CURRENT_PACKAGES_DIR}/lib" 47 | ) 48 | 49 | # Install debug library files 50 | file(INSTALL "${SOURCE_DEBUG_LIB_PATH}/impi.lib" 51 | "${SOURCE_DEBUG_LIB_PATH}/impicxx.lib" 52 | DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib" 53 | ) 54 | 55 | # 'libfabric.dll' is not needed for the compilation but it is needed for the 56 | # runtime and should be in the PATH for 'mpiexec' to work 57 | file(INSTALL "${SOURCE_LIBFABRIC_PATH}/libfabric.dll" 58 | "${SOURCE_BIN_PATH}/impi.dll" "${SOURCE_BIN_PATH}/impi.pdb" 59 | DESTINATION "${CURRENT_PACKAGES_DIR}/bin" 60 | ) 61 | 62 | file(INSTALL "${SOURCE_LIBFABRIC_PATH}/libfabric.dll" 63 | "${SOURCE_DEBUG_BIN_PATH}/impi.dll" "${SOURCE_DEBUG_BIN_PATH}/impi.pdb" 64 | DESTINATION "${CURRENT_PACKAGES_DIR}/debug/bin" 65 | ) 66 | 67 | file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/mpi-wrapper.cmake" 68 | DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" 69 | ) 70 | 71 | # Handle copyright 72 | file( 73 | COPY "${SDK_SOURCE_DIR}/licensing/2024.1/licensing/2024.1/license.htm" 74 | DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" 75 | ) 76 | file(WRITE "${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright" 77 | "See the licence.htm file in this directory." 78 | ) 79 | -------------------------------------------------------------------------------- /cpp/.vcpkg-overlay/intel-mpi/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "intel-mpi", 3 | "version": "2021.12.1", 4 | "port-version": 2, 5 | "description": "Intel MPI is a Intel implementation of the Message Passing Interface standard for developing and running parallel applications.", 6 | "homepage": "https://www.intel.com/content/www/us/en/developer/tools/oneapi/mpi-library.html", 7 | "supports": "windows & !uwp" 8 | } 9 | -------------------------------------------------------------------------------- /cpp/.vcpkg-overlay/mpi/portfile.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_POLICY_EMPTY_PACKAGE enabled) 2 | 3 | if(VCPKG_TARGET_IS_WINDOWS) 4 | file( 5 | INSTALL "${CURRENT_INSTALLED_DIR}/share/intel-mpi/mpi-wrapper.cmake" 6 | DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" 7 | RENAME vcpkg-cmake-wrapper.cmake 8 | ) 9 | endif() 10 | -------------------------------------------------------------------------------- /cpp/.vcpkg-overlay/mpi/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mpi", 3 | "version-string": "1", 4 | "port-version": 3, 5 | "description": "Message Passing Interface (MPI) is a standardized and portable message-passing standard designed by a group of researchers from academia and industry to function on a wide variety of parallel computing architectures. The standard defines the syntax and semantics of a core of library routines useful to a wide range of users writing portable message-passing programs in C, C++, and Fortran. There are several well-tested and efficient implementations of MPI, many of which are open-source or in the public domain.", 6 | "license": null, 7 | "supports": "!uwp", 8 | "dependencies": [ 9 | { 10 | "name": "intel-mpi", 11 | "platform": "windows" 12 | }, 13 | { 14 | "name": "openmpi", 15 | "platform": "!windows" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /cpp/cmake/post-install/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install( 2 | CODE "MESSAGE( 3 | \"---------------------------------------------------------------------------- 4 | DOLFINx has now been installed in 5 | 6 | ${CMAKE_INSTALL_PREFIX} 7 | 8 | and demo programs have been installed in 9 | 10 | ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/dolfinx/demo 11 | 12 | Don't forget to update your environment variables. This can be done 13 | easily using the helper file 'dolfinx.conf' which sets the appropriate 14 | variables (for users of the Bash shell). 15 | 16 | To update your environment variables, run the following command: 17 | 18 | source ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/dolfinx/dolfinx.conf 19 | 20 | ----------------------------------------------------------------------------\")" 21 | ) 22 | -------------------------------------------------------------------------------- /cpp/cmake/templates/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | message( 3 | FATAL_ERROR 4 | "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"" 5 | ) 6 | endif() 7 | 8 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 9 | string(REGEX REPLACE "\n" ";" files "${files}") 10 | foreach(file ${files}) 11 | message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 12 | if(EXISTS "$ENV{DESTDIR}${file}") 13 | exec_program( 14 | "@CMAKE_COMMAND@" ARGS 15 | "-E remove \"$ENV{DESTDIR}${file}\"" 16 | OUTPUT_VARIABLE rm_out 17 | RETURN_VALUE rm_retval 18 | ) 19 | if(NOT "${rm_retval}" STREQUAL 0) 20 | message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 21 | endif() 22 | else() 23 | message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") 24 | endif() 25 | endforeach() 26 | -------------------------------------------------------------------------------- /cpp/cmake/templates/dolfinx.conf.in: -------------------------------------------------------------------------------- 1 | # Helper file for setting non-default DOLFINx environment variables 2 | 3 | # Common Unix variables 4 | export @OS_LIBRARY_PATH_NAME@=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@:${@OS_LIBRARY_PATH_NAME@:-} 5 | export PATH=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@:${PATH:-} 6 | export PKG_CONFIG_PATH=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/pkgconfig:${PKG_CONFIG_PATH:-} 7 | export CMAKE_PREFIX_PATH=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/cmake:${CMAKE_PREFIX_PATH:-} 8 | 9 | # Special macOS variables 10 | export DYLD_FRAMEWORK_PATH=/opt/local/Library/Frameworks:${DYLD_FRAMEWORK_PATH:-} 11 | -------------------------------------------------------------------------------- /cpp/cmake/templates/dolfinx.pc.in: -------------------------------------------------------------------------------- 1 | # pkg-config configuration for DOLFINx 2 | prefix=@CMAKE_INSTALL_PREFIX@ 3 | exec_prefix=@CMAKE_INSTALL_PREFIX@ 4 | libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ 5 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 6 | compiler=@CMAKE_CXX_COMPILER@ 7 | definitions=@PKG_DEFINITIONS@ 8 | extlibs=@DOLFINX_EXT_LIBS@ 9 | 10 | Name: DOLFINx 11 | Description: Dynamic Object-oriented Library for FINite element computation 12 | Version: @DOLFINX_VERSION@ 13 | Requires: @PKG_REQUIRES@ 14 | Conflicts: 15 | Libs: @PKG_LINKFLAGS@ -L${libdir} -ldolfinx 16 | Cflags: @PKG_CXXFLAGS@ -DDOLFINX_VERSION=\"@DOLFINX_VERSION@\" ${definitions} -I${includedir} @PKG_INCLUDES@ 17 | -------------------------------------------------------------------------------- /cpp/demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project(dolfinx-demos) 3 | 4 | # Find DOLFINx config file 5 | find_package(DOLFINX REQUIRED) 6 | 7 | # Enable testing 8 | enable_testing() 9 | 10 | # Macro to add demos. Some subdirectories might be skipped because demos may not 11 | # be running in both real and complex modes. 12 | macro(add_demo_subdirectory subdir) 13 | if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}) 14 | add_subdirectory(${subdir}) 15 | endif() 16 | endmacro(add_demo_subdirectory) 17 | 18 | # Add demos 19 | add_demo_subdirectory(biharmonic) 20 | add_demo_subdirectory(codim_0_assembly) 21 | add_demo_subdirectory(custom_kernel) 22 | add_demo_subdirectory(hyperelasticity) 23 | add_demo_subdirectory(interpolation-io) 24 | add_demo_subdirectory(interpolation_different_meshes) 25 | add_demo_subdirectory(mixed_poisson) 26 | add_demo_subdirectory(poisson) 27 | add_demo_subdirectory(poisson_matrix_free) 28 | -------------------------------------------------------------------------------- /cpp/demo/README.md: -------------------------------------------------------------------------------- 1 | Documenting DOLFINx demos 2 | ========================= 3 | 4 | The documentation for the DOLFINx demos is written by hand and located 5 | together with the demos in the DOLFINx source tree. To document a (new) 6 | DOLFINx demo located in the directory foo (for instance pde/poisson), 7 | follow the two steps below. In general, the simplest way is probably 8 | to look at one of the documented demos for instance 9 | (demo/pde/poisson/) and follow the same setup. 10 | 11 | 1) Add these 3 files 12 | 13 | * foo/common.txt -- containing common information such as the main 14 | features the demo illustrates and, if applicable, a mathematical 15 | description of the differential equation that is solved. This file 16 | should then be included in the C++ and Python versions. 17 | 18 | * foo/cpp/documentation.rst -- containing the reST source file with 19 | the documentation that is specific to the C++ version of the demo. 20 | 21 | * foo/python/documentation.rst -- containing the reST source file 22 | with the documentation that is specific to the Python version of 23 | the demo. 24 | 25 | If either the C++ or the Python version of the demo does not exist, 26 | feel free to add the version and continue. 27 | 28 | 2) Move the directory foo from the directory undocumented/ to the 29 | suitable directory (for instance pde/ or la/). 30 | 31 | 32 | Note 33 | 34 | The demo documentation is automatically included in the complete 35 | DOLFINx documentation when running make doc after building 36 | DOLFINx. While documenting a demo, it may be handy to only run 37 | make doc_demo and then make doc_html_[python|cpp]. 38 | 39 | Note 40 | 41 | Tests for the validity of the code snippets used in the demo 42 | documentation are included in the standard DOLFINx tests. 43 | 44 | C++ and Python specific contents 45 | ================================ 46 | 47 | The C++ and Python documentation reST source files should 48 | 49 | * Explain each step of the solution procedure. Do this by including 50 | and explaining code snippets from the demo source code. 51 | 52 | * Include links to the API documentation using the :cpp:class: and 53 | :py:class: directives. Note that for the Python classes, the 54 | full module path is required (for instance 55 | py:class:dolfinx.cpp.NewtonSolver) 56 | 57 | * Include the complete set of files needed to run the demo using the 58 | include directive. 59 | -------------------------------------------------------------------------------- /cpp/demo/biharmonic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file was generated by running 2 | # 3 | # python cmake/scripts/generate-cmakefiles from dolfinx/cpp 4 | # 5 | cmake_minimum_required(VERSION 3.21) 6 | 7 | set(PROJECT_NAME demo_biharmonic) 8 | project(${PROJECT_NAME} LANGUAGES C CXX) 9 | 10 | if(NOT TARGET dolfinx) 11 | find_package(DOLFINX REQUIRED) 12 | endif() 13 | 14 | include(CheckSymbolExists) 15 | set(CMAKE_REQUIRED_INCLUDES ${PETSC_INCLUDE_DIRS}) 16 | check_symbol_exists(PETSC_USE_COMPLEX petscsystypes.h PETSC_SCALAR_COMPLEX) 17 | check_symbol_exists(PETSC_USE_REAL_DOUBLE petscsystypes.h PETSC_REAL_DOUBLE) 18 | 19 | # Add target to compile UFL files 20 | if(PETSC_SCALAR_COMPLEX EQUAL 1) 21 | if(PETSC_REAL_DOUBLE EQUAL 1) 22 | set(SCALAR_TYPE "--scalar_type=complex128") 23 | else() 24 | set(SCALAR_TYPE "--scalar_type=complex64") 25 | endif() 26 | else() 27 | if(PETSC_REAL_DOUBLE EQUAL 1) 28 | set(SCALAR_TYPE "--scalar_type=float64") 29 | else() 30 | set(SCALAR_TYPE "--scalar_type=float32") 31 | endif() 32 | endif() 33 | add_custom_command( 34 | OUTPUT biharmonic.c 35 | COMMAND ffcx ${CMAKE_CURRENT_SOURCE_DIR}/biharmonic.py ${SCALAR_TYPE} 36 | VERBATIM 37 | DEPENDS biharmonic.py 38 | COMMENT "Compile biharmonic.py using FFCx" 39 | ) 40 | 41 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 42 | 43 | add_executable(${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/biharmonic.c) 44 | target_link_libraries(${PROJECT_NAME} dolfinx) 45 | 46 | # Set C++20 standard 47 | set(CMAKE_CXX_EXTENSIONS OFF) 48 | target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) 49 | 50 | # Do not throw error for 'multi-line comments' (these are typical in rst which 51 | # includes LaTeX) 52 | include(CheckCXXCompilerFlag) 53 | check_cxx_compiler_flag("-Wno-comment" HAVE_NO_MULTLINE) 54 | set_source_files_properties( 55 | main.cpp 56 | PROPERTIES 57 | COMPILE_FLAGS 58 | "$<$:-Wno-comment -Wall -Wextra -pedantic -Werror>" 59 | ) 60 | 61 | # Test targets (used by DOLFINx testing system) 62 | set(TEST_PARAMETERS2 -np 2 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 63 | set(TEST_PARAMETERS3 -np 3 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 64 | add_test(NAME ${PROJECT_NAME}_mpi_2 COMMAND "mpirun" ${TEST_PARAMETERS2}) 65 | add_test(NAME ${PROJECT_NAME}_mpi_3 COMMAND "mpirun" ${TEST_PARAMETERS3}) 66 | add_test(NAME ${PROJECT_NAME}_serial COMMAND ${PROJECT_NAME}) 67 | -------------------------------------------------------------------------------- /cpp/demo/biharmonic/biharmonic.py: -------------------------------------------------------------------------------- 1 | # The first step is to define the variational problem at hand. We define 2 | # the variational problem in UFL terms in a separate form file. We begin 3 | # by defining the finite element: 4 | 5 | from basix.ufl import element 6 | from ufl import ( 7 | CellDiameter, 8 | Coefficient, 9 | Constant, 10 | FacetNormal, 11 | FunctionSpace, 12 | Mesh, 13 | TestFunction, 14 | TrialFunction, 15 | avg, 16 | div, 17 | dS, 18 | dx, 19 | grad, 20 | inner, 21 | jump, 22 | ) 23 | 24 | e = element("Lagrange", "triangle", 2) 25 | 26 | # The first argument to :py:class:`FiniteElement` is the finite element 27 | # family, the second argument specifies the domain, while the third 28 | # argument specifies the polynomial degree. Thus, in this case, our 29 | # element `element` consists of second-order, continuous Lagrange basis 30 | # functions on triangles (or in order words, continuous piecewise linear 31 | # polynomials on triangles). 32 | # 33 | # Next, we use this element to initialize the trial and test functions 34 | # ($u$ and $v$) and the coefficient function $f$: 35 | 36 | coord_element = element("Lagrange", "triangle", 1, shape=(2,)) 37 | mesh = Mesh(coord_element) 38 | 39 | V = FunctionSpace(mesh, e) 40 | 41 | u = TrialFunction(V) 42 | v = TestFunction(V) 43 | f = Coefficient(V) 44 | 45 | # Next, the outward unit normal to cell boundaries and a measure of the 46 | # cell size are defined. The average size of cells sharing a facet will 47 | # be used (`h_avg`). The UFL syntax `('+')` and `('-')` restricts a 48 | # function to the `('+')` and `('-')` sides of a facet, respectively. 49 | # The penalty parameter `alpha` is made a :cpp:class:`Constant` so 50 | # that it can be changed in the program without regenerating the code. 51 | 52 | # Normal component, mesh size and right-hand side 53 | n = FacetNormal(mesh) 54 | h = CellDiameter(mesh) 55 | h_avg = (h("+") + h("-")) / 2 56 | alpha = Constant(mesh) 57 | 58 | # Finally, we define the bilinear and linear forms according to the 59 | # variational formulation of the equations. Integrals over 60 | # internal facets are indicated by `*dS`. 61 | 62 | # Bilinear form 63 | a = ( 64 | inner(div(grad(u)), div(grad(v))) * dx 65 | - inner(avg(div(grad(u))), jump(grad(v), n)) * dS 66 | - inner(jump(grad(u), n), avg(div(grad(v)))) * dS 67 | + alpha / h_avg * inner(jump(grad(u), n), jump(grad(v), n)) * dS 68 | ) 69 | 70 | # Linear form 71 | L = inner(f, v) * dx 72 | -------------------------------------------------------------------------------- /cpp/demo/codim_0_assembly/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file was generated by running 2 | # 3 | # python cmake/scripts/generate-cmakefiles from dolfinx/cpp 4 | # 5 | cmake_minimum_required(VERSION 3.21) 6 | 7 | set(PROJECT_NAME demo_codim_0_assembly) 8 | project(${PROJECT_NAME} LANGUAGES C CXX) 9 | 10 | if(NOT TARGET dolfinx) 11 | find_package(DOLFINX REQUIRED) 12 | endif() 13 | 14 | include(CheckSymbolExists) 15 | set(CMAKE_REQUIRED_INCLUDES ${PETSC_INCLUDE_DIRS}) 16 | check_symbol_exists(PETSC_USE_COMPLEX petscsystypes.h PETSC_SCALAR_COMPLEX) 17 | check_symbol_exists(PETSC_USE_REAL_DOUBLE petscsystypes.h PETSC_REAL_DOUBLE) 18 | 19 | # Add target to compile UFL files 20 | if(PETSC_SCALAR_COMPLEX EQUAL 1) 21 | if(PETSC_REAL_DOUBLE EQUAL 1) 22 | set(SCALAR_TYPE "--scalar_type=complex128") 23 | else() 24 | set(SCALAR_TYPE "--scalar_type=complex64") 25 | endif() 26 | else() 27 | if(PETSC_REAL_DOUBLE EQUAL 1) 28 | set(SCALAR_TYPE "--scalar_type=float64") 29 | else() 30 | set(SCALAR_TYPE "--scalar_type=float32") 31 | endif() 32 | endif() 33 | add_custom_command( 34 | OUTPUT mixed_codim0.c 35 | COMMAND ffcx ${CMAKE_CURRENT_SOURCE_DIR}/mixed_codim0.py ${SCALAR_TYPE} 36 | VERBATIM 37 | DEPENDS mixed_codim0.py 38 | COMMENT "Compile mixed_codim0.py using FFCx" 39 | ) 40 | 41 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 42 | 43 | add_executable(${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/mixed_codim0.c) 44 | target_link_libraries(${PROJECT_NAME} dolfinx) 45 | 46 | # Set C++20 standard 47 | set(CMAKE_CXX_EXTENSIONS OFF) 48 | target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) 49 | 50 | # Do not throw error for 'multi-line comments' (these are typical in rst which 51 | # includes LaTeX) 52 | include(CheckCXXCompilerFlag) 53 | check_cxx_compiler_flag("-Wno-comment" HAVE_NO_MULTLINE) 54 | set_source_files_properties( 55 | main.cpp 56 | PROPERTIES 57 | COMPILE_FLAGS 58 | "$<$:-Wno-comment -Wall -Wextra -pedantic -Werror>" 59 | ) 60 | 61 | # Test targets (used by DOLFINx testing system) 62 | set(TEST_PARAMETERS2 -np 2 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 63 | set(TEST_PARAMETERS3 -np 3 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 64 | add_test(NAME ${PROJECT_NAME}_mpi_2 COMMAND "mpirun" ${TEST_PARAMETERS2}) 65 | add_test(NAME ${PROJECT_NAME}_mpi_3 COMMAND "mpirun" ${TEST_PARAMETERS3}) 66 | add_test(NAME ${PROJECT_NAME}_serial COMMAND ${PROJECT_NAME}) 67 | -------------------------------------------------------------------------------- /cpp/demo/codim_0_assembly/mixed_codim0.py: -------------------------------------------------------------------------------- 1 | # This demo aims to illustrate how to assemble a matrix with a trial function 2 | # defined on a submesh of co-dimension 0, and a test function defined on the parent mesh 3 | from basix.ufl import element 4 | from ufl import ( 5 | FunctionSpace, 6 | Mesh, 7 | TestFunction, 8 | TrialFunction, 9 | dx, 10 | inner, 11 | ) 12 | 13 | cell = "quadrilateral" 14 | coord_element = element("Lagrange", cell, 1, shape=(2,)) 15 | mesh = Mesh(coord_element) 16 | 17 | # We define the function space and test function on the full mesh 18 | e = element("Lagrange", cell, 1) 19 | V = FunctionSpace(mesh, e) 20 | v = TestFunction(V) 21 | 22 | # Next we define the sub-mesh 23 | submesh = Mesh(coord_element) 24 | W = FunctionSpace(submesh, e) 25 | p = TrialFunction(W) 26 | 27 | # And finally we define a "mass matrix" on the submesh, with the test function 28 | # of the parent mesh. The integration domain is the parent mesh, but we restrict integration 29 | # to all cells marked with subdomain_id=3, which will indicate what cells of our mesh is part 30 | # of the submesh 31 | a_mixed = inner(p, v) * dx(domain=mesh, subdomain_id=3) 32 | 33 | q = TestFunction(W) 34 | a = inner(p, q) * dx(domain=submesh) 35 | 36 | forms = [a_mixed, a] 37 | -------------------------------------------------------------------------------- /cpp/demo/custom_kernel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file was generated by running 2 | # 3 | # python cmake/scripts/generate-cmakefiles.py from dolfinx/cpp 4 | # 5 | cmake_minimum_required(VERSION 3.21) 6 | 7 | set(PROJECT_NAME demo_custom_kernel) 8 | project(${PROJECT_NAME} LANGUAGES C CXX) 9 | 10 | if(NOT TARGET dolfinx) 11 | find_package(DOLFINX REQUIRED) 12 | endif() 13 | 14 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 15 | 16 | add_executable(${PROJECT_NAME} main.cpp) 17 | target_link_libraries(${PROJECT_NAME} dolfinx) 18 | 19 | # Set C++20 standard 20 | set(CMAKE_CXX_EXTENSIONS OFF) 21 | target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) 22 | 23 | # Do not throw error for 'multi-line comments' (these are typical in rst which 24 | # includes LaTeX) 25 | include(CheckCXXCompilerFlag) 26 | check_cxx_compiler_flag("-Wno-comment" HAVE_NO_MULTLINE) 27 | set_source_files_properties( 28 | main.cpp 29 | PROPERTIES 30 | COMPILE_FLAGS 31 | "$<$:-Wno-comment -Wall -Wextra -pedantic -Werror>" 32 | ) 33 | 34 | # Test targets (used by DOLFINx testing system) 35 | set(TEST_PARAMETERS2 -np 2 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 36 | set(TEST_PARAMETERS3 -np 3 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 37 | add_test(NAME ${PROJECT_NAME}_mpi_2 COMMAND "mpirun" ${TEST_PARAMETERS2}) 38 | add_test(NAME ${PROJECT_NAME}_mpi_3 COMMAND "mpirun" ${TEST_PARAMETERS3}) 39 | add_test(NAME ${PROJECT_NAME}_serial COMMAND ${PROJECT_NAME}) 40 | -------------------------------------------------------------------------------- /cpp/demo/hyperelasticity/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file was generated by running 2 | # 3 | # python cmake/scripts/generate-cmakefiles from dolfinx/cpp 4 | # 5 | cmake_minimum_required(VERSION 3.21) 6 | 7 | set(PROJECT_NAME demo_hyperelasticity) 8 | project(${PROJECT_NAME} LANGUAGES C CXX) 9 | 10 | if(NOT TARGET dolfinx) 11 | find_package(DOLFINX REQUIRED) 12 | endif() 13 | 14 | include(CheckSymbolExists) 15 | set(CMAKE_REQUIRED_INCLUDES ${PETSC_INCLUDE_DIRS}) 16 | check_symbol_exists(PETSC_USE_COMPLEX petscsystypes.h PETSC_SCALAR_COMPLEX) 17 | if(PETSC_SCALAR_COMPLEX EQUAL 1) 18 | message(STATUS "** This demo does not support complex mode") 19 | else() 20 | check_symbol_exists(PETSC_USE_REAL_DOUBLE petscsystypes.h PETSC_REAL_DOUBLE) 21 | if(PETSC_REAL_DOUBLE EQUAL 1) 22 | set(SCALAR_TYPE "--scalar_type=float64") 23 | else() 24 | set(SCALAR_TYPE "--scalar_type=float32") 25 | endif() 26 | 27 | # Add target to compile UFL files 28 | add_custom_command( 29 | OUTPUT hyperelasticity.c 30 | COMMAND ffcx ${CMAKE_CURRENT_SOURCE_DIR}/hyperelasticity.py ${SCALAR_TYPE} 31 | VERBATIM 32 | DEPENDS hyperelasticity.py 33 | COMMENT "Compile hyperelasticity.py using FFCx" 34 | ) 35 | 36 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 37 | 38 | add_executable(${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/hyperelasticity.c) 39 | target_link_libraries(${PROJECT_NAME} dolfinx) 40 | 41 | # Set C++20 standard 42 | target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) 43 | set(CMAKE_CXX_EXTENSIONS OFF) 44 | 45 | # Do not throw error for 'multi-line comments' (these are typical in rst which 46 | # includes LaTeX) 47 | include(CheckCXXCompilerFlag) 48 | check_cxx_compiler_flag("-Wno-comment" HAVE_NO_MULTLINE) 49 | set_source_files_properties( 50 | main.cpp 51 | PROPERTIES 52 | COMPILE_FLAGS 53 | "$<$:-Wno-comment -Wall -Wextra -pedantic -Werror>" 54 | ) 55 | 56 | # Test targets (used by DOLFINx testing system) 57 | set(TEST_PARAMETERS2 -np 2 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 58 | set(TEST_PARAMETERS3 -np 3 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 59 | add_test(NAME ${PROJECT_NAME}_mpi_2 COMMAND "mpirun" ${TEST_PARAMETERS2}) 60 | add_test(NAME ${PROJECT_NAME}_mpi_3 COMMAND "mpirun" ${TEST_PARAMETERS3}) 61 | add_test(NAME ${PROJECT_NAME}_serial COMMAND ${PROJECT_NAME}) 62 | endif() 63 | -------------------------------------------------------------------------------- /cpp/demo/hyperelasticity/hyperelasticity.py: -------------------------------------------------------------------------------- 1 | # The first step is to define the variational problem at hand. 2 | # 3 | # We are interested in solving for a discrete vector field in three 4 | # dimensions, so first we need the appropriate finite element space and 5 | # trial and test functions on this space: 6 | 7 | from basix.ufl import element 8 | from ufl import ( 9 | Coefficient, 10 | Constant, 11 | FunctionSpace, 12 | Identity, 13 | Mesh, 14 | TestFunction, 15 | TrialFunction, 16 | derivative, 17 | det, 18 | diff, 19 | ds, 20 | dx, 21 | grad, 22 | inner, 23 | ln, 24 | tr, 25 | variable, 26 | ) 27 | 28 | # Function spaces 29 | e = element("Lagrange", "tetrahedron", 1, shape=(3,)) 30 | mesh = Mesh(e) 31 | V = FunctionSpace(mesh, e) 32 | 33 | # Trial and test functions 34 | du = TrialFunction(V) # Incremental displacement 35 | v = TestFunction(V) # Test function 36 | 37 | # Note that `element` with `shape=(3,)` creates a finite element space 38 | # of vector fields. 39 | # 40 | # Next, we will be needing functions for the boundary source `B`, the 41 | # traction `T` and the displacement solution itself `u`: 42 | 43 | # Functions 44 | u = Coefficient(V) # Displacement from previous iteration 45 | B = Constant(mesh, shape=(3,)) # Body force per unit volume 46 | T = Constant(mesh, shape=(3,)) # Traction force on the boundary 47 | 48 | # Now, we can define the kinematic quantities involved in the model: 49 | 50 | # Kinematics 51 | d = len(u) 52 | I = Identity(d) # Identity tensor # noqa: E741 53 | F = variable(I + grad(u)) # Deformation gradient 54 | C = F.T * F # Right Cauchy-Green tensor 55 | 56 | # Invariants of deformation tensors 57 | Ic = tr(C) 58 | J = det(F) 59 | 60 | # Before defining the energy density and thus the total potential 61 | # energy, it only remains to specify constants for the elasticity 62 | # parameters: 63 | 64 | # Elasticity parameters 65 | E = 10.0 66 | nu = 0.3 67 | mu = E / (2 * (1 + nu)) 68 | lmbda = E * nu / ((1 + nu) * (1 - 2 * nu)) 69 | 70 | # Both the first variation of the potential energy, and the Jacobian of 71 | # the variation, can be automatically computed by a call to 72 | # `derivative`: 73 | 74 | # Stored strain energy density (compressible neo-Hookean model) 75 | psi = (mu / 2) * (Ic - 3) - mu * ln(J) + (lmbda / 2) * (ln(J)) ** 2 76 | 77 | # Total potential energy 78 | Pi = psi * dx - inner(B, u) * dx - inner(T, u) * ds 79 | 80 | # First variation of Pi (directional derivative about u in the direction 81 | # of v) 82 | F_form = derivative(Pi, u, v) 83 | 84 | # Compute Jacobian of F 85 | J_form = derivative(F_form, u, du) 86 | 87 | # Compute Cauchy stress 88 | sigma = (1 / J) * diff(psi, F) * F.T 89 | 90 | forms = [F_form, J_form] 91 | elements = [e] 92 | expressions = [(sigma, [[0.25, 0.25, 0.25]])] 93 | -------------------------------------------------------------------------------- /cpp/demo/interpolation-io/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file was generated by running 2 | # 3 | # python cmake/scripts/generate-cmakefiles.py from dolfinx/cpp 4 | # 5 | cmake_minimum_required(VERSION 3.21) 6 | 7 | set(PROJECT_NAME demo_interpolation-io) 8 | project(${PROJECT_NAME} LANGUAGES C CXX) 9 | 10 | if(NOT TARGET dolfinx) 11 | find_package(DOLFINX REQUIRED) 12 | endif() 13 | 14 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 15 | 16 | add_executable(${PROJECT_NAME} main.cpp) 17 | target_link_libraries(${PROJECT_NAME} dolfinx) 18 | 19 | # Set C++20 standard 20 | set(CMAKE_CXX_EXTENSIONS OFF) 21 | target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) 22 | 23 | # Do not throw error for 'multi-line comments' (these are typical in rst which 24 | # includes LaTeX) 25 | include(CheckCXXCompilerFlag) 26 | check_cxx_compiler_flag("-Wno-comment" HAVE_NO_MULTLINE) 27 | set_source_files_properties( 28 | main.cpp 29 | PROPERTIES 30 | COMPILE_FLAGS 31 | "$<$:-Wno-comment -Wall -Wextra -pedantic -Werror>" 32 | ) 33 | 34 | # Test targets (used by DOLFINx testing system) 35 | set(TEST_PARAMETERS2 -np 2 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 36 | set(TEST_PARAMETERS3 -np 3 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 37 | add_test(NAME ${PROJECT_NAME}_mpi_2 COMMAND "mpirun" ${TEST_PARAMETERS2}) 38 | add_test(NAME ${PROJECT_NAME}_mpi_3 COMMAND "mpirun" ${TEST_PARAMETERS3}) 39 | add_test(NAME ${PROJECT_NAME}_serial COMMAND ${PROJECT_NAME}) 40 | -------------------------------------------------------------------------------- /cpp/demo/interpolation_different_meshes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file was generated by running 2 | # 3 | # python cmake/scripts/generate-cmakefiles.py from dolfinx/cpp 4 | # 5 | cmake_minimum_required(VERSION 3.21) 6 | 7 | set(PROJECT_NAME demo_interpolation_different_meshes) 8 | project(${PROJECT_NAME} LANGUAGES C CXX) 9 | 10 | if(NOT TARGET dolfinx) 11 | find_package(DOLFINX REQUIRED) 12 | endif() 13 | 14 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 15 | 16 | add_executable(${PROJECT_NAME} main.cpp) 17 | target_link_libraries(${PROJECT_NAME} dolfinx) 18 | 19 | # Set C++20 standard 20 | set(CMAKE_CXX_EXTENSIONS OFF) 21 | target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) 22 | 23 | # Do not throw error for 'multi-line comments' (these are typical in rst which 24 | # includes LaTeX) 25 | include(CheckCXXCompilerFlag) 26 | check_cxx_compiler_flag("-Wno-comment" HAVE_NO_MULTLINE) 27 | set_source_files_properties( 28 | main.cpp 29 | PROPERTIES 30 | COMPILE_FLAGS 31 | "$<$:-Wno-comment -Wall -Wextra -pedantic -Werror>" 32 | ) 33 | 34 | # Test targets (used by DOLFINx testing system) 35 | set(TEST_PARAMETERS2 -np 2 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 36 | set(TEST_PARAMETERS3 -np 3 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 37 | add_test(NAME ${PROJECT_NAME}_mpi_2 COMMAND "mpirun" ${TEST_PARAMETERS2}) 38 | add_test(NAME ${PROJECT_NAME}_mpi_3 COMMAND "mpirun" ${TEST_PARAMETERS3}) 39 | add_test(NAME ${PROJECT_NAME}_serial COMMAND ${PROJECT_NAME}) 40 | -------------------------------------------------------------------------------- /cpp/demo/mixed_poisson/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file was generated by running 2 | # 3 | # python cmake/scripts/generate-cmakefiles from dolfinx/cpp 4 | # 5 | cmake_minimum_required(VERSION 3.21) 6 | 7 | set(PROJECT_NAME demo_mixed_poisson) 8 | project(${PROJECT_NAME} LANGUAGES C CXX) 9 | 10 | if(NOT TARGET dolfinx) 11 | find_package(DOLFINX REQUIRED) 12 | endif() 13 | 14 | include(CheckSymbolExists) 15 | set(CMAKE_REQUIRED_INCLUDES ${PETSC_INCLUDE_DIRS}) 16 | check_symbol_exists(PETSC_USE_COMPLEX petscsystypes.h PETSC_SCALAR_COMPLEX) 17 | check_symbol_exists(PETSC_USE_REAL_DOUBLE petscsystypes.h PETSC_REAL_DOUBLE) 18 | 19 | # Add target to compile UFL files 20 | if(PETSC_SCALAR_COMPLEX EQUAL 1) 21 | if(PETSC_REAL_DOUBLE EQUAL 1) 22 | set(SCALAR_TYPE "--scalar_type=complex128") 23 | else() 24 | set(SCALAR_TYPE "--scalar_type=complex64") 25 | endif() 26 | else() 27 | if(PETSC_REAL_DOUBLE EQUAL 1) 28 | set(SCALAR_TYPE "--scalar_type=float64") 29 | else() 30 | set(SCALAR_TYPE "--scalar_type=float32") 31 | endif() 32 | endif() 33 | add_custom_command( 34 | OUTPUT mixed_poisson.c 35 | COMMAND ffcx ${CMAKE_CURRENT_SOURCE_DIR}/mixed_poisson.py ${SCALAR_TYPE} 36 | VERBATIM 37 | DEPENDS mixed_poisson.py 38 | COMMENT "Compile mixed_poisson.py using FFCx" 39 | ) 40 | 41 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 42 | 43 | add_executable(${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/mixed_poisson.c) 44 | target_link_libraries(${PROJECT_NAME} dolfinx) 45 | 46 | # Set C++20 standard 47 | set(CMAKE_CXX_EXTENSIONS OFF) 48 | target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) 49 | 50 | # Do not throw error for 'multi-line comments' (these are typical in rst which 51 | # includes LaTeX) 52 | include(CheckCXXCompilerFlag) 53 | check_cxx_compiler_flag("-Wno-comment" HAVE_NO_MULTLINE) 54 | set_source_files_properties( 55 | main.cpp 56 | PROPERTIES 57 | COMPILE_FLAGS 58 | "$<$:-Wno-comment -Wall -Wextra -pedantic -Werror>" 59 | ) 60 | 61 | # Test targets (used by DOLFINx testing system) 62 | set(TEST_PARAMETERS2 -np 2 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 63 | set(TEST_PARAMETERS3 -np 3 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 64 | add_test(NAME ${PROJECT_NAME}_mpi_2 COMMAND "mpirun" ${TEST_PARAMETERS2}) 65 | add_test(NAME ${PROJECT_NAME}_mpi_3 COMMAND "mpirun" ${TEST_PARAMETERS3}) 66 | add_test(NAME ${PROJECT_NAME}_serial COMMAND ${PROJECT_NAME}) 67 | -------------------------------------------------------------------------------- /cpp/demo/mixed_poisson/mixed_poisson.py: -------------------------------------------------------------------------------- 1 | # The first step is to define the variational problem at hand. We define 2 | # the variational problem in UFL terms in a separate form file 3 | # {download}`demo_mixed_poisson/mixed_poisson.py`. We begin by defining the 4 | # finite element: 5 | 6 | from basix.ufl import element, mixed_element 7 | from ufl import ( 8 | Coefficient, 9 | FacetNormal, 10 | FunctionSpace, 11 | Measure, 12 | Mesh, 13 | TestFunctions, 14 | TrialFunctions, 15 | div, 16 | inner, 17 | ) 18 | 19 | shape = "triangle" 20 | RT = element("RT", shape, 1) 21 | P = element("DP", shape, 0) 22 | ME = mixed_element([RT, P]) 23 | 24 | msh = Mesh(element("Lagrange", shape, 1, shape=(2,))) 25 | n = FacetNormal(msh) 26 | V = FunctionSpace(msh, ME) 27 | 28 | (sigma, u) = TrialFunctions(V) 29 | (tau, v) = TestFunctions(V) 30 | 31 | V0 = FunctionSpace(msh, P) 32 | f = Coefficient(V0) 33 | u0 = Coefficient(V0) 34 | 35 | dx = Measure("dx", msh) 36 | ds = Measure("ds", msh) 37 | a = inner(sigma, tau) * dx + inner(u, div(tau)) * dx + inner(div(sigma), v) * dx 38 | L = -inner(f, v) * dx + inner(u0 * n, tau) * ds(1) 39 | -------------------------------------------------------------------------------- /cpp/demo/poisson/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file was generated by running 2 | # 3 | # python cmake/scripts/generate-cmakefiles from dolfinx/cpp 4 | # 5 | cmake_minimum_required(VERSION 3.21) 6 | 7 | set(PROJECT_NAME demo_poisson) 8 | project(${PROJECT_NAME} LANGUAGES C CXX) 9 | 10 | if(NOT TARGET dolfinx) 11 | find_package(DOLFINX REQUIRED) 12 | endif() 13 | 14 | include(CheckSymbolExists) 15 | set(CMAKE_REQUIRED_INCLUDES ${PETSC_INCLUDE_DIRS}) 16 | check_symbol_exists(PETSC_USE_COMPLEX petscsystypes.h PETSC_SCALAR_COMPLEX) 17 | check_symbol_exists(PETSC_USE_REAL_DOUBLE petscsystypes.h PETSC_REAL_DOUBLE) 18 | 19 | # Add target to compile UFL files 20 | if(PETSC_SCALAR_COMPLEX EQUAL 1) 21 | if(PETSC_REAL_DOUBLE EQUAL 1) 22 | set(SCALAR_TYPE "--scalar_type=complex128") 23 | else() 24 | set(SCALAR_TYPE "--scalar_type=complex64") 25 | endif() 26 | else() 27 | if(PETSC_REAL_DOUBLE EQUAL 1) 28 | set(SCALAR_TYPE "--scalar_type=float64") 29 | else() 30 | set(SCALAR_TYPE "--scalar_type=float32") 31 | endif() 32 | endif() 33 | add_custom_command( 34 | OUTPUT poisson.c 35 | COMMAND ffcx ${CMAKE_CURRENT_SOURCE_DIR}/poisson.py ${SCALAR_TYPE} 36 | VERBATIM 37 | DEPENDS poisson.py 38 | COMMENT "Compile poisson.py using FFCx" 39 | ) 40 | 41 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 42 | 43 | add_executable(${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/poisson.c) 44 | target_link_libraries(${PROJECT_NAME} dolfinx) 45 | 46 | # Set C++20 standard 47 | set(CMAKE_CXX_EXTENSIONS OFF) 48 | target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) 49 | 50 | # Do not throw error for 'multi-line comments' (these are typical in rst which 51 | # includes LaTeX) 52 | include(CheckCXXCompilerFlag) 53 | check_cxx_compiler_flag("-Wno-comment" HAVE_NO_MULTLINE) 54 | set_source_files_properties( 55 | main.cpp 56 | PROPERTIES 57 | COMPILE_FLAGS 58 | "$<$:-Wno-comment -Wall -Wextra -pedantic -Werror>" 59 | ) 60 | 61 | # Test targets (used by DOLFINx testing system) 62 | set(TEST_PARAMETERS2 -np 2 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 63 | set(TEST_PARAMETERS3 -np 3 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 64 | add_test(NAME ${PROJECT_NAME}_mpi_2 COMMAND "mpirun" ${TEST_PARAMETERS2}) 65 | add_test(NAME ${PROJECT_NAME}_mpi_3 COMMAND "mpirun" ${TEST_PARAMETERS3}) 66 | add_test(NAME ${PROJECT_NAME}_serial COMMAND ${PROJECT_NAME}) 67 | -------------------------------------------------------------------------------- /cpp/demo/poisson/poisson.py: -------------------------------------------------------------------------------- 1 | # The first step is to define the variational problem at hand. We define 2 | # the variational problem in UFL terms in a separate form file 3 | # {download}`demo_poisson/poisson.py`. We begin by defining the finite 4 | # element: 5 | 6 | from basix.ufl import element 7 | from ufl import ( 8 | Coefficient, 9 | Constant, 10 | FunctionSpace, 11 | Mesh, 12 | TestFunction, 13 | TrialFunction, 14 | ds, 15 | dx, 16 | grad, 17 | inner, 18 | ) 19 | 20 | e = element("Lagrange", "triangle", 1) 21 | 22 | # The first argument to :py:class:`FiniteElement` is the finite element 23 | # family, the second argument specifies the domain, while the third 24 | # argument specifies the polynomial degree. Thus, in this case, our 25 | # element `element` consists of first-order, continuous Lagrange basis 26 | # functions on triangles (or in order words, continuous piecewise linear 27 | # polynomials on triangles). 28 | # 29 | # Next, we use this element to initialize the trial and test functions 30 | # ($u$ and $v$) and the coefficient functions ($f$ and $g$): 31 | 32 | coord_element = element("Lagrange", "triangle", 1, shape=(2,)) 33 | mesh = Mesh(coord_element) 34 | 35 | V = FunctionSpace(mesh, e) 36 | 37 | u = TrialFunction(V) 38 | v = TestFunction(V) 39 | f = Coefficient(V) 40 | g = Coefficient(V) 41 | kappa = Constant(mesh) 42 | 43 | # Finally, we define the bilinear and linear forms according to the 44 | # variational formulation of the equations: 45 | 46 | a = kappa * inner(grad(u), grad(v)) * dx 47 | L = inner(f, v) * dx + inner(g, v) * ds 48 | -------------------------------------------------------------------------------- /cpp/demo/poisson_matrix_free/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file was generated by running 2 | # 3 | # python cmake/scripts/generate-cmakefiles from dolfinx/cpp 4 | # 5 | cmake_minimum_required(VERSION 3.21) 6 | 7 | set(PROJECT_NAME demo_poisson_matrix_free) 8 | project(${PROJECT_NAME} LANGUAGES C CXX) 9 | 10 | if(NOT TARGET dolfinx) 11 | find_package(DOLFINX REQUIRED) 12 | endif() 13 | 14 | include(CheckSymbolExists) 15 | set(CMAKE_REQUIRED_INCLUDES ${PETSC_INCLUDE_DIRS}) 16 | check_symbol_exists(PETSC_USE_COMPLEX petscsystypes.h PETSC_SCALAR_COMPLEX) 17 | check_symbol_exists(PETSC_USE_REAL_DOUBLE petscsystypes.h PETSC_REAL_DOUBLE) 18 | 19 | # Add target to compile UFL files 20 | if(PETSC_SCALAR_COMPLEX EQUAL 1) 21 | if(PETSC_REAL_DOUBLE EQUAL 1) 22 | set(SCALAR_TYPE "--scalar_type=complex128") 23 | else() 24 | set(SCALAR_TYPE "--scalar_type=complex64") 25 | endif() 26 | else() 27 | if(PETSC_REAL_DOUBLE EQUAL 1) 28 | set(SCALAR_TYPE "--scalar_type=float64") 29 | else() 30 | set(SCALAR_TYPE "--scalar_type=float32") 31 | endif() 32 | endif() 33 | add_custom_command( 34 | OUTPUT poisson.c 35 | COMMAND ffcx ${CMAKE_CURRENT_SOURCE_DIR}/poisson.py ${SCALAR_TYPE} 36 | VERBATIM 37 | DEPENDS poisson.py 38 | COMMENT "Compile poisson.py using FFCx" 39 | ) 40 | 41 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 42 | 43 | add_executable(${PROJECT_NAME} main.cpp ${CMAKE_CURRENT_BINARY_DIR}/poisson.c) 44 | target_link_libraries(${PROJECT_NAME} dolfinx) 45 | 46 | # Set C++20 standard 47 | set(CMAKE_CXX_EXTENSIONS OFF) 48 | target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) 49 | 50 | # Do not throw error for 'multi-line comments' (these are typical in rst which 51 | # includes LaTeX) 52 | include(CheckCXXCompilerFlag) 53 | check_cxx_compiler_flag("-Wno-comment" HAVE_NO_MULTLINE) 54 | set_source_files_properties( 55 | main.cpp 56 | PROPERTIES 57 | COMPILE_FLAGS 58 | "$<$:-Wno-comment -Wall -Wextra -pedantic -Werror>" 59 | ) 60 | 61 | # Test targets (used by DOLFINx testing system) 62 | set(TEST_PARAMETERS2 -np 2 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 63 | set(TEST_PARAMETERS3 -np 3 ${MPIEXEC_PARAMS} "./${PROJECT_NAME}") 64 | add_test(NAME ${PROJECT_NAME}_mpi_2 COMMAND "mpirun" ${TEST_PARAMETERS2}) 65 | add_test(NAME ${PROJECT_NAME}_mpi_3 COMMAND "mpirun" ${TEST_PARAMETERS3}) 66 | add_test(NAME ${PROJECT_NAME}_serial COMMAND ${PROJECT_NAME}) 67 | -------------------------------------------------------------------------------- /cpp/demo/poisson_matrix_free/poisson.py: -------------------------------------------------------------------------------- 1 | # UFL input for the Matrix-free Poisson Demo 2 | 3 | from basix.ufl import element 4 | from ufl import ( 5 | Coefficient, 6 | Constant, 7 | FunctionSpace, 8 | Mesh, 9 | TestFunction, 10 | TrialFunction, 11 | action, 12 | dx, 13 | grad, 14 | inner, 15 | ) 16 | 17 | coord_element = element("Lagrange", "triangle", 1, shape=(2,)) 18 | mesh = Mesh(coord_element) 19 | 20 | # Function Space 21 | e = element("Lagrange", "triangle", 2) 22 | V = FunctionSpace(mesh, e) 23 | 24 | # Trial and test functions 25 | u = TrialFunction(V) 26 | v = TestFunction(V) 27 | 28 | # Constant RHS 29 | f = Constant(V) 30 | 31 | # Bilinear and linear forms according to the variational 32 | # formulation of the equations: 33 | a = inner(grad(u), grad(v)) * dx 34 | L = inner(f, v) * dx 35 | 36 | # Linear form representing the action of the form `a`` on the 37 | # coefficient `ui`:` 38 | ui = Coefficient(V) 39 | M = action(a, ui) 40 | 41 | # Form to compute the L2 norm of the error 42 | usol = Coefficient(V) 43 | uexact = Coefficient(V) 44 | E = inner(usol - uexact, usol - uexact) * dx 45 | 46 | forms = [M, L, E] 47 | -------------------------------------------------------------------------------- /cpp/doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | # SPHINXOPTS = -W 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = FEniCSProject 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /cpp/doc/README.md: -------------------------------------------------------------------------------- 1 | # DOLFINx C++ interface documentation 2 | 3 | The C++ API documentation is generated from the source code using 4 | [Doxygen](https://www.doxygen.nl/), and the Doxygen output is curated 5 | and rendered using reStructured text with 6 | [Sphinx](https://www.sphinx-doc.org/) and 7 | [Breathe](https://breathe.readthedocs.io/). 8 | 9 | 10 | ## Requirements 11 | 12 | - [Doxygen](https://www.doxygen.nl/) 13 | - [Sphinx](https://www.sphinx-doc.org/) 14 | - [Breathe](https://breathe.readthedocs.io/) 15 | 16 | 17 | ## Building 18 | 19 | ```bash 20 | > doxygen Doxyfile 21 | > make html 22 | ``` 23 | 24 | Sphinx/Breathe documentation is in `build/html`and the Doxygen generated 25 | HTML is in `html/`. 26 | -------------------------------------------------------------------------------- /cpp/doc/source/api.rst: -------------------------------------------------------------------------------- 1 | API documentation 2 | ================= 3 | 4 | This is experimental documentation for the C++ API. The full Doxygen 5 | generated documentation is `here `_. 6 | 7 | .. toctree:: 8 | :maxdepth: 1 9 | 10 | common 11 | geometry 12 | graph 13 | fem 14 | io 15 | la 16 | mesh 17 | refinement 18 | 19 | * :ref:`genindex` 20 | 21 | 22 | .. See https://github.com/sphinx-doc/sphinx/issues/10152 23 | -------------------------------------------------------------------------------- /cpp/doc/source/common.rst: -------------------------------------------------------------------------------- 1 | Common (``dolfinx::common``) 2 | ============================ 3 | 4 | .. doxygennamespace:: dolfinx::common 5 | :project: DOLFINx 6 | :members: -------------------------------------------------------------------------------- /cpp/doc/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | 13 | import os 14 | import sys 15 | 16 | sys.path.insert(0, os.path.abspath(".")) 17 | 18 | import jupytext_process # isort:skip 19 | 20 | 21 | myst_heading_anchors = 3 22 | 23 | jupytext_process.process() 24 | 25 | # -- Project information ----------------------------------------------------- 26 | 27 | project = "DOLFINx" 28 | copyright = "2022, FEniCS Project" 29 | author = "FEniCS Project" 30 | 31 | # TODO: automate version tagging? 32 | # The full version, including alpha/beta/rc tags 33 | release = "0.3.1" 34 | 35 | 36 | # -- General configuration --------------------------------------------------- 37 | 38 | # Add any Sphinx extension module names here, as strings. They can be 39 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 40 | # ones. 41 | extensions = [ 42 | "sphinx.ext.mathjax", 43 | "myst_parser", 44 | "breathe", 45 | ] 46 | 47 | # Add any paths that contain templates here, relative to this directory. 48 | templates_path = ["_templates"] 49 | 50 | source_suffix = {".rst": "restructuredtext", ".md": "markdown"} 51 | 52 | # List of patterns, relative to source directory, that match files and 53 | # directories to ignore when looking for source files. 54 | # This pattern also affects html_static_path and html_extra_path. 55 | exclude_patterns = [] 56 | 57 | # -- Options for HTML output ------------------------------------------------- 58 | 59 | # The theme to use for HTML and HTML Help pages. See the documentation for 60 | # a list of builtin themes. 61 | # 62 | # html_theme = 'alabaster' 63 | # html_theme = "nature" 64 | html_theme = "sphinx_rtd_theme" 65 | 66 | # Add any paths that contain custom static files (such as style sheets) here, 67 | # relative to this directory. They are copied after the builtin static files, 68 | # so a file named "default.css" will overwrite the builtin "default.css". 69 | # html_static_path = ['_static'] 70 | html_static_path = [] 71 | 72 | myst_enable_extensions = [ 73 | "dollarmath", 74 | "amsmath", 75 | ] 76 | 77 | breathe_projects = {"DOLFINx": "../xml/"} 78 | breathe_default_project = "DOLFINx" 79 | breathe_implementation_filename_extensions = [".c", ".cc", ".cpp"] 80 | 81 | # Tell sphinx what the primary language being documented is. 82 | primary_domain = "cpp" 83 | 84 | # Tell sphinx what the pygments highlight language should be. 85 | highlight_language = "cpp" 86 | -------------------------------------------------------------------------------- /cpp/doc/source/demo.rst: -------------------------------------------------------------------------------- 1 | .. DOLFINx C++ demos 2 | 3 | Demos 4 | ===== 5 | 6 | These demos illustrate DOLFINx C++ usage. Starting with the 7 | :doc:`Poisson demo ` is recommended. 8 | 9 | 10 | Introductory 11 | ------------ 12 | 13 | .. toctree:: 14 | :maxdepth: 1 15 | 16 | demos/demo_poisson.md 17 | demos/demo_biharmonic.md 18 | 19 | Intermediate 20 | ------------ 21 | 22 | .. toctree:: 23 | :maxdepth: 1 24 | 25 | demos/demo_hyperelasticity.md 26 | demos/demo_mixed_poisson.md 27 | demos/demo_poisson_matrix_free.md 28 | demos/demo_interpolation_different_meshes.md 29 | demos/demo_interpolation-io.md 30 | 31 | Advanced 32 | -------- 33 | 34 | .. toctree:: 35 | :maxdepth: 1 36 | 37 | demos/demo_custom_kernel.md 38 | -------------------------------------------------------------------------------- /cpp/doc/source/fem.rst: -------------------------------------------------------------------------------- 1 | Finite element (``dolfinx::fem``) 2 | ================================= 3 | 4 | *Under development* 5 | 6 | Finite elements 7 | --------------- 8 | 9 | .. doxygenclass:: dolfinx::fem::FiniteElement 10 | :project: DOLFINx 11 | :members: 12 | 13 | 14 | Function spaces and functions 15 | ----------------------------- 16 | 17 | Finite element functions, expressions and constants 18 | 19 | Function spaces 20 | ^^^^^^^^^^^^^^^ 21 | 22 | .. doxygenclass:: dolfinx::fem::FunctionSpace 23 | :project: DOLFINx 24 | :members: 25 | 26 | Functions 27 | ^^^^^^^^^ 28 | 29 | .. doxygenclass:: dolfinx::fem::Function 30 | :project: DOLFINx 31 | :members: 32 | 33 | 34 | Constants 35 | ^^^^^^^^^ 36 | 37 | .. doxygenclass:: dolfinx::fem::Constant 38 | :project: DOLFINx 39 | :members: 40 | 41 | 42 | Forms 43 | ----- 44 | 45 | .. doxygenclass:: dolfinx::fem::Form 46 | :project: DOLFINx 47 | :members: 48 | 49 | 50 | Dirichlet boundary conditions 51 | ----------------------------- 52 | 53 | .. doxygenclass:: dolfinx::fem::DirichletBC 54 | :project: DOLFINx 55 | :members: 56 | 57 | 58 | Degree-of-freedom maps 59 | ---------------------- 60 | 61 | .. doxygenfunction:: dolfinx::fem::transpose_dofmap 62 | :project: DOLFINx 63 | 64 | .. doxygenclass:: dolfinx::fem::DofMap 65 | :project: DOLFINx 66 | :members: 67 | 68 | Assembly 69 | -------- 70 | 71 | .. doxygenfile:: fem/assembler.h 72 | :project: DOLFINx 73 | :sections: func 74 | 75 | 76 | Interpolation 77 | ------------- 78 | 79 | .. doxygenfunction:: dolfinx::fem::interpolation_coords 80 | :project: DOLFINx 81 | 82 | 83 | Sparsity pattern construction 84 | ----------------------------- 85 | 86 | .. doxygenfunction:: dolfinx::fem::create_sparsity_pattern(const Form&) 87 | :project: DOLFINx 88 | 89 | 90 | PETSc helpers 91 | ------------- 92 | 93 | .. doxygennamespace:: dolfinx::fem::petsc 94 | :project: DOLFINx 95 | :content-only: 96 | 97 | 98 | Misc 99 | ---- 100 | 101 | .. doxygenfile:: fem/utils.h 102 | :project: DOLFINx 103 | :no-link: 104 | :sections: func 105 | .. :path: ../../../cpp/dolfinx/fem/ 106 | 107 | .. .. .. doxygennamespace:: dolfinx::fem 108 | .. .. :project: DOLFINx 109 | .. .. :members: 110 | -------------------------------------------------------------------------------- /cpp/doc/source/geometry.rst: -------------------------------------------------------------------------------- 1 | Geometry (``dolfinx::geometry``) 2 | ================================ 3 | 4 | .. doxygennamespace:: dolfinx::geometry 5 | :project: DOLFINx 6 | -------------------------------------------------------------------------------- /cpp/doc/source/graph.rst: -------------------------------------------------------------------------------- 1 | Graph (``dolfinx::graph``) 2 | ========================== 3 | 4 | Adjacency list 5 | -------------- 6 | 7 | .. doxygenclass:: dolfinx::graph::AdjacencyList 8 | :project: DOLFINx 9 | :members: 10 | 11 | 12 | Adjacency list builders 13 | ----------------------- 14 | 15 | .. doxygenfunction:: dolfinx::graph::regular_adjacency_list 16 | :project: DOLFINx 17 | 18 | 19 | Re-ordering 20 | ----------- 21 | 22 | .. doxygenfunction:: dolfinx::graph::reorder_gps 23 | :project: DOLFINx 24 | 25 | 26 | Partitioning 27 | ------------ 28 | 29 | .. doxygenfunction:: dolfinx::graph::partition_graph 30 | :project: DOLFINx 31 | 32 | .. doxygenfunction:: dolfinx::graph::scotch::partitioner 33 | :project: DOLFINx 34 | 35 | .. doxygenfunction:: dolfinx::graph::parmetis::partitioner 36 | :project: DOLFINx 37 | 38 | .. doxygenfunction:: dolfinx::graph::kahip::partitioner 39 | :project: DOLFINx 40 | 41 | 42 | Enumerations and typedefs 43 | ------------------------- 44 | 45 | .. doxygentypedef:: dolfinx::graph::partition_fn 46 | :project: DOLFINx 47 | 48 | 49 | .. doxygenenum:: dolfinx::graph::scotch::strategy 50 | :project: DOLFINx 51 | 52 | 53 | Functions for building distributed graphs 54 | ----------------------------------------- 55 | 56 | .. doxygennamespace:: dolfinx::graph::build 57 | :project: DOLFINx 58 | -------------------------------------------------------------------------------- /cpp/doc/source/index.rst: -------------------------------------------------------------------------------- 1 | ========================= 2 | DOLFINx C++ documentation 3 | ========================= 4 | 5 | This is experimental documentation for the C++ API. The full Doxygen 6 | generated documentation is `here `_. 7 | 8 | 9 | See https://docs.fenicsproject.org/dolfinx/main/python/ for installation 10 | instructions. 11 | 12 | 13 | .. toctree:: 14 | :maxdepth: 2 15 | 16 | demo 17 | 18 | .. toctree:: 19 | :maxdepth: 2 20 | 21 | api 22 | 23 | * :ref:`genindex` 24 | 25 | 26 | .. See https://github.com/sphinx-doc/sphinx/issues/10152 27 | -------------------------------------------------------------------------------- /cpp/doc/source/io.rst: -------------------------------------------------------------------------------- 1 | IO (``dolfinx::io``) 2 | ==================== 3 | 4 | .. doxygennamespace:: dolfinx::io 5 | :project: DOLFINx 6 | :members: -------------------------------------------------------------------------------- /cpp/doc/source/jupytext_process.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017-2023 Garth N. Wells, Jack S. Hale 2 | # 3 | # This file is part of DOLFINx (https://www.fenicsproject.org) 4 | # 5 | # SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | import pathlib 8 | import shutil 9 | 10 | import jupytext 11 | 12 | 13 | def process(): 14 | """Convert C++ demos in the Jupytext 'light' format into MyST 15 | flavoured markdown (and ipynb?) using Jupytext. These files can then be 16 | included in Sphinx documentation. 17 | 18 | """ 19 | # Make demo doc directory 20 | demo_doc_dir = pathlib.Path("./demos") 21 | demo_doc_dir.mkdir(parents=True, exist_ok=True) 22 | 23 | # Directories to scan demo code files 24 | demo_dirs = pathlib.Path("../../demo") 25 | 26 | # Iterate over subdirectories containing demos 27 | for demo_subdir in demo_dirs.iterdir(): 28 | if demo_subdir.is_dir(): 29 | fname = pathlib.Path("/demo_" + demo_subdir.name) 30 | demo_doc_subdir = demo_doc_dir / fname.name 31 | demo_doc_subdir.mkdir(parents=True, exist_ok=True) 32 | # Process each demo using jupytext/myst 33 | for demo_file in demo_subdir.glob("main.cpp"): 34 | # Copy demo files into documentation demo directory 35 | shutil.copy(demo_file, demo_doc_subdir) 36 | cpp_demo = jupytext.read(demo_file) 37 | cpp_myst_text = jupytext.writes(cpp_demo, fmt="myst") 38 | 39 | # myst-parser does not process blocks with {code-cell} 40 | cpp_myst_text = cpp_myst_text.replace("{code-cell}", "cpp") 41 | 42 | # Similarly for python file, dump python myst text in cpp myst 43 | for pydemo_file in demo_subdir.glob("*.py"): 44 | shutil.copy(pydemo_file, demo_doc_subdir) 45 | python_demo = jupytext.read(pydemo_file) 46 | python_myst_text = jupytext.writes(python_demo, fmt="myst") 47 | python_myst_text = python_myst_text.replace("{code-cell}", "python") 48 | cpp_myst_text = cpp_myst_text.replace("![ufl-code]", python_myst_text) 49 | 50 | for cmake_file in demo_subdir.glob("CMakeLists.txt"): 51 | shutil.copy(cmake_file, demo_doc_subdir) 52 | 53 | myst_file = (demo_doc_dir / fname.name).with_suffix(".md") 54 | with open(myst_file, "w") as fw: 55 | fw.write(cpp_myst_text) 56 | 57 | # There is a possibility to use jupyter-notebooks with C++/C kernels 58 | # ipynb_file = (demo_doc_dir / fname.name).with_suffix(".ipynb") 59 | # jupytext.write(cpp_demo, ipynb_file, fmt="ipynb") 60 | 61 | 62 | if __name__ == "__main__": 63 | process() 64 | -------------------------------------------------------------------------------- /cpp/doc/source/la.rst: -------------------------------------------------------------------------------- 1 | Linear algebra (``dolfinx::la``) 2 | ================================ 3 | 4 | .. doxygennamespace:: dolfinx::la 5 | :project: DOLFINx 6 | :members: 7 | -------------------------------------------------------------------------------- /cpp/doc/source/mesh.rst: -------------------------------------------------------------------------------- 1 | Mesh (``dolfinx::mesh``) 2 | ======================== 3 | 4 | *Under development* 5 | 6 | .. doxygennamespace:: dolfinx::mesh 7 | :project: DOLFINx 8 | :members: -------------------------------------------------------------------------------- /cpp/doc/source/refinement.rst: -------------------------------------------------------------------------------- 1 | Refinement (``dolfinx::refinement``) 2 | ==================================== 3 | 4 | .. doxygennamespace:: dolfinx::refinement 5 | :project: DOLFINx 6 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HEADERS_common 2 | ${CMAKE_CURRENT_SOURCE_DIR}/defines.h 3 | ${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_common.h 4 | ${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_doc.h 5 | ${CMAKE_CURRENT_SOURCE_DIR}/IndexMap.h 6 | ${CMAKE_CURRENT_SOURCE_DIR}/log.h 7 | ${CMAKE_CURRENT_SOURCE_DIR}/sort.h 8 | ${CMAKE_CURRENT_SOURCE_DIR}/types.h 9 | ${CMAKE_CURRENT_SOURCE_DIR}/math.h 10 | ${CMAKE_CURRENT_SOURCE_DIR}/MPI.h 11 | ${CMAKE_CURRENT_SOURCE_DIR}/Scatterer.h 12 | ${CMAKE_CURRENT_SOURCE_DIR}/Table.h 13 | ${CMAKE_CURRENT_SOURCE_DIR}/Timer.h 14 | ${CMAKE_CURRENT_SOURCE_DIR}/TimeLogger.h 15 | ${CMAKE_CURRENT_SOURCE_DIR}/timing.h 16 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.h 17 | PARENT_SCOPE 18 | ) 19 | 20 | target_sources( 21 | dolfinx 22 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/defines.cpp 23 | ${CMAKE_CURRENT_SOURCE_DIR}/IndexMap.cpp 24 | ${CMAKE_CURRENT_SOURCE_DIR}/log.cpp 25 | ${CMAKE_CURRENT_SOURCE_DIR}/MPI.cpp 26 | ${CMAKE_CURRENT_SOURCE_DIR}/Table.cpp 27 | ${CMAKE_CURRENT_SOURCE_DIR}/TimeLogger.cpp 28 | ${CMAKE_CURRENT_SOURCE_DIR}/timing.cpp 29 | ) 30 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/Table.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008-2011 Anders Logg 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace dolfinx 16 | { 17 | 18 | /// @brief This class provides storage and pretty-printing for tables. 19 | /// 20 | /// Example usage: 21 | /// 22 | /// Table table("Timings"); 23 | /// table.set("Foo", "Assemble", 0.010); 24 | /// table.set("Foo", "Solve", 0.020); 25 | /// table.set("Bar", "Assemble", 0.011); 26 | /// table.set("Bar", "Solve", 0.019); 27 | class Table 28 | { 29 | public: 30 | /// Types of MPI reduction available for Table, to get the max, min or 31 | /// average values over an MPI_Comm 32 | enum class Reduction 33 | { 34 | average, 35 | max, 36 | min 37 | }; 38 | 39 | /// Create empty table 40 | Table(std::string title = "", bool right_justify = true); 41 | 42 | /// Copy constructor 43 | Table(const Table& table) = default; 44 | 45 | /// Move constructor 46 | Table(Table&& table) = default; 47 | 48 | /// Destructor 49 | ~Table() = default; 50 | 51 | /// Assignment operator 52 | Table& operator=(const Table& table) = default; 53 | 54 | /// Move assignment 55 | Table& operator=(Table&& table) = default; 56 | 57 | /// Set table entry 58 | /// @param[in] row Row name 59 | /// @param[in] col Column name 60 | /// @param[in] value The value to set 61 | void set(std::string row, std::string col, 62 | std::variant value); 63 | 64 | /// Get value of table entry 65 | /// @param[in] row Row name 66 | /// @param[in] col Column name 67 | /// @returns Returns the entry for requested row and columns 68 | std::variant get(std::string row, 69 | std::string col) const; 70 | 71 | /// Do MPI reduction on Table 72 | /// @param[in] comm MPI communicator 73 | /// @param[in] reduction Type of reduction to perform 74 | /// @return Reduced Table 75 | Table reduce(MPI_Comm comm, Reduction reduction) const; 76 | 77 | /// Table name 78 | std::string name; 79 | 80 | /// Return string representation of the table 81 | std::string str() const; 82 | 83 | private: 84 | // Row and column names 85 | std::vector _rows, _cols; 86 | 87 | // Table entry values 88 | std::map, 89 | std::variant> 90 | _values; 91 | 92 | // True if we should right-justify the table entries 93 | bool _right_justify; 94 | }; 95 | 96 | } // namespace dolfinx 97 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/TimeLogger.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2003-2016 Anders Logg 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #include "TimeLogger.h" 8 | #include "MPI.h" 9 | #include "log.h" 10 | #include 11 | 12 | using namespace dolfinx; 13 | using namespace dolfinx::common; 14 | 15 | //----------------------------------------------------------------------------- 16 | TimeLogger& TimeLogger::instance() 17 | { 18 | static TimeLogger _instance{}; 19 | return _instance; 20 | } 21 | 22 | //----------------------------------------------------------------------------- 23 | void TimeLogger::register_timing( 24 | std::string task, std::chrono::duration> time) 25 | { 26 | // Print a message 27 | std::string line 28 | = "Elapsed time: " + std::to_string(time.count()) + " (" + task + ")"; 29 | spdlog::debug(line.c_str()); 30 | 31 | // Store values for summary 32 | if (auto it = _timings.find(task); it != _timings.end()) 33 | { 34 | std::get<0>(it->second) += 1; 35 | std::get<1>(it->second) += time; 36 | } 37 | else 38 | _timings.insert({task, {1, time}}); 39 | } 40 | //----------------------------------------------------------------------------- 41 | void TimeLogger::list_timings(MPI_Comm comm, Table::Reduction reduction) const 42 | { 43 | // Format and reduce to rank 0 44 | Table timings = this->timing_table(); 45 | timings = timings.reduce(comm, reduction); 46 | const std::string str = "\n" + timings.str(); 47 | 48 | // Print just on rank 0 49 | if (dolfinx::MPI::rank(comm) == 0) 50 | std::cout << str << std::endl; 51 | } 52 | //----------------------------------------------------------------------------- 53 | Table TimeLogger::timing_table() const 54 | { 55 | // Generate log::timing table 56 | Table table("Summary of timings (s)"); 57 | for (auto& it : _timings) 58 | { 59 | std::string task = it.first; 60 | auto [num_timings, time] = it.second; 61 | table.set(task, "reps", num_timings); 62 | table.set(task, "avg", time.count() / static_cast(num_timings)); 63 | table.set(task, "tot", time.count()); 64 | } 65 | 66 | return table; 67 | } 68 | //----------------------------------------------------------------------------- 69 | std::pair>> 70 | TimeLogger::timing(std::string task) const 71 | { 72 | // Find timing 73 | auto it = _timings.find(task); 74 | if (it == _timings.end()) 75 | { 76 | throw std::runtime_error("No timings registered for task \"" + task 77 | + "\"."); 78 | } 79 | 80 | return it->second; 81 | } 82 | //----------------------------------------------------------------------------- 83 | std::map>>> 85 | TimeLogger::timings() const 86 | { 87 | return _timings; 88 | } 89 | //----------------------------------------------------------------------------- 90 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/TimeLogger.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2003-2016 Anders Logg, 2015 Jan Blechta 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include "Table.h" 10 | #include "timing.h" 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace dolfinx::common 18 | { 19 | /// @brief Time logger maintaining data collected by Timer, if registered. 20 | /// 21 | /// @note This is a monotstate, i.e. the data members are static and thus 22 | /// timings are aggregated into a single map. 23 | class TimeLogger 24 | { 25 | public: 26 | /// @brief Singleton access. 27 | /// @return Unique time logger object. 28 | static TimeLogger& instance(); 29 | 30 | /// Register timing (for later summary) 31 | void register_timing(std::string task, 32 | std::chrono::duration> wall); 33 | 34 | /// Return a summary of timings and tasks in a Table 35 | Table timing_table() const; 36 | 37 | /// List a summary of timings and tasks. Reduction type is 38 | /// printed. 39 | /// @param comm MPI Communicator 40 | /// @param reduction Reduction type (min, max or average) 41 | void list_timings(MPI_Comm comm, Table::Reduction reduction) const; 42 | 43 | /// @brief Return timing. 44 | /// @param[in] task The task name to retrieve the timing for 45 | /// @return Values (count, total wall time) for given task. 46 | std::pair>> 47 | timing(std::string task) const; 48 | 49 | /// @brief Logged elapsed times. 50 | /// @return Elapsed [task id: (count, total wall time)]. 51 | std::map>>> 53 | timings() const; 54 | 55 | private: 56 | /// Constructor 57 | TimeLogger() = default; 58 | 59 | // This class is used as a singleton and thus should not allow copies. 60 | TimeLogger(const TimeLogger&) = delete; 61 | 62 | // This class is used as a singleton and thus should not allow copies. 63 | TimeLogger& operator=(const TimeLogger&) = delete; 64 | 65 | /// Destructor 66 | ~TimeLogger() = default; 67 | 68 | // List of timings for tasks, map from string to (num_timings, 69 | // total_wall_time) 70 | std::map>>> 72 | _timings; 73 | }; 74 | } // namespace dolfinx::common 75 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/defines.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009-2011 Johan Hake 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #include "defines.h" 8 | 9 | //------------------------------------------------------------------------- 10 | std::string dolfinx::version() { return std::string(DOLFINX_VERSION); } 11 | //------------------------------------------------------------------------- 12 | std::string dolfinx::ufcx_signature() { return std::string(UFCX_SIGNATURE); } 13 | //------------------------------------------------------------------------- 14 | std::string dolfinx::git_commit_hash() 15 | { 16 | return std::string(DOLFINX_GIT_COMMIT_HASH); 17 | } 18 | //------------------------------------------------------------------------- -------------------------------------------------------------------------------- /cpp/dolfinx/common/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2009-2011 Johan Hake 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace dolfinx 12 | { 13 | 14 | /// Return DOLFINx version string 15 | std::string version(); 16 | 17 | /// Return UFC signature string 18 | std::string ufcx_signature(); 19 | 20 | /// Return git changeset hash (returns "unknown" if changeset is 21 | /// not known) 22 | std::string git_commit_hash(); 23 | 24 | /// Return true if DOLFINx is compiled in debugging mode, 25 | /// i.e., with assertions on 26 | consteval bool has_debug() 27 | { 28 | #ifndef NDEBUG 29 | return true; 30 | #else 31 | return false; 32 | #endif 33 | } 34 | 35 | /// Return true if DOLFINx is compiled with PETSc 36 | consteval bool has_petsc() 37 | { 38 | #ifdef HAS_PETSC 39 | return true; 40 | #else 41 | return false; 42 | #endif 43 | } 44 | 45 | /// Return true if DOLFINx is compiled with SLEPc 46 | consteval bool has_slepc() 47 | { 48 | #ifdef HAS_SLEPC 49 | return true; 50 | #else 51 | return false; 52 | #endif 53 | } 54 | 55 | /// Return true if DOLFINx is compiled with ParMETIS 56 | consteval bool has_parmetis() 57 | { 58 | #ifdef HAS_PARMETIS 59 | return true; 60 | #else 61 | return false; 62 | #endif 63 | } 64 | 65 | /// Return true if DOLFINx is compiled with KaHIP 66 | consteval bool has_kahip() 67 | { 68 | #ifdef HAS_KAHIP 69 | return true; 70 | #else 71 | return false; 72 | #endif 73 | } 74 | 75 | /// Return true if DOLFINX is compiled with ADIOS2 76 | consteval bool has_adios2() 77 | { 78 | #ifdef HAS_ADIOS2 79 | return true; 80 | #else 81 | return false; 82 | #endif 83 | } 84 | 85 | /// Return true if DOLFINX is compiled with PT-SCOTCH 86 | consteval bool has_ptscotch() 87 | { 88 | #ifdef HAS_PTSCOTCH 89 | return true; 90 | #else 91 | return false; 92 | #endif 93 | } 94 | 95 | /// Return true if DOLFINx supports UFCx kernels with arguments of type C99 96 | /// _Complex. When DOLFINx was built with MSVC this returns false. This 97 | /// returning false does not preclude using DOLFINx with kernels accepting 98 | /// std::complex. 99 | consteval bool has_complex_ufcx_kernels() 100 | { 101 | #ifdef DOLFINX_NO_STDC_COMPLEX_KERNELS 102 | return false; 103 | #else 104 | return true; 105 | #endif 106 | } 107 | 108 | } // namespace dolfinx 109 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/dolfinx_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// @brief Miscellaneous classes, functions and types. 4 | /// 5 | /// This namespace provides utility type functions for managing 6 | /// subsystems, convenience classes and library-wide typedefs. 7 | namespace dolfinx::common 8 | { 9 | } 10 | 11 | // DOLFINx common 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/dolfinx_doc.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2003-2006 Anders Logg 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | /*! \mainpage DOLFINx Programmer's Reference 8 | * 9 | * This is the documentation of the DOLFINx C++ interface. 10 | * 11 | */ 12 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/log.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019 Chris Richardson 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #include "log.h" 8 | #include 9 | #include 10 | 11 | //----------------------------------------------------------------------------- 12 | void dolfinx::init_logging(int argc, char* argv[]) 13 | { 14 | // Initialise to level::warn, can be overridden later 15 | spdlog::set_level(spdlog::level::warn); 16 | spdlog::cfg::load_argv_levels(argc, argv); 17 | } 18 | //----------------------------------------------------------------------------- 19 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/log.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019 Chris Richardson 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace dolfinx 12 | { 13 | 14 | /// @brief Optional initialisation of the logging backend. 15 | /// 16 | /// The log verbosity can be controlled from the command line using 17 | /// `SPDLOG_LEVEL=`, where `` is info, warn, debug, etc. 18 | /// 19 | /// The full `spdlog` API can be used in applications to control the log 20 | /// system. See https://github.com/gabime/spdlog for the spdlog 21 | /// documentation. 22 | /// 23 | /// @param[in] argc Number of command line arguments. 24 | /// @param[in] argv Command line argument vector. 25 | void init_logging(int argc, char* argv[]); 26 | 27 | } // namespace dolfinx 28 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/timing.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2003-2011 Anders Logg 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #include "timing.h" 8 | #include "Table.h" 9 | #include "TimeLogger.h" 10 | #include "Timer.h" 11 | 12 | //----------------------------------------------------------------------- 13 | dolfinx::Table dolfinx::timing_table() 14 | { 15 | return dolfinx::common::TimeLogger::instance().timing_table(); 16 | } 17 | //----------------------------------------------------------------------------- 18 | void dolfinx::list_timings(MPI_Comm comm, Table::Reduction reduction) 19 | { 20 | dolfinx::common::TimeLogger::instance().list_timings(comm, reduction); 21 | } 22 | //----------------------------------------------------------------------------- 23 | std::pair>> 24 | dolfinx::timing(std::string task) 25 | { 26 | return dolfinx::common::TimeLogger::instance().timing(task); 27 | } 28 | //----------------------------------------------------------------------------- 29 | std::map>>> 31 | dolfinx::timings() 32 | { 33 | return dolfinx::common::TimeLogger::instance().timings(); 34 | } 35 | //----------------------------------------------------------------------------- 36 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/timing.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2005-2010 Anders Logg, 2015 Jan Blechta 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include "Table.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace dolfinx 17 | { 18 | /// @brief Return a summary of timings and tasks in a Table. 19 | /// @return Table with timings. 20 | Table timing_table(); 21 | 22 | /// @brief List a summary of timings and tasks. 23 | /// 24 | /// ``MPI_AVG`` reduction is printed. 25 | /// 26 | /// @param[in] comm MPI Communicator. 27 | /// @param[in] reduction MPI Reduction to apply (min, max or average). 28 | void list_timings(MPI_Comm comm, 29 | Table::Reduction reduction = Table::Reduction::max); 30 | 31 | /// @brief Return timing (count, total wall time) for given task. 32 | /// @param[in] task Name of a task 33 | /// @return The (count, total wall time) for the task. 34 | std::pair>> 35 | timing(std::string task); 36 | 37 | /// @brief Logged elapsed times. 38 | /// @return Elapsed [task id: (count, total wall time)]. 39 | std::map>>> 41 | timings(); 42 | 43 | } // namespace dolfinx 44 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/types.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023-2025 Garth N. Wells and Paul T. Kühner 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace dolfinx 15 | { 16 | /// @private This concept is used to constrain the a template type to floating 17 | /// point real or complex types. Note that this concept is different to 18 | /// std::floating_point which does not include std::complex. 19 | template 20 | concept scalar = std::floating_point 21 | || std::is_same_v>; 22 | 23 | /// @private These structs are used to get the float/value type from a 24 | /// template argument, including support for complex types. 25 | template 26 | struct scalar_value 27 | { 28 | /// @internal 29 | typedef T type; 30 | }; 31 | /// @private 32 | template 33 | struct scalar_value> 34 | { 35 | typedef typename T::value_type type; 36 | }; 37 | /// @private Convenience typedef 38 | template 39 | using scalar_value_t = typename scalar_value::type; 40 | 41 | /// @private mdspan/mdarray namespace 42 | namespace md = MDSPAN_IMPL_STANDARD_NAMESPACE; 43 | 44 | } // namespace dolfinx 45 | -------------------------------------------------------------------------------- /cpp/dolfinx/common/version.h.in: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define DOLFINX_VERSION_RELEASE @DOLFINX_VERSION_RELEASE@ 4 | #define DOLFINX_VERSION_MAJOR @DOLFINX_VERSION_MAJOR@ 5 | #define DOLFINX_VERSION_MINOR @DOLFINX_VERSION_MINOR@ 6 | #define DOLFINX_VERSION_MICRO @DOLFINX_VERSION_MICRO_STRIPPED@ 7 | #define DOLFINX_VERSION_STRING "@DOLFINX_VERSION@" 8 | #define DOLFINX_VERSION_GIT "@GIT_COMMIT_HASH@" 9 | #define UFCX_SIGNATURE "@UFCX_SIGNATURE@" 10 | -------------------------------------------------------------------------------- /cpp/dolfinx/dolfinx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// @brief Top-level namespace 4 | namespace dolfinx 5 | { 6 | } 7 | 8 | // DOLFINx interface 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | -------------------------------------------------------------------------------- /cpp/dolfinx/fem/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HEADERS_fem 2 | ${CMAKE_CURRENT_SOURCE_DIR}/Constant.h 3 | ${CMAKE_CURRENT_SOURCE_DIR}/CoordinateElement.h 4 | ${CMAKE_CURRENT_SOURCE_DIR}/DirichletBC.h 5 | ${CMAKE_CURRENT_SOURCE_DIR}/DofMap.h 6 | ${CMAKE_CURRENT_SOURCE_DIR}/ElementDofLayout.h 7 | ${CMAKE_CURRENT_SOURCE_DIR}/Expression.h 8 | ${CMAKE_CURRENT_SOURCE_DIR}/FiniteElement.h 9 | ${CMAKE_CURRENT_SOURCE_DIR}/Form.h 10 | ${CMAKE_CURRENT_SOURCE_DIR}/Function.h 11 | ${CMAKE_CURRENT_SOURCE_DIR}/FunctionSpace.h 12 | ${CMAKE_CURRENT_SOURCE_DIR}/assembler.h 13 | ${CMAKE_CURRENT_SOURCE_DIR}/assemble_expression_impl.h 14 | ${CMAKE_CURRENT_SOURCE_DIR}/assemble_matrix_impl.h 15 | ${CMAKE_CURRENT_SOURCE_DIR}/assemble_scalar_impl.h 16 | ${CMAKE_CURRENT_SOURCE_DIR}/assemble_vector_impl.h 17 | ${CMAKE_CURRENT_SOURCE_DIR}/discreteoperators.h 18 | ${CMAKE_CURRENT_SOURCE_DIR}/dofmapbuilder.h 19 | ${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_fem.h 20 | ${CMAKE_CURRENT_SOURCE_DIR}/interpolate.h 21 | ${CMAKE_CURRENT_SOURCE_DIR}/petsc.h 22 | ${CMAKE_CURRENT_SOURCE_DIR}/pack.h 23 | ${CMAKE_CURRENT_SOURCE_DIR}/sparsitybuild.h 24 | ${CMAKE_CURRENT_SOURCE_DIR}/traits.h 25 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.h 26 | PARENT_SCOPE 27 | ) 28 | 29 | target_sources( 30 | dolfinx 31 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/DirichletBC.cpp 32 | ${CMAKE_CURRENT_SOURCE_DIR}/CoordinateElement.cpp 33 | ${CMAKE_CURRENT_SOURCE_DIR}/DofMap.cpp 34 | ${CMAKE_CURRENT_SOURCE_DIR}/ElementDofLayout.cpp 35 | ${CMAKE_CURRENT_SOURCE_DIR}/FiniteElement.cpp 36 | ${CMAKE_CURRENT_SOURCE_DIR}/dofmapbuilder.cpp 37 | ${CMAKE_CURRENT_SOURCE_DIR}/petsc.cpp 38 | ${CMAKE_CURRENT_SOURCE_DIR}/sparsitybuild.cpp 39 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp 40 | ) 41 | -------------------------------------------------------------------------------- /cpp/dolfinx/fem/Constant.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2019-2023 Chris Richardson, Michal Habera and Garth N. 2 | // Wells 3 | // 4 | // This file is part of DOLFINx (https://www.fenicsproject.org) 5 | // 6 | // SPDX-License-Identifier: LGPL-3.0-or-later 7 | 8 | #pragma once 9 | 10 | #include "dolfinx/common/types.h" 11 | #include 12 | #include 13 | 14 | namespace dolfinx::fem 15 | { 16 | 17 | /// @brief Constant value which can be attached to a Form. 18 | /// 19 | /// Constants may be scalar (rank 0), vector (rank 1), or tensor-valued. 20 | /// @tparam T Scalar type of the Constant. 21 | template 22 | class Constant 23 | { 24 | public: 25 | /// Field type 26 | using value_type = T; 27 | 28 | /// @brief Create a rank-0 (scalar-valued) constant 29 | /// @param[in] c Value of the constant 30 | explicit Constant(value_type c) : value({c}) {} 31 | 32 | /// @brief Create a rank-1 (vector-valued) constant 33 | /// @param[in] c Value of the constant 34 | explicit Constant(std::span c) 35 | : Constant(c, std::vector{c.size()}) 36 | { 37 | } 38 | 39 | /// @brief Create a rank-d constant 40 | /// @param[in] c Value of the Constant (row-majors storage) 41 | /// @param[in] shape Shape of the Constant 42 | Constant(std::span c, std::span shape) 43 | : value(c.begin(), c.end()), shape(shape.begin(), shape.end()) 44 | { 45 | } 46 | 47 | /// Values, stored as a row-major flattened array 48 | std::vector value; 49 | 50 | /// Shape 51 | std::vector shape; 52 | }; 53 | } // namespace dolfinx::fem 54 | -------------------------------------------------------------------------------- /cpp/dolfinx/fem/dofmapbuilder.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008-2018 Anders Logg, Ola Skavhaug and Garth N. Wells 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace dolfinx::common 16 | { 17 | class IndexMap; 18 | } 19 | 20 | namespace dolfinx::mesh 21 | { 22 | class Topology; 23 | } 24 | 25 | namespace dolfinx::graph 26 | { 27 | template 28 | class AdjacencyList; 29 | } 30 | 31 | namespace dolfinx::fem 32 | { 33 | class ElementDofLayout; 34 | 35 | /// Build dofmap data for elements on a mesh topology 36 | /// @param[in] comm MPI communicator 37 | /// @param[in] topology The mesh topology 38 | /// @param[in] element_dof_layouts The element dof layouts for each cell 39 | /// type in `topology`. 40 | /// @param[in] reorder_fn Graph reordering function that is applied to 41 | /// the dofmaps 42 | /// @return The index map, block size, and dofmaps for each element type 43 | std::tuple>> 44 | build_dofmap_data(MPI_Comm comm, const mesh::Topology& topology, 45 | const std::vector& element_dof_layouts, 46 | const std::function( 47 | const graph::AdjacencyList&)>& reorder_fn); 48 | 49 | } // namespace dolfinx::fem 50 | -------------------------------------------------------------------------------- /cpp/dolfinx/fem/dolfinx_fem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// @brief Finite element method functionality 4 | /// 5 | /// Classes and algorithms for finite element method spaces and 6 | /// operations. 7 | namespace dolfinx::fem 8 | { 9 | } 10 | 11 | // DOLFINx fem interface 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | -------------------------------------------------------------------------------- /cpp/dolfinx/fem/sparsitybuild.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2007-2023 Garth N. Wells 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #include "sparsitybuild.h" 8 | #include "DofMap.h" 9 | #include 10 | #include 11 | 12 | using namespace dolfinx; 13 | using namespace dolfinx::fem; 14 | 15 | //----------------------------------------------------------------------------- 16 | void sparsitybuild::cells( 17 | la::SparsityPattern& pattern, 18 | std::array, 2> cells, 19 | std::array, 2> dofmaps) 20 | { 21 | assert(cells[0].size() == cells[1].size()); 22 | const DofMap& map0 = dofmaps[0].get(); 23 | const DofMap& map1 = dofmaps[1].get(); 24 | for (std::size_t i = 0; i < cells[0].size(); ++i) 25 | pattern.insert(map0.cell_dofs(cells[0][i]), map1.cell_dofs(cells[1][i])); 26 | } 27 | //----------------------------------------------------------------------------- 28 | void sparsitybuild::interior_facets( 29 | la::SparsityPattern& pattern, 30 | std::array, 2> cells, 31 | std::array, 2> dofmaps) 32 | { 33 | std::span cells0 = cells[0]; 34 | std::span cells1 = cells[1]; 35 | assert(cells0.size() == cells1.size()); 36 | const DofMap& dofmap0 = dofmaps[0]; 37 | const DofMap& dofmap1 = dofmaps[1]; 38 | 39 | // Iterate over facets 40 | std::vector macro_dofs0, macro_dofs1; 41 | for (std::size_t f = 0; f < cells[0].size(); f += 2) 42 | { 43 | // Test function dofs (sparsity pattern rows) 44 | auto dofs00 = dofmap0.cell_dofs(cells0[f]); 45 | auto dofs01 = dofmap0.cell_dofs(cells0[f + 1]); 46 | macro_dofs0.resize(dofs00.size() + dofs01.size()); 47 | std::ranges::copy(dofs00, macro_dofs0.begin()); 48 | std::ranges::copy(dofs01, std::next(macro_dofs0.begin(), dofs00.size())); 49 | 50 | // Trial function dofs (sparsity pattern columns) 51 | auto dofs10 = dofmap1.cell_dofs(cells1[f]); 52 | auto dofs11 = dofmap1.cell_dofs(cells1[f + 1]); 53 | macro_dofs1.resize(dofs10.size() + dofs11.size()); 54 | std::ranges::copy(dofs10, macro_dofs1.begin()); 55 | std::ranges::copy(dofs11, std::next(macro_dofs1.begin(), dofs10.size())); 56 | 57 | pattern.insert(macro_dofs0, macro_dofs1); 58 | } 59 | } 60 | //----------------------------------------------------------------------------- 61 | -------------------------------------------------------------------------------- /cpp/dolfinx/fem/sparsitybuild.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2007-2023 Garth N. Wells 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace dolfinx::la 15 | { 16 | class SparsityPattern; 17 | } 18 | 19 | namespace dolfinx::fem 20 | { 21 | class DofMap; 22 | 23 | /// Support for building sparsity patterns from degree-of-freedom maps. 24 | namespace sparsitybuild 25 | { 26 | /// @brief Iterate over cells and insert entries into sparsity pattern. 27 | /// 28 | /// Inserts the rectangular blocks of indices `dofmap[0][cells[0][i]] x 29 | /// dofmap[1][cells[1][i]]` into the sparsity pattern, i.e. entries 30 | /// `(dofmap[0][cells[0][i]][k0], dofmap[0][cells[0][i]][k1])` will 31 | /// appear in the sparsity pattern. 32 | /// 33 | /// @param pattern Sparsity pattern to insert into. 34 | /// @param cells Lists of cells to iterate over. `cells[0]` and 35 | /// `cells[1]` must have the same size. 36 | /// @param dofmaps Dofmaps to used in building the sparsity pattern. 37 | /// @note The sparsity pattern is not finalised. 38 | void cells(la::SparsityPattern& pattern, 39 | std::array, 2> cells, 40 | std::array, 2> dofmaps); 41 | 42 | /// @brief Iterate over interior facets and insert entries into sparsity 43 | /// pattern. 44 | /// 45 | /// Inserts the rectangular blocks of indices `[dofmap[0][cell0], 46 | /// dofmap[0][cell1]] x [dofmap[1][cell0] + dofmap[1][cell1]]` where 47 | /// `cell0` and `cell1` are the two cells attached to a facet. 48 | /// 49 | /// @param[in,out] pattern Sparsity pattern to insert into. 50 | /// @param[in] cells Cells to index into each dofmap. `cells[i]` is a 51 | /// list of `(cell0, cell1)` pairs for each interior facet to index into 52 | /// `dofmap[i]`. `cells[0]` and `cells[1]` must have the same size. 53 | /// @param[in] dofmaps Dofmaps to use in building the sparsity pattern. 54 | /// 55 | /// @note The sparsity pattern is not finalised. 56 | void interior_facets( 57 | la::SparsityPattern& pattern, 58 | std::array, 2> cells, 59 | std::array, 2> dofmaps); 60 | 61 | } // namespace sparsitybuild 62 | } // namespace dolfinx::fem 63 | -------------------------------------------------------------------------------- /cpp/dolfinx/fem/traits.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2024 Joseph P. Dean and Garth N. Wells 2 | // This file is part of DOLFINx (https://www.fenicsproject.org) 3 | // 4 | // SPDX-License-Identifier: LGPL-3.0-or-later 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace dolfinx::fem 16 | { 17 | 18 | /// @brief DOF transform kernel concept. 19 | template 20 | concept DofTransformKernel 21 | = std::is_invocable_v, std::span, 22 | std::int32_t, int>; 23 | 24 | /// @brief Finite element cell kernel concept. 25 | /// 26 | /// Kernel functions that can be passed to an assembler for execution 27 | /// must satisfy this concept. 28 | template 29 | concept FEkernel 30 | = std::is_invocable_v*, 31 | const int*, const std::uint8_t*, void*>; 32 | 33 | /// @brief Concept for mdspan of rank 1 or 2. 34 | template 35 | concept MDSpan2 36 | = std::is_convertible_v< 37 | std::remove_cvref_t, 38 | md::mdspan>> 39 | or std::is_convertible_v< 40 | std::remove_cvref_t, 41 | md::mdspan>>; 42 | 43 | } // namespace dolfinx::fem 44 | -------------------------------------------------------------------------------- /cpp/dolfinx/geometry/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HEADERS_geometry 2 | ${CMAKE_CURRENT_SOURCE_DIR}/BoundingBoxTree.h 3 | ${CMAKE_CURRENT_SOURCE_DIR}/gjk.h 4 | ${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_geometry.h 5 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.h 6 | PARENT_SCOPE 7 | ) 8 | -------------------------------------------------------------------------------- /cpp/dolfinx/geometry/dolfinx_geometry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// @brief Geometry data structures and algorithms 4 | /// 5 | /// Tools for geometric data structures and operations, e.g. searching. 6 | namespace dolfinx::geometry 7 | { 8 | } 9 | 10 | // DOLFINx geometry interface 11 | 12 | #include 13 | #include 14 | -------------------------------------------------------------------------------- /cpp/dolfinx/graph/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HEADERS_graph 2 | ${CMAKE_CURRENT_SOURCE_DIR}/AdjacencyList.h 3 | ${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_graph.h 4 | ${CMAKE_CURRENT_SOURCE_DIR}/ordering.h 5 | ${CMAKE_CURRENT_SOURCE_DIR}/partitioners.h 6 | ${CMAKE_CURRENT_SOURCE_DIR}/partition.h 7 | PARENT_SCOPE 8 | ) 9 | 10 | target_sources( 11 | dolfinx 12 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ordering.cpp 13 | ${CMAKE_CURRENT_SOURCE_DIR}/partitioners.cpp 14 | ${CMAKE_CURRENT_SOURCE_DIR}/partition.cpp 15 | ) 16 | -------------------------------------------------------------------------------- /cpp/dolfinx/graph/dolfinx_graph.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// @brief Graph data structures and algorithms. 4 | /// 5 | /// Data structures for building and representing graphs, and algorithms 6 | /// on graphs, e.g., re-ordering and partitioning. 7 | namespace dolfinx::graph 8 | { 9 | } 10 | 11 | // DOLFINx graph interface 12 | 13 | #include 14 | -------------------------------------------------------------------------------- /cpp/dolfinx/graph/ordering.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2021 Chris Richardson 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace dolfinx::graph 13 | { 14 | template 15 | class AdjacencyList; 16 | 17 | /// @brief Re-order a graph using the Gibbs-Poole-Stockmeyer algorithm. 18 | /// 19 | /// The algorithm is described in *An Algorithm for Reducing the 20 | /// Bandwidth and Profile of a Sparse Matrix*, SIAM Journal on Numerical 21 | /// Analysis, 13(2): 236-250, 1976, https://doi.org/10.1137/0713023. 22 | /// 23 | /// @param[in] graph The graph to compute a re-ordering for 24 | /// @return Reordering array `map`, where `map[i]` is the new index of 25 | /// node `i` 26 | std::vector 27 | reorder_gps(const graph::AdjacencyList& graph); 28 | 29 | } // namespace dolfinx::graph 30 | -------------------------------------------------------------------------------- /cpp/dolfinx/graph/partitioners.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2020-2023 Garth N. Wells and Igor A. Baratta 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include "partition.h" 10 | #include 11 | 12 | namespace dolfinx::graph 13 | { 14 | namespace scotch 15 | { 16 | #ifdef HAS_PTSCOTCH 17 | /// @brief PT-SCOTCH partitioning strategies. 18 | /// 19 | /// See PT-SCOTCH documentation for details. 20 | enum class strategy 21 | { 22 | ///< SCOTCH default strategy 23 | none, 24 | balance, 25 | quality, 26 | safety, 27 | speed, 28 | scalability 29 | }; 30 | 31 | /// @brief Create a graph partitioning function that uses PT-SCOTCH. 32 | /// 33 | /// @param[in] strategy The SCOTCH strategy 34 | /// @param[in] imbalance The allowable imbalance (between 0 and 1). The 35 | /// smaller value the more balanced the partitioning must be. 36 | /// @param[in] seed Random number generator seed 37 | /// @return A graph partitioning function 38 | graph::partition_fn partitioner(scotch::strategy strategy = strategy::none, 39 | double imbalance = 0.025, int seed = 0); 40 | #endif 41 | 42 | } // namespace scotch 43 | 44 | namespace parmetis 45 | { 46 | #ifdef HAS_PARMETIS 47 | /// @brief Create a graph partitioning function that uses ParMETIS. 48 | /// 49 | /// @note ParMETIS fails (crashes) if an MPI rank has no part of the 50 | /// graph. If necessary, the communicator should be split to avoid this 51 | /// situation. 52 | /// 53 | /// @param[in] imbalance Imbalance tolerance. See ParMETIS manual for 54 | /// details 55 | /// (https://github.com/KarypisLab/ParMETIS/blob/main/manual/manual.pdf). 56 | /// @param[in] options The ParMETIS option. See ParMETIS manual for 57 | /// details. 58 | graph::partition_fn partitioner(double imbalance = 1.02, 59 | std::array options = {1, 0, 5}); 60 | 61 | #endif 62 | } // namespace parmetis 63 | 64 | /// Interfaces to KaHIP parallel partitioner 65 | namespace kahip 66 | { 67 | #ifdef HAS_KAHIP 68 | /// @brief Create a graph partitioning function that uses KaHIP. 69 | /// 70 | /// @param[in] mode The KaHiP partitioning mode (see 71 | /// https://github.com/KaHIP/KaHIP/blob/master/parallel/parallel_src/interface/parhip_interface.h) 72 | /// @param[in] seed The KaHiP random number generator seed 73 | /// @param[in] imbalance The allowable imbalance 74 | /// @param[in] suppress_output Suppresses KaHIP output if true 75 | /// @return A KaHIP graph partitioning function with specified parameter 76 | /// options 77 | graph::partition_fn partitioner(int mode = 1, int seed = 1, 78 | double imbalance = 0.03, 79 | bool suppress_output = true); 80 | #endif 81 | } // namespace kahip 82 | 83 | } // namespace dolfinx::graph 84 | -------------------------------------------------------------------------------- /cpp/dolfinx/io/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HEADERS_io 2 | ${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_io.h 3 | ${CMAKE_CURRENT_SOURCE_DIR}/ADIOS2Writers.h 4 | ${CMAKE_CURRENT_SOURCE_DIR}/cells.h 5 | ${CMAKE_CURRENT_SOURCE_DIR}/HDF5Interface.h 6 | ${CMAKE_CURRENT_SOURCE_DIR}/vtk_utils.h 7 | ${CMAKE_CURRENT_SOURCE_DIR}/VTKFile.h 8 | ${CMAKE_CURRENT_SOURCE_DIR}/VTKHDF.h 9 | ${CMAKE_CURRENT_SOURCE_DIR}/XDMFFile.h 10 | ${CMAKE_CURRENT_SOURCE_DIR}/xdmf_function.h 11 | ${CMAKE_CURRENT_SOURCE_DIR}/xdmf_mesh.h 12 | ${CMAKE_CURRENT_SOURCE_DIR}/xdmf_utils.h 13 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.h 14 | PARENT_SCOPE 15 | ) 16 | 17 | target_sources( 18 | dolfinx 19 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ADIOS2Writers.cpp 20 | ${CMAKE_CURRENT_SOURCE_DIR}/cells.cpp 21 | ${CMAKE_CURRENT_SOURCE_DIR}/HDF5Interface.cpp 22 | ${CMAKE_CURRENT_SOURCE_DIR}/VTKFile.cpp 23 | ${CMAKE_CURRENT_SOURCE_DIR}/vtk_utils.cpp 24 | ${CMAKE_CURRENT_SOURCE_DIR}/XDMFFile.cpp 25 | ${CMAKE_CURRENT_SOURCE_DIR}/xdmf_function.cpp 26 | ${CMAKE_CURRENT_SOURCE_DIR}/xdmf_mesh.cpp 27 | ${CMAKE_CURRENT_SOURCE_DIR}/xdmf_utils.cpp 28 | ) 29 | -------------------------------------------------------------------------------- /cpp/dolfinx/io/VTKFile.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2020 Garth N. Wells 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace pugi 18 | { 19 | class xml_document; 20 | } 21 | 22 | namespace dolfinx::fem 23 | { 24 | template 25 | class Function; 26 | } 27 | 28 | namespace dolfinx::mesh 29 | { 30 | template 31 | class Mesh; 32 | } 33 | 34 | namespace dolfinx::io 35 | { 36 | 37 | /// @brief Output of meshes and functions in VTK/ParaView format. 38 | /// 39 | /// Isoparametric meshes of arbitrary degree are supported. For finite 40 | /// element functions, cell-based (DG0) and Lagrange (point-based) 41 | /// functions can be saved. For vertex-based functions the output must 42 | /// be isoparametic, i.e. the geometry and the finite element functions 43 | /// must be defined using the same basis. 44 | /// 45 | /// @warning This format is not suitable for checkpointing. 46 | class VTKFile 47 | { 48 | public: 49 | /// Create VTK file 50 | VTKFile(MPI_Comm comm, const std::filesystem::path& filename, 51 | const std::string& file_mode); 52 | 53 | /// Destructor 54 | ~VTKFile(); 55 | 56 | /// Close file 57 | void close(); 58 | 59 | /// Flushes XML files to disk 60 | void flush(); 61 | 62 | /// @brief Write a mesh to file. Supports arbitrary order Lagrange 63 | /// isoparametric cells. 64 | /// @param[in] mesh Mesh to write to file. 65 | /// @param[in] time Time parameter to associate with `mesh`. 66 | template 67 | void write(const mesh::Mesh& mesh, double time = 0.0); 68 | 69 | /// @brief Write finite elements function with an associated time 70 | /// step. 71 | /// 72 | /// @pre Functions in `u` cannot be sub-Functions. Extract 73 | /// sub-Functions before output. 74 | /// 75 | /// @pre All Functions in `u` with point-wise data must use the same 76 | /// element type (up to the block size) and the element must be 77 | /// (discontinuous) Lagrange. Interpolate fem::Function before output 78 | /// if required. 79 | /// 80 | /// @param[in] u List of functions to write to file 81 | /// @param[in] t Time parameter to associate with @p u 82 | /// @pre All Functions in `u` must share the same mesh 83 | template > 84 | void 85 | write(const std::vector>>& u, 86 | double t); 87 | 88 | private: 89 | std::unique_ptr _pvd_xml; 90 | 91 | std::filesystem::path _filename; 92 | 93 | // MPI communicator 94 | dolfinx::MPI::Comm _comm; 95 | }; 96 | } // namespace dolfinx::io 97 | -------------------------------------------------------------------------------- /cpp/dolfinx/io/dolfinx_io.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// @brief Support for file IO. 4 | /// 5 | /// IO to files for checkpointing and visualisation. 6 | namespace dolfinx::io 7 | { 8 | } 9 | 10 | // DOLFINx io interface 11 | 12 | #include 13 | #include 14 | #include 15 | -------------------------------------------------------------------------------- /cpp/dolfinx/io/vtk_utils.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2005-2022 Garth N. Wells and Jørgen S. Dokken 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #include "vtk_utils.h" 8 | #include "cells.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | using namespace dolfinx; 20 | 21 | //----------------------------------------------------------------------------- 22 | std::pair, std::array> 23 | io::extract_vtk_connectivity( 24 | md::mdspan> dofmap_x, 25 | mesh::CellType cell_type) 26 | { 27 | // Get DOLFINx to VTK permutation 28 | const std::size_t num_nodes = dofmap_x.extent(1); 29 | std::vector vtkmap 30 | = io::cells::transpose(io::cells::perm_vtk(cell_type, num_nodes)); 31 | 32 | // Extract mesh 'nodes' 33 | const std::size_t num_cells = dofmap_x.extent(0); 34 | 35 | // Build mesh connectivity 36 | 37 | // Loop over cells 38 | std::array shape = {num_cells, num_nodes}; 39 | std::vector topology(shape[0] * shape[1]); 40 | for (std::size_t c = 0; c < num_cells; ++c) 41 | { 42 | // For each cell, get the 'nodes' and place in VTK order 43 | for (std::size_t i = 0; i < num_nodes; ++i) 44 | topology[c * shape[1] + i] = dofmap_x(c, vtkmap[i]); 45 | } 46 | 47 | return {std::move(topology), shape}; 48 | } 49 | //----------------------------------------------------------------------------- 50 | -------------------------------------------------------------------------------- /cpp/dolfinx/io/xdmf_function.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2012-2023 Chris N. Richardson and Garth N. Wells 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace pugi 16 | { 17 | class xml_node; 18 | } // namespace pugi 19 | 20 | namespace dolfinx 21 | { 22 | namespace fem 23 | { 24 | template 25 | class Function; 26 | } 27 | 28 | /// Low-level methods for reading/writing XDMF files 29 | namespace io::xdmf_function 30 | { 31 | 32 | /// Write a fem::Function to XDMF 33 | template 34 | void add_function(MPI_Comm comm, const fem::Function& u, double t, 35 | pugi::xml_node& xml_node, const hid_t h5_id); 36 | } // namespace io::xdmf_function 37 | } // namespace dolfinx 38 | -------------------------------------------------------------------------------- /cpp/dolfinx/la/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HEADERS_la 2 | ${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_la.h 3 | ${CMAKE_CURRENT_SOURCE_DIR}/MatrixCSR.h 4 | ${CMAKE_CURRENT_SOURCE_DIR}/matrix_csr_impl.h 5 | ${CMAKE_CURRENT_SOURCE_DIR}/SparsityPattern.h 6 | ${CMAKE_CURRENT_SOURCE_DIR}/Vector.h 7 | ${CMAKE_CURRENT_SOURCE_DIR}/petsc.h 8 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.h 9 | ${CMAKE_CURRENT_SOURCE_DIR}/slepc.h 10 | PARENT_SCOPE 11 | ) 12 | 13 | target_sources( 14 | dolfinx 15 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/SparsityPattern.cpp 16 | ${CMAKE_CURRENT_SOURCE_DIR}/petsc.cpp 17 | ${CMAKE_CURRENT_SOURCE_DIR}/slepc.cpp 18 | ) 19 | -------------------------------------------------------------------------------- /cpp/dolfinx/la/dolfinx_la.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// @brief Linear algebra interface. 4 | /// 5 | /// Interface to linear algebra data structures and solvers. 6 | namespace dolfinx::la 7 | { 8 | } 9 | 10 | // DOLFINx la interface 11 | 12 | #include 13 | #ifdef HAS_PETSC 14 | #include 15 | #endif 16 | #include 17 | #include 18 | -------------------------------------------------------------------------------- /cpp/dolfinx/la/slepc.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2005-2018 Garth N. Wells 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #ifdef HAS_SLEPC 10 | 11 | #include "dolfinx/common/MPI.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace dolfinx::la 19 | { 20 | 21 | /// @brief This class provides an eigenvalue solver for PETSc matrices. 22 | /// It is a wrapper for the SLEPc eigenvalue solver. 23 | class SLEPcEigenSolver 24 | { 25 | public: 26 | /// Create eigenvalue solver 27 | explicit SLEPcEigenSolver(MPI_Comm comm); 28 | 29 | /// Create eigenvalue solver from EPS object 30 | SLEPcEigenSolver(EPS eps, bool inc_ref_count); 31 | 32 | // Delete copy constructor 33 | SLEPcEigenSolver(const SLEPcEigenSolver&) = delete; 34 | 35 | /// Move constructor 36 | SLEPcEigenSolver(SLEPcEigenSolver&& solver); 37 | 38 | /// Destructor 39 | ~SLEPcEigenSolver(); 40 | 41 | // Assignment operator (disabled) 42 | SLEPcEigenSolver& operator=(const SLEPcEigenSolver&) = delete; 43 | 44 | /// Move assignment 45 | SLEPcEigenSolver& operator=(SLEPcEigenSolver&& solver); 46 | 47 | /// Set operators (B may be nullptr for regular eigenvalues 48 | /// problems) 49 | void set_operators(const Mat A, const Mat B); 50 | 51 | /// Compute all eigenpairs of the matrix A (solve \f$A x = \lambda x\f$) 52 | void solve(); 53 | 54 | /// Compute the n first eigenpairs of the matrix A 55 | /// (solve \f$A x = \lambda x\f$) 56 | void solve(std::int64_t n); 57 | 58 | /// Get ith eigenvalue 59 | std::complex get_eigenvalue(int i) const; 60 | 61 | /// Get ith eigenpair 62 | void get_eigenpair(PetscScalar& lr, PetscScalar& lc, Vec r, Vec c, 63 | int i) const; 64 | 65 | /// Get the number of iterations used by the solver 66 | int get_iteration_number() const; 67 | 68 | /// Get the number of converged eigenvalues 69 | std::int64_t get_number_converged() const; 70 | 71 | /// Sets the prefix used by PETSc when searching the PETSc options 72 | /// database 73 | void set_options_prefix(std::string options_prefix); 74 | 75 | /// Returns the prefix used by PETSc when searching the PETSc options 76 | /// database 77 | std::string get_options_prefix() const; 78 | 79 | /// Set options from PETSc options database 80 | void set_from_options() const; 81 | 82 | /// Return SLEPc EPS pointer 83 | EPS eps() const; 84 | 85 | /// Return MPI communicator 86 | MPI_Comm comm() const; 87 | 88 | private: 89 | // SLEPc solver pointer 90 | EPS _eps; 91 | }; 92 | } // namespace dolfinx::la 93 | #endif 94 | -------------------------------------------------------------------------------- /cpp/dolfinx/la/utils.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018-2022 Garth N. Wells 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace dolfinx::la 14 | { 15 | /// Norm types 16 | enum class Norm 17 | { 18 | l1, 19 | l2, 20 | linf, 21 | frobenius 22 | }; 23 | 24 | /// @brief Matrix accumulate/set concept for functions that can be used 25 | /// in assemblers to accumulate or set values in a matrix. 26 | template 27 | concept MatSet 28 | = std::invocable, 29 | std::span, std::span>; 30 | } // namespace dolfinx::la 31 | -------------------------------------------------------------------------------- /cpp/dolfinx/mesh/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HEADERS_mesh 2 | ${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_mesh.h 3 | ${CMAKE_CURRENT_SOURCE_DIR}/Mesh.h 4 | ${CMAKE_CURRENT_SOURCE_DIR}/Geometry.h 5 | ${CMAKE_CURRENT_SOURCE_DIR}/Topology.h 6 | ${CMAKE_CURRENT_SOURCE_DIR}/MeshTags.h 7 | ${CMAKE_CURRENT_SOURCE_DIR}/cell_types.h 8 | ${CMAKE_CURRENT_SOURCE_DIR}/generation.h 9 | ${CMAKE_CURRENT_SOURCE_DIR}/graphbuild.h 10 | ${CMAKE_CURRENT_SOURCE_DIR}/permutationcomputation.h 11 | ${CMAKE_CURRENT_SOURCE_DIR}/topologycomputation.h 12 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.h 13 | PARENT_SCOPE 14 | ) 15 | 16 | target_sources( 17 | dolfinx 18 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Topology.cpp 19 | ${CMAKE_CURRENT_SOURCE_DIR}/cell_types.cpp 20 | ${CMAKE_CURRENT_SOURCE_DIR}/graphbuild.cpp 21 | ${CMAKE_CURRENT_SOURCE_DIR}/permutationcomputation.cpp 22 | ${CMAKE_CURRENT_SOURCE_DIR}/topologycomputation.cpp 23 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp 24 | ) 25 | -------------------------------------------------------------------------------- /cpp/dolfinx/mesh/dolfinx_mesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// @brief Mesh data structures and algorithms on meshes 4 | /// 5 | /// Representations of meshes and support for operations on meshes. 6 | namespace dolfinx::mesh 7 | { 8 | } 9 | 10 | // DOLFINx mesh interface 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | -------------------------------------------------------------------------------- /cpp/dolfinx/mesh/topologycomputation.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2006-2024 Anders Logg and Garth N. Wells 2 | // 3 | // This file is part of DOLFINx (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include "cell_types.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace dolfinx::common 17 | { 18 | class IndexMap; 19 | } 20 | 21 | namespace dolfinx::graph 22 | { 23 | template 24 | class AdjacencyList; 25 | } 26 | 27 | namespace dolfinx::mesh 28 | { 29 | class Topology; 30 | 31 | /// @brief Compute mesh entities of given topological dimension by 32 | /// computing cell-to-entity `(tdim, i) -> `(dim, entity_type)` and 33 | /// entity-to-vertex connectivity `(dim, entity_type) -> `(0, 0)` 34 | /// connectivity. 35 | /// 36 | /// Computed entities are oriented such that their local (to the 37 | /// process) orientation agrees with their global orientation 38 | /// 39 | /// @param[in] topology Mesh topology. 40 | /// @param[in] dim Dimension of the entities to create. 41 | /// @param[in] entity_type Entity type in dimension `dim` to create. 42 | /// Entity type must be in the list returned by Topology::entity_types. 43 | /// @return Tuple of (cell->entity connectivity, entity->vertex 44 | /// connectivity, index map for created entities, list of interprocess 45 | /// entities). Interprocess entities lie on the "true" boundary between 46 | /// owned cells of each process. If entities of type `entity_type` 47 | /// already exists, then {nullptr, nullptr, nullptr, std::vector()} is 48 | /// returned. 49 | std::tuple>>, 50 | std::shared_ptr>, 51 | std::shared_ptr, std::vector> 52 | compute_entities(const Topology& topology, int dim, CellType entity_type); 53 | 54 | /// @brief Compute connectivity (d0 -> d1) for given pair of entity 55 | /// types, given by topological dimension and index, as found in 56 | /// `Topology::entity_types()` 57 | /// @param[in] topology The topology 58 | /// @param[in] d0 Dimension and index of the entities, `(dim0, i)`. 59 | /// @param[in] d1 Dimension and index of the incident entities, `(dim1, 60 | /// j)`. 61 | /// @returns The connectivities [(d0 -> d1), (d1 -> d0)] if they are 62 | /// computed. If (d0, d1) already exists then a nullptr is returned. If 63 | /// (d0, d1) is computed and the computation of (d1, d0) was required as 64 | /// part of computing (d0, d1), the (d1, d0) is returned as the second 65 | /// entry. The second entry is otherwise nullptr. 66 | std::array>, 2> 67 | compute_connectivity(const Topology& topology, std::array d0, 68 | std::array d1); 69 | 70 | } // namespace dolfinx::mesh 71 | -------------------------------------------------------------------------------- /cpp/dolfinx/nls/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HEADERS_nls 2 | ${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_nls.h 3 | ${CMAKE_CURRENT_SOURCE_DIR}/NewtonSolver.h 4 | PARENT_SCOPE 5 | ) 6 | 7 | target_sources(dolfinx PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/NewtonSolver.cpp) 8 | -------------------------------------------------------------------------------- /cpp/dolfinx/nls/dolfinx_nls.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// @brief Nonlinear solvers. 4 | /// 5 | /// Methods for solving nonlinear equations. 6 | namespace dolfinx::nls 7 | { 8 | } 9 | 10 | // DOLFINx nonlinear solver 11 | 12 | #ifdef HAS_PETSC 13 | #include 14 | #endif 15 | -------------------------------------------------------------------------------- /cpp/dolfinx/refinement/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HEADERS_refinement 2 | ${CMAKE_CURRENT_SOURCE_DIR}/dolfinx_refinement.h 3 | ${CMAKE_CURRENT_SOURCE_DIR}/interval.h 4 | ${CMAKE_CURRENT_SOURCE_DIR}/plaza.h 5 | ${CMAKE_CURRENT_SOURCE_DIR}/refine.h 6 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.h 7 | ${CMAKE_CURRENT_SOURCE_DIR}/option.h 8 | PARENT_SCOPE 9 | ) 10 | 11 | target_sources( 12 | dolfinx PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/plaza.cpp 13 | ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp 14 | ) 15 | -------------------------------------------------------------------------------- /cpp/dolfinx/refinement/dolfinx_refinement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// @brief Mesh refinement algorithms. 4 | /// 5 | /// Methods for refining meshes uniformly, or with markers, using edge 6 | /// bisection. 7 | namespace dolfinx::refinement 8 | { 9 | } 10 | 11 | // DOLFINx refinement interface 12 | 13 | #include 14 | #include 15 | -------------------------------------------------------------------------------- /cpp/dolfinx/refinement/option.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2024 Paul T. Kühner 2 | // 3 | // This file is part of DOLFINX (https://www.fenicsproject.org) 4 | // 5 | // SPDX-License-Identifier: LGPL-3.0-or-later 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace dolfinx::refinement 13 | { 14 | /// @brief Options for data to compute during mesh refinement. 15 | enum class Option : std::uint8_t 16 | { 17 | none = 0b00, /*!< No extra data */ 18 | parent_facet = 0b01, /*!< Compute list of the cell-local facet indices in the 19 | parent cell of each facet in each new cell (or -1 if no match) */ 20 | parent_cell 21 | = 0b10, /*!< Compute list with the parent cell index for each new cell */ 22 | parent_cell_and_facet = 0b11 /*< Both cell and facet parent data */ 23 | }; 24 | 25 | /// @brief Combine two refinement options into one, both flags will be 26 | /// set for the resulting option. 27 | inline constexpr Option operator|(Option a, Option b) 28 | { 29 | using bitmask_t = std::underlying_type_t