Skip to content

MFEM Gallery

MFEM's examples, through Tack. Each problem is solved with PyMFEM on MFEM's own meshes: curved tetrahedra and hexahedra of order 3, nonconforming meshes from adaptive refinement, a curved surface, periodic meshes, and DG fields. Tack imports the mesh and solution with tack.interop.mfem.mfem_to_dataset, then runs its filters on them.

Tack makes everything drawn: contours and slices cut on sub-cells of the curved cells, curved and discontinuous meshes subdivided into linear cells, and each cell's edges as lines that follow the geometry. VTK only draws linear polygons and lines.

The pictures come from docs/gallery/mfem_examples.py, which needs the interop extra. The problems are in docs/gallery/_mfem.py, MFEM's examples written out. tack-examples' MFEM ports (tack_examples/mfem/) run the same problems and hold Tack to MFEM's evaluation of them: values at random points of every element, gradients, DG jumps face by face, and integrals.

Poisson on curved cells

MFEM's ex1, -Δu = 1 with u = 0 on the boundary, in H1 of order 3:

  • The Escher knot (left): curved tetrahedra of order 3. The three isosurfaces nest, the outer two translucent.
  • The Fichera corner (right): curved hexahedra of order 3, sliced through the re-entrant corner. The slice's edge follows the curved cells.
  • Isosurfaces in the Escher knot

    Curved tetrahedra (ex1, escher-p3.mesh)

  • A slice of the Fichera corner

    Curved hexahedra (ex1, fichera-q3.mesh)

# ex1 on the Escher knot: curved tetrahedra of order 3 (MFEM's "Cubic"
# nodes), the solution in H1 of order 3. Each level is cut on sub-cells, 4
# a side, its crossings placed on the field itself.
mesh = _mfem.mesh("escher-p3.mesh", 1500)
x = _mfem.poisson(mesh, 3)
data = mfem_to_dataset(mesh, {"u": x})
top = float(np.abs(x.GetDataArray()).max())
levels = [0.15 * top, 0.45 * top, 0.75 * top]
surfaces = [_scene.normals(td.contour(data, "u", v, subdivision=4)) for v in levels]
# ex1 on the Fichera corner: curved hexahedra of order 3, the solution of
# order 3, sliced through the re-entrant corner.
mesh = _mfem.mesh("fichera-q3.mesh", 600)
x = _mfem.poisson(mesh, 3)
data = mfem_to_dataset(mesh, {"u": x})
cut = td.slice(data, implicit.Plane((0.0, 0.0, 0.0), (1.0, -1.0, 1.0)), fields=["u"],
               subdivision=6)

Elasticity

MFEM's two-material beam, fixed at one end:

  • ex2 (left): pulled down at the other end. The displacement is in H1 of order 2. warp lifts the straight beam into the displacement's space, so the displaced beam is curved. The undisplaced beam's edges are drawn too.
  • ex17 (right): displaced by DG of order 2. MFEM moves the mesh's nodes into the DG space, so the geometry is a curved, discontinuous L2 geometry: each cell has its own nodes.
  • The beam warped by its displacement

    Warped by an order-2 displacement (ex2)

  • The beam displaced by its DG solution

    An order-2 L2 geometry (ex17)

# ex2: the two-material beam of hexahedra, its displacement in H1 of order 2.
# warp lifts the straight geometry into the displacement's space, so the
# displaced beam is curved, MFEM's displaced mesh node for node.
mesh = _mfem.mesh("beam-hex.mesh", 600)
x = _mfem.elasticity(mesh, 2)
data = mfem_to_dataset(mesh, {"u": x})
data.fields["|u|"] = td.magnitude(data, "u")
moved = td.warp(data, "u", scale=1.0)
# ex17: the beam of quads displaced by its DG solution of order 2 (MFEM moves
# the mesh's nodes into the DG space): a curved, discontinuous L2 geometry,
# each cell where MFEM puts it.
mesh = _mfem.mesh("beam-quad.mesh", 400)
x = _mfem.dg_elasticity(mesh, 2)
mesh.SetNodalFESpace(x.FESpace())
nodes = mesh.GetNodes()
nodes += x
data = mfem_to_dataset(mesh, {"u": x})
data.fields["|u|"] = td.magnitude(data, "u")
surface = td.subdivide(data, 4)

Adaptive refinement and curved surfaces

  • ex6 (left): the star, refined where the error estimate is largest. The mesh is nonconforming: the hanging nodes show in the cells' edges. The values agree across each T-junction, so the picture has no cracks, but face-based algorithms treat the T-junctions as boundary for now (Nonconforming meshes).
  • ex7 (right): the cube's quads snapped onto the sphere, as curved cells of order 3, with the solution of a surface PDE on them.
  • The star after adaptive refinement

    A nonconforming mesh (ex6)

  • A solution on the curved sphere

    Curved quads of order 3 (ex7)

# ex6: the star refined where Zienkiewicz-Zhu's estimate is largest, to 3000
# unknowns: a nonconforming mesh, its hanging nodes in the cells' edges.
mesh = _mfem.mesh("star.mesh")
x = _mfem.adaptive_poisson(mesh, 2, 3000)
data = mfem_to_dataset(mesh, {"u": x})
surface = td.subdivide(data, 4)
# ex7: the cube's quads snapped onto the sphere, curved cells of order 3, and
# the Laplace-Beltrami solution on them.
mesh = _mfem.sphere(3)
x = _mfem.laplace_beltrami(mesh, 3)
data = mfem_to_dataset(mesh, {"u": x})
surface = _scene.normals(td.subdivide(data, 6))

DG advection on a periodic mesh

MFEM's ex9 carries a bump across the periodic hexagon in DG of order 3. Part of the bump has crossed the seam: it shows at the bottom left.

A periodic mesh keeps its nodes per element, as an L2 geometry. Cells on the two sides of the seam share points in the topology but sit apart in space, so subdivide gives each cell its own lattice points.

  • A DG bump on the periodic hexagon

    A periodic mesh (ex9)

# ex9: a DG bump of order 3 carried across the periodic hexagon. A periodic
# mesh keeps its nodes per element, an L2 geometry: cells on two sides of the
# seam share points in the topology and sit apart in space, so each cell is
# subdivided on its own lattice.
mesh = _mfem.mesh("periodic-hexagon.mesh")
for _ in range(2):
    mesh.UniformRefinement()
u = _mfem.advection(mesh, 0.5)
data = mfem_to_dataset(mesh, {"u": u})
surface = td.subdivide(data, 6)
edges = td.extract_edges(td.subdivide(data, 1, fields=[]))  # each cell's own corners