5#ifndef DUNE_ISTL_BTDMATRIX_HH
6#define DUNE_ISTL_BTDMATRIX_HH
8#include <dune/common/fmatrix.hh>
9#include <dune/common/scalarvectorview.hh>
10#include <dune/common/scalarmatrixview.hh>
29 template <
class B,
class A=std::allocator<B> >
37 using field_type =
typename Imp::BlockTraits<B>::field_type;
52 [[deprecated(
"Use free blockLevel function. Will be removed after 2.8.")]]
63 for (
size_t i=0; i<size; i++)
69 for (
size_t i=0; i<size; i++) {
83 auto nonZeros = (size==0) ? 0 : size + 2*(size-1);
90 for (
size_t i=0; i<size; i++)
96 for (
size_t i=0; i<size; i++) {
125 void solve (V& x,
const V& rhs)
const {
129 auto&& x0 = Impl::asVector(x[0]);
130 auto&& rhs0 = Impl::asVector(rhs[0]);
131 Impl::asMatrix((*
this)[0][0]).solve(x0, rhs0);
137 std::vector<block_type> c(this->
N()-1);
138 for (
size_t i=0; i<this->
N()-1; i++)
139 c[i] = (*
this)[i][i+1];
143 Impl::asMatrix(a_00_inv).invert();
147 Impl::asMatrix(tmp).rightmultiply(Impl::asMatrix(c[0]));
152 auto&& d_0 = Impl::asVector(d[0]);
153 Impl::asMatrix(a_00_inv).mv(Impl::asVector(d_0_tmp),d_0);
155 for (
unsigned int i = 1; i < this->
N(); i++) {
159 tmp = (*this)[i][i-1];
160 Impl::asMatrix(tmp).rightmultiply(Impl::asMatrix(c[i-1]));
164 Impl::asMatrix(
id).invert();
167 Impl::asMatrix(c[i]).leftmultiply(Impl::asMatrix(
id));
171 auto&& d_i = Impl::asVector(d[i]);
172 Impl::asMatrix((*
this)[i][i-1]).mmv(Impl::asVector(d[i-1]), d_i);
174 Impl::asMatrix(
id).mv(Impl::asVector(tmpVec), d_i);
178 x[this->
N() - 1] = d[this->
N() - 1];
179 for (
int i = this->
N() - 2; i >= 0; i--) {
182 auto&& x_i = Impl::asVector(x[i]);
183 Impl::asMatrix(c[i]).mmv(Impl::asVector(x[i+1]), x_i);
199 void endrowsizes () {}
201 void endindices () {}
204 template<
typename B,
typename A>
208 using real_type =
typename FieldTraits<field_type>::real_type;
Implementation of the BCRSMatrix class.
Helper functions for determining the vector/matrix block level.
Col col
Definition matrixmatrix.hh:351
Definition allocator.hh:11
A sparse block matrix with compressed row storage.
Definition bcrsmatrix.hh:466
void endrowsizes()
indicate that size of all rows is defined
Definition bcrsmatrix.hh:1149
@ random
Build entries randomly.
Definition bcrsmatrix.hh:530
void addindex(size_type row, size_type col)
add index (row,col) to the matrix
Definition bcrsmatrix.hh:1191
void endindices()
indicate that all indices are defined, check consistency
Definition bcrsmatrix.hh:1248
size_type N() const
number of rows (counted in blocks)
Definition bcrsmatrix.hh:1972
void setSize(size_type rows, size_type columns, size_type nnz=0)
Set the size of the matrix.
Definition bcrsmatrix.hh:861
BCRSMatrix & operator=(const BCRSMatrix &Mat)
assignment
Definition bcrsmatrix.hh:911
A block-tridiagonal matrix.
Definition btdmatrix.hh:31
static constexpr auto blocklevel
increment block level counter
Definition btdmatrix.hh:53
BTDMatrix(size_type size)
Definition btdmatrix.hh:58
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:125
A::size_type size_type
implement row_type with compressed vector
Definition btdmatrix.hh:49
A allocator_type
export the allocator type
Definition btdmatrix.hh:43
B block_type
export the type representing the components
Definition btdmatrix.hh:40
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition btdmatrix.hh:37
BTDMatrix & operator=(const BTDMatrix &other)
assignment
Definition btdmatrix.hh:108
BTDMatrix()
Default constructor.
Definition btdmatrix.hh:56
void setSize(size_type size)
Resize the matrix. Invalidates the content!
Definition btdmatrix.hh:81
typename FieldTraits< field_type >::real_type real_type
Definition btdmatrix.hh:208
typename BTDMatrix< B, A >::field_type field_type
Definition btdmatrix.hh:207