Skip to content

Commit

Permalink
[ck2cti] Always write surface reactions to CTI file
Browse files Browse the repository at this point in the history
Surface reactions were not being written to the CTI file if there were no
gas-phase reactions present.

Also update the count of reactions printed in the output summary to include
surface reactions.
  • Loading branch information
speth committed Jan 19, 2018
1 parent 831b92d commit 552ba97
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
5 changes: 3 additions & 2 deletions interfaces/cython/cantera/ck2cti.py
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ def writeCTI(self, header=None, name='gas', transportModel='Mix',
for s in surf.speciesList:
lines.append(s.to_cti())

if self.reactions:
if self.reactions or any(surf.reactions for surf in self.surfaces):
# Write the reactions
lines.append(delimiterLine)
lines.append('# Reaction data')
Expand Down Expand Up @@ -2233,8 +2233,9 @@ def convertMech(self, inputFile, thermoFile=None,
# Write output file
surface_names = self.writeCTI(name=phaseName, outName=outName)
if not quiet:
nReactions = len(self.reactions) + sum(len(surf.reactions) for surf in self.surfaces)
print('Wrote CTI mechanism file to {0!r}.'.format(outName))
print('Mechanism contains {0} species and {1} reactions.'.format(len(self.speciesList), len(self.reactions)))
print('Mechanism contains {0} species and {1} reactions.'.format(len(self.speciesList), nReactions))
return surface_names


Expand Down
11 changes: 11 additions & 0 deletions interfaces/cython/cantera/test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,17 @@ def test_surface_mech(self):
self.assertEqual(covdeps['OH_Pt'][1], 1.0)
self.assertNear(covdeps['H_Pt'][2], -6e6) # 6000 J/gmol = 6e6 J/kmol

def test_surface_mech2(self):
convertMech(pjoin(self.test_data_dir, 'surface1-gas-noreac.inp'),
surfaceFile=pjoin(self.test_data_dir, 'surface1.inp'),
outName=pjoin(self.test_work_dir, 'surface1-nogasreac.cti'), quiet=True)

gas = ct.Solution('surface1-nogasreac.cti', 'gas')
surf = ct.Interface('surface1-nogasreac.cti', 'PT_SURFACE', [gas])

self.assertEqual(gas.n_reactions, 0)
self.assertEqual(surf.n_reactions, 15)


class CtmlConverterTest(utilities.CanteraTest):
def test_sofc(self):
Expand Down
41 changes: 41 additions & 0 deletions test/data/surface1-gas-noreac.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
ELEMENTS H O PT END

SPECIES
H H2 H2O H2O2 HO2 O O2 OH
END

THERMO
300.0 1000.0 3500.0
H 120186H 1 G 0300.00 5000.00 1000.00 1
0.02500000E+02 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 2
0.02547162E+06-0.04601176E+01 0.02500000E+02 0.00000000E+00 0.00000000E+00 3
0.00000000E+00 0.00000000E+00 0.02547162E+06-0.04601176E+01 4
H2 121286H 2 G 0300.00 5000.00 1000.00 1
0.02991423E+02 0.07000644E-02-0.05633828E-06-0.09231578E-10 0.15827519E-14 2
-0.08350340E+04-0.13551101E+01 0.03298124E+02 0.08249441E-02-0.08143015E-05 3
-0.09475434E-09 0.04134872E-11-0.10125209E+04-0.03294094E+02 4
H2O 20387H 2O 1 G 0300.00 5000.00 1000.00 1
0.02672145E+02 0.03056293E-01-0.08730260E-05 0.12009964E-09-0.06391618E-13 2
-0.02989921E+06 0.06862817E+02 0.03386842E+02 0.03474982E-01-0.06354696E-04 3
0.06968581E-07-0.02506588E-10-0.03020811E+06 0.02590232E+02 4
H2O2 120186H 2O 2 G 0300.00 5000.00 1000.00 1
0.04573167E+02 0.04336136E-01-0.14746888E-05 0.02348903E-08-0.14316536E-13 2
-0.01800696E+06 0.05011369E+01 0.03388753E+02 0.06569226E-01-0.14850125E-06 3
-0.04625805E-07 0.02471514E-10-0.01766314E+06 0.06785363E+02 4
HO2 20387H 1O 2 G 0300.00 5000.00 1000.00 1
0.04072191E+02 0.02131296E-01-0.05308145E-05 0.06112269E-09-0.02841164E-13 2
-0.15797270E+03 0.03476029E+02 0.02979963E+02 0.04996697E-01-0.03790997E-04 3
0.02354192E-07-0.08089024E-11 0.01762273E+04 0.09222724E+02 4
O 120186O 1 G 0300.00 5000.00 1000.00 1
0.02542059E+02-0.02755061E-03-0.03102803E-07 0.04551067E-10-0.04368051E-14 2
0.02923080E+06 0.04920308E+02 0.02946428E+02-0.16381665E-02 0.02421031E-04 3
-0.16028431E-08 0.03890696E-11 0.02914764E+06 0.02963995E+02 4
O2 121386O 2 G 0300.00 5000.00 1000.00 1
0.03697578E+02 0.06135197E-02-0.12588420E-06 0.01775281E-09-0.11364354E-14 2
-0.12339301E+04 0.03189165E+02 0.03212936E+02 0.11274864E-02-0.05756150E-05 3
0.13138773E-08-0.08768554E-11-0.10052490E+04 0.06034737E+02 4
OH 121286O 1H 1 G 0300.00 5000.00 1000.00 1
0.02882730E+02 0.10139743E-02-0.02276877E-05 0.02174683E-09-0.05126305E-14 2
0.03886888E+05 0.05595712E+02 0.03637266E+02 0.01850910E-02-0.16761646E-05 3
0.02387202E-07-0.08431442E-11 0.03606781E+05 0.13588605E+01 4
END

0 comments on commit 552ba97

Please sign in to comment.