7#ifndef DUNE_FUNCTIONS_GRIDFUNCTIONS_FACENORMALGRIDFUNCTION_HH
8#define DUNE_FUNCTIONS_GRIDFUNCTIONS_FACENORMALGRIDFUNCTION_HH
13#include <dune/common/exceptions.hh>
14#include <dune/common/typeutilities.hh>
15#include <dune/common/rangeutilities.hh>
16#include <dune/geometry/referenceelements.hh>
18#include <dune/functions/gridfunctions/gridfunction.hh>
19#include <dune/functions/gridfunctions/gridviewentityset.hh>
22namespace Dune::Functions {
27template<
class ReferenceElement,
class Coordinate>
28auto closestFaceIndex(
const ReferenceElement& re,
const Coordinate& x)
30 auto closestFaceIndex =
decltype(re.subEntity(0,1,0,1)){};
31 double closestFaceDistance = std::numeric_limits<double>::max();
32 for(
auto&& faceIndex : Dune::range(re.size(1)))
37 auto normal = re.integrationOuterNormal(faceIndex);
38 normal /= normal.two_norm();
39 auto c = re.position(faceIndex,1);
41 auto faceDistance = (c*normal);
42 if (faceDistance<closestFaceDistance)
44 closestFaceDistance = faceDistance;
45 closestFaceIndex = faceIndex;
48 return closestFaceIndex;
77 using Domain =
typename EntitySet::GlobalCoordinate;
78 using Range =
typename EntitySet::GlobalCoordinate;
86 using Geometry =
typename Element::Geometry;
87 static const int dimension = GV::dimension;
101 void bind(
const Element& element)
104 geometry_.emplace(element_.geometry());
116 return static_cast<bool>(geometry_);
130 auto&& re = Dune::referenceElement(*geometry_);
132 auto face = Impl::closestFaceIndex(re, x);
133 auto localNormal = re.integrationOuterNormal(face);
137 auto normal = Range{};
138 geometry_->jacobianInverseTransposed(x).mv(localNormal, normal);
139 normal /= normal.two_norm();
144 const Element& localContext()
const
150 friend typename Traits::LocalFunctionTraits::DerivativeInterface
derivative(
const LocalFunction& t)
152 DUNE_THROW(NotImplemented,
"not implemented");
156 std::optional<Geometry> geometry_;
169 DUNE_THROW(NotImplemented,
"not implemented");
175 DUNE_THROW(NotImplemented,
"not implemented");
181 return LocalFunction{};
191 EntitySet entitySet_;
Grid function implementing the piecewise element face normal.
Definition: facenormalgridfunction.hh:70
const EntitySet & entitySet() const
Return the stored GridViewEntitySet.
Definition: facenormalgridfunction.hh:185
friend Traits::DerivativeInterface derivative(const FaceNormalGridFunction &t)
Not implemented.
Definition: facenormalgridfunction.hh:173
friend LocalFunction localFunction(const FaceNormalGridFunction &t)
Return a local-function associated to FaceNormalGridFunction.
Definition: facenormalgridfunction.hh:179
FaceNormalGridFunction(const GridView &gridView)
Construct the FaceNormalGridFunction.
Definition: facenormalgridfunction.hh:162
Range operator()(const Domain &x) const
Not implemented.
Definition: facenormalgridfunction.hh:167
GridView::template Codim< codim >::Entity Element
Type of Elements contained in this EntitySet.
Definition: gridviewentityset.hh:36
Element::Geometry::LocalCoordinate LocalCoordinate
Type of local coordinates with respect to the Element.
Definition: gridviewentityset.hh:39
Default implementation for derivative traits.
Definition: defaultderivativetraits.hh:41