Skip to content

Commit e9b1abe

Browse files
rwestJacksonBurns
authored andcommitted
In Reaction.to_cantera, don't make kinetics twice.
The method calls the appropriate set_cantera_kinetics() method at the end, so we don't want to make them before then, because it's wasteful to do it twice. We just need to create a cantera kinetics object of the correct type. This was already done for several types of kinetics, but not all.
1 parent 387bfa3 commit e9b1abe

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

rmgpy/reaction.py

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ def to_cantera(self, species_list=None, use_chemkin_identifier=False):
320320
ct_collider[self.specific_collider.to_chemkin() if use_chemkin_identifier else self.specific_collider.label] = 1
321321

322322
if self.kinetics:
323+
# Create the Cantera reaction object,
324+
# with the correct type of kinetics object
325+
# but don't actually set its kinetics (we do that at the end)
323326
if isinstance(self.kinetics, Arrhenius):
324327
# Create an Elementary Reaction
325328
if isinstance(self.kinetics, SurfaceArrhenius): # SurfaceArrhenius inherits from Arrhenius
@@ -348,61 +351,47 @@ def to_cantera(self, species_list=None, use_chemkin_identifier=False):
348351
ct_reaction = ct.ThreeBodyReaction(reactants=ct_reactants, products=ct_products)
349352

350353
elif isinstance(self.kinetics, Troe):
351-
high_rate = self.kinetics.arrheniusHigh.to_cantera_kinetics(arrhenius_class=True)
352-
low_rate = self.kinetics.arrheniusLow.to_cantera_kinetics(arrhenius_class=True)
353-
A = self.kinetics.alpha
354-
T3 = self.kinetics.T3.value_si
355-
T1 = self.kinetics.T1.value_si
356-
357-
if self.kinetics.T2 is None:
358-
rate = ct.TroeRate(
359-
high=high_rate, low=low_rate, falloff_coeffs=[A, T3, T1]
360-
)
361-
else:
362-
T2 = self.kinetics.T2.value_si
363-
rate = ct.TroeRate(
364-
high=high_rate, low=low_rate, falloff_coeffs=[A, T3, T1, T2]
365-
)
366-
367354
if ct_collider is not None:
368355
ct_reaction = ct.FalloffReaction(
369356
reactants=ct_reactants,
370357
products=ct_products,
371358
tbody=ct_collider,
372-
rate=rate,
359+
rate=ct.TroeRate()
373360
)
374361
else:
375362
ct_reaction = ct.FalloffReaction(
376-
reactants=ct_reactants, products=ct_products, rate=rate
363+
reactants=ct_reactants,
364+
products=ct_products,
365+
rate=ct.TroeRate()
377366
)
378367

379-
380-
elif isinstance(self.kinetics, StickingCoefficient):
381-
rate = self.kinetics.to_cantera_kinetics()
382-
ct_reaction = ct.Reaction(equation=str(self), rate=rate)
383-
384368
elif isinstance(self.kinetics, Lindemann):
385-
high_rate = self.kinetics.arrheniusHigh.to_cantera_kinetics(arrhenius_class=True)
386-
low_rate = self.kinetics.arrheniusLow.to_cantera_kinetics(arrhenius_class=True)
387-
falloff = []
388-
rate = ct.LindemannRate(low_rate, high_rate, falloff)
389369
if ct_collider is not None:
390370
ct_reaction = ct.FalloffReaction(
391371
reactants=ct_reactants,
392372
products=ct_products,
393373
tbody=ct_collider,
394-
rate=rate,
374+
rate=ct.LindemannRate()
395375
)
396376
else:
397377
ct_reaction = ct.FalloffReaction(
398-
reactants=ct_reactants, products=ct_products, rate=rate
378+
reactants=ct_reactants,
379+
products=ct_products,
380+
rate=ct.LindemannRate()
399381
)
400382

383+
elif isinstance(self.kinetics, SurfaceArrhenius):
384+
ct_reaction = ct.InterfaceReaction(reactants=ct_reactants,
385+
products=ct_products,
386+
rate=ct.InterfaceArrheniusRate())
387+
401388
elif isinstance(self.kinetics, StickingCoefficient):
402-
ct_reaction = ct.Reaction(reactants=ct_reactants, products=ct_products, rate=ct.StickingArrheniusRate())
389+
ct_reaction = ct.Reaction(reactants=ct_reactants,
390+
products=ct_products,
391+
rate=ct.StickingArrheniusRate())
403392

404393
else:
405-
raise NotImplementedError('Unable to set cantera kinetics for {0}'.format(self.kinetics))
394+
raise NotImplementedError(f"Unable to set cantera kinetics for {self.kinetics}")
406395

407396
# Set reversibility, duplicate, and ID attributes
408397
if isinstance(ct_reaction, list):
@@ -417,6 +406,7 @@ def to_cantera(self, species_list=None, use_chemkin_identifier=False):
417406
ct_reaction.duplicate = self.duplicate
418407
ct_reaction.ID = str(self.index)
419408

409+
# Now we set the kinetics.
420410
self.kinetics.set_cantera_kinetics(ct_reaction, species_list)
421411

422412
return ct_reaction

0 commit comments

Comments
 (0)