Add missing renumbering in UGGridEntity specialization
The corners have to be renumbered for the multilineargeometry.
Merge request reports
Activity
I added a simple test demonstrating the problem. The test checks the corners of the face ({0,0,0},{0.25,0,0},{0,0.25,0},{0.25.0.25,0}) of the first hexahedron (see hybridtestgrids.hh, line 295) by checking all cube subEntities. Without this patch, the ordering is ({0,0,0},{0,0.25,0},{0.25,0.25,0},{0.25,0,0}) which gives a nonlinear mapping from the reference element. With this patch, the ordering is ({0,0,0},{0,0.25,0},{0.25,0,0},{0.25.0.25,0}), which is still not exactly what I was expecting (but maybe it is ok for subEntities to have a different ordering than the father entity?) but at least gives a linear mapping.
The local-to-global mapping from the reference element to the actual element. The cube reference element in Dune here has the corners (number: local coordinate)
0: (0,0)
1: (1,0)
2: (0,1)
3: (1,1)
The face element in the test has the coordinates
0: (0,0,0)
1: (0,0.25,0)
2: (0.25,0,0)
3: (0.25,0.25,0)
So the local-to-global mapping is
(x,y) --> (0.25y, 0.25x, 0)
Without the renumbering, corners 2 and 3 are swapped, so the (multilinear) mapping becomes
(x,y) --> (0.25y, 0.25(x+y - 2xy), 0)
This is a common misconception. As I said, there is no guarantee on the orientation. It is especially allowed that the embedding is different from the reference elements. I.e.
ReferenceElement::subEntity()
is in general not consistent with the corners numbering of subentities in grid entities. It should only be used as a tool to enumerate the sub-subentities.See, e.g, flyspray/FS#980 (closed) and flyspray/FS#818 (closed) for detailed discussions about this topic.
So even if the subEntities
GeometryType
is(GeometryType::cube, 2)
, it can have a reference element different from the Dune cube reference element? I did not know that. But then the numbering of the corners of the subEntity is arbitrary? Then we could as well do the renumbering :).I am currently iterating over the codim cc entities of the UGGrid by iterating over the codim cc subentities of the codim 0 elements, which seems to work with the renumbering in this patch. Without the renumbering, there are problems with the
jacobianTransposed()
method due to the nonlinear mapping.So even if the current behavior is not wrong, maybe we can still do the renumbering as it does not matter for correctness and provides an (inofficial) way to iterate over the codim cc entities of the UGGrid?
If you have the reference element
r_e
of an elemente
and the referencer_s
of a subentitys
ofe
, thenr_e
andr_s
are both standard Dune reference elements (e.g. for cubes). But the embedding ofs
intoe
is not guaranteed to be consistent with the "canonical" embedding ofr_s
intor_e
induced byr_e.subEntity(...)
but is an implementation detail which may depends one
ands
.Even if your patch seems to imply this consistency for your example this is a special case, because there is in general no consistent numbering. That's why the implementation is free to pick what even it wants. Just think of the following "algorithm" to create such a numbering: You recreate your grid by inserting elements one-by-one. Then any new element must be consistent with the face numbering of all its already inserted neighbours. This may lead to the case that you cannot add the next element without violating the rules enforced by the reference element.
If you really need to know, which number the i-th vertex of a face
s
has within an element containings
you can derive this by looping over all vertices and comparing global indices obtained byindexSet.subIndex(...)
(cf. flyspray/FS#818 (closed)). However, you will run into the problem that UGGrid does not implementindexSet.subIndex(...)
for entities other than elements or vertices (cf. !95 (merged)).That said, this question is completely unrelated to the question if the geometry mapping is linear or not (,even if it is still unclear, which map you are talking of). This holds true for the geometry map of both, the element and the face. If the map is nonlinear for a parallelepiped this must be a misuse of or bug in the geometry implementation.
I just discussed with @tobias.leibner and it seems that
- Tobias had this misunderstanding about the guarantees w.r.t. numbering
- there is really a bug, as the geometry obtained from the subentity yields a mapping which doesn't have a positive determinant of the jacobian.
We agreed that he will update the tests and check whether this is really the case.
@tobias.leibner: I'm sorry, I missed your explanation on the map above. Now I understand your problem. The opposite/neighbouring relation of the cube corners in the reference element and the entity is different. I.e. it's indeed a misuse of the geometry.
Added 1 commit:
- c8209a2d - [test-ug] make test not relying on any ordering assumptions
As discussed with @christi, here is a new test that does not rely on the ordering of the corners. It checks whether the local-to-global mapping for the codim 1 entities is bijective. As we did not find a simple solution to test all codim 1 entities the test checks only the codim 1 entities that lie in the x-y-plane.
Sorry for not intervening. Yes, there is a bug, but you really only see it for element faces with four corners. There, the UG numbering swaps to vertices when compared to the Dune numbering, and that leads to the singular jacobian that Tobias is seeing. For all other cases Carsten's comment applies: the Dune grid interface does not really require the vertex ordering of these geometries to be related to the rest of the grid at all.
I think the second part of the fix is correct, but the first part is wrong. I'll comment there directly.
Thanks for writing the test, but a test only for UGGrid is not of much use. Thinks like this may as well be wrong in other grid implementations (current or future), and a test should apply to all of them. I recognize that the issue is a but tricky to test for.
- Resolved by Tobias Leibner
- Resolved by Tobias Leibner