5#include <dune/common/diagonalmatrix.hh>
6#include <dune/common/fmatrix.hh>
7#include <dune/common/fvector.hh>
8#include <dune/common/typetraits.hh>
10#include <amdis/common/TypeTraits.hpp>
14 template <
class T,
int N>
15 struct common_type<Dune::FieldVector<T,N>, T>
20 template <
class T,
int N,
int M>
21 struct common_type<Dune::FieldMatrix<T,N,M>, T>
34 struct IsMatrix : std::false_type {};
36 template <
class T,
int M,
int N>
37 struct IsMatrix<FieldMatrix<T,M,N>> : std::true_type {};
39 template <
class T,
int N>
40 struct IsMatrix<DiagonalMatrix<T,N>> : std::true_type {};
43 struct IsScalarMatrix : std::false_type {};
46 struct IsScalarMatrix<FieldMatrix<T,1,1>> : std::true_type {};
49 struct IsScalarMatrix<DiagonalMatrix<T,1>> : std::true_type {};
53 struct IsVector : std::false_type {};
55 template <
class T,
int N>
56 struct IsVector<FieldVector<T,N>> : std::true_type {};
59 struct IsScalarVector : std::false_type {};
62 struct IsScalarVector<FieldVector<T,1>> : std::true_type {};
68 : std::integral_constant<bool, IsMatrix<T>::value || IsVector<T>::value> {};
73 template <
class A,
class S>
79 template <
class T,
int M,
int N,
class S>
80 struct MakeMatVec<FieldMatrix<T,M,N>,S>
82 using type = FieldMatrix<S,M,N>;
85 template <
class T,
int N,
class S>
86 struct MakeMatVec<DiagonalMatrix<T,N>,S>
88 using type = DiagonalMatrix<S,N>;
91 template <
class T,
int N,
class S>
92 struct MakeMatVec<FieldVector<T,N>,S>
94 using type = FieldVector<S,N>;
101 decltype(
auto) as_scalar(T&& t)
107 T as_scalar(FieldVector<T,1>
const& t)
113 T as_scalar(FieldMatrix<T,1,1>
const& t)
119 T as_scalar(DiagonalMatrix<T,1>
const& t)
121 return t.diagonal(0);
128 decltype(
auto) as_vector(T&& t)
133 template <
class T,
int N>
134 FieldVector<T,N>
const& as_vector(FieldMatrix<T,1,N>
const& t)
139 template <
class T,
int N>
140 FieldVector<T,N>& as_vector(FieldMatrix<T,1,N>& t)
150 decltype(
auto) as_matrix(T&& t)
158 template <
class T,
int N>
159 MatrixView<DiagonalMatrix<T,N>> as_matrix(DiagonalMatrix<T,N>
const& mat)
167 auto negate(A
const& a);
170 template <
class A,
class B>
171 auto plus(A
const& a, B
const& b);
174 template <
class A,
class B>
175 auto minus(A
const& a, B
const& b);
178 template <
class A,
class B,
179 std::enable_if_t<IsNumber<A>::value && IsNumber<B>::value,
int> = 0>
180 auto multiplies(A
const& a, B
const& b);
182 template <
class A,
class B,
183 std::enable_if_t<IsNumber<A>::value != IsNumber<B>::value,
int> = 0>
184 auto multiplies(A
const& a, B
const& b);
186 template <
class T,
int N,
class S>
187 auto multiplies(FieldVector<T,N>
const& a, FieldVector<S,N>
const& b);
189 template <
class Mat,
class Vec,
190 std::enable_if_t<IsMatrix<Mat>::value && IsVector<Vec>::value,
int> = 0>
191 auto multiplies(Mat
const& mat, Vec
const& vec);
193 template <
class Vec,
class Mat,
194 std::enable_if_t<IsVector<Vec>::value && IsMatrix<Mat>::value,
int> = 0>
195 auto multiplies(Vec
const& vec, Mat
const& mat);
197 template <
class T,
int L,
int M,
int N,
class S>
198 auto multiplies(FieldMatrix<T,L,M>
const& a, FieldMatrix<S,M,N>
const& b);
201 template <
class A,
class B>
202 auto divides(A a, B
const& b)
212 std::enable_if_t<MatVec::IsMatVec<A>::value,
int> = 0>
213 auto operator-(A
const& a)
215 return MatVec::negate(MatVec::as_scalar(a));
218 template <
class A,
class B,
219 std::enable_if_t<MatVec::IsMatVec<A>::value || MatVec::IsMatVec<B>::value,
int> = 0>
220 auto operator+(A
const& a, B
const& b)
222 return MatVec::plus(MatVec::as_scalar(a), MatVec::as_scalar(b));
225 template <
class A,
class B,
226 std::enable_if_t<MatVec::IsMatVec<A>::value || MatVec::IsMatVec<B>::value,
int> = 0>
227 auto operator-(A
const& a, B
const& b)
229 return MatVec::minus(MatVec::as_scalar(a), MatVec::as_scalar(b));
232 template <
class A,
class B,
233 std::enable_if_t<MatVec::IsMatVec<A>::value || MatVec::IsMatVec<B>::value,
int> = 0>
234 auto operator*(A
const& a, B
const& b)
236 return MatVec::multiplies(MatVec::as_scalar(a), MatVec::as_scalar(b));
239 template <
class A,
class B,
240 std::enable_if_t<MatVec::IsMatVec<A>::value || MatVec::IsMatVec<B>::value,
int> = 0>
241 auto operator/(A
const& a, B
const& b)
243 return MatVec::divides(MatVec::as_scalar(a), MatVec::as_scalar(b));
250 FieldVector<T, 2> cross(FieldVector<T, 2>
const& a);
254 FieldVector<T, 3> cross(FieldVector<T, 3>
const& a, FieldVector<T, 3>
const& b);
257 template <
class T,
class S,
int N>
258 auto dot(FieldVector<T,N>
const& vec1, FieldVector<S,N>
const& vec2);
260 template <
class T,
class S,
int N>
261 auto dot(FieldMatrix<T,1,N>
const& vec1, FieldMatrix<S,1,N>
const& vec2);
266 template <
class T,
int N>
267 T sum(FieldVector<T, N>
const& x);
269 template <
class T,
int N>
270 T sum(FieldMatrix<T, 1, N>
const& x);
275 std::enable_if_t<Dune::IsNumber<T>::value,
int> = 0>
276 auto unary_dot(T
const& x);
278 template <
class T,
int N>
279 auto unary_dot(FieldVector<T, N>
const& x);
281 template <
class T,
int N>
282 auto unary_dot(FieldMatrix<T, 1, N>
const& x);
285 template <
class T,
int N>
286 auto max(FieldVector<T, N>
const& x);
288 template <
class T,
int N>
289 auto max(FieldMatrix<T, 1, N>
const& x);
292 template <
class T,
int N>
293 auto min(FieldVector<T, N>
const& x);
295 template <
class T,
int N>
296 auto min(FieldMatrix<T, 1, N>
const& x);
299 template <
class T,
int N>
300 auto abs_max(FieldVector<T, N>
const& x);
302 template <
class T,
int N>
303 auto abs_max(FieldMatrix<T, 1, N>
const& x);
306 template <
class T,
int N>
307 auto abs_min(FieldVector<T, N>
const& x);
309 template <
class T,
int N>
310 auto abs_min(FieldMatrix<T, 1, N>
const& x);
317 template <
class T,
int N>
318 auto one_norm(FieldVector<T, N>
const& x);
320 template <
class T,
int N>
321 auto one_norm(FieldMatrix<T, 1, N>
const& x);
327 std::enable_if_t<Dune::IsNumber<T>::value,
int> = 0>
328 auto two_norm(T
const& x);
330 template <
class T,
int N>
331 auto two_norm(FieldVector<T, N>
const& x);
333 template <
class T,
int N>
334 auto two_norm(FieldMatrix<T, 1, N>
const& x);
339 template <
int p,
class T,
int N>
340 auto p_norm(FieldVector<T, N>
const& x);
342 template <
int p,
class T,
int N>
343 auto p_norm(FieldMatrix<T, 1, N>
const& x);
348 template <
class T,
int N>
349 auto infty_norm(FieldVector<T, N>
const& x);
351 template <
class T,
int N>
352 auto infty_norm(FieldMatrix<T, 1, N>
const& x);
358 std::enable_if_t<Dune::IsNumber<T>::value,
int> = 0>
359 T distance(T
const& lhs, T
const& rhs);
361 template <
class T,
int N>
362 T distance(FieldVector<T, N>
const& lhs, FieldVector<T, N>
const& rhs);
367 template <
class T,
class S,
int N,
int M,
int K>
368 auto outer(FieldMatrix<T,N,K>
const& vec1, FieldMatrix<S,M,K>
const& vec2);
370 template <
class T,
class S,
int N,
int M>
371 auto outer(FieldVector<T,N>
const& vec1, FieldVector<S,M>
const& vec2);
376 T det(FieldMatrix<T, 0, 0>
const& );
380 T det(FieldMatrix<T, 1, 1>
const& mat);
384 T det(FieldMatrix<T, 2, 2>
const& mat);
388 T det(FieldMatrix<T, 3, 3>
const& mat);
391 template <
class T,
int N>
392 T det(FieldMatrix<T, N, N>
const& mat);
396 template <
class T,
int N>
397 auto inv(FieldMatrix<T, N, N> mat);
400 template <
class T,
int N>
401 void solve(FieldMatrix<T, N, N>
const& A, FieldVector<T, N>& x, FieldVector<T, N>
const& b);
405 template <
class T,
int N,
int M>
406 T gramian(FieldMatrix<T,N,M>
const& DF);
409 template <
class T,
int M>
410 T gramian(FieldMatrix<T, 1, M>
const& DF);
415 template <
class T,
int M,
int N>
416 FieldMatrix<T,N,M> trans(FieldMatrix<T, M, N>
const& A);
418 template <
class T,
int N>
419 DiagonalMatrix<T,N>
const& trans(DiagonalMatrix<T,N>
const& A)
426 template <
class T1,
class T2,
int M,
int N,
int L>
427 FieldMatrix<std::common_type_t<T1,T2>,M,N> multiplies_AtB(FieldMatrix<T1, L, M>
const& A, FieldMatrix<T2, N, L>
const& B);
429 template <
class T1,
class T2,
int M,
int N,
int L>
430 FieldMatrix<std::common_type_t<T1,T2>,M,N> multiplies_ABt(FieldMatrix<T1, M, L>
const& A, FieldMatrix<T2, N, L>
const& B);
433 template <
class T1,
class T2,
class T3,
int M,
int N,
int L>
434 FieldMatrix<T3,M,N>& multiplies_ABt(FieldMatrix<T1, M, L>
const& A, FieldMatrix<T2, N, L>
const& B, FieldMatrix<T3,M,N>& C);
436 template <
class T1,
class T2,
class T3,
int N,
int L>
437 FieldVector<T3,N>& multiplies_ABt(FieldMatrix<T1, 1, L>
const& A, FieldMatrix<T2, N, L>
const& B, FieldVector<T3,N>& C);
439 template <
class T1,
class T2,
class T3,
int N,
int L>
440 FieldVector<T3,N>& multiplies_ABt(FieldVector<T1, L>
const& A, FieldMatrix<T2, N, L>
const& B, FieldVector<T3,N>& C);
442 template <
class T1,
class T2,
class T3,
int N,
int L>
443 FieldMatrix<T3,1,N>& multiplies_ABt(FieldVector<T1, L>
const& A, FieldMatrix<T2, N, L>
const& B, FieldMatrix<T3,1,N>& C);
446 template <
class T1,
class T2,
class T3,
int M,
int N>
447 FieldMatrix<T3,M,N>& multiplies_ABt(FieldMatrix<T1, M, N>
const& A, DiagonalMatrix<T2, N>
const& B, FieldMatrix<T3,M,N>& C);
449 template <
class T1,
class T2,
class T3,
int N>
450 FieldVector<T3,N>& multiplies_ABt(FieldMatrix<T1, 1, N>
const& A, DiagonalMatrix<T2, N>
const& B, FieldVector<T3,N>& C);
452 template <
class T1,
class T2,
class T3,
int N>
453 FieldVector<T3,N>& multiplies_ABt(FieldVector<T1, N>
const& A, DiagonalMatrix<T2, N>
const& B, FieldVector<T3,N>& C);
455 template <
class T1,
class T2,
class T3,
int N>
456 FieldMatrix<T3,1,N>& multiplies_ABt(FieldVector<T1, N>
const& A, DiagonalMatrix<T2, N>
const& B, FieldMatrix<T3,1,N>& C);
460 template <
class T,
int N>
461 T
const& at(FieldMatrix<T,N,1>
const& vec, std::size_t i);
463 template <
class T,
int M>
464 T
const& at(FieldMatrix<T,1,M>
const& vec, std::size_t i);
468 T
const& at(FieldMatrix<T,1,1>
const& vec, std::size_t i);
470 template <
class T,
int N>
471 T
const& at(FieldVector<T,N>
const& vec, std::size_t i);
477 using Dune::FieldMatrix;
478 using Dune::FieldVector;
481#include "FieldMatVec.inc.hpp"