From 8d4fd359057062e6933c7a177054d95efc9ff0ed Mon Sep 17 00:00:00 2001 From: Christoph Lehmann <christoph.lehmann@ufz.de> Date: Mon, 22 Aug 2016 15:22:12 +0200 Subject: [PATCH] [NL] added preFirstIteration() method --- NumLib/ODESolver/ConvergenceCriterion.h | 4 ++++ NumLib/ODESolver/NonlinearSolver.cpp | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/NumLib/ODESolver/ConvergenceCriterion.h b/NumLib/ODESolver/ConvergenceCriterion.h index 95ab8e9fdd8..db0024ed0bf 100644 --- a/NumLib/ODESolver/ConvergenceCriterion.h +++ b/NumLib/ODESolver/ConvergenceCriterion.h @@ -53,6 +53,10 @@ public: //! Check if the residual satisfies the convergence criterion. virtual void checkResidual(GlobalVector const& residual) = 0; + //! Tell the ConvergenceCriterion that it is called for the first time now + //! (while solving a specific nonlinear system). + virtual void preFirstIteration() {} + //! Indicate that a new iteration now starts. //! //! A concrete implementation of ConvergenceCriterion might want to check diff --git a/NumLib/ODESolver/NonlinearSolver.cpp b/NumLib/ODESolver/NonlinearSolver.cpp index 4cf1e2d69a2..990d00a8ce1 100644 --- a/NumLib/ODESolver/NonlinearSolver.cpp +++ b/NumLib/ODESolver/NonlinearSolver.cpp @@ -48,12 +48,12 @@ bool NonlinearSolver<NonlinearSolverTag::Picard>::solve( LinAlg::copy(x, x_new); // set initial guess, TODO save the copy + _convergence_criterion->preFirstIteration(); unsigned iteration = 1; - for (; iteration <= _maxiter; ++iteration) + for (; iteration <= _maxiter; + ++iteration, _convergence_criterion->reset()) { - _convergence_criterion->reset(); - BaseLib::RunTime time_iteration; time_iteration.start(); @@ -192,11 +192,12 @@ bool NonlinearSolver<NonlinearSolverTag::Newton>::solve( LinAlg::copy(x, minus_delta_x); minus_delta_x.setZero(); + _convergence_criterion->preFirstIteration(); + unsigned iteration = 1; - for (; iteration <= _maxiter; ++iteration) + for (; iteration <= _maxiter; + ++iteration, _convergence_criterion->reset()) { - _convergence_criterion->reset(); - BaseLib::RunTime time_iteration; time_iteration.start(); -- GitLab