Inconsistency between ALU and UG grids constructed with dgf files with wrongly ordered nodes
I use the dune modules in their releases 2.6 versions.
I am creating grids from dgf files as input.
When using ALUGrid, everything works fine. In the case that the nodes are wrongly ordered, they are reordered and the unitOuterNormal() of the intersections is correct.
When using UGGrid, everything works fine if the ordering of the nodes corresponds to the standard Dune reference element node ordering (as depicted on the cheat sheet). However, if the ordering is wrong, UGGrid does not seem to reorder nodes, leading to incorrect normal vectors (wrong sign), which leads to unexpected behavior in my program.
Here is an example, where - compared to the Dune reference node ordering - the plane 0-1-2-3 and the plane 4-5-6-7 are exchanged:
test_cubeordering.dgf:
DGF
Vertex
0.0 0.0 1.0
1.0 0.0 1.0
0.0 1.0 1.0
1.0 1.0 1.0
0.0 0.0 0.0
1.0 0.0 0.0
0.0 1.0 0.0
1.0 1.0 0.0
#
Cube
0 1 2 3 4 5 6 7
#
I then create a UGGrid from this file and write out element corners and intersection normals using
Dune::GridPtr<Dune::UGGrid<3>> gridptr("test_cubeordering.dgf");
auto gv = gridptr->leafGridView();
for (const auto& cell : elements(gv)){
auto geo = cell.geometry();
for(int i=0 ; i<geo.corners(); i++){
auto corner = geo.corner(i);
std::cout << "element corner " << i << ": " << corner << std::endl;
}
for (const auto& is : intersections(gv ,cell)) {
std::cout << "loop over intersections: " << std::endl;
auto geo_is = is.geometry();
for(int i=0 ; i<geo_is.corners(); i++){
auto corner = geo_is.corner(i);
std::cout << "intersection corner " << i << ": " << corner << std::endl;
}
const auto& ref = Dune::ReferenceElements<double, 2>::general(geo_is.type());
auto normal = is.unitOuterNormal(ref.position(0, 0));
std::cout << "unit outer normal: " << normal << std::endl;
}
}
I get the output:
element corner 0: 0 0 1
element corner 1: 1 0 1
element corner 2: 0 1 1
element corner 3: 1 1 1
element corner 4: 0 0 0
element corner 5: 1 0 0
element corner 6: 0 1 0
element corner 7: 1 1 0
loop over intersections:
intersection corner 0: 0 0 1
intersection corner 1: 0 1 1
intersection corner 2: 1 0 1
intersection corner 3: 1 1 1
unit outer normal: 0 0 -1
...
...
The corners are unchanged and the normals have the wrong sign, like shown here for the first intersection.
Using ALUGrid instead, the element nodes are reordered corresponding to the Dune ordering:
element corner 0: 0 0 1
element corner 1: 0 1 1
element corner 2: 1 0 1
element corner 3: 1 1 1
element corner 4: 0 0 0
element corner 5: 0 1 0
element corner 6: 1 0 0
element corner 7: 1 1 0
and also the normals have the correct sign.
I am wondering how this inconsistency could be best solved. Maybe there should be at least an error when reading incorrect nodes?