From: Stefano Zampini Date: Tue, 17 Jan 2023 08:07:05 +0000 (+0300) Subject: PETScWrappers::VectorBase implement copy operator X-Git-Tag: v9.5.0-rc1~601^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89ea8b434bb7b973e6b7a060c5a54bbda7e70605;p=dealii.git PETScWrappers::VectorBase implement copy operator Judging from 456c02ad25e, this was not implemented --- diff --git a/include/deal.II/lac/petsc_vector_base.h b/include/deal.II/lac/petsc_vector_base.h index 5e84c1e42e..8a5510054d 100644 --- a/include/deal.II/lac/petsc_vector_base.h +++ b/include/deal.II/lac/petsc_vector_base.h @@ -279,13 +279,6 @@ namespace PETScWrappers */ explicit VectorBase(const Vec &v); - /** - * The copy assignment operator is deleted to avoid accidental usage with - * unexpected behavior. - */ - VectorBase & - operator=(const VectorBase &) = delete; - /** * Destructor. */ @@ -311,6 +304,12 @@ namespace PETScWrappers void compress(const VectorOperation::values operation); + /** + * The copy assignment operator. + */ + VectorBase & + operator=(const VectorBase &); + /** * Set all components of the vector to the given number @p s. Simply pass * this down to the individual block objects, but we still need to declare diff --git a/source/lac/petsc_vector_base.cc b/source/lac/petsc_vector_base.cc index 5998d1894c..b1982975fe 100644 --- a/source/lac/petsc_vector_base.cc +++ b/source/lac/petsc_vector_base.cc @@ -189,6 +189,19 @@ namespace PETScWrappers + VectorBase & + VectorBase::operator=(const VectorBase &v) + { + Assert(size() == v.size(), ExcDimensionMismatch(size(), v.size())); + + PetscErrorCode ierr = VecCopy(v, vector); + AssertThrow(ierr == 0, ExcPETScError(ierr)); + + return *this; + } + + + VectorBase & VectorBase::operator=(const PetscScalar s) {