30 minutes advanced
Write a simple simulation by extending existing examples.
Learn more about MFEM and join the community.
Explore additional examples and miniapps
MFEM includes a number of well-documented example codes and miniapps that can be used as tutorials, as well as simple starting points for user applications.
These examples and miniapps are available in the
subdirectories of your VS Code terminal.
The full list of examples is below. Feel free to explore any of them depending on your interests, but we recommend starting with the ones marked with a ⭐.
- Example 0 — Simplest MFEM example, good starting point for new users (nodal H1 FEM for the Laplace problem). ⭐
- Example 1 — Nodal H1 FEM for the Laplace problem. ⭐
- Example 2 — Vector FEM for linear elasticity.
- Example 3 — Nedelec H(curl) FEM for the definite Maxwell problem.
- Example 4 — Raviart-Thomas H(div) FEM for the grad-div problem.
- Example 5 — Mixed pressure-velocity FEM for the Darcy problem.
- Example 6 — Non-conforming adaptive mesh refinement (AMR) for the Laplace problem.
- Example 7 — Laplace problem on a surface (the unit sphere). ⭐
- Example 8 — Discontinuous Petrov-Galerkin (DPG) for the Laplace problem.
- Example 9 — Discontinuous Galerkin (DG) time-dependent advection. ⭐
- Example 10 — Time-dependent implicit nonlinear elasticity. ⭐
- Example 11 — Parallel Laplace eigensolver.
- Example 12 — Parallel linear elasticity eigensolver.
- Example 13 — Parallel Maxwell eigensolver.
- Example 14 — DG for the Laplace problem.
- Example 15 — Dynamic AMR for Laplace with prescribed time-dependent source. ⭐
- Example 16 — Time-dependent nonlinear heat equation.
- Example 17 — DG for linear elasticity.
- Example 18 — DG for the Euler equations.
- Example 19 — Incompressible nonlinear elasticity.
- Example 20 — Symplectic ODE integration.
- Example 21 — AMR for linear elasticity.
- Example 22 — Complex-valued linear systems. ⭐
- Example 23 — Second-order in time wave equation. ⭐
- Example 24 — Mixed finite element spaces and interpolators.
- Example 25 — Perfectly Matched Layer (PML) for Maxwell equations.
- Example 26 — Multigrid preconditioner for the Laplace problem. ⭐
- Example 27 — Boundary conditions for the Laplace problem.
- Example 28 — Constraints and sliding boundary conditions.
- Example 29 — Solving PDEs on embedded surfaces.
- Example 30 — Mesh preprocessing, resolving problem data.
- Example 31 — Nedelec H(curl) FEM for the anisotropic definite Maxwell problem.
- Example 32 — Parallel Nedelec Maxwell eigensolver with anisotropic permittivity.
Most of these examples have a serial and a parallel version, illustrating the ease of transition and the minimal code changes between the two.
Many examples also have modifications that take advantage of optional third-party libraries such as PETSc, SLEPc, SUNDIALS, PUMI, Ginkgo, and HiOp.
Beyond the examples, a number of miniapps are available that are more representative of the advanced usage of the library in physics/application codes. Some of the included miniapps are:
- Volta — Simple electrostatics simulation code.
- Tesla — Simple magnetostatics simulation code.
- Maxwell — Transient electromagnetics simulation code.
- Joule — Transient magnetics and Joule heating miniapp.
- Navier — Solver for the incompressible time-dependent Navier-Stokes equations.
- Mesh Explorer — Visualize and manipulate meshes.
- Mesh Optimizer — Optimize high-order meshes.
- Shaper — Resolve material interfaces by mesh refinement.
- Interpolation — Evaluation of high-order finite element functions in physical space.
- Overlapping Grids — Schwarz coupling of single- and multi-physics problems.
- Extrapolation — Finite element extrapolation solver.
- Distance — Finite element distance solver.
- Shifted Diffusion — High-Order shifted boundary method for non body-fitted meshes.
- Minimal Surface — Compute the minimal surface of a given mesh.
- Display Basis — Visualize finite element basis functions.
- LOR Transfer — Map functions between high-order and low-order-refined spaces.
In addition, the sources for several external benchmark/proxy-apps built on top of MFEM are available:
- Laghos — High-Order Lagrangian hydrodynamics miniapp.
- Remhos — High-Order advection remap miniapp.
- Mulard — Multigroup thermal radiation diffusion miniapp.
A handful of "toy" miniapps of a less serious nature demonstrate the flexibility of MFEM (and provide a bit of fun):
- Automata — Model of a simple cellular automata.
- Life — Model of Conway's game of life.
- Lissajous — Spinning optical illusion.
- Mandel — Fractal visualization with AMR.
- Mondrian — Convert any image to an AMR mesh.
- Rubik — Interactive Rubik's Cube™ puzzle.
- Snake — Model of the Rubik's Snake™ puzzle.
Write a simple simulation
Modify the miniapps and example codes to create a simple simulation of your
own. You can edit the source code and rebuild the binary simply
For example, you can solve a steady-state heat conduction problem in 2D and 3D
shaper miniapp (modified for the cable shape) to define the mesh and
ex1p to solve it (modified to include separate coefficients for air
Please consult the MFEM code documentation and don't hesitate to ask if you have any implementation questions.
We want to see your creativity!
Install MFEM + GLVis on your own machine
Download MFEM from mfem.org/download or clone it from GitHub and follow the building instructions here: mfem.org/building.
You should be able to download and install the serial version in 10 minutes. The parallel version of MFEM requires installing hypre and METIS (see the building instructions).
Alternatively, if you already have Spack, you can build with
spack install mfem glvis.
With your own installation, you can explore additional topics not covered in this tutorial such as:
Partial Assembly and the Finite Element Operator Decomposition.
GPU Support on NVIDIA and AMD hardware.
Integrations with PETSc, SUNDIALS, SuperLU, libCEED, PUMI, Ginkgo, HiOp, and more.
Python support with the PyMFEM wrapper.
Visit the MFEM website
For more information about MFEM, visit the website, mfem.org, including the
- Publications, and
- Finite Elements, pages.
Review the Videos for recordings from MFEM seminars, workshops, and conference presentations:
You may also be interested in visiting the websites of the related GLVis, CEED, and BLAST projects.
Join the community
If MFEM looks exciting to you, please join the community on GitHub and help us make it better! 🚀
We welcome contributions and feedback at all levels: bugfixes; code improvements; simplifications; new mesh, discretization, or solver capabilities; improved documentation; new examples and miniapps; HPC performance improvements; etc. See CONTRIBUTING.md for more details.
You can contact the MFEM team by posting to the GitHub issue tracker or at firstname.lastname@example.org.
Back to the MFEM tutorial page