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>
43 const_iterator
end()
const
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_;
136 const RowIndexSet& s_;
156 template<
class M,
class X,
class TM,
class TD,
class T1>
166 template<
class B,
class TA,
int n,
int m>
169 template<
class M,
class X,
class TM,
class TD,
class T1>
238 virtual void setMatrix(
const Matrix&
mat,
const std::set<std::size_t>& mrs);
243 virtual void setMatrix(
const Matrix&
mat);
252 template<
class T,
class A,
int n,
int m>
255 template<
class I,
class S,
class D>
269 template<
typename Iter>
270 void addRowNnz(
const Iter&
row)
const;
272 template<
typename Iter,
typename Set>
273 void addRowNnz(
const Iter&
row,
const Set& s)
const;
277 template<
typename Iter>
282 void calcColstart()
const;
284 template<
typename Iter>
285 void copyValue(
const Iter&
row,
const CIter&
col)
const;
287 void copyValue(
const CIter&
col, size_type rowindex, size_type colidx)
const;
289 virtual void createMatrix()
const;
293 void allocateMatrixStorage()
const;
295 void allocateMarker();
302 template<
class T,
class A,
int n,
int m>
304 :
mat(&mat_), cols(mat_.N()), marker(0)
309 template<
class T,
class A,
int n,
int m>
311 :
mat(0), cols(0), marker(0)
314 template<
class T,
class A,
int n,
int m>
321 template<
class T,
class A,
int n,
int m>
322 template<
typename Iter>
325 mat->Nnz_+=row->getsize();
328 template<
class T,
class A,
int n,
int m>
329 template<
typename Iter,
typename Map>
330 void ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,
A> >::addRowNnz(
const Iter&
row,
331 const Map& indices)
const
333 typedef typename Iter::value_type::const_iterator RIter;
334 typedef typename Map::const_iterator MIter;
335 MIter siter =indices.
begin();
336 for(RIter entry=row->begin(); entry!=row->end(); ++entry)
338 for(; siter!=indices.end() && *siter<entry.index(); ++siter) ;
339 if(siter==indices.end())
341 if(*siter==entry.index())
347 template<
class T,
class A,
int n,
int m>
348 void ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,
A> >::allocate()
350 allocateMatrixStorage();
354 template<
class T,
class A,
int n,
int m>
355 void ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,
A> >::allocateMatrixStorage()
const
359 mat->values=
new T[
mat->Nnz_];
360 mat->rowindex=
new int[
mat->Nnz_];
361 mat->colstart=
new int[cols+1];
364 template<
class T,
class A,
int n,
int m>
365 void ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,
A> >::allocateMarker()
373 template<
class T,
class A,
int n,
int m>
374 template<
typename Iter>
377 DUNE_UNUSED_PARAMETER(row);
381 template<
class T,
class A,
int n,
int m>
386 assert(colindex*m+i<cols);
387 marker[colindex*m+i]+=n;
391 template<
class T,
class A,
int n,
int m>
392 void ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,
A> >::calcColstart()
const
397 mat->colstart[i+1]=
mat->colstart[i]+marker[i];
398 marker[i]=
mat->colstart[i];
402 template<
class T,
class A,
int n,
int m>
403 template<
typename Iter>
404 void ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,
A> >::copyValue(
const Iter&
row,
const CIter&
col)
const
409 template<
class T,
class A,
int n,
int m>
414 assert(colindex*m+j<cols-1 || (
int)marker[colindex*m+j]<
mat->colstart[colindex*m+j+1]);
415 assert((
int)marker[colindex*m+j]<
mat->Nnz_);
416 mat->rowindex[marker[colindex*m+j]]=rowindex*n+i;
417 mat->values[marker[colindex*m+j]]=(*col)[i][j];
418 ++marker[colindex*m+j];
423 template<
class T,
class A,
int n,
int m>
424 void ColCompMatrixInitializer<BCRSMatrix<FieldMatrix<T,n,m>,
A> >::createMatrix()
const
430 template<
class F,
class MRS>
433 typedef typename MRS::const_iterator Iter;
434 typedef typename std::iterator_traits<Iter>::value_type::const_iterator CIter;
435 for(Iter
row=mrs.begin();
row!= mrs.end(); ++
row)
436 initializer.addRowNnz(
row);
438 initializer.allocate();
440 for(Iter
row=mrs.begin();
row!= mrs.end(); ++
row) {
443 initializer.countEntries(
row,
col);
446 initializer.calcColstart();
448 for(Iter
row=mrs.begin();
row!= mrs.end(); ++
row) {
450 initializer.copyValue(
row,
col);
454 initializer.createMatrix();
457 template<
class F,
class M,
class S>
461 typedef typename MRS::RowIndexSet SIS;
462 typedef typename SIS::const_iterator SIter;
463 typedef typename MRS::const_iterator Iter;
464 typedef typename std::iterator_traits<Iter>::value_type row_type;
465 typedef typename row_type::const_iterator CIter;
471 initializer.allocate();
473 typedef typename MRS::Matrix::size_type size_type;
479 std::vector<size_type> subMatrixIndex(mrs.
matrix().
N(),
480 std::numeric_limits<size_type>::max());
483 subMatrixIndex[*index]=s++;
487 if(subMatrixIndex[
col.index()]!=std::numeric_limits<size_type>::max())
489 initializer.countEntries(subMatrixIndex[
col.index()]);
492 initializer.calcColstart();
496 if(subMatrixIndex[
col.index()]!=std::numeric_limits<size_type>::max())
498 initializer.copyValue(
col, subMatrixIndex[
row.index()], subMatrixIndex[
col.index()]);
500 initializer.createMatrix();
505 template<
class B,
class TA,
int n,
int m>
506 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::ColCompMatrix()
507 : N_(0), M_(0), Nnz_(0), values(0), rowindex(0), colstart(0)
510 template<
class B,
class TA,
int n,
int m>
511 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >
512 ::ColCompMatrix(
const Matrix&
mat)
513 : N_(n*mat.N()), M_(m*mat.M()), Nnz_(n*m*mat.nonzeroes())
516 template<
class B,
class TA,
int n,
int m>
517 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >&
518 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::operator=(
const Matrix&
mat)
526 template<
class B,
class TA,
int n,
int m>
527 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >&
528 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::operator=(
const ColCompMatrix&
mat)
536 colstart=
new int[M_+1];
537 for(
int i=0; i<=M_; ++i)
538 colstart[i]=
mat.colstart[i];
542 values =
new B[Nnz_];
543 rowindex =
new int[Nnz_];
545 for(
int i=0; i<Nnz_; ++i)
546 values[i]=
mat.values[i];
548 for(
int i=0; i<Nnz_; ++i)
549 rowindex[i]=
mat.rowindex[i];
554 template<
class B,
class TA,
int n,
int m>
555 void ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >
556 ::setMatrix(
const Matrix&
mat)
560 ColCompMatrixInitializer<Matrix> initializer(*
this);
565 template<
class B,
class TA,
int n,
int m>
566 void ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >
567 ::setMatrix(
const Matrix& mat,
const std::set<std::size_t>& mrs)
573 ColCompMatrixInitializer<Matrix> initializer(*
this);
578 template<
class B,
class TA,
int n,
int m>
579 ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::~ColCompMatrix()
585 template<
class B,
class TA,
int n,
int m>
586 void ColCompMatrix<BCRSMatrix<FieldMatrix<B,n,m>,TA> >::free()
const Matrix::row_type & dereference() const
Definition: colcompmatrix.hh:97
Matrix::size_type size_type
Definition: colcompmatrix.hh:178
Matrix::ConstRowIterator const_iterator
The matrix row iterator type.
Definition: colcompmatrix.hh:27
size_type N() const
Get the number of rows.
Definition: colcompmatrix.hh:195
Provides access to an iterator over an arbitrary subset of matrix rows.
Definition: colcompmatrix.hh:59
Implementation of the BCRSMatrix class.
size_type cols
Definition: colcompmatrix.hh:298
std::size_t countEntries(const BlockVector< FieldVector< T, i >, A > &vector)
Definition: matrixmarket.hh:886
Row row
Definition: matrixmatrix.hh:345
Definition: basearray.hh:19
const RowIndexSet & rowIndexSet() const
Definition: colcompmatrix.hh:81
A::size_type size_type
The type for the index access and the size.
Definition: bcrsmatrix.hh:447
const_iterator end() const
Get the row iterator at the end of all rows.
Definition: colcompmatrix.hh:43
This file implements a vector space as a tensor product of a given vector space. The number of compon...
VariableBlockVector< T, A >::window_type row_type
The type implementing a matrix row.
Definition: matrix.hh:38
S RowIndexSet
the type of the set of valid row indices.
Definition: colcompmatrix.hh:65
const_iterator end() const
Get the row iterator at the end of all rows.
Definition: colcompmatrix.hh:127
Matrix & mat
Definition: matrixmatrix.hh:343
M Matrix
The type of the matrix.
Definition: colcompmatrix.hh:25
size_type * marker
Definition: colcompmatrix.hh:299
Inititializer for the ColCompMatrix as needed by OverlappingSchwarz.
Definition: colcompmatrix.hh:153
int Nnz_
Definition: colcompmatrix.hh:246
int * colstart
Definition: colcompmatrix.hh:249
Col col
Definition: matrixmatrix.hh:347
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:412
B * values
Definition: colcompmatrix.hh:247
ColCompMatrix * mat
Definition: colcompmatrix.hh:297
Matrix & A
Definition: matrixmatrix.hh:216
size_type index() const
return index
Definition: bcrsmatrix.hh:555
Matrix::size_type size_type
Definition: colcompmatrix.hh:261
VariableBlockVector< T, A >::ConstIterator ConstRowIterator
Const iterator over the matrix rows.
Definition: matrix.hh:50
RowIndexSet::value_type index() const
Definition: colcompmatrix.hh:109
Matrix::row_type::const_iterator CIter
Definition: colcompmatrix.hh:260
RowIterator begin()
Get iterator to first row.
Definition: matrix.hh:79
size_type N() const
Return the number of rows.
Definition: matrix.hh:160
Definition: colcompmatrix.hh:160
Definition: matrixutils.hh:24
The matrix row iterator type.
Definition: colcompmatrix.hh:87
BCRSMatrix< FieldMatrix< B, n, m >, TA > Matrix
The type of the matrix to convert.
Definition: colcompmatrix.hh:175
Sequential overlapping Schwarz preconditioner.
Definition: colcompmatrix.hh:157
B * getValues() const
Definition: colcompmatrix.hh:214
void copyToColCompMatrix(F &initializer, const MRS &mrs)
Definition: colcompmatrix.hh:431
MatrixRowSet(const Matrix &m)
Construct an row set over all matrix rows.
Definition: colcompmatrix.hh:33
Initializer for SuperLU Matrices representing the subdomains.
Definition: overlappingschwarz.hh:42
Utility class for converting an ISTL Matrix into a column-compressed matrix.
Definition: colcompmatrix.hh:144
const Matrix & matrix() const
Definition: colcompmatrix.hh:76
void increment()
Definition: colcompmatrix.hh:105
Iterator access to matrix rows
Definition: bcrsmatrix.hh:526
void copyToColCompMatrix(F &initializer, const MatrixRowSubset< M, S > &mrs)
Definition: colcompmatrix.hh:458
bool equals(const const_iterator &o) const
Definition: colcompmatrix.hh:101
Provides access to an iterator over all matrix rows.
Definition: colcompmatrix.hh:21
Dune::BCRSMatrix< FieldMatrix< T, n, m >, A > Matrix
Definition: colcompmatrix.hh:258
MatrixRowSubset(const Matrix &m, const RowIndexSet &s)
Construct an row set over all matrix rows.
Definition: colcompmatrix.hh:72
Dune::ColCompMatrix< Matrix > ColCompMatrix
Definition: colcompmatrix.hh:259
int * rowindex
Definition: colcompmatrix.hh:248
const_iterator begin() const
Get the row iterator at the first row.
Definition: colcompmatrix.hh:38
int * getColStart() const
Definition: colcompmatrix.hh:224
const_iterator begin() const
Get the row iterator at the first row.
Definition: colcompmatrix.hh:122
const_iterator(typename Matrix::const_iterator firstRow, typename RowIndexSet::const_iterator pos)
Definition: colcompmatrix.hh:91
size_type M() const
Get the number of columns.
Definition: colcompmatrix.hh:209
size_type nnz() const
Definition: colcompmatrix.hh:200
M Matrix
the type of the matrix class.
Definition: colcompmatrix.hh:63
int * getRowIndex() const
Definition: colcompmatrix.hh:219