]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Change name and style of exception thrown upon failure of linear solvers.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 4 Apr 2001 12:48:02 +0000 (12:48 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 4 Apr 2001 12:48:02 +0000 (12:48 +0000)
git-svn-id: https://svn.dealii.org/trunk@4370 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/eigen.h
deal.II/lac/include/lac/solver.h
deal.II/lac/include/lac/solver_bicgstab.h
deal.II/lac/include/lac/solver_cg.h
deal.II/lac/include/lac/solver_control.h
deal.II/lac/include/lac/solver_gmres.h
deal.II/lac/include/lac/solver_minres.h
deal.II/lac/include/lac/solver_qmrs.h
deal.II/lac/include/lac/solver_richardson.h
deal.II/lac/source/solver_control.cc

index c64c643b8e66eb51e435c24c49ec8279ab65f1e2..c2886da3ba73b2f2e37003ff25120d85d157744f 100644 (file)
@@ -361,10 +361,13 @@ EigenPower<VECTOR>::solve (double       &value,
   memory.free(Vr);
 
   deallog.pop();
-                                  // Output
-  AssertThrow(control().last_check() == SolverControl::success,
-             typename Solver<VECTOR>::ExcNoConvergence(control().last_step(),
-                                                       control().last_value()));
+
+                                  // in case of failure: throw
+                                  // exception
+  if (control().last_check() != SolverControl::success)
+    throw SolverControl::NoConvergence (control().last_step(),
+                                       control().last_value());
+                                  // otherwise exit as normal
 }
 
 //----------------------------------------------------------------------//
@@ -470,10 +473,12 @@ EigenInverse<VECTOR>::solve (double       &value,
   
   deallog.pop();
 
-                                  // Output
-  AssertThrow(control().last_check() == SolverControl::success,
-             typename Solver<VECTOR>::ExcNoConvergence(control().last_step(),
-                                                       control().last_value()));
+                                  // in case of failure: throw
+                                  // exception
+  if (control().last_check() != SolverControl::success)
+    throw SolverControl::NoConvergence (control().last_step(),
+                                       control().last_value());
+                                  // otherwise exit as normal
 }
 
 #endif
index f6e646c5984dbeb56bdd2ff52aaaeedc1a13aad7..f638719d1d3930b0b810f9391448db7db7330942 100644 (file)
@@ -153,11 +153,6 @@ class Solver
                                      * Access to control object.
                                      */
     SolverControl& control() const;
-
-//TODO: [WB] move this class to SolverControl to avoid forcing templatized class qualification when catching such exceptions
-    DeclException2(ExcNoConvergence, int, double,
-                  << "Iteration did not converge after " << arg1
-                  << " steps. Final residual " << arg2);
   
   protected:
 
index 9e6676879c16fcdef21e0fbce13eb2114fc6bf49..9ecaee3433cf051e3b6e4cbe3eb957dd4f0783b5 100644 (file)
@@ -376,9 +376,12 @@ SolverBicgstab<VECTOR>::solve(const MATRIX &A,
   
   deallog.pop();
   
-  AssertThrow(control().last_check() == SolverControl::success,
-             typename Solver<VECTOR>::ExcNoConvergence(control().last_step(),
-                                                       control().last_value()));
+                                  // in case of failure: throw
+                                  // exception
+  if (control().last_check() != SolverControl::success)
+    throw SolverControl::NoConvergence (control().last_step(),
+                                       control().last_value());
+                                  // otherwise exit as normal
 }
 
 
index bf81acefc43972db9fe7ec578932b80bf1fa38dd..c4f4479640a5ac91db4a5d23f16e60a7d8277ae3 100644 (file)
@@ -282,9 +282,12 @@ SolverCG<VECTOR>::solve (const MATRIX &A,
                                   // Output
   deallog.pop();
  
-  AssertThrow(control().last_check() == SolverControl::success,
-             typename Solver<VECTOR>::ExcNoConvergence(control().last_step(),
-                                                       control().last_value()));
+                                  // in case of failure: throw
+                                  // exception
+  if (control().last_check() != SolverControl::success)
+    throw SolverControl::NoConvergence (control().last_step(),
+                                       control().last_value());
+                                  // otherwise exit as normal
 };
 
 
index 839e11e2ff031e6a957080f4e47934893cd89f4b..a57a7103adc8bb9b3d24b8fa3764ca888f18f151 100644 (file)
@@ -63,6 +63,46 @@ class SolverControl : public Subscriptor
     enum State {
       iterate = 0, success, failure
     };
+
+                                    /**
+                                     * Class to be thrown upon
+                                     * failing convergence of an
+                                     * iterative solver, when either
+                                     * the number of iterations
+                                     * exceeds the limit or the
+                                     * residual fails to reach the
+                                     * desired limit, e.g. in the
+                                     * case of a break-down.
+                                     *
+                                     * The residual in the last
+                                     * iteration, as well as the
+                                     * iteration number of the last
+                                     * step are stored in this object
+                                     * and can be recovered upon
+                                     * catching an exception of this
+                                     * class.
+                                     */
+    class NoConvergence : public std::exception 
+    {
+      public:
+                                        /**
+                                         * Constructor.
+                                         */
+       NoConvergence (const unsigned int last_step,
+                      const double       last_residual);
+
+                                        /**
+                                         * Iteration number of the
+                                         * last step.
+                                         */
+       const unsigned int last_step;
+
+                                        /**
+                                         * Residual in the last step.
+                                         */
+       const double       last_residual;
+    };
+    
     
                                     /**
                                      * Constructor. The parameters
index cef56c00665e01addb2550e5a8a7a994bc04bd68..d8f31db828240c105f351f4bf1ed40343d423177 100644 (file)
@@ -398,9 +398,12 @@ unsigned int dim = 0;
 
   deallog.pop();
 
-  AssertThrow(control().last_check() == SolverControl::success,
-             typename Solver<VECTOR>::ExcNoConvergence(control().last_step(),
-                                                       control().last_value()));
+                                  // in case of failure: throw
+                                  // exception
+  if (control().last_check() != SolverControl::success)
+    throw SolverControl::NoConvergence (control().last_step(),
+                                       control().last_value());
+                                  // otherwise exit as normal
 };
 
 
index fa7f86742c70bbe17a9a94435d3734fd3caa1cbf..1103da70d6b14d636aca054fc96129d1151e594b 100644 (file)
@@ -351,9 +351,12 @@ SolverMinRes<VECTOR>::solve (const MATRIX &A,
                                   // Output
   deallog.pop ();
   
-  AssertThrow(control().last_check() == SolverControl::success,
-             typename Solver<VECTOR>::ExcNoConvergence(control().last_step(),
-                                                       control().last_value()));
+                                  // in case of failure: throw
+                                  // exception
+  if (control().last_check() != SolverControl::success)
+    throw SolverControl::NoConvergence (control().last_step(),
+                                       control().last_value());
+                                  // otherwise exit as normal
 };
 
 
index 4aa2aedf9bb44a258041533e2d16804b7edf063d..dac847778b089a05c493307a21a1fbb03cf6c663 100644 (file)
@@ -254,21 +254,22 @@ SolverQMRS<VECTOR>::solve (const MATRIX &A,
     }
   while (state);
     
-  // Deallocate Memory
+                                  // Deallocate Memory
   memory.free(Vv);
   memory.free(Vp);
   memory.free(Vq);
   memory.free(Vt);
   memory.free(Vd);
  
-  // Output
-
+                                  // Output
   deallog.pop();
 
-  AssertThrow(control().last_check() == SolverControl::success,
-             typename Solver<VECTOR>::ExcNoConvergence(control().last_step(),
-                                                       control().last_value()));
+                                  // in case of failure: throw
+                                  // exception
+  if (control().last_check() != SolverControl::success)
+    throw SolverControl::NoConvergence (control().last_step(),
+                                       control().last_value());
+                                  // otherwise exit as normal
 };
 
 
index 103550ec44dc91ee86ab3df0066e576623b6d6a8..71b87816d6dc9aef7fa2e58ac1fe8b01df288606 100644 (file)
@@ -205,10 +205,13 @@ SolverRichardson<VECTOR>::solve (const MATRIX &A,
   memory.free(Vd);
 
   deallog.pop();
-                                  // Output
-  AssertThrow(control().last_check() == SolverControl::success,
-             typename Solver<VECTOR>::ExcNoConvergence(control().last_step(),
-                                                       control().last_value()));
+
+                                  // in case of failure: throw
+                                  // exception
+  if (control().last_check() != SolverControl::success)
+    throw SolverControl::NoConvergence (control().last_step(),
+                                       control().last_value());
+                                  // otherwise exit as normal
 }
 
 
@@ -251,10 +254,12 @@ SolverRichardson<VECTOR>::Tsolve (const MATRIX &A,
   memory.free(Vd);
 
   deallog.pop();
-                                  // Output
-  AssertThrow(control().last_check() == SolverControl::success,
-             typename Solver<VECTOR>::ExcNoConvergence(control().last_step(),
-                                                       control().last_value()));
+                                  // in case of failure: throw
+                                  // exception
+  if (control().last_check() != SolverControl::success)
+    throw SolverControl::NoConvergence (control().last_step(),
+                                       control().last_value());
+                                  // otherwise exit as normal
 }
 
 
index 27f671efb7e02ff84a0dba3d7102a1b3d84337f6..68b801fd3f6f2f76edfc6a4176e2951126af5843 100644 (file)
 /*----------------------- SolverControl ---------------------------------*/
 
 
+SolverControl::NoConvergence::NoConvergence (const unsigned int last_step,
+                                            const double       last_residual)
+               :
+               last_step (last_step),
+               last_residual (last_residual)
+{};
+
+
+
 SolverControl::SolverControl (const unsigned int maxiter,
                              const double tolerance,
                              const bool _log_history,

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.