Partitioning mesh in dolfinx where one imports external mesh prepared by gmsh

I am looking to partition my mesh that I read from file. I am importing mesh prepared using gmsh and the mesh contains entities and the other containing the boundary facets. I can also convert the mesh to XDMF and read it into dolfinx. There’s an example using a custom partitioner at dolfinx/python/test/unit/mesh/test_mesh_partitioners.py at main · FEniCS/dolfinx · GitHub but I am unclear how to handle the boundary facets that I import. I also want the flexibility to replace the custom partitioner with my choice of partitioner e.g. Kahip, Parmetis, PTSCOTCH, among the partitioner options available in dolfinx.

Below is the code that I use to import the XDMF file.

tria_meshfile = "triangles.xdmf"
line_meshfile = "lines.xdmf"
comm = MPI.COMM_WORLD
with io.XDMFFile(comm, tria_meshfile, "r") as infile3:
    domain = infile3.read_mesh(cpp.mesh.GhostMode.none, 'Grid')
    ct = infile3.read_meshtags(domain, name="Grid")
tdim = domain.topology.dim
fdim = tdim - 1
domain.topology.create_connectivity(tdim, fdim)

ft_imap = domain.topology.index_map(fdim)
num_facets = ft_imap.size_local + ft_imap.num_ghosts
indices = np.arange(0, num_facets)
values = np.zeros(indices.shape, dtype=np.intc)  # all facets are tagged with zero

with io.XDMFFile(comm, line_meshfile, "r") as infile2:
    ft = infile2.read_meshtags(domain, name="Grid")

values[ft.indices] = ft.values
meshtags = mesh.meshtags(domain, fdim, indices, values)
domaintags = mesh.meshtags(domain, domain.topology.dim, ct.indices, ct.values)

I can make the call:

from dolfinx import mesh
from dolfinx.graph import partitioner_parmetis
from dolfinx.io import gmshio
from mpi4py import MPI

comm = MPI.COMM_WORLD
partitioner = mesh.create_cell_partitioner(mesh.GhostMode.shared_facet)
domain, ct, ft = gmshio.read_from_msh("mesh.msh", comm, partitioner=partitioner)

but I’m unclear how to select a type of partitioner and pass it e.g. in

partitioner = mesh.create_cell_partitioner(mesh.GhostMode.shared_facet, part=partitioner_parmetis)

Boundary facets are not used in the partitioning, and should be possible to read in as long as they are associated with the original mesh.

I’ve covered this at Mesh creation in serial and parallel — FEniCSx Documentation

For purely custom partitioning (with ghosting), you can see for instance: presentations/fenicsx_at_simula/mesh_creation_prepartitioned.py at main · jorgensd/presentations · GitHub

1 Like