From 83149187767edbdd7e004992be995e301bceda4f Mon Sep 17 00:00:00 2001 From: kronbichler Date: Fri, 31 Jan 2014 19:03:37 +0000 Subject: [PATCH] Add similar interface for copying from a Trilinos MPI vector as for Petsc. git-svn-id: https://svn.dealii.org/trunk@32358 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 5 +- .../deal.II/lac/parallel_block_vector.h | 64 ++++++++++++++++++- deal.II/include/deal.II/lac/parallel_vector.h | 29 ++++++++- .../deal.II/lac/parallel_vector.templates.h | 34 ++++++++-- 4 files changed, 122 insertions(+), 10 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 7e14d6133b..f935735aa8 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -103,9 +103,10 @@ inconvenience this causes.
  1. New: There is now a method to copy the content from a - PETScWrappers::MPI::Vector to deal.II's parallel distributed vector. + PETScWrappers::MPI::Vector and TrilinosWrappers::MPI::Vector to + deal.II's parallel distributed vector.
    - (Ben Thompson, 2014/01/31) + (Ben Thompson, Martin Kronbichler, 2014/01/31)
  2. Fixed: The SolutionTransfer class had all sorts of problems when used with hp::DoFHandler that made its results at least questionable. diff --git a/deal.II/include/deal.II/lac/parallel_block_vector.h b/deal.II/include/deal.II/lac/parallel_block_vector.h index 7ffd04094b..d7a68d4c3b 100644 --- a/deal.II/include/deal.II/lac/parallel_block_vector.h +++ b/deal.II/include/deal.II/lac/parallel_block_vector.h @@ -24,13 +24,16 @@ #include #include +#include +#include + + #include #include DEAL_II_NAMESPACE_OPEN - namespace parallel { namespace distributed @@ -171,6 +174,31 @@ namespace parallel BlockVector & operator= (const Vector &V); +#ifdef DEAL_II_WITH_PETSC + /** + * Copy the content of a PETSc vector into the calling vector. This + * function assumes that the vectors layouts have already been + * initialized to match. + * + * This operator is only available if deal.II was configured with PETSc. + */ + BlockVector & + operator = (const PETScWrappers::MPI::BlockVector &petsc_vec); +#endif + +#ifdef DEAL_II_WITH_TRILINOS + /** + * Copy the content of a Trilinos vector into the calling vector. This + * function assumes that the vectors layouts have already been + * initialized to match. + * + * This operator is only available if deal.II was configured with + * Trilinos. + */ + BlockVector & + operator = (const TrilinosWrappers::MPI::BlockVector &trilinos_vec); +#endif + /** * Reinitialize the BlockVector to contain num_blocks blocks of * size block_size each. @@ -594,6 +622,40 @@ namespace parallel +#ifdef DEAL_II_WITH_PETSC + + template + BlockVector & + BlockVector::operator = (const PETScWrappers::MPI::BlockVector &petsc_vec) + { + AssertDimension(this->n_blocks(), petsc_vec.n_blocks()); + for (unsigned int i=0; in_blocks(); ++i) + this->block(i) = petsc_vec.block(i); + + return *this; + } + +#endif + + + +#ifdef DEAL_II_WITH_TRILINOS + + template + BlockVector & + BlockVector::operator = (const TrilinosWrappers::MPI::BlockVector &trilinos_vec) + { + AssertDimension(this->n_blocks(), trilinos_vec.n_blocks()); + for (unsigned int i=0; in_blocks(); ++i) + this->block(i) = trilinos_vec.block(i); + + return *this; + } + +#endif + + + template inline void diff --git a/deal.II/include/deal.II/lac/parallel_vector.h b/deal.II/include/deal.II/lac/parallel_vector.h index 9029db91c5..126737eba7 100644 --- a/deal.II/include/deal.II/lac/parallel_vector.h +++ b/deal.II/include/deal.II/lac/parallel_vector.h @@ -43,6 +43,16 @@ namespace PETScWrappers } #endif +#ifdef DEAL_II_WITH_TRILINOS +namespace TrilinosWrappers +{ + namespace MPI + { + class Vector; + } +} +#endif + namespace parallel { @@ -288,9 +298,9 @@ namespace parallel #ifdef DEAL_II_WITH_PETSC /** - * Copy the content of a PETSc vector into a vector. This function - * assumes that the vectors layouts have already been initialized to - * match. + * Copy the content of a PETSc vector into the calling vector. This + * function assumes that the vectors layouts have already been + * initialized to match. * * This operator is only available if deal.II was configured with PETSc. */ @@ -298,6 +308,19 @@ namespace parallel operator = (const PETScWrappers::MPI::Vector &petsc_vec); #endif +#ifdef DEAL_II_WITH_TRILINOS + /** + * Copy the content of a Trilinos vector into the calling vector. This + * function assumes that the vectors layouts have already been + * initialized to match. + * + * This operator is only available if deal.II was configured with + * Trilinos. + */ + Vector & + operator = (const TrilinosWrappers::MPI::Vector &trilinos_vec); +#endif + /** * This method copies the local range from another vector with the same * local range, but possibly different layout of ghost indices. diff --git a/deal.II/include/deal.II/lac/parallel_vector.templates.h b/deal.II/include/deal.II/lac/parallel_vector.templates.h index fbce1fb85d..1b60485822 100644 --- a/deal.II/include/deal.II/lac/parallel_vector.templates.h +++ b/deal.II/include/deal.II/lac/parallel_vector.templates.h @@ -20,8 +20,10 @@ #include #include +#include #include +#include DEAL_II_NAMESPACE_OPEN @@ -209,7 +211,6 @@ namespace parallel #ifdef DEAL_II_WITH_PETSC template - inline Vector & Vector::operator = (const PETScWrappers::MPI::Vector &petsc_vec) { @@ -229,9 +230,34 @@ namespace parallel AssertThrow (ierr == 0, ExcPETScError(ierr)); // spread ghost values between processes? - bool must_update_ghost_values = vector_is_ghosted || - petsc_vec.has_ghost_elements(); - if (must_update_ghost_values) + if (vector_is_ghosted || petsc_vec.has_ghost_elements()) + update_ghost_values(); + + // return a pointer to this object per normal c++ operator overloading + // semantics + return *this; + } + +#endif + + + +#ifdef DEAL_II_WITH_TRILINOS + + template + Vector & + Vector::operator = (const TrilinosWrappers::MPI::Vector &trilinos_vec) + { + Assert(trilinos_vec.locally_owned_elements() == locally_owned_elements(), + StandardExceptions::ExcInvalidState()); + + // create on trilinos data + const VectorView in_view (local_size(), trilinos_vec.begin()); + static_cast<::dealii::Vector&>(vector_view) = + static_cast&>(in_view); + + // spread ghost values between processes? + if (vector_is_ghosted || trilinos_vec.has_ghost_elements()) update_ghost_values(); // return a pointer to this object per normal c++ operator overloading -- 2.39.5