4 #ifndef DUNE_ISTL_BCRSMATRIX_HH
5 #define DUNE_ISTL_BCRSMATRIX_HH
20 #include <dune/common/stdstreams.hh>
21 #include <dune/common/iteratorfacades.hh>
22 #include <dune/common/typetraits.hh>
23 #include <dune/common/ftraits.hh>
24 #include <dune/common/scalarvectorview.hh>
25 #include <dune/common/scalarmatrixview.hh>
75 struct MatrixDimension;
84 template<
typename size_type>
142 return _m.entry(_i,j);
171 if (m.buildMode() != Matrix::implicit)
172 DUNE_THROW(
BCRSMatrixError,
"You can only create an ImplicitBuilder for a matrix in implicit build mode");
173 if (m.buildStage() != Matrix::building)
174 DUNE_THROW(
BCRSMatrixError,
"You can only create an ImplicitBuilder for a matrix with set size that has not been compressed() yet");
195 if (m.buildStage() != Matrix::notAllocated)
196 DUNE_THROW(
BCRSMatrixError,
"You can only set up a matrix for this ImplicitBuilder if it has no memory allocated yet");
197 m.setBuildMode(Matrix::implicit);
198 m.setImplicitBuildModeParameters(avg_cols_per_row,overflow_fraction);
199 m.setSize(rows,cols);
462 template<
class B,
class A=std::allocator<B> >
495 typedef Imp::CompressedBlockVectorWindow<B,A>
row_type;
504 [[deprecated(
"Use free function blockLevel(). Will be removed after 2.8.")]]
505 static constexpr
unsigned int blocklevel = blockLevel<B>()+1;
549 #ifdef DUNE_ISTL_WITH_CHECKING
551 DUNE_THROW(
BCRSMatrixError,
"You cannot use operator[] in implicit build mode before calling compress()");
561 #ifdef DUNE_ISTL_WITH_CHECKING
563 DUNE_THROW(
BCRSMatrixError,
"You cannot use operator[] in implicit build mode before calling compress()");
576 :
public RandomAccessIteratorFacade<RealRowIterator<T>, T>
648 void advance(std::ptrdiff_t diff)
653 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::copy(pattern.cbegin(), pattern.cend(), Mat.
r[i].getindexptr());
1046 return (i!=it.i) || (&Mat!=&it.Mat);
1052 return (i==it.i) && (&Mat==&it.Mat);
1070 return pattern.find(j) != pattern.end();
1079 return pattern.size();
1086 typedef std::set<size_type,std::less<size_type> > PatternType;
1087 PatternType pattern;
1128 #ifdef DUNE_ISTL_WITH_CHECKING
1132 return r[i].getsize();
1143 r[i].setsize(
r[i].getsize()+s);
1158 total +=
r[i].getsize();
1164 else if(
nnz_ < total)
1166 <<
"sufficient for calculated nonzeros ("<<total<<
"! ");
1198 DUNE_THROW(
BCRSMatrixError,
"matrix size not set and no memory allocated yet");
1204 size_type*
const first =
r[row].getindexptr();
1205 size_type*
const last = first +
r[row].getsize();
1211 if (pos!=last && *pos ==
col)
return;
1219 std::copy_backward(pos,
end,
end+1);
1231 template<
typename It>
1238 if ((col_end = std::copy(
begin,
end,
r[row].getindexptr())) != col_begin + row_size)
1241 <<
") does not match number of passed entries (" << (col_end - col_begin) <<
")");
1242 std::sort(col_begin,col_end);
1255 DUNE_THROW(
BCRSMatrixError,
"matrix size not set and no memory allocated yet");
1263 if (j.index() >=
m) {
1264 dwarn <<
"WARNING: size of row "<< i.index()<<
" is "<<j.offset()<<
". But was specified as being "<< (*i).end().offset()
1265 <<
". This means you are wasting valuable space and creating additional cache misses!"<<std::endl;
1266 nnz_ -= ((*i).end().offset() - j.offset());
1267 r[i.index()].setsize(j.offset());
1296 #ifdef DUNE_ISTL_WITH_CHECKING
1300 DUNE_THROW(
BCRSMatrixError,
"matrix already built up, use operator[] for entry access now");
1302 DUNE_THROW(
BCRSMatrixError,
"matrix size not set and no memory allocated yet");
1304 DUNE_THROW(InvalidStateException,
"You may only use entry() during the 'building' stage");
1321 std::ptrdiff_t offset = pos -
r[row].getindexptr();
1322 B* aptr =
r[row].getptr() + offset;
1328 if (
r[row].getsize() ==
avg)
1336 std::ptrdiff_t offset =
end -
r[row].getindexptr();
1337 B* apos =
r[row].getptr() + offset;
1340 r[row].setsize(
r[row].getsize()+1);
1363 DUNE_THROW(
BCRSMatrixError,
"matrix already built up, no more need for compression");
1365 DUNE_THROW(
BCRSMatrixError,
"matrix size not set and no memory allocated yet");
1367 DUNE_THROW(InvalidStateException,
"You may only call compress() at the end of the 'building' stage");
1379 typename OverflowType::iterator oit =
overflow.begin();
1382 std::vector<size_type*> perm;
1394 typename std::vector<size_type*>::iterator it = perm.begin();
1402 r[i].setindexptr(jiit);
1405 for (it = perm.begin(); it != perm.end(); ++it)
1408 while ((oit!=
overflow.end()) && (oit->first < std::make_pair(i,**it)))
1413 "Allocated memory for BCRSMatrix exhausted during compress()!"
1414 "Please increase either the average number of entries per row or the compressionBufferSize value."
1417 *jiit = oit->first.second;
1419 *aiit = oit->second;
1422 r[i].setsize(
r[i].getsize()+1);
1428 "Allocated memory for BCRSMatrix exhausted during compress()!"
1429 "Please increase either the average number of entries per row or the compressionBufferSize value."
1435 B* apos = *it -
j_.get() +
a;
1441 while ((oit!=
overflow.end()) && (oit->first.first == i))
1446 "Allocated memory for BCRSMatrix exhausted during compress()!"
1447 "Please increase either the average number of entries per row or the compressionBufferSize value."
1451 *jiit = oit->first.second;
1453 *aiit = oit->second;
1456 r[i].setsize(
r[i].getsize()+1);
1468 std::ptrdiff_t diff = (
r[
n-1].getindexptr() +
r[
n-1].getsize() -
j_.get());
1470 stats.
avg = (double) (
nnz_) / (double)
n;
1484 #ifdef DUNE_ISTL_WITH_CHECKING
1486 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1512 #ifdef DUNE_ISTL_WITH_CHECKING
1514 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1545 #ifdef DUNE_ISTL_WITH_CHECKING
1547 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1548 if(
N()!=b.
N() ||
M() != b.
M())
1549 DUNE_THROW(RangeError,
"Matrix sizes do not match!");
1567 #ifdef DUNE_ISTL_WITH_CHECKING
1569 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1570 if(
N()!=b.
N() ||
M() != b.
M())
1571 DUNE_THROW(RangeError,
"Matrix sizes do not match!");
1592 #ifdef DUNE_ISTL_WITH_CHECKING
1594 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1595 if(
N()!=b.
N() ||
M() != b.
M())
1596 DUNE_THROW(RangeError,
"Matrix sizes do not match!");
1609 template<
class X,
class Y>
1610 void mv (
const X& x, Y& y)
const
1612 #ifdef DUNE_ISTL_WITH_CHECKING
1614 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1616 "Size mismatch: M: " <<
N() <<
"x" <<
M() <<
" x: " << x.N());
1618 "Size mismatch: M: " <<
N() <<
"x" <<
M() <<
" y: " << y.N());
1627 auto&& xj = Impl::asVector(x[j.index()]);
1628 auto&& yi = Impl::asVector(y[i.index()]);
1629 Impl::asMatrix(*j).umv(xj, yi);
1635 template<
class X,
class Y>
1636 void umv (
const X& x, Y& y)
const
1638 #ifdef DUNE_ISTL_WITH_CHECKING
1640 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1650 auto&& xj = Impl::asVector(x[j.index()]);
1651 auto&& yi = Impl::asVector(y[i.index()]);
1652 Impl::asMatrix(*j).umv(xj,yi);
1658 template<
class X,
class Y>
1659 void mmv (
const X& x, Y& y)
const
1661 #ifdef DUNE_ISTL_WITH_CHECKING
1663 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1673 auto&& xj = Impl::asVector(x[j.index()]);
1674 auto&& yi = Impl::asVector(y[i.index()]);
1675 Impl::asMatrix(*j).mmv(xj,yi);
1681 template<
class X,
class Y,
class F>
1682 void usmv (F&& alpha,
const X& x, Y& y)
const
1684 #ifdef DUNE_ISTL_WITH_CHECKING
1686 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1696 auto&& xj = Impl::asVector(x[j.index()]);
1697 auto&& yi = Impl::asVector(y[i.index()]);
1698 Impl::asMatrix(*j).usmv(alpha,xj,yi);
1704 template<
class X,
class Y>
1705 void mtv (
const X& x, Y& y)
const
1707 #ifdef DUNE_ISTL_WITH_CHECKING
1709 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1719 template<
class X,
class Y>
1722 #ifdef DUNE_ISTL_WITH_CHECKING
1724 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1734 auto&& xi = Impl::asVector(x[i.index()]);
1735 auto&& yj = Impl::asVector(y[j.index()]);
1736 Impl::asMatrix(*j).umtv(xi,yj);
1742 template<
class X,
class Y>
1745 #ifdef DUNE_ISTL_WITH_CHECKING
1755 auto&& xi = Impl::asVector(x[i.index()]);
1756 auto&& yj = Impl::asVector(y[j.index()]);
1757 Impl::asMatrix(*j).mmtv(xi,yj);
1763 template<
class X,
class Y>
1766 #ifdef DUNE_ISTL_WITH_CHECKING
1768 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1778 auto&& xi = Impl::asVector(x[i.index()]);
1779 auto&& yj = Impl::asVector(y[j.index()]);
1780 Impl::asMatrix(*j).usmtv(alpha,xi,yj);
1786 template<
class X,
class Y>
1789 #ifdef DUNE_ISTL_WITH_CHECKING
1791 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1801 auto&& xi = Impl::asVector(x[i.index()]);
1802 auto&& yj = Impl::asVector(y[j.index()]);
1803 Impl::asMatrix(*j).umhv(xi,yj);
1809 template<
class X,
class Y>
1812 #ifdef DUNE_ISTL_WITH_CHECKING
1814 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1824 auto&& xi = Impl::asVector(x[i.index()]);
1825 auto&& yj = Impl::asVector(y[j.index()]);
1826 Impl::asMatrix(*j).mmhv(xi,yj);
1832 template<
class X,
class Y>
1835 #ifdef DUNE_ISTL_WITH_CHECKING
1837 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1847 auto&& xi = Impl::asVector(x[i.index()]);
1848 auto&& yj = Impl::asVector(y[j.index()]);
1849 Impl::asMatrix(*j).usmhv(alpha,xi,yj);
1860 #ifdef DUNE_ISTL_WITH_CHECKING
1862 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1865 typename FieldTraits<field_type>::real_type sum=0;
1867 for (
auto&& row : (*
this))
1868 for (
auto&&
entry : row)
1869 sum += Impl::asMatrix(
entry).frobenius_norm2();
1882 typename std::enable_if<!HasNaN<ft>::value,
int>::type = 0>
1885 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1887 using real_type =
typename FieldTraits<ft>::real_type;
1891 for (
auto const &x : *
this) {
1893 for (
auto const &y : x)
1894 sum += Impl::asMatrix(y).infinity_norm();
1895 norm = max(sum, norm);
1902 typename std::enable_if<!HasNaN<ft>::value,
int>::type = 0>
1905 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1907 using real_type =
typename FieldTraits<ft>::real_type;
1911 for (
auto const &x : *
this) {
1913 for (
auto const &y : x)
1914 sum += Impl::asMatrix(y).infinity_norm_real();
1915 norm = max(sum, norm);
1922 typename std::enable_if<HasNaN<ft>::value,
int>::type = 0>
1925 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1927 using real_type =
typename FieldTraits<ft>::real_type;
1931 real_type isNaN = 1;
1932 for (
auto const &x : *
this) {
1934 for (
auto const &y : x)
1935 sum += Impl::asMatrix(y).infinity_norm();
1936 norm = max(sum, norm);
1940 return norm * (isNaN / isNaN);
1945 typename std::enable_if<HasNaN<ft>::value,
int>::type = 0>
1948 DUNE_THROW(
BCRSMatrixError,
"You can only call arithmetic operations on fully built BCRSMatrix instances");
1950 using real_type =
typename FieldTraits<ft>::real_type;
1954 real_type isNaN = 1;
1956 for (
auto const &x : *
this) {
1958 for (
auto const &y : x)
1959 sum += Impl::asMatrix(y).infinity_norm_real();
1960 norm = max(sum, norm);
1964 return norm * (isNaN / isNaN);
2007 #ifdef DUNE_ISTL_WITH_CHECKING
2011 return (
r[i].size() &&
r[i].find(j) !=
r[i].
end());
2021 typename std::allocator_traits<A>::template rebind_alloc<B>
allocator_;
2023 typename std::allocator_traits<A>::template rebind_alloc<row_type>
rowAllocator_;
2041 std::shared_ptr<size_type>
j_;
2059 r[i].set(s,current_row.getptr(), current_row.getindexptr());
2061 current_row.setptr(current_row.getptr()+s);
2062 current_row.setindexptr(current_row.getindexptr()+s);
2065 r[i].set(0,
nullptr,
nullptr);
2085 r[i].setindexptr(jptr);
2088 r[i].set(0,
nullptr,
nullptr);
2106 if (
r[i].getsize() > 0) {
2111 r[i].set(0,
nullptr,
nullptr);
2115 aptr +=
r[i].getsize();
2159 if (
r[i].getsize()>0)
2161 for (B *
col=
r[i].getptr()+(
r[i].getsize()-1),
2162 *colend =
r[i].getptr()-1;
col!=colend; --
col) {
2169 r[i].set(0,
nullptr,
nullptr);
2174 if (
n>0 && deallocateRows &&
r) {
2175 for(
row_type *riter=
r+(
n-1), *rend=
r-1; riter!=rend; --riter)
2189 typename std::allocator_traits<A>::template rebind_alloc<size_type>& sizeAllocator_;
2192 Deallocator(
typename std::allocator_traits<A>::template rebind_alloc<size_type>& sizeAllocator)
2193 : sizeAllocator_(sizeAllocator)
2222 nnz_ = allocationSize;
2229 DUNE_THROW(InvalidStateException,
"Rows have already been allocated, cannot allocate a second time");
2257 DUNE_THROW(InvalidStateException,
"Cannot allocate data array (already allocated)");
2276 DUNE_THROW(InvalidStateException,
"implicit_allocate() may only be called in implicit build mode");
2278 DUNE_THROW(InvalidStateException,
"memory has already been allocated");
2282 DUNE_THROW(InvalidStateException,
"You have to set the implicit build mode parameters before starting to build the matrix");
2291 B* aptr =
a + osize;
2294 r[i].set(0,aptr,jptr);
Helper functions for determining the vector/matrix block level.
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Some handy generic functions for ISTL matrices.
Col col
Definition: matrixmatrix.hh:349
Definition: allocator.hh:9
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:291
Definition: matrixutils.hh:209
Statistics about compression achieved in implicit mode.
Definition: bcrsmatrix.hh:86
size_type overflow_total
total number of elements written to the overflow area during construction.
Definition: bcrsmatrix.hh:92
size_type maximum
maximum number of non-zeroes per row.
Definition: bcrsmatrix.hh:90
double avg
average number of non-zeroes per row.
Definition: bcrsmatrix.hh:88
double mem_ratio
fraction of wasted memory resulting from non-used overflow area.
Definition: bcrsmatrix.hh:97
A wrapper for uniform access to the BCRSMatrix during and after the build stage in implicit build mod...
Definition: bcrsmatrix.hh:115
Matrix::block_type block_type
The block_type of the underlying matrix.
Definition: bcrsmatrix.hh:123
ImplicitMatrixBuilder(Matrix &m)
Creates an ImplicitMatrixBuilder for matrix m.
Definition: bcrsmatrix.hh:168
M_ Matrix
The underlying matrix.
Definition: bcrsmatrix.hh:120
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:192
size_type M() const
The number of columns in the matrix.
Definition: bcrsmatrix.hh:215
Matrix::size_type size_type
The size_type of the underlying matrix.
Definition: bcrsmatrix.hh:126
row_object operator[](size_type i) const
Returns a proxy for entries in row i.
Definition: bcrsmatrix.hh:203
size_type N() const
The number of rows in the matrix.
Definition: bcrsmatrix.hh:209
Proxy row object for entry access.
Definition: bcrsmatrix.hh:135
block_type & operator[](size_type j) const
Returns entry in column j.
Definition: bcrsmatrix.hh:140
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:464
FieldTraits< field_type >::real_type frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: bcrsmatrix.hh:1875
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: bcrsmatrix.hh:486
std::allocator_traits< A >::template rebind_alloc< row_type > rowAllocator_
Definition: bcrsmatrix.hh:2023
bool exists(size_type i, size_type j) const
return true if (i,j) is in pattern
Definition: bcrsmatrix.hh:2005
BuildStage buildStage() const
The current build stage of the matrix.
Definition: bcrsmatrix.hh:1991
Iterator begin()
Get iterator to first row.
Definition: bcrsmatrix.hh:673
friend class CreateIterator
allow CreateIterator to access internal data
Definition: bcrsmatrix.hh:1092
void copyWindowStructure(const BCRSMatrix &Mat)
Copy the window structure from another matrix.
Definition: bcrsmatrix.hh:2120
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: bcrsmatrix.hh:1810
void usmhv(const field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: bcrsmatrix.hh:1833
void umtv(const X &x, Y &y) const
y += A^T x
Definition: bcrsmatrix.hh:1720
double compressionBufferSize_
Definition: bcrsmatrix.hh:2045
size_type m
Definition: bcrsmatrix.hh:2029
RealRowIterator< const row_type > const_iterator
The const iterator over the matrix rows.
Definition: bcrsmatrix.hh:705
static constexpr unsigned int blocklevel
increment block level counter
Definition: bcrsmatrix.hh:505
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:2217
~BCRSMatrix()
destructor
Definition: bcrsmatrix.hh:822
BCRSMatrix & operator=(const BCRSMatrix &Mat)
assignment
Definition: bcrsmatrix.hh:909
void allocateData()
Definition: bcrsmatrix.hh:2254
void deallocate(bool deallocateRows=true)
deallocate memory of the matrix.
Definition: bcrsmatrix.hh:2137
Iterator RowIterator
rename the iterators for easier access
Definition: bcrsmatrix.hh:699
BCRSMatrix()
an empty matrix
Definition: bcrsmatrix.hh:747
void endrowsizes()
indicate that size of all rows is defined
Definition: bcrsmatrix.hh:1147
void incrementrowsize(size_type i, size_type s=1)
increment size of row i by s (1 by default)
Definition: bcrsmatrix.hh:1136
void mtv(const X &x, Y &y) const
y = A^T x
Definition: bcrsmatrix.hh:1705
void umhv(const X &x, Y &y) const
y += A^H x
Definition: bcrsmatrix.hh:1787
size_type nonzeroes() const
number of blocks that are stored (the number of blocks that possibly are nonzero)
Definition: bcrsmatrix.hh:1982
size_type allocationSize_
Definition: bcrsmatrix.hh:2031
FieldTraits< ft >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bcrsmatrix.hh:1903
ConstIterator ConstRowIterator
rename the const row iterator for easier access
Definition: bcrsmatrix.hh:736
BuildStage ready
Definition: bcrsmatrix.hh:2018
BuildMode build_mode
Definition: bcrsmatrix.hh:2017
void setrowsize(size_type i, size_type s)
Set number of indices in row i to s.
Definition: bcrsmatrix.hh:1115
RealRowIterator< row_type > Iterator
Definition: bcrsmatrix.hh:670
size_type nnz_
Definition: bcrsmatrix.hh:2030
std::allocator_traits< A >::template rebind_alloc< size_type > sizeAllocator_
Definition: bcrsmatrix.hh:2025
RealRowIterator< row_type > iterator
The iterator over the (mutable matrix rows.
Definition: bcrsmatrix.hh:669
void usmtv(const field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: bcrsmatrix.hh:1764
ConstIterator beforeBegin() const
Definition: bcrsmatrix.hh:730
RealRowIterator< const row_type > ConstIterator
Definition: bcrsmatrix.hh:706
Iterator beforeBegin()
Definition: bcrsmatrix.hh:693
B * a
Definition: bcrsmatrix.hh:2038
BuildMode
we support two modes
Definition: bcrsmatrix.hh:508
@ implicit
Build entries randomly with an educated guess for the number of entries per row.
Definition: bcrsmatrix.hh:537
@ unknown
Build mode not set!
Definition: bcrsmatrix.hh:541
@ random
Build entries randomly.
Definition: bcrsmatrix.hh:528
@ row_wise
Build in a row-wise manner.
Definition: bcrsmatrix.hh:519
BCRSMatrix & operator/=(const field_type &k)
vector space division by scalar
Definition: bcrsmatrix.hh:1510
FieldTraits< field_type >::real_type frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: bcrsmatrix.hh:1858
BCRSMatrix(size_type _n, size_type _m, size_type _nnz, BuildMode bm)
matrix with known number of nonzeroes
Definition: bcrsmatrix.hh:754
::Dune::CompressionStatistics< size_type > CompressionStatistics
The type for the statistics object returned by compress()
Definition: bcrsmatrix.hh:501
BCRSMatrix(const BCRSMatrix &Mat)
copy constructor
Definition: bcrsmatrix.hh:803
Iterator end()
Get iterator to one beyond last row.
Definition: bcrsmatrix.hh:679
row_type * r
Definition: bcrsmatrix.hh:2035
void setIndices(size_type row, It begin, It end)
Set all column indices for row from the given iterator range.
Definition: bcrsmatrix.hh:1232
void addindex(size_type row, size_type col)
add index (row,col) to the matrix
Definition: bcrsmatrix.hh:1189
std::map< std::pair< size_type, size_type >, B > OverflowType
Definition: bcrsmatrix.hh:2047
row_type::Iterator ColIterator
Iterator for the entries of each row.
Definition: bcrsmatrix.hh:702
FieldTraits< ft >::real_type infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: bcrsmatrix.hh:1883
A::size_type size_type
The type for the index access and the size.
Definition: bcrsmatrix.hh:498
OverflowType overflow
Definition: bcrsmatrix.hh:2048
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
row_type & operator[](size_type i)
random access to the rows
Definition: bcrsmatrix.hh:547
CreateIterator createend()
get create iterator pointing to one after the last block
Definition: bcrsmatrix.hh:1101
BCRSMatrix & axpy(field_type alpha, const BCRSMatrix &b)
Add the scaled entries of another matrix to this one.
Definition: bcrsmatrix.hh:1590
BCRSMatrix & operator+=(const BCRSMatrix &b)
Add the entries of another matrix to this one.
Definition: bcrsmatrix.hh:1543
Iterator beforeEnd()
Definition: bcrsmatrix.hh:686
row_type::ConstIterator ConstColIterator
Const iterator to the entries of a row.
Definition: bcrsmatrix.hh:739
void usmv(F &&alpha, const X &x, Y &y) const
y += alpha A x
Definition: bcrsmatrix.hh:1682
size_type getrowsize(size_type i) const
get current number of indices in row i
Definition: bcrsmatrix.hh:1126
size_type M() const
number of columns (counted in blocks)
Definition: bcrsmatrix.hh:1976
size_type n
Definition: bcrsmatrix.hh:2028
Imp::CompressedBlockVectorWindow< B, A > row_type
implement row_type with compressed vector
Definition: bcrsmatrix.hh:495
CreateIterator createbegin()
get initial create iterator
Definition: bcrsmatrix.hh:1095
BuildStage
Definition: bcrsmatrix.hh:467
@ rowSizesBuilt
The row sizes of the matrix are known.
Definition: bcrsmatrix.hh:478
@ built
The matrix structure is fully built.
Definition: bcrsmatrix.hh:480
@ notbuilt
Matrix is not built at all, no memory has been allocated, build mode and size can still be set.
Definition: bcrsmatrix.hh:469
@ notAllocated
Matrix is not built at all, no memory has been allocated, build mode and size can still be set.
Definition: bcrsmatrix.hh:471
@ building
Matrix is currently being built, some memory has been allocated, build mode and size are fixed.
Definition: bcrsmatrix.hh:473
BuildMode buildMode() const
The currently selected build mode of the matrix.
Definition: bcrsmatrix.hh:1997
void mmv(const X &x, Y &y) const
y -= A x
Definition: bcrsmatrix.hh:1659
void mv(const X &x, Y &y) const
y = A x
Definition: bcrsmatrix.hh:1610
B block_type
export the type representing the components
Definition: bcrsmatrix.hh:489
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: bcrsmatrix.hh:1743
size_type avg
Definition: bcrsmatrix.hh:2044
void umv(const X &x, Y &y) const
y += A x
Definition: bcrsmatrix.hh:1636
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:2273
void setImplicitBuildModeParameters(size_type _avg, double compressionBufferSize)
Set parameters needed for creation in implicit build mode.
Definition: bcrsmatrix.hh:887
BCRSMatrix(size_type _n, size_type _m, BuildMode bm)
matrix with unknown number of nonzeroes
Definition: bcrsmatrix.hh:763
void endindices()
indicate that all indices are defined, check consistency
Definition: bcrsmatrix.hh:1246
BCRSMatrix & operator-=(const BCRSMatrix &b)
Subtract the entries of another matrix from this one.
Definition: bcrsmatrix.hh:1565
BCRSMatrix & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: bcrsmatrix.hh:1482
CompressionStatistics compress()
Finishes the buildstage in implicit mode.
Definition: bcrsmatrix.hh:1358
B & entry(size_type row, size_type col)
Returns reference to entry (row,col) of the matrix.
Definition: bcrsmatrix.hh:1294
void setDataPointers()
Set data pointers for all rows.
Definition: bcrsmatrix.hh:2101
std::allocator_traits< A >::template rebind_alloc< B > allocator_
Definition: bcrsmatrix.hh:2021
size_type N() const
number of rows (counted in blocks)
Definition: bcrsmatrix.hh:1970
void setBuildMode(BuildMode bm)
Sets the build mode of the matrix.
Definition: bcrsmatrix.hh:831
void setSize(size_type rows, size_type columns, size_type nnz=0)
Set the size of the matrix.
Definition: bcrsmatrix.hh:859
std::shared_ptr< size_type > j_
Definition: bcrsmatrix.hh:2041
void setWindowPointers(ConstRowIterator row)
Definition: bcrsmatrix.hh:2050
void setColumnPointers(ConstRowIterator row)
Copy row sizes from iterator range starting at row and set column index pointers for all rows.
Definition: bcrsmatrix.hh:2075
ConstIterator end() const
Get const iterator to one beyond last row.
Definition: bcrsmatrix.hh:716
ConstIterator begin() const
Get const iterator to first row.
Definition: bcrsmatrix.hh:710
A allocator_type
export the allocator type
Definition: bcrsmatrix.hh:492
ConstIterator beforeEnd() const
Definition: bcrsmatrix.hh:723
Iterator access to matrix rows
Definition: bcrsmatrix.hh:577
RealRowIterator()
empty constructor, use with care!
Definition: bcrsmatrix.hh:594
bool equals(const RealRowIterator< ValueType > &other) const
equality
Definition: bcrsmatrix.hh:622
std::remove_const< T >::type ValueType
The unqualified value type.
Definition: bcrsmatrix.hh:581
RealRowIterator(const RealRowIterator< ValueType > &it)
Definition: bcrsmatrix.hh:598
bool equals(const RealRowIterator< const ValueType > &other) const
equality
Definition: bcrsmatrix.hh:629
RealRowIterator(row_type *_p, size_type _i)
constructor
Definition: bcrsmatrix.hh:589
std::ptrdiff_t distanceTo(const RealRowIterator< const ValueType > &other) const
Definition: bcrsmatrix.hh:615
size_type index() const
return index
Definition: bcrsmatrix.hh:604
std::ptrdiff_t distanceTo(const RealRowIterator< ValueType > &other) const
Definition: bcrsmatrix.hh:609
Iterator class for sequential creation of blocks
Definition: bcrsmatrix.hh:955
bool operator==(const CreateIterator &it) const
equality
Definition: bcrsmatrix.hh:1050
size_type index() const
The number of the row that the iterator currently points to.
Definition: bcrsmatrix.hh:1056
bool operator!=(const CreateIterator &it) const
inequality
Definition: bcrsmatrix.hh:1044
CreateIterator(BCRSMatrix &_Mat, size_type _i)
constructor
Definition: bcrsmatrix.hh:958
CreateIterator & operator++()
prefix increment
Definition: bcrsmatrix.hh:975
void insert(size_type j)
put column index in row
Definition: bcrsmatrix.hh:1062
bool contains(size_type j)
return true if column index is in row
Definition: bcrsmatrix.hh:1068
size_type size() const
Get the current row size.
Definition: bcrsmatrix.hh:1077
Class used by shared_ptr to deallocate memory using the proper allocator.
Definition: bcrsmatrix.hh:2188
Deallocator(typename std::allocator_traits< A >::template rebind_alloc< size_type > &sizeAllocator)
Definition: bcrsmatrix.hh:2192
void operator()(size_type *p)
Definition: bcrsmatrix.hh:2196
Error specific to BCRSMatrix.
Definition: istlexception.hh:22
Thrown when the compression buffer used by the implicit BCRSMatrix construction is exhausted.
Definition: istlexception.hh:35
A generic dynamic dense matrix.
Definition: matrix.hh:559
A::size_type size_type
Type for indices and sizes.
Definition: matrix.hh:575
T block_type
Export the type representing the components.
Definition: matrix.hh:566
Definition: matrixutils.hh:536