]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Added a copy function from (parallel) Trilinos vectors to (serial) deal.II vectors.
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 8 Sep 2008 06:32:32 +0000 (06:32 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 8 Sep 2008 06:32:32 +0000 (06:32 +0000)
git-svn-id: https://svn.dealii.org/trunk@16762 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/vector.h
deal.II/lac/include/lac/vector.templates.h

index 6cf1e5281b70bc368f73a5f1cc373f952907e7ce..b0f670401ad25d19f677f6ad0a5a116c19178a97 100644 (file)
@@ -34,6 +34,13 @@ namespace PETScWrappers
 }
 #endif
 
+#ifdef DEAL_II_USE_TRILINOS
+namespace TrilinosWrappers
+{
+  class Vector;
+}
+#endif
+
 template<typename number> class LAPACKFullMatrix;
 
 template <typename> class BlockVector;
@@ -180,6 +187,26 @@ class Vector : public Subscriptor
                                       */
     Vector (const PETScWrappers::MPI::Vector &v);
 #endif
+
+#ifdef DEAL_II_USE_TRILINOS
+                                     /**
+                                      * Another copy constructor: copy the
+                                      * values from a Trilinos wrapper
+                                      * vector class. This copy constructor is
+                                      * only available if Trilinos was detected
+                                      * during configuration time.
+                                     *
+                                     * Note that due to the communication
+                                      * model used in MPI, this operation can
+                                      * only succeed if all processes do it at
+                                      * the same time. I.e., it is not
+                                      * possible for only one process to
+                                      * obtain a copy of a parallel vector
+                                      * while the other jobs do something
+                                      * else.
+                                      */
+    Vector (const TrilinosWrappers::Vector &v);
+#endif
     
                                     /**
                                      * Constructor. Set dimension to
index 5fa9e5b5e8751d248828dcfbdd01beac38f43630..fd38939bd3ea11d83873d7ebac6489de3cd5ea09 100644 (file)
 #  include <lac/petsc_parallel_vector.h>
 #endif
 
+#ifdef DEAL_II_USE_TRILINOS
+#  include <lac/trilinos_vector.h>
+#endif
+
 #include <cmath>
 #include <cstring>
 #include <algorithm>
@@ -165,6 +169,32 @@ Vector<Number>::Vector (const PETScWrappers::MPI::Vector &v)
 
 #endif
 
+#ifdef DEAL_II_USE_TRILINOS
+
+template <typename Number>
+Vector<Number>::Vector (const TrilinosWrappers::Vector &v)
+                :
+               Subscriptor(),
+               vec_size(v.size()),
+               max_vec_size(v.size()),
+               val(0)
+{
+  if (vec_size != 0)
+    {
+      val = new Number[max_vec_size];
+      Assert (val != 0, ExcOutOfMemory());
+
+                                       // get a representation of the vector
+                                       // and copy it
+      TrilinosScalar **start_ptr;
+      int ierr = v.vector->ExtractView (&start_ptr);
+      AssertThrow (ierr == 0, ExcTrilinosError(ierr));
+      
+      std::copy (start_ptr[0], start_ptr[0]+vec_size, begin());
+    }
+}
+
+#endif
 
 template <typename Number>
 template <typename Number2>

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.