From c0e9ab71853c27a75bb127dde7259705b1bb56b0 Mon Sep 17 00:00:00 2001 From: wolf Date: Tue, 6 Apr 2004 02:33:35 +0000 Subject: [PATCH] Fix a strange problem with v(i)=w(i), see the petsc_vector_assign_01 test. git-svn-id: https://svn.dealii.org/trunk@8978 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/petsc_vector_base.h | 44 +++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/deal.II/lac/include/lac/petsc_vector_base.h b/deal.II/lac/include/lac/petsc_vector_base.h index 7d26ec2715..ff4c1a1a36 100644 --- a/deal.II/lac/include/lac/petsc_vector_base.h +++ b/deal.II/lac/include/lac/petsc_vector_base.h @@ -74,6 +74,28 @@ namespace PETScWrappers const unsigned int index); public: + /** + * This looks like a copy operator, + * but does something different than + * usual. In particular, it does not + * copy the member variables of this + * reference. Rather, it handles the + * situation where we have two + * vectors @p v and @p w, and assign + * elements like in + * v(i)=w(i). Here, both + * left and right hand side of the + * assignment have data type + * VectorReference, but what we + * really mean is to assign the + * vector elements represented by the + * two references. This operator + * implements this operation. Note + * also that this allows us to make + * the assignment operator const. + */ + const VectorReference & operator = (const VectorReference &r) const; + /** * Set the referenced element of the * vector to s. @@ -87,8 +109,8 @@ namespace PETScWrappers const VectorReference & operator += (const PetscScalar &s) const; /** - * Subtract s from the referenced - * element of the vector. + * Subtract s from the + * referenced element of the vector. */ const VectorReference & operator -= (const PetscScalar &s) const; @@ -255,7 +277,8 @@ namespace PETScWrappers bool operator != (const VectorBase &v) const; /** - * Return the global dimension of the vector. + * Return the global dimension of the + * vector. */ unsigned int size () const; @@ -631,6 +654,21 @@ namespace PETScWrappers {} + inline + const VectorReference & + VectorReference::operator = (const VectorReference &r) const + { + // as explained in the class + // documentation, this is not the copy + // operator. so simply pass on to the + // "correct" assignment operator + *this = static_cast (r); + + return *this; + } + + + inline const VectorReference & VectorReference::operator = (const PetscScalar &value) const -- 2.39.5