Skip to content

Commit

Permalink
patchkernel: fix evaluation of normal for polygonal elements
Browse files Browse the repository at this point in the history
Evaluating the normal of a polygonal element as the weighted average of
the normals of its tiles will not generate a versor (triangular
inequality). After being evaluated, the vector needs to be
explicitly normalized.
  • Loading branch information
marcocisternino committed Apr 4, 2023
1 parent 070fb06 commit ba1d430
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/patchkernel/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,12 +1688,15 @@ std::array<double, 3> Element::evalNormal(const std::array<double, 3> *coordinat

case ElementType::POLYGON:
{
// The normal of a polygonal element is evaluated as the weighted average of the
// normals of its tiles. The resulting vector should be normalized in order to
// obtain a versor (euclidean vector norm is not linear, therefore is not possible
// to evaluate the weights in order to automatically obtain a versor).
int dimension = getDimension();

Tesselation tesselation = generateTesselation(coordinates);
int nTiles = tesselation.getTileCount();

double surfaceArea = 0.;
std::array<double, 3> normal = {{0., 0., 0.}};
for (int i = 0; i < nTiles; ++i) {
ElementType tileType = tesselation.getTileType(i);
Expand All @@ -1711,10 +1714,9 @@ std::array<double, 3> Element::evalNormal(const std::array<double, 3> *coordinat
tileNormal = orientation;
}

normal += tileArea * tileNormal;
surfaceArea += tileArea;
normal += tileArea * tileNormal;
}
normal = (1. / surfaceArea) * normal;
normal /= norm2(normal);

return normal;
}
Expand Down

0 comments on commit ba1d430

Please sign in to comment.