From 56815c9e9151b9dbce1550c7e7e732be402140a0 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 21 Dec 2023 15:42:18 -0700 Subject: [PATCH] Prohibit calling compress() on vectors with ghost elements. --- source/lac/petsc_vector_base.cc | 7 +++++++ source/lac/trilinos_vector.cc | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/source/lac/petsc_vector_base.cc b/source/lac/petsc_vector_base.cc index d3db0022dd..052af43735 100644 --- a/source/lac/petsc_vector_base.cc +++ b/source/lac/petsc_vector_base.cc @@ -540,6 +540,13 @@ namespace PETScWrappers void VectorBase::compress(const VectorOperation::values operation) { + Assert(has_ghost_elements() == false, + ExcMessage("Calling compress() is only useful if a vector " + "has been written into, but this is a vector with ghost " + "elements and consequently is read-only. It does " + "not make sense to call compress() for such " + "vectors.")); + { # ifdef DEBUG // Check that all processors agree that last_action is the same (or none!) diff --git a/source/lac/trilinos_vector.cc b/source/lac/trilinos_vector.cc index 0431f266b9..8d26487152 100644 --- a/source/lac/trilinos_vector.cc +++ b/source/lac/trilinos_vector.cc @@ -599,6 +599,14 @@ namespace TrilinosWrappers void Vector::compress(VectorOperation::values given_last_action) { + Assert(has_ghost_elements() == false, + ExcMessage( + "Calling compress() is only useful if a vector " + "has been written into, but this is a vector with ghost " + "elements and consequently is read-only. It does " + "not make sense to call compress() for such " + "vectors.")); + // Select which mode to send to Trilinos. Note that we use last_action if // available and ignore what the user tells us to detect wrongly mixed // operations. Typically given_last_action is only used on machines that -- 2.39.5