5#ifndef DUNE_LOCALFUNCTIONS_UTILITY_LFEMATRIX_HH
6#define DUNE_LOCALFUNCTIONS_UTILITY_LFEMATRIX_HH
19 typedef LFEMatrix< F > This;
20 typedef std::vector< F > Row;
21 typedef std::vector<Row> RealMatrix;
26 operator const RealMatrix & ()
const
31 operator RealMatrix & ()
36 template <
class Vector>
37 void row(
const unsigned int row, Vector &vec )
const
40 for (
int i=0; i<cols(); ++i)
44 const Field &operator() (
const unsigned int row,
const unsigned int col )
const
48 return matrix_[ row ][ col ];
51 Field &operator() (
const unsigned int row,
const unsigned int col )
55 return matrix_[ row ][ col ];
58 unsigned int rows ()
const
63 unsigned int cols ()
const
68 const Field *rowPtr (
const unsigned int row )
const
71 return &(matrix_[row][0]);
74 Field *rowPtr (
const unsigned int row )
77 return &(matrix_[row][0]);
80 void resize (
const unsigned int rows,
const unsigned int cols )
83 for (
unsigned int i=0; i<rows; ++i)
84 matrix_[i].resize(cols);
92 assert( rows() == cols() );
93 std::vector<unsigned int> p(rows());
94 for (
unsigned int j=0; j<rows(); ++j)
96 for (
unsigned int j=0; j<rows(); ++j)
100 Field
max = abs( (*
this)(j,j) );
101 for (
unsigned int i=j+1; i<rows(); ++i)
103 if ( abs( (*
this)(i,j) ) >
max )
105 max = abs( (*
this)(i,j) );
109 if (
max == Zero<Field>())
114 for (
unsigned int k=0; k<cols(); ++k)
115 std::swap( (*
this)(j,k), (*
this)(r,k) );
116 std::swap( p[j], p[r] );
119 Field hr = Unity<Field>()/(*this)(j,j);
120 for (
unsigned int i=0; i<rows(); ++i)
123 for (
unsigned int k=0; k<cols(); ++k)
126 for (
unsigned int i=0; i<rows(); ++i)
129 (*this)(i,k) -= (*
this)(i,j)*(*
this)(j,k);
136 for (
unsigned int i=0; i<rows(); ++i)
138 for (
unsigned int k=0; k<rows(); ++k)
139 hv[ p[k] ] = (*
this)(i,k);
140 for (
unsigned int k=0; k<rows(); ++k)
141 (*
this)(i,k) = hv[k];
148 unsigned int cols_,rows_;
151 template<
class Field >
152 inline std::ostream &operator<<(std::ostream &out,
const LFEMatrix<Field> &mat)
154 for (
unsigned int r=0; r<mat.rows(); ++r)
156 out << field_cast<double>(mat(r,0));
157 for (
unsigned int c=1; c<mat.cols(); ++c)
159 out <<
" , " << field_cast<double>(mat(r,c));
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:81
Dune namespace.
Definition: alignedallocator.hh:13
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:159