diff --git a/dune/matrix-vector/componentwisematrixmap.hh b/dune/matrix-vector/componentwisematrixmap.hh index 06bc5bfc0f081919737d34e4b5bc12719260f02a..80acaa7d9b8a349fdb6b55d5bc70a075d81219ea 100644 --- a/dune/matrix-vector/componentwisematrixmap.hh +++ b/dune/matrix-vector/componentwisematrixmap.hh @@ -9,130 +9,7 @@ #include <dune/fufem/arithmetic.hh> #include <dune/fufem/indexedsliceiterator.hh> #include <dune/matrix-vector/singlenonzerocolumnmatrix.hh> - -/** - * \brief A static matrix that has only a single nonzero row - * - * The number and values of this row 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 SingleNonZeroRowMatrix -{ -public: - typedef typename Dune::FieldMatrix<K, 1, COLS> SingleRowMatrix; - -protected: - class RowProxy - { - public: - typedef std::size_t size_type; - typedef typename SingleRowMatrix::ConstColIterator ConstIterator; - typedef ConstIterator const_iterator; - - RowProxy(const SingleRowMatrix* nzRow, size_type rowIndex, size_type nzRowIndex) : - nzRow_(nzRow), - isNonZero_(rowIndex==nzRowIndex) - {} - - ConstIterator begin() const - { - if (isNonZero_) - return (*nzRow_)[0].begin(); - else - return (*nzRow_)[0].end(); - } - - ConstIterator end() const - { - return (*nzRow_)[0].end(); - } - - protected: - const SingleRowMatrix* nzRow_; - bool isNonZero_; - }; - -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; - - /** - * \brief Create from single row matrix and row index - */ - SingleNonZeroRowMatrix(const SingleRowMatrix& r, size_type nzRowIndex) : - nzRow_(r), - nzRowIndex_(nzRowIndex) - {} - - 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<M(); ++i) - y[nzRowIndex_] += nzRow_[0][i] * x[i]; - } - - template<class X , class Y > - void umtv(const X& x, Y& y) const - { - for(size_type i=0; i<N(); ++i) - y[i] = nzRow_[0][i] * x[nzRowIndex_]; - } - - 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(&nzRow_, rowIndex, nzRowIndex_); - } - - size_type nonZeroRowIndex() const - { - return nzRowIndex_; - } - -protected: - SingleRowMatrix nzRow_; - const size_type nzRowIndex_; -}; - - - -namespace Arithmetic -{ - template<class K, int ROWS, int COLS> - struct MatrixTraits<SingleNonZeroRowMatrix<K, ROWS, COLS> > - { - enum { isMatrix=true }; - enum { isDense=false }; - enum { hasStaticSize=true }; - enum { rows=ROWS}; - enum { cols=COLS}; - }; -}; - - +#include <dune/matrix-vector/singlenonzerorowmatrix.hh> template<class K, int ROWS, int COLS> class ComponentWiseMatrixMap