4 #ifndef DUNE_PDELAB_GRIDOPERATOR_COMMON_LOCALMATRIX_HH 5 #define DUNE_PDELAB_GRIDOPERATOR_COMMON_LOCALMATRIX_HH 7 #include <dune/common/iteratorfacades.hh> 77 template<
typename LFSU,
typename LFSV>
79 const LFSU& lfsu, size_type j,
83 _container(lfsv,i,lfsu,j) += _weight * v;
91 template<
typename LFSU,
typename LFSV>
93 const LFSU& lfsu, size_type j,
97 _container(lfsv,i,lfsu,j) += v;
103 return _container.nrows();
109 return _container.ncols();
148 return _container.base();
155 const BaseContainer&
base()
const 157 return _container.base();
162 : _container(container)
168 Container& _container;
175 template<
typename T,
typename W = T>
217 :
public Dune::BidirectionalIteratorFacade<iterator,value_type>
234 return _m == other.
_m && _i == other.
_i && _j == other.
_j;
239 return _m->getEntry(_i,_j);
244 if (_j < _m->
ncols() - 1)
260 _j = _m->ncols() - 1;
282 return iterator(*
this,0,0);
287 return iterator(*
this,
nrows(),0);
310 _container.resize(r*c);
318 std::fill(_container.begin(),_container.end(),t);
323 void assign (size_type r, size_type c,
const T& t)
325 _container.assign(r*c,t);
337 template<
typename LFSU,
typename LFSV>
338 T& operator() (
const LFSV& lfsv, size_type i,
const LFSU& lfsu, size_type j)
340 return getEntry(lfsv.localIndex(i),lfsu.localIndex(j));
350 template<
typename LFSU,
typename LFSV>
351 const T& operator() (
const LFSV& lfsv, size_type i,
const LFSU& lfsu, size_type j)
const 353 return getEntry(lfsv.localIndex(i),lfsu.localIndex(j));
359 using namespace std::placeholders;
364 std::bind(std::multiplies<T>(),x,_1)
382 template<
class X,
class R>
383 void umv (
const X& x, R& y)
const 385 for (size_type i=0; i<_rows; ++i)
387 for (size_type j=0; j<_cols; j++)
393 template<
class X,
class R>
394 void usmv (
const value_type& alpha,
const X& x, R& y)
const 396 for (size_type i=0; i<_rows; ++i)
398 for (size_type j=0; j<_cols; j++)
422 const BaseContainer&
base()
const 438 return _container[j*_rows + i];
450 const value_type&
getEntry(size_type i, size_type j)
const 452 return _container[j*_rows + i];
457 std::vector<T> _container;
458 size_type _rows, _cols;
461 template<
class Stream,
class T,
class W>
462 Stream &operator<<(Stream &stream, const LocalMatrix<T,W> &m) {
463 for(
int r = 0; r < m.nrows(); ++r) {
465 stream << m.getEntry(r, 0);
466 for(
int c = 1; c < m.ncols(); ++c)
467 stream <<
"\t" << m.getEntry(r, c);
480 #endif // DUNE_PDELAB_GRIDOPERATOR_COMMON_LOCALMATRIX_HH size_type ncols() const
Returns the number of colums of the underlying container.
Definition: localmatrix.hh:107
An accumulate-only view on a local matrix that automatically takes into account an accumulation weigh...
Definition: localmatrix.hh:21
void decrement()
Definition: localmatrix.hh:253
const Container & container() const
Returns the container (of type LocalMatrix) that this view is based on (const version).
Definition: localmatrix.hh:136
LocalMatrix(size_type r, size_type c)
Construct a LocalMatrix with r rows and c columns.
Definition: localmatrix.hh:294
std::vector< T > BaseContainer
The type of the underlying storage container.
Definition: localmatrix.hh:192
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: localmatrix.hh:450
const BaseContainer & base() const
Returns the underlying storage container (const version).
Definition: localmatrix.hh:422
BaseContainer & base()
Returns the storage container of the underlying LocalMatrix.
Definition: localmatrix.hh:145
C::value_type value_type
The value type of the entries.
Definition: localmatrix.hh:36
void usmv(const value_type &alpha, const X &x, R &y) const
y += alpha A x
Definition: localmatrix.hh:394
weight_type weight()
Returns the weight associated with this view.
Definition: localmatrix.hh:60
iterator begin()
Definition: localmatrix.hh:280
BaseContainer::value_type value_type
The value type of this container.
Definition: localmatrix.hh:195
void resetModified()
Resets the modification state of the view to not modified.
Definition: localmatrix.hh:123
void assign(size_type r, size_type c, const T &t)
Resize the matrix and assign t to all entries.
Definition: localmatrix.hh:323
size_type ncols() const
Returns the number of columns.
Definition: localmatrix.hh:376
iterator(LocalMatrix &m, size_type i, size_type j)
Definition: localmatrix.hh:226
WeightedMatrixAccumulationView WeightedAccumulationView
Export this type for uniform handling of the containers themselves and their views.
Definition: localmatrix.hh:43
size_type col() const
Definition: localmatrix.hh:269
LocalMatrix & operator=(const T &t)
Assign t to all entries of the matrix.
Definition: localmatrix.hh:316
void rawAccumulate(const LFSV &lfsv, size_type i, const LFSU &lfsu, size_type j, value_type v)
Adds v to the (i,j)-th entry of the underlying container without applying the current weight...
Definition: localmatrix.hh:92
size_type nrows() const
Returns the number of rows.
Definition: localmatrix.hh:370
size_type nrows() const
Returns the number of rows of the underlying container.
Definition: localmatrix.hh:101
size_type _i
Definition: localmatrix.hh:275
void accumulate(const LFSV &lfsv, size_type i, const LFSU &lfsu, size_type j, value_type v)
Applies the current weight to v and adds the result to the matrix entry associated with the i-th entr...
Definition: localmatrix.hh:78
void resize(size_type r, size_type c)
Resize the matrix.
Definition: localmatrix.hh:308
BaseContainer::reference reference
The reference type of this container.
Definition: localmatrix.hh:201
const BaseContainer & base() const
Returns the storage container of the underlying LocalVector (const version).
Definition: localmatrix.hh:155
iterator end()
Definition: localmatrix.hh:285
iterator()
Definition: localmatrix.hh:220
size_type _j
Definition: localmatrix.hh:276
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
size_type row() const
Definition: localmatrix.hh:264
Definition: localmatrix.hh:216
bool equals(const iterator &other) const
Definition: localmatrix.hh:232
Container & container()
Returns the container (of type LocalMatrix) that this view is based on.
Definition: localmatrix.hh:129
LocalMatrix(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: localmatrix.hh:301
WeightedAccumulationView weightedAccumulationView(weight_type weight)
Returns a weighted accumulate-only view of this matrix with the given weight.
Definition: localmatrix.hh:404
C & accessBaseContainer(C &c)
Definition: localvector.hh:302
bool modified() const
Returns whether this view has been written to.
Definition: localmatrix.hh:113
value_type & dereference() const
Definition: localmatrix.hh:237
C Container
The type of the underlying container.
Definition: localmatrix.hh:27
LocalMatrix()
Default constructor.
Definition: localmatrix.hh:291
W weight_type
The weight type of this container.
Definition: localmatrix.hh:211
WeightedAccumulationView weightedAccumulationView(weight_type weight)
Returns a WeighedAccumulationView with some weight in addition to this view's weight.
Definition: localmatrix.hh:47
BaseContainer::const_reference const_reference
The const reference type of this container.
Definition: localmatrix.hh:204
Container::BaseContainer BaseContainer
The type of the storage container underlying the LocalVector.
Definition: localmatrix.hh:33
C::size_type size_type
The size_type of the underlying container.
Definition: localmatrix.hh:53
BaseContainer & base()
Returns the underlying storage container.
Definition: localmatrix.hh:413
value_type & getEntry(size_type i, size_type j)
Direct (unmapped) access to the (i,j)-th entry of the matrix.
Definition: localmatrix.hh:436
C::weight_type weight_type
The type of the weight applied when accumulating contributions.
Definition: localmatrix.hh:39
WeightedMatrixAccumulationView(Container &container, weight_type weight)
Constructor.
Definition: localmatrix.hh:161
A dense matrix for storing data associated with the degrees of freedom of a pair of LocalFunctionSpac...
Definition: localmatrix.hh:184
BaseContainer::size_type size_type
The size type of this container.
Definition: localmatrix.hh:198
WeightedMatrixAccumulationView< LocalMatrix > WeightedAccumulationView
An accumulate-only view of this container that automatically applies a weight to all contributions...
Definition: localmatrix.hh:214
void setWeight(weight_type weight)
Resets the weighting coefficient of the view.
Definition: localmatrix.hh:71
void increment()
Definition: localmatrix.hh:242
LocalMatrix * _m
Definition: localmatrix.hh:274
void umv(const X &x, R &y) const
y += A x
Definition: localmatrix.hh:383