3 #ifndef DUNE_ISTL_BTDMATRIX_HH
4 #define DUNE_ISTL_BTDMATRIX_HH
6 #include <dune/common/fmatrix.hh>
7 #include <dune/common/scalarvectorview.hh>
8 #include <dune/common/scalarmatrixview.hh>
26 template <
class B,
class A=std::allocator<B> >
34 using field_type =
typename Imp::BlockTraits<B>::field_type;
49 static constexpr
unsigned int blocklevel = Imp::BlockTraits<B>::blockLevel()+1;
59 for (
size_t i=0; i<size; i++)
65 for (
size_t i=0; i<size; i++) {
79 auto nonZeros = (size==0) ? 0 : size + 2*(size-1);
86 for (
size_t i=0; i<size; i++)
92 for (
size_t i=0; i<size; i++) {
121 void solve (V& x,
const V& rhs)
const {
125 auto&& x0 = Impl::asVector(x[0]);
126 auto&& rhs0 = Impl::asVector(rhs[0]);
127 Impl::asMatrix((*
this)[0][0]).solve(x0, rhs0);
133 std::vector<block_type> c(this->
N()-1);
134 for (
size_t i=0; i<this->
N()-1; i++)
135 c[i] = (*
this)[i][i+1];
139 Impl::asMatrix(a_00_inv).invert();
143 Impl::asMatrix(tmp).rightmultiply(Impl::asMatrix(c[0]));
148 auto&& d_0 = Impl::asVector(d[0]);
149 Impl::asMatrix(a_00_inv).mv(Impl::asVector(d_0_tmp),d_0);
151 for (
unsigned int i = 1; i < this->
N(); i++) {
155 tmp = (*this)[i][i-1];
156 Impl::asMatrix(tmp).rightmultiply(Impl::asMatrix(c[i-1]));
160 Impl::asMatrix(
id).invert();
163 Impl::asMatrix(c[i]).leftmultiply(Impl::asMatrix(
id));
167 auto&& d_i = Impl::asVector(d[i]);
168 Impl::asMatrix((*
this)[i][i-1]).mmv(Impl::asVector(d[i-1]), d_i);
170 Impl::asMatrix(
id).mv(Impl::asVector(tmpVec), d_i);
174 x[this->
N() - 1] = d[this->
N() - 1];
175 for (
int i = this->
N() - 2; i >= 0; i--) {
178 auto&& x_i = Impl::asVector(x[i]);
179 Impl::asMatrix(c[i]).mmv(Impl::asVector(x[i+1]), x_i);
195 void endrowsizes () {}
197 void endindices () {}
Implementation of the BCRSMatrix class.
Col col
Definition: matrixmatrix.hh:349
Definition: allocator.hh:7
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:426
BCRSMatrix & operator=(const BCRSMatrix &Mat)
assignment
Definition: bcrsmatrix.hh:870
void endrowsizes()
indicate that size of all rows is defined
Definition: bcrsmatrix.hh:1108
@ random
Build entries randomly.
Definition: bcrsmatrix.hh:489
void addindex(size_type row, size_type col)
add index (row,col) to the matrix
Definition: bcrsmatrix.hh:1150
void endindices()
indicate that all indices are defined, check consistency
Definition: bcrsmatrix.hh:1207
size_type N() const
number of rows (counted in blocks)
Definition: bcrsmatrix.hh:1931
void setSize(size_type rows, size_type columns, size_type nnz=0)
Set the size of the matrix.
Definition: bcrsmatrix.hh:820
A block-tridiagonal matrix.
Definition: btdmatrix.hh:28
BTDMatrix(size_type size)
Definition: btdmatrix.hh:54
void solve(V &x, const V &rhs) const
Use the Thomas algorithm to solve the system Ax=b in O(n) time.
Definition: btdmatrix.hh:121
BTDMatrix & operator=(const BTDMatrix &other)
assignment
Definition: btdmatrix.hh:104
A::size_type size_type
implement row_type with compressed vector
Definition: btdmatrix.hh:46
A allocator_type
export the allocator type
Definition: btdmatrix.hh:40
static constexpr unsigned int blocklevel
increment block level counter
Definition: btdmatrix.hh:49
B block_type
export the type representing the components
Definition: btdmatrix.hh:37
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: btdmatrix.hh:34
BTDMatrix()
Default constructor.
Definition: btdmatrix.hh:52
void setSize(size_type size)
Resize the matrix. Invalidates the content!
Definition: btdmatrix.hh:77