From 89ea8b434bb7b973e6b7a060c5a54bbda7e70605 Mon Sep 17 00:00:00 2001 From: Stefano Zampini Date: Tue, 17 Jan 2023 11:07:05 +0300 Subject: [PATCH] PETScWrappers::VectorBase implement copy operator Judging from 456c02ad25e, this was not implemented --- include/deal.II/lac/petsc_vector_base.h | 13 ++++++------- source/lac/petsc_vector_base.cc | 13 +++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) 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) { -- 2.39.5