Skip to content

Fix refine coarse mesh

Daniel Bauer requested to merge bauerd/fix-refine-coarse-mesh into master

Fixes an issue with MeshInfo::refinedCoarseMesh. This method creates a new coarse mesh that shall look exactly like the old mesh on refinement level 1. To this end, it introduces new vertices at all edges and creates new cells accordingly.

The main challenge is not introducing the same midpoint twice, when refining neighboring cells. Prior to this MR, a map from vertex coordinates, to ids of newly introduced vertices was used. The problem however was that the coordinates of the midpoints were rounded differently depending on the order of the edge endpoints. Actually, making the computation of the midpoint symmetric (e3fa0abf) is enough to fix this issue.

However, since I am paranoid, I changed the map to be from edge endpoint vertex ids (sorted) to the vertex id of the midpoint. This way, floating comparisons are removed entirely.

I strengthened the test accordingly and checked that it fails on the current master.

Lastly, I want to point out that this is a really nice real-world example demonstrating that you have to be careful with floating point arithmetic. While both versions of the midpoint calculation are mathematically equivalent, only one of them is correct.

Merge request reports