io4dolfinx 2.0.0__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {io4dolfinx-2.0.0/src/io4dolfinx.egg-info → io4dolfinx-2.2.0}/PKG-INFO +17 -2
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/README.md +15 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/pyproject.toml +25 -4
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/__init__.py +88 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/adios2/backend.py +54 -19
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/adios2/helpers.py +25 -1
- io4dolfinx-2.2.0/src/io4dolfinx/backends/adios2_serial/backend.py +146 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/h5py/backend.py +105 -39
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/h5py/storage.py +42 -1
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/h5py_serial/backend.py +9 -1
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/serial.py +38 -16
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/vtkhdf/backend.py +1 -1
- io4dolfinx-2.2.0/src/io4dolfinx/backends/xdmf/__init__.py +3 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/checkpointing.py +15 -37
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/converter.py +1 -1
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/readers.py +4 -19
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/submesh.py +4 -4
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0/src/io4dolfinx.egg-info}/PKG-INFO +17 -2
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx.egg-info/SOURCES.txt +3 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx.egg-info/requires.txt +1 -1
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_attributes.py +2 -2
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_backends.py +67 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_checkpointing.py +62 -3
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_converter.py +7 -1
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_format_version.py +1 -1
- io4dolfinx-2.2.0/tests/test_h5py_compression.py +321 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_meshtags.py +1 -1
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_openfoam.py +1 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_original_checkpoint.py +2 -2
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_snapshot_checkpoint.py +1 -1
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_submesh.py +1 -1
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_vtkhdf.py +88 -32
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_vtkhdf_compression.py +1 -1
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/LICENSE +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/setup.cfg +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/__init__.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/ascii_helpers.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/adios2/__init__.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/exodus → io4dolfinx-2.2.0/src/io4dolfinx/backends/adios2_serial}/__init__.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/gmsh → io4dolfinx-2.2.0/src/io4dolfinx/backends/exodus}/__init__.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/exodus/backend.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/h5py → io4dolfinx-2.2.0/src/io4dolfinx/backends/gmsh}/__init__.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/gmsh/backend.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/h5py_serial → io4dolfinx-2.2.0/src/io4dolfinx/backends/h5py}/__init__.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/med → io4dolfinx-2.2.0/src/io4dolfinx/backends/h5py_serial}/__init__.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/nastran → io4dolfinx-2.2.0/src/io4dolfinx/backends/med}/__init__.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/med/backend.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/opencarp → io4dolfinx-2.2.0/src/io4dolfinx/backends/nastran}/__init__.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/nastran/backend.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/nastran/helpers.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/openfoam → io4dolfinx-2.2.0/src/io4dolfinx/backends/opencarp}/__init__.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/opencarp/backend.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/opencarp/helpers.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/pyvista → io4dolfinx-2.2.0/src/io4dolfinx/backends/openfoam}/__init__.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/openfoam/backend.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/openfoam/helpers.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/vtkhdf → io4dolfinx-2.2.0/src/io4dolfinx/backends/pyvista}/__init__.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/pyvista/backend.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/pyvista/helpers.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/vtk_cell_types.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/vtkhdf_serial → io4dolfinx-2.2.0/src/io4dolfinx/backends/vtkhdf}/__init__.py +0 -0
- {io4dolfinx-2.0.0/src/io4dolfinx/backends/xdmf → io4dolfinx-2.2.0/src/io4dolfinx/backends/vtkhdf_serial}/__init__.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/vtkhdf_serial/backend.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/backends/xdmf/backend.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/comm_helpers.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/format.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/original_checkpoint.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/py.typed +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/snapshot.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/structures.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/utils.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx/writers.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx.egg-info/dependency_links.txt +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx.egg-info/entry_points.txt +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/src/io4dolfinx.egg-info/top_level.txt +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_checkpointing_vector.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_exodus.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_geometry_dofmap_reconstruction.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_gmsh.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_legacy_readers.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_med.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_mesh_writer.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_nastran.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_numpy_vectorization.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_opencarp.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_pyvista.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_version.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_write_data_input_order.py +0 -0
- {io4dolfinx-2.0.0 → io4dolfinx-2.2.0}/tests/test_xdmf.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: io4dolfinx
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Checkpointing functionality for DOLFINx meshes/functions with ADIOS2
|
|
5
5
|
Author-email: "Jørgen S. Dokken" <dokken@simula.no>, "Henrik N.T. Finsberg" <henriknf@simula.no>
|
|
6
6
|
License: Copyright 2023 Jørgen S. Dokken, Henrik N.T. Finsberg and Simula Research Laboratory
|
|
@@ -15,7 +15,7 @@ Requires-Python: >=3.12
|
|
|
15
15
|
Description-Content-Type: text/markdown
|
|
16
16
|
License-File: LICENSE
|
|
17
17
|
Requires-Dist: fenics-dolfinx>=0.10.0
|
|
18
|
-
Requires-Dist: fenicsx-compat>=0.
|
|
18
|
+
Requires-Dist: fenicsx-compat>=0.7.0
|
|
19
19
|
Requires-Dist: h5py>=3.10
|
|
20
20
|
Provides-Extra: adios2
|
|
21
21
|
Requires-Dist: adios2; extra == "adios2"
|
|
@@ -150,6 +150,21 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc
|
|
|
150
150
|
|
|
151
151
|
`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.
|
|
152
152
|
|
|
153
|
+
## Releasing
|
|
154
|
+
Versions are managed with [bump-my-version](https://callowayproject.github.io/bump-my-version/), configured in `pyproject.toml`. Between releases the version is a development version, `X.Y.Z.devN`; a release drops the suffix. Each bump commits the version change, so start from a clean working tree.
|
|
155
|
+
|
|
156
|
+
To release the current development version, e.g. `2.1.0.dev0`, and start the next one:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
bump-my-version bump release --no-tag # 2.1.0.dev0 -> 2.1.0
|
|
160
|
+
bump-my-version bump minor --no-tag # 2.1.0 -> 2.2.0.dev0
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
For a patch release of 2.1, bump `patch` instead of `minor` (`2.1.0 -> 2.1.1.dev0`), then `release` (`2.1.1.dev0 -> 2.1.1`). `bump-my-version show-bump` previews what each bump gives.
|
|
164
|
+
|
|
165
|
+
The bumps do not tag. A `v*` tag publishes to PyPI and the documentation, so tag the release commit (`Bump version: 2.1.0.dev0 → 2.1.0`) as `v2.1.0`, for instance by creating a GitHub release from it.
|
|
166
|
+
|
|
167
|
+
Releasing a new minor version also adds it to `.github/docs-versions.toml`, which lists the versions on the documentation website, built in the DOLFINx image of the previous one; edit that image afterwards if a newer DOLFINx release should be used. A patch release needs no entry, as each minor version is built from its newest tag.
|
|
153
168
|
|
|
154
169
|
## LICENSE
|
|
155
170
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -111,6 +111,21 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc
|
|
|
111
111
|
|
|
112
112
|
`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.
|
|
113
113
|
|
|
114
|
+
## Releasing
|
|
115
|
+
Versions are managed with [bump-my-version](https://callowayproject.github.io/bump-my-version/), configured in `pyproject.toml`. Between releases the version is a development version, `X.Y.Z.devN`; a release drops the suffix. Each bump commits the version change, so start from a clean working tree.
|
|
116
|
+
|
|
117
|
+
To release the current development version, e.g. `2.1.0.dev0`, and start the next one:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
bump-my-version bump release --no-tag # 2.1.0.dev0 -> 2.1.0
|
|
121
|
+
bump-my-version bump minor --no-tag # 2.1.0 -> 2.2.0.dev0
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
For a patch release of 2.1, bump `patch` instead of `minor` (`2.1.0 -> 2.1.1.dev0`), then `release` (`2.1.1.dev0 -> 2.1.1`). `bump-my-version show-bump` previews what each bump gives.
|
|
125
|
+
|
|
126
|
+
The bumps do not tag. A `v*` tag publishes to PyPI and the documentation, so tag the release commit (`Bump version: 2.1.0.dev0 → 2.1.0`) as `v2.1.0`, for instance by creating a GitHub release from it.
|
|
127
|
+
|
|
128
|
+
Releasing a new minor version also adds it to `.github/docs-versions.toml`, which lists the versions on the documentation website, built in the DOLFINx image of the previous one; edit that image afterwards if a newer DOLFINx release should be used. A patch release needs no entry, as each minor version is built from its newest tag.
|
|
114
129
|
|
|
115
130
|
## LICENSE
|
|
116
131
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
|
|
|
11
11
|
|
|
12
12
|
[project]
|
|
13
13
|
name = "io4dolfinx"
|
|
14
|
-
version = "2.
|
|
14
|
+
version = "2.2.0"
|
|
15
15
|
description = "Checkpointing functionality for DOLFINx meshes/functions with ADIOS2"
|
|
16
16
|
authors = [
|
|
17
17
|
{ name = "Jørgen S. Dokken", email = "dokken@simula.no" },
|
|
@@ -20,7 +20,7 @@ authors = [
|
|
|
20
20
|
license = { file = "LICENSE" }
|
|
21
21
|
readme = "README.md"
|
|
22
22
|
requires-python = ">=3.12"
|
|
23
|
-
dependencies = ["fenics-dolfinx>=0.10.0", "fenicsx-compat>=0.
|
|
23
|
+
dependencies = ["fenics-dolfinx>=0.10.0", "fenicsx-compat>=0.7.0", "h5py>=3.10"]
|
|
24
24
|
|
|
25
25
|
[project.scripts]
|
|
26
26
|
io4dolfinx-convert = "io4dolfinx.converter:main"
|
|
@@ -141,9 +141,30 @@ tag = true
|
|
|
141
141
|
sign_tags = false
|
|
142
142
|
tag_name = "v{new_version}"
|
|
143
143
|
tag_message = "Bump version: {current_version} → {new_version}"
|
|
144
|
-
current_version = "2.
|
|
144
|
+
current_version = "2.2.0"
|
|
145
|
+
# X.Y.Z.devN while developing, X.Y.Z when released
|
|
146
|
+
parse = '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>dev)(?P<pre_n>\d+))?'
|
|
147
|
+
serialize = ["{major}.{minor}.{patch}.{release}{pre_n}", "{major}.{minor}.{patch}"]
|
|
148
|
+
|
|
149
|
+
[tool.bumpversion.parts.release]
|
|
150
|
+
# "final" is the released state: never written in the version, reached with `bump release`
|
|
151
|
+
values = ["dev", "final"]
|
|
152
|
+
optional_value = "final"
|
|
145
153
|
|
|
146
154
|
[[tool.bumpversion.files]]
|
|
147
155
|
filename = "pyproject.toml"
|
|
148
|
-
|
|
156
|
+
# Anchored, so it is the [project] version and not current_version
|
|
157
|
+
regex = true
|
|
158
|
+
search = '^version = "{current_version}"$'
|
|
149
159
|
replace = 'version = "{new_version}"'
|
|
160
|
+
|
|
161
|
+
# Releasing a new minor version (`bump release` to X.Y.0) adds its documentation version, built
|
|
162
|
+
# in the DOLFINx image of the previous minor release. Update that image if a newer DOLFINx
|
|
163
|
+
# release is stable. A patch release needs no entry, as each minor is built from its newest tag.
|
|
164
|
+
[[tool.bumpversion.files]]
|
|
165
|
+
filename = ".github/docs-versions.toml"
|
|
166
|
+
include_bumps = ["release"]
|
|
167
|
+
ignore_missing_version = true
|
|
168
|
+
regex = true
|
|
169
|
+
search = '(?P<last>^"(?!{new_major}\.{new_minor}")\d+\.\d+" = "(?P<image>[^"]+)"\n)\Z'
|
|
170
|
+
replace = '\g<last>"{new_major}.{new_minor}" = "\g<image>"\n'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import warnings
|
|
2
|
+
from collections.abc import Iterable
|
|
2
3
|
from enum import Enum
|
|
3
4
|
from importlib import import_module
|
|
4
5
|
from pathlib import Path
|
|
@@ -23,9 +24,11 @@ __all__ = [
|
|
|
23
24
|
"DEFAULT_MESH_NAME",
|
|
24
25
|
"FileMode",
|
|
25
26
|
"IOBackend",
|
|
27
|
+
"function_not_found",
|
|
26
28
|
"get_backend",
|
|
27
29
|
"get_mesh_name",
|
|
28
30
|
"set_default_backend",
|
|
31
|
+
"with_mesh_name",
|
|
29
32
|
]
|
|
30
33
|
|
|
31
34
|
_DEFAULT_BACKEND = "h5py"
|
|
@@ -55,6 +58,70 @@ def get_mesh_name(backend_args: dict[str, Any] | None) -> str:
|
|
|
55
58
|
return DEFAULT_MESH_NAME if name is None else str(name)
|
|
56
59
|
|
|
57
60
|
|
|
61
|
+
def with_mesh_name(
|
|
62
|
+
backend_args: dict[str, Any] | None, mesh_name: str | None
|
|
63
|
+
) -> dict[str, Any] | None:
|
|
64
|
+
"""Backend arguments selecting the mesh ``mesh_name``, as backends expect them.
|
|
65
|
+
|
|
66
|
+
Public functions take the mesh as ``mesh_name``, while backends read it from
|
|
67
|
+
``backend_args["name"]`` (see :func:`get_mesh_name`). Passing the mesh name in
|
|
68
|
+
``backend_args`` to a public function is deprecated.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
backend_args: Backend arguments of the caller, not modified.
|
|
72
|
+
mesh_name: Name of the mesh, or ``None`` for the default mesh.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
``backend_args`` with ``"name"`` set to ``mesh_name``.
|
|
76
|
+
|
|
77
|
+
Raises:
|
|
78
|
+
ValueError: If ``backend_args["name"]`` and ``mesh_name`` name different meshes.
|
|
79
|
+
"""
|
|
80
|
+
if backend_args is not None and "name" in backend_args:
|
|
81
|
+
if mesh_name is not None and backend_args["name"] != mesh_name:
|
|
82
|
+
raise ValueError(
|
|
83
|
+
f"backend_args['name']={backend_args['name']!r} and mesh_name={mesh_name!r} "
|
|
84
|
+
"name different meshes; pass mesh_name only."
|
|
85
|
+
)
|
|
86
|
+
warnings.warn(
|
|
87
|
+
"Passing the mesh name as backend_args['name'] is deprecated; use mesh_name.",
|
|
88
|
+
DeprecationWarning,
|
|
89
|
+
stacklevel=3,
|
|
90
|
+
)
|
|
91
|
+
return backend_args
|
|
92
|
+
if mesh_name is None:
|
|
93
|
+
return backend_args
|
|
94
|
+
return {**(backend_args or {}), "name": mesh_name}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def function_not_found(
|
|
98
|
+
filename: Path | str, function_name: str, mesh_name: str, function_names: Iterable[str]
|
|
99
|
+
) -> KeyError:
|
|
100
|
+
"""The error for a function a checkpoint does not hold, naming the ones it does.
|
|
101
|
+
|
|
102
|
+
The names tell a misspelt name, or one written on another mesh, from a function that
|
|
103
|
+
was never written.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
filename: Path to the file
|
|
107
|
+
function_name: Name of the function asked for
|
|
108
|
+
mesh_name: Name of the mesh it was asked for on
|
|
109
|
+
function_names: Names of the functions the file holds on that mesh
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
The error to raise
|
|
113
|
+
"""
|
|
114
|
+
names = sorted(set(function_names))
|
|
115
|
+
holds = (
|
|
116
|
+
f"Functions on that mesh: {', '.join(map(repr, names))}."
|
|
117
|
+
if names
|
|
118
|
+
else "There are no functions on that mesh."
|
|
119
|
+
)
|
|
120
|
+
return KeyError(
|
|
121
|
+
f"Function {function_name!r} not found on mesh {mesh_name!r} in {filename}. {holds}"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
58
125
|
def set_default_backend(backend: str):
|
|
59
126
|
"""Set the global default backend for io4dolfinx."""
|
|
60
127
|
global _DEFAULT_BACKEND
|
|
@@ -177,6 +244,11 @@ class IOBackend(Protocol):
|
|
|
177
244
|
|
|
178
245
|
Returns:
|
|
179
246
|
Numpy array of timestamps read from file
|
|
247
|
+
|
|
248
|
+
Raises:
|
|
249
|
+
KeyError: In the adios2 and h5py backends, if the file does not hold the
|
|
250
|
+
function on that mesh. The message names the functions it does hold
|
|
251
|
+
(:func:`function_not_found`).
|
|
180
252
|
"""
|
|
181
253
|
|
|
182
254
|
def write_mesh(
|
|
@@ -501,6 +573,17 @@ def get_backend(backend: str | None = None) -> IOBackend:
|
|
|
501
573
|
stacklevel=2,
|
|
502
574
|
)
|
|
503
575
|
backend = f"{backend}-serial"
|
|
576
|
+
elif backend == "adios2":
|
|
577
|
+
import adios2
|
|
578
|
+
|
|
579
|
+
if not adios2.is_built_with_mpi:
|
|
580
|
+
warnings.warn(
|
|
581
|
+
"ADIOS2 is built without MPI, so the adios2 backend runs as adios2-serial, "
|
|
582
|
+
"which writes all data through rank 0. Install ADIOS2 with MPI for parallel IO, "
|
|
583
|
+
"see the io4dolfinx installation guide.",
|
|
584
|
+
stacklevel=2,
|
|
585
|
+
)
|
|
586
|
+
backend = "adios2-serial"
|
|
504
587
|
|
|
505
588
|
if backend == "h5py":
|
|
506
589
|
from .h5py import backend as H5PYInterface
|
|
@@ -518,6 +601,10 @@ def get_backend(backend: str | None = None) -> IOBackend:
|
|
|
518
601
|
from .adios2 import backend as ADIOS2Interface
|
|
519
602
|
|
|
520
603
|
return ADIOS2Interface
|
|
604
|
+
elif backend == "adios2-serial":
|
|
605
|
+
from .adios2_serial import backend as ADIOS2SerialInterface
|
|
606
|
+
|
|
607
|
+
return ADIOS2SerialInterface
|
|
521
608
|
elif backend == "pyvista":
|
|
522
609
|
from .pyvista import backend as PYVISTAInterface
|
|
523
610
|
|
|
@@ -563,6 +650,7 @@ BUILTIN_BACKENDS = (
|
|
|
563
650
|
"h5py-serial",
|
|
564
651
|
"vtkhdf-serial",
|
|
565
652
|
"adios2",
|
|
653
|
+
"adios2-serial",
|
|
566
654
|
"pyvista",
|
|
567
655
|
"xdmf",
|
|
568
656
|
"vtkhdf",
|
|
@@ -13,17 +13,19 @@ import numpy.typing as npt
|
|
|
13
13
|
from ...format import METADATA_KEYS, stamp
|
|
14
14
|
from ...structures import ArrayData, FunctionData, MeshData, MeshTagsData, ReadMeshData
|
|
15
15
|
from ...utils import check_file_exists
|
|
16
|
-
from .. import DEFAULT_MESH_NAME, FileMode, ReadMode, get_mesh_name
|
|
16
|
+
from .. import DEFAULT_MESH_NAME, FileMode, ReadMode, function_not_found, get_mesh_name
|
|
17
17
|
from .helpers import (
|
|
18
18
|
ADIOSFile,
|
|
19
19
|
adios_to_numpy_dtype,
|
|
20
20
|
check_variable_exists,
|
|
21
|
+
create_adios,
|
|
21
22
|
read_adjacency_list,
|
|
22
23
|
read_array,
|
|
23
24
|
read_local_rows,
|
|
24
25
|
)
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
# ADIOS2 without MPI is supported through the adios2-serial backend
|
|
28
|
+
adios2 = fenicsx_compat.resolve_adios_scope(adios2, require_mpi=False)
|
|
27
29
|
|
|
28
30
|
read_mode = ReadMode.parallel
|
|
29
31
|
|
|
@@ -68,6 +70,29 @@ def mesh_prefix(backend_args: dict[str, Any] | None) -> str:
|
|
|
68
70
|
return "" if name == DEFAULT_MESH_NAME else f"{name}/"
|
|
69
71
|
|
|
70
72
|
|
|
73
|
+
def _function_names(variables, prefix: str) -> set[str]:
|
|
74
|
+
"""Names of the functions of the mesh with ``prefix`` among ADIOS2 ``variables``.
|
|
75
|
+
|
|
76
|
+
Every function has a ``<prefix><name>_time`` variable. The default mesh's prefix is
|
|
77
|
+
empty, so a name holding ``/`` there belongs to another mesh and is left out.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
variables: Names of the variables of a step
|
|
81
|
+
prefix: The mesh's prefix (:func:`mesh_prefix`)
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
The function names
|
|
85
|
+
"""
|
|
86
|
+
suffix = "_time"
|
|
87
|
+
names = set()
|
|
88
|
+
for variable in variables:
|
|
89
|
+
if variable.startswith(prefix) and variable.endswith(suffix):
|
|
90
|
+
name = variable[len(prefix) : -len(suffix)]
|
|
91
|
+
if name and "/" not in name:
|
|
92
|
+
names.add(name)
|
|
93
|
+
return names
|
|
94
|
+
|
|
95
|
+
|
|
71
96
|
def _seek_step(adios_file, variable: str, start: int = 0) -> int:
|
|
72
97
|
"""Advance the reader to the first step at or after ``start`` holding ``variable``.
|
|
73
98
|
|
|
@@ -155,7 +180,7 @@ def read_metadata(
|
|
|
155
180
|
attribute_prefix = _metadata_prefix(kind, name, backend_args)
|
|
156
181
|
wanted = {f"{attribute_prefix}{key}": key for key in METADATA_KEYS}
|
|
157
182
|
metadata: dict[str, Any] = {}
|
|
158
|
-
adios =
|
|
183
|
+
adios = create_adios(comm)
|
|
159
184
|
with ADIOSFile(
|
|
160
185
|
adios=adios,
|
|
161
186
|
filename=filename,
|
|
@@ -194,7 +219,7 @@ def write_attributes(
|
|
|
194
219
|
engine: ADIOS2 engine to use
|
|
195
220
|
"""
|
|
196
221
|
|
|
197
|
-
adios =
|
|
222
|
+
adios = create_adios(comm)
|
|
198
223
|
backend_args = get_default_backend_args(backend_args)
|
|
199
224
|
|
|
200
225
|
with ADIOSFile(
|
|
@@ -230,7 +255,7 @@ def read_attributes(
|
|
|
230
255
|
The attributes
|
|
231
256
|
"""
|
|
232
257
|
check_file_exists(filename)
|
|
233
|
-
adios =
|
|
258
|
+
adios = create_adios(comm)
|
|
234
259
|
backend_args = get_default_backend_args(backend_args)
|
|
235
260
|
with ADIOSFile(
|
|
236
261
|
adios=adios,
|
|
@@ -265,10 +290,13 @@ def read_timestamps(
|
|
|
265
290
|
backend: What backend to use for writing.
|
|
266
291
|
Returns:
|
|
267
292
|
The time-stamps
|
|
293
|
+
|
|
294
|
+
Raises:
|
|
295
|
+
KeyError: If the file does not hold the function on that mesh, naming those it does
|
|
268
296
|
"""
|
|
269
297
|
check_file_exists(filename)
|
|
270
298
|
|
|
271
|
-
adios =
|
|
299
|
+
adios = create_adios(comm)
|
|
272
300
|
backend_args = get_default_backend_args(backend_args)
|
|
273
301
|
prefix = mesh_prefix(backend_args)
|
|
274
302
|
with ADIOSFile(
|
|
@@ -280,9 +308,12 @@ def read_timestamps(
|
|
|
280
308
|
) as adios_file:
|
|
281
309
|
time_name = f"{prefix}{function_name}_time"
|
|
282
310
|
time_stamps = []
|
|
311
|
+
function_names: set[str] = set()
|
|
283
312
|
for _ in range(adios_file.file.Steps()):
|
|
284
313
|
adios_file.file.BeginStep()
|
|
285
|
-
|
|
314
|
+
variables = adios_file.io.AvailableVariables()
|
|
315
|
+
function_names |= _function_names(variables, prefix)
|
|
316
|
+
if time_name in variables.keys():
|
|
286
317
|
arr = adios_file.io.InquireVariable(time_name)
|
|
287
318
|
time_shape = arr.Shape()
|
|
288
319
|
arr.SetSelection([[0], [time_shape[0]]])
|
|
@@ -294,6 +325,10 @@ def read_timestamps(
|
|
|
294
325
|
time_stamps.append(times[0])
|
|
295
326
|
adios_file.file.EndStep()
|
|
296
327
|
|
|
328
|
+
if not time_stamps: # Every write of a function writes its time
|
|
329
|
+
raise function_not_found(
|
|
330
|
+
filename, function_name, get_mesh_name(backend_args), function_names
|
|
331
|
+
)
|
|
297
332
|
return np.array(time_stamps)
|
|
298
333
|
|
|
299
334
|
|
|
@@ -322,7 +357,7 @@ def write_mesh(
|
|
|
322
357
|
|
|
323
358
|
mode = convert_file_mode(mode)
|
|
324
359
|
gdim = mesh.local_geometry.shape[1]
|
|
325
|
-
adios =
|
|
360
|
+
adios = create_adios(comm)
|
|
326
361
|
|
|
327
362
|
# Topology is constant in time and written once. In append mode it may
|
|
328
363
|
# already be present either because this mesh was written at an earlier time
|
|
@@ -441,7 +476,7 @@ def read_mesh_data(
|
|
|
441
476
|
The mesh topology, geometry, UFL domain and partition function
|
|
442
477
|
"""
|
|
443
478
|
|
|
444
|
-
adios =
|
|
479
|
+
adios = create_adios(comm)
|
|
445
480
|
backend_args = get_default_backend_args(backend_args)
|
|
446
481
|
legacy = backend_args.get("legacy", False)
|
|
447
482
|
if legacy:
|
|
@@ -569,7 +604,7 @@ def write_meshtags(
|
|
|
569
604
|
io_name = backend_args.get("io_name", "MeshTagWriter")
|
|
570
605
|
engine = backend_args.get("engine", "BP4")
|
|
571
606
|
prefix = mesh_prefix(backend_args)
|
|
572
|
-
adios =
|
|
607
|
+
adios = create_adios(comm)
|
|
573
608
|
with ADIOSFile(
|
|
574
609
|
adios=adios,
|
|
575
610
|
filename=filename,
|
|
@@ -624,7 +659,7 @@ def read_meshtags_data(
|
|
|
624
659
|
Internal data structure for the mesh tags read from file
|
|
625
660
|
"""
|
|
626
661
|
|
|
627
|
-
adios =
|
|
662
|
+
adios = create_adios(comm)
|
|
628
663
|
backend_args = get_default_backend_args(backend_args)
|
|
629
664
|
io_name = backend_args.get("io_name", "MeshTagsReader")
|
|
630
665
|
engine = backend_args["engine"]
|
|
@@ -754,7 +789,7 @@ def read_dofmap(
|
|
|
754
789
|
|
|
755
790
|
engine = backend_args.get("engine", "BP4")
|
|
756
791
|
|
|
757
|
-
adios =
|
|
792
|
+
adios = create_adios(comm)
|
|
758
793
|
check_file_exists(filename)
|
|
759
794
|
assert isinstance(xdofmap_path, str)
|
|
760
795
|
return read_adjacency_list(adios, comm, filename, dofmap_path, xdofmap_path, engine=engine)
|
|
@@ -788,7 +823,7 @@ def read_dofs(
|
|
|
788
823
|
io_name = backend_args.get("io_name", f"{name}_FunctionReader")
|
|
789
824
|
prefix = mesh_prefix(backend_args)
|
|
790
825
|
# Check that file contains the function to read
|
|
791
|
-
adios =
|
|
826
|
+
adios = create_adios(comm)
|
|
792
827
|
check_file_exists(filename)
|
|
793
828
|
|
|
794
829
|
if not legacy:
|
|
@@ -843,7 +878,7 @@ def read_cell_perms(
|
|
|
843
878
|
.. note::
|
|
844
879
|
No MPI communication is done during this call
|
|
845
880
|
"""
|
|
846
|
-
adios =
|
|
881
|
+
adios = create_adios(comm)
|
|
847
882
|
check_file_exists(filename)
|
|
848
883
|
|
|
849
884
|
# Open ADIOS engine
|
|
@@ -864,7 +899,7 @@ def read_hdf5_array(
|
|
|
864
899
|
group: str,
|
|
865
900
|
backend_args: dict[str, Any] | None = None,
|
|
866
901
|
) -> tuple[np.ndarray, int]:
|
|
867
|
-
adios =
|
|
902
|
+
adios = create_adios(comm)
|
|
868
903
|
"""Read an array from an HDF5 file.
|
|
869
904
|
|
|
870
905
|
Args:
|
|
@@ -908,7 +943,7 @@ def write_function(
|
|
|
908
943
|
io_name = backend_args.get("io_name", "{name}_writer")
|
|
909
944
|
prefix = mesh_prefix(backend_args)
|
|
910
945
|
|
|
911
|
-
adios =
|
|
946
|
+
adios = create_adios(comm)
|
|
912
947
|
cell_permutations_exists = False
|
|
913
948
|
dofmap_exists = False
|
|
914
949
|
XDofmap_exists = False
|
|
@@ -1001,7 +1036,7 @@ def read_format0_checkpoint(
|
|
|
1001
1036
|
The mesh, and for each function in the order of the file the arguments of its
|
|
1002
1037
|
:class:`io4dolfinx.structures.FunctionData` except the name.
|
|
1003
1038
|
"""
|
|
1004
|
-
adios =
|
|
1039
|
+
adios = create_adios(comm)
|
|
1005
1040
|
mesh: MeshData | None = None
|
|
1006
1041
|
cell_permutations = None
|
|
1007
1042
|
functions: list[dict[str, Any]] = []
|
|
@@ -1084,7 +1119,7 @@ def read_legacy_mesh(
|
|
|
1084
1119
|
- Cell type as a string (e.g. "tetrahedron") or None if not found
|
|
1085
1120
|
"""
|
|
1086
1121
|
# Create ADIOS2 reader
|
|
1087
|
-
adios =
|
|
1122
|
+
adios = create_adios(comm)
|
|
1088
1123
|
with ADIOSFile(
|
|
1089
1124
|
adios=adios,
|
|
1090
1125
|
filename=filename,
|
|
@@ -1133,7 +1168,7 @@ def snapshot_checkpoint(
|
|
|
1133
1168
|
backend_args: Arguments to backend
|
|
1134
1169
|
"""
|
|
1135
1170
|
adios_mode = convert_file_mode(mode)
|
|
1136
|
-
adios =
|
|
1171
|
+
adios = create_adios(u.function_space.mesh.comm)
|
|
1137
1172
|
backend_args = {} if backend_args is None else backend_args
|
|
1138
1173
|
io_name = backend_args.get("io_name", "SnapshotCheckPoint")
|
|
1139
1174
|
engine = backend_args.get("engine", "BP4")
|
|
@@ -4,6 +4,7 @@ Helpers reading/writing data with ADIOS2
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
+
import contextvars
|
|
7
8
|
import shutil
|
|
8
9
|
from contextlib import contextmanager
|
|
9
10
|
from pathlib import Path
|
|
@@ -19,10 +20,13 @@ import numpy.typing as npt
|
|
|
19
20
|
|
|
20
21
|
from ...utils import compute_local_range, valid_function_types
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
# ADIOS2 without MPI is supported through the adios2-serial backend
|
|
24
|
+
adios2 = fenicsx_compat.resolve_adios_scope(adios2, require_mpi=False)
|
|
23
25
|
|
|
24
26
|
|
|
25
27
|
__all__ = [
|
|
28
|
+
"force_serial_adios",
|
|
29
|
+
"create_adios",
|
|
26
30
|
"AdiosFile",
|
|
27
31
|
"ADIOSFile",
|
|
28
32
|
"check_variable_exists",
|
|
@@ -44,6 +48,26 @@ adios_to_numpy_dtype = {
|
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
|
|
51
|
+
#: Create ADIOS objects without MPI on every rank, even with ADIOS2 built with MPI. Set by the
|
|
52
|
+
#: adios2-serial backend, see :mod:`io4dolfinx.backends.serial`.
|
|
53
|
+
force_serial_adios = contextvars.ContextVar("force_serial_adios", default=False)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def create_adios(comm: MPI.Comm) -> adios2.ADIOS:
|
|
57
|
+
"""Create an ADIOS object.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
comm: The communicator of the processes opening files with it.
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
An ADIOS object on ``comm``, or one without MPI that opens files on this process
|
|
64
|
+
only, if ADIOS2 is built without MPI or :data:`force_serial_adios` is set.
|
|
65
|
+
"""
|
|
66
|
+
if adios2.is_built_with_mpi and not force_serial_adios.get():
|
|
67
|
+
return adios2.ADIOS(comm)
|
|
68
|
+
return adios2.ADIOS()
|
|
69
|
+
|
|
70
|
+
|
|
47
71
|
class AdiosFile(NamedTuple):
|
|
48
72
|
io: adios2.IO
|
|
49
73
|
file: adios2.Engine
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""The ADIOS2 backend for ADIOS2 built without MPI.
|
|
2
|
+
|
|
3
|
+
Files are read by every process on its own and written through rank 0, see
|
|
4
|
+
:mod:`io4dolfinx.backends.serial`. They are the files of the ADIOS2 backend.
|
|
5
|
+
|
|
6
|
+
SPDX License identifier: MIT
|
|
7
|
+
|
|
8
|
+
Copyright: Jørgen S. Dokken, Simula Research Laboratory
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import functools
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from mpi4py import MPI
|
|
16
|
+
|
|
17
|
+
import dolfinx
|
|
18
|
+
import numpy as np
|
|
19
|
+
|
|
20
|
+
from ...structures import FunctionData, MeshData, MeshTagsData
|
|
21
|
+
from .. import FileMode
|
|
22
|
+
from ..adios2 import backend as parallel
|
|
23
|
+
from ..adios2.helpers import ADIOSFile, create_adios, force_serial_adios
|
|
24
|
+
from ..serial import gather_function, gather_mesh, gather_meshtags, serial, write_on_root
|
|
25
|
+
|
|
26
|
+
serial_adios = functools.partial(serial, flag=force_serial_adios)
|
|
27
|
+
write_on_root_adios = functools.partial(write_on_root, flag=force_serial_adios)
|
|
28
|
+
|
|
29
|
+
read_mode = parallel.read_mode
|
|
30
|
+
get_default_backend_args = parallel.get_default_backend_args
|
|
31
|
+
convert_file_mode = parallel.convert_file_mode
|
|
32
|
+
|
|
33
|
+
read_metadata = serial_adios(parallel.read_metadata)
|
|
34
|
+
read_attributes = serial_adios(parallel.read_attributes)
|
|
35
|
+
read_timestamps = serial_adios(parallel.read_timestamps)
|
|
36
|
+
read_mesh_data = serial_adios(parallel.read_mesh_data)
|
|
37
|
+
read_meshtags_data = serial_adios(parallel.read_meshtags_data)
|
|
38
|
+
read_dofmap = serial_adios(parallel.read_dofmap)
|
|
39
|
+
read_dofs = serial_adios(parallel.read_dofs)
|
|
40
|
+
read_cell_perms = serial_adios(parallel.read_cell_perms)
|
|
41
|
+
read_hdf5_array = serial_adios(parallel.read_hdf5_array)
|
|
42
|
+
read_legacy_mesh = serial_adios(parallel.read_legacy_mesh)
|
|
43
|
+
read_function_names = parallel.read_function_names
|
|
44
|
+
read_point_data = parallel.read_point_data
|
|
45
|
+
read_cell_data = parallel.read_cell_data
|
|
46
|
+
write_data = parallel.write_data
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def write_attributes(
|
|
50
|
+
filename: Path | str,
|
|
51
|
+
comm: MPI.Comm,
|
|
52
|
+
name: str,
|
|
53
|
+
attributes: dict[str, np.ndarray],
|
|
54
|
+
backend_args: dict[str, Any] | None = None,
|
|
55
|
+
):
|
|
56
|
+
"""Write attributes to file, see :func:`io4dolfinx.backends.adios2.backend.write_attributes`."""
|
|
57
|
+
write_on_root_adios(
|
|
58
|
+
comm,
|
|
59
|
+
attributes,
|
|
60
|
+
lambda d: parallel.write_attributes(filename, MPI.COMM_SELF, name, d, backend_args),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def write_mesh(
|
|
65
|
+
filename: Path | str,
|
|
66
|
+
comm: MPI.Comm,
|
|
67
|
+
mesh: MeshData,
|
|
68
|
+
backend_args: dict[str, Any] | None = None,
|
|
69
|
+
mode: FileMode = FileMode.write,
|
|
70
|
+
time: float = 0.0,
|
|
71
|
+
):
|
|
72
|
+
"""Write a mesh to file, see :func:`io4dolfinx.backends.adios2.backend.write_mesh`."""
|
|
73
|
+
data = gather_mesh(comm, mesh)
|
|
74
|
+
write_on_root_adios(
|
|
75
|
+
comm,
|
|
76
|
+
data,
|
|
77
|
+
lambda d: parallel.write_mesh(filename, MPI.COMM_SELF, d, backend_args, mode, time),
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def write_meshtags(
|
|
82
|
+
filename: str | Path,
|
|
83
|
+
comm: MPI.Comm,
|
|
84
|
+
data: MeshTagsData,
|
|
85
|
+
backend_args: dict[str, Any] | None = None,
|
|
86
|
+
):
|
|
87
|
+
"""Write mesh tags to file, see :func:`io4dolfinx.backends.adios2.backend.write_meshtags`."""
|
|
88
|
+
tags = gather_meshtags(comm, data)
|
|
89
|
+
write_on_root_adios(
|
|
90
|
+
comm, tags, lambda d: parallel.write_meshtags(filename, MPI.COMM_SELF, d, backend_args)
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def write_function(
|
|
95
|
+
filename: Path,
|
|
96
|
+
comm: MPI.Comm,
|
|
97
|
+
u: FunctionData,
|
|
98
|
+
time: float = 0.0,
|
|
99
|
+
mode: FileMode = FileMode.append,
|
|
100
|
+
backend_args: dict[str, Any] | None = None,
|
|
101
|
+
):
|
|
102
|
+
"""Write a function to file, see :func:`io4dolfinx.backends.adios2.backend.write_function`."""
|
|
103
|
+
data = gather_function(comm, u)
|
|
104
|
+
write_on_root_adios(
|
|
105
|
+
comm,
|
|
106
|
+
data,
|
|
107
|
+
lambda d: parallel.write_function(filename, MPI.COMM_SELF, d, time, mode, backend_args),
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def snapshot_checkpoint(
|
|
112
|
+
filename: Path | str,
|
|
113
|
+
mode: FileMode,
|
|
114
|
+
u: dolfinx.fem.Function,
|
|
115
|
+
backend_args: dict[str, Any] | None,
|
|
116
|
+
):
|
|
117
|
+
"""Create or read a snapshot checkpoint, see
|
|
118
|
+
:func:`io4dolfinx.backends.adios2.backend.snapshot_checkpoint`.
|
|
119
|
+
|
|
120
|
+
Rank 0 writes the dofs of each process as a block of its own, in rank order, so that
|
|
121
|
+
each process reads its block back, as from a file of the ADIOS2 backend.
|
|
122
|
+
"""
|
|
123
|
+
if mode != FileMode.write:
|
|
124
|
+
return serial_adios(parallel.snapshot_checkpoint)(filename, mode, u, backend_args)
|
|
125
|
+
comm = u.function_space.mesh.comm
|
|
126
|
+
dofmap = u.function_space.dofmap
|
|
127
|
+
num_dofs_local = dofmap.index_map.size_local * dofmap.index_map_bs
|
|
128
|
+
blocks = comm.gather(u.x.array[:num_dofs_local].copy(), root=0)
|
|
129
|
+
backend_args = {} if backend_args is None else backend_args
|
|
130
|
+
|
|
131
|
+
def write(blocks: list[np.ndarray]):
|
|
132
|
+
with ADIOSFile(
|
|
133
|
+
adios=create_adios(MPI.COMM_SELF),
|
|
134
|
+
filename=filename,
|
|
135
|
+
mode=convert_file_mode(FileMode.write),
|
|
136
|
+
io_name=backend_args.get("io_name", "SnapshotCheckPoint"),
|
|
137
|
+
engine=backend_args.get("engine", "BP4"),
|
|
138
|
+
) as adios_file:
|
|
139
|
+
adios_file.file.BeginStep()
|
|
140
|
+
dofs = adios_file.io.DefineVariable("dofs", blocks[0], count=[len(blocks[0])])
|
|
141
|
+
for block in blocks:
|
|
142
|
+
dofs.SetSelection([[], [len(block)]])
|
|
143
|
+
adios_file.file.Put(dofs, block, parallel.adios2.Mode.Sync)
|
|
144
|
+
adios_file.file.EndStep()
|
|
145
|
+
|
|
146
|
+
write_on_root_adios(comm, blocks, write)
|