AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
DiscreteFunction.hpp
1#pragma once
2
3#include <optional>
4#include <vector>
5
6#include <dune/common/ftraits.hh>
7#include <dune/common/typeutilities.hh>
8#include <dune/functions/common/defaultderivativetraits.hh>
9#include <dune/functions/functionspacebases/flatvectorview.hh>
10#include <dune/functions/gridfunctions/gridviewentityset.hh>
11#include <dune/typetree/childextraction.hh>
12
13#include <amdis/common/DerivativeTraits.hpp>
14#include <amdis/common/Tags.hpp>
15#include <amdis/functions/NodeCache.hpp>
16#include <amdis/interpolators/SimpleInterpolator.hpp>
17#include <amdis/linearalgebra/Access.hpp>
18#include <amdis/typetree/FiniteElementType.hpp>
19#include <amdis/typetree/RangeType.hpp>
20#include <amdis/typetree/TreePath.hpp>
21
22namespace AMDiS
23{
26
37 template <class Coeff, class GB, class TreePath, class Range = void>
38 class DiscreteFunction;
39
40
42 template <class Coeff, class GB, class TreePath, class R>
44 : public DiscreteFunction<Coeff const,GB,TreePath,R>
45 {
48
49 using Coefficients = std::remove_const_t<Coeff>;
50 using GlobalBasis = GB;
51
52 public:
54 template <class C, class B, class... Path,
55 REQUIRES(Concepts::Similar<Underlying_t<C>, Coefficients>),
56 REQUIRES(Concepts::Similar<Underlying_t<B>, GlobalBasis>)>
57 DiscreteFunction(C&& coefficients, B&& basis, Path... path)
58 : Super(FWD(coefficients), FWD(basis), path...)
59 , mutableCoeff_(wrap_or_share<Coefficients>(FWD(coefficients)))
60 {}
61
62 public:
65
72 template <class Expr, class Tag = tag::assign>
73 void interpolate_noalias(Expr&& expr, Tag strategy = {});
74
76
85 template <class Expr, class Tag = tag::assign>
86 void interpolate(Expr&& expr, Tag strategy = {});
87
89 template <class Expr>
90 Self& operator<<(Expr&& expr)
91 {
92 interpolate(FWD(expr));
93 return *this;
94 }
95
97 template <class Expr>
98 Self& operator+=(Expr&& expr)
99 {
100 interpolate((*this) + expr);
101 return *this;
102 }
103
105 template <class Expr>
106 Self& operator-=(Expr&& expr)
107 {
108 interpolate((*this) - expr);
109 return *this;
110 }
111
113 Coefficients& coefficients()
114 {
115 return *mutableCoeff_;
116 }
117
120
121 template <class Range = void, class... Indices>
122 auto child(Indices... ii)
123 {
124 auto tp = cat(Super::treePath_, makeTreePath(ii...));
125 using Child = DiscreteFunction<Coeff, GB, TYPEOF(makeTreePath(tp)), Range>;
126 return Child{mutableCoeff_, Super::basis_, tp};
127 }
128
129 using Super::child;
130
131 protected:
132 std::shared_ptr<Coefficients> mutableCoeff_;
133 };
134
136 template <class Coeff, class GB, class TreePath, class R>
137 class DiscreteFunction<Coeff const,GB,TreePath,R>
138 {
139 private:
140 using Coefficients = std::remove_const_t<Coeff>;
141 using GlobalBasis = GB;
142 using LocalView = typename GlobalBasis::LocalView;
143 using GridView = typename GlobalBasis::GridView;
144
145 using Coefficient = TYPEOF(std::declval<Traits::Access>()(std::declval<Coeff const>(), std::declval<typename GB::MultiIndex>()));
146
147 using Tree = typename GlobalBasis::LocalView::Tree;
148 using SubTree = typename Dune::TypeTree::ChildForTreePath<Tree, TreePath>;
149
150 public:
152 using EntitySet = Dune::Functions::GridViewEntitySet<GridView, 0>;
153
155 using Domain = typename EntitySet::GlobalCoordinate;
156
158 using Range = std::conditional_t<std::is_same_v<R,void>, RangeType_t<SubTree,Coefficient>, R>;
159
162 enum { hasDerivative = false };
163
164 private:
166 template <class Type>
167 class LocalFunction;
168
169 public:
172
179 template <class C, class B, class... Path,
180 REQUIRES(Concepts::Similar<Underlying_t<C>, Coefficients>),
181 REQUIRES(Concepts::Similar<Underlying_t<B>, GlobalBasis>)>
182 DiscreteFunction(C&& coefficients, B&& basis, Path... path)
183 : coefficients_{wrap_or_share(FWD(coefficients))}
184 , basis_{wrap_or_share(FWD(basis))}
185 , treePath_{makeTreePath(path...)}
186 , entitySet_{basis_->gridView()}
187 {}
188
190 Range operator()(Domain const& x) const;
191
193 LocalFunction<tag::value> makeLocalFunction() const
194 {
195 return {basis().localView(), treePath_, coefficients_, tag::value{}};
196 }
197
199 EntitySet const& entitySet() const
200 {
201 return entitySet_;
202 }
203
205 GlobalBasis const& basis() const
206 {
207 return *basis_;
208 }
209
211 TreePath const& treePath() const
212 {
213 return treePath_;
214 }
215
217 Coefficients const& coefficients() const
218 {
219 return *coefficients_;
220 }
221
222 template <class Range = void, class... Indices>
223 auto child(Indices... ii) const
224 {
225 auto tp = cat(this->treePath_, makeTreePath(ii...));
226 using Child = DiscreteFunction<Coeff const, GB, TYPEOF(makeTreePath(tp)), Range>;
227 return Child{coefficients_, basis_, tp};
228 }
229
230 protected:
231 std::shared_ptr<Coefficients const> coefficients_;
232 std::shared_ptr<GlobalBasis const> basis_;
233 TreePath treePath_;
234 EntitySet entitySet_;
235 };
236
237
238 // deduction guides
239
240 template <class Coefficients, class Basis, class... Indices,
241 class C = Underlying_t<Coefficients>,
242 class B = std::remove_const_t<Underlying_t<Basis>>,
243 class TP = TYPEOF(makeTreePath(std::declval<Indices>()...)),
244 REQUIRES(Concepts::GlobalBasis<B>)>
245 DiscreteFunction(Coefficients&&, Basis&&, Indices...)
246 -> DiscreteFunction<C,B,TP>;
247
248
249 // Get the childs of a discrete function by using `valueOf`
250 // -------------------------------------------------------
251
253 template <class Range = void, class C, class GB, class TP, class R, class... Indices>
254 auto valueOf(DiscreteFunction<C,GB,TP,R>& df, Indices... ii)
255 {
256 return df.template child<Range>(ii...);
257 }
258
260 template <class Range = void, class C, class GB, class TP, class R, class... Indices>
261 auto valueOf(DiscreteFunction<C,GB,TP,R> const& df, Indices... ii)
262 {
263 return df.template child<Range>(ii...);
264 }
265
266} // end namespace AMDiS
267
268#include "DiscreteLocalFunction.inc.hpp"
269#include "DiscreteFunction.inc.hpp"
A Const DiscreteFunction.
Definition: DiscreteFunction.hpp:138
TreePath const & treePath() const
Return treePath associated with this discrete function.
Definition: DiscreteFunction.hpp:211
typename EntitySet::GlobalCoordinate Domain
Global coordinates of the EntitySet.
Definition: DiscreteFunction.hpp:155
Dune::Functions::GridViewEntitySet< GridView, 0 > EntitySet
Set of entities the DiscreteFunction is defined on.
Definition: DiscreteFunction.hpp:152
Range operator()(Domain const &x) const
Evaluate DiscreteFunction in global coordinates. NOTE: expensive.
DiscreteFunction(C &&coefficients, B &&basis, Path... path)
Definition: DiscreteFunction.hpp:182
std::conditional_t< std::is_same_v< R, void >, RangeType_t< SubTree, Coefficient >, R > Range
Range type of this DiscreteFunction. If R=void deduce the Range automatically, using RangeType_t.
Definition: DiscreteFunction.hpp:158
Coefficients const & coefficients() const
Return const coefficient vector.
Definition: DiscreteFunction.hpp:217
LocalFunction< tag::value > makeLocalFunction() const
Create a local function for this view on the DOFVector.
Definition: DiscreteFunction.hpp:193
EntitySet const & entitySet() const
Return a Dune::Functions::GridViewEntitySet.
Definition: DiscreteFunction.hpp:199
GlobalBasis const & basis() const
Return global basis bound to the DOFVector.
Definition: DiscreteFunction.hpp:205
A mutable view on the subspace of a DOFVector,.
Definition: DiscreteFunction.hpp:45
DiscreteFunction(C &&coefficients, B &&basis, Path... path)
Constructor. Stores a pointer to the mutable coefficients vector.
Definition: DiscreteFunction.hpp:57
Self & operator+=(Expr &&expr)
interpolate (*this) + expr to DOFVector
Definition: DiscreteFunction.hpp:98
Coefficients & coefficients()
Return the mutable DOFVector.
Definition: DiscreteFunction.hpp:113
Self & operator-=(Expr &&expr)
interpolate (*this) - expr to DOFVector
Definition: DiscreteFunction.hpp:106
void interpolate(Expr &&expr, Tag strategy={})
Interpolation of GridFunction to DOFVector.
Definition: DiscreteFunction.inc.hpp:52
Self & operator<<(Expr &&expr)
Interpolation of GridFunction to DOFVector, alias to interpolate()
Definition: DiscreteFunction.hpp:90
void interpolate_noalias(Expr &&expr, Tag strategy={})
Interpolation of GridFunction to DOFVector, assuming that there is no reference to this DOFVector in ...
Definition: DiscreteFunction.inc.hpp:36
Global basis defined on a pre-basis.
Definition: GlobalBasis.hpp:48
AMDiS::LocalView< Self > LocalView
Type of the local view on the restriction of the basis to a single element.
Definition: GlobalBasis.hpp:61
typename PreBasis::GridView GridView
The grid view that the FE space is defined on.
Definition: GlobalBasis.hpp:57
typename Super::Tree Tree
Tree of local finite elements / local shape function sets.
Definition: LocalView.hpp:24
constexpr bool Similar
Types are the same, up to decay of qualifiers.
Definition: Concepts.hpp:107
Definition: DerivativeTraits.hpp:18