]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
output of NoConvergence
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 2 May 2001 10:30:32 +0000 (10:30 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 2 May 2001 10:30:32 +0000 (10:30 +0000)
git-svn-id: https://svn.dealii.org/trunk@4517 0785d39b-7218-0410-832d-ea1e28bc413d

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

index a57a7103adc8bb9b3d24b8fa3764ca888f18f151..3175d430733731d01bec302c69705e3e48479374 100644 (file)
@@ -91,6 +91,12 @@ class SolverControl : public Subscriptor
        NoConvergence (const unsigned int last_step,
                       const double       last_residual);
 
+                                        /**
+                                         * Standardized output for
+                                         * catch handlers.
+                                         */
+       virtual const char * what () const throw ();
+
                                         /**
                                          * Iteration number of the
                                          * last step.
index 68b801fd3f6f2f76edfc6a4176e2951126af5843..3660cfd05d9e421e693af5105ce817cb159ae1bf 100644 (file)
@@ -17,6 +17,7 @@
 #include <lac/solver_control.h>
 
 #include <cmath>
+#include <strstream>
 
 /*----------------------- SolverControl ---------------------------------*/
 
@@ -29,6 +30,33 @@ SolverControl::NoConvergence::NoConvergence (const unsigned int last_step,
 {};
 
 
+const char *
+SolverControl::NoConvergence::what () const throw ()
+{
+                                  // have a place where to store the
+                                  // description of the exception as a char *
+                                  //
+                                  // this thing obviously is not multi-threading
+                                  // safe, but we don't care about that for now
+                                  //
+                                  // we need to make this object static, since
+                                  // we want to return the data stored in it
+                                  // and therefore need a liftime which is
+                                  // longer than the execution time of this
+                                  // function
+  static std::string description;
+                                  // convert the messages printed by the
+                                  // exceptions into a std::string
+  std::ostrstream out;
+
+  out << "Iterative method reported convergence failure in step "
+      << last_step << " with residual " << last_residual << std::ends;
+
+  description = out.str();
+  return description.c_str();
+}
+
+
 
 SolverControl::SolverControl (const unsigned int maxiter,
                              const double tolerance,
index e2c38425e2ab1922f46dd23d2f70df788b8a16eb..2532d0af04f27e69d90b043bc95129633aae8eea 100644 (file)
@@ -114,6 +114,15 @@ int main()
          deallog.push("sor");
          
          check_method(rich,A,u,f,prec_sor);
+         try 
+           {
+             check_method(cg,A,u,f,prec_sor);
+           }
+         catch (exception& e)
+           {
+             deallog << e.what() << endl;
+           }
+         
          check_method(bicgstab,A,u,f,prec_sor);
          check_method(gmres,A,u,f,prec_sor);
          

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.