From: kronbichler Date: Mon, 17 Nov 2008 16:27:29 +0000 (+0000) Subject: I messed some things up when previously submitting code. Now everything is hopefully... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d85b8ba8ebd25875a1208d23307223776dcd9d8;p=dealii-svn.git I messed some things up when previously submitting code. Now everything is hopefully working again. git-svn-id: https://svn.dealii.org/trunk@17606 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/trilinos_vector.h b/deal.II/lac/include/lac/trilinos_vector.h index 3b3d95c388..99158a0f2a 100755 --- a/deal.II/lac/include/lac/trilinos_vector.h +++ b/deal.II/lac/include/lac/trilinos_vector.h @@ -214,7 +214,7 @@ namespace TrilinosWrappers * elements. */ template - explicit Vector (const Epetra_Map &InputMap, + explicit Vector (const Epetra_Map &InputMap, const dealii::Vector &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 - * v. If fast - * is not true, 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 + * v. If fast is + * not true, 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, * allow_different_maps, * 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 * v is a distributed - * vector. In this case, the - * variable fast needs - * to be set to false, - * since it does not make sense - * to exchange data between - * differently parallelized + * vector. In this case, the variable + * fast needs to be set to + * false, 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 indices (size); std::vector values (size); - for (unsigned int i=0; iReplaceGlobalValues (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 &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 (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 indices (size); - std::vector values (size); - for (unsigned int i=0; iReplaceGlobalValues (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 n. */ - 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 Vector::Vector (const dealii::Vector &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 (new Epetra_FEVector(map)); - - std::vector indices (v.size()); - std::vector values (v.size()); - for (unsigned int i=0; iReplaceGlobalValues((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 indices (size); std::vector values (size); - for (unsigned int i=0; iReplaceGlobalValues (size, &indices[0], &values[0]); - AssertThrow (ierr == 0, ExcTrilinosError()); + AssertThrow (ierr == 0, VectorBase::ExcTrilinosError(ierr)); return *this; } diff --git a/deal.II/lac/source/trilinos_block_vector.cc b/deal.II/lac/source/trilinos_block_vector.cc index c335dd5552..0d64f03947 100644 --- a/deal.II/lac/source/trilinos_block_vector.cc +++ b/deal.II/lac/source/trilinos_block_vector.cc @@ -115,7 +115,7 @@ namespace TrilinosWrappers components.resize(n_blocks()); for (unsigned int i=0;in_blocks();++i) block(i).clear(); + + collect_sizes(); } @@ -207,15 +209,14 @@ namespace TrilinosWrappers void BlockVector::reinit (const std::vector &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; iMap().NumGlobalElements(), + v.vector->Map().NumMyElements(), + v.vector->Map().IndexBase(), + v.vector->Map().Comm()); vector = std::auto_ptr (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 (new Epetra_FEVector (map)); + vector = std::auto_ptr (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 (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 (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 (new Epetra_FEVector(map)); } diff --git a/deal.II/lac/source/trilinos_vector_base.cc b/deal.II/lac/source/trilinos_vector_base.cc index c0e69c51aa..af17b7d29f 100644 --- a/deal.II/lac/source/trilinos_vector_base.cc +++ b/deal.II/lac/source/trilinos_vector_base.cc @@ -72,8 +72,8 @@ namespace TrilinosWrappers Subscriptor(), last_action (Zero), compressed (true), - vector(std::auto_ptr - (new Epetra_FEVector(*v.vector))) + vector(std::auto_ptr + (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(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(new Epetra_FEVector(*v.vector)); } @@ -152,9 +152,10 @@ namespace TrilinosWrappers VectorBase & VectorBase::operator = (const VectorBase &v) { - if (&*vector == 0) - vector = std::auto_ptr(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(new Epetra_FEVector(*v.vector)); else *vector = *v.vector;