Skip to content

Commit

Permalink
[Reactor] Show accumulated eval errors with max steps error
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Jul 9, 2024
1 parent c00556f commit 7a69a6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/numerics/CVodesIntegrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,14 @@ void CVodesIntegrator::integrate(double tout)
int nsteps = 0;
while (m_tInteg < tout) {
if (nsteps >= m_maxsteps) {
string f_errs = m_func->getErrors();
if (!f_errs.empty()) {
f_errs = "\nExceptions caught during RHS evaluation:\n" + f_errs;
}
throw CanteraError("CVodesIntegrator::integrate",
"Maximum number of timesteps ({}) taken without reaching output "
"time ({}).\nCurrent integrator time: {}",
nsteps, tout, m_tInteg);
"time ({}).\nCurrent integrator time: {}{}",
nsteps, tout, m_tInteg, f_errs);
}
int flag = CVode(m_cvode_mem, tout, m_y, &m_tInteg, CV_ONE_STEP);
if (flag != CV_SUCCESS) {
Expand Down
8 changes: 4 additions & 4 deletions test/python/test_reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2802,7 +2802,7 @@ class TestException(Exception):
class DummyReactor(ct.ExtensibleConstPressureReactor):
def before_eval(self, t, LHS, RHS):
if t > 0.1:
raise TestException()
raise TestException("spam")

def before_component_index(self, name):
if name == "fail":
Expand All @@ -2814,11 +2814,11 @@ def before_component_index(self, name):

# Because the TestException is raised inside code called by CVODES, the actual
# error raised will be a CanteraError
with self.assertRaises(ct.CanteraError):
with pytest.raises(ct.CanteraError, match="TestException: spam"):
net.advance(0.2)

self.assertEqual(r.component_index("enthalpy"), 1)
with self.assertRaises(TestException):
assert r.component_index("enthalpy") == 1
with pytest.raises(TestException):
r.component_index("fail")

def test_misc(self):
Expand Down

0 comments on commit 7a69a6e

Please sign in to comment.