6 #include <dune/common/std/apply.hh> 8 #include <amdis/Operations.hpp> 9 #include <amdis/common/ForEach.hpp> 10 #include <amdis/common/Logical.hpp> 11 #include <amdis/common/Order.hpp> 12 #include <amdis/common/TypeTraits.hpp> 13 #include <amdis/gridfunctions/Derivative.hpp> 14 #include <amdis/gridfunctions/GridFunction.hpp> 19 template <
class Signatur,
class Element,
class Functor,
class... LocalFunctions>
24 template <
class R,
class D,
class E,
class Functor,
class... LocalFunctions>
32 enum { hasDerivative =
true };
36 template <
class... LocalFcts>
39 , localFcts_{FWD(localFcts)...}
43 void bind(Element
const& element)
45 std::apply([&](
auto&... lf) { (lf.bind(element),...); },
52 std::apply([](
auto&... lf) { (lf.unbind(),...); },
59 return std::apply([&](
auto const&... lf) {
return fct_(lf(x)...); },
66 return std::get<0>(localFcts_).localContext();
72 Functor
const&
fct()
const 77 auto const& localFunctions()
const 84 std::tuple<LocalFunctions...> localFcts_;
87 template <
class Element,
class Functor,
class... LocalFunctions>
88 auto makeComposerLocalFunction(Functor
const& f, LocalFunctions
const&... lf)
90 using D =
typename Element::Geometry::LocalCoordinate;
91 using R = TYPEOF(f(lf(std::declval<D>())...));
106 template <
class Sig,
class E,
class F,
class... LFs,
class Type,
107 REQUIRES(Concepts::HasPartial<F>)>
111 auto term_i = [&](
auto ii)
113 auto di_f = std::apply([&](
auto const&... lf) {
114 return makeComposerLocalFunction<E>(partial(composed.fct(), ii), lf...);
115 }, composed.localFunctions());
117 auto const& lf_i = std::get<ii>(composed.localFunctions());
122 auto localFct = Ranges::applyIndices<
sizeof...(LFs)>([&](
auto... ii)
139 template <
class Sig,
class E,
class F,
class... LFs,
140 REQUIRES(Concepts::HasFunctorOrder<F,
sizeof...(LFs)>
141 && (Concepts::Polynomial<LFs> &&...))>
144 return Ranges::apply([&](
auto const&... lf) {
145 return order(composed.fct(), order(lf)...);
146 }, composed.localFunctions());
168 template <
class Sig,
class EntitySet,
class Functor,
class... GridFunctions>
171 template <
class R,
class D,
class ES,
class Functor,
class... GridFunctions>
177 using EntitySet = ES;
179 enum { hasDerivative =
false };
182 template <
class Gr
idFct>
183 using LocalFct = TYPEOF( localFunction(underlying(std::declval<GridFct const&>())) );
185 using LocalDomain =
typename EntitySet::LocalCoordinate;
186 using Element =
typename EntitySet::Element;
193 template <
class... GridFcts>
195 : entitySet_{entitySet}
197 , gridFcts_{FWD(gridFcts)...}
203 return std::apply([&](
auto const&... gf) {
return fct_(underlying(gf)(x)...); },
216 return std::apply([&](
auto const&... gf) {
return LocalFunction{fct_, localFunction(underlying(gf))...}; },
221 EntitySet entitySet_;
223 std::tuple<GridFunctions...> gridFcts_;
228 template <
class Functor,
class GridView,
class... GridFcts>
229 auto makeComposerGridFunction(Functor
const& f, GridView
const& gridView,
230 GridFcts
const&... gridFcts)
232 static_assert((Concepts::GridFunction<GridFcts> && ...),
233 "All passed parameters must be GridFunctions.");
234 static_assert(Concepts::Callable<Functor, typename GridFcts::Range...>,
235 "Range types of grid functions are not compatible with the functor.");
237 using EntitySet = Dune::Functions::GridViewEntitySet<GridView, 0>;
238 using Domain =
typename EntitySet::GlobalCoordinate;
239 using Range = TYPEOF(f(underlying(gridFcts)(std::declval<Domain>())...));
242 return FGF{EntitySet{gridView},f, gridFcts...};
248 template <
class Functor,
class... PreGridFunctions>
255 template <
class Gr
idView>
256 static auto create(
Self const&
self, GridView
const& gridView)
258 return std::apply([&](
auto const&... pgf) {
259 return makeComposerGridFunction(
self.fct_, gridView,
261 },
self.preGridFcts_);
265 template <
class... PreGridFcts>
268 , preGridFcts_{FWD(pgfs)...}
273 std::tuple<PreGridFunctions...> preGridFcts_;
278 template <
class Functor,
class... PreGridFcts>
297 template <
class Functor,
class... PreGridFcts>
A Gridfunction that applies a functor to the evaluated Gridfunctions.
Definition: ComposerGridFunction.hpp:169
Definition: GridFunction.hpp:26
Functor const & fct() const
Return the stored functor.
Definition: ComposerGridFunction.hpp:72
constexpr bool Functor
A Functor is a function F with signature Signature.
Definition: Concepts.hpp:134
auto invokeAtQP(Functor const &f, PreGridFcts &&... gridFcts)
Generator function for ComposerGridFunction.
Definition: ComposerGridFunction.hpp:298
Range operator()(Domain const &x) const
Applies the functor to the evaluated gridfunctions.
Definition: ComposerGridFunction.hpp:201
decltype(auto) makeGridFunction(PreGridFct const &preGridFct, GridView const &gridView)
Generator for Gridfunctions from Expressions (PreGridfunctions)
Definition: GridFunction.hpp:168
Definition: AdaptBase.hpp:6
void bind(Element const &element)
Calls bind for all localFunctions.
Definition: ComposerGridFunction.hpp:43
Functor that represents A*B.
Definition: Arithmetic.hpp:100
Functor that represents A+B.
Definition: Arithmetic.hpp:19
Definition: ComposerGridFunction.hpp:253
ComposerGridFunction(EntitySet const &entitySet, Functor const &fct, GridFcts &&... gridFcts)
Constructor. Stores copies of the functor and gridfunctions.
Definition: ComposerGridFunction.hpp:194
Definition: ComposerGridFunction.hpp:249
LocalFunction makeLocalFunction() const
Create the localFunction by composition of the inner localFunctions.
Definition: ComposerGridFunction.hpp:214
Element const & localContext() const
Get the element this localfunction (and all inner localfunctions) are bound to.
Definition: ComposerGridFunction.hpp:64
EntitySet const & entitySet() const
Return the stored EntitySet of the first GridFunction.
Definition: ComposerGridFunction.hpp:208
Definition: ComposerGridFunction.hpp:20
ComposerLocalFunction(Functor const &fct, LocalFcts &&... localFcts)
Constructor. Stores copies of the functor and localFunction(gridfunction)s.
Definition: ComposerGridFunction.hpp:37
void unbind()
Calls unbind for all localFunctions.
Definition: ComposerGridFunction.hpp:50
Range operator()(Domain const &x) const
Applies the functor fct_ to the evaluated localFunctions.
Definition: ComposerGridFunction.hpp:57