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_)
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_; }
89 return matrix_[row][col];
98 return matrix_[row][col];
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];
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];
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;
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;
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];
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;
Definition: bindguard.hh:11
OutStreamInterface< StreamTraits > & operator<<(OutStreamInterface< StreamTraits > &out, const DiscreteFunctionInterface< Impl > &df)
write a discrete function into an output stream
Definition: discretefunction_inline.hh:396
DenseMatrix based on std::vector< std::vector< T > >
Definition: blockmatrix.hh:24
void resize(int rows, int cols)
Definition: blockmatrix.hh:60
DenseMatrix< T > & operator=(const T &val)
set all values of the matrix to given value
Definition: blockmatrix.hh:236
void multTransposed(const RowType &vec, RowType &result) const
Definition: blockmatrix.hh:143
int rows() const
Definition: blockmatrix.hh:78
int cols() const
Definition: blockmatrix.hh:79
DenseMatrix< T > & operator+=(const DenseMatrix &org)
add matrix
Definition: blockmatrix.hh:259
void multiplyTransposed(const DenseMatrix &A, const DenseMatrix &B)
Definition: blockmatrix.hh:183
void multiply(const DenseMatrix &A, const DenseMatrix &B)
Definition: blockmatrix.hh:159
void mult(const RowType &vec, RowType &result) const
Definition: blockmatrix.hh:137
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
void mult(const T *vec, RowType &result) const
Definition: blockmatrix.hh:105
std::vector< T > RowType
remember the value type
Definition: blockmatrix.hh:28
void clear()
Definition: blockmatrix.hh:300
T Ttype
Definition: blockmatrix.hh:26
void multOEM(const T *vec, T *result) const
Definition: blockmatrix.hh:122
RowType & operator[](int row)
Definition: blockmatrix.hh:101
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
T & operator()(int row, int col)
Definition: blockmatrix.hh:82
DenseMatrix()
Definition: blockmatrix.hh:39