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

3
4
#include <type_traits>

5
#include <dune/common/diagonalmatrix.hh>
6
7
8
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>

9
namespace Dune
10
{
Praetorius, Simon's avatar
Praetorius, Simon committed
11
  // some arithmetic operations with FieldVector
12
13

  template <class T, int N, class S,
14
    std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
15
  FieldVector<T,N> operator*(FieldVector<T,N> v, S factor);
16
17

  template <class S, class T, int N,
18
    std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
19
  FieldVector<T,N> operator*(S factor, FieldVector<T,N> v);
20
21

  template <class T, int N, class S,
22
    std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
23
  FieldVector<T,N> operator/(FieldVector<T,N> v, S factor);
24

25
  template <class T>
26
  FieldVector<T,1> operator*(FieldVector<T,1> const& v, FieldVector<T,1> const& w);
27

28
  template <class T, int N>
29
  FieldVector<T,N> operator*(FieldVector<T,1> const& factor, FieldVector<T,N> v);
30

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

34
35
36
37
  // ----------------------------------------------------------------------------

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

40
  /// Cross-product of two 3d-vectors
41
  template <class T>
42
  FieldVector<T, 3> cross(FieldVector<T, 3> const& a, FieldVector<T, 3> const& b);
43
44
45

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

48
  template <class T, int N, int M,
49
    std::enable_if_t<( N!=1 && M!=1 ),int> = 0>
50
  auto operator*(FieldVector<T,N> const& v, FieldVector<T,M> const& w);
51

52
53
54
  template <class T, class S, int N>
  auto dot(FieldMatrix<T,1,N> const& vec1, FieldMatrix<S,1,N> const& vec2);

55
56
57
58
  // ----------------------------------------------------------------------------

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

61
  template <class T, int N>
62
  T sum(FieldMatrix<T, 1, N> const& x);
63

64
65
66

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

69
  template <class T, int N>
70
  auto unary_dot(FieldMatrix<T, 1, N> const& x);
71

72
73
  /// Maximum over all vector entries
  template <class T, int N>
74
  auto max(FieldVector<T, N> const& x);
75

76
  template <class T, int N>
77
  auto max(FieldMatrix<T, 1, N> const& x);
78

79
80
  /// Minimum over all vector entries
  template <class T, int N>
81
  auto min(FieldVector<T, N> const& x);
82

83
  template <class T, int N>
84
  auto min(FieldMatrix<T, 1, N> const& x);
85

86
87
  /// Maximum of the absolute values of vector entries
  template <class T, int N>
88
  auto abs_max(FieldVector<T, N> const& x);
89

90
  template <class T, int N>
91
  auto abs_max(FieldMatrix<T, 1, N> const& x);
92

93
94
  /// Minimum of the absolute values of vector entries
  template <class T, int N>
95
  auto abs_min(FieldVector<T, N> const& x);
96

97
  template <class T, int N>
98
  auto abs_min(FieldMatrix<T, 1, N> const& x);
99

100
101
102
103
104
105
  // ----------------------------------------------------------------------------

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

108
  template <class T, int N>
109
  auto one_norm(FieldMatrix<T, 1, N> const& x);
110

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

117
  template <class T, int N>
118
  auto two_norm(FieldMatrix<T, 1, N> const& x);
119

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

126
  template <int p, class T, int N>
127
  auto p_norm(FieldMatrix<T, 1, N> const& x);
128

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

135
  template <class T, int N>
136
  auto infty_norm(FieldMatrix<T, 1, N> const& x);
137

138
139
140
141
  // ----------------------------------------------------------------------------

  /// The euklidean distance between two vectors = |lhs-rhs|_2
  template <class T, int N>
142
  T distance(FieldVector<T, N> const& lhs, FieldVector<T, N> const& rhs);
143
144
145
146
147

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

  /// Outer product (vec1 * vec2^T)
  template <class T, class S, int N, int M, int K>
148
  auto outer(FieldMatrix<T,N,K> const& vec1, FieldMatrix<S,M,K> const& vec2);
149
150
151
152

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

  template <class T>
153
  T det(FieldMatrix<T, 0, 0> const& /*mat*/);
154
155
156

  /// Determinant of a 1x1 matrix
  template <class T>
157
  T det(FieldMatrix<T, 1, 1> const& mat);
158
159
160

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

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

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

171
172
173

  /// Return the inverse of the matrix `mat`
  template <class T, int N>
174
  auto inv(FieldMatrix<T, N, N> mat);
175
176
177

  /// Solve the linear system A*x = b
  template <class T, int N>
178
  void solve(FieldMatrix<T, N, N> const& A,  FieldVector<T, N>& x,  FieldVector<T, N> const& b);
179
180
181
182


  /// Gramian determinant = sqrt( det( DT^T * DF ) )
  template <class T, int N, int M>
183
  T gramian(FieldMatrix<T,N,M> const& DF);
184
185
186

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

189
190
191
  // ----------------------------------------------------------------------------
  // some arithmetic operations with FieldMatrix

192
  template <class T, int M, int N>
193
  FieldMatrix<T,N,M> trans(FieldMatrix<T, M, N> const& A);
194
195


196
  template <class T, int M, int N, class S,
197
    std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
198
  FieldMatrix<T,M,N> operator*(S scalar, FieldMatrix<T, M, N> A);
199

200
  template <class T, int M, int N, class S,
201
    std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
202
  FieldMatrix<T,M,N> operator*(FieldMatrix<T, M, N> A, S scalar);
203

204
  template <class T, int M, int N, class S,
205
    std::enable_if_t<std::is_arithmetic<S>::value,int> = 0 >
206
207
  FieldMatrix<T,M,N> operator/(FieldMatrix<T, M, N> A, S scalar);

208
209

  template <class T, int M, int N>
210
  FieldMatrix<T,M,N> operator+(FieldMatrix<T, M, N> A, FieldMatrix<T, M, N> const& B);
211
212

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


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

219
220
221
222
223
224
  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);

225
226


227
  template <class T, int M, int N, int L>
228
  FieldMatrix<T,M,N> multiplies(FieldMatrix<T, M, L> const& A,  FieldMatrix<T, L, N> const& B);
229
230
231
232



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

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

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

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

244
245
246
247
248
249
250
} // end namespace Dune

namespace AMDiS
{
  using Dune::FieldMatrix;
  using Dune::FieldVector;
}
251
252

#include "FieldMatVec.inc.hpp"