]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Do resize left hand side operand in BlockVector::operator=(BlockVector).
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 28 Oct 2008 21:56:12 +0000 (21:56 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 28 Oct 2008 21:56:12 +0000 (21:56 +0000)
git-svn-id: https://svn.dealii.org/trunk@17380 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/lac/include/lac/block_vector.h
tests/lac/block_vector_copy.cc [new file with mode: 0644]
tests/lac/block_vector_copy/cmp/generic [new file with mode: 0644]

index 353ff07428f160353f45a6c6f27ccd2a242e88d8..cf68f7ea23ba6d008ac9e39b56658a20ae7f2079 100644 (file)
@@ -299,6 +299,15 @@ inconvenience this causes.
 <h3>lac</h3>
 
 <ol>
+  <li>
+  <p>
+  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.
+  <br>
+  (Christian Cornelssen, WB 2008/10/28)
+  </p>
+
   <li>
   <p>
   Changed: The SparseDirectUMFPACK class now calls the umfpack_dl_* routines 
index 345f555c4b8f1a282385082707cb31ab23b88683..77bd88e14d3d8af49b9c2a05b76b4e734694eb32 100644 (file)
@@ -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<Vector<Number> >
 
                                     /**
                                      * 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 <class Number2>
     BlockVector &
@@ -471,6 +473,7 @@ inline
 BlockVector<Number> &
 BlockVector<Number>::operator = (const BlockVector &v)
 {
+  reinit (v, true);
   BaseClass::operator = (v);
   return *this;
 }
@@ -494,6 +497,7 @@ inline
 BlockVector<Number> &
 BlockVector<Number>::operator = (const BlockVector<Number2> &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 (file)
index 0000000..617e616
--- /dev/null
@@ -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 <base/logstream.h>
+#include <lac/block_vector.h>
+#include <fstream>
+#include <iomanip>
+#include <vector>
+#include <list>
+
+void test ()
+{
+  std::vector<double>          v(9);
+  for (unsigned int i = 0; i < v.size(); ++i)
+    v[i] = double(i+1);
+
+  std::vector<unsigned int>    partition(3);
+  for (unsigned int i = 0; i < partition.size(); ++i)
+    partition[i] = 3;
+
+  dealii::BlockVector<double>  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<double>  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<char> *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 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.