3 #ifndef DUNE_FMATRIX_HH
4 #define DUNE_FMATRIX_HH
10 #include <initializer_list>
32 template<
class K,
int ROWS,
int COLS >
class FieldMatrix;
34 template<
class K,
int ROWS,
int COLS >
47 typedef typename container_type::size_type
size_type;
50 template<
class K,
int ROWS,
int COLS >
65 template<
class K,
int ROWS,
int COLS>
68 Dune::array< FieldVector<K,COLS>, ROWS > _data;
93 template<
class Other >
101 FieldMatrix (std::initializer_list<std::initializer_list<K> >
const &ll)
103 assert(ll.size() ==
rows);
104 std::copy_n(ll.begin(), std::min(static_cast<std::size_t>(ROWS),
112 assert(l.size() ==
rows);
113 std::copy_n(l.begin(), std::min(static_cast<std::size_t>(ROWS),
119 using Base::operator=;
127 for (size_type i=0; i<l; i++) {
128 for (size_type j=0; j<
cols; j++) {
130 for (size_type k=0; k<
rows; k++)
131 C[i][j] += M[i][k]*(*
this)[k][j];
142 for (size_type i=0; i<
rows; i++)
143 for (size_type j=0; j<
cols; j++) {
145 for (size_type k=0; k<
cols; k++)
146 (*
this)[i][j] += C[i][k]*M[k][j];
157 for (size_type i=0; i<
rows; i++) {
158 for (size_type j=0; j<l; j++) {
160 for (size_type k=0; k<
cols; k++)
161 C[i][j] += (*
this)[i][k]*M[k][j];
184 #ifndef DOXYGEN // hide specialization
188 class FieldMatrix<K,1,1> :
public DenseMatrix< FieldMatrix<K,1,1> >
190 FieldVector<K,1> _data;
191 typedef DenseMatrix< FieldMatrix<K,1,1> > Base;
234 template<
class Other >
237 DenseMatrixAssigner< FieldMatrix< K, 1, 1 >, Other >::apply( *
this, other );
246 FieldMatrix<K,l,1> C;
247 for (size_type j=0; j<l; j++)
248 C[j][0] = M[j][0]*(*
this)[0][0];
263 FieldMatrix<K,1,l> C;
265 for (size_type j=0; j<l; j++)
266 C[0][j] = M[0][j]*_data[0];
281 const_row_reference
mat_access ( size_type i )
const
318 operator const K& ()
const {
return _data[0]; }
324 std::ostream& operator<< (std::ostream& s, const FieldMatrix<K,1,1>& a)
332 namespace FMatrixHelp {
335 template <
typename K>
338 inverse[0][0] = 1.0/matrix[0][0];
343 template <
typename K>
351 template <
typename K>
355 K det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
357 inverse[0][0] = matrix[1][1] * det_1;
358 inverse[0][1] = - matrix[0][1] * det_1;
359 inverse[1][0] = - matrix[1][0] * det_1;
360 inverse[1][1] = matrix[0][0] * det_1;
366 template <
typename K>
370 K det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
372 inverse[0][0] = matrix[1][1] * det_1;
373 inverse[1][0] = - matrix[0][1] * det_1;
374 inverse[0][1] = - matrix[1][0] * det_1;
375 inverse[1][1] = matrix[0][0] * det_1;
380 template <
typename K>
384 K t4 = matrix[0][0] * matrix[1][1];
385 K t6 = matrix[0][0] * matrix[1][2];
386 K t8 = matrix[0][1] * matrix[1][0];
387 K t10 = matrix[0][2] * matrix[1][0];
388 K t12 = matrix[0][1] * matrix[2][0];
389 K t14 = matrix[0][2] * matrix[2][0];
391 K det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
392 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
395 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
396 inverse[0][1] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
397 inverse[0][2] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
398 inverse[1][0] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
399 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
400 inverse[1][2] = -(t6-t10) * t17;
401 inverse[2][0] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
402 inverse[2][1] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
403 inverse[2][2] = (t4-t8) * t17;
409 template <
typename K>
413 K t4 = matrix[0][0] * matrix[1][1];
414 K t6 = matrix[0][0] * matrix[1][2];
415 K t8 = matrix[0][1] * matrix[1][0];
416 K t10 = matrix[0][2] * matrix[1][0];
417 K t12 = matrix[0][1] * matrix[2][0];
418 K t14 = matrix[0][2] * matrix[2][0];
420 K det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
421 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
424 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
425 inverse[1][0] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
426 inverse[2][0] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
427 inverse[0][1] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
428 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
429 inverse[2][1] = -(t6-t10) * t17;
430 inverse[0][2] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
431 inverse[1][2] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
432 inverse[2][2] = (t4-t8) * t17;
438 template<
class K,
int m,
int n,
int p >
445 for( size_type i = 0; i < m; ++i )
447 for( size_type j = 0; j < p; ++j )
449 ret[ i ][ j ] = K( 0 );
450 for( size_type k = 0; k < n; ++k )
451 ret[ i ][ j ] += A[ i ][ k ] * B[ k ][ j ];
457 template <
typename K,
int rows,
int cols>
462 for(size_type i=0; i<cols; i++)
463 for(size_type j=0; j<cols; j++)
466 for(size_type k=0; k<rows; k++)
467 ret[i][j]+=matrix[k][i]*matrix[k][j];
474 template <
typename K,
int rows,
int cols>
479 for(size_type i=0; i<cols; ++i)
482 for(size_type j=0; j<rows; ++j)
483 ret[i] += matrix[j][i]*x[j];
488 template <
typename K,
int rows,
int cols>
497 template <
typename K,
int rows,
int cols>
FieldMatrix & rightmultiply(const FieldMatrix< K, cols, cols > &M)
Multiplies M from the right to this matrix.
Definition: fmatrix.hh:138
Dune::array< row_type, ROWS > container_type
Definition: fmatrix.hh:45
A dense n x m matrix.
Definition: densematrix.hh:22
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:217
Definition: ftraits.hh:22
DUNE_CONSTEXPR size_type mat_cols() const
Definition: fmatrix.hh:169
Eigenvalue computations for the FieldMatrix class.
#define DUNE_CONSTEXPR
Set method or expression constexpr if supported by the compiler.
Definition: constexpr.hh:21
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:475
Traits::row_reference row_reference
The type used to represent a reference to a row (usually row_type &)
Definition: densematrix.hh:214
DUNE_CONSTEXPR size_type mat_rows() const
Definition: fmatrix.hh:168
The number of block levels we contain. This is 1.
Definition: densematrix.hh:222
A few common exception classes.
DenseMatrix & operator-=(const DenseMatrix< Other > &y)
vector space subtraction
Definition: densematrix.hh:337
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:27
Definition: matvectraits.hh:29
DenseMatrix & operator/=(const field_type &k)
vector space division by scalar
Definition: densematrix.hh:353
DenseMatrix & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: densematrix.hh:345
row_reference mat_access(size_type i)
Definition: fmatrix.hh:171
size_type M() const
number of columns
Definition: densematrix.hh:691
static FieldVector< K, rows > mult(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, cols > &x)
calculates ret = matrix * x
Definition: fmatrix.hh:489
Base::const_row_reference const_row_reference
Definition: fmatrix.hh:84
FieldMatrix(std::initializer_list< std::initializer_list< K > > const &ll)
Constructor initializing the matrix from a list of lists of scalars.
Definition: fmatrix.hh:101
Traits::row_type row_type
The type used to represent a row (must fulfill the Dune::DenseVector interface)
Definition: densematrix.hh:211
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:439
Dune namespace.
Definition: alignment.hh:9
Base::size_type size_type
Definition: fmatrix.hh:80
Implements a vector constructed from a given type representing a field and a compile-time given size...
FieldTraits< K >::field_type field_type
Definition: fmatrix.hh:53
container_type::size_type size_type
Definition: fmatrix.hh:47
size_type cols() const
number of columns
Definition: densematrix.hh:703
FieldVector< K, COLS > row_type
Definition: fmatrix.hh:40
FieldMatrix(const Other &other)
Constructor initializing the whole matrix with a scalar.
Definition: fmatrix.hh:94
Base::row_type row_type
Definition: fmatrix.hh:81
static FieldVector< K, cols > multTransposed(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, rows > &x)
calculates ret = matrix^T * x
Definition: fmatrix.hh:498
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:344
const row_type & const_row_reference
Definition: fmatrix.hh:43
static void multTransposedMatrix(const FieldMatrix< K, rows, cols > &matrix, FieldMatrix< K, cols, cols > &ret)
calculates ret= A_t*A
Definition: fmatrix.hh:458
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
you have to specialize this structure for any type that should be assignable to a DenseMatrix ...
Definition: densematrix.hh:71
T field_type
export the type representing the field
Definition: ftraits.hh:25
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:153
FieldMatrix()
Default constructor.
Definition: fmatrix.hh:89
DenseMatrix & operator+=(const DenseMatrix< Other > &y)
vector space addition
Definition: densematrix.hh:328
static void multAssign(const DenseMatrix< MAT > &matrix, const DenseVector< V1 > &x, DenseVector< V2 > &ret)
calculates ret = matrix * x
Definition: densematrix.hh:1183
Various precision settings for calculations with FieldMatrix and FieldVector.
K value_type
Definition: fmatrix.hh:46
Definition of the DUNE_CONSTEXPR macro.
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:123
FieldMatrix(std::initializer_list< Dune::FieldVector< K, cols > > const &l)
Constructor initializing the matrix from a list of vector.
Definition: fmatrix.hh:111
static K invertMatrix(const FieldMatrix< K, 1, 1 > &matrix, FieldMatrix< K, 1, 1 > &inverse)
invert scalar without changing the original matrix
Definition: fmatrix.hh:336
FieldMatrix< K, ROWS, COLS > derived_type
Definition: fmatrix.hh:37
row_type & row_reference
Definition: fmatrix.hh:42
const_row_reference mat_access(size_type i) const
Definition: fmatrix.hh:177
A dense n x m matrix.
Definition: densematrix.hh:35
FieldTraits< K >::real_type real_type
Definition: fmatrix.hh:54
size_type rows() const
number of rows
Definition: densematrix.hh:697
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densematrix.hh:208
Base::row_reference row_reference
Definition: fmatrix.hh:83