From cfa233480b5b271905a54e841fa4f732bbc6aa3b Mon Sep 17 00:00:00 2001 From: bangerth Date: Thu, 23 Oct 2008 03:06:09 +0000 Subject: [PATCH] The template functions that copied a deal.II vector to a Trilinos vector were there but not instantiated. Rewrite this to move the function into the base class and instantiate the template. git-svn-id: https://svn.dealii.org/trunk@17309 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/trilinos_vector.h | 85 +++++++++++-------- .../lac/include/lac/trilinos_vector_base.h | 21 +++++ deal.II/lac/source/trilinos_vector.cc | 54 +----------- deal.II/lac/source/trilinos_vector_base.cc | 39 +++++++++ .../lac/source/trilinos_vector_base.inst.in | 20 +++++ 5 files changed, 131 insertions(+), 88 deletions(-) create mode 100644 deal.II/lac/source/trilinos_vector_base.inst.in diff --git a/deal.II/lac/include/lac/trilinos_vector.h b/deal.II/lac/include/lac/trilinos_vector.h index 1386d52fa0..12308c0e09 100755 --- a/deal.II/lac/include/lac/trilinos_vector.h +++ b/deal.II/lac/include/lac/trilinos_vector.h @@ -326,16 +326,10 @@ namespace TrilinosWrappers * change the map, use the * reinit(const Epetra_Map * &input_map) function. - * - * Since Trilinos only works on - * doubles, this function is - * limited to accept only one - * possible number type in the - * deal.II vector. */ template Vector & - operator = (const ::dealii::Vector &v); + operator = (const ::dealii::Vector &v); /** * This reinit function is @@ -414,7 +408,7 @@ namespace TrilinosWrappers { u.swap (v); } - + #ifndef DOXYGEN @@ -453,6 +447,16 @@ namespace TrilinosWrappers return *this; } + + template + Vector & + Vector::operator = (const ::dealii::Vector &v) + { + VectorBase::operator = (v); + return *this; + } + + #endif } /* end of namespace MPI */ @@ -594,8 +598,11 @@ namespace TrilinosWrappers operator = (const Vector &V); private: + /** + * A map indicating the size of the + * vector. + */ Epetra_LocalMap map; - }; @@ -612,46 +619,54 @@ namespace TrilinosWrappers * @relates TrilinosWrappers::Vector * @author Martin Kronbichler, Wolfgang Bangerth, 2008 */ - inline - void swap (Vector &u, Vector &v) - { - u.swap (v); - } + inline + void swap (Vector &u, Vector &v) + { + u.swap (v); + } #ifndef DOXYGEN - template - Vector::Vector (const dealii::Vector &v) - : + template + Vector::Vector (const dealii::Vector &v) + : #ifdef DEAL_II_COMPILER_SUPPORTS_MPI - map (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD)) + map (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD)) #else - map (v.size(), 0, Epetra_SerialComm()) + map (v.size(), 0, Epetra_SerialComm()) #endif - { - vector = std::auto_ptr (new Epetra_FEVector(map, false)); + { + vector = std::auto_ptr (new Epetra_FEVector(map, false)); - std::vector indices (v.size()); - for (unsigned int i=0; i indices (v.size()); + for (unsigned int i=0; iReplaceGlobalValues(v.size(), 0, v.begin(), - &indices[0]); - AssertThrow (ierr == 0, ExcTrilinosError()); - } + const int ierr = vector->ReplaceGlobalValues(v.size(), 0, v.begin(), + &indices[0]); + AssertThrow (ierr == 0, ExcTrilinosError()); + } - inline - Vector & - Vector::operator = (const TrilinosScalar s) - { - VectorBase::operator = (s); + inline + Vector & + Vector::operator = (const TrilinosScalar s) + { + VectorBase::operator = (s); - return *this; - } + return *this; + } + template + Vector & + Vector::operator = (const ::dealii::Vector &v) + { + VectorBase::operator = (v); + return *this; + } + #endif diff --git a/deal.II/lac/include/lac/trilinos_vector_base.h b/deal.II/lac/include/lac/trilinos_vector_base.h index 7bffc8adb8..0448e3c63d 100644 --- a/deal.II/lac/include/lac/trilinos_vector_base.h +++ b/deal.II/lac/include/lac/trilinos_vector_base.h @@ -364,6 +364,27 @@ namespace TrilinosWrappers VectorBase & operator = (const TrilinosScalar s); + /** + * Another copy function. This + * one takes a deal.II vector and + * copies it into a + * TrilinosWrapper vector. Note + * that since we do not provide + * any Epetra_map that tells + * about the partitioning of the + * vector among the MPI + * processes, the size of the + * TrilinosWrapper vector has to + * be the same as the size of the + * input vector. In order to + * change the map, use the + * reinit(const Epetra_Map + * &input_map) function. + */ + template + VectorBase & + operator = (const ::dealii::Vector &v); + /** * Test for equality. This * function assumes that the diff --git a/deal.II/lac/source/trilinos_vector.cc b/deal.II/lac/source/trilinos_vector.cc index caa5d8d56f..24eed161be 100755 --- a/deal.II/lac/source/trilinos_vector.cc +++ b/deal.II/lac/source/trilinos_vector.cc @@ -191,35 +191,6 @@ namespace TrilinosWrappers - template - Vector & - Vector::operator = (const ::dealii::Vector &v) - { - Assert (size() == v.size(), - ExcDimensionMismatch(size(), v.size())); - - vector = std::auto_ptr (new Epetra_FEVector(map)); - - const int min_my_id = map.MinMyGID(); - const unsigned int size = map.NumMyElements(); - - Assert (map.MaxLID() == size-1, - ExcDimensionMismatch(map.MaxLID(), size-1)); - - std::vector indices (size); - for (unsigned int i=0; iReplaceGlobalValues(size, 0, v.begin()+min_my_id, - &indices[0]); - AssertThrow (ierr == 0, ExcTrilinosError()); - - return *this; - } - - - void Vector::do_data_exchange (const TrilinosWrappers::SparseMatrix &m, const Vector &v) @@ -424,30 +395,7 @@ namespace TrilinosWrappers return *this; } - - - - template - Vector & - Vector::operator = (const ::dealii::Vector &v) - { - if (size() != v.size()) - { - map = LocalMap (v.size(), 0, vector->Comm()); - vector = std::auto_ptr (new Epetra_FEVector(map)); - } - - std::vector indices (v.size()); - for (unsigned int i=0; iReplaceGlobalValues(v.size(), 0, v.begin(), - &indices[0]); - AssertThrow (ierr == 0, ExcTrilinosError()); - - return *this; - } - + } DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/lac/source/trilinos_vector_base.cc b/deal.II/lac/source/trilinos_vector_base.cc index 2522478eab..7d74519947 100644 --- a/deal.II/lac/source/trilinos_vector_base.cc +++ b/deal.II/lac/source/trilinos_vector_base.cc @@ -146,6 +146,40 @@ namespace TrilinosWrappers } + template + VectorBase & + VectorBase::operator = (const ::dealii::Vector &v) + { + Assert (size() == v.size(), + ExcDimensionMismatch(size(), v.size())); + + // this is probably not very efficient + // but works. in particular, we could do + // better if we know that + // number==TrilinosScalar because then we + // could elide the copying of elements + // + // let's hope this isn't a + // particularly frequent operation + std::pair + local_range = this->local_range (); + std::vector indices (local_range.second - + local_range.first); + std::vector values (local_range.second - + local_range.first); + + for (unsigned int i=0; i &v); + } -- 2.39.5