I am trying to identify elements before and after refinement with each other. However, mesh.GetParentElement is returning strange results (both using mesh.Refine() and mesh.RefineUniform()) Running the following MWE
from ngsolve import *
mesh = Mesh(unit_square.GenerateMesh(maxh=2))
mesh.Refine() # mesh.RefineUniform()
for i in range(mesh.ne):
print(i, mesh.GetParentElement(ElementId(VOL, i)).nr)
As the original mesh only has two volume elements, I was expecting only 1 and 0 as outputs. Uniform refinements leads to the parent ElementId Nr 18446744073709551615 for all elements. Same results on latest master branch on linux and v6.2.2608 on mac. Is this a bug or have I misunderstood the usage?
Thank you for the quick reply! However, I still don’t quite understand the output: Even when I call mesh.Refine() once, I get 8 elements from the two (checked in the gui) and parent numbers 2 and 3.
for that I have to explain how we encode the element hierarchy:
The mesh is an array of the current elements. All elements in the whole hierarchy are about twice as many, they are not stored.
Every element stores one parent element. That’s enough for the whole hierarchy.
If an element is split into two elements, say left and right one. The left takes the number of the parent, the right one is appended at the end of the array. The right one stores the parent number, the left one keeps the parent of the parent.
From this storage we cannot do grid transfer operators on the individual elements, but we can do it efficiently for the whole mesh: When we prolongate the value from parent to the right child, we also prolongate to the left child (and overwrite the parent value).
Hope this explains the numbers you see.
The mesh.Refine() calls the bisection twice, and the number of elements increases by a factor for 4 in 2D (when all elements are marked). To get only one bisection step, call it with: