Skip to content

Commit 925bcc5

Browse files
jorgensdfinsberg
andauthored
VTKHDF backend for reading and writing point data (#199)
* Start working on a mesh-writer that depends on time * Fix write (time-dependent) geometry to file * Fix vtkhdf in topology permutation * After hours of Gemini prompting, it turns out I need to read the VTKHDF docs more carefully, should just have turned on track_groups. Only thing Gemini in the end did for me. * Add recursive search through groups * Fix all vtkhdf tests * Further work, writing meshtags * Add reading multiple meshes * Add write/read meshtags * Add geometry dofmap constructor that is bulletproof * Create vtk-hdf backend that can write point data * Add read/write capabilities of point/cell-data * Add test of mixed data types * Clean up paths. * Finsberg/vtkhdf write mesh (#200) * Add pyvista and xdmf deps to test dependencies * Use tmp_path * Apply suggestions from code review Documentation fixes and some logic simplification Co-authored-by: Henrik Finsberg <henrikfinsberg@hotmail.com> * Refactor vtkhdf backend (#203) * Refactor code for getting UnstructuredGrid * Refactor time index * No more walrus * Refactor single partition data * Less indendation * Simplifications and type hinting * Documentation and some simplifications * Remove stray comment --------- Co-authored-by: Jørgen S. Dokken <dokken@simula.no> --------- Co-authored-by: Henrik Finsberg <henrikfinsberg@hotmail.com>
1 parent 97c8854 commit 925bcc5

17 files changed

Lines changed: 1444 additions & 126 deletions

.github/workflows/test_package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
- name: Install package
8383
run: |
8484
HDF5_MPI=ON HDF5_PKGCONFIG_NAME="hdf5" python3 -m pip install h5py --no-build-isolation --no-binary=h5py
85-
python3 -m pip install .[test,xdmf,pyvista]
85+
python3 -m pip install .[test]
8686
8787
- name: Run tests
8888
run: |

.github/workflows/test_package_openmpi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
- name: Install package
7979
run: |
8080
HDF5_MPI=ON HDF5_PKGCONFIG_NAME="hdf5" python3 -m pip install h5py --no-build-isolation --no-binary=h5py
81-
python3 -m pip install .[test,xdmf,pyvista]
81+
python3 -m pip install .[test]
8282
- name: Run tests
8383
run: |
8484
coverage run --rcfile=.coveragerc -m mpi4py -m pytest -xvs ./tests/

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ readme = "README.md"
1111
dependencies = ["fenics-dolfinx>=0.10.0", "packaging"]
1212

1313
[project.optional-dependencies]
14-
test = ["pytest", "coverage", "ipyparallel", "adios4dolfinx[h5py]"]
14+
test = [
15+
"pytest",
16+
"coverage",
17+
"ipyparallel",
18+
"adios4dolfinx[h5py]",
19+
"adios4dolfinx[pyvista]",
20+
"adios4dolfinx[xdmf]"
21+
]
1522
dev = ["pdbpp", "ipython", "mypy", "ruff"]
1623
h5py = ["h5py"]
1724
pyvista = ["pyvista"]

src/adios4dolfinx/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
read_meshtags,
1818
read_timestamps,
1919
write_attributes,
20+
write_cell_data,
2021
write_function,
2122
write_mesh,
2223
write_meshtags,
24+
write_point_data,
2325
)
2426
from .original_checkpoint import write_function_on_input_mesh, write_mesh_input_order
2527
from .readers import (
@@ -52,9 +54,12 @@
5254
"write_function_on_input_mesh",
5355
"write_mesh_input_order",
5456
"write_attributes",
57+
"write_data",
5558
"read_attributes",
5659
"read_function_names",
5760
"read_point_data",
5861
"read_timestamps",
5962
"get_backend",
63+
"write_cell_data",
64+
"write_point_data",
6065
]

src/adios4dolfinx/backends/__init__.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
import numpy.typing as npt
1111

12-
from ..structures import FunctionData, MeshData, MeshTagsData, ReadMeshData
12+
from ..structures import ArrayData, FunctionData, MeshData, MeshTagsData, ReadMeshData
1313

1414
__all__ = ["FileMode", "IOBackend", "get_backend"]
1515

@@ -381,6 +381,28 @@ def read_cell_data(
381381
"""
382382
...
383383

384+
def write_data(
385+
self,
386+
filename: Path | str,
387+
array_data: ArrayData,
388+
comm: MPI.Intracomm,
389+
time: str | float | None,
390+
mode: FileMode,
391+
backend_args: dict[str, Any] | None,
392+
):
393+
"""Write a 2D-array to file.
394+
395+
396+
Args:
397+
filename: Path to file
398+
array_data: Data to write to file.
399+
comm: The MPI communicator to open the writer with.
400+
time: The time stamp
401+
mode: Append or write
402+
backend_args: The backend arguments
403+
"""
404+
...
405+
384406

385407
def get_backend(backend: str) -> IOBackend:
386408
"""Get backend class from backend name.

src/adios4dolfinx/backends/adios2/backend.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
import numpy.typing as npt
1111

12-
from ...structures import FunctionData, MeshData, MeshTagsData, ReadMeshData
12+
from ...structures import ArrayData, FunctionData, MeshData, MeshTagsData, ReadMeshData
1313
from ...utils import check_file_exists, compute_local_range
1414
from .. import FileMode, ReadMode
1515
from .helpers import (
@@ -971,3 +971,25 @@ def read_cell_data(
971971
freedom within that cell.
972972
"""
973973
raise NotImplementedError("The ADIOS2 backend does not support reading cell data.")
974+
975+
976+
def write_data(
977+
filename: Path | str,
978+
array_data: ArrayData,
979+
comm: MPI.Intracomm,
980+
time: str | float | None,
981+
mode: FileMode,
982+
backend_args: dict[str, Any] | None,
983+
):
984+
"""Write a 2D-array to file (distributed across proceses with MPI).
985+
986+
987+
Args:
988+
filename: Path to file
989+
array_data: Data to write to file
990+
comm: MPI communicator to open the file with.
991+
time: Time stamp
992+
mode: Append or write
993+
backend_args: The backend arguments
994+
"""
995+
raise NotImplementedError("ADIOS2 has not implemented this yet")

src/adios4dolfinx/backends/h5py/backend.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import numpy.typing as npt
1818
from dolfinx.graph import adjacencylist
1919

20-
from ...structures import FunctionData, MeshData, MeshTagsData, ReadMeshData
20+
from ...structures import ArrayData, FunctionData, MeshData, MeshTagsData, ReadMeshData
2121
from ...utils import check_file_exists, compute_local_range
2222
from .. import FileMode, ReadMode
2323

@@ -199,7 +199,9 @@ def write_mesh(
199199
# Write geometry data
200200
gdim = mesh.local_geometry.shape[1]
201201
geometry_dataset = geometry_group.create_dataset(
202-
"Points", [mesh.num_nodes_global, gdim], dtype=mesh.local_geometry.dtype
202+
"Points",
203+
[mesh.num_nodes_global, gdim],
204+
dtype=mesh.local_geometry.dtype,
203205
)
204206
geometry_dataset[slice(*mesh.local_geometry_pos), :] = mesh.local_geometry
205207

@@ -796,3 +798,24 @@ def read_cell_data(
796798
freedom within that cell.
797799
"""
798800
raise NotImplementedError("The h5py backend does not support reading cell data.")
801+
802+
803+
def write_data(
804+
filename: Path | str,
805+
array_data: ArrayData,
806+
comm: MPI.Intracomm,
807+
time: str | float | None,
808+
mode: FileMode,
809+
backend_args: dict[str, Any] | None,
810+
):
811+
"""Write a 2D-array to file (distributed across proceses with MPI).
812+
813+
Args:
814+
filename: Path to file
815+
array_data: Data to write to file
816+
comm: MPI communicator to open the file with
817+
time: Time-stamp for data.
818+
mode: Append or write
819+
backend_args: The backend arguments
820+
"""
821+
raise NotImplementedError("H5PY has not implemented this yet")

src/adios4dolfinx/backends/pyvista/backend.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
import basix
1919
import dolfinx
2020

21-
from adios4dolfinx.structures import FunctionData, MeshData, MeshTagsData, ReadMeshData
21+
from adios4dolfinx.structures import ArrayData, FunctionData, MeshData, MeshTagsData, ReadMeshData
2222
from adios4dolfinx.utils import check_file_exists
2323

2424
from .. import FileMode, ReadMode
2525

2626
# Cell types can be found at
2727
# https://vtk.org/doc/nightly/html/vtkCellType_8h_source.html
2828
_first_order_vtk = {
29+
1: "point",
2930
3: "interval",
3031
5: "triangle",
3132
9: "quadrilateral",
@@ -564,3 +565,24 @@ def read_hdf5_array(
564565
Process 0 has [0, M), process 1 [M, N), process 2 [N, O) etc.
565566
"""
566567
raise NotImplementedError("The Pyvista backend cannot read HDF5 arrays")
568+
569+
570+
def write_data(
571+
filename: Path | str,
572+
array_data: ArrayData,
573+
comm: MPI.Intracomm,
574+
time: str | float | None,
575+
mode: FileMode,
576+
backend_args: dict[str, Any] | None,
577+
):
578+
"""Write a 2D-array to file (distributed across proceses with MPI).
579+
580+
Args:
581+
filename: Path to file
582+
array_data: Data to write to file
583+
comm: MPI communicator to open the file with
584+
time: Time stamp
585+
mode: Append or write
586+
backend_args: The backend arguments
587+
"""
588+
raise NotImplementedError("The pyvista backend does not support writing point data")

0 commit comments

Comments
 (0)