]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
VectoBase::add
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 10 Aug 2005 23:26:59 +0000 (23:26 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 10 Aug 2005 23:26:59 +0000 (23:26 +0000)
git-svn-id: https://svn.dealii.org/trunk@11279 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/petsc_vector_base.h
deal.II/lac/source/petsc_vector_base.cc

index 75db62118bb1886ba9f24669345fe43588a75ead..833e1407dacad05935df798aab0fd62fdfd287e8 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <petscvec.h>
 
+#include <vector>
 #include <utility>
 
 
@@ -350,6 +351,19 @@ namespace PETScWrappers
                                         */
       PetscScalar
       operator () (const unsigned int index) const;
+
+                                       /**
+                                        * A collective set operation: instead
+                                        * of setting individual elements of a
+                                        * vector, this function allows to set
+                                        * a whole set of elements at once. The
+                                        * indices of the elements to be set
+                                        * are stated in the first argument,
+                                        * the corresponding values in the
+                                        * second.
+                                        */
+      void set (const std::vector<unsigned int> &indices,
+                const std::vector<PetscScalar>  &values);
       
                                        /**
                                         * Return the scalar product of two
index 2c5aa4cb39e7fca6d232e28121fc87d7bfba16c5..fca25cd832888ff583d4e3266270a5f17fb0496d 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 2004 by the deal.II authors
+//    Copyright (C) 2004, 2005 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -209,6 +209,45 @@ namespace PETScWrappers
 
 
 
+  void
+  VectorBase::set (const std::vector<unsigned int> &indices,
+                   const std::vector<PetscScalar>  &values)
+  {
+    Assert (indices.size() == values.size(),
+            ExcMessage ("Function called with arguments of different sizes"));
+
+    if (last_action != VectorBase::LastAction::insert)
+      {
+        int ierr;
+        ierr = VecAssemblyBegin (vector);
+        AssertThrow (ierr == 0, ExcPETScError(ierr));
+
+        ierr = VecAssemblyEnd (vector);
+        AssertThrow (ierr == 0, ExcPETScError(ierr));
+      }
+
+#if (PETSC_VERSION_MAJOR <= 2) && \
+    ((PETSC_VERSION_MINOR < 2) ||  \
+     ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0)))
+    const std::vector<int> petsc_indices (indices.begin(),
+                                          indices.end());
+#else
+    const std::vector<PetscInt> petsc_indices (indices.begin(),
+                                               indices.end());
+#endif
+    
+    const int ierr
+      = VecSetValues (vector, indices.size(),
+                      &petsc_indices[0], &values[0],
+                      INSERT_VALUES);
+    AssertThrow (ierr == 0, ExcPETScError(ierr));
+    
+
+    last_action = LastAction::insert;
+  }
+  
+
+
   PetscScalar
   VectorBase::operator * (const VectorBase &vec) const
   {

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.