Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow partitioner to be passed to model_to_mesh #2394

Merged
merged 9 commits into from
Oct 11, 2022
11 changes: 7 additions & 4 deletions python/dolfinx/io/gmshio.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ def extract_geometry(model: gmsh.model, name: str = None) -> npt.NDArray[np.floa
assert np.all(indices[perm_sort] == np.arange(len(indices)))
return points[perm_sort]

def model_to_mesh(model: gmsh.model, comm: _MPI.Comm, rank: int,
gdim: int = 3) -> typing.Tuple[Mesh, _cpp.mesh.MeshTags_int32, _cpp.mesh.MeshTags_int32]:
def model_to_mesh(
model: gmsh.model, comm: _MPI.Comm, rank: int,
gdim: int = 3,
partitioner=create_cell_partitioner(GhostMode.none)) -> typing.Tuple[
jpdean marked this conversation as resolved.
Show resolved Hide resolved
Mesh, _cpp.mesh.MeshTags_int32, _cpp.mesh.MeshTags_int32]:
"""
Given a Gmsh model, take all physical entities of the highest
topological dimension and create the corresponding DOLFINx mesh.
Expand All @@ -178,6 +181,7 @@ def model_to_mesh(model: gmsh.model, comm: _MPI.Comm, rank: int,
rank: The rank the Gmsh model is initialized on
model: The Gmsh model
gdim: Geometrical dimension of the mesh
partitioner: Function that computes the parallel distribution of cells across MPI ranks

Returns:
A triplet (mesh, cell_tags, facet_tags) where cell_tags hold
Expand Down Expand Up @@ -241,8 +245,7 @@ def model_to_mesh(model: gmsh.model, comm: _MPI.Comm, rank: int,
ufl_domain = ufl_mesh(cell_id, gdim)
gmsh_cell_perm = cell_perm_array(_cpp.mesh.to_type(str(ufl_domain.ufl_cell())), num_nodes)
cells = cells[:, gmsh_cell_perm]
part = create_cell_partitioner(GhostMode.none)
mesh = create_mesh(comm, cells, x[:, :gdim], ufl_domain, part)
mesh = create_mesh(comm, cells, x[:, :gdim], ufl_domain, partitioner)

# Create MeshTags for cells
local_entities, local_values = _cpp.io.distribute_entity_data(mesh, mesh.topology.dim, cells, cell_values)
Expand Down