Skip to content

Commit d9f205d

Browse files
committed
Use identity reorder maps when reactions were not reordered
The reversible and pressure-dependent reorder maps were built by counting Cantera's reactions, which do not correspond one-to-one with the generated code's: a reaction written with an explicit collider is pressure-dependent to Cantera, while the Chemkin reader folds the collider into the rate expression. For h2o2 that produced a permutation of eleven indices applied to the six entries the generated code writes. The maps exist only to undo a reordering of the reactions, so where the reactions were not reordered they are now identities sized from the generated mechanism. This also covers the case where the species were reordered but the reactions were not.
1 parent dbbd9a5 commit d9f205d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/pyjac/functional_tester/test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,21 @@ def check_optimized(self, build_dir, gas, filename='mechanism.h'):
395395
[np.where(self.back_pdep_map == x)[0][0] for x in range(pdep_reacs)]
396396
)
397397

398+
# Those maps are built from Cantera's reactions, which do not always
399+
# correspond one-to-one with the generated code's: a reaction written
400+
# with an explicit collider is pressure-dependent to Cantera, while the
401+
# Chemkin reader folds the collider into the rate expression and emits
402+
# no pressure-modification entry for it. The maps exist only to undo a
403+
# reordering of the reactions, so where the reactions were not
404+
# reordered there is nothing to undo, and an identity sized from the
405+
# generated mechanism is both correct and the right length.
406+
if np.array_equal(self.fwd_rxn_map, np.arange(n_reac)):
407+
counts = mechanism_counts(build_dir, filename)
408+
self.fwd_rev_rxn_map = np.arange(counts['REV_RATES'])
409+
self.back_rev_rxn_map = np.arange(counts['REV_RATES'])
410+
self.fwd_pdep_map = np.arange(counts['PRES_MOD_RATES'])
411+
self.back_pdep_map = np.arange(counts['PRES_MOD_RATES'])
412+
398413
self.back_dydt_map = np.array([0] + [x + 1 for x in self.back_spec_map])
399414

400415
def __init__(self, build_dir, gas, module_name='pyjacob', filename='mechanism.h'):

0 commit comments

Comments
 (0)