From adb7ef2ee46fa32c90f1b9c9a2e05903423b0b0a Mon Sep 17 00:00:00 2001 From: Polina Lakrisenko Date: Fri, 10 Jun 2022 18:31:26 +0200 Subject: [PATCH 1/3] move sim_steps increment --- src/steadystateproblem.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/steadystateproblem.cpp b/src/steadystateproblem.cpp index a2acec9596..761ed4d8b9 100644 --- a/src/steadystateproblem.cpp +++ b/src/steadystateproblem.cpp @@ -647,7 +647,10 @@ void SteadystateProblem::runSteadystateSimulation(const Solver &solver, stable computation value is not important for AMICI_ONE_STEP mode, only direction w.r.t. current t */ + /* increase counter */ + sim_steps++; solver.step(std::max(state_.t, 1.0) * 10); + if (backward) { solver.writeSolution(&state_.t, xB_, state_.dx, state_.sx, xQ_); } else { @@ -670,8 +673,7 @@ void SteadystateProblem::runSteadystateSimulation(const Solver &solver, if (wrms_ < conv_thresh) break; // converged - /* increase counter, check for maxsteps */ - sim_steps++; + /* check for maxsteps */ if (sim_steps >= solver.getMaxSteps()) { throw NewtonFailure(AMICI_TOO_MUCH_WORK, "exceeded maximum number of steps"); From 7d6c315e62d935c00789bdfca4e76700e27a814f Mon Sep 17 00:00:00 2001 From: Polina Lakrisenko Date: Fri, 10 Jun 2022 19:00:56 +0200 Subject: [PATCH 2/3] move also max steps and large time point checks --- src/steadystateproblem.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/steadystateproblem.cpp b/src/steadystateproblem.cpp index 761ed4d8b9..3b4d7948eb 100644 --- a/src/steadystateproblem.cpp +++ b/src/steadystateproblem.cpp @@ -647,6 +647,16 @@ void SteadystateProblem::runSteadystateSimulation(const Solver &solver, stable computation value is not important for AMICI_ONE_STEP mode, only direction w.r.t. current t */ + /* check for maxsteps */ + if (sim_steps >= solver.getMaxSteps()) { + throw NewtonFailure(AMICI_TOO_MUCH_WORK, + "exceeded maximum number of steps"); + } + if (state_.t >= 1e200) { + throw NewtonFailure(AMICI_NO_STEADY_STATE, + "simulated to late time" + " point without convergence of RHS"); + } /* increase counter */ sim_steps++; solver.step(std::max(state_.t, 1.0) * 10); @@ -673,16 +683,6 @@ void SteadystateProblem::runSteadystateSimulation(const Solver &solver, if (wrms_ < conv_thresh) break; // converged - /* check for maxsteps */ - if (sim_steps >= solver.getMaxSteps()) { - throw NewtonFailure(AMICI_TOO_MUCH_WORK, - "exceeded maximum number of steps"); - } - if (state_.t >= 1e200) { - throw NewtonFailure(AMICI_NO_STEADY_STATE, - "simulated to late time" - " point without convergence of RHS"); - } } // if check_sensi_conv_ is deactivated, we still have to update sensis From 98105813dfc64f8ad6492c7256ee472027708960 Mon Sep 17 00:00:00 2001 From: Polina Lakrisenko Date: Sat, 11 Jun 2022 15:50:10 +0200 Subject: [PATCH 3/3] tidy up --- src/steadystateproblem.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/steadystateproblem.cpp b/src/steadystateproblem.cpp index 3b4d7948eb..1da5fc31bd 100644 --- a/src/steadystateproblem.cpp +++ b/src/steadystateproblem.cpp @@ -640,13 +640,6 @@ void SteadystateProblem::runSteadystateSimulation(const Solver &solver, convergence_check_frequency = 25; while (true) { - /* One step of ODE integration - reason for tout specification: - max with 1 ensures correct direction (any positive value would do) - multiplication with 10 ensures nonzero difference and should ensure - stable computation value is not important for AMICI_ONE_STEP mode, - only direction w.r.t. current t - */ /* check for maxsteps */ if (sim_steps >= solver.getMaxSteps()) { throw NewtonFailure(AMICI_TOO_MUCH_WORK, @@ -658,7 +651,14 @@ void SteadystateProblem::runSteadystateSimulation(const Solver &solver, " point without convergence of RHS"); } /* increase counter */ - sim_steps++; + sim_steps++; + /* One step of ODE integration + reason for tout specification: + max with 1 ensures correct direction (any positive value would do) + multiplication with 10 ensures nonzero difference and should ensure + stable computation value is not important for AMICI_ONE_STEP mode, + only direction w.r.t. current t + */ solver.step(std::max(state_.t, 1.0) * 10); if (backward) {