In the field of scientific computing, the Finite Element Method (FEM) is a commonly used numerical tool for handling partial differential equation (PDE) problems. Whether in structural mechanics, electromagnetic fields, or fluid mechanics, FEM can provide efficient computational solutions for complex physical problems. This article introduces an open-source library widely used across various high-performance computing platforms—MFEM . With its flexible, scalable, and high-performance features, this library assists researchers and engineers in developing advanced finite element algorithms across different computing environments. It has also been recommended by some followers of this account.
MFEM official website, reference [1]
What is MFEM?
MFEM, short for “Modular Finite Element Methods,” is a lightweight, scalable C++ library developed by LLNL (Lawrence Livermore National Laboratory). It aims to help users develop efficient finite element discretization algorithms, capable of scaling from personal computers to GPU-accelerated supercomputers. MFEM is not only an open-source library but also a “toolbox” in the finite element field, offering rich building blocks to simplify the development of complex finite element algorithms, similar to MATLAB’s role in linear algebra methods.
Key Features
- High-Order Finite Element Spaces
- MFEM supports various high-order finite element spaces, including H1, H(div), H(curl), etc. It also supports discontinuous L2 spaces, numerical trace spaces, and NURBS spaces for isogeometric analysis, meeting various complex computational needs.
- Flexible Discretization Methods
- Mixed Finite Elements
- Discontinuous Galerkin (DG) Methods
- Isogeometric Analysis
- Discontinuous Petrov-Galerkin (DPG) Methods
Discontinuous Petrov-Galerkin (DPG) method, selected from reference [2]
- Hybridization and static condensation methods for high-order problems.
- MFEM allows rapid prototyping of different finite element methods.
- Extensive Mesh Support
- Supports various mesh elements like triangles, quadrilaterals, hexahedra, etc. MFEM can handle arbitrary mesh transformations, providing local mesh optimization, surface embedding, and high-order mesh optimization features. With integration with the PUMI distributed mesh management system, it also supports automatic adaptive analysis and parallel mesh modification.
- Parallel, Scalable, and GPU Support
- MFEM is designed to support traditional MPI parallel computing and is compatible with GPU acceleration (CUDA, HIP, RAJA, etc.). Whether on hundreds of parallel cores or GPU-accelerated supercomputers, MFEM can execute efficiently.
- Built-in Solvers
- MFEM is not only a “translator” from finite elements to linear algebra but also integrates a rich library of solvers, including Krylov subspace methods, AMG preconditioners, and efficient sparse matrix solvers. Additionally, MFEM seamlessly integrates with high-performance libraries like hypre, PETSc, and SLEPc, supporting various types of linear and nonlinear equation solving.
- Automatic Differentiation (AD)
- MFEM integrates automatic differentiation capabilities, allowing users to achieve precise derivative calculations through C++ lambda expressions or functors. Unlike symbolic differentiation or numerical approximation, automatic differentiation provides completely accurate derivative results. MFEM’s AD implementation supports forward and reverse modes and is based on local dual numbers and the external library CoDiPack. Users can choose the optimal automatic differentiation engine according to their needs, making this feature particularly suitable for applications like topology optimization.
- Rich Example Code
- For beginners and advanced users, MFEM offers numerous example codes ranging from simple to complex, covering various finite element applications like Laplace problems, linear elasticity, electromagnetic problems, and discontinuous Galerkin methods, helping users quickly get started with development. Some example codes are shown in the image below, and you will certainly find examples of interest :
A large number of official example codes, selected from reference [6]
Application Scenarios and Real Cases
MFEM has been widely used in several well-known research projects, such as:
- BLAST: Used for shock wave dynamics simulation
- Cardioid: Heart simulation project
- Palace: Electromagnetic simulation project
- CEED: Center for Efficient Exascale Discretizations in Exascale computing projects
MFEM solution for nonlinear elasticity problems, selected from reference [2]
Topology optimization of a drone fuselage using LLNL’s LiDO project based on MFEM, selected from references [3,4]
Additionally, MFEM provides several mini-applications and physical problem codes, such as electromagnetic, fluid dynamics, and mesh optimization problems, helping users directly apply them in research work.
Visualization and Extensibility
MFEM is compatible with multiple visualization tools, such as GLVis, VisIt, and ParaView, capable of accurately displaying high-order meshes and finite element functions. These tools allow users to easily view and analyze simulation results. Moreover, MFEM adopts a modular design, with a small codebase, facilitating cross-platform use and offering high extensibility.
Magnetic field streamlines obtained from the static magnetic interaction of two magnetic spheres using parallel computing on the MFEM platform, visualized with VTK, selected from reference [4]
Conclusion
MFEM provides a powerful finite element computing platform by integrating rich features and functionalities, including automatic differentiation and parallel computing support. Its flexible architecture and efficient performance have led to its widespread application in scientific computing and engineering simulations. Interested readers can learn more through the references provided in this article.
Reference
[1] https://mfem.org/
[2] MFEM - Finite Element Discretization Library
[3] https://str.llnl.gov/past-issues/march-2018/leading-revolution-design
[4] MFEM - Finite Element Discretization Library
[5] GitHub - mfem/mfem: Lightweight, general, scalable C++ library for finite element methods
[6] MFEM - Finite Element Discretization Library