3#ifndef DUNE_ISTL_COLCOMPMATRIX_HH
4#define DUNE_ISTL_COLCOMPMATRIX_HH
59 template<
class M,
class S>
77 const Matrix& matrix()
const
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>
147 class ColCompMatrixInitializer;
149 template<
class M,
class X,
class TM,
class TD,
class T1>
150 class SeqOverlappingSchwarz;
152 template<
class T,
bool flag>
153 struct SeqOverlappingSchwarzAssemblerHelper;
160 template<
class Mat,
class I =
int>
165 using B =
typename Mat::field_type;
197 size_type nnz()
const
202 const auto n = MatrixDimension<typename Matrix::block_type>::rowdim(dummy);
203 const auto m = MatrixDimension<typename Matrix::block_type>::coldim(dummy);
221 Index* getRowIndex()
const
226 Index* getColStart()
const
247 size_type N_, M_, Nnz_;
253 template<
class M,
class I>
256 template<
class IList,
class S,
class D>
262 typedef typename Matrix::row_type::const_iterator CIter;
269 template <
class Block=
typename M::block_type>
277 template <
class Block=
typename M::block_type>
286 template<
typename Iter>
287 void addRowNnz(
const Iter& row)
const;
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>
298 void countEntries(
const Iter& row,
const CIter& col)
const;
300 void countEntries(size_type colidx)
const;
302 void calcColstart()
const;
304 template<
typename Iter>
305 void copyValue(
const Iter& row,
const CIter& col)
const;
307 void copyValue(
const CIter& col, size_type rowindex, size_type colidx)
const;
309 virtual void createMatrix()
const;
313 void allocateMatrixStorage()
const;
315 void allocateMarker();
324 mutable std::vector<size_type> marker;
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>
357 void ColCompMatrixInitializer<M, I>::addRowNnz(
const Iter& row)
const
359 mat->Nnz_+=row->getsize();
362 template<
class M,
class I>
363 template<
typename Iter,
typename FullMatrixIndex>
364 void ColCompMatrixInitializer<M, I>::addRowNnz(
const Iter& row,
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>
383 void ColCompMatrixInitializer<M, I>::addRowNnz(
const Iter& row,
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)
392 template<
class M,
class I>
393 void ColCompMatrixInitializer<M, I>::allocate()
395 allocateMatrixStorage();
399 template<
class M,
class I>
400 void ColCompMatrixInitializer<M, I>::allocateMatrixStorage()
const
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>
410 void ColCompMatrixInitializer<M, I>::allocateMarker()
413 std::fill(marker.begin(), marker.end(), 0);
416 template<
class M,
class I>
417 template<
typename Iter>
418 void ColCompMatrixInitializer<M, I>::countEntries(
const Iter& row,
const CIter& col)
const
421 countEntries(col.index());
424 template<
class M,
class I>
425 void ColCompMatrixInitializer<M, I>::countEntries(size_type colindex)
const
427 for(size_type i=0; i < m; ++i)
429 assert(colindex*m+i<cols);
430 marker[colindex*m+i]+=n;
434 template<
class M,
class I>
435 void ColCompMatrixInitializer<M, I>::calcColstart()
const
438 for(size_type i=0; i < cols; ++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>
447 void ColCompMatrixInitializer<M, I>::copyValue(
const Iter& row,
const CIter& col)
const
449 copyValue(col, row.index(), col.index());
452 template<
class M,
class I>
453 void ColCompMatrixInitializer<M, I>::copyValue(
const CIter& col, size_type rowindex, size_type colindex)
const
455 for(size_type i=0; i<n; i++) {
456 for(size_type j=0; j<m; j++) {
457 assert(colindex*m+j<cols-1 || (size_type)marker[colindex*m+j]<(size_type)mat->colstart[colindex*m+j+1]);
458 assert((size_type)marker[colindex*m+j]<mat->Nnz_);
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>
467 void ColCompMatrixInitializer<M, I>::createMatrix()
const
472 template<
class F,
class MRS>
473 void copyToColCompMatrix(F& initializer,
const MRS& 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>
500 void copyToColCompMatrix(F& initializer,
const MatrixRowSubset<M,S>& mrs)
502 typedef MatrixRowSubset<M,S> MRS;
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(),
518 for(SIter index = mrs.rowIndexSet().begin(); index!=mrs.rowIndexSet().end(); ++index)
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) {
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) {
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)
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>
607 N_=MatrixDimension<Mat>::rowdim(mat);
608 M_=MatrixDimension<Mat>::coldim(mat);
609 ColCompMatrixInitializer<Mat, I> initializer(*
this);
611 copyToColCompMatrix(initializer, MatrixRowSet<Matrix>(mat));
614 template<
class Mat,
class 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);
625 copyToColCompMatrix(initializer, MatrixRowSubset<Mat,std::set<std::size_t> >(mat,mrs));
628 template<
class Mat,
class I>
635 template<
class Mat,
class I>
Implementation of the BCRSMatrix class.
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Inititializer for the ColCompMatrix as needed by OverlappingSchwarz.
Definition: colcompmatrix.hh:255
ColCompMatrixInitializer(ColCompMatrix &lum, typename std::enable_if_t< Dune::IsNumber< Block >::value > *sfinae=nullptr)
Constructor for scalar-valued matrices.
Definition: colcompmatrix.hh:329
ColCompMatrixInitializer(ColCompMatrix &lum, typename std::enable_if_t<!Dune::IsNumber< Block >::value > *sfinae=nullptr)
Constructor for dense matrix-valued matrices.
Definition: colcompmatrix.hh:340
Utility class for converting an ISTL Matrix into a column-compressed matrix.
Definition: colcompmatrix.hh:162
virtual ~ColCompMatrix()
Destructor.
virtual void setMatrix(const Matrix &mat, const std::set< std::size_t > &mrs)
Initialize data from a given set of matrix rows and columns.
ColCompMatrix(const Matrix &mat)
Constructor that initializes the data.
Mat Matrix
The type of the matrix to convert.
Definition: colcompmatrix.hh:169
virtual void free()
free allocated space.
size_type N() const
Get the number of rows.
Definition: colcompmatrix.hh:192
size_type M() const
Get the number of columns.
Definition: colcompmatrix.hh:211
virtual void setMatrix(const Matrix &mat)
Initialize data from given matrix.
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:139
ConstIterator class for sequential access.
Definition: matrix.hh:401
Provides access to an iterator over all matrix rows.
Definition: colcompmatrix.hh:23
Matrix::ConstRowIterator const_iterator
The matrix row iterator type.
Definition: colcompmatrix.hh:28
const_iterator begin() const
Get the row iterator at the first row.
Definition: colcompmatrix.hh:39
M Matrix
The type of the matrix.
Definition: colcompmatrix.hh:26
MatrixRowSet(const Matrix &m)
Construct an row set over all matrix rows.
Definition: colcompmatrix.hh:34
const_iterator end() const
Get the row iterator at the end of all rows.
Definition: colcompmatrix.hh:44
The matrix row iterator type.
Definition: colcompmatrix.hh:90
Provides access to an iterator over an arbitrary subset of matrix rows.
Definition: colcompmatrix.hh:61
S RowIndexSet
the type of the set of valid row indices.
Definition: colcompmatrix.hh:66
const_iterator begin() const
Get the row iterator at the first row.
Definition: colcompmatrix.hh:123
M Matrix
the type of the matrix class.
Definition: colcompmatrix.hh:64
MatrixRowSubset(const Matrix &m, const RowIndexSet &s)
Construct an row set over all matrix rows.
Definition: colcompmatrix.hh:73
const_iterator end() const
Get the row iterator at the end of all rows.
Definition: colcompmatrix.hh:128
A generic dynamic dense matrix.
Definition: matrix.hh:558
A::size_type size_type
Type for indices and sizes.
Definition: matrix.hh:574
size_type M() const
Return the number of columns.
Definition: matrix.hh:696
T block_type
Export the type representing the components.
Definition: matrix.hh:565
MatrixImp::DenseMatrixBase< T, A >::window_type row_type
The type implementing a matrix row.
Definition: matrix.hh:571
size_type N() const
Return the number of rows.
Definition: matrix.hh:691
Initializer for SuperLU Matrices representing the subdomains.
Definition: overlappingschwarz.hh:44
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
Dune namespace.
Definition: alignedallocator.hh:14
Implements a scalar matrix view wrapper around an existing scalar.
Whether this type acts as a scalar in the context of (hierarchically blocked) containers.
Definition: typetraits.hh:163
Traits for type conversions and type information.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.