Skip to content

Commit f684261

Browse files
authored
Merge pull request #11 from scientificcomputing/finsberg/max_facet_to_cell_links
API change due to FEniCS/dolfinx#4082
2 parents c9ae6d9 + 11dd03c commit f684261

2 files changed

Lines changed: 31 additions & 3 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

0 commit comments

Comments
 (0)