VTKHDF-backend#
Relies on MPI compatible h5py, similar to the H5PY backend.
See that backend for detailed installation instructions. With h5py built without MPI,
it runs as vtkhdf-serial, which writes through rank 0 in the same way as
h5py-serial.
Lossless compression#
Datasets can be stored with lossless HDF5 filters, set through backend_args; by default,
the integer mesh arrays use scale-offset. See Compressing HDF5 output for the options, an
example and a comparison of file sizes and write/read times.
Vectors and tensors#
VTK reads arrays with 3 components as vectors and arrays with 9 components as tensors.
Point and cell data with fewer components are therefore padded with zeros when written:
vectors of length 1 or 2 are stored with 3 components, and tensors of at most 3 x 3 are
embedded in a 3 x 3 tensor (row by row), so that, for instance, a 2D displacement can warp
the mesh in ParaView. The value shape of each array is stored as the attribute
ValueShape of the array’s metadata group,
/io4dolfinx/<mesh name>/<Point|Cell>Data/<array name>, and io4dolfinx removes the
padding when it reads the array back with its value shape. Arrays without this
attribute, written by other programs or by older versions of io4dolfinx, are read with
as many components as are stored: one component as a scalar, more as a vector.
Time steps#
A VTKHDF array has data at every time step, the time steps increase, and all meshes and mesh tags in a file share them. io4dolfinx keeps to these rules when writing:
A mesh or an array can be written only once at a time; a second write raises a
ValueErrorand leaves the file unchanged. Times that differ by round-off are the same time.A new time must be later than the last time step of the file.
A new time step is added to every mesh and mesh tags in the file.
At a step where an array or the geometry was not written, it holds its latest earlier write, and the steps before its first write hold its first write.
The steps at which io4dolfinx wrote each array and mesh are recorded in
/io4dolfinx, which VTK ignores. Files without this record, from older versions of io4dolfinx, are assumed to have a write at the first step and wherever the offsets of the data change.
Only the geometry of a mesh can change between time steps: its topology is stored once,
so writing a mesh with another number of points or cells under the same name raises a
ValueError.
VTK 9.7 reads only the first time step of a MultiBlockDataSet when a time is requested
(vtk#20246), unless the root has a
Steps group. Until this is fixed, io4dolfinx links /VTKHDF/Steps to the time steps
of the first mesh, which earlier versions of VTK ignore.
io4dolfinx.read_timestamps() returns every time step of the mesh an array is
stored on. See Time steps in VTKHDF files for an executed example with a splitting
scheme, and the write orders that are rejected.
Module that can read the VTKHDF format using h5py.
- io4dolfinx.backends.vtkhdf.backend.find_all_unique_cell_types(comm, cell_types, num_nodes)[source]#
Given a set of cell types and number of nodes per cell, find all unique cell types across all ranks.
- Parameters:
comm – MPI communicator
cell_types – Local cell types
num_nodes – Number of nodes per cell
- Returns:
A 2D array where each row corresponds to a cell type (vtk int) and the number of nodes.
- io4dolfinx.backends.vtkhdf.backend.get_default_backend_args(arguments: dict[str, Any] | None) dict[str, Any][source]#
Get default backend arguments given a set of input arguments.
- Parameters:
arguments – Input backend arguments
- Returns:
Updated backend arguments
- io4dolfinx.backends.vtkhdf.backend.read_function_names(filename: Path | str, comm: Comm, backend_args: dict[str, Any] | None) list[str][source]#
Read all function names from a file.
- Parameters:
filename – Path to file
comm – MPI communicator to launch IO on.
backend_args – Arguments to backend
- Returns:
A list of function names.
- io4dolfinx.backends.vtkhdf.backend.read_mesh_data(filename: Path | str, comm: Comm, time: str | float | None, read_from_partition: bool, backend_args: dict[str, Any] | None) ReadMeshData[source]#
Read mesh data from file.
- Parameters:
filename – Path to file to read from
comm – MPI communicator used in storage
time – Time stamp associated with the mesh to read
read_from_partition – Whether to read partition information
backend_args – Arguments to backend
- Returns:
Internal data structure for the mesh data read from file
- io4dolfinx.backends.vtkhdf.backend.read_point_data(filename: Path | str, name: str, comm: Comm, time: float | str | None, backend_args: dict[str, Any] | None) tuple[ndarray, int][source]#
Read data from the nodes of a mesh.
- Parameters:
filename – Path to file
name – Name of point data
comm – Communicator to launch IO on.
time – The time stamp
backend_args – The backend arguments
- Returns:
Data local to process (contiguous, no mpi comm) and local start range
- io4dolfinx.backends.vtkhdf.backend.read_value_shape(filename: Path | str, name: str, comm: Comm, backend_args: dict[str, Any] | None, entity: str) tuple[int, ...] | None[source]#
Read the value shape of point or cell data.
- Parameters:
filename – Path to file
name – Name of the array
comm – MPI communicator used in storage
backend_args – Arguments to backend
entity –
"Point"for point data,"Cell"for cell data
- Returns:
The value shape of an array written by io4dolfinx,
Nonefor other arrays
- io4dolfinx.backends.vtkhdf.backend.write_data(filename: Path | str, array_data: ArrayData, comm: Comm, time: str | float | None, mode: FileMode, backend_args: dict[str, Any] | None)[source]#
Write function to file by interpolating into geometry nodes.
- Parameters:
filename – Path to file
array_data – Data to write to file
time – Time stamp
mode – Append or write
backend_args – The backend arguments