AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
GridFunctionOperator.hpp
1#pragma once
2
3#include <cassert>
4#include <type_traits>
5
6#include <amdis/GridFunctionOperatorTransposed.hpp>
7#include <amdis/Output.hpp>
8#include <amdis/common/Order.hpp>
9#include <amdis/common/TypeTraits.hpp>
10#include <amdis/utility/QuadratureFactory.hpp>
11
12namespace AMDiS
13{
19 template <class LF, class Imp>
20 class GridFunctionLocalOperator;
21
22
24
37 template <class GF, class Imp>
39 {
40 public:
41 using GridFunction = GF;
42 using Implementation = Imp;
43
45
49 template <class GridFct, class Impl>
50 GridFunctionOperator(GridFct&& gridFct, Impl&& impl,
51 int derivDeg, int gridFctOrder)
52 : gridFct_(FWD(gridFct))
53 , impl_(FWD(impl))
54 , derivDeg_(derivDeg)
55 , gridFctOrder_(gridFctOrder)
56 {}
57
58 template <class GridView>
59 void update(GridView const&) { /* do nothing */ }
60
61 friend auto localOperator(GridFunctionOperator const& op)
62 {
63 return GridFunctionLocalOperator{localFunction(op.gridFct_), op.impl_,
64 op.derivDeg_, op.gridFctOrder_};
65 }
66
67 private:
69 GridFunction gridFct_;
70
72 Implementation impl_;
73
75 int derivDeg_;
76
78 int gridFctOrder_;
79 };
80
81 template <class GridFct, class Impl>
82 GridFunctionOperator(GridFct const& gridFct, Impl const& impl, int, int)
83 -> GridFunctionOperator<GridFct, Impl>;
84
85
87
100 template <class LF, class Imp>
102 {
103 private:
105 using LocalFunction = LF;
106
108 using Implementation = Imp;
109
110 public:
112
117 template <class LocalFct, class Impl>
118 GridFunctionLocalOperator(LocalFct&& localFct, Impl&& impl,
119 int derivDeg, int localFctOrder)
120 : localFct_(FWD(localFct))
121 , impl_(FWD(impl))
122 , derivDeg_(derivDeg)
123 , localFctOrder_(localFctOrder)
124 {}
125
127
130 template <class Element>
131 void bind(Element const& element)
132 {
133 localFct_.bind(element);
134 }
135
137 void unbind()
138 {
139 localFct_.unbind();
140 }
141
143
147 template <class CG, class RN, class CN, class Mat>
148 void assemble(CG const& contextGeo, RN const& rowNode, CN const& colNode,
149 Mat& elementMatrix) const
150 {
151 auto const& quad = getQuadratureRule(contextGeo.geometry(),
152 derivDeg_, localFctOrder(), rowNode, colNode);
153 impl().assemble(contextGeo, rowNode, colNode, quad, localFct_, elementMatrix);
154 }
155
157
161 template <class CG, class Node, class Vec>
162 void assemble(CG const& contextGeo, Node const& node,
163 Vec& elementVector) const
164 {
165 auto const& quad = getQuadratureRule(contextGeo.geometry(),
166 derivDeg_, localFctOrder(), node);
167 impl().assemble(contextGeo, node, quad, localFct_, elementVector);
168 }
169
170 Implementation & impl() { return impl_; }
171 Implementation const& impl() const { return impl_; }
172
173 protected:
174 // Return the order of the coefficients function, either localFctOrder_ or
175 // the order of the local-function
176 int localFctOrder() const
177 {
178 if (localFctOrder_ >= 0)
179 return localFctOrder_;
180 else {
181 int coeffOrder = -1;
182 // Try to get polynomial order of local-functions
183 if constexpr (Concepts::Polynomial<LF>)
184 coeffOrder = order(localFct_);
185
186 test_exit(coeffOrder >= 0,
187 "Polynomial degree of coefficients cannot be determined. "
188 "Please provide a quadrature order manually.");
189
190 return coeffOrder;
191 }
192 }
193
194 private:
196 LocalFunction localFct_;
197
199 Implementation impl_;
200
202 int derivDeg_;
203
205 int localFctOrder_;
206 };
207
208 // deduction guide
209 template <class LocalFct, class Impl>
210 GridFunctionLocalOperator(LocalFct const& localFct, Impl const& impl, int, int)
211 -> GridFunctionLocalOperator<LocalFct, Impl>;
212
213
215 template <class Tag, class LocalContext>
217
218 template <class Tag, class Expr>
220 {
221 Tag tag;
222 Expr expr;
223 int gridFctDeg;
224
225 OperatorTerm(Tag tag, Expr const& expr, int gridFctDeg = -1)
226 : tag(tag)
227 , expr(expr)
228 , gridFctDeg(gridFctDeg)
229 {}
230 };
231
234 template <class Tag, class Expr>
235 auto makeOperator(Tag const& tag, Expr&& expr, int gridFctDeg = -1)
236 {
237 return OperatorTerm{tag, FWD(expr), gridFctDeg};
238 }
239
240 template <class Tag, class Expr>
241 auto operatorTerm(Tag const& tag, Expr&& expr, int gridFctDeg = -1)
242 {
243 return OperatorTerm{tag, FWD(expr), gridFctDeg};
244 }
245
248#ifndef DOXYGEN
249
250 template <class R, class Tag>
251 using IsTransposed = decltype(R::transposedTag(std::declval<Tag>()));
252
255 template <class Context, class Tag, class Expr, class GridView>
256 auto makeOperator(OperatorTerm<Tag,Expr> const& op, GridView const& gridView)
257 {
258 auto gf = makeGridFunction(std::move(op.expr), gridView);
259
260 using Registry = GridFunctionOperatorRegistry<Tag,Context>;
261 if constexpr (Dune::Std::is_detected_v<IsTransposed,Registry,Tag>) {
262 auto impl = typename Registry::type{Registry::transposedTag(op.tag)};
263 return GridFunctionOperatorTransposed{
264 GridFunctionOperator{std::move(gf), std::move(impl), Registry::degree, op.gridFctDeg}
265 };
266 } else {
267 auto impl = typename Registry::type{op.tag};
268 return GridFunctionOperator{std::move(gf), std::move(impl), Registry::degree, op.gridFctDeg};
269 }
270 }
272
273#endif // DOXYGEN
274
275} // end namespace AMDiS
The main implementation of a local-operator depending on a local-function.
Definition: GridFunctionOperator.hpp:102
GridFunctionLocalOperator(LocalFct &&localFct, Impl &&impl, int derivDeg, int localFctOrder)
Constructor. Stores a copy of localFct and impl.
Definition: GridFunctionOperator.hpp:118
void bind(Element const &element)
Binds operator to element.
Definition: GridFunctionOperator.hpp:131
void assemble(CG const &contextGeo, Node const &node, Vec &elementVector) const
Assemble a local element vector on the element that is bound.
Definition: GridFunctionOperator.hpp:162
void assemble(CG const &contextGeo, RN const &rowNode, CN const &colNode, Mat &elementMatrix) const
Assemble a local element matrix on the element that is bound.
Definition: GridFunctionOperator.hpp:148
void unbind()
Unbinds operator from element.
Definition: GridFunctionOperator.hpp:137
The main implementation of an operator depending on a grid-function.
Definition: GridFunctionOperator.hpp:39
GridFunctionOperator(GridFct &&gridFct, Impl &&impl, int derivDeg, int gridFctOrder)
Constructor. Stores a copy of gridFct and impl.
Definition: GridFunctionOperator.hpp:50
decltype(auto) makeGridFunction(PreGridFct const &preGridFct, GridView const &gridView)
Generator for Gridfunctions from Expressions (PreGridfunctions)
Definition: GridFunction.hpp:168
auto makeOperator(Tag const &tag, Expr &&expr, int gridFctDeg=-1)
Definition: GridFunctionOperator.hpp:235
Registry to specify a tag for each implementation type.
Definition: GridFunctionOperator.hpp:216
Definition: GridFunctionOperator.hpp:220