Skip to content

Commit bdb15e6

Browse files
committed
Merge remote-tracking branch 'origin/main' into finsberg/deploy-pages
2 parents 85de7e7 + 92415d8 commit bdb15e6

4 files changed

Lines changed: 45 additions & 28 deletions

File tree

src/io4dolfinx/checkpointing.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from __future__ import annotations
88

9+
import inspect
910
import typing
1011
from pathlib import Path
1112
from typing import Any
@@ -383,6 +384,7 @@ def read_mesh(
383384
read_from_partition: bool = False,
384385
backend_args: dict[str, Any] | None = None,
385386
backend: str = "adios2",
387+
max_facet_to_cell_links: int = 2,
386388
) -> dolfinx.mesh.Mesh:
387389
"""
388390
Read an ADIOS2 mesh into DOLFINx.
@@ -395,6 +397,8 @@ def read_mesh(
395397
time: Time stamp associated with mesh
396398
read_from_partition: Read mesh with partition from file
397399
backend_args: List of arguments to reader backend
400+
max_facet_to_cell_links: Maximum number of cells a facet
401+
can be connected to.
398402
Returns:
399403
The distributed mesh
400404
"""
@@ -432,9 +436,18 @@ def partitioner(comm: MPI.Intracomm, n, m, topo):
432436
else:
433437
return partition_graph
434438
else:
435-
partitioner = dolfinx.cpp.mesh.create_cell_partitioner(ghost_mode)
439+
sig = inspect.signature(dolfinx.mesh.create_cell_partitioner)
440+
part_kwargs = {}
441+
if "max_facet_to_cell_links" in list(sig.parameters.keys()):
442+
part_kwargs["max_facet_to_cell_links"] = max_facet_to_cell_links
443+
partitioner = dolfinx.cpp.mesh.create_cell_partitioner(ghost_mode, **part_kwargs)
444+
436445
return dolfinx.mesh.create_mesh(
437-
comm, cells=dist_in_data.cells, x=dist_in_data.x, e=domain, partitioner=partitioner
446+
comm,
447+
cells=dist_in_data.cells,
448+
x=dist_in_data.x,
449+
e=domain,
450+
partitioner=partitioner,
438451
)
439452

440453

src/io4dolfinx/readers.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from __future__ import annotations
88

9+
import inspect
910
import pathlib
1011
import typing
1112
from pathlib import Path
@@ -149,6 +150,7 @@ def read_mesh_from_legacy_h5(
149150
group: str,
150151
cell_type: str = "tetrahedron",
151152
backend: str = "adios2",
153+
max_facet_to_cell_links: int = 2,
152154
) -> dolfinx.mesh.Mesh:
153155
"""
154156
Read mesh from `h5`-file generated by legacy DOLFIN `HDF5File.write` or `XDMF.write_checkpoint`.
@@ -158,6 +160,10 @@ def read_mesh_from_legacy_h5(
158160
filename: Path to `h5` or `xdmf` file
159161
group: Name of mesh in `h5`-file
160162
cell_type: What type of cell type, by default tetrahedron.
163+
backend: The IO backend to use when reading the mesh (must
164+
support legacy mesh reading, e.g., "adios2").
165+
max_facet_to_cell_links: Maximum number of cells a facet
166+
can be connected to.
161167
"""
162168
# Make sure we use the HDF5File and check that the file is present
163169
check_file_exists(filename)
@@ -175,9 +181,18 @@ def read_mesh_from_legacy_h5(
175181
shape=(mesh_geometry.shape[1],),
176182
)
177183
domain = ufl.Mesh(element)
184+
sig = inspect.signature(dolfinx.mesh.create_mesh)
185+
kwargs: dict[str, int] = {}
186+
if "max_facet_to_cell_links" in list(sig.parameters.keys()):
187+
kwargs["max_facet_to_cell_links"] = max_facet_to_cell_links
178188

179189
return dolfinx.mesh.create_mesh(
180-
comm=MPI.COMM_WORLD, cells=mesh_topology, x=mesh_geometry, e=domain
190+
comm=MPI.COMM_WORLD,
191+
cells=mesh_topology,
192+
x=mesh_geometry,
193+
e=domain,
194+
partitioner=None,
195+
**kwargs,
181196
)
182197

183198

tests/conftest.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import sys
21
import typing
32
from collections import ChainMap
4-
from unittest.mock import patch
53

64
from mpi4py import MPI
75

@@ -36,15 +34,7 @@ def find_backends():
3634

3735
@pytest.fixture(params=find_backends(), scope="function")
3836
def backend(request):
39-
value = request.param
40-
if value == "adios2":
41-
# Mock h5py to test adios2 only
42-
with patch.dict(sys.modules, {"h5py": None}):
43-
yield value
44-
else:
45-
# Mock adios2 to test h5py only
46-
with patch.dict(sys.modules, {"adios2": None}):
47-
yield value
37+
yield request.param
4838

4939

5040
@pytest.fixture(scope="module")

tests/test_mesh_writer.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,28 @@ def test_mesh_read_writer(backend, encoder, suffix, ghost_mode, tmp_path, store_
8989
backend_args = None
9090
if backend == "adios2":
9191
backend_args = {"engine": encoder}
92-
9392
write_mesh(
9493
file.with_suffix(suffix),
9594
mesh,
9695
store_partition_info=store_partition,
9796
backend_args=backend_args,
9897
backend=backend,
9998
)
99+
100100
mesh.comm.Barrier()
101101
with dolfinx.io.XDMFFile(mesh.comm, xdmf_file.with_suffix(".xdmf"), "w") as xdmf:
102102
xdmf.write_mesh(mesh)
103103
mesh.comm.Barrier()
104104

105-
mesh_adios = read_mesh(
105+
in_mesh = read_mesh(
106106
file.with_suffix(suffix),
107107
MPI.COMM_WORLD,
108108
ghost_mode=ghost_mode,
109109
read_from_partition=store_partition,
110110
backend_args=backend_args,
111111
backend=backend,
112112
)
113-
mesh_adios.comm.Barrier()
113+
in_mesh.comm.Barrier()
114114
if store_partition:
115115

116116
def compute_distance_matrix(points_A, points_B, tol=1e-12):
@@ -120,7 +120,7 @@ def compute_distance_matrix(points_A, points_B, tol=1e-12):
120120
return distances < tol
121121

122122
cell_map = mesh.topology.index_map(mesh.topology.dim)
123-
new_cell_map = mesh_adios.topology.index_map(mesh_adios.topology.dim)
123+
new_cell_map = in_mesh.topology.index_map(in_mesh.topology.dim)
124124
assert cell_map.size_local == new_cell_map.size_local
125125
assert cell_map.num_ghosts == new_cell_map.num_ghosts
126126
mesh.topology.create_connectivity(mesh.topology.dim, mesh.topology.dim)
@@ -129,10 +129,10 @@ def compute_distance_matrix(points_A, points_B, tol=1e-12):
129129
mesh.topology.dim,
130130
np.arange(cell_map.size_local + cell_map.num_ghosts, dtype=np.int32),
131131
)
132-
mesh_adios.topology.create_connectivity(mesh_adios.topology.dim, mesh_adios.topology.dim)
132+
in_mesh.topology.create_connectivity(in_mesh.topology.dim, in_mesh.topology.dim)
133133
new_midpoints = dolfinx.mesh.compute_midpoints(
134-
mesh_adios,
135-
mesh_adios.topology.dim,
134+
in_mesh,
135+
in_mesh.topology.dim,
136136
np.arange(new_cell_map.size_local + new_cell_map.num_ghosts, dtype=np.int32),
137137
)
138138
# Check that all points in owned by initial mesh is owned by the new mesh
@@ -156,27 +156,26 @@ def compute_distance_matrix(points_A, points_B, tol=1e-12):
156156
for i in range(mesh.topology.dim + 1):
157157
mesh.topology.create_entities(i)
158158
mesh_xdmf.topology.create_entities(i)
159-
mesh_adios.topology.create_entities(i)
159+
in_mesh.topology.create_entities(i)
160160
assert (
161-
mesh_xdmf.topology.index_map(i).size_global
162-
== mesh_adios.topology.index_map(i).size_global
161+
mesh_xdmf.topology.index_map(i).size_global == in_mesh.topology.index_map(i).size_global
163162
)
164163

165164
# Check that integration over different entities are consistent
166165
measures = (
167166
[ufl.ds, ufl.dx] if ghost_mode is dolfinx.mesh.GhostMode.none else [ufl.ds, ufl.dS, ufl.dx]
168167
)
169168
for measure in measures:
170-
print(mesh_adios, mesh_adios.ufl_domain().ufl_coordinate_element())
171-
c_adios = dolfinx.fem.assemble_scalar(dolfinx.fem.form(1 * measure(domain=mesh_adios)))
169+
form = dolfinx.fem.form(1 * measure(domain=in_mesh))
170+
c_adios = dolfinx.fem.assemble_scalar(form)
172171
c_ref = dolfinx.fem.assemble_scalar(dolfinx.fem.form(1 * measure(domain=mesh)))
173172
c_xdmf = dolfinx.fem.assemble_scalar(dolfinx.fem.form(1 * measure(domain=mesh_xdmf)))
174173
assert np.isclose(
175-
mesh_adios.comm.allreduce(c_adios, MPI.SUM),
174+
in_mesh.comm.allreduce(c_adios, MPI.SUM),
176175
mesh.comm.allreduce(c_xdmf, MPI.SUM),
177176
)
178177
assert np.isclose(
179-
mesh_adios.comm.allreduce(c_adios, MPI.SUM),
178+
in_mesh.comm.allreduce(c_adios, MPI.SUM),
180179
mesh.comm.allreduce(c_ref, MPI.SUM),
181180
)
182181

0 commit comments

Comments
 (0)