6#include <amdis/Operations.hpp>
7#include <amdis/algorithm/Map.hpp>
8#include <amdis/common/ForEach.hpp>
9#include <amdis/common/Logical.hpp>
10#include <amdis/common/Order.hpp>
11#include <amdis/common/TypeTraits.hpp>
12#include <amdis/gridfunctions/Derivative.hpp>
13#include <amdis/gridfunctions/GridFunction.hpp>
18 template <
class Signatur,
class Element,
class Functor,
class LocalFunctions>
23 template <
class R,
class D,
class E,
class Functor,
class LocalFct>
31 enum { hasDerivative =
true };
34 using LocalFctRange = TYPEOF( std::declval<LocalFct>()(std::declval<Domain>()) );
39 : fct_(std::move(fct))
40 , localFcts_(std::move(localFcts))
44 void bind(Element
const& element)
46 for (
auto& lf : localFcts_)
53 for (
auto& lf : localFcts_)
60 return localFcts_[0].bound();
66 return fct_(Recursive::map([&](
auto const& lf) {
return lf(x); }, localFcts_));
72 return localFcts_[0].localContext();
78 Functor
const&
fct()
const
83 auto const& localFunctions()
const
90 std::vector<LocalFct> localFcts_;
93 template <
class Element,
class Functor,
class LocalFct>
94 auto makeComposerVectorLocalFunction(Functor
const& f, std::vector<LocalFct> lfs)
96 using D =
typename Element::Geometry::LocalCoordinate;
97 using LocalFctRange = TYPEOF(std::declval<LocalFct>()(std::declval<D>()));
98 using R = TYPEOF(f(std::vector<LocalFctRange>{}));
99 return ComposerLocalFunction<R(D), Element,
Functor, LocalFct>{f, std::move(lfs)};
112 T operator()(std::vector<T>
const& ts)
const
114 return std::accumulate(ts.begin(),ts.end(),T(0));
118 inline int order(
PlusVector const&, std::vector<int>
const& orders)
120 return *std::max_element(orders.begin(), orders.end());
123 inline auto partial(PlusVector
const&, std::size_t i)
141 template <
class Sig,
class E,
class F,
class LF,
class Type,
142 REQUIRES(Concepts::HasPartial<F>)>
143 auto derivativeOf(ComposerVectorLocalFunction<Sig,E,F,LF>
const& composed, Type
const& type)
146 auto term_i = [&](std::size_t i)
148 auto di_f = makeComposerVectorLocalFunction<E>(partial(composed.fct(), i),
149 composed.localFunctions());
150 auto df = makeComposerLocalFunction<E>(Operation::Multiplies{}, di_f,
151 derivativeOf(composed.localFunctions()[i], type));
152 if (composed.bound())
153 df.bind(composed.localContext());
158 std::vector<TYPEOF(term_i(0))> terms;
159 for (std::size_t i = 0; i < composed.localFunctions().size(); ++i)
160 terms.emplace_back(term_i(i));
161 return makeComposerVectorLocalFunction<E>(Operation::PlusVector{}, terms);
173 template <
class Sig,
class E,
class F,
class LF,
174 REQUIRES(Concepts::HasFunctorVectorOrder<F> && Concepts::Polynomial<LF>)>
175 int order(ComposerVectorLocalFunction<Sig,E,F,LF>
const& composed)
177 return order(composed.fct(),
178 Recursive::map([](
auto const& lf) { return order(lf); }, composed.localFunctions()));
200 template <
class Sig,
class EntitySet,
class Functor,
class Gr
idFct>
203 template <
class R,
class D,
class ES,
class Functor,
class Gr
idFct>
209 using EntitySet = ES;
211 enum { hasDerivative =
false };
214 using LocalFct = TYPEOF( localFunction(std::declval<GridFct const&>()) );
215 using LocalDomain =
typename EntitySet::LocalCoordinate;
216 using Element =
typename EntitySet::Element;
224 : entitySet_(entitySet)
225 , fct_(std::move(fct))
226 , gridFcts_(std::move(gridFcts))
232 return fct_(Recursive::map([&](
auto const& gf) {
return gf(x); }, gridFcts_));
245 Recursive::map([](
auto const& gf) {
return localFunction(gf); }, gridFcts_)};
249 EntitySet entitySet_;
251 std::vector<GridFct> gridFcts_;
256 template <
class Functor,
class Gr
idView,
class Gr
idFct>
257 auto makeComposerVectorGridFunction(Functor
const& f, GridView
const& gridView,
258 std::vector<GridFct> gridFcts)
260 static_assert((Concepts::GridFunction<GridFct>),
261 "All passed parameters must be GridFunctions.");
263 using EntitySet = Dune::Functions::GridViewEntitySet<GridView, 0>;
264 using Domain =
typename EntitySet::GlobalCoordinate;
265 using GridFctRange = TYPEOF( std::declval<GridFct>()(std::declval<Domain>()) );
267 static_assert(Concepts::Callable<Functor, std::vector<GridFctRange>>,
268 "Range types of grid functions are not compatible with the functor.");
269 using Range = TYPEOF(f(std::vector<GridFctRange>{}));
271 using FGF = ComposerVectorGridFunction<Range(Domain), EntitySet,
Functor, GridFct>;
272 return FGF{EntitySet{gridView},f, std::move(gridFcts)};
278 template <
class Functor,
class PreGr
idFct>
285 template <
class Gr
idView>
286 static auto create(
Self const& self, GridView
const& gridView)
288 return makeComposerVectorGridFunction(self.fct_, gridView,
289 Recursive::map([&](
auto const& pgf) { return makeGridFunction(pgf, gridView); },
295 : fct_(std::move(fct))
296 , preGridFcts_(std::move(pgfs))
301 std::vector<PreGridFct> preGridFcts_;
306 template <
class Functor,
class PreGr
idFct>
323 template <
class Functor,
class PreGr
idFct>
LocalFunction makeLocalFunction() const
Create the localFunction by composition of the inner localFunctions.
Definition ComposerVectorGridFunction.hpp:242
Range operator()(Domain const &x) const
Applies the functor to the evaluated gridfunctions.
Definition ComposerVectorGridFunction.hpp:230
ComposerVectorGridFunction(EntitySet const &entitySet, Functor fct, std::vector< GridFct > gridFcts)
Constructor. Stores copies of the functor and gridfunctions.
Definition ComposerVectorGridFunction.hpp:223
EntitySet const & entitySet() const
Return the stored EntitySet of the first GridFunction.
Definition ComposerVectorGridFunction.hpp:236
Definition ComposerVectorGridFunction.hpp:201
bool bound() const
Check whether the LocalFunction is bound to an element.
Definition ComposerVectorGridFunction.hpp:58
ComposerVectorLocalFunction(Functor fct, std::vector< LocalFct > localFcts)
Constructor. Stores copies of the functor and localFunction(gridfunction)s.
Definition ComposerVectorGridFunction.hpp:38
Range operator()(Domain const &x) const
Applies the functor fct_ to the evaluated localFunctions.
Definition ComposerVectorGridFunction.hpp:64
Functor const & fct() const
Return the stored functor.
Definition ComposerVectorGridFunction.hpp:78
void bind(Element const &element)
Calls bind for all localFunctions.
Definition ComposerVectorGridFunction.hpp:44
Element const & localContext() const
Get the element this localfunction (and all inner localfunctions) are bound to.
Definition ComposerVectorGridFunction.hpp:70
void unbind()
Calls unbind for all localFunctions.
Definition ComposerVectorGridFunction.hpp:51
Definition ComposerVectorGridFunction.hpp:19
constexpr bool Functor
A Functor is a function F with signature Signature.
Definition Concepts.hpp:133
auto invokeVectorAtQP(Functor f, std::vector< PreGridFct > gridFcts)
Generator function for ComposerVectorPreGridFunction.
Definition ComposerVectorGridFunction.hpp:324
Definition ComposerVectorGridFunction.hpp:284
Definition ComposerVectorGridFunction.hpp:280
Functor that represents A+B.
Definition ComposerVectorGridFunction.hpp:110
Definition GridFunction.hpp:28