From 4f7bf57bba9d544afd9044082141d783130749d1 Mon Sep 17 00:00:00 2001 From: kanschat Date: Fri, 8 Sep 2006 20:15:05 +0000 Subject: [PATCH] add new PointerMatrixVector git-svn-id: https://svn.dealii.org/trunk@13860 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/pointer_matrix.h | 221 +++++++++++++++++++++++ 1 file changed, 221 insertions(+) diff --git a/deal.II/lac/include/lac/pointer_matrix.h b/deal.II/lac/include/lac/pointer_matrix.h index aa537cc7da..2cdf32d965 100644 --- a/deal.II/lac/include/lac/pointer_matrix.h +++ b/deal.II/lac/include/lac/pointer_matrix.h @@ -15,6 +15,7 @@ #include #include +#include template class VectorMemory; @@ -358,6 +359,116 @@ class PointerMatrixAux : public PointerMatrixBase }; + +/** + * Implement matrix multiplications for a vector using the + * PointerMatrixBase functionality. Objects of this + * class can be used in block matrices. + * + * Implements a matrix with image dimension 1 by using the scalar + * product (#vmult()) and scalar multiplication (#Tvmult()) functions + * of the Vector class. + * + * @author Guidl Kanschat, 2006 + */ +template +PointerMatrixVector : public PointerMatrixBase > +{ + public: + /** + * Constructor. The pointer in the + * argument is stored in this + * class. As usual, the lifetime of + * *M must be longer than the + * one of the PointerMatrix. + * + * If M is zero, no + * matrix is stored. + */ + PointerMatrix (const Vector* M=0); + + /** + * Constructor. The name argument + * is used to identify the + * SmartPointer for this object. + */ + PointerMatrix(const char* name); + + /** + * Constructor. M points + * to a matrix which must live + * longer than the + * PointerMatrix. The name + * argument is used to identify + * the SmartPointer for this + * object. + */ + PointerMatrix(const Vector* M, + const char* name); + + // Use doc from base class + virtual void clear(); + + /** + * Return whether the object is + * empty. + */ + bool empty () const; + + /** + * Assign a new matrix + * pointer. Deletes the old pointer + * and releases its matrix. + * @see SmartPointer + */ + const PointerMatrix& operator= (const Vector* M); + + /** + * Matrix-vector product, + * actually the scalar product of + * src and #m. + */ + virtual void vmult (Vector& dst, + const Vector& src) const; + + /** + * Tranposed matrix-vector + * product, actually the + * multiplication of #m with + * src(0). + */ + virtual void Tvmult (Vector& dst, + const Vector& src) const; + + /** + * Matrix-vector product, adding to + * dst. + */ + virtual void vmult_add (Vector& dst, + const Vector& src) const; + + /** + * Tranposed matrix-vector product, + * adding to dst. + */ + virtual void Tvmult_add (Vector& dst, + const Vector& src) const; + + private: + /** + * Return the address of the + * matrix for comparison. + */ + virtual const void* get() const; + + /** + * The pointer to the actual matrix. + */ + SmartPointer > m; +}; + + + /** * This function helps you creating a PointerMatrixBase object if you * do not want to provide the full template arguments of @@ -668,4 +779,114 @@ PointerMatrixAux::get () const } +//----------------------------------------------------------------------// + + +template +PointerMatrixVector >::PointerMatrix (const MATRIX* M) + : m(M, typeid(*this).name()) +{} + + +template +PointerMatrixVector >::PointerMatrix (const char* name) + : m(0, name) +{} + + +template +PointerMatrixVector >::PointerMatrix ( + const MATRIX* M, + const char* name) + : m(M, name) +{} + + +template +inline void +PointerMatrixVector >::clear () +{ + m = 0; +} + + +template +inline const PointerMatrixVector >& +PointerMatrixVector >::operator= (const MATRIX* M) +{ + m = M; + return *this; +} + + +template +inline bool +PointerMatrixVector >::empty () const +{ + if (m == 0) + return true; + return m->empty(); +} + +template +inline void +PointerMatrixVector >::vmult ( + Vector& dst, + const Vector& src) const +{ + Assert (m != 0, ExcNotInitialized()); + Assert (dst.size() == 1, ExcDimensionMismatch(dst.size(), 1)); + + dst(0) = *m * src; +} + + +template +inline void +PointerMatrixVector >::Tvmult ( + Vector& dst, + const Vector& src) const +{ + Assert (m != 0, ExcNotInitialized()); + Assert(src.size() == 1, ExcDimensionMismatch(src.size(), 1)); + + dst.equ (src(0), *m); +} + + +template +inline void +PointerMatrixVector >::vmult_add ( + Vector& dst, + const Vector& src) const +{ + Assert (m != 0, ExcNotInitialized()); + Assert (dst.size() == 1, ExcDimensionMismatch(dst.size(), 1)); + + dst(0) += *m * src; +} + + +template +inline void +PointerMatrixVector >::Tvmult_add ( + Vector& dst, + const Vector& src) const +{ + Assert (m != 0, ExcNotInitialized()); + Assert(src.size() == 1, ExcDimensionMismatch(src.size(), 1)); + + dst.add (src(0), *m); +} + + +template +inline const void* +PointerMatrixVector >::get () const +{ + return m; +} + + + #endif -- 2.39.5