From: Denis Davydov Date: Wed, 16 Aug 2017 11:16:03 +0000 (+0200) Subject: minor fix of ConsecutiveControl X-Git-Tag: v9.0.0-rc1~1218^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f889751bc99622b5816c0bffffe6c679b30d716;p=dealii.git minor fix of ConsecutiveControl --- diff --git a/doc/news/changes/minor/20170816DenisDavydov b/doc/news/changes/minor/20170816DenisDavydov new file mode 100644 index 0000000000..58422eae1a --- /dev/null +++ b/doc/news/changes/minor/20170816DenisDavydov @@ -0,0 +1,4 @@ +Fixed: ConsecutiveControl now asserts that check() is being called for zeroth +iteration. +
+(Denis Davydov, 2017/08/16) diff --git a/source/lac/solver_control.cc b/source/lac/solver_control.cc index d20d5fe552..b01c280ef6 100644 --- a/source/lac/solver_control.cc +++ b/source/lac/solver_control.cc @@ -36,7 +36,7 @@ SolverControl::SolverControl (const unsigned int maxiter, lcheck(failure), initial_val(numbers::signaling_nan()), lvalue(numbers::signaling_nan()), - lstep(0), + lstep(numbers::invalid_unsigned_int), check_failure(false), relative_failure_residual(0), failure_residual(0), @@ -399,6 +399,14 @@ ConsecutiveControl::check (const unsigned int step, // reset the counter if ConsecutiveControl is being reused if (step==0) n_converged_iterations = 0; + else + { + // check two things: + // (i) steps are ascending without repetitions + // (ii) user started from zero even when solver is being reused. + Assert (step-1 == lstep, + ExcMessage("steps should be ascending integers.")); + } SolverControl::State state = SolverControl::check(step, check_value); // check if we need to override the success: diff --git a/tests/lac/solver_control_06.cc b/tests/lac/solver_control_06.cc new file mode 100644 index 0000000000..62b0b44b3e --- /dev/null +++ b/tests/lac/solver_control_06.cc @@ -0,0 +1,49 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// make sure ConsecutiveControl does not allow its (re)usage when not starting +// from 0-th iteration. This test is expected to run, but throw an error. + +#include "../tests.h" +#include +#include +#include + + +int main(int argc, char **argv) +{ + std::ofstream logfile("output"); + logfile.precision(4); + deallog.attach(logfile); + + { + ConsecutiveControl solver_control(12345, 1.e-3, 3, true, true); + // // n_converged_iterations: + solver_control.check(0,1.e-1); // 0 + solver_control.check(1,1.e-4); // 1 + solver_control.check(2,1.e-5); // 2 + solver_control.check(3,2.e-3); // 0 + solver_control.check(4,5.e-4); // 1 + solver_control.check(5,4.e-4); // 2 + solver_control.check(6,3.e-4); // 3 ==> success + + // reuse + solver_control.check(1,3.e-4); // 1 <----- start from 1st iteration NO-NO-NO + solver_control.check(2,2.e-4); // 2 + solver_control.check(3,1.e-4); // 3 ==> success + + } +} diff --git a/tests/lac/solver_control_06.expect=run.debug.output b/tests/lac/solver_control_06.expect=run.debug.output new file mode 100644 index 0000000000..84e46e5084 --- /dev/null +++ b/tests/lac/solver_control_06.expect=run.debug.output @@ -0,0 +1,2 @@ + +content irrelevant