4 #ifndef DUNE_FMATRIX_HH
5 #define DUNE_FMATRIX_HH
32 template<
class K,
int ROWS,
int COLS >
class FieldMatrix;
34 template<
class K,
int ROWS,
int COLS >
50 template<
class K,
int ROWS,
int COLS >
65 template<
class K,
int ROWS,
int COLS>
93 template<
class Other >
100 using Base::operator=;
109 for (size_type i=0; i<
rows; i++)
110 for (size_type j=0; j<
cols; j++) {
112 for (size_type k=0; k<
rows; k++)
113 (*
this)[i][j] += M[i][k]*C[k][j];
126 for (size_type i=0; i<l; i++) {
127 for (size_type j=0; j<
cols; j++) {
129 for (size_type k=0; k<
rows; k++)
130 C[i][j] += M[i][k]*(*
this)[k][j];
141 for (size_type i=0; i<
rows; i++)
142 for (size_type j=0; j<
cols; j++) {
144 for (size_type k=0; k<
cols; k++)
145 (*
this)[i][j] += C[i][k]*M[k][j];
156 for (size_type i=0; i<
rows; i++) {
157 for (size_type j=0; j<l; j++) {
159 for (size_type k=0; k<
cols; k++)
160 C[i][j] += (*
this)[i][k]*M[k][j];
183 #ifndef DOXYGEN // hide specialization
187 class FieldMatrix<K,1,1> :
public DenseMatrix< FieldMatrix<K,1,1> >
189 FieldVector<K,1> _data;
190 typedef DenseMatrix< FieldMatrix<K,1,1> > Base;
233 template<
class Other >
236 DenseMatrixAssigner< FieldMatrix< K, 1, 1 >, Other >::apply( *
this, other );
245 FieldMatrix<K,l,1> C;
246 for (size_type j=0; j<l; j++)
247 C[j][0] = M[j][0]*(*
this)[0][0];
262 FieldMatrix<K,1,l> C;
264 for (size_type j=0; j<l; j++)
265 C[0][j] = M[0][j]*_data[0];
279 const_row_reference
mat_access ( size_type i )
const
315 operator K ()
const {
return _data[0]; }
321 std::ostream& operator<< (std::ostream& s, const FieldMatrix<K,1,1>& a)
329 namespace FMatrixHelp {
332 template <
typename K>
335 inverse[0][0] = 1.0/matrix[0][0];
340 template <
typename K>
348 template <
typename K>
352 K det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
354 inverse[0][0] = matrix[1][1] * det_1;
355 inverse[0][1] = - matrix[0][1] * det_1;
356 inverse[1][0] = - matrix[1][0] * det_1;
357 inverse[1][1] = matrix[0][0] * det_1;
363 template <
typename K>
367 K det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
369 inverse[0][0] = matrix[1][1] * det_1;
370 inverse[1][0] = - matrix[0][1] * det_1;
371 inverse[0][1] = - matrix[1][0] * det_1;
372 inverse[1][1] = matrix[0][0] * det_1;
377 template <
typename K>
381 K t4 = matrix[0][0] * matrix[1][1];
382 K t6 = matrix[0][0] * matrix[1][2];
383 K t8 = matrix[0][1] * matrix[1][0];
384 K t10 = matrix[0][2] * matrix[1][0];
385 K t12 = matrix[0][1] * matrix[2][0];
386 K t14 = matrix[0][2] * matrix[2][0];
388 K det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
389 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
392 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
393 inverse[0][1] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
394 inverse[0][2] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
395 inverse[1][0] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
396 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
397 inverse[1][2] = -(t6-t10) * t17;
398 inverse[2][0] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
399 inverse[2][1] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
400 inverse[2][2] = (t4-t8) * t17;
406 template <
typename K>
410 K t4 = matrix[0][0] * matrix[1][1];
411 K t6 = matrix[0][0] * matrix[1][2];
412 K t8 = matrix[0][1] * matrix[1][0];
413 K t10 = matrix[0][2] * matrix[1][0];
414 K t12 = matrix[0][1] * matrix[2][0];
415 K t14 = matrix[0][2] * matrix[2][0];
417 K det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
418 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
421 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
422 inverse[1][0] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
423 inverse[2][0] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
424 inverse[0][1] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
425 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
426 inverse[2][1] = -(t6-t10) * t17;
427 inverse[0][2] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
428 inverse[1][2] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
429 inverse[2][2] = (t4-t8) * t17;
435 template<
class K,
int m,
int n,
int p >
442 for( size_type i = 0; i < m; ++i )
444 for( size_type j = 0; j < p; ++j )
446 ret[ i ][ j ] = K( 0 );
447 for( size_type k = 0; k < n; ++k )
448 ret[ i ][ j ] += A[ i ][ k ] * B[ k ][ j ];
454 template <
typename K,
int rows,
int cols>
459 for(size_type i=0; i<cols; i++)
460 for(size_type j=0; j<cols; j++)
463 for(size_type k=0; k<rows; k++)
464 ret[i][j]+=matrix[k][i]*matrix[k][j];
469 template <
typename K,
int rows,
int cols>
475 for(size_type i=0; i<rows; ++i)
478 for(size_type j=0; j<cols; ++j)
480 ret[i] += matrix[i][j]*x[j];
489 template <
typename K,
int rows,
int cols>
494 for(size_type i=0; i<cols; ++i)
497 for(size_type j=0; j<rows; ++j)
498 ret[i] += matrix[j][i]*x[j];
503 template <
typename K,
int rows,
int cols>
512 template <
typename K,
int rows,
int cols>
const_row_reference mat_access(size_type i) const
Definition: fmatrix.hh:176
row_type & row_reference
Definition: fmatrix.hh:42
static FieldVector< K, rows > mult(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, cols > &x)
calculates ret = matrix * x
Definition: fmatrix.hh:504
Simple fixed size array class. This replaces std::array, if that is not available.
Definition: array.hh:40
Dune namespace.
Definition: alignment.hh:13
A few common exception classes.
Fallback implementation of the C++0x static_assert feature.
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
Dune::array< row_type, ROWS > container_type
Definition: fmatrix.hh:45
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:341
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densematrix.hh:215
FieldVector< K, COLS > row_type
Definition: fmatrix.hh:40
std::size_t size_type
Type used for array indices.
Definition: array.hh:59
Traits::row_type row_type
The type used to represent a row (must fulfill the Dune::DenseVector interface)
Definition: densematrix.hh:218
row_reference mat_access(size_type i)
Definition: fmatrix.hh:170
DUNE_CONSTEXPR size_type mat_cols() const
Definition: fmatrix.hh:168
Base::const_row_reference const_row_reference
Definition: fmatrix.hh:84
K value_type
Definition: fmatrix.hh:46
T field_type
export the type representing the field
Definition: ftraits.hh:26
you have to specialize this structure for any type that should be assignable to a DenseMatrix ...
Definition: densematrix.hh:73
FieldMatrix< K, ROWS, COLS > & leftmultiply(const DenseMatrix< M2 > &M)
Multiplies M from the left to this matrix.
Definition: densematrix.hh:624
static K invertMatrix(const FieldMatrix< K, 1, 1 > &matrix, FieldMatrix< K, 1, 1 > &inverse)
invert scalar without changing the original matrix
Definition: fmatrix.hh:333
FieldTraits< K >::field_type field_type
Definition: fmatrix.hh:53
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:152
FieldMatrix()
Default constructor.
Definition: fmatrix.hh:89
static void multAssign(const DenseMatrix< MAT > &matrix, const DenseVector< V1 > &x, DenseVector< V2 > &ret)
calculates ret = matrix * x
Definition: densematrix.hh:1190
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:436
DenseMatrix & operator-=(const DenseMatrix< Other > &y)
vector space subtraction
Definition: densematrix.hh:344
static FieldVector< K, cols > multTransposed(const FieldMatrix< K, rows, cols > &matrix, const FieldVector< K, rows > &x)
calculates ret = matrix^T * x
Definition: fmatrix.hh:513
FieldTraits< K >::real_type real_type
Definition: fmatrix.hh:54
DenseMatrix & operator/=(const field_type &k)
vector space division by scalar
Definition: densematrix.hh:360
#define DUNE_CONSTEXPR
Definition: constexpr.hh:7
container_type::size_type size_type
Definition: fmatrix.hh:47
DenseMatrix & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: densematrix.hh:352
size_type cols() const
number of columns
Definition: densematrix.hh:710
Base::row_reference row_reference
Definition: fmatrix.hh:83
size_type M() const
number of columns
Definition: densematrix.hh:698
Implements a vector constructed from a given type representing a field and a compile-time given size...
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:490
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
A dense n x m matrix.
Definition: densematrix.hh:24
static void multTransposedMatrix(const FieldMatrix< K, rows, cols > &matrix, FieldMatrix< K, cols, cols > &ret)
calculates ret= A_t*A
Definition: fmatrix.hh:455
const row_type & const_row_reference
Definition: fmatrix.hh:43
Definition: ftraits.hh:23
DenseMatrix & operator+=(const DenseMatrix< Other > &y)
vector space addition
Definition: densematrix.hh:335
The number of block levels we contain. This is 1.
Definition: densematrix.hh:229
Base::size_type size_type
Definition: fmatrix.hh:80
Various precision settings for calculations with FieldMatrix and FieldVector.
DUNE_CONSTEXPR size_type mat_rows() const
Definition: fmatrix.hh:167
FieldMatrix & rightmultiply(const FieldMatrix< K, cols, cols > &M)
Multiplies M from the right to this matrix.
Definition: fmatrix.hh:137
size_type rows() const
number of rows
Definition: densematrix.hh:704
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:224
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
FieldMatrix(const Other &other)
Constructor initializing the whole matrix with a scalar.
Definition: fmatrix.hh:94
FieldMatrix< K, ROWS, COLS > derived_type
Definition: fmatrix.hh:37
Base::row_type row_type
Definition: fmatrix.hh:81
Traits::row_reference row_reference
The type used to represent a reference to a row (usually row_type &)
Definition: densematrix.hh:221
Eigenvalue computations for the FieldMatrix class.
Definition: matvectraits.hh:30
A dense n x m matrix.
Definition: densematrix.hh:37