]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
I messed some things up when previously submitting code. Now everything is hopefully...
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 17 Nov 2008 16:27:29 +0000 (16:27 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 17 Nov 2008 16:27:29 +0000 (16:27 +0000)
git-svn-id: https://svn.dealii.org/trunk@17606 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/trilinos_vector.h
deal.II/lac/source/trilinos_block_vector.cc
deal.II/lac/source/trilinos_vector.cc
deal.II/lac/source/trilinos_vector_base.cc

index 3b3d95c38862f6168b25231de9219debad7a67a0..99158a0f2a2ec0e4c94b48fffe7a30eba6efad09 100755 (executable)
@@ -214,7 +214,7 @@ namespace TrilinosWrappers
                                           * elements.
                                           */
         template <typename Number>
-        explicit Vector (const Epetra_Map              &InputMap,
+        explicit Vector (const Epetra_Map             &InputMap,
                          const dealii::Vector<Number> &v);
 
                                       /**
@@ -229,41 +229,38 @@ namespace TrilinosWrappers
 
                                       /**
                                        * Reinit functionality. This
-                                       * function sets the calling
-                                       * vector to the dimension and
-                                       * the parallel distribution of
-                                       * the input vector, but does not
-                                       * copy the elements in
-                                       * <tt>v</tt>. If <tt>fast</tt>
-                                       * is not <tt>true</tt>, the
-                                       * elements in the vector are
-                                       * initialized with zero,
-                                       * otherwise the content will be
-                                       * left unchanged and the user
-                                       * has to set all elements.
+                                       * function sets the calling vector
+                                       * to the dimension and the parallel
+                                       * distribution of the input vector,
+                                       * but does not copy the elements in
+                                       * <tt>v</tt>. If <tt>fast</tt> is
+                                       * not <tt>true</tt>, the elements in
+                                       * the vector are initialized with
+                                       * zero, otherwise the content will
+                                       * be left unchanged and the user has
+                                       * to set all elements.
                                        *
-                                       * This class has a third
-                                       * possible argument,
+                                       * Reinit functionality. This class
+                                       * also has a third possible
+                                       * argument,
                                        * <tt>allow_different_maps</tt>,
                                        * that allows for an exchange of
                                        * data between two equal-sized
                                        * vectors (but being distributed
                                        * differently among the
-                                       * processors). A trivial
-                                       * application of this function
-                                       * is to generate a replication
-                                       * of a whole vector on each
-                                       * machine, when the calling
-                                       * vector is build according to
-                                       * the localized vector class
+                                       * processors). A trivial application
+                                       * of this function is to generate a
+                                       * replication of a whole vector on
+                                       * each machine, when the calling
+                                       * vector is build according to the
+                                       * localized vector class
                                        * TrilinosWrappers::Vector, and
                                        * <tt>v</tt> is a distributed
-                                       * vector. In this case, the
-                                       * variable <tt>fast</tt> needs
-                                       * to be set to <tt>false</tt>,
-                                       * since it does not make sense
-                                       * to exchange data between
-                                       * differently parallelized
+                                       * vector. In this case, the variable
+                                       * <tt>fast</tt> needs to be set to
+                                       * <tt>false</tt>, since it does not
+                                       * make sense to exchange data
+                                       * between differently parallelized
                                        * vectors without touching the
                                        * elements.
                                        */
@@ -431,7 +428,7 @@ namespace TrilinosWrappers
                                   // that a direct access is not possible.
       std::vector<int> indices (size);
       std::vector<double> values (size);
-      for (unsigned int i=0; i<size; ++i)
+      for (int i=0; i<size; ++i)
        {
          indices[i] = map.GID(i);
          values[i] = v(i);
@@ -440,7 +437,7 @@ namespace TrilinosWrappers
       const int ierr = vector->ReplaceGlobalValues (size, &indices[0], 
                                                    &values[0]);
 
-      AssertThrow (ierr == 0, ExcTrilinosError());
+      AssertThrow (ierr == 0, VectorBase::ExcTrilinosError());
     }
 
   
@@ -459,34 +456,16 @@ namespace TrilinosWrappers
     Vector & 
     Vector::operator = (const ::dealii::Vector<Number> &v)
     {
+      if (size() != v.size())
+       {
 #ifdef DEAL_II_COMPILER_SUPPORTS_MPI
-      map = Epetra_Map (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD));
+         map = Epetra_Map (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD));
 #else
-      map = Epetra_Map (v.size(), 0, Epetra_SerialComm());
+         map = Epetra_Map (v.size(), 0, Epetra_SerialComm());
 #endif
-
-      vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
-      
-      const int min_my_id = map.MinMyGID();
-      const int size = map.NumMyElements();
-
-      Assert (map.MaxLID() == size-1,
-             ExcDimensionMismatch(map.MaxLID(), size-1));
-
-                                  // Need to copy out values, since the
-                                  // deal.II might not use doubles, so 
-                                  // that a direct access is not possible.
-      std::vector<int> indices (size);
-      std::vector<double> values (size);
-      for (unsigned int i=0; i<size; ++i)
-       {
-         indices[i] = map.GID(i);
-         values[i] = v(i);
        }
-
-      const int ierr = vector->ReplaceGlobalValues (size, &indices[0], 
-                                                   &values[0]);
-      AssertThrow (ierr == 0, ExcTrilinosError());
+      
+      *this = Vector(map, v);
 
       return *this;
     }
@@ -566,7 +545,8 @@ namespace TrilinosWrappers
                                        * the vector to the size
                                        * specified by <tt>n</tt>.
                                        */
-      void reinit (const unsigned int n);
+      void reinit (const unsigned int n,
+                  const bool         fast = false);
 
                                        /**
                                        * Initialization with an
@@ -586,10 +566,9 @@ namespace TrilinosWrappers
 
                                        /**
                                        * Reinit function. Takes the
-                                       * information of a
-                                       * Vector and copies
-                                       * everything to the calling
-                                       * vector.
+                                       * information of a Vector and copies
+                                       * everything to the calling vector,
+                                       * now also allowing different maps.
                                        */
       void reinit (const VectorBase &V,
                   const bool        fast = false,
@@ -665,27 +644,8 @@ namespace TrilinosWrappers
 
   template <typename number>
   Vector::Vector (const dealii::Vector<number> &v)
-                 :
-#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
-                 map (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD))
-#else
-                 map (v.size(), 0, Epetra_SerialComm())
-#endif
   {
-    vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
-
-    std::vector<int> indices (v.size());
-    std::vector<double> values (v.size());
-    for (unsigned int i=0; i<v.size(); ++i)
-      {
-       indices[i] = map.GID(i);
-       values[i] = v(i);
-      }
-
-    const int ierr = vector->ReplaceGlobalValues((int)v.size(),
-                                                &indices[0], &values[0]);
-
-    AssertThrow (ierr == 0, ExcTrilinosError(ierr));
+    *this = v;
   }
 
   
@@ -722,7 +682,7 @@ namespace TrilinosWrappers
                                   // that a direct access is not possible.
     std::vector<int> indices (size);
     std::vector<double> values (size);
-    for (unsigned int i=0; i<size; ++i)
+    for (int i=0; i<size; ++i)
       {
        indices[i] = map.GID(i);
        values[i] = v(i);
@@ -730,7 +690,7 @@ namespace TrilinosWrappers
 
     const int ierr = vector->ReplaceGlobalValues (size, &indices[0], 
                                                  &values[0]);
-    AssertThrow (ierr == 0, ExcTrilinosError());
+    AssertThrow (ierr == 0, VectorBase::ExcTrilinosError(ierr));
 
     return *this;
   }
index c335dd5552660df37f04f7bb717ee409769a2eab..0d64f039474ce943958e86de32a0ee433e0bccb5 100644 (file)
@@ -115,7 +115,7 @@ namespace TrilinosWrappers
         components.resize(n_blocks());
   
       for (unsigned int i=0;i<n_blocks();++i)
-        components[i].reinit(v.block(i), fast);
+        components[i].reinit(v.block(i), fast, false);
       
       collect_sizes();
     }
@@ -132,6 +132,8 @@ namespace TrilinosWrappers
   
       for (unsigned int i=0;i<this->n_blocks();++i)
         block(i).clear();
+
+      collect_sizes();
     }
 
 
@@ -207,15 +209,14 @@ namespace TrilinosWrappers
 
   void
   BlockVector::reinit (const std::vector<unsigned int> &block_sizes,
-                      const bool                       /*fast*/)
+                      const bool                       fast)
   {
     this->block_indices.reinit (block_sizes);
     if (components.size() != n_blocks())
       components.resize(n_blocks());
 
     for (unsigned int i=0; i<n_blocks(); ++i)
-//TODO: use the 'fast' argument here...      
-      components[i].reinit(block_sizes[i]);
+      components[i].reinit(block_sizes[i], fast);
 
     collect_sizes();      
   }
@@ -230,7 +231,7 @@ namespace TrilinosWrappers
       components.resize(n_blocks());
   
     for (unsigned int i=0;i<n_blocks();++i)
-      components[i].reinit(v.block(i));
+      components[i].reinit(v.block(i), true, false);
       
     collect_sizes();
   }
@@ -247,6 +248,8 @@ namespace TrilinosWrappers
   
     for (unsigned int i=0;i<n_blocks();++i)
       block(i).clear();
+
+    collect_sizes();
   }
 
 
index 24eed161befbc597e3d291dd42fc1bc67c93d5a8..12666aea66f3e92c2a64d1ff66f2e6a56266598e 100755 (executable)
@@ -165,7 +165,10 @@ namespace TrilinosWrappers
       else
        {
          vector.reset();
-         map = v.map;
+         map = Epetra_Map(v.vector->Map().NumGlobalElements(),
+                          v.vector->Map().NumMyElements(),
+                          v.vector->Map().IndexBase(),
+                          v.vector->Map().Comm());
          vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(*v.vector));
        }
 
@@ -275,22 +278,23 @@ namespace TrilinosWrappers
 
 
   void
-  Vector::reinit (const unsigned int n)
+  Vector::reinit (const unsigned int n,
+                 const bool         fast)
   {
-    vector.reset();
-
-    if (map.NumGlobalElements() != (int)n)
+    if (size() != n)
       {
+       vector.reset();
+
 #ifdef DEAL_II_COMPILER_SUPPORTS_MPI
        map = Epetra_LocalMap ((int)n, 0, Epetra_MpiComm(MPI_COMM_WORLD));
 #else
        map = Epetra_LocalMap ((int)n, 0, Epetra_SerialComm());
 #endif
-      }
 
-    last_action = Zero;
+       last_action = Zero;
 
-    vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector (map));
+       vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector (map));
+      }
   }
 
 
@@ -303,7 +307,8 @@ namespace TrilinosWrappers
 
     if (map.NumGlobalElements() != input_map.NumGlobalElements())
       {
-       map = Epetra_LocalMap (input_map.NumGlobalElements(),0,
+       map = Epetra_LocalMap (input_map.NumGlobalElements(),
+                              input_map.IndexBase(),
                               input_map.Comm());
       }
 
@@ -331,7 +336,9 @@ namespace TrilinosWrappers
       {
        vector.reset();
        if (map.SameAs(v.vector->Map()) == false)
-         map = Epetra_LocalMap (v.vector->GlobalLength(),0,v.vector->Comm());
+         map = Epetra_LocalMap (v.vector->GlobalLength(),
+                                v.vector->Map().IndexBase(),
+                                v.vector->Comm());
 
        vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
        last_action = Zero;
@@ -368,9 +375,10 @@ namespace TrilinosWrappers
   Vector &
   Vector::operator = (const MPI::Vector &v)
   {
-    if (vector->Map().SameAs(v.vector->Map()) == false)
+    if (size() != v.size())
       {
-       map = Epetra_LocalMap (v.vector->Map().NumGlobalElements(), 0,
+       map = Epetra_LocalMap (v.vector->Map().NumGlobalElements(), 
+                              v.vector->Map().IndexBase(),
                               v.vector->Comm());
        vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
       }
@@ -386,7 +394,8 @@ namespace TrilinosWrappers
   {
     if (vector->Map().SameAs(v.vector->Map()) == false)
       {
-       map = Epetra_LocalMap (v.vector->Map().NumGlobalElements(), 0,
+       map = Epetra_LocalMap (v.vector->Map().NumGlobalElements(), 
+                              v.vector->Map().IndexBase(),
                               v.vector->Comm());
        vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
       }
index c0e69c51aa56d268bb4a773faacfeffd010d739a..af17b7d29fb09020dc939cd78e1e950f8cadc40f 100644 (file)
@@ -72,8 +72,8 @@ namespace TrilinosWrappers
                        Subscriptor(),
                        last_action (Zero),
                        compressed (true),
-                         vector(std::auto_ptr<Epetra_FEVector> 
-                                (new Epetra_FEVector(*v.vector)))
+                       vector(std::auto_ptr<Epetra_FEVector> 
+                              (new Epetra_FEVector(*v.vector)))
   {}
   
 
@@ -107,10 +107,10 @@ namespace TrilinosWrappers
   VectorBase::reinit (const VectorBase &v,
                      const bool        fast)
   {
-    (void)fast;
-    if (&*vector == 0)
-      vector = std::auto_ptr<Epetra_FEVector>(new Epetra_FEVector(*v.vector));
-    else if (vector->Map().SameAs(v.vector->Map()) == false)
+    Assert (&*vector != 0,
+           ExcMessage("Vector is not constructed properly."));
+
+    if (fast == false || vector->Map().SameAs(v.vector->Map()) == false)
       vector = std::auto_ptr<Epetra_FEVector>(new Epetra_FEVector(*v.vector));
   }
 
@@ -152,9 +152,10 @@ namespace TrilinosWrappers
   VectorBase &
   VectorBase::operator = (const VectorBase &v)
   {
-    if (&*vector == 0)
-      vector = std::auto_ptr<Epetra_FEVector>(new Epetra_FEVector(*v.vector));
-    else if (vector->Map().SameAs(v.vector->Map()) == false)
+    Assert (&*vector != 0,
+           ExcMessage("Vector is not constructed properly."));
+
+    if (vector->Map().SameAs(v.vector->Map()) == false)
       vector = std::auto_ptr<Epetra_FEVector>(new Epetra_FEVector(*v.vector));
     else
       *vector = *v.vector;

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.