From: heister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Date: Tue, 13 Aug 2013 19:58:15 +0000 (+0000)
Subject: PETSc/Trilinos BlockVectors now only allow assignment if destination is empty or... 
X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=458988d2c002a2830c757163ab2307d895158d30;p=dealii-svn.git

PETSc/Trilinos BlockVectors now only allow assignment if destination is empty or had the same number of blocks

git-svn-id: https://svn.dealii.org/trunk@30307 0785d39b-7218-0410-832d-ea1e28bc413d
---

diff --git a/deal.II/include/deal.II/lac/petsc_parallel_block_vector.h b/deal.II/include/deal.II/lac/petsc_parallel_block_vector.h
index f7e5a4f1db..f55e61d5cc 100644
--- a/deal.II/include/deal.II/lac/petsc_parallel_block_vector.h
+++ b/deal.II/include/deal.II/lac/petsc_parallel_block_vector.h
@@ -441,17 +441,25 @@ namespace PETScWrappers
       return *this;
     }
 
-
-
     inline
     BlockVector &
     BlockVector::operator = (const BlockVector &v)
     {
-      BaseClass::operator = (v);
-      return *this;
-    }
+      // we only allow assignment to vectors with the same number of blocks
+      // or to an empty BlockVector
+      Assert (n_blocks() == 0 || n_blocks() == v.n_blocks(),
+          ExcDimensionMismatch(n_blocks(), v.n_blocks()));
 
+      if (this->n_blocks() != v.n_blocks())
+        reinit(v.n_blocks());
 
+      for (size_type i=0; i<this->n_blocks(); ++i)
+        this->components[i] = v.block(i);
+
+      collect_sizes();
+
+      return *this;
+    }
 
     inline
     BlockVector::~BlockVector ()
diff --git a/deal.II/source/lac/trilinos_block_vector.cc b/deal.II/source/lac/trilinos_block_vector.cc
index b09660c236..7344ec1199 100644
--- a/deal.II/source/lac/trilinos_block_vector.cc
+++ b/deal.II/source/lac/trilinos_block_vector.cc
@@ -59,6 +59,11 @@ namespace TrilinosWrappers
     BlockVector &
     BlockVector::operator = (const BlockVector &v)
     {
+      // we only allow assignment to vectors with the same number of blocks
+      // or to an empty BlockVector
+      Assert (n_blocks() == 0 || n_blocks() == v.n_blocks(),
+                    ExcDimensionMismatch(n_blocks(), v.n_blocks()));
+
       if (this->n_blocks() != v.n_blocks())
         reinit(v.n_blocks());