dune-pdelab  2.7-git
diagonallocalmatrix.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 
4 #ifndef DUNE_PDELAB_GRIDOPERATOR_COMMON_DIAGONALLOCALMATRIX_HH
5 #define DUNE_PDELAB_GRIDOPERATOR_COMMON_DIAGONALLOCALMATRIX_HH
6 
8 
9 namespace Dune {
10  namespace PDELab {
11 
18  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 
65  : _m(nullptr)
66  , _i(0)
67  {}
68 
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 
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 
106 
107  };
108 
110  {
111  return iterator(*this,0);
112  }
113 
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 
205  size_type nrows () const
206  {
207  return _rows;
208  }
209 
211  size_type ncols () const
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
Dune::PDELab::DiagonalLocalMatrix::iterator
Definition: diagonallocalmatrix.hh:60
Dune::PDELab::DiagonalLocalMatrix::iterator::_i
size_type _i
Definition: diagonallocalmatrix.hh:105
Dune::PDELab::DiagonalLocalMatrix::end
iterator end()
Definition: diagonallocalmatrix.hh:114
Dune::PDELab::DiagonalLocalMatrix::weightedAccumulationView
WeightedAccumulationView weightedAccumulationView(weight_type weight)
Returns a weighted accumulate-only view of this matrix with the given weight.
Definition: diagonallocalmatrix.hh:239
Dune::PDELab::DiagonalLocalMatrix::resize
void resize(size_type r, size_type c)
Resize the matrix.
Definition: diagonallocalmatrix.hh:141
Dune::PDELab::DiagonalLocalMatrix::value_type
BaseContainer::value_type value_type
The value type of this container.
Definition: diagonallocalmatrix.hh:39
Dune::PDELab::DiagonalLocalMatrix::iterator::iterator
iterator(DiagonalLocalMatrix &m, size_type i)
Definition: diagonallocalmatrix.hh:69
Dune::PDELab::DiagonalLocalMatrix
A dense matrix for storing data associated with the degrees of freedom of a pair of LocalFunctionSpac...
Definition: diagonallocalmatrix.hh:28
Dune::PDELab::DiagonalLocalMatrix::getEntry
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
Dune::PDELab::DiagonalLocalMatrix::usmv
void usmv(const value_type &alpha, const X &x, R &y) const
y += alpha A x
Definition: diagonallocalmatrix.hh:229
Dune::PDELab::DiagonalLocalMatrix::DiagonalLocalMatrix
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
Dune
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Dune::PDELab::DiagonalLocalMatrix::iterator::increment
void increment()
Definition: diagonallocalmatrix.hh:84
Dune::PDELab::DiagonalLocalMatrix::BaseContainer
std::vector< T > BaseContainer
The type of the underlying storage container.
Definition: diagonallocalmatrix.hh:36
Dune::PDELab::DiagonalLocalMatrix::weight_type
W weight_type
The weight type of this container.
Definition: diagonallocalmatrix.hh:55
Dune::PDELab::DiagonalLocalMatrix::nrows
size_type nrows() const
Returns the number of rows.
Definition: diagonallocalmatrix.hh:205
Dune::PDELab::DiagonalLocalMatrix::operator*=
DiagonalLocalMatrix & operator*=(const T &x)
Multiplies all entries of the matrix with x.
Definition: diagonallocalmatrix.hh:192
Dune::PDELab::DiagonalLocalMatrix::iterator::dereference
value_type & dereference() const
Definition: diagonallocalmatrix.hh:79
Dune::PDELab::DiagonalLocalMatrix::const_reference
BaseContainer::const_reference const_reference
The const reference type of this container.
Definition: diagonallocalmatrix.hh:48
Dune::PDELab::DiagonalLocalMatrix::iterator::col
size_type col() const
Definition: diagonallocalmatrix.hh:99
Dune::PDELab::DiagonalLocalMatrix::ncols
size_type ncols() const
Returns the number of columns.
Definition: diagonallocalmatrix.hh:211
Dune::PDELab::DiagonalLocalMatrix::getEntry
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
Dune::PDELab::accessBaseContainer
C & accessBaseContainer(C &c)
Definition: localvector.hh:368
Dune::PDELab::DiagonalLocalMatrix::iterator::iterator
iterator()
Definition: diagonallocalmatrix.hh:64
Dune::PDELab::DiagonalLocalMatrix::reference
BaseContainer::reference reference
The reference type of this container.
Definition: diagonallocalmatrix.hh:45
Dune::PDELab::DiagonalLocalMatrix::iterator::_m
DiagonalLocalMatrix * _m
Definition: diagonallocalmatrix.hh:104
Dune::PDELab::DiagonalLocalMatrix::operator()
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
Dune::PDELab::DiagonalLocalMatrix::WeightedAccumulationView
WeightedMatrixAccumulationView< DiagonalLocalMatrix > WeightedAccumulationView
An accumulate-only view of this container that automatically applies a weight to all contributions.
Definition: diagonallocalmatrix.hh:58
Dune::PDELab::DiagonalLocalMatrix::assign
void assign(size_type r, size_type c, const T &t)
Resize the matrix and assign t to all entries.
Definition: diagonallocalmatrix.hh:157
Dune::PDELab::DiagonalLocalMatrix::iterator::row
size_type row() const
Definition: diagonallocalmatrix.hh:94
Dune::PDELab::DiagonalLocalMatrix::operator=
DiagonalLocalMatrix & operator=(const T &t)
Assign t to all entries of the matrix.
Definition: diagonallocalmatrix.hh:150
Dune::PDELab::DiagonalLocalMatrix::iterator::decrement
void decrement()
Definition: diagonallocalmatrix.hh:89
Dune::PDELab::DiagonalLocalMatrix::begin
iterator begin()
Definition: diagonallocalmatrix.hh:109
Dune::PDELab::DiagonalLocalMatrix::base
BaseContainer & base()
Returns the underlying storage container.
Definition: diagonallocalmatrix.hh:248
Dune::PDELab::WeightedMatrixAccumulationView
An accumulate-only view on a local matrix that automatically takes into account an accumulation weigh...
Definition: localmatrix.hh:21
Dune::PDELab::DiagonalLocalMatrix::iterator::equals
bool equals(const iterator &other) const
Definition: diagonallocalmatrix.hh:74
Dune::PDELab::DiagonalLocalMatrix::umv
void umv(const X &x, R &y) const
y += A x
Definition: diagonallocalmatrix.hh:218
Dune::PDELab::DiagonalLocalMatrix::DiagonalLocalMatrix
DiagonalLocalMatrix()
Default constructor.
Definition: diagonallocalmatrix.hh:120
Dune::PDELab::DiagonalLocalMatrix::base
const BaseContainer & base() const
Returns the underlying storage container (const version).
Definition: diagonallocalmatrix.hh:257
localmatrix.hh
Dune::PDELab::DiagonalLocalMatrix::size_type
BaseContainer::size_type size_type
The size type of this container.
Definition: diagonallocalmatrix.hh:42
Dune::PDELab::DiagonalLocalMatrix::DiagonalLocalMatrix
DiagonalLocalMatrix(size_type r, size_type c)
Construct a LocalMatrix with r rows and c columns.
Definition: diagonallocalmatrix.hh:123