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();
52 typename M::size_type nonZeros = 0;
54 for(RowIterator row = matrix.begin(); row != endRow; ++row) {
55 typedef typename M::ConstColIterator Entry;
56 Entry endEntry = row->end();
57 for(Entry entry = row->begin(); entry != endEntry; ++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>
90 DUNE_UNUSED_PARAMETER(mat);
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())
97 DUNE_THROW(
ISTLError,
"Missing diagonal value in row "<<row.index()
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())
114 DUNE_THROW(
ISTLError,
"Missing diagonal value in row "<<row.index()
115 <<
" at block recursion level "<<l);
120 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
121 typename T6,
typename T7,
typename T8,
typename T9>
124 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
125 typename T6,
typename T7,
typename T8,
typename T9, std::size_t blocklevel, std::size_t l>
137 #ifdef DUNE_ISTL_WITH_CHECKING 157 return NonZeroCounter<M::blocklevel>::count(matrix);
168 template<
class G,
class M>
169 bool operator()(
const std::pair<G,M>& p1,
const std::pair<G,M>& p2)
171 return p1.first<p2.first;
176 template<
class M,
class C>
179 typedef typename C::ParallelIndexSet::const_iterator IIter;
180 typedef typename C::OwnerSet OwnerSet;
181 typedef typename C::ParallelIndexSet::GlobalIndex GlobalIndex;
185 for(IIter idx=ooc.indexSet().begin(), eidx=ooc.indexSet().end();
187 gmax=std::max(gmax,idx->global());
189 gmax=ooc.communicator().max(gmax);
190 ooc.buildGlobalLookup();
192 for(IIter idx=ooc.indexSet().begin(), eidx=ooc.indexSet().end();
194 if(OwnerSet::contains(idx->local().attribute()))
196 typedef typename M::block_type Block;
198 std::set<std::pair<GlobalIndex,Block>,CompPair> entries;
201 typedef typename M::ConstColIterator CIter;
202 for(CIter c=mat[idx->local()].begin(), cend=mat[idx->local()].end();
204 const typename C::ParallelIndexSet::IndexPair* pair
205 =ooc.globalLookup().pair(c.index());
207 entries.insert(std::make_pair(pair->global(), *c));
211 GlobalIndex rowidx = idx->global();
212 GlobalIndex cur=std::numeric_limits<GlobalIndex>::max();
214 cur=ooc.communicator().min(rowidx);
217 typedef typename std::set<std::pair<GlobalIndex,Block>,CompPair>::iterator SIter;
218 for(SIter s=entries.begin(), send=entries.end(); s!=send; ++s)
219 os<<idx->global()<<
" "<<s->first<<
" "<<s->second<<std::endl;
225 ooc.freeGlobalLookup();
227 GlobalIndex cur=std::numeric_limits<GlobalIndex>::max();
228 while(cur!=ooc.communicator().min(cur)) ;
236 template<
typename B,
typename TA>
243 static size_type
rowdim (
const Matrix& A, size_type i)
245 const B* row = A.
r[i].
getptr();
252 static size_type
coldim (
const Matrix& A, size_type c)
257 for (size_type k=0; k<A.
nnz_; k++) {
258 if (A.
j_.get()[k] == c) {
265 for (size_type i=0; i<A.
N(); i++)
269 for (size_type k=0; k<A.
r[i].
getsize(); k++)
280 static size_type
rowdim (
const Matrix& A){
282 for (size_type i=0; i<A.
N(); i++)
287 static size_type
coldim (
const Matrix& A){
294 std::vector<size_type> coldims(A.
M(),
295 std::numeric_limits<size_type>::max());
297 for (ConstRowIterator row=A.
begin(); row!=A.
end(); ++row)
298 for (ConstColIterator
col=row->begin();
col!=row->end(); ++
col)
300 if (coldims[
col.index()]==std::numeric_limits<size_type>::max())
304 for (
typename std::vector<size_type>::iterator it=coldims.begin();
305 it!=coldims.end(); ++it)
315 template<
typename B,
int n,
int m,
typename TA>
321 static size_type
rowdim (
const Matrix& , size_type )
326 static size_type
coldim (
const Matrix& , size_type )
331 static size_type
rowdim (
const Matrix& A) {
335 static size_type
coldim (
const Matrix& A) {
340 template<
typename K,
int n,
int m>
346 static size_type
rowdim(
const Matrix& , size_type )
351 static size_type
coldim(
const Matrix& , size_type )
373 static size_type
rowdim(
const MatrixType& , size_type )
378 static size_type
coldim(
const MatrixType& , size_type )
383 static size_type
rowdim(
const MatrixType& A)
388 static size_type
coldim(
const MatrixType& A)
394 template<
typename K,
int n,
int m,
typename TA>
400 static size_type
rowdim(
const ThisMatrix& , size_type )
405 static size_type
coldim(
const ThisMatrix& , size_type )
410 static size_type
rowdim(
const ThisMatrix& A)
415 static size_type
coldim(
const ThisMatrix& A)
421 template<
typename K,
int n>
427 static size_type
rowdim(
const Matrix& , size_type )
432 static size_type
coldim(
const Matrix& , size_type )
448 template<
typename K,
int n>
454 static size_type
rowdim(
const Matrix& , size_type )
459 static size_type
coldim(
const Matrix& , size_type )
501 template<
typename T,
typename A>
size_type * getindexptr()
get pointer
Definition: bvector.hh:1056
std::size_t size_type
The type used for the index access and size operations.
Definition: scaledidmatrix.hh:41
size_type nnz_
Definition: bcrsmatrix.hh:1909
size_type N() const
Return the number of rows.
Definition: matrix.hh:160
Definition: matrixutils.hh:122
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:129
Matrix & mat
Definition: matrixmatrix.hh:343
B * a
Definition: bcrsmatrix.hh:1917
size_type M() const
Return the number of columns.
Definition: matrix.hh:165
static size_type rowdim(const MatrixType &A)
Definition: matrixutils.hh:383
static size_type rowdim(const MatrixType &, size_type)
Definition: matrixutils.hh:373
static size_type rowdim(const Matrix &, size_type)
Definition: matrixutils.hh:427
Test whether a type is an ISTL Matrix.
Definition: matrixutils.hh:479
row_type::const_iterator ConstColIterator
Const iterator for the entries of each row.
Definition: matrix.hh:53
Iterator access to matrix rows
Definition: bcrsmatrix.hh:526
static size_type coldim(const Matrix &A)
Definition: matrixutils.hh:287
iterator class for sequential access
Definition: basearray.hh:580
derive error class from the base class in common
Definition: istlexception.hh:16
static size_type coldim(const Matrix &)
Definition: matrixutils.hh:361
Definition: matrixutils.hh:25
int countNonZeros(const M &matrix)
Get the number of nonzero fields in the matrix.
Definition: matrixutils.hh:155
static size_type coldim(const Matrix &, size_type)
Definition: matrixutils.hh:326
static size_type rowdim(const Matrix &, size_type)
Definition: matrixutils.hh:321
std::shared_ptr< size_type > j_
Definition: bcrsmatrix.hh:1920
Matrix::size_type size_type
Definition: matrixutils.hh:452
Iterator begin()
Get iterator to first row.
Definition: bcrsmatrix.hh:624
B block_type
export the type representing the components
Definition: bcrsmatrix.hh:438
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
row_type * r
Definition: bcrsmatrix.hh:1914
static size_type coldim(const ThisMatrix &, size_type)
Definition: matrixutils.hh:405
BCRSMatrix< FieldMatrix< B, n, m >,TA > Matrix
Definition: matrixutils.hh:318
A generic dynamic dense matrix.
Definition: matrix.hh:24
Matrix::block_type block_type
Definition: matrixutils.hh:240
MatrixType::size_type size_type
Definition: matrixutils.hh:371
ThisMatrix::size_type size_type
Definition: matrixutils.hh:398
static void check(const Matrix &mat)
Check whether the a matrix has diagonal values on blocklevel recursion levels.
Definition: matrixutils.hh:88
static size_type rowdim(const Matrix &)
Definition: matrixutils.hh:356
static size_type coldim(const Matrix &A, size_type c)
Definition: matrixutils.hh:252
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:135
static size_type rowdim(const Matrix &)
Definition: matrixutils.hh:437
Check whether the a matrix has diagonal values on blocklevel recursion levels.
Definition: matrixutils.hh:82
size_type M() const
number of columns (counted in blocks)
Definition: bcrsmatrix.hh:1855
Matrix::size_type size_type
Definition: matrixutils.hh:241
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:412
Matrix::size_type size_type
Definition: matrixutils.hh:319
A::size_type size_type
The type for the index access and the size.
Definition: bcrsmatrix.hh:447
BCRSMatrix< B, TA > Matrix
Definition: matrixutils.hh:239
Matrix::size_type size_type
Definition: matrixutils.hh:425
static size_type coldim(const Matrix &, size_type)
Definition: matrixutils.hh:432
Definition: matrixutils.hh:513
FieldMatrix< K, n, m > Matrix
Definition: matrixutils.hh:343
static size_type rowdim(const Matrix &, size_type)
Definition: matrixutils.hh:346
static size_type coldim(const ThisMatrix &A)
Definition: matrixutils.hh:415
static size_type coldim(const Matrix &, size_type)
Definition: matrixutils.hh:351
static size_type rowdim(const Matrix &A)
Definition: matrixutils.hh:331
static size_type coldim(const MatrixType &A)
Definition: matrixutils.hh:388
static void check(const Matrix &mat)
Definition: matrixutils.hh:109
A::size_type size_type
Type for indices and sizes.
Definition: matrix.hh:41
B * getptr()
get pointer
Definition: bvector.hh:1050
RowIterator end()
Get iterator to one beyond last row.
Definition: matrix.hh:85
VariableBlockVector< T, A >::ConstIterator ConstRowIterator
Const iterator over the matrix rows.
Definition: matrix.hh:50
static size_type rowdim(const Matrix &, size_type)
Definition: matrixutils.hh:454
static size_type coldim(const Matrix &)
Definition: matrixutils.hh:442
Col col
Definition: matrixmatrix.hh:347
static size_type coldim(const MatrixType &, size_type)
Definition: matrixutils.hh:378
ScaledIdentityMatrix< K, n > Matrix
Definition: matrixutils.hh:451
void printGlobalSparseMatrix(const M &mat, C &ooc, std::ostream &os)
Definition: matrixutils.hh:177
Dune::DynamicMatrix< T > MatrixType
Definition: matrixutils.hh:370
static size_type coldim(const Matrix &)
Definition: matrixutils.hh:469
A multiple of the identity matrix of static size.
Definition: scaledidmatrix.hh:27
static size_type rowdim(const ThisMatrix &A)
Definition: matrixutils.hh:410
static size_type coldim(const Matrix &A)
Definition: matrixutils.hh:335
Matrix< FieldMatrix< K, n, m >, TA > ThisMatrix
Definition: matrixutils.hh:397
static size_type rowdim(const Matrix &A)
Definition: matrixutils.hh:280
Definition: bcrsmatrix.hh:71
static size_type rowdim(const Matrix &A, size_type i)
Definition: matrixutils.hh:243
static size_type coldim(const Matrix &, size_type)
Definition: matrixutils.hh:459
Matrix::size_type size_type
Definition: matrixutils.hh:344
static size_type rowdim(const ThisMatrix &, size_type)
Definition: matrixutils.hh:400
Iterator end()
Get iterator to one beyond last row.
Definition: bcrsmatrix.hh:630
bool operator()(const T *l, const T *r)
Definition: matrixutils.hh:515
static size_type rowdim(const Matrix &)
Definition: matrixutils.hh:464
Definition: basearray.hh:19
DiagonalMatrix< K, n > Matrix
Definition: matrixutils.hh:424
RowIterator begin()
Get iterator to first row.
Definition: matrix.hh:79
size_type N() const
number of rows (counted in blocks)
Definition: bcrsmatrix.hh:1849