From 8908478667ffa0c969cdee4f5ffddeac71e405bb Mon Sep 17 00:00:00 2001 From: Andreas Lauser <and@poware.org> Date: Thu, 20 Jan 2011 10:03:51 +0000 Subject: [PATCH] box models: improve exception handling all non-NumericalProblem exceptions are caught at the level of the newton method and the constructor of the NumericalProblem class can directly take a string as an argument for improved convenience, git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@5040 2fb0f335-1f38-0410-981e-8018bf24f1b0 --- dumux/common/exceptions.hh | 19 +++++++++++++++++-- dumux/nonlinear/newtoncontroller.hh | 11 ++++++++++- dumux/nonlinear/newtonmethod.hh | 6 ------ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/dumux/common/exceptions.hh b/dumux/common/exceptions.hh index 2302528f33..f1b25ffd21 100644 --- a/dumux/common/exceptions.hh +++ b/dumux/common/exceptions.hh @@ -1,5 +1,4 @@ // $Id$ - /***************************************************************************** * Copyright (C) 2009 by Andreas Lauser * * Institute of Hydraulic Engineering * @@ -28,6 +27,8 @@ #include <dune/common/exceptions.hh> +#include <string> + namespace Dumux { /*! * \brief Exception thrown if a fixable numerical problem occurs. @@ -35,7 +36,21 @@ namespace Dumux { * (e.g. time step too big, etc.) */ class NumericalProblem : public Dune::Exception -{ }; +{ +public: + // copy constructor + NumericalProblem(const NumericalProblem &v) + : Dune::Exception(v) + {} + + // default constructor + NumericalProblem() + {} + + // constructor with error message + NumericalProblem(const std::string &s) + { this->message(s); } + }; } #endif diff --git a/dumux/nonlinear/newtoncontroller.hh b/dumux/nonlinear/newtoncontroller.hh index aaf4703994..7a445bcae2 100644 --- a/dumux/nonlinear/newtoncontroller.hh +++ b/dumux/nonlinear/newtoncontroller.hh @@ -467,7 +467,7 @@ public: if (!converged) { DUNE_THROW(NumericalProblem, - "A process threw MatrixBlockError"); + "A process threw NumericalProblem"); } } catch (Dune::MatrixBlockError e) { @@ -482,6 +482,15 @@ public: p.message(ms.str()); throw p; } + catch (const Dune::ISTLError &e) { + // make sure all processes converged + int converged = 0; + gridView_().comm().min(converged); + + Dumux::NumericalProblem p; + p.message(e.what()); + throw p; + } } /*! diff --git a/dumux/nonlinear/newtonmethod.hh b/dumux/nonlinear/newtonmethod.hh index 1774073fa0..bc48cd3a15 100644 --- a/dumux/nonlinear/newtonmethod.hh +++ b/dumux/nonlinear/newtonmethod.hh @@ -103,12 +103,6 @@ public: try { return execute_(ctl); } - catch (const Dune::ISTLError &e) { - if (ctl.verbose()) - std::cout << "Newton: Caught exception: \"" << e.what() << "\"\n"; - ctl.newtonFail(); - return false; - } catch (const Dumux::NumericalProblem &e) { if (ctl.verbose()) std::cout << "Newton: Caught exception: \"" << e.what() << "\"\n"; -- GitLab