Allow colons in species names in CTI phase definitions

This commit is contained in:
Ray Speth 2016-11-19 15:45:27 -05:00
parent 05ad05c904
commit 3300611379
3 changed files with 44 additions and 34 deletions

View file

@ -1767,29 +1767,8 @@ class phase(object):
# dictionary of species names
self._spmap = {}
# for each species string, check whether or not the species
# are imported or defined locally. If imported, the string
# contains a colon (:)
for sp in self._species:
icolon = sp.find(':')
if icolon > 0:
#datasrc, spnames = sp.split(':')
datasrc = sp[:icolon].strip()
spnames = sp[icolon+1:]
self._sp.append((datasrc+'.xml', spnames))
else:
spnames = sp
self._sp.append(('', spnames))
for s in spnames.split():
self._spmap[s] = self._dim
self._rxns = reactions
# check that species have been declared
if len(self._spmap) == 0:
raise CTI_Error('No species declared for phase '+self._name)
# and that only one species is declared if it is a pure phase
if self.is_pure() and len(self._spmap) > 1:
raise CTI_Error('Stoichiometric phases must declare exactly one species, \n'+
@ -1819,7 +1798,6 @@ class phase(object):
rate coefficients."""
return (1, -self._dim)
def buildrxns(self, p):
if isinstance(self._rxns, str):
@ -1865,6 +1843,34 @@ class phase(object):
def build(self, p):
# for each species string, check whether or not the species
# are imported or defined locally. If imported, the string
# contains a colon (:)
for sp in self._species:
foundColon = False
allLocal = True
for token in sp.split():
if ':' in sp:
foundColon = True
if token not in _speciesnames:
allLocal = False
if foundColon and not allLocal:
icolon = sp.find(':')
datasrc = sp[:icolon].strip()
spnames = sp[icolon+1:]
self._sp.append((datasrc+'.xml', spnames))
else:
spnames = sp
self._sp.append(('', spnames))
for s in spnames.split():
self._spmap[s] = self._dim
# check that species have been declared
if len(self._spmap) == 0:
raise CTI_Error('No species declared for phase '+self._name)
p.addComment(' phase '+self._name+' ')
ph = p.addChild('phase')
ph['id'] = self._name

View file

@ -142,22 +142,22 @@ class chemkinConverterTest(utilities.CanteraTest):
outName=pjoin(self.test_work_dir, 'species-names.cti'), quiet=True)
gas = ct.Solution('species-names.cti')
self.assertEqual(gas.n_species, 6)
self.assertEqual(gas.n_species, 7)
self.assertEqual(gas.species_name(0), '(Parens)')
self.assertEqual(gas.species_name(1), '@#$%^-2')
self.assertEqual(gas.species_name(2), '[xy2]*{.}')
self.assertEqual(gas.species_name(3), 'plus+')
self.assertEqual(gas.species_name(4), 'eq=uals')
self.assertEqual(gas.species_name(5), 'plus')
self.assertEqual(gas.species_name(3), '[xy2]*{.}')
self.assertEqual(gas.species_name(4), 'plus+')
self.assertEqual(gas.species_name(5), 'eq=uals')
self.assertEqual(gas.species_name(6), 'plus')
self.assertEqual(gas.n_reactions, 6)
nu = gas.product_stoich_coeffs() - gas.reactant_stoich_coeffs()
self.assertEqual(list(nu[:,0]), [-1, -1, 2, 0, 0, 0])
self.assertEqual(list(nu[:,1]), [-2, 3, -1, 0, 0, 0])
self.assertEqual(list(nu[:,2]), [-1, 0, 0, 1, 0, 0])
self.assertEqual(list(nu[:,3]), [3, 0, 0, -2, -1, 0])
self.assertEqual(list(nu[:,4]), [2, 0, 0, -1, 0, -1])
self.assertEqual(list(nu[:,5]), [1, 0, 0, 1, -1, -1])
self.assertEqual(list(nu[:,0]), [-1, -1, 0, 2, 0, 0, 0])
self.assertEqual(list(nu[:,1]), [-2, 3, 0, -1, 0, 0, 0])
self.assertEqual(list(nu[:,2]), [-1, 0, 0, 0, 1, 0, 0])
self.assertEqual(list(nu[:,3]), [3, 0, 0, 0, -2, -1, 0])
self.assertEqual(list(nu[:,4]), [2, 0, 0, 0, -1, 0, -1])
self.assertEqual(list(nu[:,5]), [1, 0, 0, 0, 1, -1, -1])
def test_unterminatedSections(self):
with self.assertRaises(ck2cti.InputParseError):

View file

@ -2,7 +2,7 @@ Elements
H C
End
SPEC
(Parens) @#$%^-2 [xy2]*{.} plus+ eq=uals plus
(Parens) @#$%^-2 co:lons [xy2]*{.} plus+ eq=uals plus
end
thermo
@ -15,6 +15,10 @@ thermo
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
co:lons 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