3#ifndef DUNE_LOCALFUNCTIONS_UTILITY_LFEMATRIX_HH
4#define DUNE_LOCALFUNCTIONS_UTILITY_LFEMATRIX_HH
17 typedef LFEMatrix< F > This;
18 typedef std::vector< F > Row;
19 typedef std::vector<Row> RealMatrix;
24 operator const RealMatrix & ()
const
29 operator RealMatrix & ()
34 template <
class Vector>
35 void row(
const unsigned int row, Vector &vec )
const
38 for (
int i=0; i<cols(); ++i)
42 const Field &operator() (
const unsigned int row,
const unsigned int col )
const
46 return matrix_[ row ][ col ];
49 Field &operator() (
const unsigned int row,
const unsigned int col )
53 return matrix_[ row ][ col ];
56 unsigned int rows ()
const
61 unsigned int cols ()
const
66 const Field *rowPtr (
const unsigned int row )
const
69 return &(matrix_[row][0]);
72 Field *rowPtr (
const unsigned int row )
75 return &(matrix_[row][0]);
78 void resize (
const unsigned int rows,
const unsigned int cols )
81 for (
unsigned int i=0; i<rows; ++i)
82 matrix_[i].resize(cols);
89 assert( rows() == cols() );
90 std::vector<unsigned int> p(rows());
91 for (
unsigned int j=0; j<rows(); ++j)
93 for (
unsigned int j=0; j<rows(); ++j)
97 Field max = std::abs( (*
this)(j,j) );
98 for (
unsigned int i=j+1; i<rows(); ++i)
100 if ( std::abs( (*
this)(i,j) ) > max )
102 max = std::abs( (*
this)(i,j) );
106 if (max == Zero<Field>())
111 for (
unsigned int k=0; k<cols(); ++k)
112 std::swap( (*
this)(j,k), (*
this)(r,k) );
113 std::swap( p[j], p[r] );
116 Field hr = Unity<Field>()/(*this)(j,j);
117 for (
unsigned int i=0; i<rows(); ++i)
120 for (
unsigned int k=0; k<cols(); ++k)
123 for (
unsigned int i=0; i<rows(); ++i)
126 (*this)(i,k) -= (*
this)(i,j)*(*
this)(j,k);
133 for (
unsigned int i=0; i<rows(); ++i)
135 for (
unsigned int k=0; k<rows(); ++k)
136 hv[ p[k] ] = (*
this)(i,k);
137 for (
unsigned int k=0; k<rows(); ++k)
138 (*
this)(i,k) = hv[k];
145 unsigned int cols_,rows_;
148 template<
class Field >
149 inline std::ostream &operator<<(std::ostream &out,
const LFEMatrix<Field> &mat)
151 for (
unsigned int r=0; r<mat.rows(); ++r)
153 out << field_cast<double>(mat(r,0));
154 for (
unsigned int c=1; c<mat.cols(); ++c)
156 out <<
" , " << field_cast<double>(mat(r,c));
Dune namespace.
Definition: alignedallocator.hh:10
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:157