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/diagonalmatrix.hh>
12 #include <dune/common/unused.hh>
20 template<
typename B,
typename A>
23 template<
typename K,
int n,
int m>
26 template<
class T,
class A>
46 static typename M::size_type
count(
const M& matrix)
48 typedef typename M::ConstRowIterator RowIterator;
50 RowIterator endRow = matrix.end();
51 typename M::size_type nonZeros = 0;
53 for(RowIterator
row = matrix.begin();
row != endRow; ++
row) {
54 typedef typename M::ConstColIterator Entry;
55 Entry endEntry =
row->end();
56 for(Entry entry =
row->begin(); entry != endEntry; ++entry) {
65 struct NonZeroCounter<1>
68 static typename M::size_type
count(
const M& matrix)
70 return matrix.N()*matrix.M();
80 template<
class Matrix, std::
size_t blocklevel, std::
size_t l=blocklevel>
89 DUNE_UNUSED_PARAMETER(mat);
90 #ifdef DUNE_ISTL_WITH_CHECKING
94 Entry diagonal =
row->find(
row.index());
95 if(diagonal==
row->end())
96 DUNE_THROW(
ISTLError,
"Missing diagonal value in row "<<
row.index()
97 <<
" at block recursion level "<<l-blocklevel);
105 template<
class Matrix, std::
size_t l>
113 DUNE_THROW(
ISTLError,
"Missing diagonal value in row "<<
row.index()
114 <<
" at block recursion level "<<l);
119 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
120 typename T6,
typename T7,
typename T8,
typename T9>
123 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
124 typename T6,
typename T7,
typename T8,
typename T9, std::size_t blocklevel, std::size_t l>
136 #ifdef DUNE_ISTL_WITH_CHECKING
167 template<
class G,
class M>
168 bool operator()(
const std::pair<G,M>& p1,
const std::pair<G,M>& p2)
170 return p1.first<p2.first;
175 template<
class M,
class C>
178 typedef typename C::ParallelIndexSet::const_iterator IIter;
179 typedef typename C::OwnerSet OwnerSet;
180 typedef typename C::ParallelIndexSet::GlobalIndex GlobalIndex;
184 for(IIter idx=ooc.indexSet().begin(), eidx=ooc.indexSet().end();
186 gmax=std::max(gmax,idx->global());
188 gmax=ooc.communicator().max(gmax);
189 ooc.buildGlobalLookup();
191 for(IIter idx=ooc.indexSet().begin(), eidx=ooc.indexSet().end();
193 if(OwnerSet::contains(idx->local().attribute()))
195 typedef typename M::block_type Block;
197 std::set<std::pair<GlobalIndex,Block>,CompPair> entries;
200 typedef typename M::ConstColIterator CIter;
201 for(CIter c=mat[idx->local()].begin(), cend=mat[idx->local()].end();
203 const typename C::ParallelIndexSet::IndexPair* pair
204 =ooc.globalLookup().pair(c.index());
206 entries.insert(std::make_pair(pair->global(), *c));
210 GlobalIndex rowidx = idx->global();
211 GlobalIndex cur=std::numeric_limits<GlobalIndex>::max();
213 cur=ooc.communicator().min(rowidx);
216 typedef typename std::set<std::pair<GlobalIndex,Block>,CompPair>::iterator SIter;
217 for(SIter s=entries.begin(), send=entries.end(); s!=send; ++s)
218 os<<idx->global()<<
" "<<s->first<<
" "<<s->second<<std::endl;
224 ooc.freeGlobalLookup();
226 GlobalIndex cur=std::numeric_limits<GlobalIndex>::max();
227 while(cur!=ooc.communicator().min(cur)) ;
231 struct MatrixDimension
235 template<
typename B,
typename TA>
242 static size_type
rowdim (
const Matrix&
A, size_type i)
251 static size_type
coldim (
const Matrix&
A, size_type c)
256 for (size_type k=0; k<A.
nnz; k++) {
257 if (A.
j.get()[k]==c) {
264 for (size_type i=0; i<A.
N(); i++)
268 for (size_type k=0; k<A.
r[i].
getsize(); k++)
281 for (size_type i=0; i<A.
N(); i++)
293 std::vector<size_type> coldims(A.
M(),
294 std::numeric_limits<size_type>::max());
299 if (coldims[
col.index()]==std::numeric_limits<size_type>::max())
303 for (
typename std::vector<size_type>::iterator it=coldims.begin();
304 it!=coldims.end(); ++it)
314 template<
typename B,
int n,
int m,
typename TA>
320 static size_type
rowdim (
const Matrix& , size_type )
325 static size_type
coldim (
const Matrix& , size_type )
339 template<
typename K,
int n,
int m>
345 static size_type
rowdim(
const Matrix& , size_type )
350 static size_type
coldim(
const Matrix& , size_type )
366 template<
typename K,
int n,
int m,
typename TA>
372 static size_type
rowdim(
const ThisMatrix& , size_type )
377 static size_type
coldim(
const ThisMatrix& , size_type )
393 template<
typename K,
int n>
399 static size_type
rowdim(
const Matrix& , size_type )
404 static size_type
coldim(
const Matrix& , size_type )
420 template<
typename K,
int n>
426 static size_type
rowdim(
const Matrix& , size_type )
431 static size_type
coldim(
const Matrix& , size_type )
473 template<
typename T,
typename A>
static size_type rowdim(const Matrix &, size_type)
Definition: matrixutils.hh:426
Test whether a type is an ISTL Matrix.
Definition: matrixutils.hh:451
Row row
Definition: matrixmatrix.hh:345
Definition: basearray.hh:19
size_type M() const
number of columns (counted in blocks)
Definition: bcrsmatrix.hh:1855
DiagonalMatrix< K, n > Matrix
Definition: matrixutils.hh:396
static size_type coldim(const Matrix &)
Definition: matrixutils.hh:360
ScaledIdentityMatrix< K, n > Matrix
Definition: matrixutils.hh:423
A::size_type size_type
The type for the index access and the size.
Definition: bcrsmatrix.hh:447
derive error class from the base class in common
Definition: istlexception.hh:16
Matrix & mat
Definition: matrixmatrix.hh:343
static size_type rowdim(const Matrix &A)
Definition: matrixutils.hh:279
int countNonZeros(const M &matrix)
Get the number of nonzero fields in the matrix.
Definition: matrixutils.hh:154
static size_type rowdim(const Matrix &, size_type)
Definition: matrixutils.hh:399
static size_type rowdim(const ThisMatrix &A)
Definition: matrixutils.hh:382
size_type M() const
Return the number of columns.
Definition: matrix.hh:165
static size_type coldim(const Matrix &)
Definition: matrixutils.hh:414
Matrix::size_type size_type
Definition: matrixutils.hh:343
static void check(const Matrix &mat)
Definition: matrixutils.hh:108
static size_type rowdim(const Matrix &, size_type)
Definition: matrixutils.hh:345
Check whether the a matrix has diagonal values on blocklevel recursion levels.
Definition: matrixutils.hh:81
B * getptr()
get pointer
Definition: bvector.hh:1050
Col col
Definition: matrixmatrix.hh:347
static size_type coldim(const ThisMatrix &A)
Definition: matrixutils.hh:387
static size_type rowdim(const Matrix &, size_type)
Definition: matrixutils.hh:320
static size_type rowdim(const Matrix &)
Definition: matrixutils.hh:436
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:412
static size_type rowdim(const Matrix &A, size_type i)
Definition: matrixutils.hh:242
Definition: matrixutils.hh:121
Iterator end()
Get iterator to one beyond last row.
Definition: bcrsmatrix.hh:630
Matrix & A
Definition: matrixmatrix.hh:216
static size_type coldim(const Matrix &A)
Definition: matrixutils.hh:286
std::size_t size_type
The type used for the index access and size operations.
Definition: scaledidmatrix.hh:41
Matrix::size_type size_type
Definition: matrixutils.hh:240
static size_type rowdim(const Matrix &)
Definition: matrixutils.hh:355
size_type nnz
Definition: bcrsmatrix.hh:1909
VariableBlockVector< T, A >::ConstIterator ConstRowIterator
Const iterator over the matrix rows.
Definition: matrix.hh:50
size_type N() const
number of rows (counted in blocks)
Definition: bcrsmatrix.hh:1849
True if T is an ISTL matrix.
Definition: matrixutils.hh:457
Matrix::block_type block_type
Definition: matrixutils.hh:239
void printGlobalSparseMatrix(const M &mat, C &ooc, std::ostream &os)
Definition: matrixutils.hh:176
static size_type coldim(const Matrix &A)
Definition: matrixutils.hh:334
Dune::CheckIfDiagonalPresent< MultiTypeBlockMatrix< T1, T2, T3, T4, T5, T6, T7, T8, T9 >, blocklevel, l >::Matrix MultiTypeBlockMatrix< T1, T2, T3, T4, T5, T6, T7, T8, T9 > Matrix
Definition: matrixutils.hh:128
Matrix::size_type size_type
Definition: matrixutils.hh:397
static size_type coldim(const Matrix &)
Definition: matrixutils.hh:441
static size_type coldim(const ThisMatrix &, size_type)
Definition: matrixutils.hh:377
RowIterator begin()
Get iterator to first row.
Definition: matrix.hh:79
row_type::const_iterator ConstColIterator
Const iterator for the entries of each row.
Definition: matrix.hh:53
ThisMatrix::size_type size_type
Definition: matrixutils.hh:370
BCRSMatrix< B, TA > Matrix
Definition: matrixutils.hh:238
Matrix< FieldMatrix< K, n, m >, TA > ThisMatrix
Definition: matrixutils.hh:369
iterator class for sequential access
Definition: basearray.hh:580
static size_type coldim(const Matrix &, size_type)
Definition: matrixutils.hh:431
size_type N() const
Return the number of rows.
Definition: matrix.hh:160
static size_type rowdim(const ThisMatrix &, size_type)
Definition: matrixutils.hh:372
bool operator()(const T *l, const T *r)
Definition: matrixutils.hh:487
RowIterator end()
Get iterator to one beyond last row.
Definition: matrix.hh:85
static size_type coldim(const Matrix &, size_type)
Definition: matrixutils.hh:350
size_type * getindexptr()
get pointer
Definition: bvector.hh:1056
std::size_t count
Definition: matrixmatrix.hh:215
Definition: matrixutils.hh:24
BCRSMatrix< FieldMatrix< B, n, m >,TA > Matrix
Definition: matrixutils.hh:317
Matrix::size_type size_type
Definition: matrixutils.hh:424
static size_type coldim(const Matrix &, size_type)
Definition: matrixutils.hh:404
static size_type coldim(const Matrix &, size_type)
Definition: matrixutils.hh:325
B * a
Definition: bcrsmatrix.hh:1917
static size_type rowdim(const Matrix &A)
Definition: matrixutils.hh:330
Iterator begin()
Get iterator to first row.
Definition: bcrsmatrix.hh:624
B block_type
export the type representing the components
Definition: bcrsmatrix.hh:438
Dune::CheckIfDiagonalPresent< MultiTypeBlockMatrix< T1, T2, T3, T4, T5, T6, T7, T8, T9 >, blocklevel, l >::check static void check(const Matrix &)
Check whether the a matrix has diagonal values on blocklevel recursion levels.
Definition: matrixutils.hh:134
Definition: matrixutils.hh:485
row_type * r
Definition: bcrsmatrix.hh:1914
A generic dynamic dense matrix.
Definition: matrix.hh:24
Iterator access to matrix rows
Definition: bcrsmatrix.hh:526
std::shared_ptr< size_type > j
Definition: bcrsmatrix.hh:1920
static size_type coldim(const Matrix &A, size_type c)
Definition: matrixutils.hh:251
static size_type rowdim(const Matrix &)
Definition: matrixutils.hh:409
Definition: bcrsmatrix.hh:71
A::size_type size_type
Type for indices and sizes.
Definition: matrix.hh:41
static void check(const Matrix &mat)
Check whether the a matrix has diagonal values on blocklevel recursion levels.
Definition: matrixutils.hh:87
Matrix::size_type size_type
Definition: matrixutils.hh:318
This file implements a quadratic matrix of fixed size which is a multiple of the identity.
size_type getsize() const
get size
Definition: bvector.hh:1073
A multiple of the identity matrix of static size.
Definition: scaledidmatrix.hh:27
FieldMatrix< K, n, m > Matrix
Definition: matrixutils.hh:342