From: bangerth Date: Tue, 28 Oct 2008 21:56:12 +0000 (+0000) Subject: Do resize left hand side operand in BlockVector::operator=(BlockVector). X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f75f6bab0f0adeffd1b440f0a82db40b97d7999;p=dealii-svn.git Do resize left hand side operand in BlockVector::operator=(BlockVector). git-svn-id: https://svn.dealii.org/trunk@17380 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 353ff07428..cf68f7ea23 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -299,6 +299,15 @@ inconvenience this causes.

lac

    +
  1. +

    + Fixed: Whereas the Vector class copy operator resized the left hand side + operand whenever necessary, the corresponding operator of the BlockVector + class did not. This is now fixed. +
    + (Christian Cornelssen, WB 2008/10/28) +

    +
  2. Changed: The SparseDirectUMFPACK class now calls the umfpack_dl_* routines diff --git a/deal.II/lac/include/lac/block_vector.h b/deal.II/lac/include/lac/block_vector.h index 345f555c4b..77bd88e14d 100644 --- a/deal.II/lac/include/lac/block_vector.h +++ b/deal.II/lac/include/lac/block_vector.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 by the deal.II authors +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -198,14 +198,16 @@ class BlockVector : public BlockVectorBase > /** * Copy operator for arguments of the - * same type. + * same type. Resize the + * present vector if necessary. */ BlockVector & operator= (const BlockVector &V); /** * Copy operator for template arguments - * of different types. + * of different types. Resize the + * present vector if necessary. */ template BlockVector & @@ -471,6 +473,7 @@ inline BlockVector & BlockVector::operator = (const BlockVector &v) { + reinit (v, true); BaseClass::operator = (v); return *this; } @@ -494,6 +497,7 @@ inline BlockVector & BlockVector::operator = (const BlockVector &v) { + reinit (v, true); BaseClass::operator = (v); return *this; } diff --git a/tests/lac/block_vector_copy.cc b/tests/lac/block_vector_copy.cc new file mode 100644 index 0000000000..617e616018 --- /dev/null +++ b/tests/lac/block_vector_copy.cc @@ -0,0 +1,110 @@ +//-------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2008 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//-------------------------------------------------------------------- + + +#include "../tests.h" +#include +#include +#include +#include +#include +#include + +void test () +{ + std::vector v(9); + for (unsigned int i = 0; i < v.size(); ++i) + v[i] = double(i+1); + + std::vector partition(3); + for (unsigned int i = 0; i < partition.size(); ++i) + partition[i] = 3; + + dealii::BlockVector b(partition); + assert (b.n_blocks() == partition.size()); + + unsigned int size = 0; + for (unsigned int i = 0; i < b.n_blocks(); ++i) + { + assert (b.block(i).size() == partition[i]); + size += b.block(i).size(); + } + assert (b.size() == size); + + for (unsigned int i = 0; i < b.size(); ++i) + { + b(i) = v[i]; + assert (b(i) == v[i]); + } + + dealii::BlockVector c; + c = b; + assert (c == b); + assert (c.n_blocks() == b.n_blocks()); + + deallog << "OK" << std::endl; +} + + + + +int main () +{ + std::ofstream logfile("block_vector_copy/output"); + deallog << std::fixed; + deallog << std::setprecision(3); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + // do the same weird stuff as in + // tests/base/reference.cc +#if __GNUC__ != 2 + std::basic_streambuf *old_cerr_buf = std::cerr.rdbuf(); +#else + streambuf *old_cerr_buf = std::cerr.rdbuf(); +#endif + std::cerr.rdbuf(logfile.rdbuf()); + + try + { + test (); + } + catch (std::exception &e) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << e.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + // abort + return 0; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + // abort + return 0; + }; + + std::cerr.rdbuf(old_cerr_buf); +} + diff --git a/tests/lac/block_vector_copy/cmp/generic b/tests/lac/block_vector_copy/cmp/generic new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/lac/block_vector_copy/cmp/generic @@ -0,0 +1,2 @@ + +DEAL::OK