AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
Operations.hpp
1#pragma once
2
3#include <amdis/Operations.hpp>
4#include <amdis/common/FieldMatVec.hpp>
5#include <amdis/gridfunctions/ComposerGridFunction.hpp>
6#include <amdis/operations/Arithmetic.hpp>
7#include <amdis/operations/FieldMatVec.hpp>
8
9namespace AMDiS
10{
16 // scalar operations
17 // @{
18
20 template <class Lhs,
21 REQUIRES(Concepts::AnyGridFunction<Lhs>)>
22 auto operator-(Lhs&& lhs)
23 {
24 return invokeAtQP(Operation::Negate{}, FWD(lhs));
25 }
26
28 template <class Lhs, class Rhs,
29 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
30 auto operator+(Lhs&& lhs, Rhs&& rhs)
31 {
32 return invokeAtQP(Operation::Plus{}, FWD(lhs), FWD(rhs));
33 }
34
36 template <class Lhs, class Rhs,
37 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
38 auto operator-(Lhs&& lhs, Rhs&& rhs)
39 {
40 return invokeAtQP(Operation::Minus{}, FWD(lhs), FWD(rhs));
41 }
42
44 template <class Lhs, class Rhs,
45 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
46 auto operator*(Lhs&& lhs, Rhs&& rhs)
47 {
48 if constexpr(Dune::IsNumber<TYPEOF(lhs)>::value)
49 return invokeAtQP(Operation::Scale<TYPEOF(lhs)>{lhs}, FWD(rhs));
50 else if constexpr(Dune::IsNumber<TYPEOF(rhs)>::value)
51 return invokeAtQP(Operation::Scale<TYPEOF(rhs)>{rhs}, FWD(lhs));
52 else
53 return invokeAtQP(Operation::Multiplies{}, FWD(lhs), FWD(rhs));
54 }
55
57 template <class Lhs, class Rhs,
58 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
59 auto operator/(Lhs&& lhs, Rhs&& rhs)
60 {
61 if constexpr(Dune::IsNumber<TYPEOF(rhs)>::value)
62 return invokeAtQP(Operation::Scale<TYPEOF(1.0/rhs)>{1.0/rhs}, FWD(lhs));
63 else
64 return invokeAtQP(Operation::Divides{}, FWD(lhs), FWD(rhs));
65 }
66
67
69 template <class Lhs, class Rhs,
70 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
71 auto max(Lhs&& lhs, Rhs&& rhs)
72 {
73 return invokeAtQP(Operation::Max{}, FWD(lhs), FWD(rhs));
74 }
75
77 template <class Lhs, class Rhs,
78 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
79 auto min(Lhs&& lhs, Rhs&& rhs)
80 {
81 return invokeAtQP(Operation::Min{}, FWD(lhs), FWD(rhs));
82 }
83
85 template <class Lhs, class Rhs,
86 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
87 auto abs_max(Lhs&& lhs, Rhs&& rhs)
88 {
89 return invokeAtQP(Operation::AbsMax{}, FWD(lhs), FWD(rhs));
90 }
91
93 template <class Lhs, class Rhs,
94 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
95 auto abs_min(Lhs&& lhs, Rhs&& rhs)
96 {
97 return invokeAtQP(Operation::AbsMin{}, FWD(lhs), FWD(rhs));
98 }
99
101 template <class V, class T,
102 REQUIRES(Concepts::AnyGridFunction<V>)>
103 auto clamp(V&& v, T const& lo, T const& hi)
104 {
105 return invokeAtQP(Operation::Clamp<T>{lo,hi}, FWD(v));
106 }
107
108 template <class T,
109 REQUIRES(Concepts::AnyGridFunction<T>)>
110 auto abs(T&& value)
111 {
112 return invokeAtQP([](auto const& v) { using std::abs; return abs(v); }, FWD(value));
113 }
114
116 template <class T,
117 REQUIRES(Concepts::AnyGridFunction<T>)>
118 auto tanh(T&& value)
119 {
120 return invokeAtQP(Operation::Tanh{}, FWD(value));
121 }
122
124 template <class T,
125 REQUIRES(Concepts::AnyGridFunction<T>)>
126 auto signum(T&& value)
127 {
128 return invokeAtQP(Operation::Signum{}, FWD(value));
129 }
130
132 template <class T,
133 REQUIRES(Concepts::AnyGridFunction<T>)>
134 auto sqr(T&& value)
135 {
136 return invokeAtQP(Operation::Sqr{}, FWD(value));
137 }
138
140 template <int p, class T,
141 REQUIRES(Concepts::AnyGridFunction<T>)>
142 auto pow(T&& value)
143 {
144 return invokeAtQP(Operation::Pow<p>{}, FWD(value));
145 }
146
148 template <class T,
149 REQUIRES(Concepts::AnyGridFunction<T>)>
150 auto pow(T&& value, double p)
151 {
152 return invokeAtQP(Operation::Power{p}, FWD(value));
153 }
154
156 template <std::size_t I, class T,
157 REQUIRES(Concepts::AnyGridFunction<T>)>
158 auto get(T&& value)
159 {
160 return invokeAtQP(Operation::Get<I>{}, FWD(value));
161 }
162
164 template <class T,
165 REQUIRES(Concepts::AnyGridFunction<T>)>
166 auto get(T&& value, std::size_t i)
167 {
168 return invokeAtQP(Operation::Get_{i}, FWD(value));
169 }
170
172 template <class T>
173 auto constant(T const& value)
174 {
175 return invokeAtQP(Operation::Constant{value});
176 }
177
179 template <class T>
180 auto reference(T& value)
181 {
182 return invokeAtQP(Operation::Reference{value});
183 }
184
185 // @}
186
187 // unary vector operations
188 // @{
189
191 template <class Vec,
192 REQUIRES(Concepts::AnyGridFunction<Vec>)>
193 auto sum(Vec&& vec)
194 {
195 return invokeAtQP([](auto const& v) { return sum(v); }, FWD(vec));
196 }
197
199 template <class Vec,
200 REQUIRES(Concepts::AnyGridFunction<Vec>)>
201 auto unary_dot(Vec&& vec)
202 {
203 return invokeAtQP(Operation::UnaryDot{}, FWD(vec));
204 }
205
207 template <class Vec,
208 REQUIRES(Concepts::AnyGridFunction<Vec>)>
209 auto one_norm(Vec&& vec)
210 {
211 return invokeAtQP([](auto const& v) { return one_norm(v); }, FWD(vec));
212 }
213
215 template <class Vec,
216 REQUIRES(Concepts::AnyGridFunction<Vec>)>
217 auto two_norm(Vec&& vec)
218 {
219 return invokeAtQP(Operation::TwoNorm{}, FWD(vec));
220 }
221
223 template <int p, class Vec,
224 REQUIRES(Concepts::AnyGridFunction<Vec>)>
225 auto p_norm(Vec&& vec)
226 {
227 return invokeAtQP([](auto const& v) { return p_norm<p>(v); }, FWD(vec));
228 }
229
231 template <class Vec,
232 REQUIRES(Concepts::AnyGridFunction<Vec>)>
233 auto infty_norm(Vec&& vec)
234 {
235 return invokeAtQP([](auto const& v) { return infty_norm(v); }, FWD(vec));
236 }
237
239 template <class Mat,
240 REQUIRES(Concepts::AnyGridFunction<Mat>)>
241 auto trans(Mat&& mat)
242 {
243 return invokeAtQP(Operation::Trans{}, FWD(mat));
244 }
245
246 // @}
247
248
249 // binary vector operations
250 // @{
251
253 template <class Lhs, class Rhs,
254 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
255 auto dot(Lhs&& lhs, Rhs&& rhs)
256 {
257 return invokeAtQP(Operation::Dot{},
258 FWD(lhs), FWD(rhs));
259 }
260
262 template <class Lhs, class Rhs,
263 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
264 auto distance(Lhs&& lhs, Rhs&& rhs)
265 {
266 using namespace Operation;
267 return invokeAtQP(compose(TwoNorm{}, Minus{}),
268 FWD(lhs), FWD(rhs));
269 }
270
272 template <class Lhs, class Rhs,
273 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
274 auto outer(Lhs&& lhs, Rhs&& rhs)
275 {
276 return invokeAtQP([](auto const& v, auto const& w) { return outer(v,w); },
277 FWD(lhs), FWD(rhs));
278 }
279
281 template <class Lhs, class Rhs,
282 REQUIRES(Concepts::AnyGridFunction<Lhs,Rhs>)>
283 auto cross(Lhs&& lhs, Rhs&& rhs)
284 {
285 return invokeAtQP([](auto const& v, auto const& w) { return Dune::cross(v,w); },
286 FWD(lhs), FWD(rhs));
287 }
288
289 // @}
290
293} // end namespace AMDiS
auto pow(T &&value, double p)
Applies Operation::Power to GridFunction.
Definition: Operations.hpp:150
auto one_norm(Vec &&vec)
Applies a one_norm() functor to a vector-valued GridFunction.
Definition: Operations.hpp:209
auto trans(Mat &&mat)
Applies Operation::Trans to a matrix-valued GridFunction.
Definition: Operations.hpp:241
auto sum(Vec &&vec)
Applies a sum() functor to a vector-valued GridFunction.
Definition: Operations.hpp:193
auto cross(Lhs &&lhs, Rhs &&rhs)
Applies a cross() functor to two vector-valued GridFunctions.
Definition: Operations.hpp:283
auto signum(T &&value)
Applies Operation::Signum to GridFunctions.
Definition: Operations.hpp:126
auto abs_max(Lhs &&lhs, Rhs &&rhs)
Applies Operation::AbsMax to GridFunctions.
Definition: Operations.hpp:87
auto two_norm(Vec &&vec)
Applies Operation::TwoNorm to a vector-valued GridFunction.
Definition: Operations.hpp:217
auto dot(Lhs &&lhs, Rhs &&rhs)
Applies Operation::Dot to two vector-valued GridFunctions.
Definition: Operations.hpp:255
auto get(T &&value, std::size_t i)
Applies Operation::Get_ to GridFunction.
Definition: Operations.hpp:166
auto abs_min(Lhs &&lhs, Rhs &&rhs)
Applies Operation::AbsMin to GridFunctions.
Definition: Operations.hpp:95
auto distance(Lhs &&lhs, Rhs &&rhs)
Applies a distance-functor to two vector-valued GridFunctions.
Definition: Operations.hpp:264
auto tanh(T &&value)
Applies Operation::Tanh to GridFunctions.
Definition: Operations.hpp:118
auto pow(T &&value)
Applies Operation::Pow.
Definition: Operations.hpp:142
auto operator-(Lhs &&lhs, Rhs &&rhs)
Applies Operation::Minus to GridFunctions.
Definition: Operations.hpp:38
auto reference(T &value)
Return a reference-wrapper as GridFunction.
Definition: Operations.hpp:180
auto clamp(V &&v, T const &lo, T const &hi)
Applies Operation::Clamp to GridFunction.
Definition: Operations.hpp:103
auto operator+(Lhs &&lhs, Rhs &&rhs)
Applies Operation::Plus to GridFunctions.
Definition: Operations.hpp:30
auto min(Lhs &&lhs, Rhs &&rhs)
Applies Operation::Min to GridFunctions.
Definition: Operations.hpp:79
auto unary_dot(Vec &&vec)
Applies Operation::UnaryDot to a vector-valued GridFunction.
Definition: Operations.hpp:201
auto get(T &&value)
Applies Operation::Get<I> to GridFunction.
Definition: Operations.hpp:158
auto outer(Lhs &&lhs, Rhs &&rhs)
Applies an outer() functor to two vector-valued GridFunctions.
Definition: Operations.hpp:274
auto infty_norm(Vec &&vec)
Applies a infty_norm() functor to a vector-valued GridFunction.
Definition: Operations.hpp:233
auto max(Lhs &&lhs, Rhs &&rhs)
Applies Operation::Max to GridFunctions.
Definition: Operations.hpp:71
auto operator-(Lhs &&lhs)
Applies Operation::Negate to GridFunctions.
Definition: Operations.hpp:22
auto operator/(Lhs &&lhs, Rhs &&rhs)
Applies Operation::Divides to GridFunctions.
Definition: Operations.hpp:59
auto constant(T const &value)
Return a reference-wrapper as GridFunction.
Definition: Operations.hpp:173
auto p_norm(Vec &&vec)
Applies a p_norm() functor to a vector-valued GridFunction.
Definition: Operations.hpp:225
auto sqr(T &&value)
Applies Operation::Sqr to GridFunction.
Definition: Operations.hpp:134
auto operator*(Lhs &&lhs, Rhs &&rhs)
Applies Operation::Multiplies to GridFunctions.
Definition: Operations.hpp:46
Operation that represents max(|A|,|B|)
Definition: MaxMin.hpp:33
Operation that represents min(|A|,|B|)
Definition: MaxMin.hpp:46
Definition: CMath.hpp:111
Functor representing a constant value.
Definition: Basic.hpp:88
Functor that represents A/B.
Definition: Arithmetic.hpp:188
(Binary-)Functor representing the euclidean dot-product
Definition: FieldMatVec.hpp:19
Definition: Basic.hpp:203
Definition: Basic.hpp:189
Operation that represents max(A,B)
Definition: MaxMin.hpp:9
Operation that represents min(A,B)
Definition: MaxMin.hpp:21
Functor that represents A-B.
Definition: Arithmetic.hpp:62
Functor that represents A*B.
Definition: Arithmetic.hpp:101
Functor that represents A-B.
Definition: Arithmetic.hpp:209
Functor that represents A+B.
Definition: Arithmetic.hpp:20
Functor that represents x^p,.
Definition: Arithmetic.hpp:322
Functor representing a constant value.
Definition: Basic.hpp:120
Functor that represents f*A.
Definition: Arithmetic.hpp:148
Functor that represents the signum function.
Definition: CMath.hpp:48
Definition: FieldMatVec.hpp:86
(Unary-)Functor representing the euclidean 2-norm
Definition: FieldMatVec.hpp:70
(Unary-)Functor representing the euclidean dot-product
Definition: FieldMatVec.hpp:46