DUNE-ACFEM (2.5.1)

gridfunctionwrapperexpression.hh
1#ifndef __DUNE_ACFEM_GRIDFUNCTIONWRAPPEREXPRESSION_HH__
2#define __DUNE_ACFEM_GRIDFUNCTIONWRAPPEREXPRESSION_HH__
3
4#include "../functions/gridfunctionwrapper.hh"
5#include "../functions/functionexpression.hh"
6#include "../functions/gridfunctionexpressionbase.hh"
7#include "../expressions/parameterexpression.hh"
8
9namespace Dune
10{
11
12 namespace ACFem
13 {
14
44 // forward
45 template<class UnOp, class Function>
46 class UnaryGridFunctionExpression;
47
48 // forward
49 template<class BinOp, class LeftFunction, class RightFunction>
50 class BinaryGridFunctionExpression;
51
52 namespace {
53
55 template<class GridFunction, class GridPart>
56 struct EssGridFunction
57 {
58 typedef GridFunctionWrapper<GridFunction, GridPart> WrappedFunctionType;
59 enum {
60 hasLocalFunction = std::is_base_of<Fem::HasLocalFunction, GridFunction>::value
61 };
62
63 template<bool hasLF, class dummy = void>
64 struct Helper;
65
66 template<class dummy>
67 struct Helper<true, dummy>
68 {
69 typedef GridFunction FunctionType;
70 static const FunctionType& construct(const WrappedFunctionType& arg)
71 {
72 return arg.function();
73 }
74 };
75
76 template<class dummy>
77 struct Helper<false, dummy>
78 {
79 typedef WrappedFunctionType FunctionType;
80 static const FunctionType& construct(const WrappedFunctionType& arg)
81 {
82 return arg;
83 }
84 };
85
86 typedef Helper<hasLocalFunction> HelperType;
87 typedef typename HelperType::FunctionType FunctionType;
88 static const FunctionType& construct(const WrappedFunctionType& arg)
89 {
90 return HelperType::construct(arg);
91 }
92 };
93
95 template<class GridFunction, class GridPart>
96 const typename EssGridFunction<GridFunction, GridPart>::FunctionType&
97 asEssGridFct(const GridFunctionWrapper<GridFunction, GridPart>& arg)
98 {
99 return EssGridFunction<GridFunction, GridPart>::construct(arg);
100 }
101
104 template<class GridFunction, class GridPart>
105 auto
106 asExprArg(const GridFunctionWrapper<GridFunction, GridPart>& arg)
107 -> decltype(asExprFunction(asEssGridFct(arg)))
108 {
109 return asExprFunction(asEssGridFct(arg));
110 }
111
112 }
113
115 template<class Function, class GridPart>
116 static inline
118 -> GridFunctionWrapper<decltype(-asExprArg(f_)), GridPart>
119 {
120 typedef decltype(-asExprArg(f_)) InnerExpressionType;
121 typedef GridPart GridPartType;
123
124 auto inner(-asExprArg(f_));
125
126 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
127 }
128
130 template<class Function, class GridPart>
131 static inline
134 {
135 return f_;
136 }
137
139 template<class Left, class Right, class GridPart>
140 static inline
141 auto operator+(const GridFunctionWrapper<Left, GridPart>& f_,
143 -> GridFunctionWrapper<decltype(asExprArg(f_) + asExprArg(g_)), GridPart>
144 {
145 typedef decltype(asExprArg(f_) + asExprArg(g_)) InnerExpressionType;
146 typedef GridPart GridPartType;
148
149 auto inner(asExprArg(f_) + asExprArg(g_));
150
151 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
152 }
153
155 template<class Left, class Right, class GridPart>
156 static inline
157 auto operator-(const GridFunctionWrapper<Left, GridPart>& f_,
159 -> GridFunctionWrapper<decltype(asExprArg(f_) - asExprArg(g_)), GridPart>
160 {
161 typedef decltype(asExprArg(f_) - asExprArg(g_)) InnerExpressionType;
162 typedef GridPart GridPartType;
164
165 auto inner(asExprArg(f_) - asExprArg(g_));
166
167 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
168 }
169
171 template<class Function, class GridPart>
172 static inline
173 auto operator*(const typename Function::RangeFieldType& s_,
175 -> GridFunctionWrapper<decltype(s_ * asExprArg(f_)), GridPart>
176 {
177 typedef decltype(s_ * asExprArg(f_)) InnerExpressionType;
178 typedef GridPart GridPartType;
180
181 auto inner(s_ * asExprArg(f_));
182
183 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
184 }
185
187 template<class Function, class GridPart>
188 static inline
190 const typename Function::RangeFieldType& s_)
191 -> decltype(s_ * f_)
192 {
193 return s_ * f_;
194 }
195
197 template<class Parameter, class Function, class GridPart>
198 static inline
201 -> GridFunctionWrapper<decltype(asImp(p_) * asExprArg(f_)), GridPart>
202 {
203 typedef decltype(asImp(p_) * asExprArg(f_)) InnerExpressionType;
204 typedef GridPart GridPartType;
206
207 auto inner(asImp(p_) * asExprArg(f_));
208
209 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
210 }
211
213 template<class Parameter, class Function, class GridPart>
214 static inline
217 -> decltype(asImp(p_) * f_)
218 {
219 return asImp(p_) * f_;
220 }
221
223 template<class Field, class Parameter, class Function, class GridPart>
224 static inline
225 auto operator*(const BinaryParameterExpression<SMultiplyOperation, Field, Parameter>& p_,
227 -> decltype(p_.left() * (p_.right() * f_))
228 {
229 return p_.left() * (p_.right() * f_);
230 }
231
233 template<class Left, class Right, class GridPart>
234 static inline
237 -> GridFunctionWrapper<decltype(asExprArg(f_) * asExprArg(g_)), GridPart>
238 {
239 typedef decltype(asExprArg(f_) * asExprArg(g_)) InnerExpressionType;
240 typedef GridPart GridPartType;
242
243 auto inner(asExprArg(f_) * asExprArg(g_));
244
245 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
246 }
247
249 template<class Left, class Right, class GridPart>
250 static inline
253 -> GridFunctionWrapper<decltype(asExprArg(f_) / asExprArg(g_)), GridPart>
254 {
255 typedef decltype(asExprArg(f_) / asExprArg(g_)) InnerExpressionType;
256 typedef GridPart GridPartType;
258
259 auto inner(asExprArg(f_) / asExprArg(g_));
260
261 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
262 }
263
265 template<class Function, class GridPart>
266 static inline
267 auto operator/(const typename Function::RangeFieldType& s_,
269 -> GridFunctionWrapper<decltype(s_ / asExprArg(f_)), GridPart>
270 {
271 typedef decltype(s_ / asExprArg(f_)) InnerExpressionType;
272 typedef GridPart GridPartType;
274
275 auto inner(s_ / asExprArg(f_));
276
277 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
278 }
279
281 template<class Parameter, class Function, class GridPart>
282 static inline
285 -> GridFunctionWrapper<decltype(asImp(p_) / asExprArg(f_)), GridPart>
286 {
287 typedef decltype(asImp(p_) / asExprArg(f_)) InnerExpressionType;
288 typedef GridPart GridPartType;
290
291 auto inner(asImp(p_) / asExprArg(f_));
292
293 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
294 }
295
297 template<class Function, class GridPart>
298 static inline
300 -> GridFunctionWrapper<decltype(exp(asExprArg(f_))), GridPart>
301 {
302 typedef decltype(exp(asExprArg(f_))) InnerExpressionType;
303 typedef GridFunctionWrapper<decltype(exp(asExprArg(f_))), GridPart> ExpressionType;
304
305 auto inner(exp(asExprArg(f_)));
306
307 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
308 }
309
311 template<class Function, class GridPart>
312 static inline
314 -> GridFunctionWrapper<decltype(log(asExprArg(f_))), GridPart>
315 {
316 typedef decltype(log(asExprArg(f_))) InnerExpressionType;
317 typedef GridFunctionWrapper<decltype(log(asExprArg(f_))), GridPart> ExpressionType;
318
319 auto inner(log(asExprArg(f_)));
320
321 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
322 }
323
325 template<class Function, class GridPart>
326 static inline
328 -> GridFunctionWrapper<decltype(sqrt(asExprArg(f_))), GridPart>
329 {
330 typedef decltype(sqrt(asExprArg(f_))) InnerExpressionType;
331 typedef GridFunctionWrapper<decltype(sqrt(asExprArg(f_))), GridPart> ExpressionType;
332
333 auto inner(sqrt(asExprArg(f_)));
334
335 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
336 }
337
339 template<class Function, class GridPart>
340 static inline
342 -> GridFunctionWrapper<decltype(sqr(asExprArg(f_))), GridPart>
343 {
344 typedef decltype(sqr(asExprArg(f_))) InnerExpressionType;
345 typedef GridFunctionWrapper<decltype(sqr(asExprArg(f_))), GridPart> ExpressionType;
346
347 auto inner(sqr(asExprArg(f_)));
348
349 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
350 }
351
353 template<class Function, class GridPart>
354 static inline
356 -> GridFunctionWrapper<decltype(sin(asExprArg(f_))), GridPart>
357 {
358 typedef decltype(sin(asExprArg(f_))) InnerExpressionType;
359 typedef GridFunctionWrapper<decltype(sin(asExprArg(f_))), GridPart> ExpressionType;
360
361 auto inner(sin(asExprArg(f_)));
362
363 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
364 }
365
367 template<class Function, class GridPart>
368 static inline
370 -> GridFunctionWrapper<decltype(cos(asExprArg(f_))), GridPart>
371 {
372 typedef decltype(cos(asExprArg(f_))) InnerExpressionType;
373 typedef GridFunctionWrapper<decltype(cos(asExprArg(f_))), GridPart> ExpressionType;
374
375 auto inner(cos(asExprArg(f_)));
376
377 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
378 }
379
381 template<class Function, class GridPart>
382 static inline
384 -> GridFunctionWrapper<decltype(tan(asExprArg(f_))), GridPart>
385 {
386 typedef decltype(tan(asExprArg(f_))) InnerExpressionType;
387 typedef GridFunctionWrapper<decltype(tan(asExprArg(f_))), GridPart> ExpressionType;
388
389 auto inner(tan(asExprArg(f_)));
390
391 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
392 }
393
395 template<class Function, class GridPart>
396 static inline
398 -> GridFunctionWrapper<decltype(atan(asExprArg(f_))), GridPart>
399 {
400 typedef decltype(atan(asExprArg(f_))) InnerExpressionType;
401 typedef GridFunctionWrapper<decltype(atan(asExprArg(f_))), GridPart> ExpressionType;
402
403 auto inner(atan(asExprArg(f_)));
404
405 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
406 }
407
409 template<class Function, class GridPart>
410 static inline
412 -> GridFunctionWrapper<decltype(asin(asExprArg(f_))), GridPart>
413 {
414 typedef decltype(asin(asExprArg(f_))) InnerExpressionType;
415 typedef GridFunctionWrapper<decltype(asin(asExprArg(f_))), GridPart> ExpressionType;
416
417 auto inner(asin(asExprArg(f_)));
418
419 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
420 }
421
423 template<class Function, class GridPart>
424 static inline
426 -> GridFunctionWrapper<decltype(acos(asExprArg(f_))), GridPart>
427 {
428 typedef decltype(acos(asExprArg(f_))) InnerExpressionType;
429 typedef GridFunctionWrapper<decltype(acos(asExprArg(f_))), GridPart> ExpressionType;
430
431 auto inner(acos(asExprArg(f_)));
432
433 return ExpressionType(inner.name(), inner, f_.gridPart(), inner.space().order());
434 }
435
437
439
441
443
444 } // ACFem::
445
446} // Dune::
447
448#endif // __DUNE_ACFEM_GRIDFUNCTIONWRAPPEREXPRESSION_HH__
A special version of Fem::GridFunctionAdapter which stores a copy to the function,...
Definition: gridfunctionwrapper.hh:51
Parameters are quasi-constant quantities, like the time-step size in one time-step when solving trans...
Definition: parameterinterface.hh:80
static auto operator/(const Fem::Function< typename Left::FunctionSpaceType, Left > &f_, const BoundarySupportedFunction< Right, RightInd > &g_) -> decltype(asBndryFct(asEssBndryFct(f_/asExprArg(g_))))
f / Wrapped(g) = Wrapped(f / g)
Definition: boundaryfunctionexpression.hh:657
const Implementation & asImp(const Fem::BartonNackmanInterface< Interface, Implementation > &arg)
Up-cast to the implementation for any Fem::BartonNackmanInterface.
Definition: expressionoperations.hh:71
static UnaryGridFunctionExpression< LogOperation, Function > log(const Fem::Function< typename Function::FunctionSpaceType, Function > &f_)
Component-wise logarithm, log(f)(x) = [log(f(x)_0),...,log(f(x)_N].
Definition: gridfunctionexpression.hh:2844
static const Fem::Function< typename GridFunction::FunctionSpaceType, GridFunction > & asExprFunction(const GridFunction &arg)
Cast to the proper underlying expression class; for the generic case this is just the underlying Fem:...
Definition: gridfunctionexpression.hh:61
BinaryParameterExpression< MultiplyOperation, Left, Right > operator*(const ParameterInterface< Left > &left, const ParameterInterface< Right > &right)
Scalar product between parameters.
Definition: parameterexpression.hh:321
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 12, 23:28, 2025)