Rodin::MMG namespace

MMG integration with Rodin.

The Rodin::MMG module provides C++ wrappers for the Mmg Platform, enabling metric-based mesh adaptation, mesh-quality optimization, and level-set discretization directly from Rodin objects.

Key Classes

ClassPurpose
MMG::MeshLocal mesh type extending Geometry::Mesh<Local> with corner, ridge, and required-entity metadata.
MMG::AdaptMetric-based adaptation from a nodal size map.
MMG::OptimizerMesh-quality optimization without an external metric field.
MMG::LevelSetDiscretizerLevel-set meshing: cuts a background mesh along an isovalue or extracts the isosurface.
MMG::MMG5Base class providing shared MMG configuration and native conversion helpers.

Workflow Semantics

Optimizer, Adapt, and LevelSetDiscretizer are intentionally different operations:

WorkflowExpected behavior
OptimizerImproves element quality while keeping the mesh close to the existing local size distribution.
AdaptRefines, coarsens, moves, and reconnects elements according to a size field.
LevelSetDiscretizerAlters topology as needed to conform the output mesh to the selected level-set isovalue.

All workflows convert an MMG::Mesh to native MMG structures, run MMG, and convert the result back. The output is a remeshed object; input element indices should be treated as stable only where the wrapper or tests explicitly document preservation.

Auto-Dispatch

The wrappers auto-dispatch to the appropriate MMG backend based on the mesh type:

Mesh typeBackend
2D planarMMG2D
3D volumetricMMG3D
Surface in 3DMMGS

Shared Configuration (MMG5 base)

The MMG wrappers inherit common configuration methods from MMG5; each returns *this for chaining:

MethodDescription
setHMin(hmin)Minimal allowed edge size
setHMax(hmax)Maximal allowed edge size
setHausdorff(hausd)Hausdorff distance tolerance for boundary approximation
setGradation(hgrad)Edge-size gradation ratio between adjacent elements
setAngleDetection(bool)Enable ridge angle detection for feature preservation

Required Entities

MMG::Mesh stores MMG-specific metadata:

MethodDescription
setCorner(vertexIdx)Mark a vertex as a geometric corner
setRidge(edgeIdx)Mark an edge as a geometric ridge
setRequiredVertex(idx)Mark a vertex as required (MG_REQ)
setRequiredEdge(idx)Mark an edge as required (MG_REQ)
setRequiredTriangle(idx)Mark a triangle as required (MG_REQ)
setRequiredTetrahedron(idx)Mark a tetrahedron as required (MG_REQ)

Required vertices, edges, triangles, and tetrahedra are serialized through MEDIT, converted to native MMG MG_REQ tags, and restored from native MMG output. The optimizer and level-set wrappers restore required index sets when the original indices are still valid after remeshing. In MMG3D, setRequiredTriangle(idx) applies to boundary triangles exported to MMG's triangle table; interior faces of a tetrahedral mesh are not exported as MMG boundary triangles when face-cell incidence is available.

For level-set discretization, the tested behavior is:

  • required entities not crossed by the level set retain their required metadata and original geometry in the 2D/3D cases covered by the test suite;
  • required entities crossed by the level set are not guaranteed to remain intact. MMG may replace them to conform the mesh to the isovalue, even when MG_REQ, individual labels, adjacent tetrahedron labels, local closure requirements, or noSplit(ref) are used.

See MMG behavior and guarantees for the full characterization.

LevelSetDiscretizer API

In addition to MMG5 parameters, LevelSetDiscretizer provides:

MethodDescription
setLevelSet(ls)Isovalue to extract (default: 0.0)
surface(bool)When true, discretize the isosurface; when false, discretize the subdomain volume
setRMC(rmc)Removal threshold for small parasitic components
setBoundaryReference(ref)Material reference for the discretized boundary
setBaseReferences(refs)Restrict level-set splitting to specified base materials
split(ref, split)Split one material reference into inside/outside references
noSplit(ref)Keep one material reference from being split by the material policy

noSplit(ref) is a material-reference splitting policy. It is not an element-integrity guarantee for an individual edge, triangle, or tetrahedron that the level set cuts.

MMG::Mesh cut = MMG::LevelSetDiscretizer()
  .setLevelSet(0.0)
  .split(interior, { interior, exterior })
  .setBoundaryReference(interface)
  .discretize(phi);

Use MMG::Mesh::Build() to construct meshes programmatically via the builder pattern.

Classes

class Adapt
Performs anisotropic/isotropic remeshing from a nodal size map.
class LevelSetDiscretizer
Discretizes implicit geometry defined by a nodal level-set field.
class Mesh
Local mesh enriched with MMG boundary tags and constraints.
class MeshLoader
Loads an Rodin::MMG::Mesh from the MEDIT format.
class MeshPrinter
Printer for Rodin::MMG::Mesh in MEDIT/MMG-compatible syntax.
class MMG5
Base class for MMG-backed operations in Rodin.
template<class FuncName>
class MMG5Exception
Exception type for MMG wrapper failures.
struct NoSplitT
Tag type indicating that a material reference must not be split.
class Optimizer
Improves mesh quality while preserving characteristic local sizes.
struct Split
Interior/exterior labels produced when splitting one material.

Typedefs

using SplitMap = UnorderedMap<Geometry::Attribute, std::variant<Split, NoSplitT>>
Material splitting policy map used by level-set discretization.
template<class Range>
using GridFunction = Variational::GridFunction<Variational::P1<Range, Geometry::Mesh<Context::Local>>, Math::Vector<Real>>
Grid function type used by the MMG module.
using RealGridFunction = GridFunction<Real>
Scalar MMG grid function alias.
using VectorGridFunction = GridFunction<Math::SpatialVector<Real>>
Vector-valued MMG grid function alias.
using ReturnCode = int
Return-code type used by MMG C API calls.

Functions

auto getISCDMshdistExecutable() -> const char*
Gets the configured path to the mshdist executable.
auto getISCDAdvectExecutable() -> const char*
Gets the configured path to the advect executable.
auto getMMGVerbosityLevel() -> int
Gets the MMG verbosity level selected at configuration time.

Variables

static NoSplitT NoSplit constexpr
Singleton tag instance for convenience in split configuration.
const char* ISCD_MSHDIST_EXECUTABLE constexpr
Path to the ISCD Mshdist executable.
const char* ISCD_ADVECTION_EXECUTABLE constexpr
Path to the ISCD Mshdist executable.
const int VERBOSITY_LEVEL constexpr
Verbosity level for MMG console output.

Typedef documentation

using Rodin::MMG::SplitMap = UnorderedMap<Geometry::Attribute, std::variant<Split, NoSplitT>>

Material splitting policy map used by level-set discretization.

Keys are input material attributes from the source mesh. Values describe whether each material is split into distinct interior/exterior labels (Split) or kept unchanged (NoSplitT).

This map is consumed by LevelSetDiscretizer::setSplit.

template<class Range>
using Rodin::MMG::GridFunction = Variational::GridFunction<Variational::P1<Range, Geometry::Mesh<Context::Local>>, Math::Vector<Real>>

Grid function type used by the MMG module.

Template parameters
Range Value type (Real for scalar fields, Math::SpatialVector<Real> for vector fields).

MMG workflows in Rodin operate on first-order nodal fields defined on local meshes. This alias standardizes that representation for scalar and vector quantities transferred to/from MMG solution structures.

using Rodin::MMG::RealGridFunction = GridFunction<Real>

Scalar MMG grid function alias.

Commonly used for size maps and level-set values passed to Adapt and LevelSetDiscretizer.

using Rodin::MMG::VectorGridFunction = GridFunction<Math::SpatialVector<Real>>

Vector-valued MMG grid function alias.

Useful for vector metrics or vector fields in MMG-related pre/post-processing.

using Rodin::MMG::ReturnCode = int

Return-code type used by MMG C API calls.

MMG kernels conventionally return MMG5_SUCCESS, MMG5_LOWFAILURE, or MMG5_STRONGFAILURE.

Function documentation

const char* Rodin::MMG::getISCDMshdistExecutable()

Gets the configured path to the mshdist executable.

Returns Null-terminated executable path.

const char* Rodin::MMG::getISCDAdvectExecutable()

Gets the configured path to the advect executable.

Returns Null-terminated executable path.

int Rodin::MMG::getMMGVerbosityLevel()

Gets the MMG verbosity level selected at configuration time.

Returns MMG verbosity value passed to MMG imprim settings.

Variable documentation

static NoSplitT Rodin::MMG::NoSplit constexpr

Singleton tag instance for convenience in split configuration.

Example:

SplitMap split;
split[5] = NoSplit;

const char* Rodin::MMG::ISCD_MSHDIST_EXECUTABLE constexpr

Path to the ISCD Mshdist executable.

const char* Rodin::MMG::ISCD_ADVECTION_EXECUTABLE constexpr

Path to the ISCD Mshdist executable.

const int Rodin::MMG::VERBOSITY_LEVEL constexpr

Verbosity level for MMG console output.

Ranges from -1 to INT_MAX. A higher number means more verbose output.