Go to the documentation of this file.
3 #ifndef DUNE_FMATRIX_HH
4 #define DUNE_FMATRIX_HH
10 #include <initializer_list>
33 template<
class K,
int ROWS,
int COLS >
class FieldMatrix;
35 template<
class K,
int ROWS,
int COLS >
48 typedef typename container_type::size_type
size_type;
51 template<
class K,
int ROWS,
int COLS >
66 template<
class K,
int ROWS,
int COLS>
69 std::array< FieldVector<K,COLS>, ROWS > _data;
95 assert(l.size() ==
rows);
96 std::copy_n(l.begin(), std::min(
static_cast<std::size_t
>(ROWS),
102 typename = std::enable_if_t<HasDenseMatrixAssigner<FieldMatrix, T>::value>>
108 using Base::operator=;
111 template <
typename T,
int rows,
int cols>
114 static_assert(
rows == ROWS,
"Size mismatch in matrix assignment (rows)");
115 static_assert(
cols == COLS,
"Size mismatch in matrix assignment (columns)");
130 C[i][j] += M[i][k]*(*
this)[k][j];
139 template <
int r,
int c>
142 static_assert(r == c,
"Cannot rightmultiply with non-square matrix");
143 static_assert(r ==
cols,
"Size mismatch");
150 (*
this)[i][j] += C[i][k]*M[k][j];
165 C[i][j] += (*
this)[i][k]*M[k][j];
188 #ifndef DOXYGEN // hide specialization
192 class FieldMatrix<K,1,1> :
public DenseMatrix< FieldMatrix<K,1,1> >
194 FieldVector<K,1> _data;
195 typedef DenseMatrix< FieldMatrix<K,1,1> > Base;
235 std::copy_n(l.begin(), std::min(
static_cast< std::size_t
>( 1 ), l.size()), &_data);
239 typename = std::enable_if_t<HasDenseMatrixAssigner<FieldMatrix, T>::value>>
245 using Base::operator=;
253 FieldMatrix<K,l,1> C;
255 C[j][0] = M[j][0]*(*
this)[0][0];
270 FieldMatrix<K,1,l> C;
273 C[0][j] = M[0][j]*_data[0];
325 operator const K& ()
const {
return _data[0]; }
331 std::ostream&
operator<< (std::ostream& s,
const FieldMatrix<K,1,1>& a)
339 namespace FMatrixHelp {
342 template <
typename K>
345 inverse[0][0] = 1.0/matrix[0][0];
350 template <
typename K>
358 template <
typename K>
362 K det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
364 inverse[0][0] = matrix[1][1] * det_1;
365 inverse[0][1] = - matrix[0][1] * det_1;
366 inverse[1][0] = - matrix[1][0] * det_1;
367 inverse[1][1] = matrix[0][0] * det_1;
373 template <
typename K>
377 K det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
379 inverse[0][0] = matrix[1][1] * det_1;
380 inverse[1][0] = - matrix[0][1] * det_1;
381 inverse[0][1] = - matrix[1][0] * det_1;
382 inverse[1][1] = matrix[0][0] * det_1;
387 template <
typename K>
391 K t4 = matrix[0][0] * matrix[1][1];
392 K t6 = matrix[0][0] * matrix[1][2];
393 K t8 = matrix[0][1] * matrix[1][0];
394 K t10 = matrix[0][2] * matrix[1][0];
395 K t12 = matrix[0][1] * matrix[2][0];
396 K t14 = matrix[0][2] * matrix[2][0];
398 K det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
399 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
402 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
403 inverse[0][1] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
404 inverse[0][2] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
405 inverse[1][0] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
406 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
407 inverse[1][2] = -(t6-t10) * t17;
408 inverse[2][0] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
409 inverse[2][1] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
410 inverse[2][2] = (t4-t8) * t17;
416 template <
typename K>
420 K t4 = matrix[0][0] * matrix[1][1];
421 K t6 = matrix[0][0] * matrix[1][2];
422 K t8 = matrix[0][1] * matrix[1][0];
423 K t10 = matrix[0][2] * matrix[1][0];
424 K t12 = matrix[0][1] * matrix[2][0];
425 K t14 = matrix[0][2] * matrix[2][0];
427 K det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
428 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
431 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
432 inverse[1][0] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
433 inverse[2][0] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
434 inverse[0][1] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
435 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
436 inverse[2][1] = -(t6-t10) * t17;
437 inverse[0][2] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
438 inverse[1][2] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
439 inverse[2][2] = (t4-t8) * t17;
445 template<
class K,
int m,
int n,
int p >
452 for( size_type i = 0; i < m; ++i )
454 for( size_type j = 0; j < p; ++j )
456 ret[ i ][ j ] = K( 0 );
457 for( size_type k = 0; k < n; ++k )
458 ret[ i ][ j ] += A[ i ][ k ] * B[ k ][ j ];
464 template <
typename K,
int rows,
int cols>
469 for(size_type i=0; i<cols; i++)
470 for(size_type j=0; j<cols; j++)
473 for(size_type k=0; k<rows; k++)
474 ret[i][j]+=matrix[k][i]*matrix[k][j];
481 template <
typename K,
int rows,
int cols>
486 for(size_type i=0; i<cols; ++i)
489 for(size_type j=0; j<rows; ++j)
490 ret[i] += matrix[j][i]*x[j];
495 template <
typename K,
int rows,
int cols>
504 template <
typename K,
int rows,
int cols>
Base::row_type row_type
Definition: fmatrix.hh:82
Base::row_reference row_reference
Definition: fmatrix.hh:84
A dense n x m matrix.
Definition: densematrix.hh:39
FieldMatrix & operator=(FieldMatrix< T, rows, cols > const &rhs)
Definition: fmatrix.hh:112
const_row_reference mat_access(size_type i) const
Definition: fmatrix.hh:181
FieldMatrix()
Default constructor.
Definition: fmatrix.hh:90
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
FieldMatrix(std::initializer_list< Dune::FieldVector< K, cols > > const &l)
Constructor initializing the matrix from a list of vector.
Definition: fmatrix.hh:94
MAT & rightmultiply(const DenseMatrix< M2 > &M)
Multiplies M from the right to this matrix.
Definition: densematrix.hh:634
static FieldVector< K, rows > mult(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, cols > &x)
calculates ret = matrix * x
Definition: fmatrix.hh:496
constexpr size_type mat_cols() const
Definition: fmatrix.hh:173
A few common exception classes.
Dune namespace.
Definition: alignedallocator.hh:9
K value_type
Definition: fmatrix.hh:47
Traits::row_type row_type
The type used to represent a row (must fulfill the Dune::DenseVector interface)
Definition: densematrix.hh:186
static K invertMatrix_retTransposed(const FieldMatrix< K, 1, 1 > &matrix, FieldMatrix< K, 1, 1 > &inverse)
invert scalar without changing the original matrix
Definition: fmatrix.hh:351
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
FieldMatrix< K, rows, l > rightmultiplyany(const FieldMatrix< K, cols, l > &M) const
Multiplies M from the right to this matrix, this matrix is not modified.
Definition: fmatrix.hh:157
std::array< row_type, ROWS > container_type
Definition: fmatrix.hh:46
Various precision settings for calculations with FieldMatrix and FieldVector.
static K invertMatrix(const FieldMatrix< K, 1, 1 > &matrix, FieldMatrix< K, 1, 1 > &inverse)
invert scalar without changing the original matrix
Definition: fmatrix.hh:343
static void multAssign(const DenseMatrix< MAT > &matrix, const DenseVector< V1 > &x, DenseVector< V2 > &ret)
calculates ret = matrix * x
Definition: densematrix.hh:1161
Implements a vector constructed from a given type representing a field and a compile-time given size.
Eigenvalue computations for the FieldMatrix class.
FieldMatrix< K, ROWS, COLS > derived_type
Definition: fmatrix.hh:38
FieldMatrix & rightmultiply(const FieldMatrix< K, r, c > &M)
Multiplies M from the right to this matrix.
Definition: fmatrix.hh:140
static FieldVector< K, cols > multTransposed(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, rows > &x)
calculates ret = matrix^T * x
Definition: fmatrix.hh:505
static void multAssignTransposed(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, rows > &x, FieldVector< K, cols > &ret)
calculates ret = matrix^T * x
Definition: fmatrix.hh:482
static void multTransposedMatrix(const FieldMatrix< K, rows, cols > &matrix, FieldMatrix< K, cols, cols > &ret)
calculates ret= A_t*A
Definition: fmatrix.hh:465
@ cols
The number of columns.
Definition: fmatrix.hh:78
container_type::size_type size_type
Definition: fmatrix.hh:48
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
const typedef row_type & const_row_reference
Definition: fmatrix.hh:44
Base::size_type size_type
Definition: fmatrix.hh:81
Base::const_row_reference const_row_reference
Definition: fmatrix.hh:85
FieldTraits< K >::real_type real_type
Definition: fmatrix.hh:55
FieldVector< K, COLS > row_type
Definition: fmatrix.hh:41
row_reference mat_access(size_type i)
Definition: fmatrix.hh:175
static void multMatrix(const FieldMatrix< K, m, n > &A, const FieldMatrix< K, n, p > &B, FieldMatrix< K, m, p > &ret)
calculates ret = A * B
Definition: fmatrix.hh:446
Macro for wrapping boundary checks.
Traits::const_row_reference const_row_reference
The type used to represent a reference to a constant row (usually const row_type &)
Definition: densematrix.hh:192
FieldTraits< K >::field_type field_type
Definition: fmatrix.hh:54
row_type & row_reference
Definition: fmatrix.hh:43
Definition: ftraits.hh:23
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition: bigunsignedint.hh:272
T field_type
export the type representing the field
Definition: ftraits.hh:26
FieldMatrix(T const &rhs)
Definition: fmatrix.hh:103
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
constexpr size_type mat_rows() const
Definition: fmatrix.hh:172
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densematrix.hh:183
A dense n x m matrix.
Definition: densematrix.hh:26
Traits for type conversions and type information.
Traits::row_reference row_reference
The type used to represent a reference to a row (usually row_type &)
Definition: densematrix.hh:189
Definition: matvectraits.hh:29
@ rows
The number of rows.
Definition: fmatrix.hh:76
FieldMatrix< K, l, cols > leftmultiplyany(const FieldMatrix< K, l, rows > &M) const
Multiplies M from the left to this matrix, this matrix is not modified.
Definition: fmatrix.hh:122