Rodin::IO namespace

Namespace IO.

Directory src/Rodin/IO

Module for mesh and grid function input/output.

The IO module provides facilities for reading and writing meshes and grid functions in several formats:

Additionally, the XDMF class provides XDMF 3.0 output for scientific visualization in ParaView, supporting time series and multiple fields.

XDMF Architecture

The XDMF writer uses a two-level design:

  • XDMF — Top-level writer that manages the .xdmf XML file and .h5 HDF5 data. Provides write(), flush(), close(), setPadding().
  • XDMF::Grid — A lightweight handle returned by xdmf.grid() (default) or xdmf.grid("name") (named). Provides setMesh(), add(), hasMesh(), reset() — all returning Grid& for method chaining.
IO::XDMF xdmf("output");
xdmf.grid().setMesh(mesh).add("u", u.getSolution());
xdmf.write();

For MPI-distributed I/O, pass the communicator: IO::XDMF xdmf("distributed_output", MPI_COMM_WORLD);

File Format Summary

FormatExtensionsKey ClassesNotes
MFEM.mesh, .gfIO::FileFormat::MFEMText-based, compatible with MFEM ecosystem
MEDIT.meshIO::FileFormat::MEDITUsed by MMG, supports attributes
HDF5.h5IO::FileFormat::HDF5Binary, parallel-capable
XDMF.xdmf + .h5IO::XDMF, IO::XDMF::GridParaView visualization, time series

Namespaces

namespace HDF5
HDF5 utility namespace providing type aliases, path constants, RAII handle wrappers, and low-level dataset read/write helpers.
namespace Internal
Internal helpers for PETSc HDF5 serialization primitives.

Classes

template<FileFormat Fmt, class FES, class Data>
class GridFunctionLoader
Loader template for grid functions with specific file format.
template<class FES>
class GridFunctionLoader<FileFormat::HDF5, FES, ::Vec>
HDF5 loader for PETSc-backed grid functions.
template<class FES, class Scalar>
class GridFunctionLoader<FileFormat::HDF5, FES, Math::Vector<Scalar>>
HDF5 grid function loader for local grid functions backed by Math::Vector<Scalar>.
template<class FES>
class GridFunctionLoader<FileFormat::MEDIT, FES, Math::Vector<typename FormLanguage::Traits<FES>::ScalarType>>
Reads matrix entries stored as independent MEDIT scalar vertex fields. Higher-order spaces interpolate the vertex field, as required by SolAtVertices.
template<size_t K, class Range>
class GridFunctionLoader<FileFormat::MEDIT, Variational::H1<K, Range, Geometry::Mesh<Context::Local>>, Math::Vector<typename FormLanguage::Traits<Range>::ScalarType>>
MEDIT grid-function loader for local H1 finite element spaces.
template<class Range>
class GridFunctionLoader<FileFormat::MEDIT, Variational::P1<Range, Geometry::Mesh<Context::Local>>, Math::Vector<typename FormLanguage::Traits<Range>::ScalarType>>
MEDIT grid-function loader for local P1 finite element spaces.
template<class FES, class Scalar>
class GridFunctionLoader<FileFormat::MFEM, FES, Math::Vector<Scalar>>
Loads each MFEM component through the scalar family's node mapping.
template<size_t K, class Range>
class GridFunctionLoader<FileFormat::MFEM, Variational::H1<K, Range, Geometry::Mesh<Context::Local>>, Math::Vector<typename FormLanguage::Traits<Range>::ScalarType>>
Specialization for loading H1 grid functions from MFEM format.
template<class Range>
class GridFunctionLoader<FileFormat::MFEM, Variational::P0<Range, Geometry::Mesh<Context::Local>>, Math::Vector<typename FormLanguage::Traits<Range>::ScalarType>>
Loader for P0 (piecewise constant) grid functions in MFEM format.
template<class Range>
class GridFunctionLoader<FileFormat::MFEM, Variational::P1<Range, Geometry::Mesh<Context::Local>>, Math::Vector<typename FormLanguage::Traits<Range>::ScalarType>>
Specialization for loading P1 grid functions from MFEM format.
template<class FES, class Data>
class GridFunctionLoaderBase
Base class for concrete grid function loaders.
template<FileFormat Fmt, class FES, class Data>
class GridFunctionPrinter
Printer template for grid functions with specific file format.
template<class FES>
class GridFunctionPrinter<FileFormat::HDF5, FES, ::Vec>
HDF5 printer for PETSc-backed grid functions.
template<class FES, class Scalar>
class GridFunctionPrinter<FileFormat::HDF5, FES, Math::Vector<Scalar>>
HDF5 grid function printer for local grid functions backed by Math::Vector<Scalar>.
template<class FES>
class GridFunctionPrinter<FileFormat::MEDIT, FES, ::Vec>
MEDIT printer for PETSc-backed grid functions.
template<class FES>
class GridFunctionPrinter<FileFormat::MEDIT, FES, Math::Vector<typename FormLanguage::Traits<FES>::ScalarType>>
MEDIT grid-function printer for vector-backed grid functions.
template<class FES>
class GridFunctionPrinter<FileFormat::MFEM, FES, ::Vec>
Matrix PETSc fields export through the local scalar-family permutation.
template<class FES, class Scalar>
class GridFunctionPrinter<FileFormat::MFEM, FES, Math::Vector<Scalar>>
Final specialization for printing grid functions with vector data in MFEM format.
template<size_t K, class Range, class Scalar>
class GridFunctionPrinter<FileFormat::MFEM, Variational::H1<K, Range, Geometry::Mesh<Context::Local>>, Math::Vector<Scalar>>
Specialization for printing H1 grid functions with vector data in MFEM format.
template<size_t K, class Range, class Ctx>
class GridFunctionPrinter<FileFormat::MFEM, Variational::H1<K, Range, Geometry::Mesh<Ctx>>, ::Vec>
MFEM printer for PETSc-backed H1 (order $ K $ ) grid functions.
template<class Range, class Ctx>
class GridFunctionPrinter<FileFormat::MFEM, Variational::P0<Range, Geometry::Mesh<Ctx>>, ::Vec>
MFEM printer for PETSc-backed P0 grid functions.
template<class Range, class Ctx>
class GridFunctionPrinter<FileFormat::MFEM, Variational::P1<Range, Geometry::Mesh<Ctx>>, ::Vec>
MFEM printer for PETSc-backed P1 grid functions.
template<FileFormat Fmt, class FES, class Data>
class GridFunctionPrinterBase
Base class for concrete grid function printers.
template<class FES, class Data>
class GridFunctionPrinterBase<FileFormat::MEDIT, FES, Data>
Base class for MEDIT grid-function printers.
template<size_t K, class Range, class Context, class Data>
class GridFunctionPrinterBase<FileFormat::MFEM, Variational::H1<K, Range, Geometry::Mesh<Context>>, Data>
Base class for printing H1 (continuous Lagrange) grid functions in MFEM format.
template<class Range, class Context, class Data>
class GridFunctionPrinterBase<FileFormat::MFEM, Variational::P0<Range, Geometry::Mesh<Context>>, Data>
Base class for printing P0 (piecewise constant) grid functions in MFEM format.
template<class Range, class Context, class Data>
class GridFunctionPrinterBase<FileFormat::MFEM, Variational::P1<Range, Geometry::Mesh<Context>>, Data>
Base class for printing P1 (continuous Lagrange) grid functions in MFEM format.
template<class T>
class Loader
Base template for loading objects from files or streams.
template<FileFormat Fmt, class Trait>
class MeshLoader
Loader template for meshes with specific file format and context.
template<>
class MeshLoader<FileFormat::HDF5, Context::Local>
HDF5 mesh loader specialization for local (sequential) meshes.
template<>
class MeshLoader<FileFormat::HDF5, Context::MPI>
Loads a distributed MPI mesh from an HDF5 file.
template<>
class MeshLoader<IO::FileFormat::MFEM, Context::Local>
Specialization for loading sequential meshes in MFEM format.
template<class Context>
class MeshLoaderBase
Base class for loading meshes from files or streams.
template<FileFormat Fmt, class Trait>
class MeshPrinter
Printer template for meshes with specific file format and context.
template<>
class MeshPrinter<FileFormat::HDF5, Context::Local>
HDF5 mesh printer specialization for local (sequential) meshes.
template<>
class MeshPrinter<FileFormat::HDF5, Context::MPI>
Prints a distributed MPI mesh to an HDF5 file.
template<>
class MeshPrinter<FileFormat::MEDIT, Context::Local>
MEDIT mesh printer for local meshes.
template<>
class MeshPrinter<FileFormat::MFEM, Context::Local>
Specialization for printing sequential meshes in MFEM format.
template<class Context>
class MeshPrinterBase
Base class for printing meshes to streams or files.
template<class T>
class Printer
Base template for printing objects to streams.
class XDMF
XDMF domain writer for static or transient visualization output.

Enums

enum class FileFormat { MFEM, MEDIT, HDF5 }
Enumeration of supported file formats for mesh and grid function I/O.

Typedefs

template<size_t K, class Range>
using MFEM_H1_PETSc_Local_Printer = GridFunctionPrinter<FileFormat::MFEM, Variational::H1<K, Range, Geometry::Mesh<Context::Local>>, ::Vec>
Convenience alias for local PETSc-backed H1 MFEM printers.
template<size_t K, class Range>
using MFEM_H1_PETSc_MPI_Printer = GridFunctionPrinter<FileFormat::MFEM, Variational::H1<K, Range, Geometry::Mesh<Context::MPI>>, ::Vec>
Convenience alias for MPI PETSc-backed H1 MFEM printers.

Functions

auto toCharString(FileFormat fmt) -> const char* constexpr
Converts a FileFormat enum value to its string representation.
auto operator<<(std::ostream& os, FileFormat fmt) -> std::ostream&
Stream output operator for FileFormat enum.
static auto padIndex(size_t index, size_t width) -> std::string
Formats an index with leading zeros.
static auto makeRankSuffix(const std::string& rank) -> std::string
Formats the optional MPI rank suffix.
static auto expandPattern(const std::string& pattern, const std::string& stem, const std::string& grid, const std::string& name, const std::string& index, const std::string& rank = "") -> std::string
Expands XDMF filename placeholders and normalizes separators.
static void writeXMLHeader(std::ostream& os)
Writes the XDMF XML declaration and root opening tag.
static void writeXMLFooter(std::ostream& os)
Writes the XDMF root closing tag.
static auto indent(size_t level) -> std::string
Constructs indentation for an XML nesting level.
static auto getGeometryType(size_t sdim) -> const char*
Selects the XDMF coordinate-layout name.
static auto makeGridPieceName(const std::string& gridName, size_t rank) -> std::string
Constructs a grid-piece name for an MPI rank.

Enum documentation

enum class Rodin::IO::FileFormat

Enumeration of supported file formats for mesh and grid function I/O.

This enum identifies the different file formats that can be used for reading and writing meshes and grid functions in Rodin.

Enumerators
MFEM

MFEM mesh format - native format for MFEM library.

MEDIT

MEDIT mesh format - used by MMG remeshing software.

HDF5

HDF5 hierarchical binary format for raw mesh/function storage.

Typedef documentation

template<size_t K, class Range>
using Rodin::IO::MFEM_H1_PETSc_Local_Printer = GridFunctionPrinter<FileFormat::MFEM, Variational::H1<K, Range, Geometry::Mesh<Context::Local>>, ::Vec>

Convenience alias for local PETSc-backed H1 MFEM printers.

template<size_t K, class Range>
using Rodin::IO::MFEM_H1_PETSc_MPI_Printer = GridFunctionPrinter<FileFormat::MFEM, Variational::H1<K, Range, Geometry::Mesh<Context::MPI>>, ::Vec>

Convenience alias for MPI PETSc-backed H1 MFEM printers.

Function documentation

const char* Rodin::IO::toCharString(FileFormat fmt) constexpr

Converts a FileFormat enum value to its string representation.

Parameters
fmt in File format enum value
Returns C-style string name of the format, or nullptr if invalid
Example
const char* name = toCharString(FileFormat::MFEM);  // Returns "MFEM"

std::ostream& Rodin::IO::operator<<(std::ostream& os, FileFormat fmt)

Stream output operator for FileFormat enum.

Parameters
os in/out Output stream
fmt in File format to output
Returns Reference to the output stream

Writes the string representation of the file format to the stream.

Example
std::cout << FileFormat::MEDIT;  // Outputs "MEDIT"

static std::string Rodin::IO::padIndex(size_t index, size_t width)

Formats an index with leading zeros.

Parameters
index Degree-of-freedom index.
width Minimum number of decimal digits.
Returns Decimal index padded to at least the requested width.

static std::string Rodin::IO::makeRankSuffix(const std::string& rank)

Formats the optional MPI rank suffix.

Parameters
rank Rank identifier; an empty string omits the rank suffix.
Returns An empty string for an empty rank, otherwise the rank prefixed by .r.

static std::string Rodin::IO::expandPattern(const std::string& pattern, const std::string& stem, const std::string& grid, const std::string& name, const std::string& index, const std::string& rank = "")

Expands XDMF filename placeholders and normalizes separators.

Parameters
pattern Filename pattern containing named placeholders.
stem Value replacing the stem placeholder.
grid Value replacing the grid placeholder.
name Value replacing the name placeholder.
index Value replacing the index placeholder.
rank Rank identifier; an empty string omits the rank suffix.
Returns Expanded filename with separators introduced by empty placeholders normalized.

static void Rodin::IO::writeXMLHeader(std::ostream& os)

Writes the XDMF XML declaration and root opening tag.

Parameters
os Output stream receiving the formatted data.

static void Rodin::IO::writeXMLFooter(std::ostream& os)

Writes the XDMF root closing tag.

Parameters
os Output stream receiving the formatted data.

static std::string Rodin::IO::indent(size_t level)

Constructs indentation for an XML nesting level.

Parameters
level Indentation level, with two spaces per level.
Returns A string containing two spaces per nesting level.

static const char* Rodin::IO::getGeometryType(size_t sdim)

Selects the XDMF coordinate-layout name.

Parameters
sdim Spatial coordinate dimension, from one to three.
Returns X, XY, or XYZ for spatial dimensions one, two, or three.

static std::string Rodin::IO::makeGridPieceName(const std::string& gridName, size_t rank)

Constructs a grid-piece name for an MPI rank.

Parameters
gridName Grid name, possibly empty.
rank MPI rank identifying the grid piece.
Returns Grid name followed by _r and the rank, or r and the rank when the grid name is empty.