H5PY-backend#

The H5PY-backend relies on an MPI compatible build of HDF5, which should be linked to the same MPI implementation as DOLFINx relies on.

The DOLFINx docker images (ghcr.io/fenics/dolfinx/dolfinx:stable) comes with an already configures MPI compatible HDF5 installation, and h5py can in turn be installed with

HDF5_MPI="ON" HDF5_DIR="/usr/local" python3 -m pip install --no-binary=h5py h5py --no-build-isolation

If you are using apt on Ubuntu, this can for instance be achieved with the following commands (here using Docker). Note that this code block does not install DOLFINx, it just illustrates how to get the correct h5py.

FROM ubuntu:24.04 AS base
RUN apt-get update && apt-get install -y python3-dev python3-pip python3-venv libhdf5-mpi-dev libopenmpi-dev


ENV VIRTUAL_ENV=/test-env
ENV PATH=/test-env/bin:$PATH
RUN python3 -m venv ${VIRTUAL_ENV}

ENV HDF5_MPI="ON"
ENV HDF5_DIR=/usr/lib/x86_64-linux-gnu/hdf5/openmpi/
ENV C_PATH=/usr/lib/x86_64-linux-gnu/openmpi/include/:${C_PATH}
RUN python3 -m pip install setuptools cython numpy pkgconfig mpi4py
RUN CC=mpicc python3 -m pip install --no-binary=h5py h5py --no-build-isolation

H5py interface to io4dolfinx

SPDX License identifier: MIT

Copyright: Jørgen S. Dokken, Henrik N.T. Finsberg, Simula Research Laboratory

io4dolfinx.backends.h5py.backend.h5pyfile(h5name, filemode='r', force_serial: bool = False, comm=None)[source]#

Context manager for opening an HDF5 file with h5py.

Parameters:
  • h5name – The name of the HDF5 file.

  • filemode – The file mode.

  • force_serial – Force serial access to the file.

  • comm – The MPI communicator

io4dolfinx.backends.h5py.backend.read_attributes(filename: Path | str, comm: Intracomm, name: str, backend_args: dict[str, Any] | None = None) dict[str, Any][source]#

Read attributes from file using H5PY.

Parameters:
  • filename – Path to file to read from

  • comm – MPI communicator used in storage

  • name – Name of the attributes

Returns:

The attributes

io4dolfinx.backends.h5py.backend.read_cell_data(filename: Path | str, name: str, comm: Intracomm, time: str | float | None, backend_args: dict[str, Any] | None) tuple[ndarray[tuple[int, ...], dtype[int64]], ndarray][source]#

Read data from the cells 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:

A tuple (topology, dofs) where topology contains the vertex indices of the cells, dofs the degrees of freedom within that cell.

io4dolfinx.backends.h5py.backend.read_cell_perms(comm: Intracomm, filename: Path | str, backend_args: dict[str, Any] | None) ndarray[tuple[int, ...], dtype[uint32]][source]#

Read cell permutation from file with given communicator, Split in continuous chunks based on number of cells in the input data.

Parameters:
  • comm – MPI communicator used in storage

  • filename – Path to file to read from

  • backend_args – Arguments to backend

Returns:

Contiguous sequence of permutations (with respect to input data) Process 0 has [0, M), process 1 [M, N), process 2 [N, O) etc.

io4dolfinx.backends.h5py.backend.read_dofmap(filename: str | Path, comm: Intracomm, name: str, backend_args: dict[str, Any] | None) AdjacencyList[source]#

Read the dofmap of a function with a given name.

Parameters:
  • filename – Path to file to read from

  • comm – MPI communicator used in storage

  • name – Name of the function to read the dofmap for

  • backend_args – Arguments to backend

Returns:

class}`dolfinx.graph.AdjacencyList`

Return type:

Dofmap as an {py

io4dolfinx.backends.h5py.backend.read_dofs(filename: str | Path, comm: Intracomm, name: str, time: float, backend_args: dict[str, Any] | None) tuple[ndarray[tuple[int, ...], dtype[float32 | float64 | complex64 | complex128]], int][source]#

Read the dofs (values) of a function with a given name from a given timestep.

Parameters:
  • filename – Path to file to read from

  • comm – MPI communicator used in storage

  • name – Name of the function to read the dofs for

  • time – Time stamp associated with the function to read

  • backend_args – Arguments to backend

Returns:

Contiguous sequence of degrees of freedom (with respect to input data) and the global starting point on the process. Process 0 has [0, M), process 1 [M, N), process 2 [N, O) etc.

io4dolfinx.backends.h5py.backend.read_function_names(filename: Path | str, comm: Intracomm, 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.h5py.backend.read_hdf5_array(comm: Intracomm, filename: Path | str, group: str, backend_args: dict[str, Any] | None = None) tuple[ndarray, int][source]#

Read an array from an HDF5 file.

Parameters:
  • comm – MPI communicator used in storage

  • filename – Path to file to read from

  • group – Group in HDF5 file where array is stored

  • backend_args – Arguments to backend

Returns:

  • Numpy array read from file

  • Global starting point on the process.

    Process 0 has [0, M), process 1 [M, N), process 2 [N, O) etc.

Return type:

Tuple containing

io4dolfinx.backends.h5py.backend.read_legacy_mesh(filename: Path | str, comm: Intracomm, group: str) tuple[ndarray[tuple[int, ...], dtype[int64]], ndarray[tuple[int, ...], dtype[floating]], str | None][source]#

Read in the mesh topology, geometry and (optionally) cell type from a legacy DOLFIN HDF5-file.

Parameters:
  • filename – Path to file to read from

  • comm – MPI communicator used in storage

  • group – Group in HDF5 file where mesh is stored

Returns:

  • Topology as a (num_cells, num_vertices_per_cell) array of global vertex indices

  • Geometry as a (num_vertices, geometric_dimension) array of vertex coordinates

  • Cell type as a string (e.g. “tetrahedron”) or None if not found

Return type:

Tuple containing

io4dolfinx.backends.h5py.backend.read_mesh_data(filename: Path | str, comm: Intracomm, time: str | float | None = 0.0, read_from_partition: bool = False, backend_args: dict[str, Any] | None = None) ReadMeshData[source]#

Read mesh data from h5py based checkpoint files.

Parameters:
  • filename – Path to input file

  • comm – The MPI communciator to distribute the mesh over

  • time – Time stamp associated with mesh

  • read_from_partition – Read mesh with partition from file

Returns:

The mesh topology, geometry, UFL domain and partition function

io4dolfinx.backends.h5py.backend.read_meshtags_data(filename: str | Path, comm: Intracomm, name: str, backend_args: dict[str, Any] | None = None) MeshTagsData[source]#

Read mesh tags from file.

Parameters:
  • filename – Path to file to read from

  • comm – MPI communicator used in storage

  • name – Name of the mesh tags to read

  • backend_args – Arguments to backend. If “legacy_dolfin” is supplied as argument the HDF5 file is assumed to have been made with DOLFIN

Returns:

Internal data structure for the mesh tags read from file

io4dolfinx.backends.h5py.backend.read_timestamps(filename: Path | str, comm: Intracomm, function_name: str, backend_args: dict[str, Any] | None = None) ndarray[tuple[int, ...], dtype[float64 | str]][source]#

Read time-stamps from a checkpoint file.

Parameters:
  • comm – MPI communicator

  • filename – Path to file

  • function_name – Name of the function to read time-stamps for

  • backend_args – Arguments for backend, for instance file type.

Returns:

The time-stamps

io4dolfinx.backends.h5py.backend.snapshot_checkpoint(filename: Path | str, mode: FileMode, u: Function, backend_args: dict[str, Any] | None)[source]#

Create a snapshot checkpoint of a dolfinx function.

Parameters:
  • filename – Path to file to read from

  • mode – File-mode to store the function

  • u – dolfinx function to create a snapshot checkpoint for

  • backend_args – Arguments to backend

io4dolfinx.backends.h5py.backend.write_attributes(filename: Path | str, comm: Intracomm, name: str, attributes: dict[str, ndarray], backend_args: dict[str, Any] | None = None)[source]#

Write attributes to file using H5PY.

Parameters:
  • filename – Path to file to write to

  • comm – MPI communicator used in storage

  • name – Name of the attributes

  • attributes – Dictionary of attributes to write to file

  • engine – ADIOS2 engine to use

io4dolfinx.backends.h5py.backend.write_data(filename: Path | str, array_data: ArrayData, comm: Intracomm, time: str | float | None, mode: FileMode, backend_args: dict[str, Any] | None)[source]#

Write a 2D-array to file (distributed across proceses with MPI).

Parameters:
  • filename – Path to file

  • array_data – Data to write to file

  • comm – MPI communicator to open the file with

  • time – Time-stamp for data.

  • mode – Append or write

  • backend_args – The backend arguments

io4dolfinx.backends.h5py.backend.write_function(filename: str | Path, comm: Intracomm, u: FunctionData, time: float, mode: FileMode, backend_args: dict[str, Any] | None = None)[source]#

Write a function to file.

Parameters:
  • comm – MPI communicator used in storage

  • u – Internal data structure for the function data to save to file

  • filename – Path to file to write to

  • time – Time stamp associated with function

  • mode – File-mode to store the function

  • backend_args – Arguments to backend

io4dolfinx.backends.h5py.backend.write_mesh(filename: Path | str, comm: Intracomm, mesh: MeshData, backend_args: dict[str, Any] | None = None, mode: FileMode = FileMode.write, time: float = 0.0)[source]#

Write a mesh to file using H5PY

Parameters:
  • comm – MPI communicator used in storage

  • mesh – Internal data structure for the mesh data to save to file

  • filename – Path to file to write to.

  • mode – Mode to use (write or append)

  • time – Time stamp

io4dolfinx.backends.h5py.backend.write_meshtags(filename: str | Path, comm: Intracomm, data: MeshTagsData, backend_args: dict[str, Any] | None = None)[source]#

Write mesh tags to file.

Parameters:
  • filename – Path to file to write to

  • comm – MPI communicator used in storage

  • data – Internal data structure for the mesh tags to save to file

  • backend_args – Arguments to backend