mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[Python] Remove most weakproxy sentinels
This commit is contained in:
parent
4d3025587f
commit
3e036b7c84
@ -153,7 +153,6 @@ cdef class Domain1D:
|
|||||||
cdef shared_ptr[CxxDomain1D] _domain
|
cdef shared_ptr[CxxDomain1D] _domain
|
||||||
cdef CxxDomain1D* domain
|
cdef CxxDomain1D* domain
|
||||||
cdef _SolutionBase gas
|
cdef _SolutionBase gas
|
||||||
cdef object _weakref_proxy
|
|
||||||
cdef public pybool have_user_tolerances
|
cdef public pybool have_user_tolerances
|
||||||
|
|
||||||
cdef class Boundary1D(Domain1D):
|
cdef class Boundary1D(Domain1D):
|
||||||
|
@ -9,23 +9,16 @@ from ._utils cimport stringify, pystr, anymap_to_py
|
|||||||
from ._utils import CanteraError
|
from ._utils import CanteraError
|
||||||
from cython.operator import dereference as deref
|
from cython.operator import dereference as deref
|
||||||
|
|
||||||
# Need a pure-python class to store weakrefs to
|
|
||||||
class _WeakrefProxy:
|
|
||||||
pass
|
|
||||||
|
|
||||||
cdef class Domain1D:
|
cdef class Domain1D:
|
||||||
_domain_type = "none"
|
_domain_type = "none"
|
||||||
def __cinit__(self, _SolutionBase phase not None, *args, **kwargs):
|
def __cinit__(self, _SolutionBase phase not None, *args, **kwargs):
|
||||||
self.domain = NULL
|
self.domain = NULL
|
||||||
|
|
||||||
def __init__(self, phase, *args, **kwargs):
|
def __init__(self, phase, *args, **kwargs):
|
||||||
self._weakref_proxy = _WeakrefProxy()
|
|
||||||
if self.domain is NULL:
|
if self.domain is NULL:
|
||||||
raise TypeError("Can't instantiate abstract class Domain1D.")
|
raise TypeError("Can't instantiate abstract class Domain1D.")
|
||||||
|
|
||||||
self.gas = phase
|
self.gas = phase
|
||||||
# Block species from being added to the phase as long as this object exists
|
|
||||||
self.gas._references[self._weakref_proxy] = True
|
|
||||||
self.set_default_tolerances()
|
self.set_default_tolerances()
|
||||||
|
|
||||||
property phase:
|
property phase:
|
||||||
@ -424,7 +417,6 @@ cdef class ReactingSurface1D(Boundary1D):
|
|||||||
_domain_type = "reacting-surface"
|
_domain_type = "reacting-surface"
|
||||||
|
|
||||||
def __init__(self, _SolutionBase phase, name=None):
|
def __init__(self, _SolutionBase phase, name=None):
|
||||||
self._weakref_proxy = _WeakrefProxy()
|
|
||||||
gas = None
|
gas = None
|
||||||
for val in phase._adjacent.values():
|
for val in phase._adjacent.values():
|
||||||
if val.phase_of_matter == "gas":
|
if val.phase_of_matter == "gas":
|
||||||
@ -435,8 +427,6 @@ cdef class ReactingSurface1D(Boundary1D):
|
|||||||
super().__init__(gas, name=name)
|
super().__init__(gas, name=name)
|
||||||
|
|
||||||
self.surface = phase
|
self.surface = phase
|
||||||
# Block species from being added to the phase as long as this object exists
|
|
||||||
self.surface._references[self._weakref_proxy] = True
|
|
||||||
|
|
||||||
property phase:
|
property phase:
|
||||||
"""
|
"""
|
||||||
|
@ -142,6 +142,11 @@ class DustyGas(DustyGasTransport, Kinetics, ThermoPhase):
|
|||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
|
|
||||||
|
# A pure-Python class to store weakrefs to
|
||||||
|
class _WeakrefProxy:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Quantity:
|
class Quantity:
|
||||||
"""
|
"""
|
||||||
A class representing a specific quantity of a `Solution`. In addition to the
|
A class representing a specific quantity of a `Solution`. In addition to the
|
||||||
@ -382,11 +387,6 @@ for _attr in dir(Solution):
|
|||||||
setattr(Quantity, _attr, _prop(_attr))
|
setattr(Quantity, _attr, _prop(_attr))
|
||||||
|
|
||||||
|
|
||||||
# A pure-Python class to store weakrefs to
|
|
||||||
class _WeakrefProxy:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class SolutionArray(SolutionArrayBase):
|
class SolutionArray(SolutionArrayBase):
|
||||||
"""
|
"""
|
||||||
A class providing a convenient interface for representing many thermodynamic
|
A class providing a convenient interface for representing many thermodynamic
|
||||||
@ -583,8 +583,6 @@ class SolutionArray(SolutionArrayBase):
|
|||||||
|
|
||||||
def __init__(self, phase, shape=(0,), states=None, extra=None, meta={}, init=True):
|
def __init__(self, phase, shape=(0,), states=None, extra=None, meta={}, init=True):
|
||||||
self._phase = phase
|
self._phase = phase
|
||||||
self._weakref_proxy = _WeakrefProxy()
|
|
||||||
phase._references[self._weakref_proxy] = True
|
|
||||||
if not init:
|
if not init:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -52,5 +52,4 @@ cdef extern from "cantera/equil/MultiPhase.h" namespace "Cantera":
|
|||||||
cdef class Mixture:
|
cdef class Mixture:
|
||||||
cdef CxxMultiPhase* mix
|
cdef CxxMultiPhase* mix
|
||||||
cdef list _phases
|
cdef list _phases
|
||||||
cdef object _weakref_proxy
|
|
||||||
cpdef int element_index(self, element) except *
|
cpdef int element_index(self, element) except *
|
||||||
|
@ -8,10 +8,6 @@ from .solutionbase cimport *
|
|||||||
from .thermo cimport *
|
from .thermo cimport *
|
||||||
from ._utils cimport *
|
from ._utils cimport *
|
||||||
|
|
||||||
# Need a pure-python class to store weakrefs to
|
|
||||||
class _WeakrefProxy:
|
|
||||||
pass
|
|
||||||
|
|
||||||
cdef class Mixture:
|
cdef class Mixture:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -44,7 +40,6 @@ cdef class Mixture:
|
|||||||
def __cinit__(self, phases):
|
def __cinit__(self, phases):
|
||||||
self.mix = new CxxMultiPhase()
|
self.mix = new CxxMultiPhase()
|
||||||
self._phases = []
|
self._phases = []
|
||||||
self._weakref_proxy = _WeakrefProxy()
|
|
||||||
|
|
||||||
cdef _SolutionBase phase
|
cdef _SolutionBase phase
|
||||||
if isinstance(phases[0], _SolutionBase):
|
if isinstance(phases[0], _SolutionBase):
|
||||||
@ -53,7 +48,6 @@ cdef class Mixture:
|
|||||||
|
|
||||||
for phase,moles in phases:
|
for phase,moles in phases:
|
||||||
# Block species from being added to the phase as long as this object exists
|
# Block species from being added to the phase as long as this object exists
|
||||||
phase._references[self._weakref_proxy] = True
|
|
||||||
self.mix.addPhase(phase.thermo, moles)
|
self.mix.addPhase(phase.thermo, moles)
|
||||||
self._phases.append(phase)
|
self._phases.append(phase)
|
||||||
|
|
||||||
|
@ -223,7 +223,6 @@ cdef class ReactorBase:
|
|||||||
cdef list _outlets
|
cdef list _outlets
|
||||||
cdef list _walls
|
cdef list _walls
|
||||||
cdef list _surfaces
|
cdef list _surfaces
|
||||||
cdef object _weakref_proxy
|
|
||||||
cdef public dict node_attr
|
cdef public dict node_attr
|
||||||
"""
|
"""
|
||||||
A dictionary containing draw attributes for the representation of the reactor as a
|
A dictionary containing draw attributes for the representation of the reactor as a
|
||||||
|
@ -14,10 +14,6 @@ from .drawnetwork import *
|
|||||||
|
|
||||||
_reactor_counts = _defaultdict(int)
|
_reactor_counts = _defaultdict(int)
|
||||||
|
|
||||||
# Need a pure-python class to store weakrefs to
|
|
||||||
class _WeakrefProxy:
|
|
||||||
pass
|
|
||||||
|
|
||||||
cdef class ReactorBase:
|
cdef class ReactorBase:
|
||||||
"""
|
"""
|
||||||
Common base class for reactors and reservoirs.
|
Common base class for reactors and reservoirs.
|
||||||
@ -41,8 +37,6 @@ cdef class ReactorBase:
|
|||||||
|
|
||||||
def __init__(self, _SolutionBase contents=None, name=None, *, volume=None,
|
def __init__(self, _SolutionBase contents=None, name=None, *, volume=None,
|
||||||
node_attr=None):
|
node_attr=None):
|
||||||
|
|
||||||
self._weakref_proxy = _WeakrefProxy()
|
|
||||||
self._inlets = []
|
self._inlets = []
|
||||||
self._outlets = []
|
self._outlets = []
|
||||||
self._walls = []
|
self._walls = []
|
||||||
@ -61,8 +55,6 @@ cdef class ReactorBase:
|
|||||||
properties and kinetic rates for this reactor.
|
properties and kinetic rates for this reactor.
|
||||||
"""
|
"""
|
||||||
self._thermo = solution
|
self._thermo = solution
|
||||||
# Block species from being added to the phase as long as this object exists
|
|
||||||
self._thermo._references[self._weakref_proxy] = True
|
|
||||||
self.rbase.setSolution(solution._base)
|
self.rbase.setSolution(solution._base)
|
||||||
|
|
||||||
property type:
|
property type:
|
||||||
|
@ -122,4 +122,3 @@ cdef class _SolutionBase:
|
|||||||
cdef class SolutionArrayBase:
|
cdef class SolutionArrayBase:
|
||||||
cdef shared_ptr[CxxSolutionArray] _base
|
cdef shared_ptr[CxxSolutionArray] _base
|
||||||
cdef CxxSolutionArray* base
|
cdef CxxSolutionArray* base
|
||||||
cdef public object _weakref_proxy
|
|
||||||
|
@ -270,10 +270,9 @@ cdef class ThermoPhase(_SolutionBase):
|
|||||||
# In composite objects, the ThermoPhase constructor needs to be called first
|
# In composite objects, the ThermoPhase constructor needs to be called first
|
||||||
# to prevent instantiation of stand-alone 'Kinetics' or 'Transport' objects.
|
# to prevent instantiation of stand-alone 'Kinetics' or 'Transport' objects.
|
||||||
# The following is used as a sentinel. After initialization, the _references
|
# The following is used as a sentinel. After initialization, the _references
|
||||||
# object is used to track whether the ThermoPhase is being used by a `Reactor`,
|
# object is used to track whether the ThermoPhase is being used by other
|
||||||
# `Domain1D`, or `Mixture` object and to prevent species from being added to the
|
# objects that require the number of species to remain constant and do not
|
||||||
# ThermoPhase if so, since these objects require the number of species to remain
|
# have C++ implementations (e.g. Quantity objects).
|
||||||
# constant.
|
|
||||||
self._references = weakref.WeakKeyDictionary()
|
self._references = weakref.WeakKeyDictionary()
|
||||||
# validate plasma phase
|
# validate plasma phase
|
||||||
self._enable_plasma = False
|
self._enable_plasma = False
|
||||||
@ -583,8 +582,7 @@ cdef class ThermoPhase(_SolutionBase):
|
|||||||
"""
|
"""
|
||||||
if self._references:
|
if self._references:
|
||||||
raise CanteraError('Cannot add species to ThermoPhase object because it'
|
raise CanteraError('Cannot add species to ThermoPhase object because it'
|
||||||
' is being used by another object,\nsuch as a Reactor, Domain1D (flame),'
|
' is being used by a Quantity object.')
|
||||||
' SolutionArray, Quantity, or Mixture object.')
|
|
||||||
self.thermo.addUndefinedElements()
|
self.thermo.addUndefinedElements()
|
||||||
self.thermo.addSpecies(species._species)
|
self.thermo.addSpecies(species._species)
|
||||||
species._phase = self
|
species._phase = self
|
||||||
|
Loading…
Reference in New Issue
Block a user