diff --git a/dune/matrix-vector/componentwisematrixmap.hh b/dune/matrix-vector/componentwisematrixmap.hh index a29079fd2b6f59ced67294e68b20a66a5c4d9bda..06bc5bfc0f081919737d34e4b5bc12719260f02a 100644 --- a/dune/matrix-vector/componentwisematrixmap.hh +++ b/dune/matrix-vector/componentwisematrixmap.hh @@ -8,128 +8,7 @@ #include <dune/fufem/arithmetic.hh> #include <dune/fufem/indexedsliceiterator.hh> - - - - -/** - * \brief A static matrix that has only a single nonzero column - * - * The number and values of this column are dynamic. - * For simplicity this derives from FieldMatrix and sets - * all entries accordingly. So it will not reduce memory - * requirements but allows to implement methods more efficiently. - */ -template<class K, int ROWS, int COLS> -class SingleNonZeroColumnMatrix -{ - class RowProxy - { - public: - typedef std::size_t size_type; - typedef IndexedSliceIterator<const K*, const K> ConstIterator; - typedef ConstIterator const_iterator; - - RowProxy(const K* value, size_type nzColIndex) : - value_(value), - nzColIndex_(nzColIndex) - {} - - ConstIterator begin() const - { - return ConstIterator(value_, nzColIndex_, 0, 1); - } - - ConstIterator end() const - { - return ConstIterator(value_, nzColIndex_+1, 0, 1); - } - - protected: - const K* value_; - size_type nzColIndex_; - }; - -public: - enum { rows = ROWS, cols = COLS}; - - typedef RowProxy row_type; - typedef row_type const_row_reference; - typedef typename std::size_t size_type; - typedef typename RowProxy::ConstIterator ConstColIterator; - - typedef typename Dune::FieldMatrix<K, ROWS, 1> SingleColumnMatrix; - - /** - * \brief Create from single column matrix and column index - */ - SingleNonZeroColumnMatrix(const SingleColumnMatrix& c, size_type nzColIndex) : - nzCol_(c), - nzColIndex_(nzColIndex) - {} - - size_type N() const - { - return ROWS; - } - - size_type M() const - { - return COLS; - } - - template<class X , class Y > - void umv(const X& x, Y& y) const - { - for(size_type i=0; i<N(); ++i) - y[i] += nzCol_[i] * x[nzColIndex_]; - } - - template<class X , class Y > - void umtv(const X& x, Y& y) const - { - for(size_type i=0; i<N(); ++i) - y[nzColIndex_] = nzCol_[i] * x[i]; - } - - template<class X , class Y > - void mtv(const X& x, Y& y) const - { - y = 0.0; - umtv(x, y); - } - - const_row_reference operator[] (size_type rowIndex) const - { - return const_row_reference(&(nzCol_[rowIndex][0]), nzColIndex_); - } - - size_type nonZeroColumnIndex() const - { - return nzColIndex_; - } - -protected: - SingleColumnMatrix nzCol_; - const size_type nzColIndex_; -}; - - - -namespace Arithmetic -{ - template<class K, int ROWS, int COLS> - struct MatrixTraits<SingleNonZeroColumnMatrix<K, ROWS, COLS> > - { - enum { isMatrix=true }; - enum { isDense=false }; - enum { hasStaticSize=true }; - enum { rows=ROWS}; - enum { cols=COLS}; - }; -}; - - +#include <dune/matrix-vector/singlenonzerocolumnmatrix.hh> /** * \brief A static matrix that has only a single nonzero row