[ck2cti] Allow stoichiometric coefficients ending in decimal points

Fixes Issue 220.
This commit is contained in:
Ray Speth
2014-05-07 21:57:22 +00:00
parent c621d5f9db
commit d6a3ea4aa7
3 changed files with 34 additions and 8 deletions

View File

@@ -40,9 +40,6 @@ import numpy as np
import re
import itertools
reFloat = re.compile(r'\+?\d*\.?\d+([eEdD][-+]?\d+)?$')
reInt = re.compile(r'\+?\d+$')
QUANTITY_UNITS = {'MOL': 'mol',
'MOLE': 'mol',
'MOLES': 'mol',
@@ -1086,12 +1083,16 @@ class Parser(object):
j = reaction.find(token)
i = len(token)
reaction = reaction[:j] + ' '*i + reaction[j+i:]
if reInt.match(token):
if token == '+':
continue
try:
locs[j] = int(token), 'coeff'
elif reFloat.match(token):
locs[j] = float(token), 'coeff'
elif token != '+':
raise InputParseError('Unexpected token "{0}" in reaction expression "{1}".'.format(token, reaction))
except ValueError:
try:
locs[j] = float(token), 'coeff'
except ValueError:
raise InputParseError('Unexpected token "{0}" in reaction expression "{1}".'.format(token, reaction))
reactants = []
products = []

View File

@@ -251,6 +251,19 @@ class chemkinConverterTest(utilities.CanteraTest):
self.checkKinetics(default, custom,
[300, 800, 1450, 2800], [5e3, 1e5, 2e6], 1e-7)
def test_float_stoich_coeffs(self):
convertMech('../data/float-stoich.inp',
thermoFile='../data/dummy-thermo.dat',
outName='float-stoich.cti', quiet=True)
gas = ct.Solution('float-stoich.cti')
R = gas.reactant_stoich_coeffs()
P = gas.product_stoich_coeffs()
self.assertArrayNear(R[:,0], [0, 1.5, 0.5, 0])
self.assertArrayNear(P[:,0], [1, 0, 0, 1])
self.assertArrayNear(R[:,1], [1, 0, 0, 1])
self.assertArrayNear(P[:,1], [0, 0.33, 1.67, 0])
def test_transport_normal(self):
convertMech('../../data/inputs/h2o2.inp',
transportFile='../../data/transport/gri30_tran.dat',

View File

@@ -0,0 +1,12 @@
ELEMENTS
H C
END
SPECIES
H R1A R1B P1
END
REACTIONS
1.5R1A+.5R1B => 1.H+P1 1e12 0.0 20000.0
1.0H+1.P1=>.33R1A+1.67R1B 5e13 -2.0 5000.0
END