Examples and tutorials » Input/Output examples » MEDIT format

How to load and convert MEDIT-format meshes.

Introduction

The MEDIT format (.mesh) is developed by INRIA and is the native format for the MMG mesh tools. It stores vertex coordinates, element connectivity, and integer attributes (material tags, boundary labels).

Use IO::FileFormat::MEDIT when saving or loading.

Loading a MEDIT Mesh

A mesh in MEDIT format can be loaded into either a standard Mesh or an MMG::Mesh:

#include <Rodin/Geometry.h>

using namespace Rodin;
using namespace Rodin::Geometry;

int main(int, char** argv)
{
  Mesh mesh;
  mesh.load(argv[1], IO::FileFormat::MEDIT);

  std::cout << "Loaded mesh with "
            << mesh.getVertexCount() << " vertices and "
            << mesh.getCellCount() << " cells" << std::endl;

  return 0;
}

Format Conversion

A common workflow is to convert a MEDIT mesh produced by MMG into MFEM format for use with other tools:

Mesh mesh;
mesh.load("input.medit.mesh", IO::FileFormat::MEDIT);
mesh.save("output.mfem.mesh", IO::FileFormat::MFEM);

Using with MMG

When working with the MMG module, MEDIT is the recommended format because it preserves MMG-specific metadata:

#include <Rodin/MMG.h>

MMG::Mesh mesh;
mesh.load("domain.medit.mesh", IO::FileFormat::MEDIT);

// Optimize and save
MMG::Optimizer().setHMax(0.1).optimize(mesh);
mesh.save("optimized.medit.mesh", IO::FileFormat::MEDIT);

Full Source Code

See Also