From c32b6119724d58fc2df50c5ba8fadbf9cdbf18b1 Mon Sep 17 00:00:00 2001 From: kronbichler Date: Mon, 8 Sep 2008 06:32:32 +0000 Subject: [PATCH] Added a copy function from (parallel) Trilinos vectors to (serial) deal.II vectors. git-svn-id: https://svn.dealii.org/trunk@16762 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/vector.h | 27 +++++++++++++++++++ deal.II/lac/include/lac/vector.templates.h | 30 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/deal.II/lac/include/lac/vector.h b/deal.II/lac/include/lac/vector.h index 6cf1e5281b..b0f670401a 100644 --- a/deal.II/lac/include/lac/vector.h +++ b/deal.II/lac/include/lac/vector.h @@ -34,6 +34,13 @@ namespace PETScWrappers } #endif +#ifdef DEAL_II_USE_TRILINOS +namespace TrilinosWrappers +{ + class Vector; +} +#endif + template class LAPACKFullMatrix; template 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 diff --git a/deal.II/lac/include/lac/vector.templates.h b/deal.II/lac/include/lac/vector.templates.h index 5fa9e5b5e8..fd38939bd3 100644 --- a/deal.II/lac/include/lac/vector.templates.h +++ b/deal.II/lac/include/lac/vector.templates.h @@ -24,6 +24,10 @@ # include #endif +#ifdef DEAL_II_USE_TRILINOS +# include +#endif + #include #include #include @@ -165,6 +169,32 @@ Vector::Vector (const PETScWrappers::MPI::Vector &v) #endif +#ifdef DEAL_II_USE_TRILINOS + +template +Vector::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 template -- 2.39.5