1#ifndef DUNE_FEM_BLOCKSPMATRIX_HH 
    2#define DUNE_FEM_BLOCKSPMATRIX_HH 
   30      typedef std::vector < RowType > MatrixType;
 
   48        matrix_(org.matrix_) , rows_(org.rows_) , cols_(org.cols_)
 
   60      void resize(
int rows, 
int cols)
 
   62        if( (rows == rows_) && (cols == cols_) ) return ;
 
   68        for(
int row=0; row<rows_; ++row)
 
   70          matrix_[row].resize(cols);
 
   71          for(
int col=0; col<cols_; ++col) matrix_[row][col] = 0;
 
   78      int rows()
 const {
return rows_; }
 
   79      int cols()
 const {
return cols_; }
 
   82      T& operator() (
int row, 
int col)
 
   89        return matrix_[row][col];
 
   91      const T& operator() (
int row, 
int col)
 const 
   98        return matrix_[row][col];
 
  101      RowType & operator [] (
int row) { 
return matrix_[row]; }
 
  102      const RowType & operator [] (
int row)
 const { 
return matrix_[row]; }
 
  105      void mult(
const T * vec, 
RowType & result)
 const 
  107        assert( ((
int) result.size() != rows()) ?
 
  108            (std::cout << result.size() << 
" s|r " << rows() << 
"\n",0) : 1 );
 
  109        const int nRow= rows();
 
  110        const int nCol= cols();
 
  111        for(
int row=0; row<nRow; ++row)
 
  114          for(
int col=0; col<nCol; ++col)
 
  116            result[row] += matrix_[row][col]*vec[col];
 
  122      void multOEM(
const T * vec, T * result)
 const 
  124        const int nRow= rows();
 
  125        const int nCol= cols();
 
  126        for(
int row=0; row<nRow; ++row)
 
  129          for(
int col=0; col<nCol; ++col)
 
  131            result[row] += matrix_[row][col]*vec[col];
 
  139        this->mult(&vec[0],result);
 
  145        assert( (
int) result.size() == cols() );
 
  146        const int nCols = cols();
 
  147        const int nRows = rows();
 
  148        for(
int col=0; col<nCols; ++col)
 
  151          for(
int row=0; row<nRows; ++row)
 
  153            result[col] += matrix_[row][col]*vec[row];
 
  159      void multiply(
const DenseMatrix & A, 
const DenseMatrix & B)
 
  161        assert( A.cols() == B.rows() );
 
  163        resize( A.rows() , B.cols() );
 
  165        const int nRows = rows();
 
  166        const int nCols = cols();
 
  167        const int Acols = A.cols();
 
  168        for(
int row=0; row<nRows; ++row)
 
  170          for(
int col=0; col<nCols; ++col)
 
  173            for(
int k=0; k<Acols; ++k)
 
  175              sum += A[row][k] * B[k][col];
 
  177            matrix_[row][col] = sum;
 
  183      void multiplyTransposed(
const DenseMatrix & A, 
const DenseMatrix & B)
 
  185        assert( A.cols() == B.cols() );
 
  187        resize(A.rows() , B.rows());
 
  189        for(
int row=0; row<rows(); ++row)
 
  191          for(
int col=0; col<cols(); ++col)
 
  194            for(
int k=0; k<A.cols(); ++k)
 
  196              sum += A[row][k] * B[col][k];
 
  198            matrix_[row][col] = sum;
 
  206        resize(A.cols() , A.cols());
 
  208        for(
int row=0; row<rows(); ++row)
 
  210          for(
int col=0; col<cols(); ++col)
 
  213            const int aRows = A.rows();
 
  214            for(
int k=0; k<aRows; ++k)
 
  216              sum += A[k][row] * A[k][col];
 
  218            matrix_[row][col] = sum;
 
  226        for(
int row=0; row<rows(); ++row)
 
  228          for(
int col=0; col<cols(); ++col)
 
  230            matrix_[row][col] *= val;
 
  238        for(
int row=0; row<rows(); ++row)
 
  240          for(
int col=0; col<cols(); ++col)
 
  242            matrix_[row][col] = val;
 
  254        matrix_ = org.matrix_;
 
  261        const int nRows = rows();
 
  262        const int nCols = cols();
 
  263        assert( nRows == org.rows() );
 
  264        assert( nCols == org.cols() );
 
  265        for(
int row=0; row<nRows; ++row)
 
  267          for(
int col=0; col<nCols; ++col)
 
  269            matrix_[row][col] += org.matrix_[row][col];
 
  278        assert( rows() == rows() );
 
  279        assert( cols() == org.cols() );
 
  280        for(
int row=0; row<rows(); ++row)
 
  282          for(
int col=0; col<cols(); ++col)
 
  283            matrix_[row][col] -= org.matrix_[row][col];
 
  289      void print(std::ostream & s=std::cout)
 const 
  291        for(
int i=0; i<rows(); ++i)
 
  293          for(
int j=0; j<cols(); ++j)
 
  294            s << matrix_[i][j] << 
" ";
 
  302        for(
int row=0; row<rows(); ++row)
 
  304          for(
int col=0; col<cols(); ++col)
 
  305            matrix_[row][col] = 0;
 
  312    std::ostream& operator<< (std::ostream& s, 
const DenseMatrix<K> & matrix)
 
DenseMatrix based on std::vector< std::vector< T > >
Definition: blockmatrix.hh:24
 
DenseMatrix< T > & operator=(const T &val)
set all values of the matrix to given value
Definition: blockmatrix.hh:236
 
DenseMatrix< T > & operator+=(const DenseMatrix &org)
add matrix
Definition: blockmatrix.hh:259
 
DenseMatrix(int rows, int cols)
Definition: blockmatrix.hh:55
 
void scale(const T &val)
scale matrix with scalar
Definition: blockmatrix.hh:224
 
void print(std::ostream &s=std::cout) const
print matrix
Definition: blockmatrix.hh:289
 
std::vector< T > RowType
remember the value type
Definition: blockmatrix.hh:28
 
DenseMatrix< T > & operator-=(const DenseMatrix &org)
substract matrix
Definition: blockmatrix.hh:276
 
DenseMatrix(const DenseMatrix< T > &org)
Copy Constructor.
Definition: blockmatrix.hh:47
 
void multiply_AT_A(const DenseMatrix &A)
this = A^T * A
Definition: blockmatrix.hh:204
 
Dune namespace.
Definition: alignedallocator.hh:13