Dune Core Modules (2.9.0)

composedgridfunction.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_FUNCTIONS_GRIDFUNCTIONS_COMPOSEDGRIDFUNCTION_HH
4#define DUNE_FUNCTIONS_GRIDFUNCTIONS_COMPOSEDGRIDFUNCTION_HH
5
6#include <type_traits>
7#include <tuple>
8
9#include <dune/common/referencehelper.hh>
11
12#include <dune/functions/common/defaultderivativetraits.hh>
13#include <dune/functions/common/differentiablefunction.hh>
14#include <dune/functions/gridfunctions/gridfunction.hh>
15
16
17namespace Dune {
18namespace Functions {
19
20
21
40template<class OF, class... IF>
42{
43 using InnerFunctions = std::tuple<IF...>;
44 using InnerLocalFunctions = std::tuple<decltype(localFunction(resolveRef(std::declval<const IF&>())))...>;
45
46 template<std::size_t i>
47 using InnerFunction = std::decay_t<ResolveRef_t<std::tuple_element_t<i, InnerFunctions>>>;
48
49 using OuterFunction = OF;
50
51public:
52
53 using EntitySet = typename InnerFunction<0>::EntitySet;
54 using Element = typename EntitySet::Element;
55
56 using Domain = typename EntitySet::GlobalCoordinate;
57 using LocalDomain = typename EntitySet::LocalCoordinate;
58
59 using Range = decltype(std::declval<OF>()(std::declval<IF>()(std::declval<Domain>())...));
60
61private:
62
63 using Traits = Imp::GridFunctionTraits<Range(Domain), EntitySet, DefaultDerivativeTraits, 16>;
64
65 class LocalFunction
66 {
67 public:
74 LocalFunction(const ComposedGridFunction& globalFunction) :
75 globalFunction_(globalFunction),
76 innerLocalFunctions_(globalFunction.innerLocalFunctions())
77 {}
78
88 void bind(const Element& element)
89 {
90 std::apply([&](auto&... innerFunction) {
91 (innerFunction.bind(element),...);
92 }, innerLocalFunctions_);
93 }
94
96 void unbind()
97 {
98 std::apply([&](auto&... innerFunction) {
99 (innerFunction.unbind(),...);
100 }, innerLocalFunctions_);
101 }
102
105 bool bound() const
106 {
107 return std::apply([](const auto&... innerFunction) {
108 return (innerFunction.bound() && ...);
109 }, innerLocalFunctions_);
110 }
111
121 Range operator()(const LocalDomain& x) const
122 {
123 return std::apply([&](const auto&... innerFunction) {
124 return globalFunction_.outerFunction_(innerFunction(x)...);
125 }, innerLocalFunctions_);
126 }
127
137 const Element& localContext() const
138 {
139 return std::get<0>(innerLocalFunctions_).localContext();
140 }
141
143 friend typename Traits::LocalFunctionTraits::DerivativeInterface derivative(const LocalFunction& t)
144 {
145 DUNE_THROW(NotImplemented,"not implemented");
146 }
147
148 private:
149 const ComposedGridFunction& globalFunction_;
150 InnerLocalFunctions innerLocalFunctions_;
151 };
152
153public:
154
164 template<class OFT, class... IFT,
166 std::enable_if_t<(sizeof...(IFT) > 0), int> = 0>
167 ComposedGridFunction(OFT&& outerFunction, IFT&&... innerFunctions) :
168 outerFunction_(std::forward<OFT>(outerFunction)),
169 innerFunctions_(std::forward<IFT>(innerFunctions)...)
170 {}
171
173 Range operator()(const Domain& x) const
174 {
175 DUNE_THROW(NotImplemented,"not implemented");
176 }
177
179 friend typename Traits::DerivativeInterface derivative(const ComposedGridFunction& t)
180 {
181 DUNE_THROW(NotImplemented,"not implemented");
182 }
183
190 friend LocalFunction localFunction(const ComposedGridFunction& cgf)
191 {
192 return LocalFunction(cgf);
193 }
194
205 const EntitySet& entitySet() const
206 {
207 return resolveRef(std::get<0>(innerFunctions_)).entitySet();
208 }
209
210protected:
211
212 InnerLocalFunctions innerLocalFunctions() const
213 {
214 return std::apply([&](const auto&... innerFunction) {
215 return std::make_tuple(localFunction(resolveRef(innerFunction))...);
216 }, innerFunctions_);
217 }
218
219 OuterFunction outerFunction_;
220 InnerFunctions innerFunctions_;
221};
222
223
224
247template<class OF, class... IF>
248auto makeComposedGridFunction(OF&& outerFunction, IF&&... innerFunction)
249{
250 using ComposedGridFunctionType = ComposedGridFunction<std::decay_t<OF>, std::decay_t<IF>...>;
251 return ComposedGridFunctionType(std::forward<OF>(outerFunction), std::forward<IF>(innerFunction)...);
252}
253
254
255
256}} // namespace Dune::Functions
257
258
259
260#endif // DUNE_FUNCTIONS_GRIDFUNCTIONS_COMPOSEDGRIDFUNCTION_HH
Composition of grid functions with another function.
Definition: composedgridfunction.hh:42
ComposedGridFunction(OFT &&outerFunction, IFT &&... innerFunctions)
Create ComposedGridFunction.
Definition: composedgridfunction.hh:167
const EntitySet & entitySet() const
Return the EntitySet associated to this composed grid-function.
Definition: composedgridfunction.hh:205
friend LocalFunction localFunction(const ComposedGridFunction &cgf)
Create a local-function of this composed grid-function.
Definition: composedgridfunction.hh:190
Range operator()(const Domain &x) const
Evaluation of the composed grid function in coordinates x
Definition: composedgridfunction.hh:173
friend Traits::DerivativeInterface derivative(const ComposedGridFunction &t)
Not implemented.
Definition: composedgridfunction.hh:179
Default exception for dummy implementations.
Definition: exceptions.hh:263
constexpr T & resolveRef(T &gf) noexcept
Helper function to resolve std::reference_wrapper.
Definition: referencehelper.hh:47
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
auto makeComposedGridFunction(OF &&outerFunction, IF &&... innerFunction)
Create a ComposedGridFunction that composes grid-functions with another function.
Definition: composedgridfunction.hh:248
std::enable_if_t< not Impl::disableCopyMoveHelper< This, T... >::value, int > disableCopyMove
Helper to disable constructor as copy and move constructor.
Definition: typeutilities.hh:45
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Default implementation for derivative traits.
Definition: defaultderivativetraits.hh:37
Utilities for type computations, constraining overloads, ...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)