JanvdW
June 11, 2026, 1:33pm
1
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.
dokken
June 11, 2026, 1:43pm
2
The parent_cells and parent_facets has a slightly different meaning than you think, see:
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…
and
opened 12:47PM - 06 Jul 24 UTC
closed 01:51PM - 06 Jul 24 UTC
### Summarize the issue
Reported at: https://fenicsproject.discourse.group/t… /mesh-refinement-using-dolfinx-mesh-refine-plaza/15168/4
### How to reproduce the bug
Run the following
### Minimal Example (Python)
```Python
from mpi4py import MPI
import numpy as np
import dolfinx
msh_c = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 2, 2)
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)
for i, (child_vertex, parent_vertex) in enumerate(zip(child_vertices, parent_vertices)):
print(f"Child {i} has parent {parent_cells[i]}")
child_vertex_coords = msh_f.geometry.x[child_vertex]
print(f"Child {i} has vertices {child_vertex} at {child_vertex_coords}")
parent_vertex_coords = msh_c.geometry.x[parent_vertex]
print(f"Parent {parent_cells[i]} has vertices {parent_vertex} at {parent_vertex_coords}")
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(msh_f, msh_f.topology.dim, np.arange(len(parent_cells), dtype=np.int32), 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)
```
### Output (Python)
_No response_
### Version
main branch
### DOLFINx git commit
_No response_
### Installation
_No response_
### Additional information

JanvdW
June 11, 2026, 2:14pm
3
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?
dokken
June 11, 2026, 2:22pm
4
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.