]> https://gitweb.dealii.org/ - dealii.git/commitdiff
minor fix of ConsecutiveControl 4870/head
authorDenis Davydov <davydden@gmail.com>
Wed, 16 Aug 2017 11:16:03 +0000 (13:16 +0200)
committerDenis Davydov <davydden@gmail.com>
Wed, 16 Aug 2017 13:47:18 +0000 (15:47 +0200)
doc/news/changes/minor/20170816DenisDavydov [new file with mode: 0644]
source/lac/solver_control.cc
tests/lac/solver_control_06.cc [new file with mode: 0644]
tests/lac/solver_control_06.expect=run.debug.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20170816DenisDavydov b/doc/news/changes/minor/20170816DenisDavydov
new file mode 100644 (file)
index 0000000..58422ea
--- /dev/null
@@ -0,0 +1,4 @@
+Fixed: ConsecutiveControl now asserts that check() is being called for zeroth
+iteration.
+<br>
+(Denis Davydov, 2017/08/16)
index d20d5fe552c3bc45ec8681779435596039c73494..b01c280ef680c846142c0bf0ce686427bf931643 100644 (file)
@@ -36,7 +36,7 @@ SolverControl::SolverControl (const unsigned int maxiter,
   lcheck(failure),
   initial_val(numbers::signaling_nan<double>()),
   lvalue(numbers::signaling_nan<double>()),
-  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 (file)
index 0000000..62b0b44
--- /dev/null
@@ -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 <deal.II/base/utilities.h>
+#include <iostream>
+#include <deal.II/lac/solver_control.h>
+
+
+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 (file)
index 0000000..84e46e5
--- /dev/null
@@ -0,0 +1,2 @@
+
+content irrelevant

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.