From: hartmann Date: Mon, 26 Jun 2000 15:34:10 +0000 (+0000) Subject: SolverControl returns failure also if the solver diverges. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=193263eb7ea85fa5a4fdc37dcfa46a690af2c781;p=dealii-svn.git SolverControl returns failure also if the solver diverges. git-svn-id: https://svn.dealii.org/trunk@3078 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/solver_control.h b/deal.II/lac/include/lac/solver_control.h index 5186620fcd..f2d9f25b0b 100644 --- a/deal.II/lac/include/lac/solver_control.h +++ b/deal.II/lac/include/lac/solver_control.h @@ -156,6 +156,24 @@ class SolverControl : public Subscriptor * Change maximum number of steps. */ unsigned int set_max_steps (const unsigned int); + + /** + * Enables the failure + * check. Solving is stopped with + * @p{ReturnState} @p{failure} if + * @p{residual>failure_residual} with + * @p{failure_residual:=rel_failure_residual*first_residual}. + */ + void set_failure_criterion (const double rel_failure_residual); + + /** + * Disables failure check and + * resets + * @p{relative_failure_residual} + * and @p{failure_residual} to + * zero. + */ + void clear_failure_criterion (); /** * Tolerance. @@ -194,7 +212,7 @@ class SolverControl : public Subscriptor * Prescribed tolerance to be achieved. */ double tol; - + /** * Last value of the convergence criterion. */ @@ -205,6 +223,33 @@ class SolverControl : public Subscriptor */ unsigned int lstep; + /** + * Is set to @p{true} by + * @p{set_failure_criterion} and + * enables failure checking. + */ + bool check_failure; + + /* + * Stores the + * @p{rel_failure_residual} set by + * @p{set_failure_criterion} + */ + double relative_failure_residual; + + + /** + * @p{failure_residual} equals the + * first residual multiplied by + * @p{relative_crit} set by + * @p{set_failure_criterion} (see there). + * + * Until the first residual is + * known it is 0. + */ + double failure_residual; + + /** * Log convergence history to @p{deallog}. */ @@ -336,6 +381,23 @@ SolverControl::set_max_steps (unsigned int newval) } +inline void +SolverControl::set_failure_criterion (const double rel_failure_residual) +{ + relative_failure_residual=rel_failure_residual; + check_failure=true; +} + + +inline void +SolverControl::clear_failure_criterion () +{ + relative_failure_residual=0; + failure_residual=0; + check_failure=false; +} + + inline double SolverControl::tolerance () const { diff --git a/deal.II/lac/source/solver_control.cc b/deal.II/lac/source/solver_control.cc index 9cb22dfe4f..e13abc3c85 100644 --- a/deal.II/lac/source/solver_control.cc +++ b/deal.II/lac/source/solver_control.cc @@ -16,6 +16,7 @@ #include #include +#include /*----------------------- SolverControl ---------------------------------*/ @@ -29,6 +30,9 @@ SolverControl::SolverControl (const unsigned int maxiter, tol(tolerance), lvalue(1.e300), lstep(0), + check_failure(false), + relative_failure_residual(0), + failure_residual(0), _log_history(_log_history), _log_frequency(1), _log_result(_log_result) @@ -51,10 +55,19 @@ SolverControl::check (const unsigned int step, lstep = step; lvalue = check_value; - if ((step==0) && _log_result) - deallog << "Starting value " << check_value << endl; + if (step==0) + { + if (check_failure) + failure_residual=relative_failure_residual*check_value; + + if (_log_result) + deallog << "Starting value " << check_value << endl; + } - if (step >= maxsteps) + + if ((step >= maxsteps) || + (check_failure && ((check_value > failure_residual) || + isnan(check_value)))) { if (_log_result) deallog << "Failure step " << step @@ -69,6 +82,7 @@ SolverControl::check (const unsigned int step, << " value " << check_value << endl; return success; } + return iterate; }