3 #ifndef DUNE_DENSEMATRIX_HH
4 #define DUNE_DENSEMATRIX_HH
41 static typename V::size_type
size(
const V & v) {
return v.size(); }
44 template<
class K,
int N>
47 typedef FieldVector<K,N> V;
48 static typename V::size_type
size(
const V & v) {
return N; }
70 template<
class DenseMatrix,
class RHS >
75 template<
class DenseMatrix,
class K,
int N,
int M >
78 for(
int i = 0; i < N; ++i )
79 for(
int j = 0; j < M; ++j )
80 denseMatrix[ i ][ j ] = values[ i ][ j ];
88 template<
class DenseMatrix,
class RHS,
89 bool primitive = Conversion< RHS, typename DenseMatrix::field_type >::exists >
90 class DenseMatrixAssignerImplementation;
92 template<
class DenseMatrix,
class RHS >
93 class DenseMatrixAssignerImplementation< DenseMatrix, RHS, true >
96 static void apply ( DenseMatrix &denseMatrix,
const RHS &rhs )
99 std::fill( denseMatrix.begin(), denseMatrix.end(),
static_cast< field_type
>( rhs ) );
103 template<
class DenseMatrix,
class RHS >
104 class DenseMatrixAssignerImplementation< DenseMatrix, RHS, false >
106 template<
class M,
class T>
107 struct have_istl_assign_to_fmatrix
109 struct yes {
char dummy[ 1 ]; };
110 struct no {
char dummy[ 2 ]; };
121 static const bool v =
sizeof( test< const T >( 0 ) ) ==
sizeof( yes );
124 template< class M, class T, bool = have_istl_assign_to_fmatrix< M, T >::v >
125 struct DefaultImplementation;
128 template<
class M,
class T >
129 struct DefaultImplementation< M, T, true >
131 static void apply ( M &m,
const T &
t )
138 template<
class M,
class T >
139 struct DefaultImplementation< M, T, false >
141 static void apply ( M &m,
const T &
t )
143 static_assert( (Conversion< const T, const M >::exists),
"No template specialization of DenseMatrixAssigner found" );
144 m =
static_cast< const M &
>(
t );
149 static void apply ( DenseMatrix &denseMatrix,
const RHS &rhs )
151 DefaultImplementation< DenseMatrix, RHS >::apply( denseMatrix, rhs );
158 template<
class DenseMatrix,
class RHS >
159 struct DenseMatrixAssigner
161 static void apply ( DenseMatrix &denseMatrix,
const RHS &rhs )
163 DenseMatrixAssignerImplementation< DenseMatrix, RHS >::apply( denseMatrix, rhs );
166 #endif // #ifndef DOXYGEN
183 template<
typename MAT>
189 MAT & asImp() {
return static_cast<MAT&
>(*this); }
190 const MAT & asImp()
const {
return static_cast<const MAT&
>(*this); }
230 return asImp().mat_access(i);
235 return asImp().mat_access(i);
252 typedef typename remove_reference<row_reference>::type::Iterator
ColIterator;
287 typedef typename remove_reference<const_row_reference>::type::ConstIterator
ConstColIterator;
296 ConstIterator
end ()
const
317 template<
class RHS >
327 template <
class Other>
330 for (size_type i=0; i<
rows(); i++)
336 template <
class Other>
339 for (size_type i=0; i<
rows(); i++)
347 for (size_type i=0; i<
rows(); i++)
355 for (size_type i=0; i<
rows(); i++)
361 template <
class Other>
364 for( size_type i = 0; i <
rows(); ++i )
365 (*
this)[ i ].
axpy( k, y[ i ] );
370 template <
class Other>
373 for (size_type i=0; i<
rows(); i++)
374 if ((*
this)[i]!=y[i])
379 template <
class Other>
389 template<
class X,
class Y>
390 void mv (
const X& x, Y& y)
const
392 #ifdef DUNE_FMatrix_WITH_CHECKING
396 for (size_type i=0; i<
rows(); ++i)
399 for (size_type j=0; j<
cols(); j++)
400 y[i] += (*
this)[i][j] * x[j];
405 template<
class X,
class Y >
406 void mtv (
const X &x, Y &y )
const
408 #ifdef DUNE_FMatrix_WITH_CHECKING
418 for( size_type i = 0; i <
cols(); ++i )
421 for( size_type j = 0; j <
rows(); ++j )
422 y[ i ] += (*
this)[ j ][ i ] * x[ j ];
427 template<
class X,
class Y>
428 void umv (
const X& x, Y& y)
const
430 #ifdef DUNE_FMatrix_WITH_CHECKING
432 DUNE_THROW(
FMatrixError,
"y += A x -- index out of range (sizes: x: " << x.N() <<
", y: " << y.N() <<
", A: " << this->
N() <<
" x " << this->
M() <<
")" << std::endl);
434 DUNE_THROW(
FMatrixError,
"y += A x -- index out of range (sizes: x: " << x.N() <<
", y: " << y.N() <<
", A: " << this->
N() <<
" x " << this->
M() <<
")" << std::endl);
436 for (size_type i=0; i<
rows(); i++)
437 for (size_type j=0; j<
cols(); j++)
438 y[i] += (*
this)[i][j] * x[j];
442 template<
class X,
class Y>
443 void umtv (
const X& x, Y& y)
const
445 #ifdef DUNE_FMatrix_WITH_CHECKING
450 for (size_type i=0; i<
rows(); i++)
451 for (size_type j=0; j<
cols(); j++)
452 y[j] += (*
this)[i][j]*x[i];
456 template<
class X,
class Y>
457 void umhv (
const X& x, Y& y)
const
459 #ifdef DUNE_FMatrix_WITH_CHECKING
464 for (size_type i=0; i<
rows(); i++)
465 for (size_type j=0; j<
cols(); j++)
470 template<
class X,
class Y>
471 void mmv (
const X& x, Y& y)
const
473 #ifdef DUNE_FMatrix_WITH_CHECKING
477 for (size_type i=0; i<
rows(); i++)
478 for (size_type j=0; j<
cols(); j++)
479 y[i] -= (*
this)[i][j] * x[j];
483 template<
class X,
class Y>
484 void mmtv (
const X& x, Y& y)
const
486 #ifdef DUNE_FMatrix_WITH_CHECKING
491 for (size_type i=0; i<
rows(); i++)
492 for (size_type j=0; j<
cols(); j++)
493 y[j] -= (*
this)[i][j]*x[i];
497 template<
class X,
class Y>
498 void mmhv (
const X& x, Y& y)
const
500 #ifdef DUNE_FMatrix_WITH_CHECKING
505 for (size_type i=0; i<
rows(); i++)
506 for (size_type j=0; j<
cols(); j++)
511 template<
class X,
class Y>
512 void usmv (
const field_type& alpha,
const X& x, Y& y)
const
514 #ifdef DUNE_FMatrix_WITH_CHECKING
518 for (size_type i=0; i<
rows(); i++)
519 for (size_type j=0; j<
cols(); j++)
520 y[i] += alpha * (*
this)[i][j] * x[j];
524 template<
class X,
class Y>
525 void usmtv (
const field_type& alpha,
const X& x, Y& y)
const
527 #ifdef DUNE_FMatrix_WITH_CHECKING
532 for (size_type i=0; i<
rows(); i++)
533 for (size_type j=0; j<
cols(); j++)
534 y[j] += alpha*(*
this)[i][j]*x[i];
538 template<
class X,
class Y>
539 void usmhv (
const field_type& alpha,
const X& x, Y& y)
const
541 #ifdef DUNE_FMatrix_WITH_CHECKING
546 for (size_type i=0; i<
rows(); i++)
547 for (size_type j=0; j<
cols(); j++)
557 for (size_type i=0; i<
rows(); ++i) sum += (*
this)[i].two_norm2();
558 return fvmeta::sqrt(sum);
565 for (size_type i=0; i<
rows(); ++i) sum += (*
this)[i].two_norm2();
575 ConstIterator it =
begin();
576 typename remove_const< typename FieldTraits<value_type>::real_type >::type max = (*it).one_norm();
577 for (it = it + 1; it !=
end(); ++it)
578 max = std::max(max, (*it).one_norm());
589 ConstIterator it =
begin();
590 typename remove_const< typename FieldTraits<value_type>::real_type >::type max = (*it).one_norm_real();
591 for (it = it + 1; it !=
end(); ++it)
592 max = std::max(max, (*it).one_norm_real());
604 void solve (V& x,
const V& b)
const;
616 template<
typename M2>
622 for (size_type i=0; i<
rows(); i++)
623 for (size_type j=0; j<
cols(); j++) {
625 for (size_type k=0; k<
rows(); k++)
626 (*
this)[i][j] += M[i][k]*C[k][j];
633 template<
typename M2>
639 for (size_type i=0; i<
rows(); i++)
640 for (size_type j=0; j<
cols(); j++) {
642 for (size_type k=0; k<
cols(); k++)
643 (*
this)[i][j] += C[i][k]*M[k][j];
655 for (size_type i=0; i<l; i++) {
656 for (size_type j=0; j<
cols(); j++) {
658 for (size_type k=0; k<
rows(); k++)
659 C[i][j] += M[i][k]*(*
this)[k][j];
667 FieldMatrix<K,rows,l> rightmultiplyany (
const FieldMatrix<K,cols,l>& M)
const
669 FieldMatrix<K,rows,l> C;
671 for (size_type i=0; i<
rows(); i++) {
672 for (size_type j=0; j<l; j++) {
674 for (size_type k=0; k<
cols(); k++)
675 C[i][j] += (*
this)[i][k]*M[k][j];
699 return asImp().mat_rows();
705 return asImp().mat_cols();
711 bool exists (size_type i, size_type j)
const
713 #ifdef DUNE_FMatrix_WITH_CHECKING
728 ElimPivot(std::vector<size_type> & pivot);
730 void swap(
int i,
int j);
733 void operator()(
const T&,
int,
int)
736 std::vector<size_type> & pivot_;
744 void swap(
int i,
int j);
746 void operator()(
const typename V::field_type& factor,
int k,
int i);
753 ElimDet(field_type&
sign) : sign_(sign)
759 void operator()(
const field_type&,
int,
int)
767 void luDecomposition(DenseMatrix<MAT>& A, Func func)
const;
771 template<
typename MAT>
772 DenseMatrix<MAT>::ElimPivot::ElimPivot(std::vector<size_type> & pivot)
775 typedef typename std::vector<size_type>::size_type size_type;
776 for(size_type i=0; i < pivot_.size(); ++i) pivot_[i]=i;
779 template<
typename MAT>
780 void DenseMatrix<MAT>::ElimPivot::swap(
int i,
int j)
785 template<
typename MAT>
787 DenseMatrix<MAT>::Elim<V>::Elim(V& rhs)
791 template<
typename MAT>
793 void DenseMatrix<MAT>::Elim<V>::swap(
int i,
int j)
795 std::swap((*rhs_)[i], (*rhs_)[j]);
798 template<
typename MAT>
800 void DenseMatrix<MAT>::
801 Elim<V>::operator()(
const typename V::field_type& factor,
int k,
int i)
803 (*rhs_)[k] -= factor*(*rhs_)[i];
805 template<
typename MAT>
806 template<
typename Func>
807 inline void DenseMatrix<MAT>::luDecomposition(DenseMatrix<MAT>& A, Func func)
const
809 typedef typename FieldTraits<value_type>::real_type
811 real_type norm = A.infinity_norm_real();
812 real_type pivthres = std::max( FMatrixPrecision< real_type >::absolute_limit(), norm * FMatrixPrecision< real_type >::pivoting_limit() );
813 real_type singthres = std::max( FMatrixPrecision< real_type >::absolute_limit(), norm * FMatrixPrecision< real_type >::singular_limit() );
816 for (size_type i=0; i<rows(); i++)
818 typename FieldTraits<value_type>::real_type pivmax=fvmeta::absreal(A[i][i]);
825 typename FieldTraits<value_type>::real_type abs(0.0);
826 for (size_type k=i+1; k<rows(); k++)
827 if ((abs=fvmeta::absreal(A[k][i]))>pivmax)
829 pivmax = abs; imax = k;
833 for (size_type j=0; j<rows(); j++)
834 std::swap(A[i][j],A[imax][j]);
840 if (pivmax<singthres)
841 DUNE_THROW(FMatrixError,
"matrix is singular");
844 for (size_type k=i+1; k<rows(); k++)
846 field_type factor = A[k][i]/A[i][i];
848 for (size_type j=i+1; j<rows(); j++)
849 A[k][j] -= factor*A[i][j];
855 template<
typename MAT>
857 inline void DenseMatrix<MAT>::solve(V& x,
const V& b)
const
861 DUNE_THROW(FMatrixError,
"Can't solve for a " << rows() <<
"x" << cols() <<
" matrix!");
865 #ifdef DUNE_FMatrix_WITH_CHECKING
866 if (fvmeta::absreal((*
this)[0][0])<FMatrixPrecision<>::absolute_limit())
867 DUNE_THROW(FMatrixError,
"matrix is singular");
869 x[0] = b[0]/(*this)[0][0];
872 else if (rows()==2) {
874 field_type detinv = (*this)[0][0]*(*this)[1][1]-(*this)[0][1]*(*this)[1][0];
875 #ifdef DUNE_FMatrix_WITH_CHECKING
876 if (fvmeta::absreal(detinv)<FMatrixPrecision<>::absolute_limit())
877 DUNE_THROW(FMatrixError,
"matrix is singular");
881 x[0] = detinv*((*this)[1][1]*b[0]-(*this)[0][1]*b[1]);
882 x[1] = detinv*((*this)[0][0]*b[1]-(*this)[1][0]*b[0]);
885 else if (rows()==3) {
887 field_type d = determinant();
888 #ifdef DUNE_FMatrix_WITH_CHECKING
889 if (fvmeta::absreal(d)<FMatrixPrecision<>::absolute_limit())
890 DUNE_THROW(FMatrixError,
"matrix is singular");
893 x[0] = (b[0]*(*this)[1][1]*(*this)[2][2] - b[0]*(*this)[2][1]*(*this)[1][2]
894 - b[1] *(*this)[0][1]*(*this)[2][2] + b[1]*(*this)[2][1]*(*this)[0][2]
895 + b[2] *(*this)[0][1]*(*this)[1][2] - b[2]*(*this)[1][1]*(*this)[0][2]) / d;
897 x[1] = ((*this)[0][0]*b[1]*(*this)[2][2] - (*this)[0][0]*b[2]*(*this)[1][2]
898 - (*this)[1][0] *b[0]*(*this)[2][2] + (*this)[1][0]*b[2]*(*this)[0][2]
899 + (*this)[2][0] *b[0]*(*this)[1][2] - (*this)[2][0]*b[1]*(*this)[0][2]) / d;
901 x[2] = ((*this)[0][0]*(*this)[1][1]*b[2] - (*this)[0][0]*(*this)[2][1]*b[1]
902 - (*this)[1][0] *(*this)[0][1]*b[2] + (*this)[1][0]*(*this)[2][1]*b[0]
903 + (*this)[2][0] *(*this)[0][1]*b[1] - (*this)[2][0]*(*this)[1][1]*b[0]) / d;
913 luDecomposition(A, elim);
916 for(
int i=rows()-1; i>=0; i--) {
917 for (size_type j=i+1; j<rows(); j++)
918 rhs[i] -= A[i][j]*x[j];
919 x[i] = rhs[i]/A[i][i];
924 template<
typename MAT>
925 inline void DenseMatrix<MAT>::invert()
929 DUNE_THROW(FMatrixError,
"Can't invert a " << rows() <<
"x" << cols() <<
" matrix!");
933 #ifdef DUNE_FMatrix_WITH_CHECKING
934 if (fvmeta::absreal((*
this)[0][0])<FMatrixPrecision<>::absolute_limit())
935 DUNE_THROW(FMatrixError,
"matrix is singular");
937 (*this)[0][0] = field_type( 1 ) / (*this)[0][0];
940 else if (rows()==2) {
942 field_type detinv = (*this)[0][0]*(*this)[1][1]-(*this)[0][1]*(*this)[1][0];
943 #ifdef DUNE_FMatrix_WITH_CHECKING
944 if (fvmeta::absreal(detinv)<FMatrixPrecision<>::absolute_limit())
945 DUNE_THROW(FMatrixError,
"matrix is singular");
947 detinv = field_type( 1 ) / detinv;
949 field_type temp=(*this)[0][0];
950 (*this)[0][0] = (*this)[1][1]*detinv;
951 (*this)[0][1] = -(*this)[0][1]*detinv;
952 (*this)[1][0] = -(*this)[1][0]*detinv;
953 (*this)[1][1] = temp*detinv;
959 std::vector<size_type> pivot(rows());
960 luDecomposition(A, ElimPivot(pivot));
961 DenseMatrix<MAT>& L=A;
962 DenseMatrix<MAT>& U=A;
967 for(size_type i=0; i<rows(); ++i)
971 for (size_type i=0; i<rows(); i++)
972 for (size_type j=0; j<i; j++)
973 for (size_type k=0; k<rows(); k++)
974 (*
this)[i][k] -= L[i][j]*(*this)[j][k];
977 for (size_type i=rows(); i>0;) {
979 for (size_type k=0; k<rows(); k++) {
980 for (size_type j=i+1; j<rows(); j++)
981 (*
this)[i][k] -= U[i][j]*(*this)[j][k];
982 (*this)[i][k] /= U[i][i];
986 for(size_type i=rows(); i>0; ) {
989 for(size_type j=0; j<rows(); ++j)
990 std::swap((*
this)[j][pivot[i]], (*this)[j][i]);
996 template<
typename MAT>
997 inline typename DenseMatrix<MAT>::field_type
998 DenseMatrix<MAT>::determinant()
const
1002 DUNE_THROW(FMatrixError,
"There is no determinant for a " << rows() <<
"x" << cols() <<
" matrix!");
1005 return (*
this)[0][0];
1008 return (*
this)[0][0]*(*this)[1][1] - (*this)[0][1]*(*this)[1][0];
1012 field_type t4 = (*this)[0][0] * (*this)[1][1];
1013 field_type t6 = (*this)[0][0] * (*this)[1][2];
1014 field_type t8 = (*this)[0][1] * (*this)[1][0];
1015 field_type t10 = (*this)[0][2] * (*this)[1][0];
1016 field_type t12 = (*this)[0][1] * (*this)[2][0];
1017 field_type t14 = (*this)[0][2] * (*this)[2][0];
1019 return (t4*(*
this)[2][2]-t6*(*
this)[2][1]-t8*(*
this)[2][2]+
1020 t10*(*
this)[2][1]+t12*(*
this)[1][2]-t14*(*
this)[1][1]);
1028 luDecomposition(A, ElimDet(det));
1030 catch (FMatrixError&)
1034 for (size_type i = 0; i < rows(); ++i)
1041 namespace DenseMatrixHelp {
1043 template <
typename K>
1047 inverse[0][0] = 1.0/matrix[0][0];
1048 return matrix[0][0];
1052 template <
typename K>
1060 template <
typename K>
1064 field_type det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
1065 field_type det_1 = 1.0/det;
1066 inverse[0][0] = matrix[1][1] * det_1;
1067 inverse[0][1] = - matrix[0][1] * det_1;
1068 inverse[1][0] = - matrix[1][0] * det_1;
1069 inverse[1][1] = matrix[0][0] * det_1;
1075 template <
typename K>
1079 field_type det = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
1080 field_type det_1 = 1.0/det;
1081 inverse[0][0] = matrix[1][1] * det_1;
1082 inverse[1][0] = - matrix[0][1] * det_1;
1083 inverse[0][1] = - matrix[1][0] * det_1;
1084 inverse[1][1] = matrix[0][0] * det_1;
1089 template <
typename K>
1093 field_type t4 = matrix[0][0] * matrix[1][1];
1094 field_type t6 = matrix[0][0] * matrix[1][2];
1095 field_type t8 = matrix[0][1] * matrix[1][0];
1096 field_type t10 = matrix[0][2] * matrix[1][0];
1097 field_type t12 = matrix[0][1] * matrix[2][0];
1098 field_type t14 = matrix[0][2] * matrix[2][0];
1100 field_type det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
1101 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
1102 field_type t17 = 1.0/det;
1104 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
1105 inverse[0][1] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
1106 inverse[0][2] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
1107 inverse[1][0] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
1108 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
1109 inverse[1][2] = -(t6-t10) * t17;
1110 inverse[2][0] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
1111 inverse[2][1] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
1112 inverse[2][2] = (t4-t8) * t17;
1118 template <
typename K>
1122 field_type t4 = matrix[0][0] * matrix[1][1];
1123 field_type t6 = matrix[0][0] * matrix[1][2];
1124 field_type t8 = matrix[0][1] * matrix[1][0];
1125 field_type t10 = matrix[0][2] * matrix[1][0];
1126 field_type t12 = matrix[0][1] * matrix[2][0];
1127 field_type t14 = matrix[0][2] * matrix[2][0];
1129 field_type det = (t4*matrix[2][2]-t6*matrix[2][1]-t8*matrix[2][2]+
1130 t10*matrix[2][1]+t12*matrix[1][2]-t14*matrix[1][1]);
1131 field_type t17 = 1.0/det;
1133 inverse[0][0] = (matrix[1][1] * matrix[2][2] - matrix[1][2] * matrix[2][1])*t17;
1134 inverse[1][0] = -(matrix[0][1] * matrix[2][2] - matrix[0][2] * matrix[2][1])*t17;
1135 inverse[2][0] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1])*t17;
1136 inverse[0][1] = -(matrix[1][0] * matrix[2][2] - matrix[1][2] * matrix[2][0])*t17;
1137 inverse[1][1] = (matrix[0][0] * matrix[2][2] - t14) * t17;
1138 inverse[2][1] = -(t6-t10) * t17;
1139 inverse[0][2] = (matrix[1][0] * matrix[2][1] - matrix[1][1] * matrix[2][0]) * t17;
1140 inverse[1][2] = -(matrix[0][0] * matrix[2][1] - t12) * t17;
1141 inverse[2][2] = (t4-t8) * t17;
1147 template<
class K,
int m,
int n,
int p >
1154 for( size_type i = 0; i < m; ++i )
1156 for( size_type j = 0; j < p; ++j )
1158 ret[ i ][ j ] = K( 0 );
1159 for( size_type k = 0; k < n; ++k )
1160 ret[ i ][ j ] += A[ i ][ k ] * B[ k ][ j ];
1166 template <
typename K,
int rows,
int cols>
1171 for(size_type i=0; i<cols(); i++)
1172 for(size_type j=0; j<cols(); j++)
1175 for(size_type k=0; k<rows(); k++)
1176 ret[i][j]+=matrix[k][i]*matrix[k][j];
1182 template <
typename MAT,
typename V1,
typename V2>
1186 assert(ret.
size() == matrix.
rows());
1189 for(size_type i=0; i<matrix.
rows(); ++i)
1192 for(size_type j=0; j<matrix.
cols(); ++j)
1194 ret[i] += matrix[i][j]*x[j];
1200 template <
typename K,
int rows,
int cols>
1206 for(size_type i=0; i<cols(); ++i)
1209 for(size_type j=0; j<rows(); ++j)
1210 ret[i] += matrix[j][i]*x[j];
1215 template <
typename K,
int rows,
int cols>
1216 static inline FieldVector<K,rows>
mult(
const FieldMatrix<K,rows,cols> &matrix,
const FieldVector<K,cols> & x)
1218 FieldVector<K,rows> ret;
1224 template <
typename K,
int rows,
int cols>
1225 static inline FieldVector<K,cols>
multTransposed(
const FieldMatrix<K,rows,cols> &matrix,
const FieldVector<K,rows> & x)
1227 FieldVector<K,cols> ret;
1236 template<
typename MAT>
1237 std::ostream& operator<< (std::ostream& s, const DenseMatrix<MAT>& a)
1240 s << a[i] << std::endl;
DenseMatrix & axpy(const field_type &k, const DenseMatrix< Other > &y)
vector space axpy operation (*this += k y)
Definition: densematrix.hh:362
FieldTraits< value_type >::real_type frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: densematrix.hh:554
DUNE_CONSTEXPR size_type size() const
Definition: fvector.hh:160
ConstIterator end() const
end iterator
Definition: densematrix.hh:296
ConstIterator beforeBegin() const
Definition: densematrix.hh:310
Traits::value_type value_type
export the type representing the field
Definition: densematrix.hh:199
ConstIterator begin() const
begin iterator
Definition: densematrix.hh:290
Iterator RowIterator
rename the iterators for easier access
Definition: densematrix.hh:250
A dense n x m matrix.
Definition: densematrix.hh:22
size_type size() const
size method
Definition: densevector.hh:296
const FieldTraits< typename DenseMatVecTraits< M >::value_type >::real_type real_type
Definition: densematrix.hh:28
Iterator begin()
begin iterator
Definition: densematrix.hh:255
void umhv(const X &x, Y &y) const
y += A^H x
Definition: densematrix.hh:457
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
MAT & rightmultiply(const DenseMatrix< M2 > &M)
Multiplies M from the right to this matrix.
Definition: densematrix.hh:634
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:103
DenseIterator< const DenseMatrix, const row_type, const_row_reference > ConstIterator
Iterator class for sequential access.
Definition: densematrix.hh:281
int sign(const T &val)
Return the sign of the value.
Definition: math.hh:119
void umtv(const X &x, Y &y) const
y += A^T x
Definition: densematrix.hh:443
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
Iterator end()
end iterator
Definition: densematrix.hh:261
Traits::row_reference row_reference
The type used to represent a reference to a row (usually row_type &)
Definition: densematrix.hh:214
DenseIterator< DenseMatrix, row_type, row_reference > Iterator
Iterator class for sequential access.
Definition: densematrix.hh:246
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
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: densevector.hh:643
Generic iterator class for dense vector and matrix implementations.
Definition: densevector.hh:125
MAT & leftmultiply(const DenseMatrix< M2 > &M)
Multiplies M from the left to this matrix.
Definition: densematrix.hh:617
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:27
size_type N() const
number of rows
Definition: densematrix.hh:685
FieldTraits< value_type >::real_type infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: densematrix.hh:570
void mv(const X &x, Y &y) const
y = A x
Definition: densematrix.hh:390
Definition: matvectraits.hh:29
DenseMatrix & operator/=(const field_type &k)
vector space division by scalar
Definition: densematrix.hh:353
FieldTraits< value_type >::real_type frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: densematrix.hh:562
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:18
DenseMatrix & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: densematrix.hh:345
ConstIterator beforeEnd() const
Definition: densematrix.hh:303
bool operator==(const DenseMatrix< Other > &y) const
Binary matrix comparison.
Definition: densematrix.hh:371
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
Traits::value_type block_type
export the type representing the components
Definition: densematrix.hh:205
T t
Definition: alignment.hh:34
field_type determinant() const
calculates the determinant of this matrix
void usmtv(const field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: densematrix.hh:525
Iterator beforeEnd()
Definition: densematrix.hh:268
remove_reference< row_reference >::type::Iterator ColIterator
rename the iterators for easier access
Definition: densematrix.hh:252
void invert()
Compute inverse.
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
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
Dune namespace.
Definition: alignment.hh:9
void istl_assign_to_fmatrix(DenseMatrix &denseMatrix, const K(&values)[M][N])
Definition: densematrix.hh:76
Base::size_type size_type
Definition: fmatrix.hh:80
bool exists(size_type i, size_type j) const
return true when (i,j) is in pattern
Definition: densematrix.hh:711
Default exception class for mathematical errors.
Definition: exceptions.hh:266
bool operator!=(const DenseMatrix< Other > &y) const
Binary matrix incomparison.
Definition: densematrix.hh:380
Implements a vector constructed from a given type representing a field and a compile-time given size...
A free function to provide the demangled class name of a given object or type as a string...
size_type cols() const
number of columns
Definition: densematrix.hh:703
void umv(const X &x, Y &y) const
y += A x
Definition: densematrix.hh:428
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: densematrix.hh:498
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
Some useful basic math stuff.
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
void usmhv(const field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: densematrix.hh:539
ConstIterator const_iterator
typedef for stl compliant access
Definition: densematrix.hh:283
vector space out of a tensor product of fields.
Definition: densematrix.hh:36
static void multTransposedMatrix(const FieldMatrix< K, rows, cols > &matrix, FieldMatrix< K, cols, cols > &ret)
calculates ret= A_t*A
Definition: fmatrix.hh:458
DenseMatrix & operator=(const RHS &rhs)
Definition: densematrix.hh:318
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
row_reference operator[](size_type i)
random access
Definition: densematrix.hh:228
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
you have to specialize this structure for any type that should be assignable to a DenseMatrix ...
Definition: densematrix.hh:71
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: densematrix.hh:484
void solve(V &x, const V &b) const
Solve system A x = b.
DenseMatrix & operator+=(const DenseMatrix< Other > &y)
vector space addition
Definition: densematrix.hh:328
Iterator iterator
typedef for stl compliant access
Definition: densematrix.hh:248
static void multAssign(const DenseMatrix< MAT > &matrix, const DenseVector< V1 > &x, DenseVector< V2 > &ret)
calculates ret = matrix * x
Definition: densematrix.hh:1183
void mmv(const X &x, Y &y) const
y -= A x
Definition: densematrix.hh:471
Various precision settings for calculations with FieldMatrix and FieldVector.
void mtv(const X &x, Y &y) const
y = A^T x
Definition: densematrix.hh:406
FieldTraits< value_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densematrix.hh:584
Traits::value_type field_type
export the type representing the field
Definition: densematrix.hh:202
void usmv(const field_type &alpha, const X &x, Y &y) const
y += alpha A x
Definition: densematrix.hh:512
const FieldTraits< typename DenseMatVecTraits< M >::value_type >::field_type field_type
Definition: densematrix.hh:27
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
Iterator beforeBegin()
Definition: densematrix.hh:275
remove_reference< const_row_reference >::type::ConstIterator ConstColIterator
rename the iterators for easier access
Definition: densematrix.hh:287
size_type size() const
size method (number of rows)
Definition: densematrix.hh:239
A dense n x m matrix.
Definition: densematrix.hh:35
ConstIterator ConstRowIterator
rename the iterators for easier access
Definition: densematrix.hh:285
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
Traits::derived_type derived_type
type of derived matrix class
Definition: densematrix.hh:196
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:171
FieldVector()
Constructor making default-initialized vector.
Definition: fvector.hh:108