From: Matthias Maier Date: Mon, 4 May 2015 07:36:52 +0000 (+0200) Subject: Bugfix: Implement BlockVector::swap for different block sizes X-Git-Tag: v8.3.0-rc1~202^2~8 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba49b5b0a162bfdfc65e824f60cfdf2c24fd6e9d;p=dealii.git Bugfix: Implement BlockVector::swap for different block sizes --- diff --git a/include/deal.II/lac/block_vector.h b/include/deal.II/lac/block_vector.h index 6b1ac989cf..95e7bbf2d3 100644 --- a/include/deal.II/lac/block_vector.h +++ b/include/deal.II/lac/block_vector.h @@ -314,10 +314,6 @@ public: * only swaps the pointers to the data of the two vectors and therefore does * not need to allocate temporary storage and move data around. * - * Limitation: right now this function only works if both vectors have the - * same number of blocks. If needed, the numbers of blocks should be - * exchanged, too. - * * This function is analog to the the swap() function of all C++ standard * containers. Also, there is a global function swap(u,v) that simply calls * u.swap(v), again in analogy to standard functions. @@ -433,6 +429,7 @@ BlockVector & BlockVector::operator= (BlockVector &&v) { swap(v); + // be nice and reset v to zero v.reinit(0, 0, false); diff --git a/include/deal.II/lac/block_vector.templates.h b/include/deal.II/lac/block_vector.templates.h index abdb94e7e0..d873067e55 100644 --- a/include/deal.II/lac/block_vector.templates.h +++ b/include/deal.II/lac/block_vector.templates.h @@ -173,11 +173,8 @@ BlockVector::operator= (const TrilinosWrappers::BlockVector &v) template void BlockVector::swap (BlockVector &v) { - Assert (this->n_blocks() == v.n_blocks(), - ExcDimensionMismatch(this->n_blocks(), v.n_blocks())); + std::swap(this->components, v.components); - for (size_type i=0; in_blocks(); ++i) - dealii::swap (this->components[i], v.components[i]); dealii::swap (this->block_indices, v.block_indices); }