]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Fix PETSc problem with my previous commit.
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 21 Sep 2009 07:22:01 +0000 (07:22 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 21 Sep 2009 07:22:01 +0000 (07:22 +0000)
git-svn-id: https://svn.dealii.org/trunk@19484 0785d39b-7218-0410-832d-ea1e28bc413d

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

index b2f920801fe63da77ed99e232cbc362764bfddcc..e4be758cda8206ebf718d7ca6c5449944c085414 100644 (file)
@@ -384,6 +384,29 @@ namespace PETScWrappers
       void add (const std::vector<unsigned int> &indices,
                 const std::vector<PetscScalar>  &values);
 
+                                      /**
+                                       * This is a second collective
+                                       * add operation. As a
+                                       * difference, this function
+                                       * takes a deal.II vector of
+                                       * values.
+                                       */
+      void add (const std::vector<unsigned int>     &indices,
+               const ::dealii::Vector<PetscScalar> &values);
+
+                                     /**
+                                      * Take an address where
+                                      * <tt>n_elements</tt> are stored
+                                      * contiguously and add them into
+                                      * the vector. Handles all cases
+                                      * which are not covered by the
+                                      * other two <tt>add()</tt>
+                                      * functions above.
+                                      */
+      void add (const unsigned int  n_elements,
+               const unsigned int *indices,
+               const PetscScalar  *values);
+
                                        /**
                                         * Return the scalar product of two
                                         * vectors. The vectors must have the
@@ -734,8 +757,9 @@ namespace PETScWrappers
                                         * @p add_values flag set to the
                                         * corresponding value.
                                         */
-      void do_set_add_operation (const std::vector<unsigned int> &indices,
-                                const std::vector<PetscScalar>  &values,
+      void do_set_add_operation (const unsigned int  n_elements,
+                                const unsigned int *indices,
+                                const PetscScalar  *values,
                                 const bool add_values);
   };
 
index a359b72f8715a35b988d523f313924b7ee3c10ee..ea4d9575b86e735c617a1c90afb8f212320e3064 100644 (file)
@@ -218,7 +218,9 @@ namespace PETScWrappers
   VectorBase::set (const std::vector<unsigned int> &indices,
                    const std::vector<PetscScalar>  &values)
   {
-    do_set_add_operation(indices, values, false);
+    Assert (indices.size() == values.size(),
+            ExcMessage ("Function called with arguments of different sizes"));
+    do_set_add_operation(indices.size(), &indices[0], &values[0], false);
   }
 
 
@@ -227,7 +229,32 @@ namespace PETScWrappers
   VectorBase::add (const std::vector<unsigned int> &indices,
                    const std::vector<PetscScalar>  &values)
   {
-    do_set_add_operation(indices, values, true);
+    Assert (indices.size() == values.size(),
+            ExcMessage ("Function called with arguments of different sizes"));
+    do_set_add_operation(indices.size(), &indices[0], &values[0], true);
+  }
+
+
+
+  void
+  VectorBase::add (const std::vector<unsigned int>    &indices,
+                   const ::dealii::Vector<PetscScalar>&values)
+  {
+    Assert (indices.size() == values.size(),
+            ExcMessage ("Function called with arguments of different sizes"));
+    do_set_add_operation(indices.size(), &indices[0], 
+                        &(*const_cast<dealii::Vector<PetscScalar>*>(&values))(0), 
+                        true);
+  }
+
+
+
+  void
+  VectorBase::add (const unsigned int  n_elements,
+                  const unsigned int *indices,
+                  const PetscScalar  *values)
+  {
+    do_set_add_operation(n_elements, indices, values, true);
   }
 
 
@@ -940,13 +967,11 @@ namespace PETScWrappers
 
 
   void
-  VectorBase::do_set_add_operation (const std::vector<unsigned int> &indices,
-                                   const std::vector<PetscScalar>  &values,
-                                   const bool add_values)
+  VectorBase::do_set_add_operation (const unsigned int  n_elements,
+                                   const unsigned int *indices,
+                                   const 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;
@@ -963,24 +988,24 @@ namespace PETScWrappers
                                     // collective operation, so we
                                     // can skip the call if necessary
                                     // (unlike the above calls)
-    if (indices.size() != 0)
+    if (n_elements != 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());
+#if (PETSC_VERSION_MAJOR <= 2) &&                                      \
+     ((PETSC_VERSION_MINOR < 2) ||                                             \
+      ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0)))
+       const int * petsc_indices = indices;
 #else
-       const std::vector<PetscInt> petsc_indices (indices.begin(),
-                                                  indices.end());
+       std::vector<PetscInt> petsc_ind (n_elements);
+       for (unsigned int i=0; i<n_elements; ++i)
+         petsc_ind[i] = indices[i];
+        const PetscInt * petsc_indices = &petsc_ind[0];
 #endif
 
-       InsertMode mode = INSERT_VALUES;
-       if (add_values)
-         mode = ADD_VALUES;
+       InsertMode mode = ADD_VALUES;
+       if (!add_values)
+         mode = INSERT_VALUES;
        const int ierr
-         = VecSetValues (vector, indices.size(),
-                         &petsc_indices[0], &values[0],
+         = VecSetValues (vector, n_elements, petsc_indices, values,
                          mode);
        AssertThrow (ierr == 0, ExcPETScError(ierr));
       }

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.