Skip to content

Commit

Permalink
[Reactor] Improve error message when advancing to past time
Browse files Browse the repository at this point in the history
Resolves #1195
  • Loading branch information
speth authored and ischoegl committed Aug 4, 2023
1 parent 0b80608 commit 3ec4577
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/numerics/CVodesIntegrator.cpp
Expand Up @@ -514,6 +514,11 @@ void CVodesIntegrator::integrate(double tout)
{
if (tout == m_time) {
return;
} else if (tout < m_time) {
throw CanteraError("CVodesIntegrator::integrate",
"Cannot integrate backwards in time.\n"
"Requested time {} < current time {}",
tout, m_time);
}
int nsteps = 0;
while (m_tInteg < tout) {
Expand Down
5 changes: 5 additions & 0 deletions src/numerics/IdasIntegrator.cpp
Expand Up @@ -453,6 +453,11 @@ void IdasIntegrator::integrate(double tout)
{
if (tout == m_time) {
return;
} else if (tout < m_time) {
throw CanteraError("IdasIntegrator::integrate",
"Cannot integrate backwards in time.\n"
"Requested time {} < current time {}",
tout, m_time);
}
int nsteps = 0;
while (m_tInteg < tout) {
Expand Down
15 changes: 15 additions & 0 deletions test/python/test_reactor.py
Expand Up @@ -348,6 +348,12 @@ def test_advance_limits_invalid(self):
with pytest.raises(ct.CanteraError, match="No component named 'spam'"):
self.r1.set_advance_limit("spam", 0.1)

def test_advance_reverse(self):
self.make_reactors(n_reactors=1)
self.net.advance(0.1)
with pytest.raises(ct.CanteraError, match="backwards in time"):
self.net.advance(0.09)

def test_heat_transfer2(self):
# Result should be the same if (m * cp) / (U * A) is held constant
self.make_reactors(T1=300, T2=1000)
Expand Down Expand Up @@ -1531,6 +1537,15 @@ def make_reactors(self, gas, surf):
sim = ct.ReactorNet([r])
return r, rsurf, sim

def test_advance_reverse(self):
surf, gas = self.import_phases()
gas.TPX = 1500, 4000, 'NH3:1.0, SiF4:0.4'
r, rsurf, sim = self.make_reactors(gas, surf)

sim.advance(0.1)
with pytest.raises(ct.CanteraError, match="backwards in time"):
sim.advance(0.09)

def test_no_mass_flow_rate(self):
surf, gas = self.import_phases()
r = ct.FlowReactor(gas)
Expand Down

0 comments on commit 3ec4577

Please sign in to comment.