From: Timo Heister <timo.heister@gmail.com>
Date: Mon, 5 Aug 2013 15:29:22 +0000 (+0000)
Subject: fix assignment and reinit of PETScWrappers::MPI::Vector
X-Git-Tag: v8.1.0~1149
X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d0fe0db725b25e8207a8c70c68848856fa19b9a;p=dealii.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.
 <h3>Specific improvements</h3>
 
 <ol>
+  <li>
+  Fixed: various fixes with assignment and reinit of PETScWrappers::MPI::Vector.
+  <br>
+  (Timo Heister, 2013/08/05)
+  </li>
+
   <li>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;
     }