From 809223f670c8abf2197aa9db0038a1d594e6bc93 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 18 Mar 2016 15:52:30 -0400 Subject: [PATCH] [1D/Python] Fix range of components used when settings species tolerances Boundaries do not necessarily have species variables, so setting species tolerances will now raise an exception. This approach also avoids making the assumption that the index of the first species equation is 4 in flow domains. --- interfaces/cython/cantera/_cantera.pxd | 3 +-- interfaces/cython/cantera/onedim.pyx | 36 ++++++++++++++------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 07cc19d0fc..a8bd982aa8 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -957,10 +957,10 @@ cdef class ReactorNet: cdef class Domain1D: cdef CxxDomain1D* domain + cdef _SolutionBase gas cdef class Boundary1D(Domain1D): cdef CxxBdry1D* boundary - cdef _SolutionBase phase cdef class Inlet1D(Boundary1D): cdef CxxInlet1D* inlet @@ -982,7 +982,6 @@ cdef class ReactingSurface1D(Boundary1D): cdef class _FlowBase(Domain1D): cdef CxxStFlow* flow - cdef _SolutionBase gas cdef class FreeFlow(_FlowBase): pass diff --git a/interfaces/cython/cantera/onedim.pyx b/interfaces/cython/cantera/onedim.pyx index efa66a362b..b530370c5b 100644 --- a/interfaces/cython/cantera/onedim.pyx +++ b/interfaces/cython/cantera/onedim.pyx @@ -5,13 +5,15 @@ cdef class Domain1D: self.domain = NULL # The signature of this function causes warnings for Sphinx documentation - def __init__(self, *args, name=None, **kwargs): + def __init__(self, _SolutionBase phase, *args, name=None, **kwargs): if self.domain is NULL: raise TypeError("Can't instantiate abstract class Domain1D.") if name is not None: self.name = name + self.gas = phase + property index: """ Index of this domain in a stack. Returns -1 if this domain is not part @@ -60,7 +62,8 @@ cdef class Domain1D: self.domain.setBounds(n, default[0], default[1]) if Y is not None: - for n in range(4, self.n_components): + k0 = self.component_index(self.gas.species_name(0)) + for n in range(k0, k0 + self.gas.n_species): self.domain.setBounds(n, Y[0], Y[1]) for name,(lower,upper) in kwargs.items(): @@ -80,7 +83,8 @@ cdef class Domain1D: self.domain.setSteadyTolerances(default[0], default[1]) if Y is not None: - for n in range(4, self.n_components): + k0 = self.component_index(self.gas.species_name(0)) + for n in range(k0, k0 + self.gas.n_species): self.domain.setSteadyTolerances(Y[0], Y[1], n) for name,(lower,upper) in kwargs.items(): @@ -100,7 +104,8 @@ cdef class Domain1D: self.domain.setTransientTolerances(default[0], default[1]) if Y is not None: - for n in range(4, self.n_components): + k0 = self.component_index(self.gas.species_name(0)) + for n in range(k0, k0 + self.gas.n_species): self.domain.setTransientTolerances(Y[0], Y[1], n) for name,(lower,upper) in kwargs.items(): @@ -171,12 +176,10 @@ cdef class Boundary1D(Domain1D): self.boundary = NULL # The signature of this function causes warnings for Sphinx documentation - def __init__(self, *args, _SolutionBase phase, **kwargs): + def __init__(self, *args, **kwargs): if self.boundary is NULL: raise TypeError("Can't instantiate abstract class Boundary1D.") self.domain = (self.boundary) - self.phase = phase - Domain1D.__init__(self, *args, **kwargs) property T: @@ -199,12 +202,12 @@ cdef class Boundary1D(Domain1D): or as an array. """ def __get__(self): - self.phase.TPY = self.phase.T, self.phase.P, self.Y - return self.phase.X + self.gas.TPY = self.gas.T, self.gas.P, self.Y + return self.gas.X def __set__(self, X): - self.phase.TPX = None, None, X - cdef np.ndarray[np.double_t, ndim=1] data = self.phase.X + self.gas.TPX = None, None, X + cdef np.ndarray[np.double_t, ndim=1] data = self.gas.X self.boundary.setMoleFractions(&data[0]) property Y: @@ -221,8 +224,8 @@ cdef class Boundary1D(Domain1D): return Y def __set__(self, Y): - self.phase.TPY = self.phase.T, self.phase.P, Y - self.X = self.phase.X + self.gas.TPY = self.gas.T, self.gas.P, Y + self.X = self.gas.X cdef class Inlet1D(Boundary1D): @@ -321,12 +324,11 @@ cdef class _FlowBase(Domain1D): def __cinit__(self, *args, **kwargs): self.flow = NULL - def __init__(self, _SolutionBase thermo, *args, **kwargs): + def __init__(self, *args, **kwargs): self.domain = (self.flow) super().__init__(*args, **kwargs) - if not thermo.transport_model: - thermo.transport_model = 'Mix' - self.gas = thermo + if not self.gas.transport_model: + self.gas.transport_model = 'Mix' self.flow.setKinetics(deref(self.gas.kinetics)) self.flow.setTransport(deref(self.gas.transport)) self.P = self.gas.P