Skip to content

Commit f787cae

Browse files
committed
[Python] Add three-body-Arrhenius to API
1 parent 6c96f6c commit f787cae

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

interfaces/cython/cantera/_cantera.pxd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,17 @@ cdef extern from "cantera/kinetics/Reaction.h" namespace "Cantera":
546546
CxxCustomFunc1Rate()
547547
void setRateFunction(shared_ptr[CxxFunc1]) except +translate_exception
548548

549+
cdef cppclass CxxThreeBodyBase "Cantera::ThreeBodyBase":
550+
void getEfficiencies(CxxAnyMap)
551+
void efficiency(string&) except +translate_exception
552+
double defaultEfficiency()
553+
double thirdBodyConcentration()
554+
555+
cdef cppclass CxxThreeBodyArrheniusRate "Cantera::ThreeBodyArrheniusRate" (CxxReactionRate, CxxArrhenius, CxxThreeBodyBase):
556+
CxxThreeBodyArrheniusRate()
557+
CxxThreeBodyArrheniusRate(CxxAnyMap) except +translate_exception
558+
CxxThreeBodyArrheniusRate(double, double, double)
559+
549560
cdef cppclass CxxCoverageBase "Cantera::CoverageBase":
550561
void getCoverageDependencies(CxxAnyMap)
551562
void setCoverageDependencies(CxxAnyMap) except +translate_exception
@@ -1407,6 +1418,9 @@ cdef class CustomRate(ReactionRate):
14071418
cdef CxxCustomFunc1Rate* cxx_object(self)
14081419
cdef Func1 _rate_func
14091420

1421+
cdef class ThreeBodyRateBase(ArrheniusRateBase):
1422+
cdef CxxThreeBodyBase* threebody
1423+
14101424
cdef class InterfaceRateBase(ArrheniusRateBase):
14111425
cdef CxxCoverageBase* coverage
14121426

interfaces/cython/cantera/reaction.pyx

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,64 @@ cdef class CustomRate(ReactionRate):
685685
self.cxx_object().setRateFunction(self._rate_func._func)
686686

687687

688+
cdef class ThreeBodyRateBase(ArrheniusRateBase):
689+
"""
690+
Base class collecting commonly used features of Arrhenius-type rate objects
691+
that include three.
692+
"""
693+
694+
property efficiencies:
695+
"""
696+
Get a `dict` defining non-default third-body efficiencies for this
697+
reaction, where the keys are the species names and the values are the
698+
efficiencies.
699+
"""
700+
def __get__(self):
701+
cdef CxxAnyMap cxx_effs
702+
self.threebody.getEfficiencies(cxx_effs)
703+
return anymap_to_dict(cxx_effs)
704+
705+
property default_efficiency:
706+
"""
707+
Get the default third-body efficiency associated with this rate, used for
708+
species used for species not in `efficiencies`.
709+
"""
710+
def __get__(self):
711+
return self.threebody.defaultEfficiency()
712+
713+
property third_body_concentration:
714+
"""Concentration of third-body collider"""
715+
def __get__(self):
716+
return self.threebody.thirdBodyConcentration()
717+
718+
719+
cdef class ThreeBodyArrheniusRate(ThreeBodyRateBase):
720+
r"""
721+
A reaction rate coefficient which depends on temperature and the concentration of
722+
a third-body collider
723+
"""
724+
_reaction_rate_type = "three-body-Arrhenius"
725+
726+
def __cinit__(self, A=None, b=None, Ea=None, input_data=None, init=True):
727+
728+
if init:
729+
self._cinit(input_data, A=A, b=b, Ea=Ea)
730+
731+
def _from_dict(self, dict input_data):
732+
self._rate.reset(new CxxThreeBodyArrheniusRate(dict_to_anymap(input_data)))
733+
734+
def _from_parameters(self, A, b, Ea):
735+
self._rate.reset(new CxxThreeBodyArrheniusRate(A, b, Ea))
736+
737+
cdef set_cxx_object(self):
738+
self.rate = self._rate.get()
739+
self.base = <CxxArrhenius*>self.rate
740+
self.threebody = <CxxThreeBodyBase*>self.cxx_object()
741+
742+
cdef CxxThreeBodyArrheniusRate* cxx_object(self):
743+
return <CxxThreeBodyArrheniusRate*>self.rate
744+
745+
688746
cdef class InterfaceRateBase(ArrheniusRateBase):
689747
"""
690748
Base class collecting commonly used features of Arrhenius-type rate objects
@@ -718,7 +776,6 @@ cdef class InterfaceRateBase(ArrheniusRateBase):
718776
return anymap_to_dict(cxx_deps)
719777
def __set__(self, dict deps):
720778
cdef CxxAnyMap cxx_deps = dict_to_anymap(deps)
721-
722779
self.coverage.setCoverageDependencies(cxx_deps)
723780

724781
def set_species(self, species):

0 commit comments

Comments
 (0)