diff --git a/interfaces/cython/cantera/ctml_writer.py b/interfaces/cython/cantera/ctml_writer.py index f2f908f44e5..8ad99db4de0 100644 --- a/interfaces/cython/cantera/ctml_writer.py +++ b/interfaces/cython/cantera/ctml_writer.py @@ -1138,11 +1138,10 @@ def __init__(self, if self._order: order = getPairs(self._order) for o in order.keys(): - if o in self._rxnorder: - self._rxnorder[o] = order[o] + if o not in self._rxnorder and 'nonreactant_orders' not in self._options: + raise CTI_Error("order specified for non-reactant: "+o+" and no \'nonreactant_orders\' option given") else: - if 'nonreactant_orders' not in self._options: - raise CTI_Error("order specified for non-reactant: "+o) + self._rxnorder[o] = order[o] self._kf = kf self._igspecies = [] diff --git a/interfaces/cython/cantera/test/test_convert.py b/interfaces/cython/cantera/test/test_convert.py index be9c4d88d20..4ee62fe1b0e 100644 --- a/interfaces/cython/cantera/test/test_convert.py +++ b/interfaces/cython/cantera/test/test_convert.py @@ -390,3 +390,13 @@ def test_noninteger_atomicity(self): gas = ct.Solution('../data/noninteger-atomicity.cti') self.assertNear(gas.molecular_weights[gas.species_index('CnHm')], 10.65*gas.atomic_weight('C') + 21.8*gas.atomic_weight('H')) + + def test_reaction_orders(self): + gas = ct.Solution('../data/non-reactant-species.cti') + R=gas.reaction(0) + allow=R.allow_nonreactant_orders + self.assertEqual(allow, True) + self.assertNear(R.orders.get('OH'), 0.15) + allow=R.allow_negative_orders + self.assertEqual(allow, True) + self.assertNear(R.orders.get('H2'), -0.25) diff --git a/test/data/reaction-orders.cti b/test/data/reaction-orders.cti new file mode 100644 index 00000000000..77d3c8a2e1b --- /dev/null +++ b/test/data/reaction-orders.cti @@ -0,0 +1,23 @@ +# Input file to test use of non-reactant species + +units(length = "cm", time = "s", quantity = "mol", act_energy = "kJ/mol") + +ideal_gas(name = "gas", + elements = " O H ", + species = """gri30: H2 O2 H2O OH """, + reactions = "all", + initial_state = state(temperature = 300.0, + pressure = OneAtm) ) + +#------------------------------------------------------------------------------- +# Reactions data +#------------------------------------------------------------------------------- + +#test negative orders and non-reactant orders +reaction("2 H2 + O2 => 2 H2O", [1e13, 0.0, 0.0], + order="H2:-0.25 OH:0.15", + options=['negative_orders', 'nonreactant_orders']) + +#if uncomment, should throw an error +#reaction("2 H2 + O2 => 2 H2O", [1e13, 0.0, 0.0], +# order="OH:0.15")