MFEM Documentation

repository·master·Indexed 25 days ago

https://github.com/mfem/mfem

MFEM is a modular parallel C++ library for finite element methods, designed for high-performance scalable discretization research and application development. It supports platforms ranging from laptops to supercomputers and includes tools for Docker-based development, Jupyter Notebook integration via xeus-cling, and specialized miniapps for contact mechanics and diagonal smoothers.

Tokens
9.4K
Snippets
20
Records
53
Agent score
75%

What's inside MFEM

  1. Overview of MFEM git hooks

    master

    MFEM provides two primary git hooks to maintain code quality and repository health:

    • pre-commit: Runs astyle on your code before every commit to ensure changes comply with MFEM code styling guidelines.
    • pre-push: Runs a suite of tests before every push to verify that file headers are compliant and that no unexpectedly large files have been added to the repository.
  2. Overview of MFEM capabilities

    master

    MFEM is a modular parallel C++ library designed for high-performance scalable finite element discretization. It functions as a 'finite element toolbox' similar to how MATLAB works for linear algebra, providing building blocks for developing complex algorithms.

    Key Capabilities:

    • Finite Element Spaces: Supports arbitrary high-order H1-conforming, discontinuous (L2), H(div)-conforming, H(curl)-conforming, and NURBS spaces in 2D and 3D.
    • Discretization Methods: Enables prototyping of Galerkin methods, mixed finite elements, Discontinuous Galerkin (DG), isogeometric analysis, hybridization, and Discontinuous Petrov-Galerkin (DPG) approaches.
    • Mesh Support: Handles triangular, quadrilateral, tetrahedral, and hexahedral meshes, including surface and topologically periodical meshes. Supports mesh refinement (AMR) and high-order elements with curved boundaries via arbitrary element transformations.
    • Linear Algebra Translation: Translates finite element objects into linear algebra vectors and assembled operators (global sparse matrices or matrix-free operators).
    • Solvers & Integrators: Includes smoothers, Krylov solvers (PCG, MINRES, GMRES), nonlinear solvers (Newton method), eigensolvers (LOBPCG), and Runge-Kutta time integrators.
    • Parallelism & Acceleration: Supports MPI-based parallelism and GPU acceleration via CUDA, HIP, OCCA, RAJA, and OpenMP. It integrates with external libraries like hypre, PETSc, SUNDIALS, and libCEED.
  3. Overview of Incompressible Schrödinger Flow (ISF)

    master

    Incompressible Schrödinger Flow (ISF) is a $\mathbb{C}^2$-valued Schrödinger equation used to model classical incompressible fluids. Based on Madelung's quantum hydrodynamics, it is particularly effective at capturing thin vortex behaviors.

    The method solves the equation $i\hbar \partial\Psi/\partial t = -\frac{1}{2}\hbar^2\Delta\Psi + p\Psi$ subject to the constraints $\text{Re}(\langle\Delta\Psi, i\Psi\rangle) = 0$ and $|\Psi|^2 = 1$.

  4. What is AMG with Filtering (AMGF)?

    master

    The AMGF preconditioner is designed for large-scale contact mechanics optimization. It extends classical Algebraic Multigrid (AMG) by adding a targeted small-subspace correction restricted to degrees of freedom involved in active contact constraints.

    Why use it? Classical AMG performance typically degrades in late-stage Interior Point (IP) iterations where contact constraints dominate. AMGF improves convergence by addressing this specific subspace.

    Requirements:

    • To use -amgf, MFEM must be built with a parallel sparse direct solver, specifically MUMPS (MFEM_USE_MUMPS=YES) or CPardiso (MFEM_USE_CPARDISO=YES).
    • If no direct solver is available, you can use standard AMG, but it may exhibit slower or stagnating convergence.
  5. Configure basis types for spectrally equivalent LOR solvers

    master

    To ensure Low-Order Refined (LOR) solvers are effective and spectrally equivalent to their high-order counterparts, you must use specific basis types for the high-order space:

    • H1 spaces: Use BasisType::GaussLobatto.
    • Nedelec and Raviart-Thomas spaces:
      • Closed basis: Use BasisType::GaussLobatto.
      • Open basis: Use BasisType::IntegratedGLL.
  6. The ISF Simulation Pipeline

    master

    The Incompressible Schrödinger Flow simulation is implemented using a splitting method consisting of the following five steps:

    1. Linear Schrödinger equation solver: Solves the base equation.
    2. Normalization of the wave function: Ensures the wave function satisfies the required constraints.
    3. Pressure projection: Applies the incompressibility constraint.
    4. Enforce geometry constraints: Handles boundary or domain-specific constraints.
    5. Compute velocity field: Generates the velocity field used for visualization.
  7. Understand Absolute-value L(1)-Jacobi assembly levels

    master

    The Abs-Value-L(1)-Jacobi preconditioner is designed to work with different assembly levels. The implementation focuses on AssemblyLevel::PARTIAL.

    Given the FEM operator structure $A = P^T G^T B^T D B G P$, the standard L(1)-Jacobi is $D_1 = \text{diag}(|A|1)$. Using the triangle inequality, the absolute-value version $D{abs} = \text{diag}(|P^T| |G^T| |B^T| |D| |B| |G| |P|_1)$ is also $A$-convergent.

    In MFEM, you can use the AbsMult operator to unwrap a composition of different operators as their absolute-value application. Similar run-time options are available for this purpose.

  8. Load MFEM in xeus-cling notebooks

    master

    When using xeus-cling to run MFEM code in a Jupyter notebook, you must explicitly load the MFEM shared library into the cling interpreter. This is done using a #pragma directive at the beginning of your notebook cells.

    If the library is not in the default search path, you may also need to use #pragma cling statements to configure the runtime environment to locate your MFEM and GLVis installations.

    #pragma cling load("mfem")
  9. Set up MFEM git hooks

    master

    To improve your development experience and ensure compliance with MFEM coding standards, you can install recommended git hooks. Running the provided make command creates symlinks from the config/githooks directory to your local .git/hooks directory.

    Alternatively, you can enable individual hooks by manually creating symlinks to specific scripts in the config/githooks directory.

    make hooks
  10. Use the mfem-ubuntu-base container for MFEM development with Spack

    master

    The ghcr.io/mfem/mfem-ubuntu-base container is designed for developers working on MFEM itself. It uses Spack to manage the environment.

    Workflow:

    1. Shell into the container.
    2. Source the Spack environment.
    3. Activate the MFEM environment located at /opt/mfem-env/.
    4. Use spack install to update the environment (note: concretization may take a while).
    5. Use spack load mfem to load the library into your path.

    Development Tip: To develop your own project using the MFEM environment, you can bind your local project directory to the /code directory inside the container: docker run -it ghcr.io/mfem/mfem-ubuntu-base -v $PWD:/code bash

    # Build the base image
    docker build -f config/docker/Dockerfile.base -t ghcr.io/mfem/mfem-ubuntu-base .
    
    # Run and enter the container
    docker run -it ghcr.io/mfem/mfem-ubuntu-base bash
    
    # Inside the container: setup Spack and activate environment
    source /opt/spack/share/spack/setup-env.sh
    cd /opt/mfem-env/
    spack env activate .
    
    # Load mfem
    spack load mfem
  11. Extend the miniapp with custom topologies

    master

    The miniapp is designed to be extensible. To implement a new topology (e.g., different microstructures), you must implement an appropriate distance metric by creating a child class of MaterialTopology.

    After implementing your class, you must swap the instantiation line in generate_random_field.cpp to use your new object instead of the default particle or octet truss implementations.