6#include <dune/common/referencehelper.hh>
7#include <dune/functions/gridfunctions/gridviewentityset.hh>
9#include <amdis/common/TypeTraits.hpp>
10#include <amdis/Output.hpp>
26template <
class GV,
class GF>
31 using EntitySet = Dune::Functions::GridViewEntitySet<GV,0>;
34 using Domain =
typename EntitySet::GlobalCoordinate;
37 using Range = std::invoke_result_t<GF, Domain>;
43 using Element =
typename EntitySet::Element;
45 using Grid =
typename GV::Grid;
46 using Geometry =
typename Element::Geometry;
48 template <
class ES,
class LF>
56 using Mapping = std::function<Domain(Domain
const&)>;
58 typename Element::HierarchicIterator it;
72 , localFct_(std::move(localFct))
82 void bind(Element
const& element)
84 element_.emplace(element);
87 if (entitySet_.contains(*element_)) {
88 localFct_.bind(*element_);
92 test_exit_dbg(!element_->isLeaf(),
"Element is leaf. Cannot traverse its children.");
93 for (
auto it = element_->hbegin(maxLevel_); it != element_->hend(maxLevel_); ++it) {
94 if (entitySet_.contains(*it))
95 childs_.emplace_back(
ChildElement{.it=it, .local=makeMapping(*element_,*it)});
98 test_exit_dbg(!childs_.empty(),
"No child element in entitySet found!");
120 typename Grid::ctype
const checkInsideTolerance = std::sqrt(std::numeric_limits<typename Grid::ctype>::epsilon());
121 for (
auto const& child : childs_) {
122 auto refElem = referenceElement(*child.it);
123 auto local = child.local(x);
124 auto refTypeId = refElem.type().id();
125 bool isInside = Dune::Geo::Impl::checkInside(refTypeId, Geometry::mydimension, local, checkInsideTolerance);
127 localFct_.bind(*child.it);
128 return localFct_(local);
132 error_exit(
"No child element with x in child found!");
144 template <
class LF_ = LF>
149 entitySet_, derivative(localFct_)};
161 Mapping map = [](
Domain const& x) {
return x; };
162 while (coarse != fine && fine.hasFather()) {
163 map = [map, geo=fine.geometryInFather()](Domain
const& x) {
164 return map(geo.local(x));
166 fine = fine.father();
172 ES
const& entitySet_;
173 mutable LF localFct_;
175 std::optional<Element> element_;
177 std::vector<ChildElement> childs_;
187 : gridView_{gridView}
188 , entitySet_{gridView}
193 : gridView_{gridView}
194 , entitySet_{gridView}
195 , gridFct_{std::move(gridFct)}
205 template <
class GF_ = GF>
208 TYPEOF(derivative(Dune::resolveRef(std::declval<GF_ const&>())))>
210 return {gridView_, derivative(Dune::resolveRef(gridFct_))};
216 using LF = TYPEOF(localFunction(Dune::resolveRef(gridFct_)));
218 return LocalFunction{gridFct_.entitySet(),
219 localFunction(Dune::resolveRef(gridFct_)),
220 gridView_.grid().maxLevel()};
Definition: CoarsenedGridFunction.hpp:50
auto makeDerivative() const -> CoarsenedLocalFunction< ES, TYPEOF(derivative(std::declval< LF_ const & >()))>
Construct a derivative by wrapping the derivative of the wrapped local-function.
Definition: CoarsenedGridFunction.hpp:145
bool bound() const
Check whether the LocalFunction is bound to an element.
Definition: CoarsenedGridFunction.hpp:108
Range operator()(Domain const &x) const
Evaluate LocalFunction at bound element.
Definition: CoarsenedGridFunction.hpp:114
void bind(Element const &element)
Bind the wrapped local-function to grid element.
Definition: CoarsenedGridFunction.hpp:82
CoarsenedLocalFunction(ES const &entitySet, LF const &localFct, int maxLevel)
Constructor. Stores the localFct by value.
Definition: CoarsenedGridFunction.hpp:64
Element const & localContext() const
Return the element this LocalFunction is bound to.
Definition: CoarsenedGridFunction.hpp:137
void unbind()
Unbind the wrapped local-function.
Definition: CoarsenedGridFunction.hpp:102
A grid function defining data on a coarser entity level than it can be bound to.
Definition: CoarsenedGridFunction.hpp:28
std::invoke_result_t< GF, Domain > Range
The result type of the function.
Definition: CoarsenedGridFunction.hpp:37
auto makeDerivative() const -> CoarsenedGridFunction< GV, TYPEOF(derivative(Dune::resolveRef(std::declval< GF_ const & >())))>
Construct a derivative by wrapping the derivative of the wrapped grid-function.
Definition: CoarsenedGridFunction.hpp:206
typename EntitySet::GlobalCoordinate Domain
The global coordinates.
Definition: CoarsenedGridFunction.hpp:34
Range operator()(Domain const &x) const
Evaluate the wrapped grid-function.
Definition: CoarsenedGridFunction.hpp:199
typename EntitySet::Element Element
Type of the grid element the LocalFunction can be bound to.
Definition: CoarsenedGridFunction.hpp:43
auto makeLocalFunction() const
Construct local function from a DiscreteGlobalBasisFunction.
Definition: CoarsenedGridFunction.hpp:214
EntitySet const & entitySet() const
Get associated EntitySet.
Definition: CoarsenedGridFunction.hpp:224
typename EntitySet::LocalCoordinate LocalDomain
The local coordinates.
Definition: CoarsenedGridFunction.hpp:40
CoarsenedGridFunction(GV const &gridView, GF const &gridFct)
Constructor.
Definition: CoarsenedGridFunction.hpp:186
Dune::Functions::GridViewEntitySet< GV, 0 > EntitySet
The set of entities this function can be evaluated on.
Definition: CoarsenedGridFunction.hpp:31
Definition: CoarsenedGridFunction.hpp:57