Skip to content

Mesh

Introduction

mufem reads the computational mesh from a file and uses it for the lifetime of the simulation. The mesh is loaded either through the Simulation.New factory or, later, through the domain:

sim = mufem.Simulation.New("My Example", "data/geometry.mesh")

# Equivalent two-step form:
sim = mufem.Simulation.New("My Example")
sim.get_domain().load_mesh("data/geometry.mesh")

The same load_mesh call accepts optional matching and merging interface conditions. mufem uses these during partitioning. The call also accepts a non-conforming option for adaptively refined meshes.

Supported Formats

The underlying MFEM library parses the mesh file. The mufem test suite exercises two formats:

Extension Format Notes
.mesh MFEM native Recommended for in-house workflows; preserves curvature directly.
.msh Gmsh Write the MSH 2.2 format (see note below). Both integer attributes and PhysicalNames are read.

Write Gmsh meshes in the MSH 2.2 format

mufem reads the Gmsh 2.2 format reliably. The current Gmsh default (MSH 4.x) can fail on import with Gmsh file : vertices indices are not unique, especially for meshes that carry several physical groups. Select the 2.2 format explicitly: in the Gmsh Python API set gmsh.option.setNumber("Mesh.MshFileVersion", 2.2) before gmsh.write(...), or on the command line pass -format msh22.

On import, mufem converts NURBS meshes to a piecewise-polynomial curved mesh.

Entities and Attributes

mufem exposes two kinds of mesh entities:

Entity Marker keyword Used for
Volume Vol Material assignment, model regions, volumetric reports.
Boundary Bnd Boundary conditions, interfaces, surface reports.

Edges and points are not addressable from the Python interface.

Each entity carries a mesh attribute. This is either an integer (for example the Gmsh physical tag 11) or a string name (for example the PhysicalNames entry "Bnd1"). You can use both forms when you construct a Marker:

inlet = 11      @ Bnd
inlet = "Bnd1"  @ Bnd

Named tags are recommended: they survive renumbering by the mesher and make case scripts self-documenting. See Markers for the full syntax, including list and union markers.

Mesh Coefficients

A set of mesh-derived coefficients (Position, Cell Attribute, Cell Volume, Cell Aspect Ratio, Element Type, Element Order, Global Cell Index, Local Cell Index) is registered automatically and listed in Built-in Coefficients. You can export them with the Field Exporter to inspect mesh quality and topology.

Quality Check on Import

When you load a mesh, mufem automatically scans every element and reports any geometry that would compromise the solution. The check runs once per import. It costs a single Jacobian evaluation per element node. It is negligible compared to partitioning.

Two conditions are reported:

Condition Meaning
Inverted element The Jacobian determinant \(\det(J)\) is non-positive at one or more nodal points of the element. The element has folded onto itself and will cause solver instability or wrong results. Most commonly produced by midpoint snapping on curved boundaries in second-order meshes.
Sliver element \(\det(J)\) is positive but below \(10^{-14}\). The element is nearly degenerate; the solution stays valid but iterative solvers may converge slowly.

An inverted-element report looks like:

============================================================
!!  INVERTED MESH ELEMENTS DETECTED  !!
============================================================
  Inverted element count : 3
  min det(J)             : -1.842e-04
  max det(J)             : 7.531e-02
  worst local cell       : 18427
  Such elements will cause solver instability or incorrect results.
  Fix the mesh before trusting the solution -- typically by refining
  near curved surfaces.
============================================================

If mufem reports inverted elements, regenerate the mesh before you use the solution. Use finer resolution along curved surfaces. Sliver warnings are advisory. They do not invalidate results.