From 7b902005de550cd52b3e6a423e7e62a79363acba Mon Sep 17 00:00:00 2001 From: Stefano Zampini Date: Tue, 17 Jan 2023 11:38:11 +0300 Subject: [PATCH] Remove usage of VecGetValues It fails with the newest versions of PETSc if the vector is not assembled --- source/lac/petsc_vector_base.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/lac/petsc_vector_base.cc b/source/lac/petsc_vector_base.cc index 17c50e09b6..309fb0e361 100644 --- a/source/lac/petsc_vector_base.cc +++ b/source/lac/petsc_vector_base.cc @@ -108,9 +108,12 @@ namespace PETScWrappers (index < static_cast(end)), ExcAccessToNonlocalElement(index, begin, end - 1)); - PetscInt idx = index; - PetscScalar value; - ierr = VecGetValues(vector.vector, 1, &idx, &value); + const PetscScalar *ptr; + PetscScalar value; + ierr = VecGetArrayRead(vector.vector, &ptr); + AssertThrow(ierr == 0, ExcPETScError(ierr)); + value = *(ptr + index - begin); + ierr = VecRestoreArrayRead(vector.vector, &ptr); AssertThrow(ierr == 0, ExcPETScError(ierr)); return value; -- 2.39.5