Further Steps
30 minutes advanced
Lesson Objectives
Write a simple simulation by extending existing examples.
Learn more about MFEM and join the community.
Note
Explore additional examples and miniapps
MFEM includes a number of welldocumented 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 mfem/examples
and mfem/miniapps
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 — RaviartThomas H(div) FEM for the graddiv problem.
 Example 5 — Mixed pressurevelocity FEM for the Darcy problem.
 Example 6 — Nonconforming adaptive mesh refinement (AMR) for the Laplace problem.
 Example 7 — Laplace problem on a surface (the unit sphere). ⭐
 Example 8 — Discontinuous PetrovGalerkin (DPG) for the Laplace problem.
 Example 9 — Discontinuous Galerkin (DG) timedependent advection. ⭐
 Example 10 — Timedependent 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 timedependent source. ⭐
 Example 16 — Timedependent 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 — Complexvalued linear systems. ⭐
 Example 23 — Secondorder 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.
 Example 33 — Nodal C0 FEM for the fractional Laplacian problem.
 Example 34 — Source function from SubMesh.
 Example 35 — Port boundary condition from SubMesh.
 Example 36 — Highorder FEM for the obstacle problem.
 Example 37 — Topology optimization.
 Example 38 — Cutsurface and cutvolume integration.
 Example 39 — Named mesh attributes.
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 thirdparty 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 timedependent NavierStokes equations.
 Mesh Explorer — Visualize and manipulate meshes.
 Mesh Optimizer — Optimize highorder meshes.
 Shaper — Resolve material interfaces by mesh refinement.
 Interpolation — Evaluation of highorder finite element functions in physical space.
 Overlapping Grids — Schwarz coupling of single and multiphysics problems.
 Extrapolation — Finite element extrapolation solver.
 Distance — Finite element distance solver.
 Shifted Diffusion — HighOrder shifted boundary method for non bodyfitted meshes.
 Minimal Surface — Compute the minimal surface of a given mesh.
 Display Basis — Visualize finite element basis functions.
 LOR Transfer — Map functions between highorder and loworderrefined spaces.
 SPDE — Generate a Gaussian random field via the SPDE method; i.e., by solving a fractional PDE with random load.
 Contact — Mortar contact patch test for elasticity using the Tribol library.
 Multidomain — Multidomain and SubMesh demonstration Miniapp.
 DPG — Discontinuous PetrovGalerkin (DPG) for various examples.
In addition, the sources for several external benchmark/proxyapps built on top of MFEM are available:
 Laghos — HighOrder Lagrangian hydrodynamics miniapp.
 Remhos — HighOrder 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
with make
.
For example, you can solve a steadystate heat conduction problem in 2D and 3D
using the shaper
miniapp (modified for the cable shape) to define the mesh and
ex1
or ex1p
to solve it (modified to include separate coefficients for air
and cable).
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 and Jupyter notebooks .
Visit the MFEM website
For more information about MFEM, visit the website, mfem.org, including the
 Features,
 Examples,
 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 mfemdev@llnl.gov.
Thank you!
Back to the MFEM tutorial page