From ab5448fdcee3ed90b49cc102c1963600960bfa23 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Tue, 14 Oct 2014 16:19:34 -0400 Subject: [PATCH] Allow v=0.0 for ghosted PETSc and Trilinos vectors --- doc/news/changes.h | 6 ++++++ include/deal.II/lac/trilinos_vector_base.h | 4 ---- source/lac/petsc_vector_base.cc | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/doc/news/changes.h b/doc/news/changes.h index 0665d082ae..ce74a29e2b 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -307,6 +307,12 @@ inconvenience this causes.

Specific improvements

    +
  1. Changed: PETSc and Trilinos vectors with ghost entries can now be reset to zero + using = 0.0; +
    + (Timo Heister, 2014/10/14) +
  2. +
  3. New: The new function FiniteElement::get_associated_geometry_primitive() allows to query whether a given degree of freedom is associated with a vertex, line, quad, or hex. diff --git a/include/deal.II/lac/trilinos_vector_base.h b/include/deal.II/lac/trilinos_vector_base.h index dd8fc22fc9..449c4a5cf0 100644 --- a/include/deal.II/lac/trilinos_vector_base.h +++ b/include/deal.II/lac/trilinos_vector_base.h @@ -1227,10 +1227,6 @@ namespace TrilinosWrappers VectorBase & VectorBase::operator = (const TrilinosScalar s) { - // if we have ghost values, do not allow - // writing to this vector at all. - Assert (!has_ghost_elements(), ExcGhostsPresent()); - Assert (numbers::is_finite(s), ExcNumberNotFinite()); const int ierr = vector->PutScalar(s); diff --git a/source/lac/petsc_vector_base.cc b/source/lac/petsc_vector_base.cc index 4bb7c835ed..007453082d 100644 --- a/source/lac/petsc_vector_base.cc +++ b/source/lac/petsc_vector_base.cc @@ -213,14 +213,26 @@ namespace PETScWrappers VectorBase & VectorBase::operator = (const PetscScalar s) { - Assert (!has_ghost_elements(), ExcGhostsPresent()); Assert (numbers::is_finite(s), ExcNumberNotFinite()); //TODO[TH]: assert(is_compressed()) - const int ierr = VecSet (vector, s); + int ierr = VecSet (vector, s); AssertThrow (ierr == 0, ExcPETScError(ierr)); + if (has_ghost_elements()) + { + Vec ghost = PETSC_NULL; + ierr = VecGhostGetLocalForm(vector, &ghost); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + ierr = VecSet (ghost, s); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + ierr = VecGhostRestoreLocalForm(vector, &ghost); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + } + return *this; } -- 2.39.5