Mesh refinement using dolfinx.mesh.refine_plaza()

Turns out you can get the mapping with the following:

from mpi4py import MPI
import numpy as np
import dolfinx

msh_c = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 2, 5, ghost_mode=dolfinx.mesh.GhostMode.none)
msh_c.topology.create_entities(1)
msh_f, parent_cells, _ = dolfinx.mesh.refine_plaza(msh_c, redistribute=False, option=dolfinx.mesh.RefinementOption.parent_cell)

child_vertices = dolfinx.mesh.entities_to_geometry(msh_f, 2, np.arange(len(parent_cells), dtype=np.int32))
parent_vertices = dolfinx.mesh.entities_to_geometry(msh_c, 2, parent_cells)

num_cells = msh_c.topology.index_map(msh_c.topology.dim).size_local
marker = np.arange(num_cells, dtype=np.int32)
ct = dolfinx.mesh.meshtags(msh_c, msh_c.topology.dim, marker, marker)


ct_refined = dolfinx.mesh.MeshTags(dolfinx.cpp.refinement.transfer_cell_meshtag(ct._cpp_object, msh_f.topology, parent_cells))




with dolfinx.io.XDMFFile(msh_c.comm, "ct.xdmf", "w") as xdmf:
    xdmf.write_mesh(msh_c)
    xdmf.write_meshtags(ct, msh_c.geometry)


with dolfinx.io.XDMFFile(msh_f.comm, "ct_refined.xdmf", "w") as xdmf:
    xdmf.write_mesh(msh_f)
    xdmf.write_meshtags(ct_refined, msh_f.geometry)

where ct_refined.values is the map between cells in the refined mesh and cells in the original mesh.