7#ifndef DUNE_FUNCTIONS_GRIDFUNCTIONS_COMPOSEDGRIDFUNCTION_HH
8#define DUNE_FUNCTIONS_GRIDFUNCTIONS_COMPOSEDGRIDFUNCTION_HH
13#include <dune/common/referencehelper.hh>
14#include <dune/common/typeutilities.hh>
16#include <dune/functions/common/defaultderivativetraits.hh>
17#include <dune/functions/common/differentiablefunction.hh>
18#include <dune/functions/gridfunctions/gridfunction.hh>
44template<
class OF,
class... IF>
47 using InnerFunctions = std::tuple<IF...>;
48 using InnerLocalFunctions = std::tuple<decltype(localFunction(resolveRef(std::declval<const IF&>())))...>;
50 template<std::
size_t i>
51 using InnerFunction = std::decay_t<ResolveRef_t<std::tuple_element_t<i, InnerFunctions>>>;
53 using OuterFunction = OF;
57 using EntitySet =
typename InnerFunction<0>::EntitySet;
58 using Element =
typename EntitySet::Element;
60 using Domain =
typename EntitySet::GlobalCoordinate;
61 using LocalDomain =
typename EntitySet::LocalCoordinate;
63 using Range =
decltype(std::declval<OF>()(std::declval<IF>()(std::declval<Domain>())...));
79 globalFunction_(globalFunction),
80 innerLocalFunctions_(globalFunction.innerLocalFunctions())
92 void bind(
const Element& element)
94 std::apply([&](
auto&... innerFunction) {
95 (innerFunction.bind(element),...);
96 }, innerLocalFunctions_);
102 std::apply([&](
auto&... innerFunction) {
103 (innerFunction.unbind(),...);
104 }, innerLocalFunctions_);
111 return std::apply([](
const auto&... innerFunction) {
112 return (innerFunction.bound() && ...);
113 }, innerLocalFunctions_);
127 return std::apply([&](
const auto&... innerFunction) {
128 return globalFunction_.outerFunction_(innerFunction(x)...);
129 }, innerLocalFunctions_);
141 const Element& localContext()
const
143 return std::get<0>(innerLocalFunctions_).localContext();
147 friend typename Traits::LocalFunctionTraits::DerivativeInterface
derivative(
const LocalFunction& t)
149 DUNE_THROW(NotImplemented,
"not implemented");
154 InnerLocalFunctions innerLocalFunctions_;
168 template<
class OFT,
class... IFT,
169 disableCopyMove<ComposedGridFunction, OFT> = 0,
170 std::enable_if_t<(
sizeof...(IFT) > 0),
int> = 0>
172 outerFunction_(std::forward<OFT>(outerFunction)),
173 innerFunctions_(std::forward<IFT>(innerFunctions)...)
179 return std::apply([&](
const auto&... innerFunction) {
180 return outerFunction_(innerFunction(x)...);
187 DUNE_THROW(NotImplemented,
"not implemented");
198 return LocalFunction(cgf);
213 return resolveRef(std::get<0>(innerFunctions_)).entitySet();
218 InnerLocalFunctions innerLocalFunctions()
const
220 return std::apply([&](
const auto&... innerFunction) {
221 return std::make_tuple(
localFunction(resolveRef(innerFunction))...);
225 OuterFunction outerFunction_;
226 InnerFunctions innerFunctions_;
230template<
class OF,
class... IF>
231ComposedGridFunction(
const OF&,
const IF&...)
232 -> ComposedGridFunction<OF,IF...>;
257template<
class OF,
class... IF>
261 return ComposedGridFunctionType(std::forward<OF>(outerFunction), std::forward<IF>(innerFunction)...);
Composition of grid functions with another function.
Definition: composedgridfunction.hh:46
ComposedGridFunction(OFT &&outerFunction, IFT &&... innerFunctions)
Create ComposedGridFunction.
Definition: composedgridfunction.hh:171
const EntitySet & entitySet() const
Return the EntitySet associated to this composed grid-function.
Definition: composedgridfunction.hh:211
friend LocalFunction localFunction(const ComposedGridFunction &cgf)
Create a local-function of this composed grid-function.
Definition: composedgridfunction.hh:196
Range operator()(const Domain &x) const
Evaluation of the composed grid function in coordinates x
Definition: composedgridfunction.hh:177
friend Traits::DerivativeInterface derivative(const ComposedGridFunction &t)
Not implemented.
Definition: composedgridfunction.hh:185
auto makeComposedGridFunction(OF &&outerFunction, IF &&... innerFunction)
Create a ComposedGridFunction that composes grid-functions with another function.
Definition: composedgridfunction.hh:258
Definition: polynomial.hh:17
Default implementation for derivative traits.
Definition: defaultderivativetraits.hh:41