6#include <amdis/Operations.hpp>
7#include <amdis/common/ForEach.hpp>
8#include <amdis/common/Logical.hpp>
9#include <amdis/common/Order.hpp>
10#include <amdis/common/TypeTraits.hpp>
11#include <amdis/gridfunctions/Derivative.hpp>
12#include <amdis/gridfunctions/GridFunction.hpp>
17 template <
class Signatur,
class Element,
class Functor,
class... LocalFunctions>
22 template <
class R,
class D,
class E,
class Functor,
class... LocalFunctions>
30 enum { hasDerivative =
true };
34 template <
class... LocalFcts>
37 , localFcts_{FWD(localFcts)...}
41 void bind(Element
const& element)
43 std::apply([&](
auto &...lf) { (lf.bind(element), ...); }, localFcts_);
49 std::apply([](
auto&... lf) { (lf.unbind(),...); },
56 return std::get<0>(localFcts_).bound();
62 return std::apply([&](
auto const&... lf) {
return fct_(lf(x)...); },
69 return std::get<0>(localFcts_).localContext();
80 auto const& localFunctions()
const
87 std::tuple<LocalFunctions...> localFcts_;
90 template <
class Element,
class Functor,
class... LocalFunctions>
91 auto makeComposerLocalFunction(
Functor const& f, LocalFunctions
const&... lf)
93 using D =
typename Element::Geometry::LocalCoordinate;
94 using R = TYPEOF(f(lf(std::declval<D>())...));
95 return ComposerLocalFunction<R(D), Element,
Functor, LocalFunctions...>{f, lf...};
109 template <
class Sig,
class E,
class F,
class... LFs,
class Type,
110 REQUIRES(Concepts::HasPartial<F>)>
111 auto derivativeOf(ComposerLocalFunction<Sig,E,F,LFs...>
const& composed, Type
const& type)
114 auto term_i = [&](
auto ii)
116 auto di_f = std::apply([&](
auto const&... lf) {
117 return makeComposerLocalFunction<E>(partial(composed.fct(), ii), lf...);
118 }, composed.localFunctions());
120 auto const& lf_i = std::get<ii>(composed.localFunctions());
122 = makeComposerLocalFunction<E>(Operation::Multiplies{}, di_f, derivativeOf(lf_i, type));
123 if (composed.bound())
124 df.bind(composed.localContext());
129 auto localFct = Ranges::applyIndices<
sizeof...(LFs)>([&](
auto... ii)
131 return makeComposerLocalFunction<E>(Operation::Plus{}, term_i(ii)...);
146 template <
class Sig,
class E,
class F,
class... LFs,
147 REQUIRES(Concepts::HasFunctorOrder<F,
sizeof...(LFs)>
148 && (Concepts::Polynomial<LFs> &&...))>
149 int order(ComposerLocalFunction<Sig,E,F,LFs...>
const& composed)
151 return Ranges::apply([&](
auto const&... lf) {
152 return order(composed.fct(), order(lf)...);
153 }, composed.localFunctions());
175 template <
class Sig,
class EntitySet,
class Functor,
class... GridFunctions>
178 template <
class R,
class D,
class ES,
class Functor,
class... GridFunctions>
184 using EntitySet = ES;
186 enum { hasDerivative =
false };
189 template <
class Gr
idFct>
190 using LocalFct = TYPEOF( localFunction(underlying(std::declval<GridFct const&>())) );
192 using LocalDomain =
typename EntitySet::LocalCoordinate;
193 using Element =
typename EntitySet::Element;
200 template <
class... GridFcts>
202 : entitySet_{entitySet}
204 , gridFcts_{FWD(gridFcts)...}
210 return std::apply([&](
auto const&... gf) {
return fct_(underlying(gf)(x)...); },
223 return std::apply([&](
auto const&... gf) {
return LocalFunction{fct_, localFunction(underlying(gf))...}; },
228 EntitySet entitySet_;
230 std::tuple<GridFunctions...> gridFcts_;
235 template <
class Functor,
class GridView,
class... GridFcts>
236 auto makeComposerGridFunction(
Functor const& f, GridView
const& gridView,
237 GridFcts
const&... gridFcts)
239 static_assert((Concepts::GridFunction<GridFcts> && ...),
240 "All passed parameters must be GridFunctions.");
242 "Range types of grid functions are not compatible with the functor.");
244 using EntitySet = Dune::Functions::GridViewEntitySet<GridView, 0>;
245 using Domain =
typename EntitySet::GlobalCoordinate;
246 using Range = TYPEOF(f(underlying(gridFcts)(std::declval<Domain>())...));
248 using FGF = ComposerGridFunction<Range(Domain), EntitySet,
Functor, GridFcts...>;
249 return FGF{EntitySet{gridView},f, gridFcts...};
255 template <
class Functor,
class... PreGridFunctions>
262 template <
class Gr
idView>
263 static auto create(
Self const& self, GridView
const& gridView)
265 return std::apply([&](
auto const&... pgf) {
266 return makeComposerGridFunction(self.fct_, gridView,
268 }, self.preGridFcts_);
272 template <
class... PreGridFcts>
275 , preGridFcts_{FWD(pgfs)...}
280 std::tuple<PreGridFunctions...> preGridFcts_;
285 template <
class Functor,
class... PreGridFcts>
304 template <
class Functor,
class... PreGridFcts>
LocalFunction makeLocalFunction() const
Create the localFunction by composition of the inner localFunctions.
Definition: ComposerGridFunction.hpp:221
Range operator()(Domain const &x) const
Applies the functor to the evaluated gridfunctions.
Definition: ComposerGridFunction.hpp:208
EntitySet const & entitySet() const
Return the stored EntitySet of the first GridFunction.
Definition: ComposerGridFunction.hpp:215
ComposerGridFunction(EntitySet const &entitySet, Functor const &fct, GridFcts &&... gridFcts)
Constructor. Stores copies of the functor and gridfunctions.
Definition: ComposerGridFunction.hpp:201
A Gridfunction that applies a functor to the evaluated Gridfunctions.
Definition: ComposerGridFunction.hpp:176
bool bound() const
Check whether the LocalFunction is bound to an element.
Definition: ComposerGridFunction.hpp:54
Range operator()(Domain const &x) const
Applies the functor fct_ to the evaluated localFunctions.
Definition: ComposerGridFunction.hpp:60
ComposerLocalFunction(Functor const &fct, LocalFcts &&... localFcts)
Constructor. Stores copies of the functor and localFunction(gridfunction)s.
Definition: ComposerGridFunction.hpp:35
Functor const & fct() const
Return the stored functor.
Definition: ComposerGridFunction.hpp:75
void bind(Element const &element)
Calls bind for all localFunctions.
Definition: ComposerGridFunction.hpp:41
Element const & localContext() const
Get the element this localfunction (and all inner localfunctions) are bound to.
Definition: ComposerGridFunction.hpp:67
void unbind()
Calls unbind for all localFunctions.
Definition: ComposerGridFunction.hpp:47
Definition: ComposerGridFunction.hpp:18
constexpr bool Functor
A Functor is a function F with signature Signature.
Definition: Concepts.hpp:133
constexpr bool Callable
A Collable is a function F that can be called with arguments of type Args....
Definition: Concepts.hpp:120
auto invokeAtQP(Functor const &f, PreGridFcts &&... gridFcts)
Generator function for ComposerGridFunction.
Definition: ComposerGridFunction.hpp:305
decltype(auto) makeGridFunction(PreGridFct const &preGridFct, GridView const &gridView)
Generator for Gridfunctions from Expressions (PreGridfunctions)
Definition: GridFunction.hpp:168
Definition: ComposerGridFunction.hpp:261
Definition: ComposerGridFunction.hpp:257
Definition: GridFunction.hpp:27