| Crates.io | xdmf |
| lib.rs | xdmf |
| version | 0.1.0 |
| created_at | 2025-08-26 22:01:05.543841+00 |
| updated_at | 2025-08-26 22:01:05.543841+00 |
| description | Small library to write XDMF files for Paraview |
| homepage | |
| repository | https://github.com/philbucher/xdmf |
| max_upload_size | |
| id | 1811956 |
| size | 249,610 |
This crate implements the xdmf file format for writing meshes with data, to be read and visualized by ParaView or VisIt.
The data storage is split into light and heavy data. The light data is metadata in xml-format, describing where and how the heavy data is stored. The heavy data can be stored in different formats. HDF is the preferred format, for space and time efficient data storage.
A large advantage over VTK based formats is that data can be referenced. The mesh can be written only once, and then referenced for the visualization of time step data. This reduces the storage requirements and write times significatly.
While this crate allows to construct the individual xdmf elements to compose an xdmf file (see here), it is recommended for most cases to use the TimeSeriesWriter. Check this file for elaborate examples.
It has a simple interface that allows to write a mesh and add time-step data to it:
use xdmf::TimeSeriesWriter;
// construct the writer (using HDF5 for heavy data storage)
let xdmf_writer = TimeSeriesWriter::new(
"xdmf_writing",
xdmf::DataStorage::Hdf5SingleFile
).expect("failed to create XDMF writer");
// define 3 points and 2 cells (a line and a triangle)
let coords = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0];
let connectivity = [0, 1, 0, 2, 1]; // line (0,1) and triangle (0,2,1)
let cell_types = [xdmf::CellType::Edge, xdmf::CellType::Triangle];
// write the mesh
let mut time_series_writer = xdmf_writer.write_mesh(&coords, (&connectivity, &cell_types)).expect("failed to write mesh");
// define some point and cell data for time step 0.0
let point_data = vec![(
"point_data".to_string(),
(xdmf::DataAttribute::Vector, vec![0.0; 9].into()),
)]
.into_iter()
.collect();
let cell_data = vec![(
"cell_data".to_string(),
(xdmf::DataAttribute::Scalar, vec![0.0, 1.0].into()),
)]
.into_iter()
.collect();
// write the data for 10 time steps
for i in 0..10 {
time_series_writer
.write_data(&i.to_string(), Some(&point_data), Some(&cell_data))
.expect("failed to write time step data");
}
The xdmf format allows to separate the storing of light and heavy data. Different data storage methods are implemented for the latter:
Ascii: This format stores the heavy data in ascii text files.AsciiInline: This format stores the heavy data together with the light data in the xml file. This is only recommended for testing or little data, since its neither fast nor space efficient. It however is the only method that stores everything in one single fileXdmfH5Single: The heavy data is stored in a single hdf5 file. This is the recommended format unless special requirements exist.XdmfH5Multiple: The heavy data is stored in a multiple hdf5 files, one for each time step (and mesh). This creates more files and usually only makes sense when the data is accessed concurrently while its being written.Initial comparisons show smaller storage sizes as well as faster write times. The conclusions still have to be summarized here. In the meantime check this file for a comparion.