From 319c5b69f0f7dc159731199aedc2d6183164c6cc Mon Sep 17 00:00:00 2001 From: bangerth Date: Sun, 4 Nov 2007 05:19:32 +0000 Subject: [PATCH] Fixed: Vector::operator/= should have checked that the argument is non-zero, but it checks that it is positive. This is of course bogus. git-svn-id: https://svn.dealii.org/trunk@15436 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 8 ++ deal.II/lac/include/lac/vector.h | 2 +- tests/bits/vector_21_negative.cc | 90 +++++++++++++++++++++++ tests/bits/vector_21_negative/cmp/generic | 2 + 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 tests/bits/vector_21_negative.cc create mode 100644 tests/bits/vector_21_negative/cmp/generic diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 67ddb23054..2841e6f913 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -158,6 +158,14 @@ inconvenience this causes.
    +
  1. 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. +
    +(WB 2007/11/03) +
  2. +
  3. New: A class ScaledMatrix was introduced which combines the vector operations of an underlying matrix with a scaling.
    diff --git a/deal.II/lac/include/lac/vector.h b/deal.II/lac/include/lac/vector.h index fe2eeb0e57..40014ecb15 100644 --- a/deal.II/lac/include/lac/vector.h +++ b/deal.II/lac/include/lac/vector.h @@ -956,7 +956,7 @@ Vector::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 index 0000000000..9b56ea2959 --- /dev/null +++ b/tests/bits/vector_21_negative.cc @@ -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::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 +#include +#include +#include + + +void test (Vector &v) +{ + // set only certain elements of the + // vector. have a bit pattern of where we + // actually wrote elements to + std::vector pattern (v.size(), false); + for (unsigned int i=0; i 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 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/bits/vector_21_negative/cmp/generic @@ -0,0 +1,2 @@ + +DEAL::OK -- 2.39.5