Skip to content

Commit

Permalink
[1D] Initialize number-of-steps counter at start of solve
Browse files Browse the repository at this point in the history
Fixes the enforcement of the maximum number of steps constraint if solve() is
called again after an exception.
  • Loading branch information
speth committed Mar 28, 2016
1 parent 233399f commit 4c5301d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
12 changes: 6 additions & 6 deletions include/cantera/oneD/OneDim.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/oneD/OneDim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -30,8 +30,8 @@ OneDim::OneDim(vector<Domain1D*> 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));
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/oneD/Sim1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 4c5301d

Please sign in to comment.