]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
SolverControl returns failure also if the solver diverges.
authorhartmann <hartmann@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 26 Jun 2000 15:34:10 +0000 (15:34 +0000)
committerhartmann <hartmann@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 26 Jun 2000 15:34:10 +0000 (15:34 +0000)
git-svn-id: https://svn.dealii.org/trunk@3078 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/solver_control.h
deal.II/lac/source/solver_control.cc

index 5186620fcded4b03741e14286f32d3abcf7d72d4..f2d9f25b0ba5b9c621772b60697be2949b89fec0 100644 (file)
@@ -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
 {
index 9cb22dfe4feb2c5340227c4c89a9f514df53bddb..e13abc3c855aaee91097266fb0c8aafa76605b7a 100644 (file)
@@ -16,6 +16,7 @@
 #include <base/parameter_handler.h>
 #include <lac/solver_control.h>
 
+#include <cmath>
 
 /*----------------------- 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;
 }
 

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.