Skip to content

Commit

Permalink
[Reactor] Check for valid component name when setting advance limits
Browse files Browse the repository at this point in the history
Fixes #1213
  • Loading branch information
speth authored and ischoegl committed Mar 13, 2022
1 parent e6a5ffd commit 719275e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions interfaces/cython/cantera/test/test_reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re

import numpy as np
import pytest
from .utilities import unittest

import cantera as ct
Expand Down Expand Up @@ -291,6 +292,12 @@ def test_heat_transfer1(self):
self.assertNear(self.r1.T, self.r2.T, 5e-7)
self.assertNotAlmostEqual(self.r1.thermo.P, self.r2.thermo.P)

def test_advance_limits_invalid(self):
self.make_reactors(n_reactors=1)

with pytest.raises(ct.CanteraError, match="No component named 'spam'"):
self.r1.set_advance_limit("spam", 0.1)

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
3 changes: 3 additions & 0 deletions src/zeroD/Reactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ bool Reactor::getAdvanceLimits(double *limits)
void Reactor::setAdvanceLimit(const string& nm, const double limit)
{
size_t k = componentIndex(nm);
if (k == npos) {
throw CanteraError("Reactor::setAdvanceLimit", "No component named '{}'", nm);
}

if (m_thermo == 0) {
throw CanteraError("Reactor::setAdvanceLimit",
Expand Down

0 comments on commit 719275e

Please sign in to comment.