From dc7e4e3e2508e3c66bec565a5391f01753938516 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Tue, 16 Jun 2015 23:01:54 +0200 Subject: [PATCH] extend operator= for PETSc MPI vector to handle complex-valued case --- .../deal.II/lac/parallel_vector.templates.h | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/include/deal.II/lac/parallel_vector.templates.h b/include/deal.II/lac/parallel_vector.templates.h index 5e7ab011a9..0230a8e926 100644 --- a/include/deal.II/lac/parallel_vector.templates.h +++ b/include/deal.II/lac/parallel_vector.templates.h @@ -210,6 +210,33 @@ namespace parallel #ifdef DEAL_II_WITH_PETSC + namespace internal + { + template + void copy_petsc_vector (const PETSC_Number *petsc_start_ptr, + const PETSC_Number *petsc_end_ptr, + Number *ptr) + { + std::copy(petsc_start_ptr, petsc_end_ptr, ptr); + } + + template + void copy_petsc_vector (const std::complex *petsc_start_ptr, + const std::complex *petsc_end_ptr, + std::complex *ptr) + { + std::copy(petsc_start_ptr, petsc_end_ptr, ptr); + } + + template + void copy_petsc_vector (const std::complex *petsc_start_ptr, + const std::complex *petsc_end_ptr, + Number *ptr) + { + AssertThrow(false, ExcMessage("Tried to copy complex -> real")); + } + } + template Vector & Vector::operator = (const PETScWrappers::MPI::Vector &petsc_vec) @@ -223,7 +250,7 @@ namespace parallel AssertThrow (ierr == 0, ExcPETScError(ierr)); const size_type vec_size = local_size(); - std::copy (start_ptr, start_ptr + vec_size, begin()); + internal::copy_petsc_vector (start_ptr, start_ptr + vec_size, begin()); // restore the representation of the vector ierr = VecRestoreArray (static_cast(petsc_vec), &start_ptr); -- 2.39.5