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)