FieldMatVec.hpp 7.66 KB
Newer Older
1
2
#pragma once

3
#include <dune/common/diagonalmatrix.hh>
4
5
6
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>

7
#include <amdis/common/ConceptsBase.hpp>
8
#include <amdis/common/ScalarTypes.hpp>
9
10
11

namespace AMDiS
{
Praetorius, Simon's avatar
Praetorius, Simon committed
12
13
14
15
  using Dune::FieldVector;
  using Dune::FieldMatrix;

  // some arithmetic operations with FieldVector
16
17
18

  template <class T, int N, class S,
    REQUIRES(Concepts::Arithmetic<S>) >
19
  FieldVector<T,N> operator*(FieldVector<T,N> v, S factor);
20
21
22

  template <class S, class T, int N,
    REQUIRES(Concepts::Arithmetic<S>) >
23
  FieldVector<T,N> operator*(S factor, FieldVector<T,N> v);
24
25
26

  template <class T, int N, class S,
    REQUIRES(Concepts::Arithmetic<S>) >
27
  FieldVector<T,N> operator/(FieldVector<T,N> v, S factor);
28

29
  template <class T>
30
  FieldVector<T,1> operator*(FieldVector<T,1> const& v, FieldVector<T,1> const& w);
31

32
  template <class T, int N>
33
  FieldVector<T,N> operator*(FieldVector<T,1> const& factor, FieldVector<T,N> v);
34

35
  template <class T, int N>
36
  FieldVector<T,N> operator*(FieldVector<T,N> v, FieldVector<T,1> const& factor);
37

38
39
40
41
  // ----------------------------------------------------------------------------

  /// Cross-product a 2d-vector = orthogonal vector
  template <class T>
42
  FieldVector<T, 2> cross(FieldVector<T, 2> const& a);
43

44
  /// Cross-product of two 3d-vectors
45
  template <class T>
46
  FieldVector<T, 3> cross(FieldVector<T, 3> const& a, FieldVector<T, 3> const& b);
47
48
49

  /// Dot product (vec1^T * vec2)
  template <class T, class S, int N>
50
  auto dot(FieldVector<T,N> const& vec1, FieldVector<S,N> const& vec2);
51

52
53
  template <class T, int N, int M,
    REQUIRES( N!=1 && M!=1 )>
54
  auto operator*(FieldVector<T,N> const& v, FieldVector<T,M> const& w);
55

56
57
58
  template <class T, class S, int N>
  auto dot(FieldMatrix<T,1,N> const& vec1, FieldMatrix<S,1,N> const& vec2);

59
60
61
62
  // ----------------------------------------------------------------------------

  /// Sum of vector entires.
  template <class T, int N>
63
  T sum(FieldVector<T, N> const& x);
64

65
  template <class T, int N>
66
  T sum(FieldMatrix<T, 1, N> const& x);
67

68
69
70

  /// Dot-product with the vector itself
  template <class T, int N>
71
  auto unary_dot(FieldVector<T, N> const& x);
72

73
  template <class T, int N>
74
  auto unary_dot(FieldMatrix<T, 1, N> const& x);
75

76
77
  /// Maximum over all vector entries
  template <class T, int N>
78
  auto max(FieldVector<T, N> const& x);
79

80
  template <class T, int N>
81
  auto max(FieldMatrix<T, 1, N> const& x);
82

83
84
  /// Minimum over all vector entries
  template <class T, int N>
85
  auto min(FieldVector<T, N> const& x);
86

87
  template <class T, int N>
88
  auto min(FieldMatrix<T, 1, N> const& x);
89

90
91
  /// Maximum of the absolute values of vector entries
  template <class T, int N>
92
  auto abs_max(FieldVector<T, N> const& x);
93

94
  template <class T, int N>
95
  auto abs_max(FieldMatrix<T, 1, N> const& x);
96

97
98
  /// Minimum of the absolute values of vector entries
  template <class T, int N>
99
  auto abs_min(FieldVector<T, N> const& x);
100

101
  template <class T, int N>
102
  auto abs_min(FieldMatrix<T, 1, N> const& x);
103

104
105
106
107
108
109
  // ----------------------------------------------------------------------------

  /** \ingroup vector_norms
   *  \brief The 1-norm of a vector = sum_i |x_i|
   **/
  template <class T, int N>
110
  auto one_norm(FieldVector<T, N> const& x);
111

112
  template <class T, int N>
113
  auto one_norm(FieldMatrix<T, 1, N> const& x);
114

115
116
117
118
  /** \ingroup vector_norms
   *  \brief The euklidean 2-norm of a vector = sqrt( sum_i |x_i|^2 )
   **/
  template <class T, int N>
119
  auto two_norm(FieldVector<T, N> const& x);
120

121
  template <class T, int N>
122
  auto two_norm(FieldMatrix<T, 1, N> const& x);
123

124
125
126
127
  /** \ingroup vector_norms
   *  \brief The p-norm of a vector = ( sum_i |x_i|^p )^(1/p)
   **/
  template <int p, class T, int N>
128
  auto p_norm(FieldVector<T, N> const& x);
129

130
  template <int p, class T, int N>
131
  auto p_norm(FieldMatrix<T, 1, N> const& x);
132

133
134
135
136
  /** \ingroup vector_norms
   *  \brief The infty-norm of a vector = max_i |x_i| = alias for \ref abs_max
   **/
  template <class T, int N>
137
  auto infty_norm(FieldVector<T, N> const& x);
138

139
  template <class T, int N>
140
  auto infty_norm(FieldMatrix<T, 1, N> const& x);
141

142
143
144
145
  // ----------------------------------------------------------------------------

  /// The euklidean distance between two vectors = |lhs-rhs|_2
  template <class T, int N>
146
  T distance(FieldVector<T, N> const& lhs, FieldVector<T, N> const& rhs);
147
148
149
150
151

  // ----------------------------------------------------------------------------

  /// Outer product (vec1 * vec2^T)
  template <class T, class S, int N, int M, int K>
152
  auto outer(FieldMatrix<T,N,K> const& vec1, FieldMatrix<S,M,K> const& vec2);
153
154
155
156

  // ----------------------------------------------------------------------------

  template <class T>
157
  T det(FieldMatrix<T, 0, 0> const& /*mat*/);
158
159
160

  /// Determinant of a 1x1 matrix
  template <class T>
161
  T det(FieldMatrix<T, 1, 1> const& mat);
162
163
164

  /// Determinant of a 2x2 matrix
  template <class T>
165
  T det(FieldMatrix<T, 2, 2> const& mat);
166
167
168

  /// Determinant of a 3x3 matrix
  template <class T>
169
  T det(FieldMatrix<T, 3, 3> const& mat);
170
171
172

  /// Determinant of a NxN matrix
  template <class T,  int N>
173
174
  T det(FieldMatrix<T, N, N> const& mat);

175
176
177

  /// Return the inverse of the matrix `mat`
  template <class T, int N>
178
  auto inv(FieldMatrix<T, N, N> mat);
179
180
181

  /// Solve the linear system A*x = b
  template <class T, int N>
182
  void solve(FieldMatrix<T, N, N> const& A,  FieldVector<T, N>& x,  FieldVector<T, N> const& b);
183
184
185
186


  /// Gramian determinant = sqrt( det( DT^T * DF ) )
  template <class T, int N, int M>
187
  T gramian(FieldMatrix<T,N,M> const& DF);
188
189
190

  /// Gramian determinant, specialization for 1 column matrices
  template <class T, int M>
191
  T gramian(FieldMatrix<T, 1, M> const& DF);
192

193
194
195
  // ----------------------------------------------------------------------------
  // some arithmetic operations with FieldMatrix

196
  template <class T, int M, int N>
197
  FieldMatrix<T,N,M> trans(FieldMatrix<T, M, N> const& A);
198
199


200
201
  template <class T, int M, int N, class S,
    REQUIRES(Concepts::Arithmetic<S>) >
202
  FieldMatrix<T,M,N> operator*(S scalar, FieldMatrix<T, M, N> A);
203

204
205
  template <class T, int M, int N, class S,
    REQUIRES(Concepts::Arithmetic<S>) >
206
  FieldMatrix<T,M,N> operator*(FieldMatrix<T, M, N> A, S scalar);
207

208
209
  template <class T, int M, int N, class S,
    REQUIRES(Concepts::Arithmetic<S>) >
210
211
  FieldMatrix<T,M,N> operator/(FieldMatrix<T, M, N> A, S scalar);

212
213

  template <class T, int M, int N>
214
  FieldMatrix<T,M,N> operator+(FieldMatrix<T, M, N> A, FieldMatrix<T, M, N> const& B);
215
216

  template <class T, int M, int N>
217
  FieldMatrix<T,M,N> operator-(FieldMatrix<T, M, N> A, FieldMatrix<T, M, N> const& B);
218
219
220


  template <class T, int N, int M>
221
  FieldVector<T,N> operator*(FieldMatrix<T,N,M> const& mat, FieldVector<T,M> const& vec);
222

223
224
225
226
227
228
  template <class T, int N, int M>
  FieldMatrix<T,N,M> operator*(FieldMatrix<T,N,M> mat, FieldVector<T,1> const& scalar);

  template <class T, int N>
  FieldMatrix<T,N,1> operator*(FieldMatrix<T,N,1> mat, FieldVector<T,1> const& scalar);

229
230


231
  template <class T, int M, int N, int L>
232
  FieldMatrix<T,M,N> multiplies(FieldMatrix<T, M, L> const& A,  FieldMatrix<T, L, N> const& B);
233
234
235
236



  template <class T, int M, int N, int L>
237
  FieldMatrix<T,M,N> multiplies_AtB(FieldMatrix<T, L, M> const& A,  FieldMatrix<T, N, L> const& B);
238
239

  template <class T, int M, int N, int L>
240
  FieldMatrix<T,M,N> multiplies_ABt(FieldMatrix<T, M, L> const& A,  FieldMatrix<T, N, L> const& B);
241
242

  template <class T, int M, int N, int L>
243
  FieldMatrix<T,M,N>& multiplies_ABt(FieldMatrix<T, M, L> const& A,  FieldMatrix<T, N, L> const& B, FieldMatrix<T,M,N>& C);
244

245
  template <class T, int M, int N>
246
  FieldMatrix<T,M,N>& multiplies_ABt(FieldMatrix<T, M, N> const& A,  Dune::DiagonalMatrix<T, N> const& B, FieldMatrix<T,M,N>& C);
247

248
} // end namespace AMDiS
249
250

#include "FieldMatVec.inc.hpp"