Possible Bug in mesh refinement

Hi,

I am new to the Fenics project and dolfinx. So forgive me, if I misunderstand something.
When experimenting with dolfinx for mesh refinement, I stumbled on some behavior I cannot explain to my self.
Here is my code:

xdmf = XDMFFile(comm, "unit_square.xdmf", "r")
mesh = xdmf.read_mesh(name="Grid")
mesh.topology.create_entities(0)
mesh.topology.create_entities(1)
mesh.topology.create_entities(2)

refined_mesh, parent_cells, parent_facets = dfx.mesh.refine(mesh, option=dolfinx.mesh.RefinementOption.parent_cell_and_facet)

vertex_map_coarse = mesh.topology.connectivity(2, 0)
vertex_map_fine = refined_mesh.topology.connectivity(2, 0)

fine_points = refined_mesh.geometry.x
coarse_points = mesh.geometry.x

fine_idx = 0
coarse_idx = parent_cells[fine_idx]

corase_verts = vertex_map_coarse.links(coarse_idx)
fine_verts = vertex_map_fine.links(fine_idx)

print(coarse_points[corase_verts])
print()
print(fine_points[fine_verts])

The result is the following output:

[[0.        0.        0.       ]
 [0.25      0.        0.       ]
 [0.1830127 0.1830127 0.       ]]

[[0.90849365 0.78349365 0.        ]
 [1.         0.875      0.        ]
 [1.         0.75       0.        ]]

As we can clearly see, the coordinates of the two outputs have nothing to do with each other even though I would expect them to share one vertex. Please educate me, if I have a fundamental misunderstanding of the objects in this code.

The parent_cells and parent_facets has a slightly different meaning than you think, see:

and

Thank you very much for the very swift reply! Is there a good resource explaining the meaning of the array parent_cells and the functionality of the function transfer_meshtags?

I think the expert on this is @Chris_Richardson.
I at some point understood this, but frankly I’ve forgotten how this works.
To me it seems like it is “The mesh partitioner does not take into account that cells are re-ordered in the mesh creation step.”, at least that is what I believed back in 2024.