Skip to content

Commit

Permalink
Update ExtensibleReaction example to model additional methods
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Apr 17, 2023
1 parent 4d7c731 commit 659df28
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions samples/python/kinetics/custom_reactions.py
Expand Up @@ -52,27 +52,38 @@ def update(self, gas):
class ExtensibleArrhenius(ct.ExtensibleRate):
__slots__ = ("A", "b", "Ea_R")
def set_parameters(self, params, units):
self.A = params["A"]
self.A = params.convert_rate_coeff("A", units)
self.b = params["b"]
self.Ea_R = params["Ea_R"]
self.Ea_R = params.convert_activation_energy("Ea", "K")

def get_parameters(self, params):
params.set_quantity("A", self.A, self.conversion_units)
params["b"] = self.b
params.set_activation_energy("Ea", self.Ea_R, "K")

def validate(self, equation, soln):
if self.A < 0:
raise ValueError(f"Found negative 'A' for reaction {equation}")

def eval(self, data):
return self.A * data.T**self.b * exp(-self.Ea_R/data.T)

extensible_yaml2 = """
equation: H2 + O <=> H + OH
type: extensible-Arrhenius
A: 38.7
units: {length: cm, quantity: mol, activation-energy: cal/mol}
A: 3.87e+04
b: 2.7
Ea_R: 3150.1542797022735
Ea: 6260.0
"""

extensible_yaml4 = """
equation: H2O2 + O <=> HO2 + OH
type: extensible-Arrhenius
A: 9630.0
units: {length: cm, quantity: mol, activation-energy: cal/mol}
A: 9.63e+06
b: 2
Ea_R: 2012.8781339950629
Ea: 4000
"""

extensible_reactions = gas0.reactions()
Expand Down

0 comments on commit 659df28

Please sign in to comment.