General concepts » Meshes » 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::FileFormat enumeration:

FormatExtensionDescription
MFEM.meshMFEM native format
MEDIT.meshMEDIT format from INRIA (used by MMG)
HDF5.h5High-performance binary format

Loading meshes

Basic loading

Use Mesh::load() with an explicit IO::FileFormat.

#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::save() with an explicit format.

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