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>
11 #include <dune/common/scalarmatrixview.hh>
59 template<
class M,
class S>
89 :
public ForwardIteratorFacade<const_iterator, const typename Matrix::row_type>
93 typename RowIndexSet::const_iterator pos)
94 : firstRow_(firstRow), pos_(pos)
100 return *(firstRow_+ *pos_);
110 typename RowIndexSet::value_type
index()
const
117 typename Matrix::const_iterator firstRow_;
119 typename RowIndexSet::const_iterator pos_;
146 template<
class M,
class I =
int>
149 template<
class M,
class X,
class TM,
class TD,
class T1>
152 template<
class T,
bool flag>
160 template<
class Mat,
class I =
int>
165 using B =
typename Mat::field_type;
253 template<
class M,
class I>
256 template<
class IList,
class S,
class D>
269 template <
class Block=
typename M::block_type>
271 typename std::enable_if_t<Dune::IsNumber<Block>::value>* sfinae =
nullptr);
277 template <
class Block=
typename M::block_type>
279 typename std::enable_if_t<!Dune::IsNumber<Block>::value>* sfinae =
nullptr);
286 template<
typename Iter>
289 template<
typename Iter,
typename FullMatrixIndex>
290 void addRowNnz(
const Iter& row,
const std::set<FullMatrixIndex>& indices)
const;
292 template<
typename Iter,
typename SubMatrixIndex>
293 void addRowNnz(
const Iter& row,
const std::vector<SubMatrixIndex>& indices)
const;
297 template<
typename Iter>
304 template<
typename Iter>
327 template<
class M,
class I>
328 template <
class Block>
330 :
mat(&mat_), cols(mat_.M())
338 template<
class M,
class I>
339 template <
class Block>
341 :
mat(&mat_), cols(mat_.M())
344 n = M::block_type::rows;
345 m = M::block_type::cols;
350 template<
class M,
class I>
352 :
mat(0), cols(0), n(0), m(0)
355 template<
class M,
class I>
356 template<
typename Iter>
359 mat->Nnz_+=row->getsize();
362 template<
class M,
class I>
363 template<
typename Iter,
typename FullMatrixIndex>
365 const std::set<FullMatrixIndex>& indices)
const
367 typedef typename Iter::value_type::const_iterator RIter;
368 typedef typename std::set<FullMatrixIndex>::const_iterator MIter;
369 MIter siter =indices.begin();
370 for(RIter entry=row->begin(); entry!=row->end(); ++entry)
372 for(; siter!=indices.end() && *siter<entry.index(); ++siter) ;
373 if(siter==indices.end())
375 if(*siter==entry.index())
381 template<
class M,
class I>
382 template<
typename Iter,
typename SubMatrixIndex>
384 const std::vector<SubMatrixIndex>& indices)
const
386 using RIter =
typename Iter::value_type::const_iterator;
387 for(RIter entry=row->begin(); entry!=row->end(); ++entry)
388 if (indices[entry.index()]!=std::numeric_limits<SubMatrixIndex>::max())
392 template<
class M,
class I>
395 allocateMatrixStorage();
399 template<
class M,
class I>
404 mat->values=
new typename M::field_type[
mat->Nnz_];
405 mat->rowindex=
new I[
mat->Nnz_];
406 mat->colstart=
new I[cols+1];
409 template<
class M,
class I>
413 std::fill(marker.begin(), marker.end(), 0);
416 template<
class M,
class I>
417 template<
typename Iter>
420 DUNE_UNUSED_PARAMETER(row);
424 template<
class M,
class I>
429 assert(colindex*m+i<cols);
430 marker[colindex*m+i]+=n;
434 template<
class M,
class I>
440 mat->colstart[i+1]=
mat->colstart[i]+marker[i];
441 marker[i]=
mat->colstart[i];
445 template<
class M,
class I>
446 template<
typename Iter>
449 copyValue(
col, row.index(),
col.index());
452 template<
class M,
class I>
457 assert(colindex*m+j<cols-1 || (
size_type)marker[colindex*m+j]<(
size_type)
mat->colstart[colindex*m+j+1]);
459 mat->rowindex[marker[colindex*m+j]]=rowindex*n+i;
460 mat->values[marker[colindex*m+j]]=Impl::asMatrix(*
col)[i][j];
461 ++marker[colindex*m+j];
466 template<
class M,
class I>
472 template<
class F,
class MRS>
475 typedef typename MRS::const_iterator Iter;
476 typedef typename std::iterator_traits<Iter>::value_type::const_iterator CIter;
477 for(Iter row=mrs.begin(); row!= mrs.end(); ++row)
478 initializer.addRowNnz(row);
480 initializer.allocate();
482 for(Iter row=mrs.begin(); row!= mrs.end(); ++row) {
484 for(CIter
col=row->begin();
col != row->end(); ++
col)
485 initializer.countEntries(row,
col);
488 initializer.calcColstart();
490 for(Iter row=mrs.begin(); row!= mrs.end(); ++row) {
491 for(CIter
col=row->begin();
col != row->end(); ++
col) {
492 initializer.copyValue(row,
col);
496 initializer.createMatrix();
499 template<
class F,
class M,
class S>
503 typedef typename MRS::RowIndexSet SIS;
504 typedef typename SIS::const_iterator SIter;
505 typedef typename MRS::const_iterator Iter;
506 typedef typename std::iterator_traits<Iter>::value_type row_type;
507 typedef typename row_type::const_iterator CIter;
509 typedef typename MRS::Matrix::size_type size_type;
515 std::vector<size_type> subMatrixIndex(mrs.
matrix().N(),
516 std::numeric_limits<size_type>::max());
519 subMatrixIndex[*index]=s++;
522 for(Iter row=mrs.
begin(); row!= mrs.
end(); ++row)
523 initializer.addRowNnz(row, subMatrixIndex);
525 initializer.allocate();
527 for(Iter row=mrs.
begin(); row!= mrs.
end(); ++row)
528 for(CIter
col=row->begin();
col != row->end(); ++
col) {
529 if(subMatrixIndex[
col.index()]!=std::numeric_limits<size_type>::max())
531 initializer.countEntries(subMatrixIndex[
col.index()]);
534 initializer.calcColstart();
536 for(Iter row=mrs.
begin(); row!= mrs.
end(); ++row)
537 for(CIter
col=row->begin();
col != row->end(); ++
col) {
538 if(subMatrixIndex[
col.index()]!=std::numeric_limits<size_type>::max())
540 initializer.copyValue(
col, subMatrixIndex[row.index()], subMatrixIndex[
col.index()]);
542 initializer.createMatrix();
547 template<
class Mat,
class I>
548 ColCompMatrix<Mat, I>::ColCompMatrix()
549 : N_(0), M_(0), Nnz_(0), values(0), rowindex(0), colstart(0)
552 template<
class Mat,
class I>
553 ColCompMatrix<Mat, I>
554 ::ColCompMatrix(
const Matrix&
mat)
557 typename Matrix::block_type dummy;
558 const auto n = MatrixDimension<typename Matrix::block_type>::rowdim(dummy);
559 const auto m = MatrixDimension<typename Matrix::block_type>::coldim(dummy);
562 Nnz_ = n*m*
mat.nonzeroes();
565 template<
class Mat,
class I>
566 ColCompMatrix<Mat, I>&
567 ColCompMatrix<Mat, I>::operator=(
const Matrix&
mat)
575 template<
class Mat,
class I>
576 ColCompMatrix<Mat, I>&
577 ColCompMatrix<Mat, I>::operator=(
const ColCompMatrix&
mat)
585 colstart=
new size_type[M_+1];
586 for(size_type i=0; i<=M_; ++i)
587 colstart[i]=
mat.colstart[i];
591 values =
new B[Nnz_];
592 rowindex =
new size_type[Nnz_];
594 for(size_type i=0; i<Nnz_; ++i)
595 values[i]=
mat.values[i];
597 for(size_type i=0; i<Nnz_; ++i)
598 rowindex[i]=
mat.rowindex[i];
603 template<
class Mat,
class I>
604 void ColCompMatrix<Mat, I>
605 ::setMatrix(
const Matrix&
mat)
607 N_=MatrixDimension<Mat>::rowdim(
mat);
608 M_=MatrixDimension<Mat>::coldim(
mat);
609 ColCompMatrixInitializer<Mat, I> initializer(*
this);
614 template<
class Mat,
class I>
615 void ColCompMatrix<Mat, I>
616 ::setMatrix(
const Matrix&
mat,
const std::set<std::size_t>& mrs)
621 N_=mrs.size()*MatrixDimension<Mat>::rowdim(
mat) /
mat.N();
622 M_=mrs.size()*MatrixDimension<Mat>::coldim(
mat) /
mat.M();
623 ColCompMatrixInitializer<Mat, I> initializer(*
this);
628 template<
class Mat,
class I>
629 ColCompMatrix<Mat, I>::~ColCompMatrix()
635 template<
class Mat,
class I>
636 void ColCompMatrix<Mat, I>::free()
const_iterator(typename Matrix::const_iterator firstRow, typename RowIndexSet::const_iterator pos)
Definition: colcompmatrix.hh:92
virtual ~ColCompMatrixInitializer()
Definition: colcompmatrix.hh:283
M Matrix
the type of the matrix class.
Definition: colcompmatrix.hh:64
void countEntries(const Iter &row, const CIter &col) const
Definition: colcompmatrix.hh:418
Index * getRowIndex() const
Definition: colcompmatrix.hh:221
void allocate()
Definition: colcompmatrix.hh:393
void copyToColCompMatrix(F &initializer, const MatrixRowSubset< M, S > &mrs)
Definition: colcompmatrix.hh:500
Col col
Definition: matrixmatrix.hh:349
Index * rowindex
Definition: colcompmatrix.hh:249
virtual void free()
free allocated space.
virtual void createMatrix() const
Definition: colcompmatrix.hh:467
const_iterator begin() const
Get the row iterator at the first row.
Definition: colcompmatrix.hh:123
Matrix Matrix
The type of the matrix to convert.
Definition: colcompmatrix.hh:169
MatrixRowSubset(const Matrix &m, const RowIndexSet &s)
Construct an row set over all matrix rows.
Definition: colcompmatrix.hh:73
virtual ~ColCompMatrix()
Destructor.
Index * colstart
Definition: colcompmatrix.hh:250
Sequential overlapping Schwarz preconditioner.
Definition: colcompmatrix.hh:150
void addRowNnz(const Iter &row) const
Definition: colcompmatrix.hh:357
const_iterator begin() const
Get the row iterator at the first row.
Definition: colcompmatrix.hh:39
The matrix row iterator type.
Definition: colcompmatrix.hh:88
Iterator access to matrix rows
Definition: bcrsmatrix.hh:535
Matrix::ConstRowIterator const_iterator
The matrix row iterator type.
Definition: colcompmatrix.hh:28
B * values
Definition: colcompmatrix.hh:248
size_type cols
Definition: colcompmatrix.hh:318
size_type nnz() const
Definition: colcompmatrix.hh:197
Matrix::row_type::const_iterator CIter
Definition: colcompmatrix.hh:262
A generic dynamic dense matrix.
Definition: matrix.hh:557
M Matrix
The type of the matrix.
Definition: colcompmatrix.hh:26
Index * getColStart() const
Definition: colcompmatrix.hh:226
const_iterator end() const
Get the row iterator at the end of all rows.
Definition: colcompmatrix.hh:44
RowIndexSet::value_type index() const
Definition: colcompmatrix.hh:110
Utility class for converting an ISTL Matrix into a column-compressed matrix.
Definition: colcompmatrix.hh:161
void allocateMatrixStorage() const
Definition: colcompmatrix.hh:400
MatrixRowSet(const Matrix &m)
Construct an row set over all matrix rows.
Definition: colcompmatrix.hh:34
S RowIndexSet
the type of the set of valid row indices.
Definition: colcompmatrix.hh:66
Matrix::size_type size_type
Definition: colcompmatrix.hh:263
void calcColstart() const
Definition: colcompmatrix.hh:435
Implementation of the BCRSMatrix class.
Provides access to an iterator over an arbitrary subset of matrix rows.
Definition: colcompmatrix.hh:60
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:424
const_iterator end() const
Get the row iterator at the end of all rows.
Definition: colcompmatrix.hh:128
void allocateMarker()
Definition: colcompmatrix.hh:410
virtual void setMatrix(const Matrix &mat, const std::set< std::size_t > &mrs)
Initialize data from a given set of matrix rows and columns.
Definition: colcompmatrix.hh:153
Definition: allocator.hh:7
Matrix::size_type size_type
Definition: colcompmatrix.hh:173
MatrixImp::DenseMatrixBase< T, A >::window_type row_type
The type implementing a matrix row.
Definition: matrix.hh:571
std::vector< size_type > marker
Definition: colcompmatrix.hh:324
ColCompMatrix * mat
Definition: colcompmatrix.hh:317
static auto rowdim(const M &A)
Definition: matrixutils.hh:212
A::size_type size_type
Type for indices and sizes.
Definition: matrix.hh:574
size_type M_
Definition: colcompmatrix.hh:247
Inititializer for the ColCompMatrix as needed by OverlappingSchwarz.
Definition: colcompmatrix.hh:147
Provides access to an iterator over all matrix rows.
Definition: colcompmatrix.hh:22
size_type Nnz_
Definition: colcompmatrix.hh:247
size_type N() const
Get the number of rows.
Definition: colcompmatrix.hh:192
Matrix & mat
Definition: matrixmatrix.hh:345
static auto coldim(const M &A)
Definition: matrixutils.hh:217
const RowIndexSet & rowIndexSet() const
Definition: colcompmatrix.hh:82
std::size_t countEntries(const BlockVector< T, A > &vector)
Definition: matrixmarket.hh:1051
I Index
Definition: colcompmatrix.hh:260
bool equals(const const_iterator &o) const
Definition: colcompmatrix.hh:102
const Matrix::row_type & dereference() const
Definition: colcompmatrix.hh:98
ColCompMatrix & operator=(const Matrix &mat)
I Index
Definition: colcompmatrix.hh:175
size_type n
Definition: colcompmatrix.hh:322
T block_type
Export the type representing the components.
Definition: matrix.hh:565
Initializer for SuperLU Matrices representing the subdomains.
Definition: overlappingschwarz.hh:42
Dune::ColCompMatrix< Matrix, Index > ColCompMatrix
Definition: colcompmatrix.hh:261
size_type N_
Definition: colcompmatrix.hh:247
This file implements a vector space as a tensor product of a given vector space. The number of compon...
ColCompMatrixInitializer()
Definition: colcompmatrix.hh:351
ConstIterator class for sequential access.
Definition: matrix.hh:400
void copyValue(const Iter &row, const CIter &col) const
Definition: colcompmatrix.hh:447
B * getValues() const
Definition: colcompmatrix.hh:216
size_type m
Definition: colcompmatrix.hh:322
void increment()
Definition: colcompmatrix.hh:106
const Matrix & matrix() const
Definition: colcompmatrix.hh:77
size_type M() const
Get the number of columns.
Definition: colcompmatrix.hh:211