Mesh input/output
Saving and loading meshes.
Rodin supports reading and writing meshes in various file formats through the IO module.
Introduction
Mesh I/O operations provide:
- Load meshes from external mesh generators
- Save computed meshes for later use
- Exchange meshes with other software
- Archive simulation data
Supported formats
The file format is specified explicitly via the IO::
| Format | Extension | Description |
|---|---|---|
| MFEM | .mesh | MFEM native format |
| MEDIT | .mesh | MEDIT format from INRIA (used by MMG) |
| HDF5 | .h5 | High-performance binary format |
Loading meshes
Basic loading
Use Mesh::
#include <Rodin/Geometry.h> using namespace Rodin; using namespace Rodin::Geometry; int main() { Mesh mesh; // Load MFEM format mesh.load("domain.mfem.mesh", IO::FileFormat::MFEM); // Load MEDIT format mesh.load("domain.medit.mesh", IO::FileFormat::MEDIT); return 0; }
Saving meshes
Basic saving
Use Mesh::
Mesh mesh; mesh = mesh.UniformGrid(Polytope::Type::Triangle, {16, 16}); // Save in MFEM format mesh.save("output.mfem.mesh", IO::FileFormat::MFEM); // Save in MEDIT format mesh.save("output.medit.mesh", IO::FileFormat::MEDIT);
MEDIT format
The MEDIT format is commonly used with the MMG mesh adaptation tools.
mesh.save("domain.mesh", IO::FileFormat::MEDIT);
Complete example
The complete program is available in MEDIT.cpp.
The generated input makes the program self-contained. Its output files use distinct names for each representation.
External mesh generators
MMG
MMG is used for mesh adaptation and optimization. Rodin integrates directly with MMG through the MMG module. See the MMG examples for details.
File paths
Absolute paths
mesh.load("/home/user/meshes/domain.mesh", IO::FileFormat::MFEM);
Relative paths
Relative paths are resolved from the executable's working directory. Create output directories before saving files into them.
mesh.load("../data/domain.mesh", IO::FileFormat::MFEM); mesh.save("./output/result.mesh", IO::FileFormat::MFEM);
Format considerations
Compatibility
- MFEM supports MFEM-based workflows.
- MEDIT supplies the format required by MMG tools.
Attributes
Select a supported mesh representation and verify its round trip. The core geometry data comprises:
- Vertex coordinates
- Element connectivity
- Element attributes (region markers)
- Boundary attributes
See also
- I/O in Rodin — Comprehensive I/O guide including XDMF
- Mesh creation
- Meshes overview
- I/O namespace