Dune Core Modules (2.7.0)

bdmatrix.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_ISTL_BDMATRIX_HH
4#define DUNE_ISTL_BDMATRIX_HH
5
6#include <memory>
7
10
12
18namespace Dune {
28 template <class B, class A=std::allocator<B> >
29 class BDMatrix : public BCRSMatrix<B,A>
30 {
31 public:
32
33 //===== type definitions and constants
34
36 using field_type = typename Imp::BlockTraits<B>::field_type;
37
39 typedef B block_type;
40
42 typedef A allocator_type;
43
45 //typedef BCRSMatrix<B,A>::row_type row_type;
46
48 typedef typename A::size_type size_type;
49
51 static constexpr unsigned int blocklevel = Imp::BlockTraits<B>::blockLevel()+1;
52
54 BDMatrix() : BCRSMatrix<B,A>() {}
55
56 explicit BDMatrix(int size)
57 : BCRSMatrix<B,A>(size, size, BCRSMatrix<B,A>::random) {
58
59 for (int i=0; i<size; i++)
61
63
64 for (int i=0; i<size; i++)
65 this->BCRSMatrix<B,A>::addindex(i, i);
66
68
69 }
70
72 BDMatrix (std::initializer_list<B> const &list)
73 : BDMatrix(list.size())
74 {
75 size_t i=0;
76 for (auto it = list.begin(); it != list.end(); ++it, ++i)
77 (*this)[i][i] = *it;
78 }
79
81 void setSize(size_type size)
82 {
83 this->BCRSMatrix<B,A>::setSize(size, // rows
84 size, // columns
85 size); // nonzeros
86
87 for (auto i : range(size))
89
91
92 for (auto i : range(size))
93 this->BCRSMatrix<B,A>::addindex(i, i);
94
96 }
97
99 BDMatrix& operator= (const BDMatrix& other) {
100 this->BCRSMatrix<B,A>::operator=(other);
101 return *this;
102 }
103
107 return *this;
108 }
109
115 template <class V>
116 void solve (V& x, const V& rhs) const {
117 for (size_type i=0; i<this->N(); i++)
118 {
119 auto&& xv = Impl::asVector(x[i]);
120 auto&& rhsv = Impl::asVector(rhs[i]);
121 Impl::asMatrix((*this)[i][i]).solve(xv,rhsv);
122 }
123 }
124
126 void invert() {
127 for (size_type i=0; i<this->N(); i++)
128 Impl::asMatrix((*this)[i][i]).invert();
129 }
130
131 private:
132
133 // ////////////////////////////////////////////////////////////////////////////
134 // The following methods from the base class should now actually be called
135 // ////////////////////////////////////////////////////////////////////////////
136
137 // createbegin and createend should be in there, too, but I can't get it to compile
138 // BCRSMatrix<B,A>::CreateIterator createbegin () {}
139 // BCRSMatrix<B,A>::CreateIterator createend () {}
140 void setrowsize (size_type i, size_type s) {}
141 void incrementrowsize (size_type i) {}
142 void endrowsizes () {}
143 void addindex (size_type row, size_type col) {}
144 void endindices () {}
145 };
148} // end namespace Dune
149
150#endif
Implementation of the BCRSMatrix class.
A sparse block matrix with compressed row storage.
Definition: bcrsmatrix.hh:425
void endrowsizes()
indicate that size of all rows is defined
Definition: bcrsmatrix.hh:1107
void setrowsize(size_type i, size_type s)
Set number of indices in row i to s.
Definition: bcrsmatrix.hh:1075
@ random
Build entries randomly.
Definition: bcrsmatrix.hh:488
void addindex(size_type row, size_type col)
add index (row,col) to the matrix
Definition: bcrsmatrix.hh:1149
void endindices()
indicate that all indices are defined, check consistency
Definition: bcrsmatrix.hh:1206
size_type N() const
number of rows (counted in blocks)
Definition: bcrsmatrix.hh:1930
void setSize(size_type rows, size_type columns, size_type nnz=0)
Set the size of the matrix.
Definition: bcrsmatrix.hh:819
BCRSMatrix & operator=(const BCRSMatrix &Mat)
assignment
Definition: bcrsmatrix.hh:869
A block-diagonal matrix.
Definition: bdmatrix.hh:30
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: bdmatrix.hh:36
A::size_type size_type
implement row_type with compressed vector
Definition: bdmatrix.hh:48
BDMatrix()
Default constructor.
Definition: bdmatrix.hh:54
BDMatrix(std::initializer_list< B > const &list)
Construct from a std::initializer_list.
Definition: bdmatrix.hh:72
B block_type
export the type representing the components
Definition: bdmatrix.hh:39
void solve(V &x, const V &rhs) const
Solve the system Ax=b in O(n) time.
Definition: bdmatrix.hh:116
A allocator_type
export the allocator type
Definition: bdmatrix.hh:42
BDMatrix & operator=(const BDMatrix &other)
assignment
Definition: bdmatrix.hh:99
static constexpr unsigned int blocklevel
increment block level counter
Definition: bdmatrix.hh:51
void setSize(size_type size)
Resize the matrix. Invalidates the content!
Definition: bdmatrix.hh:81
void invert()
Inverts the matrix.
Definition: bdmatrix.hh:126
Dune namespace.
Definition: alignedallocator.hh:14
Utilities for reduction like operations on ranges.
Implements a scalar matrix view wrapper around an existing scalar.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)