|
1 | 1 | # io4dolfinx - A framework for reading and writing data to various mesh formats |
2 | 2 |
|
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. |
4 | 4 |
|
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). |
11 | 5 |
|
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 |
25 | 7 |
|
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. |
27 | 9 |
|
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 | +``` |
29 | 13 |
|
30 | | -## Statement of Need |
| 14 | +For specific backend requirements (like ADIOS2 or H5PY), see the [Installation Guide](./docs/installation.md). |
31 | 15 |
|
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. |
36 | 16 |
|
37 | | -## Installation |
| 17 | +## Quick Start |
38 | 18 |
|
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). |
40 | 20 |
|
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 |
43 | 26 |
|
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" |
45 | 34 |
|
| 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) |
46 | 40 |
|
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 | +``` |
48 | 48 |
|
49 | | -### DOLFINx |
50 | 49 |
|
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 |
56 | 51 |
|
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. |
59 | 53 |
|
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: |
62 | 56 |
|
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. |
65 | 59 |
|
| 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. |
66 | 62 |
|
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. |
68 | 64 |
|
69 | | -The repository contains many documented examples of usage, in the `docs`-folder, including |
70 | 65 |
|
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. |
77 | 68 |
|
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). |
79 | 72 |
|
80 | | -Only checkpoints for `Lagrange` or `DG` functions are supported from legacy DOLFIN |
81 | 73 |
|
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) |
85 | 74 |
|
86 | | -See the [API](./docs/api) for more information. |
| 75 | +## Advanced Usage |
87 | 76 |
|
88 | | -## Testing |
| 77 | +The repository contains detailed documented examples in the `docs` folder: |
89 | 78 |
|
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) |
93 | 84 |
|
94 | | -```bash |
95 | | -python3 -m pytest . |
96 | | -``` |
| 85 | +For a full API reference and backend details, see the [Documentation](https://jsdokken.com/io4dolfinx/). |
97 | 86 |
|
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. |
99 | 91 |
|
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 |
102 | 93 |
|
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. |
107 | 96 |
|
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. |
109 | 99 |
|
110 | | -```bash |
111 | | -python3 ./tests/create_legacy_data.py --output-dir=legacy |
112 | | -``` |
| 100 | +## Contributing |
113 | 101 |
|
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. |
115 | 103 |
|
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 |
118 | 105 |
|
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. |
122 | 107 |
|
123 | | -Then, inside the container, call |
124 | 108 |
|
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. |
0 commit comments