Go to the documentation of this file.
3 #ifndef DUNE_ISTL_COLCOMPMATRIX_HH
4 #define DUNE_ISTL_COLCOMPMATRIX_HH
7 #include <dune/common/fmatrix.hh>
8 #include <dune/common/fvector.hh>
9 #include <dune/common/typetraits.hh>
10 #include <dune/common/unused.hh>
58 template<
class M,
class S>
88 :
public ForwardIteratorFacade<const_iterator, const typename Matrix::row_type>
92 typename RowIndexSet::const_iterator pos)
93 : firstRow_(firstRow), pos_(pos)
99 return *(firstRow_+ *pos_);
109 typename RowIndexSet::value_type
index()
const
116 typename Matrix::const_iterator firstRow_;
118 typename RowIndexSet::const_iterator pos_;
156 template<
class M,
class X,
class TM,
class TD,
class T1>
159 template<
class T,
bool flag>
166 template<
class B,
class TA,
int n,
int m>
235 virtual void setMatrix(
const Matrix&
mat,
const std::set<std::size_t>& mrs);
240 virtual void setMatrix(
const Matrix&
mat);
249 template<
class T,
class A,
int n,
int m>
252 template<
class I,
class S,
class D>
266 template<
typename Iter>
267 void addRowNnz(
const Iter& row)
const;
269 template<
typename Iter,
typename Set>
270 void addRowNnz(
const Iter& row,
const Set& s)
const;
274 template<
typename Iter>
279 void calcColstart()
const;
281 template<
typename Iter>
282 void copyValue(
const Iter& row,
const CIter&
col)
const;
286 virtual void createMatrix()
const;
290 void allocateMatrixStorage()
const;
292 void allocateMarker();
299 template<
class T,
class A,
int n,
int m>
301 :
mat(&mat_), cols(mat_.M()), marker(0)
306 template<
class T,
class A,
int n,
int m>
308 :
mat(0), cols(0), marker(0)
311 template<
class T,
class A,
int n,
int m>
318 template<
class T,
class A,
int n,
int m>
319 template<
typename Iter>
322 mat->Nnz_+=row->getsize();
325 template<
class T,
class A,
int n,
int m>
326 template<
typename Iter,
typename Map>
328 const Map& indices)
const
330 typedef typename Iter::value_type::const_iterator RIter;
331 typedef typename Map::const_iterator MIter;
332 MIter siter =indices.
begin();
333 for(RIter entry=row->begin(); entry!=row->end(); ++entry)
335 for(; siter!=indices.end() && *siter<entry.index(); ++siter) ;
336 if(siter==indices.end())
338 if(*siter==entry.index())
344 template<
class T,
class A,
int n,
int m>
347 allocateMatrixStorage();
351 template<
class T,
class A,
int n,
int m>
356 mat->values=
new T[
mat->Nnz_];
357 mat->rowindex=
new int[
mat->Nnz_];
358 mat->colstart=
new int[cols+1];
361 template<
class T,
class A,
int n,
int m>
370 template<
class T,
class A,
int n,
int m>
371 template<
typename Iter>
374 DUNE_UNUSED_PARAMETER(row);
378 template<
class T,
class A,
int n,
int m>
383 assert(colindex*m+i<cols);
384 marker[colindex*m+i]+=n;
388 template<
class T,
class A,
int n,
int m>
394 mat->colstart[i+1]=
mat->colstart[i]+marker[i];
395 marker[i]=
mat->colstart[i];
399 template<
class T,
class A,
int n,
int m>
400 template<
typename Iter>
403 copyValue(
col, row.index(),
col.index());
406 template<
class T,
class A,
int n,
int m>
411 assert(colindex*m+j<cols-1 || (
int)marker[colindex*m+j]<
mat->colstart[colindex*m+j+1]);
412 assert((
int)marker[colindex*m+j]<
mat->Nnz_);
413 mat->rowindex[marker[colindex*m+j]]=rowindex*n+i;
414 mat->values[marker[colindex*m+j]]=(*col)[i][j];
415 ++marker[colindex*m+j];
420 template<
class T,
class A,
int n,
int m>
427 template<
class F,
class MRS>
430 typedef typename MRS::const_iterator Iter;
431 typedef typename std::iterator_traits<Iter>::value_type::const_iterator CIter;
432 for(Iter row=mrs.begin(); row!= mrs.end(); ++row)
433 initializer.addRowNnz(row);
435 initializer.allocate();
437 for(Iter row=mrs.begin(); row!= mrs.end(); ++row) {
439 for(CIter
col=row->begin();
col != row->end(); ++
col)
440 initializer.countEntries(row,
col);
443 initializer.calcColstart();
445 for(Iter row=mrs.begin(); row!= mrs.end(); ++row) {
446 for(CIter
col=row->begin();
col != row->end(); ++
col) {
447 initializer.copyValue(row,
col);
451 initializer.createMatrix();
454 template<
class F,
class M,
class S>
458 typedef typename MRS::RowIndexSet SIS;
459 typedef typename SIS::const_iterator SIter;
460 typedef typename MRS::const_iterator Iter;
461 typedef typename std::iterator_traits<Iter>::value_type row_type;
462 typedef typename row_type::const_iterator CIter;
465 for(Iter row=mrs.
begin(); row!= mrs.
end(); ++row)
468 initializer.allocate();
470 typedef typename MRS::Matrix::size_type size_type;
476 std::vector<size_type> subMatrixIndex(mrs.
matrix().
N(),
477 std::numeric_limits<size_type>::max());
480 subMatrixIndex[*index]=s++;
482 for(Iter row=mrs.
begin(); row!= mrs.
end(); ++row)
483 for(CIter
col=row->begin();
col != row->end(); ++
col) {
484 if(subMatrixIndex[
col.index()]!=std::numeric_limits<size_type>::max())
486 initializer.countEntries(subMatrixIndex[
col.index()]);
489 initializer.calcColstart();
491 for(Iter row=mrs.
begin(); row!= mrs.
end(); ++row)
492 for(CIter
col=row->begin();
col != row->end(); ++
col) {
493 if(subMatrixIndex[
col.index()]!=std::numeric_limits<size_type>::max())
495 initializer.copyValue(
col, subMatrixIndex[row.index()], subMatrixIndex[
col.index()]);
497 initializer.createMatrix();
502 template<
class B,
class TA,
int n,
int m>
503 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::ColCompMatrix()
504 : N_(0), M_(0), Nnz_(0), values(0), rowindex(0), colstart(0)
507 template<
class B,
class TA,
int n,
int m>
508 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >
509 ::ColCompMatrix(
const Matrix&
mat)
510 : N_(n*
mat.N()), M_(m*
mat.M()), Nnz_(n*m*
mat.nonzeroes())
513 template<
class B,
class TA,
int n,
int m>
514 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >&
515 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::operator=(
const Matrix&
mat)
523 template<
class B,
class TA,
int n,
int m>
524 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >&
525 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::operator=(
const ColCompMatrix&
mat)
533 colstart=
new int[M_+1];
534 for(
int i=0; i<=M_; ++i)
535 colstart[i]=
mat.colstart[i];
539 values =
new B[Nnz_];
540 rowindex =
new int[Nnz_];
542 for(
int i=0; i<Nnz_; ++i)
543 values[i]=
mat.values[i];
545 for(
int i=0; i<Nnz_; ++i)
546 rowindex[i]=
mat.rowindex[i];
551 template<
class B,
class TA,
int n,
int m>
552 void ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >
553 ::setMatrix(
const Matrix&
mat)
557 ColCompMatrixInitializer<Matrix> initializer(*
this);
562 template<
class B,
class TA,
int n,
int m>
563 void ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >
564 ::setMatrix(
const Matrix&
mat,
const std::set<std::size_t>& mrs)
570 ColCompMatrixInitializer<Matrix> initializer(*
this);
575 template<
class B,
class TA,
int n,
int m>
576 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::~ColCompMatrix()
582 template<
class B,
class TA,
int n,
int m>
583 void ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::free()
const_iterator end() const
Get the row iterator at the end of all rows.
Definition: colcompmatrix.hh:127
B * values
Definition: colcompmatrix.hh:244
const_iterator begin() const
Get the row iterator at the first row.
Definition: colcompmatrix.hh:38
Provides access to an iterator over an arbitrary subset of matrix rows.
Definition: colcompmatrix.hh:59
bool equals(const const_iterator &o) const
Definition: colcompmatrix.hh:101
const_iterator end() const
Get the row iterator at the end of all rows.
Definition: colcompmatrix.hh:43
Dune::ColCompMatrix< Matrix > ColCompMatrix
Definition: colcompmatrix.hh:256
M Matrix
The type of the matrix.
Definition: colcompmatrix.hh:25
Matrix::size_type size_type
Definition: colcompmatrix.hh:258
void increment()
Definition: colcompmatrix.hh:105
Matrix & mat
Definition: matrixmatrix.hh:345
int * rowindex
Definition: colcompmatrix.hh:245
A generic dynamic dense matrix.
Definition: matrix.hh:554
int * getRowIndex() const
Definition: colcompmatrix.hh:217
void copyToColCompMatrix(F &initializer, const MRS &mrs)
Definition: colcompmatrix.hh:428
size_type M() const
Get the number of columns.
Definition: colcompmatrix.hh:207
MatrixRowSubset(const Matrix &m, const RowIndexSet &s)
Construct an row set over all matrix rows.
Definition: colcompmatrix.hh:72
int * getColStart() const
Definition: colcompmatrix.hh:222
Definition: matrixutils.hh:25
ConstIterator class for sequential access.
Definition: matrix.hh:397
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:422
A::size_type size_type
The type for the index access and the size.
Definition: bcrsmatrix.hh:457
void copyToColCompMatrix(F &initializer, const MatrixRowSubset< M, S > &mrs)
Definition: colcompmatrix.hh:455
Iterator access to matrix rows
Definition: bcrsmatrix.hh:536
const_iterator(typename Matrix::const_iterator firstRow, typename RowIndexSet::const_iterator pos)
Definition: colcompmatrix.hh:91
size_type nnz() const
Definition: colcompmatrix.hh:198
std::size_t countEntries(const BlockVector< FieldVector< T, i >, A > &vector)
Definition: matrixmarket.hh:886
RowIndexSet::value_type index() const
Definition: colcompmatrix.hh:109
RowIterator begin()
Get iterator to first row.
Definition: matrix.hh:609
Sequential overlapping Schwarz preconditioner.
Definition: colcompmatrix.hh:157
Implementation of the BCRSMatrix class.
MatrixImp::DenseMatrixBase< T, A >::window_type row_type
The type implementing a matrix row.
Definition: matrix.hh:568
const_iterator begin() const
Get the row iterator at the first row.
Definition: colcompmatrix.hh:122
int Nnz_
Definition: colcompmatrix.hh:243
const Matrix::row_type & dereference() const
Definition: colcompmatrix.hh:97
size_type cols
Definition: colcompmatrix.hh:295
Provides access to an iterator over all matrix rows.
Definition: colcompmatrix.hh:21
Matrix::ConstRowIterator const_iterator
The matrix row iterator type.
Definition: colcompmatrix.hh:27
Matrix::size_type size_type
Definition: colcompmatrix.hh:176
const RowIndexSet & rowIndexSet() const
Definition: colcompmatrix.hh:81
int * colstart
Definition: colcompmatrix.hh:246
size_type * marker
Definition: colcompmatrix.hh:296
size_type N() const
Return the number of rows.
Definition: matrix.hh:690
M Matrix
the type of the matrix class.
Definition: colcompmatrix.hh:63
Matrix::row_type::const_iterator CIter
Definition: colcompmatrix.hh:257
const Matrix & matrix() const
Definition: colcompmatrix.hh:76
Definition: allocator.hh:7
MatrixRowSet(const Matrix &m)
Construct an row set over all matrix rows.
Definition: colcompmatrix.hh:33
Inititializer for the ColCompMatrix as needed by OverlappingSchwarz.
Definition: colcompmatrix.hh:153
ColCompMatrix * mat
Definition: colcompmatrix.hh:294
Col col
Definition: matrixmatrix.hh:349
B * getValues() const
Definition: colcompmatrix.hh:212
BCRSMatrix< FieldMatrix< B, n, m >, TA > Matrix
The type of the matrix to convert.
Definition: colcompmatrix.hh:173
This file implements a vector space as a tensor product of a given vector space. The number of compon...
The matrix row iterator type.
Definition: colcompmatrix.hh:87
Initializer for SuperLU Matrices representing the subdomains.
Definition: overlappingschwarz.hh:42
S RowIndexSet
the type of the set of valid row indices.
Definition: colcompmatrix.hh:65
size_type N() const
Get the number of rows.
Definition: colcompmatrix.hh:193
Definition: colcompmatrix.hh:160
Utility class for converting an ISTL Matrix into a column-compressed matrix.
Definition: colcompmatrix.hh:144