From ccf7555ba0c7edc446e8878d43660a9f2d650e60 Mon Sep 17 00:00:00 2001 From: kronbichler Date: Mon, 17 Nov 2008 14:35:35 +0000 Subject: [PATCH] A few vector reinit functions using the = operator did not work properly. This is now fixed. git-svn-id: https://svn.dealii.org/trunk@17605 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/trilinos_vector.h | 60 ++++++++++++++++++- .../lac/include/lac/trilinos_vector_base.h | 13 +++- deal.II/lac/source/trilinos_vector_base.cc | 20 ++++++- 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/deal.II/lac/include/lac/trilinos_vector.h b/deal.II/lac/include/lac/trilinos_vector.h index a0babddce0..3b3d95c388 100755 --- a/deal.II/lac/include/lac/trilinos_vector.h +++ b/deal.II/lac/include/lac/trilinos_vector.h @@ -459,7 +459,35 @@ namespace TrilinosWrappers Vector & Vector::operator = (const ::dealii::Vector &v) { - VectorBase::operator = (v); +#ifdef DEAL_II_COMPILER_SUPPORTS_MPI + map = Epetra_Map (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD)); +#else + 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()); + return *this; } @@ -675,7 +703,35 @@ namespace TrilinosWrappers Vector & Vector::operator = (const ::dealii::Vector &v) { - VectorBase::operator = (v); +#ifdef DEAL_II_COMPILER_SUPPORTS_MPI + map = Epetra_LocalMap (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD)); +#else + map = Epetra_LocalMap (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()); + return *this; } diff --git a/deal.II/lac/include/lac/trilinos_vector_base.h b/deal.II/lac/include/lac/trilinos_vector_base.h index 0448e3c63d..9b0e5f4b39 100644 --- a/deal.II/lac/include/lac/trilinos_vector_base.h +++ b/deal.II/lac/include/lac/trilinos_vector_base.h @@ -364,6 +364,17 @@ namespace TrilinosWrappers VectorBase & operator = (const TrilinosScalar s); + /** + * Copy function. This function takes + * a VectorBase vector and copies all + * the elements. The target vector + * will have the same parallel + * distribution as the calling + * vector. + */ + VectorBase & + operator = (const VectorBase &v); + /** * Another copy function. This * one takes a deal.II vector and @@ -383,7 +394,7 @@ namespace TrilinosWrappers */ template VectorBase & - operator = (const ::dealii::Vector &v); + operator = (const ::dealii::Vector &v); /** * Test for equality. This diff --git a/deal.II/lac/source/trilinos_vector_base.cc b/deal.II/lac/source/trilinos_vector_base.cc index 9a0e0eaf64..c0e69c51aa 100644 --- a/deal.II/lac/source/trilinos_vector_base.cc +++ b/deal.II/lac/source/trilinos_vector_base.cc @@ -108,12 +108,14 @@ namespace TrilinosWrappers const bool fast) { (void)fast; - if (&*vector != 0) + if (&*vector == 0) vector = std::auto_ptr(new Epetra_FEVector(*v.vector)); else if (vector->Map().SameAs(v.vector->Map()) == false) vector = std::auto_ptr(new Epetra_FEVector(*v.vector)); } + + void VectorBase::compress () { @@ -146,6 +148,22 @@ 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) + vector = std::auto_ptr(new Epetra_FEVector(*v.vector)); + else + *vector = *v.vector; + + return *this; + } + + + template VectorBase & VectorBase::operator = (const ::dealii::Vector &v) -- 2.39.5