DUNE-FUNCTIONS (2.8)

analyticgridviewfunction.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_ANALYTICGRIDVIEWFUNCTION_HH
4#define DUNE_FUNCTIONS_GRIDFUNCTIONS_ANALYTICGRIDVIEWFUNCTION_HH
5
6#include <type_traits>
7#include <optional>
8
9#include <dune/common/typeutilities.hh>
10
11#include <dune/functions/common/signature.hh>
12#include <dune/functions/common/defaultderivativetraits.hh>
13#include <dune/functions/common/differentiablefunction_imp.hh>
14#include <dune/functions/common/differentiablefunction.hh>
15#include <dune/functions/gridfunctions/gridviewentityset.hh>
16#include <dune/functions/gridfunctions/localderivativetraits.hh>
17
18
19namespace Dune {
20namespace Functions {
21
22namespace Imp {
23
24template<class Signature, class GV, class FLocal, template<class> class DerivativeTraits=DefaultDerivativeTraits>
25class LocalAnalyticGridViewFunction;
26
27template<class Range, class LocalDomain, class GV, class F, template<class> class DerivativeTraits>
28class LocalAnalyticGridViewFunction<Range(LocalDomain), GV, F, DerivativeTraits>
29{
30public:
31 using Signature = Range(LocalDomain);
32 using RawSignature = typename SignatureTraits<Signature>::RawSignature;
33 using DerivativeSignature = typename DerivativeTraits<RawSignature>::Range(LocalDomain);
34
35 using GridView = GV;
36 using EntitySet = GridViewEntitySet<GridView, 0>;
37 using Element = typename EntitySet::Element;
38// using Geometry = typename Element::Geometry;
39 using Geometry = typename std::decay<typename Element::Geometry>::type;
40
41 // Use the inderiction via derivativeIfImplemented to also support
42 // function types F that do not implement derivative. In this case
43 // the interface type DifferentiableFunction is used a dummy for
44 // the derivative type
45 using DerivativeDummy = DifferentiableFunction<DerivativeSignature>;
46 using GlobalRawDerivative = decltype(Imp::derivativeIfImplemented<DerivativeDummy, F>(std::declval<F>()));
47 using LocalDerivative = LocalAnalyticGridViewFunction<DerivativeSignature, GridView, GlobalRawDerivative, DerivativeTraits>;
48
49 template<class FT, disableCopyMove<LocalAnalyticGridViewFunction, FT> = 0>
50 LocalAnalyticGridViewFunction(FT&& f) :
51 f_(std::forward<FT>(f))
52 {}
53
54
55 void bind(const Element& element)
56 {
57 element_ = element;
58
59 // We'd like to do
60 //
61 // geometry_ = element_.geometry();
62 //
63 // But since Geometry is not assignable we
64 // have to reconstruct it - argh
65 geometry_.reset();
66 geometry_.emplace(element_.geometry());
67 }
68
69 void unbind()
70 {}
71
72 Range operator()(const LocalDomain& x) const
73 {
74 return f_(geometry_.value().global(x));
75 }
76
77 const Element& localContext() const
78 {
79 return element_;
80 }
81
82 friend LocalDerivative derivative(const LocalAnalyticGridViewFunction& t)
83 {
84 return LocalDerivative(Imp::derivativeIfImplemented<DerivativeDummy, F>(t.f_));
85 }
86
87private:
88
89 // Hack around the fact that Geometry is not default constructible.
90 std::optional<Geometry> geometry_;
91
92 Element element_;
93 F f_;
94};
95
96} // end namespace Imp
97
98
99
100
101template<class Signature, class GV, class F, template<class> class DerivativeTraits=DefaultDerivativeTraits>
102class AnalyticGridViewFunction;
103
104
110template<class Range, class Domain, class GV, class F, template<class> class DerivativeTraits>
111class AnalyticGridViewFunction<Range(Domain), GV, F, DerivativeTraits>
112{
113public:
114 using Signature = Range(Domain);
115 using RawSignature = typename SignatureTraits<Signature>::RawSignature;
116 using DerivativeSignature = typename DerivativeTraits<RawSignature>::Range(Domain);
117
118 using GridView = GV;
120 using Element = typename EntitySet::Element;
121 using Geometry = typename Element::Geometry;
122
123 // Use the inderiction via derivativeIfImplemented to also support
124 // function types F that do not implement derivative. In this case
125 // the interface type DifferentiableFunction is used a dummy for
126 // the derivative type
127 using DerivativeDummy = DifferentiableFunction<DerivativeSignature>;
128 using GlobalRawDerivative = decltype(Imp::derivativeIfImplemented<DerivativeDummy, F>(std::declval<F>()));
129 using Derivative = AnalyticGridViewFunction<DerivativeSignature, GridView, GlobalRawDerivative, DerivativeTraits>;
130
131 using LocalDomain = typename EntitySet::LocalCoordinate;
132 using LocalFunction = typename Imp::LocalAnalyticGridViewFunction<Range(LocalDomain), GridView, F, LocalDerivativeTraits<EntitySet, DerivativeTraits>::template Traits>;
133
134 template<class FT>
135 AnalyticGridViewFunction(FT&& f, const GridView& gridView) :
136 f_(std::forward<FT>(f)),
137 entitySet_(gridView)
138 {}
139
140 Range operator()(const Domain& x) const
141 {
142 return f_(x);
143 }
144
145 friend Derivative derivative(const AnalyticGridViewFunction& t)
146 {
147 return Derivative(Imp::derivativeIfImplemented<DerivativeDummy, F>(t.f_), t.entitySet_.gridView());
148 }
149
150 friend LocalFunction localFunction(const AnalyticGridViewFunction& t)
151 {
152 return LocalFunction(t.f_);
153 }
154
155 const EntitySet& entitySet() const
156 {
157 return entitySet_;
158 }
159
160private:
161 F f_;
162 EntitySet entitySet_;
163};
164
165
166
178template<class F, class GridView>
179AnalyticGridViewFunction<
180 typename std::invoke_result<F, typename GridView::template Codim<0>::Geometry::GlobalCoordinate>::type // Range
181 (typename GridView::template Codim<0>::Geometry::GlobalCoordinate), // Domain
182 GridView,
183 typename std::decay<F>::type > // Raw type of F (without & or &&)
184 makeAnalyticGridViewFunction(F&& f, const GridView& gridView)
185{
186 using Domain = typename GridView::template Codim<0>::Geometry::GlobalCoordinate;
187 using Range = typename std::invoke_result<F, Domain>::type;
188 using FRaw = typename std::decay<F>::type;
189
190 return AnalyticGridViewFunction<Range(Domain), GridView, FRaw>(std::forward<F>(f), gridView);
191}
192
193
194
195}} // namespace Dune::Functions
196
197
198
199#endif // DUNE_FUNCTIONS_GRIDFUNCTIONS_ANALYTICGRIDVIEWFUNCTION_HH
GridView::template Codim< codim >::Entity Element
Type of Elements contained in this EntitySet.
Definition: gridviewentityset.hh:32
Element::Geometry::LocalCoordinate LocalCoordinate
Type of local coordinates with respect to the Element.
Definition: gridviewentityset.hh:35
void localFunction(DiscreteGlobalBasisFunction< TT... > &&t)=delete
Construction of local functions from a temporary DiscreteGlobalBasisFunction (forbidden)
TrigonometricFunction< K, -cosFactor, sinFactor > derivative(const TrigonometricFunction< K, sinFactor, cosFactor > &f)
Obtain derivative of TrigonometricFunction function.
Definition: trigonometricfunction.hh:39
Definition: polynomial.hh:10
Derivative traits for local functions.
Definition: localderivativetraits.hh:28
Helper class to deduce the signature of a callable.
Definition: signature.hh:56
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)