]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Restored VectorBase::set and introduced a collective add function.
authorprill <prill@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 16 Jul 2007 05:55:14 +0000 (05:55 +0000)
committerprill <prill@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 16 Jul 2007 05:55:14 +0000 (05:55 +0000)
git-svn-id: https://svn.dealii.org/trunk@14856 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 79a69eada85f12fb4f39cfe41196f155258fac7d..66579a3fe2e397beb53ed387f60f81502c96ef14 100644 (file)
@@ -370,12 +370,18 @@ namespace PETScWrappers
                                         * are stated in the first argument,
                                         * the corresponding values in the
                                         * second.
-                                       * If the flag @p add_values is true,
-                                       * the values are added to the vector.
                                         */
       void set (const std::vector<unsigned int> &indices,
-                const std::vector<PetscScalar>  &values,
-               const bool add_values = false);
+                const std::vector<PetscScalar>  &values);
+
+                                      /**
+                                        * A collective add operation: This
+                                       * function adds a whole set of values
+                                       * stored in @p values to the vector
+                                       * components specified by @p indices.
+                                        */
+      void add (const std::vector<unsigned int> &indices,
+                const std::vector<PetscScalar>  &values);
       
                                        /**
                                         * Return the scalar product of two
@@ -677,6 +683,18 @@ namespace PETScWrappers
                                         * Make the reference class a friend.
                                         */
       friend class internal::VectorReference;
+
+                                      /**
+                                        * Collective set or add
+                                        * operation: This function is
+                                        * invoked by the collective @p
+                                        * set and @p add with the
+                                        * @add_values flag set to the
+                                        * corresponding value.
+                                        */
+      void do_set_add_operation (const std::vector<unsigned int> &indices,
+                                const std::vector<PetscScalar>  &values,
+                                const bool add_values);
   };
 
 
index f9260ec675eeb18d68a8f93bbf2aac871359d054..2878a49d27dcdf742998b8afab55053023e5db76 100644 (file)
@@ -216,51 +216,18 @@ namespace PETScWrappers
 
   void
   VectorBase::set (const std::vector<unsigned int> &indices,
-                   const std::vector<PetscScalar>  &values,
-                  const bool add_values)
+                   const std::vector<PetscScalar>  &values)
   {
-    Assert (indices.size() == values.size(),
-            ExcMessage ("Function called with arguments of different sizes"));
+    do_set_add_operation(indices, values, false);
+  }
 
-    if (last_action != VectorBase::LastAction::insert)
-      {
-        int ierr;
-        ierr = VecAssemblyBegin (vector);
-        AssertThrow (ierr == 0, ExcPETScError(ierr));
 
-        ierr = VecAssemblyEnd (vector);
-        AssertThrow (ierr == 0, ExcPETScError(ierr));
-      }
 
-                                    // VecSetValues complains if we
-                                    // come with an empty
-                                    // vector. however, it is not a
-                                    // collective operation, so we
-                                    // can skip the call if necessary
-                                    // (unlike the above calls)
-    if (indices.size() != 0)
-      {
-#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
-
-       InsertMode mode = INSERT_VALUES;
-       if (add_values)
-         mode = ADD_VALUES;
-       const int ierr
-         = VecSetValues (vector, indices.size(),
-                         &petsc_indices[0], &values[0],
-                         mode);
-       AssertThrow (ierr == 0, ExcPETScError(ierr));
-      }
-
-    last_action = LastAction::insert;
+  void
+  VectorBase::add (const std::vector<unsigned int> &indices,
+                   const std::vector<PetscScalar>  &values)
+  {
+    do_set_add_operation(indices, values, true);
   }
   
 
@@ -879,6 +846,57 @@ namespace PETScWrappers
   {
     return vector;
   }
+
+
+
+  void
+  VectorBase::do_set_add_operation (const std::vector<unsigned int> &indices,
+                                   const std::vector<PetscScalar>  &values,
+                                   const bool add_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));
+      }
+
+                                    // VecSetValues complains if we
+                                    // come with an empty
+                                    // vector. however, it is not a
+                                    // collective operation, so we
+                                    // can skip the call if necessary
+                                    // (unlike the above calls)
+    if (indices.size() != 0)
+      {
+#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
+
+       InsertMode mode = INSERT_VALUES;
+       if (add_values)
+         mode = ADD_VALUES;
+       const int ierr
+         = VecSetValues (vector, indices.size(),
+                         &petsc_indices[0], &values[0],
+                         mode);
+       AssertThrow (ierr == 0, ExcPETScError(ierr));
+      }
+
+    last_action = LastAction::insert;
+  }
   
 }
 

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.