6 #ifndef DUNE_ISTL_BCRSMATRIX_HH 7 #define DUNE_ISTL_BCRSMATRIX_HH 23 #include <dune/common/stdstreams.hh> 24 #include <dune/common/iteratorfacades.hh> 25 #include <dune/common/typetraits.hh> 26 #include <dune/common/ftraits.hh> 27 #include <dune/common/scalarvectorview.hh> 28 #include <dune/common/scalarmatrixview.hh> 87 template<
typename size_type>
145 return _m.entry(_i,j);
174 if (m.buildMode() != Matrix::implicit)
175 DUNE_THROW(
BCRSMatrixError,
"You can only create an ImplicitBuilder for a matrix in implicit build mode");
176 if (m.buildStage() != Matrix::building)
177 DUNE_THROW(
BCRSMatrixError,
"You can only create an ImplicitBuilder for a matrix with set size that has not been compressed() yet");
198 if (m.buildStage() != Matrix::notAllocated)
199 DUNE_THROW(
BCRSMatrixError,
"You can only set up a matrix for this ImplicitBuilder if it has no memory allocated yet");
200 m.setBuildMode(Matrix::implicit);
201 m.setImplicitBuildModeParameters(avg_cols_per_row,overflow_fraction);
202 m.setSize(rows,cols);
465 template<
class B,
class A=std::allocator<B> >
501 typedef Imp::CompressedBlockVectorWindow<B,size_type>
row_type;
548 #ifdef DUNE_ISTL_WITH_CHECKING 550 DUNE_THROW(
BCRSMatrixError,
"You cannot use operator[] in implicit build mode before calling compress()");
560 #ifdef DUNE_ISTL_WITH_CHECKING 562 DUNE_THROW(
BCRSMatrixError,
"You cannot use operator[] in implicit build mode before calling compress()");
575 :
public RandomAccessIteratorFacade<RealRowIterator<T>, T>
647 void advance(std::ptrdiff_t diff)
652 T& elementAt(std::ptrdiff_t diff)
const 788 DUNE_THROW(
BCRSMatrixError,
"Only call this constructor when using the implicit build mode");
794 DUNE_THROW(
BCRSMatrixError,
"You cannot set a negative overflow fraction");
809 DUNE_THROW(InvalidStateException,
"BCRSMatrix can only be copy-constructed when source matrix is completely empty (size not set) or fully built)");
841 DUNE_THROW(InvalidStateException,
"Matrix structure cannot be changed at this stage anymore (ready == "<<
ready<<
").");
867 DUNE_THROW(
Dune::BCRSMatrixError,
"number of non-zeroes may not be set in implicit mode, use setImplicitBuildModeParameters() instead");
875 allocate(rows, columns, nnz,
true,
false);
893 if (compressionBufferSize < 0.0)
894 DUNE_THROW(
BCRSMatrixError,
"You cannot set a negative compressionBufferSize value");
898 DUNE_THROW(InvalidStateException,
"You cannot modify build mode parameters at this stage anymore");
912 if (&Mat==
this)
return *
this;
915 DUNE_THROW(InvalidStateException,
"BCRSMatrix can only be copied when both target and source are empty or fully built)");
922 if (
n>0 &&
n!=Mat.
n) {
924 for(
row_type *riter=
r+(
n-1), *rend=
r-1; riter!=rend; --riter)
945 DUNE_THROW(InvalidStateException,
"Scalar assignment only works on fully built BCRSMatrix)");
959 : Mat(_Mat), i(_i), nnz(0), current_row(nullptr, Mat.
j_.
get(), 0)
966 DUNE_THROW(
BCRSMatrixError,
"creation only allowed for uninitialized matrix");
968 DUNE_THROW(
BCRSMatrixError,
"creation only allowed if row wise allocation was requested in the constructor");
969 if(i==0 && _Mat.
N()==0)
1002 Mat.
r[i].set(s,
nullptr,current_row.getindexptr());
1003 current_row.setindexptr(current_row.getindexptr()+s);
1012 Mat.
r[i].set(s,b,j);
1016 Mat.
r[i].set(0,
nullptr,
nullptr);
1019 std::visit([&](
const auto& row_indices){
1020 std::copy(row_indices.cbegin(), row_indices.cend(), Mat.
r[i].getindexptr());
1021 }, pattern.storage());
1048 return (i!=it.i) || (&Mat!=&it.Mat);
1054 return (i==it.i) && (&Mat==&it.Mat);
1072 return pattern.contains(j);
1081 return pattern.size();
1088 using PatternType =
typename Impl::RowIndexSet;
1089 PatternType pattern;
1130 #ifdef DUNE_ISTL_WITH_CHECKING 1134 return r[i].getsize();
1145 r[i].setsize(
r[i].getsize()+s);
1160 total +=
r[i].getsize();
1166 else if(
nnz_ < total)
1168 <<
"sufficient for calculated nonzeros ("<<total<<
"! ");
1200 DUNE_THROW(
BCRSMatrixError,
"matrix size not set and no memory allocated yet");
1206 size_type*
const first =
r[row].getindexptr();
1207 size_type*
const last = first +
r[row].getsize();
1213 if (pos!=last && *pos ==
col)
return;
1221 std::copy_backward(pos,
end,
end+1);
1234 template<
typename It>
1241 if ((col_end = std::copy(
begin,
end,
r[row].getindexptr())) != col_begin + row_size)
1244 <<
") does not match number of passed entries (" << (col_end - col_begin) <<
")");
1257 template<
typename It>
1264 if ((col_end = std::copy(
begin,
end,
r[row].getindexptr())) != col_begin + row_size)
1267 <<
") does not match number of passed entries (" << (col_end - col_begin) <<
")");
1268 std::sort(col_begin,col_end);
1281 DUNE_THROW(
BCRSMatrixError,
"matrix size not set and no memory allocated yet");
1289 if (j.index() >=
m) {
1290 dwarn <<
"WARNING: size of row "<< i.index()<<
" is "<<j.offset()<<
". But was specified as being "<< (*i).end().offset()
1291 <<
". This means you are wasting valuable space and creating additional cache misses!"<<std::endl;
1292 nnz_ -= ((*i).end().offset() - j.offset());
1293 r[i.index()].setsize(j.offset());
1322 #ifdef DUNE_ISTL_WITH_CHECKING 1326 DUNE_THROW(
BCRSMatrixError,
"matrix already built up, use operator[] for entry access now");
1328 DUNE_THROW(
BCRSMatrixError,
"matrix size not set and no memory allocated yet");
1330 DUNE_THROW(InvalidStateException,
"You may only use entry() during the 'building' stage");
1347 std::ptrdiff_t offset = pos -
r[row].getindexptr();
1348 B* aptr =
r[row].getptr() + offset;
1354 if (
r[row].getsize() ==
avg)
1362 std::ptrdiff_t offset =
end -
r[row].getindexptr();
1363 B* apos =
r[row].getptr() + offset;
1366 r[row].setsize(
r[row].getsize()+1);
1389 DUNE_THROW(
BCRSMatrixError,
"matrix already built up, no more need for compression");
1391 DUNE_THROW(
BCRSMatrixError,
"matrix size not set and no memory allocated yet");
1393 DUNE_THROW(InvalidStateException,
"You may only call compress() at the end of the 'building' stage");
1405 typename OverflowType::iterator oit =
overflow.begin();
1408 std::vector<size_type*> perm;
1420 typename std::vector<size_type*>::iterator it = perm.begin();
1425 std::sort(perm.begin(),perm.end(), [](
const size_type* l,
const size_type*
r){
return *l < *
r; });
1428 r[i].setindexptr(jiit);
1431 for (it = perm.begin(); it != perm.end(); ++it)
1434 while ((oit!=
overflow.end()) && (oit->first < std::make_pair(i,**it)))
1439 "Allocated memory for BCRSMatrix exhausted during compress()!" 1440 "Please increase either the average number of entries per row or the compressionBufferSize value." 1443 *jiit = oit->first.second;
1445 *aiit = oit->second;
1448 r[i].setsize(
r[i].getsize()+1);
1454 "Allocated memory for BCRSMatrix exhausted during compress()!" 1455 "Please increase either the average number of entries per row or the compressionBufferSize value." 1461 B* apos = *it -
j_.get() +
a;
1467 while ((oit!=
overflow.end()) && (oit->first.first == i))
1472 "Allocated memory for BCRSMatrix exhausted during compress()!" 1473 "Please increase either the average number of entries per row or the compressionBufferSize value." 1477 *jiit = oit->first.second;
1479 *aiit = oit->second;
1482 r[i].setsize(
r[i].getsize()+1);
1501 std::ptrdiff_t diff = (
r[
n-1].getindexptr() +
r[
n-1].getsize() -
j_.get());
1503 stats.
avg = (double) (
nnz_) / (double)
n;
1518 #ifdef DUNE_ISTL_WITH_CHECKING 1520 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1546 #ifdef DUNE_ISTL_WITH_CHECKING 1548 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1579 #ifdef DUNE_ISTL_WITH_CHECKING 1581 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1582 if(
N()!=b.
N() ||
M() != b.
M())
1583 DUNE_THROW(RangeError,
"Matrix sizes do not match!");
1601 #ifdef DUNE_ISTL_WITH_CHECKING 1603 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1604 if(
N()!=b.
N() ||
M() != b.
M())
1605 DUNE_THROW(RangeError,
"Matrix sizes do not match!");
1626 #ifdef DUNE_ISTL_WITH_CHECKING 1628 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1629 if(
N()!=b.
N() ||
M() != b.
M())
1630 DUNE_THROW(RangeError,
"Matrix sizes do not match!");
1643 template<
class X,
class Y>
1644 void mv (
const X& x, Y& y)
const 1646 #ifdef DUNE_ISTL_WITH_CHECKING 1648 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1650 "Size mismatch: M: " <<
N() <<
"x" <<
M() <<
" x: " << x.N());
1652 "Size mismatch: M: " <<
N() <<
"x" <<
M() <<
" y: " << y.N());
1661 auto&& xj = Impl::asVector(x[j.index()]);
1662 auto&& yi = Impl::asVector(y[i.index()]);
1663 Impl::asMatrix(*j).umv(xj, yi);
1669 template<
class X,
class Y>
1670 void umv (
const X& x, Y& y)
const 1672 #ifdef DUNE_ISTL_WITH_CHECKING 1674 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1684 auto&& xj = Impl::asVector(x[j.index()]);
1685 auto&& yi = Impl::asVector(y[i.index()]);
1686 Impl::asMatrix(*j).umv(xj,yi);
1692 template<
class X,
class Y>
1693 void mmv (
const X& x, Y& y)
const 1695 #ifdef DUNE_ISTL_WITH_CHECKING 1697 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1707 auto&& xj = Impl::asVector(x[j.index()]);
1708 auto&& yi = Impl::asVector(y[i.index()]);
1709 Impl::asMatrix(*j).mmv(xj,yi);
1715 template<
class X,
class Y,
class F>
1716 void usmv (F&& alpha,
const X& x, Y& y)
const 1718 #ifdef DUNE_ISTL_WITH_CHECKING 1720 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1730 auto&& xj = Impl::asVector(x[j.index()]);
1731 auto&& yi = Impl::asVector(y[i.index()]);
1732 Impl::asMatrix(*j).usmv(alpha,xj,yi);
1738 template<
class X,
class Y>
1739 void mtv (
const X& x, Y& y)
const 1741 #ifdef DUNE_ISTL_WITH_CHECKING 1743 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1753 template<
class X,
class Y>
1756 #ifdef DUNE_ISTL_WITH_CHECKING 1758 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1768 auto&& xi = Impl::asVector(x[i.index()]);
1769 auto&& yj = Impl::asVector(y[j.index()]);
1770 Impl::asMatrix(*j).umtv(xi,yj);
1776 template<
class X,
class Y>
1779 #ifdef DUNE_ISTL_WITH_CHECKING 1789 auto&& xi = Impl::asVector(x[i.index()]);
1790 auto&& yj = Impl::asVector(y[j.index()]);
1791 Impl::asMatrix(*j).mmtv(xi,yj);
1797 template<
class X,
class Y>
1800 #ifdef DUNE_ISTL_WITH_CHECKING 1802 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1812 auto&& xi = Impl::asVector(x[i.index()]);
1813 auto&& yj = Impl::asVector(y[j.index()]);
1814 Impl::asMatrix(*j).usmtv(alpha,xi,yj);
1820 template<
class X,
class Y>
1823 #ifdef DUNE_ISTL_WITH_CHECKING 1825 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1835 auto&& xi = Impl::asVector(x[i.index()]);
1836 auto&& yj = Impl::asVector(y[j.index()]);
1837 Impl::asMatrix(*j).umhv(xi,yj);
1843 template<
class X,
class Y>
1846 #ifdef DUNE_ISTL_WITH_CHECKING 1848 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1858 auto&& xi = Impl::asVector(x[i.index()]);
1859 auto&& yj = Impl::asVector(y[j.index()]);
1860 Impl::asMatrix(*j).mmhv(xi,yj);
1866 template<
class X,
class Y>
1869 #ifdef DUNE_ISTL_WITH_CHECKING 1871 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1881 auto&& xi = Impl::asVector(x[i.index()]);
1882 auto&& yj = Impl::asVector(y[j.index()]);
1883 Impl::asMatrix(*j).usmhv(alpha,xi,yj);
1894 #ifdef DUNE_ISTL_WITH_CHECKING 1896 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1899 typename FieldTraits<field_type>::real_type sum=0;
1901 for (
auto&& row : (*
this))
1902 for (
auto&&
entry : row)
1903 sum += Impl::asMatrix(
entry).frobenius_norm2();
1916 typename std::enable_if<!HasNaN<ft>::value,
int>::type = 0>
1919 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1921 using real_type =
typename FieldTraits<ft>::real_type;
1925 for (
auto const &x : *
this) {
1927 for (
auto const &y : x)
1928 sum += Impl::asMatrix(y).infinity_norm();
1929 norm = max(sum, norm);
1936 typename std::enable_if<!HasNaN<ft>::value,
int>::type = 0>
1939 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1941 using real_type =
typename FieldTraits<ft>::real_type;
1945 for (
auto const &x : *
this) {
1947 for (
auto const &y : x)
1948 sum += Impl::asMatrix(y).infinity_norm_real();
1949 norm = max(sum, norm);
1956 typename std::enable_if<HasNaN<ft>::value,
int>::type = 0>
1959 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1961 using real_type =
typename FieldTraits<ft>::real_type;
1965 real_type is_nan = 1;
1966 for (
auto const &x : *
this) {
1968 for (
auto const &y : x)
1969 sum += Impl::asMatrix(y).infinity_norm();
1970 norm = max(sum, norm);
1974 return norm * (is_nan / is_nan);
1979 typename std::enable_if<HasNaN<ft>::value,
int>::type = 0>
1982 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1984 using real_type =
typename FieldTraits<ft>::real_type;
1988 real_type is_nan = 1;
1990 for (
auto const &x : *
this) {
1992 for (
auto const &y : x)
1993 sum += Impl::asMatrix(y).infinity_norm_real();
1994 norm = max(sum, norm);
1998 return norm * (is_nan / is_nan);
2041 #ifdef DUNE_ISTL_WITH_CHECKING 2045 return (
r[i].size() &&
r[i].find(j) !=
r[i].
end());
2055 typename std::allocator_traits<A>::template rebind_alloc<B>
allocator_;
2057 typename std::allocator_traits<A>::template rebind_alloc<row_type>
rowAllocator_;
2075 std::shared_ptr<size_type>
j_;
2093 r[i].set(s,current_row.getptr(), current_row.getindexptr());
2095 current_row.setptr(current_row.getptr()+s);
2096 current_row.setindexptr(current_row.getindexptr()+s);
2099 r[i].set(0,
nullptr,
nullptr);
2119 r[i].setindexptr(jptr);
2122 r[i].set(0,
nullptr,
nullptr);
2140 if (
r[i].getsize() > 0) {
2145 r[i].set(0,
nullptr,
nullptr);
2149 aptr +=
r[i].getsize();
2193 if (
r[i].getsize()>0)
2195 for (B *
col=
r[i].getptr()+(
r[i].getsize()-1),
2196 *colend =
r[i].getptr()-1;
col!=colend; --
col) {
2197 std::allocator_traits<decltype(allocator_)>::destroy(
allocator_,
col);
2203 r[i].set(0,
nullptr,
nullptr);
2208 if (
n>0 && deallocateRows &&
r) {
2209 for(
row_type *riter=
r+(
n-1), *rend=
r-1; riter!=rend; --riter)
2243 nnz_ = allocationSize;
2250 DUNE_THROW(InvalidStateException,
"Rows have already been allocated, cannot allocate a second time");
2269 alloc.deallocate(ptr, size);
2282 DUNE_THROW(InvalidStateException,
"Cannot allocate data array (already allocated)");
2301 DUNE_THROW(InvalidStateException,
"implicit_allocate() may only be called in implicit build mode");
2303 DUNE_THROW(InvalidStateException,
"memory has already been allocated");
2307 DUNE_THROW(InvalidStateException,
"You have to set the implicit build mode parameters before starting to build the matrix");
2316 B* aptr =
a + osize;
2319 r[i].set(0,aptr,jptr);
2329 template<
class B,
class A>
2333 using real_type =
typename FieldTraits<field_type>::real_type;
bool operator==(const CreateIterator &it) const
equality
Definition: bcrsmatrix.hh:1052
RealRowIterator(row_type *_p, size_type _i)
constructor
Definition: bcrsmatrix.hh:588
BCRSMatrix & operator/=(const field_type &k)
vector space division by scalar
Definition: bcrsmatrix.hh:1544
RealRowIterator< row_type > iterator
The iterator over the (mutable matrix rows.
Definition: bcrsmatrix.hh:668
Imp::CompressedBlockVectorWindow< B, size_type > row_type
implement row_type with compressed vector
Definition: bcrsmatrix.hh:501
BCRSMatrix & operator-=(const BCRSMatrix &b)
Subtract the entries of another matrix from this one.
Definition: bcrsmatrix.hh:1599
bool equals(const RealRowIterator< ValueType > &other) const
equality
Definition: bcrsmatrix.hh:621
BuildStage ready
Definition: bcrsmatrix.hh:2052
row_type & operator[](size_type i)
random access to the rows
Definition: bcrsmatrix.hh:546
A generic dynamic dense matrix.
Definition: matrix.hh:560
ImplicitMatrixBuilder(Matrix &m)
Creates an ImplicitMatrixBuilder for matrix m.
Definition: bcrsmatrix.hh:171
row_object operator[](size_type i) const
Returns a proxy for entries in row i.
Definition: bcrsmatrix.hh:206
size_type size() const
Get the current row size.
Definition: bcrsmatrix.hh:1079
ConstIterator end() const
Get const iterator to one beyond last row.
Definition: bcrsmatrix.hh:715
std::allocator_traits< A >::template rebind_alloc< size_type > sizeAllocator_
Definition: bcrsmatrix.hh:2059
typename BCRSMatrix< B, A >::field_type field_type
Definition: bcrsmatrix.hh:2332
void usmv(F &&alpha, const X &x, Y &y) const
y += alpha A x
Definition: bcrsmatrix.hh:1716
void deallocate(bool deallocateRows=true)
deallocate memory of the matrix.
Definition: bcrsmatrix.hh:2171
Build entries randomly with an educated guess for the number of entries per row.
Definition: bcrsmatrix.hh:536
row_type::ConstIterator ConstColIterator
Const iterator to the entries of a row.
Definition: bcrsmatrix.hh:738
size_type nnz_
Definition: bcrsmatrix.hh:2064
std::ptrdiff_t distanceTo(const RealRowIterator< ValueType > &other) const
Definition: bcrsmatrix.hh:608
void setDataPointers()
Set data pointers for all rows.
Definition: bcrsmatrix.hh:2135
BCRSMatrix(size_type _n, size_type _m, BuildMode bm)
matrix with unknown number of nonzeroes
Definition: bcrsmatrix.hh:762
A::size_type size_type
Type for indices and sizes.
Definition: matrix.hh:577
void allocateData()
Definition: bcrsmatrix.hh:2279
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:466
size_type index() const
return index
Definition: bcrsmatrix.hh:603
void setBuildMode(BuildMode bm)
Sets the build mode of the matrix.
Definition: bcrsmatrix.hh:831
Statistics about compression achieved in implicit mode.
Definition: bcrsmatrix.hh:88
BCRSMatrix & operator=(const BCRSMatrix &Mat)
assignment
Definition: bcrsmatrix.hh:909
BuildMode
we support two modes
Definition: bcrsmatrix.hh:507
BCRSMatrix(size_type _n, size_type _m, size_type _nnz, BuildMode bm)
matrix with known number of nonzeroes
Definition: bcrsmatrix.hh:753
Thrown when the compression buffer used by the implicit BCRSMatrix construction is exhausted...
Definition: istlexception.hh:35
void umv(const X &x, Y &y) const
y += A x
Definition: bcrsmatrix.hh:1670
The matrix structure is fully built.
Definition: bcrsmatrix.hh:483
double avg
average number of non-zeroes per row.
Definition: bcrsmatrix.hh:91
Matrix is not built at all, no memory has been allocated, build mode and size can still be set...
Definition: bcrsmatrix.hh:472
FieldTraits< field_type >::real_type frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: bcrsmatrix.hh:1892
BCRSMatrix(const BCRSMatrix &Mat)
copy constructor
Definition: bcrsmatrix.hh:803
T block_type
Export the type representing the components.
Definition: matrix.hh:568
Col col
Definition: matrixmatrix.hh:351
void umhv(const X &x, Y &y) const
y += A^H x
Definition: bcrsmatrix.hh:1821
Iterator class for sequential creation of blocks
Definition: bcrsmatrix.hh:954
BCRSMatrix & operator+=(const BCRSMatrix &b)
Add the entries of another matrix to this one.
Definition: bcrsmatrix.hh:1577
Proxy row object for entry access.
Definition: bcrsmatrix.hh:137
size_type N() const
number of rows (counted in blocks)
Definition: bcrsmatrix.hh:2004
void setIndicesNoSort(size_type row, It begin, It end)
Set all column indices for row from the given iterator range.
Definition: bcrsmatrix.hh:1235
typename FieldTraits< field_type >::real_type real_type
Definition: bcrsmatrix.hh:2333
Matrix::size_type size_type
The size_type of the underlying matrix.
Definition: bcrsmatrix.hh:129
size_type M() const
The number of columns in the matrix.
Definition: bcrsmatrix.hh:218
size_type index() const
The number of the row that the iterator currently points to.
Definition: bcrsmatrix.hh:1058
std::map< std::pair< size_type, size_type >, B > OverflowType
Definition: bcrsmatrix.hh:2081
bool contains(size_type j)
return true if column index is in row
Definition: bcrsmatrix.hh:1070
Matrix is not built at all, no memory has been allocated, build mode and size can still be set...
Definition: bcrsmatrix.hh:474
void setColumnPointers(ConstRowIterator row)
Copy row sizes from iterator range starting at row and set column index pointers for all rows...
Definition: bcrsmatrix.hh:2109
BuildStage
Definition: bcrsmatrix.hh:470
size_type allocationSize_
Definition: bcrsmatrix.hh:2065
void umtv(const X &x, Y &y) const
y += A^T x
Definition: bcrsmatrix.hh:1754
double compressionBufferSize_
Definition: bcrsmatrix.hh:2079
Iterator end()
Get iterator to one beyond last row.
Definition: bcrsmatrix.hh:678
size_type N() const
The number of rows in the matrix.
Definition: bcrsmatrix.hh:212
Helper functions for determining the vector/matrix block level.
void usmhv(const field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: bcrsmatrix.hh:1867
void endrowsizes()
indicate that size of all rows is defined
Definition: bcrsmatrix.hh:1149
double mem_ratio
fraction of wasted memory resulting from non-used overflow area.
Definition: bcrsmatrix.hh:100
BuildStage buildStage() const
The current build stage of the matrix.
Definition: bcrsmatrix.hh:2025
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: bcrsmatrix.hh:1777
RealRowIterator< row_type > Iterator
Definition: bcrsmatrix.hh:669
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: bcrsmatrix.hh:489
M_ Matrix
The underlying matrix.
Definition: bcrsmatrix.hh:123
BuildMode build_mode
Definition: bcrsmatrix.hh:2051
B & entry(size_type row, size_type col)
Returns reference to entry (row,col) of the matrix.
Definition: bcrsmatrix.hh:1320
ConstIterator begin() const
Get const iterator to first row.
Definition: bcrsmatrix.hh:709
void mmv(const X &x, Y &y) const
y -= A x
Definition: bcrsmatrix.hh:1693
ImplicitMatrixBuilder(Matrix &m, size_type rows, size_type cols, size_type avg_cols_per_row, double overflow_fraction)
Sets up matrix m for implicit construction using the given parameters and creates an ImplicitBmatrixu...
Definition: bcrsmatrix.hh:195
void implicit_allocate(size_type _n, size_type _m)
organizes allocation implicit mode calculates correct array size to be allocated and sets the the win...
Definition: bcrsmatrix.hh:2298
B * a
Definition: bcrsmatrix.hh:2072
BuildMode buildMode() const
The currently selected build mode of the matrix.
Definition: bcrsmatrix.hh:2031
This file implements a vector space as a tensor product of a given vector space. The number of compon...
RealRowIterator()
empty constructor, use with care!
Definition: bcrsmatrix.hh:593
Iterator beforeBegin()
Definition: bcrsmatrix.hh:692
block_type & operator[](size_type j) const
Returns entry in column j.
Definition: bcrsmatrix.hh:143
CreateIterator createend()
get create iterator pointing to one after the last block
Definition: bcrsmatrix.hh:1103
~BCRSMatrix()
destructor
Definition: bcrsmatrix.hh:822
Matrix is currently being built, some memory has been allocated, build mode and size are fixed...
Definition: bcrsmatrix.hh:476
void setIndices(size_type row, It begin, It end)
Set all column indices for row from the given iterator range.
Definition: bcrsmatrix.hh:1258
row_type * r
Definition: bcrsmatrix.hh:2069
Iterator begin()
Get iterator to first row.
Definition: bcrsmatrix.hh:672
void allocate(size_type rows, size_type columns, size_type allocationSize, bool allocateRows, bool allocate_data)
Allocate memory for the matrix structure.
Definition: bcrsmatrix.hh:2238
void mv(const X &x, Y &y) const
y = A x
Definition: bcrsmatrix.hh:1644
BCRSMatrix(size_type _n, size_type _m, size_type _avg, double compressionBufferSize, BuildMode bm)
construct matrix with a known average number of entries per row
Definition: bcrsmatrix.hh:782
B block_type
export the type representing the components
Definition: bcrsmatrix.hh:492
FieldTraits< ft >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bcrsmatrix.hh:1937
::Dune::CompressionStatistics< size_type > CompressionStatistics
The type for the statistics object returned by compress()
Definition: bcrsmatrix.hh:504
void incrementrowsize(size_type i, size_type s=1)
increment size of row i by s (1 by default)
Definition: bcrsmatrix.hh:1138
void endindices()
indicate that all indices are defined, check consistency
Definition: bcrsmatrix.hh:1272
The row sizes of the matrix are known.
Definition: bcrsmatrix.hh:481
A::size_type size_type
The type for the index access and the size.
Definition: bcrsmatrix.hh:498
size_type n
Definition: bcrsmatrix.hh:2062
ConstIterator beforeBegin() const
Definition: bcrsmatrix.hh:729
size_type maximum
maximum number of non-zeroes per row.
Definition: bcrsmatrix.hh:93
CreateIterator(BCRSMatrix &_Mat, size_type _i)
constructor
Definition: bcrsmatrix.hh:958
row_type::Iterator ColIterator
Iterator for the entries of each row.
Definition: bcrsmatrix.hh:701
void addindex(size_type row, size_type col)
add index (row,col) to the matrix
Definition: bcrsmatrix.hh:1191
void setrowsize(size_type i, size_type s)
Set number of indices in row i to s.
Definition: bcrsmatrix.hh:1117
void copyWindowStructure(const BCRSMatrix &Mat)
Copy the window structure from another matrix.
Definition: bcrsmatrix.hh:2154
Build in a row-wise manner.
Definition: bcrsmatrix.hh:518
std::remove_const< T >::type ValueType
The unqualified value type.
Definition: bcrsmatrix.hh:580
bool exists(size_type i, size_type j) const
return true if (i,j) is in pattern
Definition: bcrsmatrix.hh:2039
size_type getrowsize(size_type i) const
get current number of indices in row i
Definition: bcrsmatrix.hh:1128
Definition: bcrsmatrix.hh:78
bool operator!=(const CreateIterator &it) const
inequality
Definition: bcrsmatrix.hh:1046
Matrix::block_type block_type
The block_type of the underlying matrix.
Definition: bcrsmatrix.hh:126
BCRSMatrix & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: bcrsmatrix.hh:1516
FieldTraits< ft >::real_type infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: bcrsmatrix.hh:1917
Build mode not set!
Definition: bcrsmatrix.hh:540
std::ptrdiff_t distanceTo(const RealRowIterator< const ValueType > &other) const
Definition: bcrsmatrix.hh:614
Error specific to BCRSMatrix.
Definition: istlexception.hh:22
size_type avg
Definition: bcrsmatrix.hh:2078
size_type overflow_total
total number of elements written to the overflow area during construction.
Definition: bcrsmatrix.hh:95
Iterator beforeEnd()
Definition: bcrsmatrix.hh:685
ConstIterator beforeEnd() const
Definition: bcrsmatrix.hh:722
friend class CreateIterator
allow CreateIterator to access internal data
Definition: bcrsmatrix.hh:1094
OverflowType overflow
Definition: bcrsmatrix.hh:2082
Some handy generic functions for ISTL matrices.
Iterator access to matrix rows
Definition: bcrsmatrix.hh:574
size_type M() const
number of columns (counted in blocks)
Definition: bcrsmatrix.hh:2010
A wrapper for uniform access to the BCRSMatrix during and after the build stage in implicit build mod...
Definition: bcrsmatrix.hh:117
Definition: allocator.hh:11
std::allocator_traits< A >::template rebind_alloc< row_type > rowAllocator_
Definition: bcrsmatrix.hh:2057
BCRSMatrix & axpy(field_type alpha, const BCRSMatrix &b)
Add the scaled entries of another matrix to this one.
Definition: bcrsmatrix.hh:1624
void mtv(const X &x, Y &y) const
y = A^T x
Definition: bcrsmatrix.hh:1739
RealRowIterator< const row_type > ConstIterator
Definition: bcrsmatrix.hh:705
size_type m
Definition: bcrsmatrix.hh:2063
std::allocator_traits< A >::template rebind_alloc< B > allocator_
Definition: bcrsmatrix.hh:2055
std::shared_ptr< size_type > j_
Definition: bcrsmatrix.hh:2075
CompressionStatistics compress()
Finishes the buildstage in implicit mode.
Definition: bcrsmatrix.hh:1384
void setSize(size_type rows, size_type columns, size_type nnz=0)
Set the size of the matrix.
Definition: bcrsmatrix.hh:859
CreateIterator createbegin()
get initial create iterator
Definition: bcrsmatrix.hh:1097
FieldTraits< field_type >::real_type frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: bcrsmatrix.hh:1909
A allocator_type
export the allocator type
Definition: bcrsmatrix.hh:495
void insert(size_type j)
put column index in row
Definition: bcrsmatrix.hh:1064
PropertyMapTypeSelector< Amg::VertexVisitedTag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > >::Type get([[maybe_unused]] const Amg::VertexVisitedTag &tag, Amg::PropertiesGraph< G, Amg::VertexProperties, EP, VM, EM > &graph)
Definition: dependency.hh:293
RealRowIterator(const RealRowIterator< ValueType > &it)
Definition: bcrsmatrix.hh:597
bool equals(const RealRowIterator< const ValueType > &other) const
equality
Definition: bcrsmatrix.hh:628
void usmtv(const field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: bcrsmatrix.hh:1798
RealRowIterator< const row_type > const_iterator
The const iterator over the matrix rows.
Definition: bcrsmatrix.hh:704
void setWindowPointers(ConstRowIterator row)
Definition: bcrsmatrix.hh:2084
void setImplicitBuildModeParameters(size_type _avg, double compressionBufferSize)
Set parameters needed for creation in implicit build mode.
Definition: bcrsmatrix.hh:887
ConstIterator ConstRowIterator
rename the const row iterator for easier access
Definition: bcrsmatrix.hh:735
Iterator RowIterator
rename the iterators for easier access
Definition: bcrsmatrix.hh:698
CreateIterator & operator++()
prefix increment
Definition: bcrsmatrix.hh:975
BCRSMatrix()
an empty matrix
Definition: bcrsmatrix.hh:746
Build entries randomly.
Definition: bcrsmatrix.hh:527
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: bcrsmatrix.hh:1844
size_type nonzeroes() const
number of blocks that are stored (the number of blocks that possibly are nonzero) ...
Definition: bcrsmatrix.hh:2016