From 6442bfb0a934778a58200355dddbfe9dd5de7b7a Mon Sep 17 00:00:00 2001 From: guido Date: Wed, 2 May 2001 10:30:32 +0000 Subject: [PATCH] output of NoConvergence git-svn-id: https://svn.dealii.org/trunk@4517 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/solver_control.h | 6 +++++ deal.II/lac/source/solver_control.cc | 28 ++++++++++++++++++++++++ tests/lac/solver.cc | 9 ++++++++ 3 files changed, 43 insertions(+) diff --git a/deal.II/lac/include/lac/solver_control.h b/deal.II/lac/include/lac/solver_control.h index a57a7103ad..3175d43073 100644 --- a/deal.II/lac/include/lac/solver_control.h +++ b/deal.II/lac/include/lac/solver_control.h @@ -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. diff --git a/deal.II/lac/source/solver_control.cc b/deal.II/lac/source/solver_control.cc index 68b801fd3f..3660cfd05d 100644 --- a/deal.II/lac/source/solver_control.cc +++ b/deal.II/lac/source/solver_control.cc @@ -17,6 +17,7 @@ #include #include +#include /*----------------------- 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, diff --git a/tests/lac/solver.cc b/tests/lac/solver.cc index e2c38425e2..2532d0af04 100644 --- a/tests/lac/solver.cc +++ b/tests/lac/solver.cc @@ -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); -- 2.39.5