DUNE PDELab (git)

diagonallocalmatrix.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_PDELAB_GRIDOPERATOR_COMMON_DIAGONALLOCALMATRIX_HH
5#define DUNE_PDELAB_GRIDOPERATOR_COMMON_DIAGONALLOCALMATRIX_HH
6
7#include <dune/pdelab/gridoperator/common/localmatrix.hh>
8
9namespace Dune {
10 namespace PDELab {
11
19 template<typename T, typename W = T>
29 {
30 public:
31
33
36 typedef std::vector<T> BaseContainer;
37
39 typedef typename BaseContainer::value_type value_type;
40
42 typedef typename BaseContainer::size_type size_type;
43
45 typedef typename BaseContainer::reference reference;
46
48 typedef typename BaseContainer::const_reference const_reference;
49
51
55 typedef W weight_type;
56
59
60 struct iterator
61 : public Dune::BidirectionalIteratorFacade<iterator,value_type>
62 {
63
64 iterator()
65 : _m(nullptr)
66 , _i(0)
67 {}
68
69 iterator(DiagonalLocalMatrix& m, size_type i)
70 : _m(&m)
71 , _i(i)
72 {}
73
74 bool equals(const iterator& other) const
75 {
76 return _m == other._m && _i == other._i;
77 }
78
79 value_type& dereference() const
80 {
81 return _m->getEntry(_i,_i);
82 }
83
84 void increment()
85 {
86 ++_i;
87 }
88
89 void decrement()
90 {
91 --_i;
92 }
93
94 size_type row() const
95 {
96 return _i;
97 }
98
99 size_type col() const
100 {
101 return _i;
102 }
103
105 size_type _i;
106
107 };
108
109 iterator begin()
110 {
111 return iterator(*this,0);
112 }
113
114 iterator end()
115 {
116 return iterator(*this,nrows());
117 }
118
121
124 : _container(r)
125 , _rows(r)
126 , _cols(c)
127 {
128 assert(r == c);
129 }
130
133 : _container(r,t)
134 , _rows(r)
135 , _cols(c)
136 {
137 assert(r == c);
138 }
139
142 {
143 assert(r == c);
144 _container.resize(r);
145 _rows = r;
146 _cols = c;
147 }
148
151 {
152 std::fill(_container.begin(),_container.end(),t);
153 return *this;
154 }
155
157 void assign (size_type r, size_type c, const T& t)
158 {
159 assert(r == c);
160 _container.assign(r,t);
161 _rows = r;
162 _cols = c;
163 }
164
166
172 template<typename LFSU, typename LFSV>
173 T& operator() (const LFSV& lfsv, size_type i, const LFSU& lfsu, size_type j)
174 {
175 return getEntry(lfsv.localIndex(i),lfsu.localIndex(j));
176 }
177
179
185 template<typename LFSU, typename LFSV>
186 const T& operator() (const LFSV& lfsv, size_type i, const LFSU& lfsu, size_type j) const
187 {
188 return getEntry(lfsv.localIndex(i),lfsu.localIndex(j));
189 }
190
193 {
194 using namespace std::placeholders;
195 std::transform(
196 _container.begin(),
197 _container.end(),
198 _container.begin(),
199 std::bind(std::multiplies<T>(),x,_1)
200 );
201 return *this;
202 }
203
206 {
207 return _rows;
208 }
209
212 {
213 return _cols;
214 }
215
217 template<class X, class R>
218 void umv (const X& x, R& y) const
219 {
220 for (size_type i=0; i<_rows; ++i)
221 {
222 for (size_type j=0; j<_cols; j++)
223 accessBaseContainer(y)[i] += getEntry(i,j) * accessBaseContainer(x)[j];
224 }
225 }
226
228 template<class X, class R>
229 void usmv (const value_type& alpha, const X& x, R& y) const
230 {
231 for (size_type i=0; i<_rows; ++i)
232 {
233 for (size_type j=0; j<_cols; j++)
234 accessBaseContainer(y)[i] += alpha * getEntry(i,j) * accessBaseContainer(x)[j];
235 }
236 }
237
240 {
241 return WeightedAccumulationView(*this,weight);
242 }
243
245
249 {
250 return _container;
251 }
252
254
257 const BaseContainer& base() const
258 {
259 return _container;
260 }
261
263
272 {
273 assert(i == j);
274 return _container[i];
275 }
276
278
287 {
288 assert(i == j);
289 return _container[i];
290 }
291
292 private:
293
294 std::vector<T> _container;
295 size_type _rows, _cols;
296 };
297
302 } // namespace PDELab
303} // namespace Dune
304
305#endif // DUNE_PDELAB_GRIDOPERATOR_COMMON_DIAGONALLOCALMATRIX_HH
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:275
A dense matrix for storing data associated with the degrees of freedom of a pair of LocalFunctionSpac...
Definition: diagonallocalmatrix.hh:29
BaseContainer::const_reference const_reference
The const reference type of this container.
Definition: diagonallocalmatrix.hh:48
const value_type & getEntry(size_type i, size_type j) const
Direct (unmapped) access to the (i,j)-th entry of the matrix (const version).
Definition: diagonallocalmatrix.hh:286
const BaseContainer & base() const
Returns the underlying storage container (const version).
Definition: diagonallocalmatrix.hh:257
BaseContainer::value_type value_type
The value type of this container.
Definition: diagonallocalmatrix.hh:39
BaseContainer::size_type size_type
The size type of this container.
Definition: diagonallocalmatrix.hh:42
void assign(size_type r, size_type c, const T &t)
Resize the matrix and assign t to all entries.
Definition: diagonallocalmatrix.hh:157
DiagonalLocalMatrix & operator*=(const T &x)
Multiplies all entries of the matrix with x.
Definition: diagonallocalmatrix.hh:192
void umv(const X &x, R &y) const
y += A x
Definition: diagonallocalmatrix.hh:218
W weight_type
The weight type of this container.
Definition: diagonallocalmatrix.hh:55
BaseContainer::reference reference
The reference type of this container.
Definition: diagonallocalmatrix.hh:45
T & operator()(const LFSV &lfsv, size_type i, const LFSU &lfsu, size_type j)
Access the value associated with the i-th DOF of lfsv and the j-th DOF of lfsu.
Definition: diagonallocalmatrix.hh:173
WeightedAccumulationView weightedAccumulationView(weight_type weight)
Returns a weighted accumulate-only view of this matrix with the given weight.
Definition: diagonallocalmatrix.hh:239
BaseContainer & base()
Returns the underlying storage container.
Definition: diagonallocalmatrix.hh:248
value_type & getEntry(size_type i, size_type j)
Direct (unmapped) access to the (i,j)-th entry of the matrix.
Definition: diagonallocalmatrix.hh:271
std::vector< T > BaseContainer
The type of the underlying storage container.
Definition: diagonallocalmatrix.hh:36
void usmv(const value_type &alpha, const X &x, R &y) const
y += alpha A x
Definition: diagonallocalmatrix.hh:229
void resize(size_type r, size_type c)
Resize the matrix.
Definition: diagonallocalmatrix.hh:141
DiagonalLocalMatrix(size_type r, size_type c, const T &t)
Construct a LocalMatrix with r rows and c columns and initialize its entries with t.
Definition: diagonallocalmatrix.hh:132
size_type ncols() const
Returns the number of columns.
Definition: diagonallocalmatrix.hh:211
DiagonalLocalMatrix(size_type r, size_type c)
Construct a LocalMatrix with r rows and c columns.
Definition: diagonallocalmatrix.hh:123
size_type nrows() const
Returns the number of rows.
Definition: diagonallocalmatrix.hh:205
DiagonalLocalMatrix & operator=(const T &t)
Assign t to all entries of the matrix.
Definition: diagonallocalmatrix.hh:150
DiagonalLocalMatrix()
Default constructor.
Definition: diagonallocalmatrix.hh:120
WeightedMatrixAccumulationView< DiagonalLocalMatrix > WeightedAccumulationView
An accumulate-only view of this container that automatically applies a weight to all contributions.
Definition: diagonallocalmatrix.hh:58
An accumulate-only view on a local matrix that automatically takes into account an accumulation weigh...
Definition: localmatrix.hh:22
constexpr index_constant< 1 > _1
Compile time index with value 1.
Definition: indices.hh:55
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:587
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)