]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Fixed: Vector::operator/= should have checked that the argument is non-zero, but...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 4 Nov 2007 05:19:32 +0000 (05:19 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 4 Nov 2007 05:19:32 +0000 (05:19 +0000)
git-svn-id: https://svn.dealii.org/trunk@15436 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 67ddb23054b06364e147af405d7d3edd1f7898ae..2841e6f9133a5b979993379fb97eef3205cd2c61 100644 (file)
@@ -158,6 +158,14 @@ inconvenience this causes.
 
 <ol>
 
+<li> Fixed: Vector::operator/= can't work when the scaling factor is zero,
+but it happened to check whether the factor was positive. That's of course
+bogus, the check should have been whether it is non-zero. This has now been
+fixed.
+<br>
+(WB 2007/11/03)
+</li>
+
 <li> New: A class ScaledMatrix was introduced which combines the vector operations of
 an underlying matrix with a scaling.
 <br>
index fe2eeb0e574ff8d5f0448ad1ec453caf6a7ca1d8..40014ecb151d9946a28b2f874e65eb8fe3a7d67f 100644 (file)
@@ -956,7 +956,7 @@ Vector<Number>::operator /= (const Number factor)
 {
   Assert (numbers::is_finite(factor), 
           ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
-  Assert (factor > 0., ExcZero() );
+  Assert (factor != 0., ExcZero() );
 
   *this *= (1./factor);
   return *this;
diff --git a/tests/bits/vector_21_negative.cc b/tests/bits/vector_21_negative.cc
new file mode 100644 (file)
index 0000000..9b56ea2
--- /dev/null
@@ -0,0 +1,90 @@
+//----------------------------  vector_21_negative.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2004, 2005, 2007 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.
+//
+//----------------------------  vector_21_negative.cc  ---------------------------
+
+
+// check Vector<double>::operator /=. the original check was that the factor
+// by which we divide must be positive. this is of course nonsensical, it
+// should have been that the factor is != 0...
+
+#include "../tests.h"
+#include <lac/vector.h>    
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (Vector<double> &v)
+{
+                                   // set only certain elements of the
+                                   // vector. have a bit pattern of where we
+                                   // actually wrote elements to
+  std::vector<bool> pattern (v.size(), false);
+  for (unsigned int i=0; i<v.size(); i+=1+i)
+    {
+      v(i) = i;
+      pattern[i] = true;
+    }
+  v.compress ();
+
+                                   // multiply v with 3/4
+  v /= -4./3.;
+
+                                   // check that the entries are ok
+  for (unsigned int i=0; i<v.size(); ++i)
+    Assert (((pattern[i] == true) && (v(i)-(-3.*i/4.) == 0))
+           ||
+           ((pattern[i] == false) && (v(i) == 0)),
+           ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main () 
+{
+  std::ofstream logfile("vector_21_negative/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  try
+    {
+      Vector<double> v (100);
+      test (v);
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+               << exc.what() << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      
+      return 1;
+    }
+  catch (...) 
+    {
+      std::cerr << std::endl << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+               << "Aborting!" << std::endl
+               << "----------------------------------------------------"
+               << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/bits/vector_21_negative/cmp/generic b/tests/bits/vector_21_negative/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.