import numpy as np from math import exp import cantera as ct mech = 'gri30.yaml' fuel = 'CH4' gas0 = ct.Solution(mech) species = gas0.species() reactions = gas0.reactions() # construct custom reactions: replace 2nd reaction with equivalent custom reaction custom_reactions = [r for r in reactions] custom_reactions[2] = ct.CustomReaction( equation='H2 + O <=> H + OH', rate=lambda T: 38.7 * T**2.7 * exp(-3150.15428/T), kinetics=gas0) gas1 = ct.Solution(thermo='ideal-gas', kinetics='gas', species=species, reactions=custom_reactions) # old framework - use xml input gas2 = ct.Solution(mech.replace('.yaml', '.xml')) # construct test case - simulate ignition def ignition(gas): # set up reactor gas.TP = 1000., 5 * ct.one_atm gas.set_equivalence_ratio(0.8, fuel, 'O2:1.0, N2:3.773')
def test_custom(self): rxn = ct.CustomReaction(equation=self._equation, rate=lambda T: 38.7 * T**2.7 * exp(-3150.15428/T), kinetics=self.gas) self.check_rxn(rxn)
def test_custom_lambda(self): # check instantiation from keywords / rate provided as lambda function rxn = ct.CustomReaction(equation=self._equation, rate=lambda T: 38.7 * T**2.7 * exp(-3150.15428/T), kinetics=self.gas) self.check_rxn(rxn)
def test_from_func(self): f = ct.Func1(self._rate) rxn = ct.CustomReaction(equation=self._equation, rate=f, kinetics=self.gas) self.check_rxn(rxn)
def test_from_func1(self): # check instantiation from keywords / rate provided as func1 f = ct.Func1(self._rate) rxn = ct.CustomReaction(equation=self._equation, rate=f, kinetics=self.gas) self.check_rxn(rxn)