From 4c5301d6cd9fd2f5b1c884306d5d4a254c226cfd Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 28 Mar 2016 17:13:24 -0400 Subject: [PATCH] [1D] Initialize number-of-steps counter at start of solve Fixes the enforcement of the maximum number of steps constraint if solve() is called again after an exception. --- include/cantera/oneD/OneDim.h | 12 ++++++------ src/oneD/OneDim.cpp | 10 +++++----- src/oneD/Sim1D.cpp | 1 + 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/cantera/oneD/OneDim.h b/include/cantera/oneD/OneDim.h index d62dd54bed..7778d503c0 100644 --- a/include/cantera/oneD/OneDim.h +++ b/include/cantera/oneD/OneDim.h @@ -340,6 +340,12 @@ class OneDim //! Function called at the start of every call to #eval. Func1* m_interrupt; + //! Number of time steps taken in the current call to solve() + int m_nsteps; + + //! Maximum number of timesteps allowed per call to solve() + int m_nsteps_max; + private: // statistics int m_nevals; @@ -350,12 +356,6 @@ class OneDim vector_int m_funcEvals; vector_fp m_funcElapsed; - //! Number of time steps taken in the current call to solve() - int m_nsteps; - - //! Maximum number of timesteps allowed per call to solve() - int m_nsteps_max; - //! Number of time steps taken in each call to solve() (e.g. for each //! successive grid refinement) vector_int m_timeSteps; diff --git a/src/oneD/OneDim.cpp b/src/oneD/OneDim.cpp index a55ec1491c..0b4dcc7f45 100644 --- a/src/oneD/OneDim.cpp +++ b/src/oneD/OneDim.cpp @@ -18,8 +18,8 @@ OneDim::OneDim() m_bw(0), m_size(0), m_init(false), m_pts(0), m_solve_time(0.0), m_ss_jac_age(20), m_ts_jac_age(20), - m_interrupt(0), m_nevals(0), m_evaltime(0.0), m_nsteps(0), - m_nsteps_max(500) + m_interrupt(0), m_nsteps(0), m_nsteps_max(500), + m_nevals(0), m_evaltime(0.0) { m_newt.reset(new MultiNewton(1)); } @@ -30,8 +30,8 @@ OneDim::OneDim(vector domains) : m_bw(0), m_size(0), m_init(false), m_solve_time(0.0), m_ss_jac_age(20), m_ts_jac_age(20), - m_interrupt(0), m_nevals(0), m_evaltime(0.0), m_nsteps(0), - m_nsteps_max(500) + m_interrupt(0), m_nsteps(0), m_nsteps_max(500), + m_nevals(0), m_evaltime(0.0) { // create a Newton iterator, and add each domain. m_newt.reset(new MultiNewton(1)); @@ -364,7 +364,7 @@ doublereal OneDim::timeStep(int nsteps, doublereal dt, doublereal* x, dt *= 1.5; } dt = std::min(dt, m_tmax); - if (m_nsteps == m_nsteps_max) { + if (m_nsteps >= m_nsteps_max) { throw CanteraError("OneDim::timeStep", "Took maximum number of timesteps allowed ({}) without " "reaching steady-state solution.", m_nsteps_max); diff --git a/src/oneD/Sim1D.cpp b/src/oneD/Sim1D.cpp index 0dab816575..e4224eb975 100644 --- a/src/oneD/Sim1D.cpp +++ b/src/oneD/Sim1D.cpp @@ -230,6 +230,7 @@ void Sim1D::solve(int loglevel, bool refine_grid) int new_points = 1; int nsteps; doublereal dt = m_tstep; + m_nsteps = 0; int soln_number = -1; finalize();