Skip to content

[draft] Add ElementGeometryGridFunction

Carsten Gräser requested to merge feature/add-elementgeometrygridfunction into master

This maps any point x to a tuple consisting of the element, it's geometry, and the local coordinate of the point.

While this function is not very helpful on its own, it allows to implement grid functions representing geometric mesh properties with very little effort by composition. E.g. FaceNormalGridFunction could be implemented as

  auto computeFaceNormal = [](auto arg)
  {
    const auto& [element, geometry, x] = arg;

    auto&& re = Dune::referenceElement(geometry);
    // Compute reference normal of closest face to given point
    auto face = Dune::Functions::Impl::closestFaceIndex(re, x);
    auto localNormal = re.integrationOuterNormal(face);

    // Transform reference normal into global unit outer normal using
    // covariant Piola transformation
    using Range = typename GridView::template Codim<0>::Entity::Geometry::GlobalCoordinate;
    auto normal = Range{};
    geometry.jacobianInverseTransposed(x).mv(localNormal, normal);
    normal /= normal.two_norm();
    return normal;
  };

  auto normal = Dune::Functions::makeComposedGridFunction(computeFaceNormal, Dune::Functions::ElementGeometryGridFunction(gridView));

Similarly one could implement element circumference, maximal edge length, ... .

Merge request reports

Loading