]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Remove usage of VecGetValues
authorStefano Zampini <stefano.zampini@gmail.com>
Tue, 17 Jan 2023 08:38:11 +0000 (11:38 +0300)
committerStefano Zampini <stefano.zampini@gmail.com>
Sun, 22 Jan 2023 11:03:03 +0000 (14:03 +0300)
It fails with the newest versions of PETSc if the vector is not assembled

source/lac/petsc_vector_base.cc

index 17c50e09b688055c11d67cf19920922405af5841..309fb0e3613e0bc50848f20ae3848a7cb1112f69 100644 (file)
@@ -108,9 +108,12 @@ namespace PETScWrappers
                     (index < static_cast<size_type>(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;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.