From: heister Date: Mon, 5 Aug 2013 15:29:22 +0000 (+0000) Subject: fix assignment and reinit of PETScWrappers::MPI::Vector X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36cf271c71e7b8fba0445fd566a0b5cda8d0a6a6;p=dealii-svn.git fix assignment and reinit of PETScWrappers::MPI::Vector git-svn-id: https://svn.dealii.org/trunk@30221 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index b411a0066f..be39ececbd 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -44,6 +44,12 @@ inconvenience this causes.

Specific improvements

    +
  1. + Fixed: various fixes with assignment and reinit of PETScWrappers::MPI::Vector. +
    + (Timo Heister, 2013/08/05) +
  2. +
  3. Fixed: An assertion wrongly triggered in DoFTools::make_hanging_node_constraints when used with a particular combination of FESystem elements containing FE_Nothing. This is now fixed. diff --git a/deal.II/include/deal.II/lac/petsc_parallel_vector.h b/deal.II/include/deal.II/lac/petsc_parallel_vector.h index 95cdddc214..0c0cf8ae63 100644 --- a/deal.II/include/deal.II/lac/petsc_parallel_vector.h +++ b/deal.II/include/deal.II/lac/petsc_parallel_vector.h @@ -588,10 +588,30 @@ namespace PETScWrappers Vector & Vector::operator = (const Vector &v) { + if (v.size()==0) + { + // this happens if v has not been initialized to something useful: + // Vector x,v;x=v; + // we skip the code below and create a simple serial vector of + // length 0 + const int n = 0; + const int ierr + = VecCreateSeq (PETSC_COMM_SELF, n, &vector); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + ghosted = false; + ghost_indices.clear(); + return *this; + } + // if the vectors have different sizes, // then first resize the present one if (size() != v.size()) - reinit (v.communicator, v.size(), v.local_size(), true); + { + if (v.has_ghost_elements()) + reinit( v.locally_owned_elements(), v.ghost_indices, v.communicator); + else + reinit (v.communicator, v.size(), v.local_size(), true); + } const int ierr = VecCopy (v.vector, vector); AssertThrow (ierr == 0, ExcPETScError(ierr)); diff --git a/deal.II/source/lac/petsc_parallel_vector.cc b/deal.II/source/lac/petsc_parallel_vector.cc index 7c4cc997ee..3b06dbb0c8 100644 --- a/deal.II/source/lac/petsc_parallel_vector.cc +++ b/deal.II/source/lac/petsc_parallel_vector.cc @@ -39,6 +39,7 @@ namespace PETScWrappers const int ierr = VecCreateSeq (PETSC_COMM_SELF, n, &vector); AssertThrow (ierr == 0, ExcPETScError(ierr)); + ghosted = false; }