[ck2cti] Fix to allow species names starting with special characters
This commit is contained in:
parent
2778267a43
commit
f1e5183431
3 changed files with 51 additions and 2 deletions
|
|
@ -807,6 +807,12 @@ def fortFloat(s):
|
|||
s = s.replace('E ', 'E+').replace('e ', 'e+')
|
||||
return float(s)
|
||||
|
||||
def isnumberlike(text):
|
||||
""" Returns true if `text` contains only the digits 0-9 and '.' """
|
||||
for char in text:
|
||||
if not char.isdigit() and char != '.':
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_index(seq, value):
|
||||
"""
|
||||
|
|
@ -1064,10 +1070,10 @@ class Parser(object):
|
|||
|
||||
for term in expression.split('+'):
|
||||
term = term.strip()
|
||||
if not term[0].isalpha():
|
||||
if isnumberlike(term[0]):
|
||||
# This allows for for non-unity stoichiometric coefficients, e.g.
|
||||
# 2A=B+C or .85A+.15B=>C
|
||||
j = [i for i,c in enumerate(term) if c.isalpha()][0]
|
||||
j = [i for i,c in enumerate(term) if not isnumberlike(c)][0]
|
||||
if term[:j].isdigit():
|
||||
stoichiometry = int(term[:j])
|
||||
else:
|
||||
|
|
|
|||
27
test/data/species-names.inp
Normal file
27
test/data/species-names.inp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
Elements
|
||||
H C
|
||||
End
|
||||
SPECIES
|
||||
(Parens) @#$%^-2 [xy2]*{.}
|
||||
end
|
||||
|
||||
thermo
|
||||
300.000 1000.000 5000.000
|
||||
(Parens) C 1H 4 G 200.000 3500.000 1000.000 1
|
||||
7.48514950E-02 1.33909467E-02-5.73285809E-06 1.22292535E-09-1.01815230E-13 2
|
||||
-9.46834459E+03 1.84373180E+01 5.14987613E+00-1.36709788E-02 4.91800599E-05 3
|
||||
-4.84743026E-08 1.66693956E-11-1.02466476E+04-4.64130376E+00 4
|
||||
@#$%^-2 C 1H 4 G 200.000 3500.000 1000.000 1
|
||||
7.48514950E-02 1.33909467E-02-5.73285809E-06 1.22292535E-09-1.01815230E-13 2
|
||||
-9.46834459E+03 1.84373180E+01 5.14987613E+00-1.36709788E-02 4.91800599E-05 3
|
||||
-4.84743026E-08 1.66693956E-11-1.02466476E+04-4.64130376E+00 4
|
||||
[xy2]*{.} C 1H 4 G 200.000 3500.000 1000.000 1
|
||||
7.48514950E-02 1.33909467E-02-5.73285809E-06 1.22292535E-09-1.01815230E-13 2
|
||||
-9.46834459E+03 1.84373180E+01 5.14987613E+00-1.36709788E-02 4.91800599E-05 3
|
||||
-4.84743026E-08 1.66693956E-11-1.02466476E+04-4.64130376E+00 4
|
||||
end
|
||||
|
||||
reactions
|
||||
(Parens) + @#$%^-2 = 2 [xy2]*{.} 1.2345e12 1.0 200.0
|
||||
2(Parens) + [xy2]*{.} = 3@#$%^-2 5.4321e10 1.0 500.0
|
||||
end
|
||||
|
|
@ -100,6 +100,22 @@ class chemkinConverterTest(utilities.CanteraTest):
|
|||
outName='h2o2_missingThermo.cti',
|
||||
quiet=True))
|
||||
|
||||
def test_pathologicalSpeciesNames(self):
|
||||
convertMech('../data/species-names.inp',
|
||||
outName='species-names.cti', quiet=True)
|
||||
gas = ct.IdealGasMix('species-names.cti')
|
||||
|
||||
self.assertEqual(gas.nSpecies(), 3)
|
||||
self.assertEqual(gas.speciesName(0), '(Parens)')
|
||||
self.assertEqual(gas.speciesName(1), '@#$%^-2')
|
||||
self.assertEqual(gas.speciesName(2), '[xy2]*{.}')
|
||||
|
||||
self.assertEqual(gas.nReactions(), 2)
|
||||
nu = gas.productStoichCoeffs() - gas.reactantStoichCoeffs()
|
||||
self.assertEqual(list(nu[:,0]), [-1, -1, 2])
|
||||
self.assertEqual(list(nu[:,1]), [-2, 3, -1])
|
||||
|
||||
|
||||
def test_nasa9(self):
|
||||
convertMech('../data/nasa9-test.inp',
|
||||
thermoFile='../data/nasa9-test-therm.dat',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue