Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added method from arrhenius to Arrhenius ep #1097

Merged
merged 4 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions rmgpy/data/kinetics/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,20 +1037,14 @@ def addKineticsRulesFromTrainingSet(self, thermoDatabase=None):
label = ';'.join([g.label for g in template]),
item=Reaction(reactants=[g.item for g in template],
products=[]),
data = ArrheniusEP(
A = deepcopy(data.A),
n = deepcopy(data.n),
alpha = 0,
E0 = deepcopy(data.Ea),
Tmin = deepcopy(data.Tmin),
Tmax = deepcopy(data.Tmax),
comment = "{0} from training reaction {1}".format(';'.join([g.label for g in template]), entry.index),
),
data = data.toArrheniusEP(),
rank = entry.rank,
reference=entry.reference,
shortDesc="Rate rule generated from training reaction {0}. ".format(entry.index) + entry.shortDesc,
longDesc="Rate rule generated from training reaction {0}. ".format(entry.index) + entry.longDesc,
)
new_entry.data.comment = "{0} from training reaction {1}".format(';'.join([g.label for g in template]), entry.index)

new_entry.data.A.value_si /= entry.item.degeneracy
try:
self.rules.entries[new_entry.label].append(new_entry)
Expand Down Expand Up @@ -1091,20 +1085,14 @@ def addKineticsRulesFromTrainingSet(self, thermoDatabase=None):
label = ';'.join([g.label for g in template]),
item=Reaction(reactants=[g.item for g in template],
products=[]),
data = ArrheniusEP(
A = deepcopy(data.A),
n = deepcopy(data.n),
alpha = 0,
E0 = deepcopy(data.Ea),
Tmin = deepcopy(data.Tmin),
Tmax = deepcopy(data.Tmax),
comment = "{0} from training reaction {1}".format(';'.join([g.label for g in template]), entry.index),
),
data = data.toArrheniusEP(),
rank = entry.rank,
reference=entry.reference,
shortDesc="Rate rule generated from training reaction {0}. ".format(entry.index) + entry.shortDesc,
longDesc="Rate rule generated from training reaction {0}. ".format(entry.index) + entry.longDesc,
)
new_entry.data.comment = "{0} from training reaction {1}".format(';'.join([g.label for g in template]), entry.index)

new_entry.data.A.value_si /= new_degeneracy
try:
self.rules.entries[new_entry.label].append(new_entry)
Expand Down
4 changes: 3 additions & 1 deletion rmgpy/data/kinetics/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

from rmgpy.quantity import Quantity, ScalarQuantity
from rmgpy.reaction import Reaction
from rmgpy.kinetics import ArrheniusEP
from rmgpy.kinetics import ArrheniusEP, Arrhenius
from .common import KineticsError, saveEntry

################################################################################
Expand Down Expand Up @@ -77,6 +77,8 @@ def loadEntry(self,
treeDistances=None
):

if isinstance(kinetics,Arrhenius):
kinetics = kinetics.toArrheniusEP()
entry = Entry(
index = index,
label = label,
Expand Down
2 changes: 2 additions & 0 deletions rmgpy/kinetics/arrhenius.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ cdef class Arrhenius(KineticsModel):

cpdef changeRate(self, double factor)

cpdef ArrheniusEP toArrheniusEP(self, double alpha=?, double dHrxn=?)

################################################################################

cdef class ArrheniusEP(KineticsModel):
Expand Down
27 changes: 25 additions & 2 deletions rmgpy/kinetics/arrhenius.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ from libc.math cimport exp, log, sqrt, log10

cimport rmgpy.constants as constants
import rmgpy.quantity as quantity

################################################################################

cdef class Arrhenius(KineticsModel):
Expand Down Expand Up @@ -249,7 +248,29 @@ cdef class Arrhenius(KineticsModel):

# Set the rate parameter to a cantera Arrhenius object
ctReaction.rate = self.toCanteraKinetics()


cpdef ArrheniusEP toArrheniusEP(self, double alpha=0.0, double dHrxn=0.0):
"""
Converts an Arrhenius object to ArrheniusEP

If setting alpha, you need to also input dHrxn, which must be given
in J/mol (and vise versa).
"""

if (bool(alpha) ^ bool(dHrxn)):
raise Exception('If you set alpha or dHrxn in toArrheniusEP, '\
'you need to set the other value to non-zero.')
self.changeT0(1)
aep = ArrheniusEP(A = self.A,
n = self.n,
alpha = alpha,
E0 = (self.Ea.value_si-alpha*dHrxn,'J/mol'),
Tmin = self.Tmin,
Tmax = self.Tmax,
Pmin = self.Pmin,
Pmax = self.Pmax,
comment = self.comment)
return aep
################################################################################

cdef class ArrheniusEP(KineticsModel):
Expand Down Expand Up @@ -367,6 +388,8 @@ cdef class ArrheniusEP(KineticsModel):
T0 = (1,"K"),
Tmin = self.Tmin,
Tmax = self.Tmax,
Pmin = self.Pmin,
Pmax = self.Pmax,
comment = self.comment,
)

Expand Down
24 changes: 24 additions & 0 deletions rmgpy/kinetics/arrheniusTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,30 @@ def test_toCanteraKinetics(self):
self.assertAlmostEqual(ctArrhenius.temperature_exponent, 0.5)
self.assertAlmostEqual(ctArrhenius.activation_energy, 41.84e6)

def test_toArrheniusEP(self):
"""
Tests that the Arrhenius object can be converted to ArrheniusEP
"""
arrRate = self.arrhenius.getRateCoefficient(500)
arrEP = self.arrhenius.toArrheniusEP()
arrEPRate = arrEP.getRateCoefficient(500,10) # the second number should not matter
self.assertAlmostEqual(arrRate,arrEPRate)

def test_toArrheniusEP_with_alpha_and_Hrxn(self):
"""
Tests that the Arrhenius object can be converted to ArrheniusEP given parameters
"""
hrxn = 5
arrRate = self.arrhenius.getRateCoefficient(500)
arrEP = self.arrhenius.toArrheniusEP(alpha=1, dHrxn=hrxn)
self.assertAlmostEqual(1.,arrEP.alpha.value_si)
arrEPRate = arrEP.getRateCoefficient(500,hrxn)
self.assertAlmostEqual(arrRate,arrEPRate)

def test_toArrheniusEP_throws_error_with_just_alpha(self):
with self.assertRaises(Exception):
self.arrhenius.toArrheniusEP(alpha=1)

################################################################################

class TestArrheniusEP(unittest.TestCase):
Expand Down