Skip to content

Commit aef36c5

Browse files
committed
Add more docs
1 parent 34e2c84 commit aef36c5

File tree

7 files changed

+529
-106
lines changed

7 files changed

+529
-106
lines changed

README.md

Lines changed: 70 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,110 @@
11
# io4dolfinx - A framework for reading and writing data to various mesh formats
22

3-
io4dolfinx is an extension for [DOLFINx](https://github.com/FEniCS/dolfinx/) that supports reading and writing various mesh formats using a variety of backends:
3+
**io4dolfinx** is an extension for [DOLFINx](https://github.com/FEniCS/dolfinx/) that provides advanced input/output capabilities. It focuses on **N-to-M checkpointing** (writing data on N processors, reading on M processors) and supports reading/writing various mesh formats using interchangeable backends.
44

5-
## Reading meshes, node data and cell data
6-
Most meshing formats supports associating data with the nodes of the mesh (the mesh can be higher order) and the cells of the mesh. The node data can be read in as P-th order Lagrange functions (where P is the order of the grid), while the cell data can be read in as piecewise constant (DG-0) functions.
7-
8-
- [VTKHDF](./docs/backends/vtkhdf.rst): The new scalable format from VTK, called [VTKHDF](https://docs.vtk.org/en/latest/vtk_file_formats/vtkhdf_file_format/index.html) is supported by the `vtkhdf` backend.
9-
- [XDMF](./docs/backends/xdmf.rst) (eXtensible Model Data Format): `.xdmf`. The `xdmf` backend supports the `HDF5` encoding, to ensure performance in parallel.
10-
- [PyVista](./docs/backends/pyvista.rst) (IO backend is meshio): The [pyvista](https://pyvista.org/) backend uses {py:func}`pyvista.read` to read in meshes, point data and cell data. `pyvista` relies on [meshio](https://github.com/nschloe/meshio) for most reading operations (including the XDMF ascii format).
115

12-
## Checkpointing
13-
Many finite element applications requires storage of functions that cannot be associated with the nodes or cells of the mesh. Therefore, we have implemented our own, native checkpointing format that supports N-to-M checkpointing (write data on N processors, read in on M) through the following backends:
14-
- [h5py](./docs/backends/h5py.rst): Requires HDF5 with MPI support to work, but can store, meshes, partitioning info, meshtags, function data and more.
15-
- [adios2](./docs/backends/adios2.rst): Requires [ADIOS 2](https://adios2.readthedocs.io/en/latest/) compiled with MPI support and Python bindings. Supports the same set of operations as the `h5py` backend.
16-
17-
The code uses the ADIOS2/Python-wrappers and h5py module to write DOLFINx objects to file, supporting N-to-M (_recoverable_) and N-to-N (_snapshot_) checkpointing.
18-
See: [Checkpointing in DOLFINx - FEniCS 23](https://jsdokken.com/checkpointing-presentation/#/) or the examples in the [Documentation](https://jsdokken.com/io4dolfinx/) for more information.
19-
20-
For scalability, the code uses [MPI Neighbourhood collectives](https://www.mpi-forum.org/docs/mpi-3.1/mpi31-report/node200.htm) for communication across processes.
21-
22-
## Relation to adios4dolfinx
23-
24-
This library is an evolution of the [adios4dolfinx](https://doi.org/10.21105/joss.06451) code and has all the functionality of that library, and can read the checkpointing files from `adios4dolfinx`.
6+
## Installation
257

26-
As `adios4dolfinx` was solely relying on ADIOS2 it was hard to interface other meshing formats and still keep the library structure sane.
8+
The library is compatible with the DOLFINx nightly release, v0.10.0, and v0.9.0.
279

28-
`io4dolfinx` support custom user backends, which can be provided as a string through all functions via the `backend` keyword arg, i.e. `backend="name_of_my_module"`.
10+
```bash
11+
python3 -m pip install io4dolfinx
12+
```
2913

30-
## Statement of Need
14+
For specific backend requirements (like ADIOS2 or H5PY), see the [Installation Guide](./docs/installation.md).
3115

32-
As the usage of high performance computing clusters increases, more and more large-scale, long-running simulations are deployed.
33-
The need for storing intermediate solutions from such simulations are crucial, as the HPC system might crash, or the simulation might crash or exceed the alloted computational budget.
34-
Having a checkpoint of related variables, such as the solutions to partial differential equations (PDEs) is therefore essential.
35-
The `io4dolfinx` library extends the [DOLFINx](https://github.com/FEniCS/dolfinx/) computational framework for solving PDEs with checkpointing functionality, such that immediate solutions and mesh information can be stored and re-used in another simulation.
3616

37-
## Installation
17+
## Quick Start
3818

39-
The library is backwards compatible against the DOLFINx API of the nightly release of DOLFINx, v0.10.0 and v0.9.0.
19+
Here is a minimal example of saving and loading a simulation state (Checkpointing).
4020

41-
The library can be installed through `pip` with `python3 -m pip install io4dolfinx`.
42-
For notes on installation of specific backends see the individual backend documentation.
21+
```python
22+
from pathlib import Path
23+
from mpi4py import MPI
24+
import dolfinx
25+
import io4dolfinx
4326

44-
See [./docs/installation.md](./docs/installation.md) for further info.
27+
# 1. Create a mesh and function
28+
comm = MPI.COMM_WORLD
29+
mesh = dolfinx.mesh.create_unit_square(comm, 10, 10)
30+
V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1))
31+
u = dolfinx.fem.Function(V)
32+
u.interpolate(lambda x: x[0] + x[1])
33+
u.name = "my_function"
4534

35+
# 2. Write checkpoint
36+
# The mesh must be written before the function
37+
filename = Path("checkpoint.bp")
38+
io4dolfinx.write_mesh(filename, mesh)
39+
io4dolfinx.write_function(filename, u, time=0.0)
4640

47-
## Functionality
41+
# 3. Read checkpoint
42+
# This works even if the number of MPI processes changes (N-to-M)
43+
mesh_new = io4dolfinx.read_mesh(filename, comm)
44+
V_new = dolfinx.fem.functionspace(mesh_new, ("Lagrange", 1))
45+
u_new = dolfinx.fem.Function(V_new)
46+
io4dolfinx.read_function(filename, u_new, time=0.0, name="my_function")
47+
```
4848

49-
### DOLFINx
5049

51-
- Reading and writing meshes, using `io4dolfinx.read/write_mesh`
52-
- Reading and writing meshtags associated to meshes `io4dolfinx.read/write_meshtags`
53-
- Reading checkpoints for any element (serial and parallel, arbitrary number of functions and timesteps per file). Use `io4dolfinx.read/write_function`.
54-
- Writing standalone function checkpoints relating to "original meshes", i.e. meshes read from `XDMFFile`. Use `io4dolfinx.write_function_on_input_mesh` for this.
55-
- Store mesh partitioning and re-read the mesh with this information, avoiding calling SCOTCH, Kahip or Parmetis.
50+
## Features and Backends
5651

57-
> [!IMPORTANT]
58-
> For checkpoints written with `write_function` to be valid, you first have to store the mesh with `write_mesh` to the checkpoint file.
52+
`io4dolfinx` supports custom user backends. You can switch backends by passing `backend="name"` to IO functions.
5953

60-
> [!IMPORTANT]
61-
> A checkpoint file supports multiple functions and multiple time steps, as long as the functions are associated with the same mesh
54+
### Checkpointing (N-to-M)
55+
Many finite element applications requires storage of functions that cannot be associated with the nodes or cells of the mesh. Therefore, we have implemented our own, native checkpointing format that supports N-to-M checkpointing (write data on N processors, read in on M) through the following backends:
6256

63-
> [!IMPORTANT]
64-
> Only one mesh per file is allowed
57+
- [h5py](./docs/backends/h5py.rst): Requires HDF5 with MPI support to work, but can store, meshes, partitioning info, meshtags, function data and more.
58+
- [adios2](./docs/backends/adios2.rst): Requires [ADIOS 2](https://adios2.readthedocs.io/en/latest/) compiled with MPI support and Python bindings. Supports the same set of operations as the `h5py` backend.
6559

60+
The code uses the ADIOS2/Python-wrappers and h5py module to write DOLFINx objects to file, supporting N-to-M (_recoverable_) and N-to-N (_snapshot_) checkpointing.
61+
See: [Checkpointing in DOLFINx - FEniCS 23](https://jsdokken.com/checkpointing-presentation/#/) or the examples in the [Documentation](https://jsdokken.com/io4dolfinx/) for more information.
6662

67-
## Example Usage
63+
For scalability, the code uses [MPI Neighbourhood collectives](https://www.mpi-forum.org/docs/mpi-3.1/mpi31-report/node200.htm) for communication across processes.
6864

69-
The repository contains many documented examples of usage, in the `docs`-folder, including
7065

71-
- [Reading and writing mesh checkpoints](./docs/writing_mesh_checkpoint.py)
72-
- [Storing mesh partitioning data](./docs/partitioned_mesh.py)
73-
- [Writing mesh-tags to a checkpoint](./docs/meshtags.py)
74-
- [Reading and writing function checkpoints](./docs/writing_functions_checkpoint.py)
75-
- [Checkpoint on input mesh](./docs/original_checkpoint.py)
76-
- Further examples can be found at [io4dolfinx examples](https://jsdokken.com/io4dolfinx/)
66+
### Mesh IO (Import/Export)
67+
Most meshing formats supports associating data with the nodes of the mesh (the mesh can be higher order) and the cells of the mesh. The node data can be read in as P-th order Lagrange functions (where P is the order of the grid), while the cell data can be read in as piecewise constant (DG-0) functions.
7768

78-
### Legacy DOLFIN
69+
- [VTKHDF](./docs/backends/vtkhdf.rst): The new scalable format from VTK, called [VTKHDF](https://docs.vtk.org/en/latest/vtk_file_formats/vtkhdf_file_format/index.html) is supported by the `vtkhdf` backend.
70+
- [XDMF](./docs/backends/xdmf.rst) (eXtensible Model Data Format): `.xdmf`. The `xdmf` backend supports the `HDF5` encoding, to ensure performance in parallel.
71+
- [PyVista](./docs/backends/pyvista.rst) (IO backend is meshio): The [pyvista](https://pyvista.org/) backend uses {py:func}`pyvista.read` to read in meshes, point data and cell data. `pyvista` relies on [meshio](https://github.com/nschloe/meshio) for most reading operations (including the XDMF ascii format).
7972

80-
Only checkpoints for `Lagrange` or `DG` functions are supported from legacy DOLFIN
8173

82-
- Reading meshes from the DOLFIN HDF5File-format
83-
- Reading checkpoints from the DOLFIN HDF5File-format (one checkpoint per file only)
84-
- Reading checkpoints from the DOLFIN XDMFFile-format (one checkpoint per file only, and only uses the `.h5` file)
8574

86-
See the [API](./docs/api) for more information.
75+
## Advanced Usage
8776

88-
## Testing
77+
The repository contains detailed documented examples in the `docs` folder:
8978

90-
This library uses `pytest` for testing.
91-
To execute the tests, one should first install the library and its dependencies, as listed above.
92-
Then, can execute all tests by calling
79+
* [Reading and writing mesh checkpoints](./docs/writing_mesh_checkpoint.py)
80+
* [Storing mesh partitioning data](./docs/partitioned_mesh.py) (Avoid re-partitioning when restarting)
81+
* [Writing mesh-tags](./docs/meshtags.py)
82+
* [Writing function checkpoints](./docs/writing_functions_checkpoint.py)
83+
* [Checkpoint on input mesh](./docs/original_checkpoint.py)
9384

94-
```bash
95-
python3 -m pytest .
96-
```
85+
For a full API reference and backend details, see the [Documentation](https://jsdokken.com/io4dolfinx/).
9786

98-
### Testing against data from legacy dolfin
87+
### Legacy DOLFIN Support
88+
`io4dolfinx` can read checkpoints created by the legacy version of DOLFIN (Lagrange or DG functions).
89+
* Reading meshes from DOLFIN HDF5File-format.
90+
* Reading checkpoints from DOLFIN HDF5File and XDMFFile.
9991

100-
Some tests check the capability of reading data created with the legacy version of DOLFIN.
101-
To create this dataset, start a docker container with legacy DOLFIN, for instance:
92+
## Project Background
10293

103-
```bash
104-
docker run -ti -v $(pwd):/root/shared -w /root/s
105-
hared --rm ghcr.io/scientificcomputing/fenics:2024-02-19
106-
```
94+
### Relation to adios4dolfinx
95+
This library is an evolution of [adios4dolfinx](https://doi.org/10.21105/joss.06451). It includes all functionality of the original library but has been refactored to support multiple IO backends (not just ADIOS2), making it easier to interface with different meshing formats while keeping the library structure sane.
10796

108-
Then, inside this container, call
97+
### Statement of Need
98+
As large-scale, long-running simulations on HPC clusters become more common, the need to store intermediate solutions is crucial. If a system crashes or a computational budget is exceeded, checkpoints allow the simulation to resume without restarting from scratch. `io4dolfinx` extends DOLFINx with this essential functionality.
10999

110-
```bash
111-
python3 ./tests/create_legacy_data.py --output-dir=legacy
112-
```
100+
## Contributing
113101

114-
### Testing against data from older versions of io4dolfinx
102+
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
115103

116-
Some tests check the capability to read data generated by `io4dolfinx<0.7.2`.
117-
To generate data for these tests use the following commands:
104+
## Testing
118105

119-
```bash
120-
docker run -ti -v $(pwd):/root/shared -w /root/shared --rm ghcr.io/fenics/dolfinx/dolfinx:v0.7.3
121-
```
106+
`io4dolfinx` includes a comprehensive test suite that ensures functionality across different backends and compatibility with legacy data formats, see the [Testing Guide](./docs/testing.md) for details.
122107

123-
Then, inside the container, call
124108

125-
```bash
126-
python3 -m pip install io4dolfinx==0.7.1
127-
python3 ./tests/create_legacy_checkpoint.py --output-dir=legacy_checkpoint
128-
```
109+
## LICENSE
110+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

_toc.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ parts:
55
- caption: How to guides
66
chapters:
77
- file: "docs/installation"
8+
- file: "docs/quickstart"
89
- file: "docs/adding_backend"
910
- file: "docs/migration_guide"
11+
- file: "docs/testing.md"
12+
- file: "docs/reading_legacy_data"
1013

1114
- caption: Introduction to IPyParallel
1215
chapters:
@@ -32,4 +35,8 @@ parts:
3235
- file: "docs/backends/h5py"
3336
- file: "docs/backends/pyvista"
3437
- file: "docs/backends/xdmf"
35-
- file: "docs/backends/vtkhdf"
38+
- file: "docs/backends/vtkhdf"
39+
40+
- caption: Contributing
41+
chapters:
42+
- file: "CONTRIBUTING"

docs/installation.md

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
# Installation
22

3+
The main way to install `io4dolfinx` is through [PYPI](https://pypi.org/project/io4dolfinx/), which provides pre-built binary wheels for most platforms. This is the recommended method for most users.
34

4-
## Spack
5+
```bash
6+
python3 -m pip install io4dolfinx
7+
```
8+
9+
`io4dolfinx` has some optional dependencies for specific backends (like ADIOS2 or H5PY). If you want to use these backends, you can install the library with the appropriate extras:
510

6-
io4dolfinx is a [spack package](https://packages.spack.io/package.html?name=py-io4dolfinx)
7-
which can be installed with
11+
- Test dependencies (for running the test suite):
12+
```bash
13+
python3 -m pip install "io4dolfinx[test]"
14+
```
815

16+
- Documentation dependencies (for building the docs):
917
```bash
10-
spack add py-io4dolfinx ^py-fenics-dolfinx+petsc4py+slepc4py
11-
spack concretize
12-
spack install
18+
python3 -m pip install "io4dolfinx[docs]"
1319
```
1420

15-
once you have downloaded spack and set up a new environment, as described in [Spack: Installation notes](https://github.com/spack/spack?tab=readme-ov-file#installation).
16-
To ensure that the spack packages are up to date, please call
21+
- For HDF5 support with MPI, you need to have an HDF5 library installed with MPI support, and the `h5py` Python package installed with MPI support. You can install `h5py` with MPI support using pip:
22+
```bash
23+
python3 -m pip install --no-binary=h5py h5py
24+
```
1725

26+
- For pyvista support, you can install the `pyvista` package:
1827
```bash
19-
spack repo update builtin
28+
python3 -m pip install pyvista
2029
```
30+
or equivalently
31+
```bash
32+
python3 -m pip install "io4dolfinx[pyvista]"
33+
```
34+
35+
- For ADIOS2 support you should have ADIOS2 installed with Python bindings, see https://adios2.readthedocs.io/en/latest/setting_up/setting_up.html for more info.
36+
2137

22-
prior to concretizing.
38+
## Spack
39+
40+
TBW
2341

2442
## Docker
2543

@@ -38,7 +56,7 @@ For the latest version compatible with nightly (with the ability to run the test
3856
```bash
3957
export HDF5_MPI=ON
4058
export HDF5_DIR=/usr/local
41-
python3 -m pip install --no-binary-h5py --no-build-isolation io4dolfinx[test]@git+https://github.com/jorgensd/io4dolfinx@main
59+
python3 -m pip install --no-binary-h5py --no-build-isolation io4dolfinx[test]@git+https://github.com/scientificcomputing/io4dolfinx@main
4260
```
4361

4462
If you are using the `stable` image, you can install `io4dolfinx` from [PYPI](https://pypi.org/project/io4dolfinx/) with
@@ -57,19 +75,21 @@ at a later instance
5775

5876
## Conda
5977

60-
> [!NOTE]
61-
> Conda supports the stable release of DOLFINx, and thus the appropriate version should be installed, see the section above for more details.
78+
```{note}
79+
Conda supports the stable release of DOLFINx, and thus the appropriate version should be installed, see the section above for more details.
80+
```
6281

6382
Following is a minimal recipe of how to install io4dolfinx, given that you have conda installed on your system.
6483

6584
```bash
66-
conda create -n dolfinx-checkpoint python=3.10
85+
conda create -n dolfinx-checkpoint python=3.12
6786
conda activate dolfinx-checkpoint
6887
conda install -c conda-forge io4dolfinx
6988
```
7089

71-
> [!NOTE]
72-
> Remember to download the appropriate version of `io4dolfinx` from Github [io4dolfinx: Releases](https://github.com/jorgensd/io4dolfinx/releases)
90+
```{note}
91+
Remember to download the appropriate version of `io4dolfinx` from Github [io4dolfinx: Releases](https://github.com/scientificcomputing/io4dolfinx/releases)
92+
```
7393

7494
To run the test suite, you should also install `ipyparallel`, `pytest` and `coverage`, which can all be installed with conda
7595

docs/original_checkpoint.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def create_xdmf_mesh(filename: Path):
3333
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
3434
facets = dolfinx.mesh.locate_entities_boundary(mesh, mesh.topology.dim - 1, locate_facets)
3535
facet_tag = dolfinx.mesh.meshtags(mesh, mesh.topology.dim - 1, facets, 1)
36-
facet_tag.name = "FacetTag"
3736
with dolfinx.io.XDMFFile(MPI.COMM_WORLD, filename.with_suffix(".xdmf"), "w") as xdmf:
3837
xdmf.write_mesh(mesh)
3938
xdmf.write_meshtags(facet_tag, mesh.geometry)

0 commit comments

Comments
 (0)