]> https://gitweb.dealii.org/ - dealii.git/commitdiff
implement mean_value() for PETScWrappers::MPI::Vector.
authorTimo Heister <timo.heister@gmail.com>
Sun, 6 Feb 2011 16:38:39 +0000 (16:38 +0000)
committerTimo Heister <timo.heister@gmail.com>
Sun, 6 Feb 2011 16:38:39 +0000 (16:38 +0000)
git-svn-id: https://svn.dealii.org/trunk@23297 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/source/lac/petsc_vector_base.cc

index 5b39a8318b28e6d27bbe1066879a497233f15e02..18efed8d5fd2b359f371d366c8c2f707ca3638e2 100644 (file)
@@ -414,13 +414,21 @@ namespace PETScWrappers
   PetscScalar
   VectorBase::mean_value () const
   {
-    Assert(dynamic_cast<const PETScWrappers::MPI::Vector *>(this) == 0,
-          ExcMessage   ("::mean_value() not implemented for MPI::Vector."));
+    int ierr;
+                                    // We can only use our more efficient
+                                    // routine in the serial case.
+    if (dynamic_cast<const PETScWrappers::MPI::Vector *>(this) != 0)
+      {
+       PetscScalar sum;
+       ierr = VecSum( vector, &sum);
+       AssertThrow (ierr == 0, ExcPETScError(ierr));
+       return sum/size();
+      }
     
                                      // get a representation of the vector and
                                      // loop over all the elements
     PetscScalar *start_ptr;
-    int ierr = VecGetArray (vector, &start_ptr);
+    ierr = VecGetArray (vector, &start_ptr);
     AssertThrow (ierr == 0, ExcPETScError(ierr));
 
     PetscScalar mean = 0;

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.