Skip to content

Commit

Permalink
[Python] Allow use of '__slots__' in Extensible classes
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Jan 21, 2023
1 parent f687bfd commit 199c98b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions interfaces/cython/cantera/reaction.pxd
Expand Up @@ -257,9 +257,11 @@ cdef class CustomRate(ReactionRate):
cdef Func1 _rate_func # prevent premature garbage collection

cdef class ExtensibleRate(ReactionRate):
cdef public list _delegates
cdef set_cxx_object(self, CxxReactionRate* rate=*)

cdef class ExtensibleRateData:
cdef public list _delegates
cdef set_cxx_object(self, CxxReactionDataDelegator* rate)

cdef class InterfaceRateBase(ArrheniusRateBase):
Expand Down
1 change: 1 addition & 0 deletions interfaces/cython/cantera/reactor.pxd
Expand Up @@ -215,6 +215,7 @@ cdef class FlowReactor(Reactor):
pass

cdef class ExtensibleReactor(Reactor):
cdef public _delegates
cdef CxxReactorAccessor* accessor

cdef class ReactorSurface:
Expand Down
2 changes: 2 additions & 0 deletions samples/python/kinetics/custom_reactions.py
Expand Up @@ -33,6 +33,7 @@
# construct reactions based on ExtensibleRate: replace 2nd reaction with equivalent
# ExtensibleRate
class ExtensibleArrheniusData(ct.ExtensibleRateData):
__slots__ = ("T",)
def __init__(self):
self.T = None

Expand All @@ -46,6 +47,7 @@ def replace_update(self, gas):

@ct.extension(name="extensible-Arrhenius", data=ExtensibleArrheniusData)
class ExtensibleArrhenius(ct.ExtensibleRate):
__slots__ = ("A", "b", "Ea_R")
def after_set_parameters(self, params, units):
self.A = params["A"]
self.b = params["b"]
Expand Down
4 changes: 4 additions & 0 deletions test/python/user_ext.py
@@ -1,12 +1,16 @@
import cantera as ct

class SquareRateData(ct.ExtensibleRateData):
__slots__ = ("Tsquared",)

def replace_update(self, gas):
self.Tsquared = gas.T**2
return True

@ct.extension(name="square-rate", data=SquareRateData)
class SquareRate(ct.ExtensibleRate):
__slots__ = ("A",)

def after_set_parameters(self, node, units):
self.A = node["A"]

Expand Down

0 comments on commit 199c98b

Please sign in to comment.