I’m doing a post-processing work which outputs the node values of a 2D P2 element using VTK. Since Freefem++ currently doesn’t support outputing the P2 elements (VTK order = 2) directly, one possible way is to first refine the mesh (truncated with split = 2), then output the refined mesh with P1 elements (VTK order = 1).
The mesh refinement is easy to implement. Assuming we have an original 2D mesh called Th, and a refined mesh ThR is established by using the command:
mesh ThR = Th;
ThR = trunc(ThR, true, split=2);
But, it is a bit difficult to establish the node numbering mapping between the original Th with P2 elements and the refined ThR with P1 elements.
The node numbering for the original P2 elements can be accessed as follows:
mesh Th = square(2, 2);
fespace Wh(Th, P2);
for (int k = 0; k < Th.nt; k++) {
for (int i = 0; i < 6; i++) {
cout << Wh(k, i) << " ";
}
cout << endl;
}
However, the node numbering rule for the refined mesh ThR with P1 elements is not very clear. The node numbering for the common nodes of Th & ThR are the same, but the rule for the newly added nodes is not clear.
Here is an example.
Fig. 1 gives the P1 node numbering of the mesh Th.
Fig. 2 gives the P1 node numbering of the refined mesh ThR.
Fig. 3 gives the P2 node numbering of the mesh Th.
Of course, we can find the mapping relation by comparing each nodes’ coordinates, and determine whether they’re the same one by Euclidean distance like
sqrt((xi - xj)^2 + (yi - yj)^2 + (zi - zj)^2) < epsilon
Is there any more efficient way to address this problem, since the above method maybe time cost expensive when there are millions of nodes?


