3#ifndef DUNE_ISTL_MATRIXUTILS_HH
4#define DUNE_ISTL_MATRIXUTILS_HH
9#include <dune/common/typetraits.hh>
10#include <dune/common/fmatrix.hh>
11#include <dune/common/dynmatrix.hh>
12#include <dune/common/diagonalmatrix.hh>
13#include <dune/common/unused.hh>
21 template<
typename B,
typename A>
24 template<
typename K,
int n,
int m>
27 template<
class T,
class A>
47 static typename M::size_type count(
const M& matrix)
49 typedef typename M::ConstRowIterator RowIterator;
51 RowIterator
endRow = matrix.end();
54 for(RowIterator row = matrix.begin(); row !=
endRow; ++row) {
55 typedef typename M::ConstColIterator
Entry;
58 nonZeros += NonZeroCounter<i-1>::count(*entry);
66 struct NonZeroCounter<1>
69 static typename M::size_type count(
const M& matrix)
71 return matrix.N()*matrix.M();
81 template<
class Matrix, std::
size_t blocklevel, std::
size_t l=blocklevel>
91#ifdef DUNE_ISTL_WITH_CHECKING
94 for(Row row =
mat.begin(); row!=
mat.end(); ++row) {
95 Entry diagonal = row->find(row.index());
96 if(diagonal==row->end())
98 <<
" at block recursion level "<<
l-blocklevel);
106 template<
class Matrix, std::
size_t l>
112 for(Row row =
mat.begin(); row!=
mat.end(); ++row) {
113 if(row->find(row.index())==row->end())
115 <<
" at block recursion level "<<
l);
120 template<
typename FirstRow,
typename... Args>
121 class MultiTypeBlockMatrix;
123 template<std::size_t blocklevel, std::size_t l,
typename T1,
typename... Args>
135#ifdef DUNE_ISTL_WITH_CHECKING
155 return NonZeroCounter<M::blocklevel>::count(matrix);
166 template<
class G,
class M>
167 bool operator()(
const std::pair<G,M>& p1,
const std::pair<G,M>& p2)
169 return p1.first<p2.first;
174 template<
class M,
class C>
177 typedef typename C::ParallelIndexSet::const_iterator
IIter;
178 typedef typename C::OwnerSet OwnerSet;
179 typedef typename C::ParallelIndexSet::GlobalIndex GlobalIndex;
188 ooc.buildGlobalLookup();
192 if(OwnerSet::contains(
idx->local().attribute()))
194 typedef typename M::block_type
Block;
196 std::set<std::pair<GlobalIndex,Block>,CompPair> entries;
199 typedef typename M::ConstColIterator CIter;
202 const typename C::ParallelIndexSet::IndexPair*
pair
203 =
ooc.globalLookup().pair(c.index());
205 entries.insert(std::make_pair(
pair->global(), *c));
210 GlobalIndex
cur=std::numeric_limits<GlobalIndex>::max();
215 typedef typename std::set<std::pair<GlobalIndex,Block>,CompPair>::iterator
SIter;
217 os<<
idx->global()<<
" "<<
s->first<<
" "<<
s->second<<std::endl;
223 ooc.freeGlobalLookup();
225 GlobalIndex
cur=std::numeric_limits<GlobalIndex>::max();
226 while(
cur!=
ooc.communicator().min(
cur)) ;
234 template<
typename B,
typename TA>
243 const B* row = A.r[i].getptr();
256 if (A.j_.get()[k] == c) {
266 B* a = A.r[i].getptr();
267 for (
size_type k=0; k<A.r[i].getsize(); k++)
292 std::vector<size_type>
coldims(A.M(),
293 std::numeric_limits<size_type>::max());
295 for (ConstRowIterator row=A.begin(); row!=A.end(); ++row)
296 for (ConstColIterator
col=row->begin();
col!=row->end(); ++
col)
298 if (
coldims[
col.index()]==std::numeric_limits<size_type>::max())
302 for (
typename std::vector<size_type>::iterator
it=
coldims.begin();
313 template<
typename B,
int n,
int m,
typename TA>
338 template<
typename K,
int n,
int m>
392 template<
typename K,
int n,
int m,
typename TA>
419 template<
typename K,
int n>
446 template<
typename K,
int n>
499 template<
typename T,
typename A>
This file implements a quadratic matrix of fixed size which is a multiple of the identity.
Col col
Definition matrixmatrix.hh:347
Matrix & mat
Definition matrixmatrix.hh:343
int countNonZeros(const M &matrix)
Get the number of nonzero fields in the matrix.
Definition matrixutils.hh:153
Definition basearray.hh:19
void printGlobalSparseMatrix(const M &mat, C &ooc, std::ostream &os)
Definition matrixutils.hh:175
Iterator implementation class
Definition basearray.hh:84
Definition matrixutils.hh:231
Statistics about compression achieved in implicit mode.
Definition bcrsmatrix.hh:81
A sparse block matrix with compressed row storage.
Definition bcrsmatrix.hh:412
derive error class from the base class in common
Definition istlexception.hh:16
ConstIterator class for sequential access.
Definition matrix.hh:398
A generic dynamic dense matrix.
Definition matrix.hh:555
A::size_type size_type
Type for indices and sizes.
Definition matrix.hh:571
RowIterator end()
Get iterator to one beyond last row.
Definition matrix.hh:615
RowIterator begin()
Get iterator to first row.
Definition matrix.hh:609
T block_type
Export the type representing the components.
Definition matrix.hh:562
Definition matrixutils.hh:25
Check whether the a matrix has diagonal values on blocklevel recursion levels.
Definition matrixutils.hh:83
static void check(const Matrix &mat)
Check whether the a matrix has diagonal values on blocklevel recursion levels.
Definition matrixutils.hh:88
static void check(const Matrix &mat)
Definition matrixutils.hh:109
A Matrix class to support different block types.
Definition multitypeblockmatrix.hh:44
static void check(const Matrix &)
Check whether the a matrix has diagonal values on blocklevel recursion levels.
Definition matrixutils.hh:133
MultiTypeBlockMatrix< T1, Args... > Matrix
Definition matrixutils.hh:127
BCRSMatrix< B, TA > Matrix
Definition matrixutils.hh:237
static size_type coldim(const Matrix &A)
Definition matrixutils.hh:285
Matrix::block_type block_type
Definition matrixutils.hh:238
static size_type coldim(const Matrix &A, size_type c)
Definition matrixutils.hh:250
Matrix::size_type size_type
Definition matrixutils.hh:239
static size_type rowdim(const Matrix &A, size_type i)
Definition matrixutils.hh:241
static size_type rowdim(const Matrix &A)
Definition matrixutils.hh:278
static size_type coldim(const Matrix &A)
Definition matrixutils.hh:333
static size_type rowdim(const Matrix &, size_type)
Definition matrixutils.hh:319
static size_type rowdim(const Matrix &A)
Definition matrixutils.hh:329
Matrix::size_type size_type
Definition matrixutils.hh:317
BCRSMatrix< FieldMatrix< B, n, m >,TA > Matrix
Definition matrixutils.hh:316
static size_type coldim(const Matrix &, size_type)
Definition matrixutils.hh:324
static size_type rowdim(const Matrix &, size_type)
Definition matrixutils.hh:344
static size_type coldim(const Matrix &)
Definition matrixutils.hh:359
Matrix::size_type size_type
Definition matrixutils.hh:342
FieldMatrix< K, n, m > Matrix
Definition matrixutils.hh:341
static size_type coldim(const Matrix &, size_type)
Definition matrixutils.hh:349
static size_type rowdim(const Matrix &)
Definition matrixutils.hh:354
static size_type coldim(const MatrixType &A)
Definition matrixutils.hh:386
static size_type rowdim(const MatrixType &A)
Definition matrixutils.hh:381
static size_type rowdim(const MatrixType &, size_type)
Definition matrixutils.hh:371
MatrixType::size_type size_type
Definition matrixutils.hh:369
static size_type coldim(const MatrixType &, size_type)
Definition matrixutils.hh:376
Dune::DynamicMatrix< T > MatrixType
Definition matrixutils.hh:368
static size_type coldim(const ThisMatrix &A)
Definition matrixutils.hh:413
static size_type rowdim(const ThisMatrix &A)
Definition matrixutils.hh:408
Matrix< FieldMatrix< K, n, m >, TA > ThisMatrix
Definition matrixutils.hh:395
static size_type coldim(const ThisMatrix &, size_type)
Definition matrixutils.hh:403
static size_type rowdim(const ThisMatrix &, size_type)
Definition matrixutils.hh:398
ThisMatrix::size_type size_type
Definition matrixutils.hh:396
static size_type coldim(const Matrix &, size_type)
Definition matrixutils.hh:430
Matrix::size_type size_type
Definition matrixutils.hh:423
static size_type coldim(const Matrix &)
Definition matrixutils.hh:440
static size_type rowdim(const Matrix &)
Definition matrixutils.hh:435
DiagonalMatrix< K, n > Matrix
Definition matrixutils.hh:422
static size_type rowdim(const Matrix &, size_type)
Definition matrixutils.hh:425
static size_type coldim(const Matrix &)
Definition matrixutils.hh:467
static size_type rowdim(const Matrix &, size_type)
Definition matrixutils.hh:452
static size_type coldim(const Matrix &, size_type)
Definition matrixutils.hh:457
Matrix::size_type size_type
Definition matrixutils.hh:450
ScaledIdentityMatrix< K, n > Matrix
Definition matrixutils.hh:449
static size_type rowdim(const Matrix &)
Definition matrixutils.hh:462
Test whether a type is an ISTL Matrix.
Definition matrixutils.hh:478
@ value
True if T is an ISTL matrix.
Definition matrixutils.hh:483
Definition matrixutils.hh:512
bool operator()(const T *l, const T *r)
Definition matrixutils.hh:513
A multiple of the identity matrix of static size.
Definition scaledidmatrix.hh:28