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 std::transform(_container.begin(),_container.end(),_container.begin(),std::bind1st(std::multiplies<T>(),x));
376 template<
class X,
class R>
377 void umv (
const X& x, R& y)
const 379 for (size_type i=0; i<_rows; ++i)
381 for (size_type j=0; j<_cols; j++)
387 template<
class X,
class R>
388 void usmv (
const value_type& alpha,
const X& x, R& y)
const 390 for (size_type i=0; i<_rows; ++i)
392 for (size_type j=0; j<_cols; j++)
416 const BaseContainer&
base()
const 432 return _container[j*_rows + i];
444 const value_type&
getEntry(size_type i, size_type j)
const 446 return _container[j*_rows + i];
451 std::vector<T> _container;
452 size_type _rows, _cols;
455 template<
class Stream,
class T,
class W>
456 Stream &operator<<(Stream &stream, const LocalMatrix<T,W> &m) {
457 for(
int r = 0; r < m.nrows(); ++r) {
459 stream << m.getEntry(r, 0);
460 for(
int c = 1; c < m.ncols(); ++c)
461 stream <<
"\t" << m.getEntry(r, c);
474 #endif // DUNE_PDELAB_GRIDOPERATOR_COMMON_LOCALMATRIX_HH LocalMatrix & operator=(const T &t)
Assign t to all entries of the matrix.
Definition: localmatrix.hh:316
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
const Container & container() const
Returns the container (of type LocalMatrix) that this view is based on (const version).
Definition: localmatrix.hh:136
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:370
BaseContainer::value_type value_type
The value type of this container.
Definition: localmatrix.hh:195
void resize(size_type r, size_type c)
Resize the matrix.
Definition: localmatrix.hh:308
An accumulate-only view on a local matrix that automatically takes into account an accumulation weigh...
Definition: localmatrix.hh:21
C::value_type value_type
The value type of the entries.
Definition: localmatrix.hh:36
WeightedAccumulationView weightedAccumulationView(weight_type weight)
Returns a WeighedAccumulationView with some weight in addition to this view's weight.
Definition: localmatrix.hh:47
weight_type weight()
Returns the weight associated with this view.
Definition: localmatrix.hh:60
WeightedMatrixAccumulationView< LocalMatrix > WeightedAccumulationView
An accumulate-only view of this container that automatically applies a weight to all contributions...
Definition: localmatrix.hh:214
Container & container()
Returns the container (of type LocalMatrix) that this view is based on.
Definition: localmatrix.hh:129
size_type nrows() const
Returns the number of rows.
Definition: localmatrix.hh:364
Definition: localmatrix.hh:216
size_type col() const
Definition: localmatrix.hh:269
iterator(LocalMatrix &m, size_type i, size_type j)
Definition: localmatrix.hh:226
void setWeight(weight_type weight)
Resets the weighting coefficient of the view.
Definition: localmatrix.hh:71
WeightedMatrixAccumulationView WeightedAccumulationView
Export this type for uniform handling of the containers themselves and their views.
Definition: localmatrix.hh:43
std::vector< T > BaseContainer
The type of the underlying storage container.
Definition: localmatrix.hh:192
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
WeightedAccumulationView weightedAccumulationView(weight_type weight)
Returns a weighted accumulate-only view of this matrix with the given weight.
Definition: localmatrix.hh:398
void increment()
Definition: localmatrix.hh:242
BaseContainer::size_type size_type
The size type of this container.
Definition: localmatrix.hh:198
value_type & dereference() const
Definition: localmatrix.hh:237
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
C::size_type size_type
The size_type of the underlying container.
Definition: localmatrix.hh:53
const BaseContainer & base() const
Returns the storage container of the underlying LocalVector (const version).
Definition: localmatrix.hh:155
BaseContainer::const_reference const_reference
The const reference type of this container.
Definition: localmatrix.hh:204
C Container
The type of the underlying container.
Definition: localmatrix.hh:27
W weight_type
The weight type of this container.
Definition: localmatrix.hh:211
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
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:444
LocalMatrix()
Default constructor.
Definition: localmatrix.hh:291
void decrement()
Definition: localmatrix.hh:253
void usmv(const value_type &alpha, const X &x, R &y) const
y += alpha A x
Definition: localmatrix.hh:388
size_type row() const
Definition: localmatrix.hh:264
value_type & getEntry(size_type i, size_type j)
Direct (unmapped) access to the (i,j)-th entry of the matrix.
Definition: localmatrix.hh:430
bool modified() const
Returns whether this view has been written to.
Definition: localmatrix.hh:113
size_type ncols() const
Returns the number of colums of the underlying container.
Definition: localmatrix.hh:107
size_type _j
Definition: localmatrix.hh:276
BaseContainer & base()
Returns the underlying storage container.
Definition: localmatrix.hh:407
BaseContainer & base()
Returns the storage container of the underlying LocalMatrix.
Definition: localmatrix.hh:145
LocalMatrix(size_type r, size_type c)
Construct a LocalMatrix with r rows and c columns.
Definition: localmatrix.hh:294
LocalMatrix * _m
Definition: localmatrix.hh:274
Container::BaseContainer BaseContainer
The type of the storage container underlying the LocalVector.
Definition: localmatrix.hh:33
void umv(const X &x, R &y) const
y += A x
Definition: localmatrix.hh:377
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 resetModified()
Resets the modification state of the view to not modified.
Definition: localmatrix.hh:123
iterator begin()
Definition: localmatrix.hh:280
C::weight_type weight_type
The type of the weight applied when accumulating contributions.
Definition: localmatrix.hh:39
iterator end()
Definition: localmatrix.hh:285
const BaseContainer & base() const
Returns the underlying storage container (const version).
Definition: localmatrix.hh:416
C & accessBaseContainer(C &c)
Definition: localvector.hh:296
iterator()
Definition: localmatrix.hh:220
BaseContainer::reference reference
The reference type of this container.
Definition: localmatrix.hh:201
size_type nrows() const
Returns the number of rows of the underlying container.
Definition: localmatrix.hh:101
bool equals(const iterator &other) const
Definition: localmatrix.hh:232