AMDiS 2.11-git
The Adaptive Multi-Dimensional Simulation Toolbox
 
Loading...
Searching...
No Matches
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/common/typetree/childaccess.hh>
9#include <dune/functions/common/defaultderivativetraits.hh>
10#include <dune/functions/functionspacebases/flatvectorview.hh>
11#include <dune/functions/gridfunctions/gridviewentityset.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 RangeGenerator = RangeType<SubTree,Coefficient,R>;
159 using Range = typename RangeGenerator::type;
160
163 enum { hasDerivative = false };
164
165 private:
167 template <class Type>
168 class LocalFunction;
169
170 public:
173
180 template <class C, class B, class... Path,
181 REQUIRES(Concepts::Similar<Underlying_t<C>, Coefficients>),
182 REQUIRES(Concepts::Similar<Underlying_t<B>, GlobalBasis>)>
183 DiscreteFunction(C&& coefficients, B&& basis, Path... path)
184 : coefficients_{wrap_or_share(FWD(coefficients))}
185 , basis_{wrap_or_share(FWD(basis))}
186 , treePath_{makeTreePath(path...)}
187 , entitySet_{basis_->gridView()}
188 {}
189
191 Range operator()(Domain const& x) const;
192
194 LocalFunction<tag::value> makeLocalFunction() const
195 {
196 return {basis().localView(), treePath_, coefficients_, tag::value{}};
197 }
198
200 EntitySet const& entitySet() const
201 {
202 return entitySet_;
203 }
204
206 GlobalBasis const& basis() const
207 {
208 return *basis_;
209 }
210
212 TreePath const& treePath() const
213 {
214 return treePath_;
215 }
216
218 Coefficients const& coefficients() const
219 {
220 return *coefficients_;
221 }
222
223 template <class Range = void, class... Indices>
224 auto child(Indices... ii) const
225 {
226 auto tp = cat(this->treePath_, makeTreePath(ii...));
227 using Child = DiscreteFunction<Coeff const, GB, TYPEOF(makeTreePath(tp)), Range>;
228 return Child{coefficients_, basis_, tp};
229 }
230
231 protected:
232 std::shared_ptr<Coefficients const> coefficients_;
233 std::shared_ptr<GlobalBasis const> basis_;
234 TreePath treePath_;
235 EntitySet entitySet_;
236 };
237
238
239 // deduction guides
240
241 template <class Coefficients, class Basis, class... Indices,
242 class C = Underlying_t<Coefficients>,
243 class B = std::remove_const_t<Underlying_t<Basis>>,
244 class TP = TYPEOF(makeTreePath(std::declval<Indices>()...)),
245 REQUIRES(Concepts::GlobalBasis<B>)>
246 DiscreteFunction(Coefficients&&, Basis&&, Indices...)
247 -> DiscreteFunction<C,B,TP>;
248
249
250 // Get the childs of a discrete function by using `valueOf`
251 // -------------------------------------------------------
252
254 template <class Range = void, class C, class GB, class TP, class R, class... Indices>
255 auto valueOf(DiscreteFunction<C,GB,TP,R>& df, Indices... ii)
256 {
257 return df.template child<Range>(ii...);
258 }
259
261 template <class Range = void, class C, class GB, class TP, class R, class... Indices>
262 auto valueOf(DiscreteFunction<C,GB,TP,R> const& df, Indices... ii)
263 {
264 return df.template child<Range>(ii...);
265 }
266
267} // end namespace AMDiS
268
269#include "DiscreteLocalFunction.inc.hpp"
270#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:212
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:183
Coefficients const & coefficients() const
Return const coefficient vector.
Definition DiscreteFunction.hpp:218
LocalFunction< tag::value > makeLocalFunction() const
Create a local function for this view on the DOFVector.
Definition DiscreteFunction.hpp:194
EntitySet const & entitySet() const
Return a Dune::Functions::GridViewEntitySet.
Definition DiscreteFunction.hpp:200
RangeType< SubTree, Coefficient, R > RangeGenerator
Range type of this DiscreteFunction. If R=void deduce the Range automatically, using RangeType_t.
Definition DiscreteFunction.hpp:158
GlobalBasis const & basis() const
Return global basis bound to the DOFVector.
Definition DiscreteFunction.hpp:206
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:47
AMDiS::LocalView< Self > LocalView
Type of the local view on the restriction of the basis to a single element.
Definition GlobalBasis.hpp:60
typename PreBasis::GridView GridView
The grid view that the FE space is defined on.
Definition GlobalBasis.hpp:56
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