[Cython/1D] Completed Boundary1D mass/mole fraction property interface

Added getter for mole fractions and setter for mass fractions. This
requires that the boundary object hold a reference to the thermo object.

Resolves Issue 143.
This commit is contained in:
Ray Speth 2013-03-04 17:31:35 +00:00
parent 229ef825f0
commit d4fb33c688
2 changed files with 61 additions and 14 deletions

View file

@ -154,15 +154,24 @@ cdef class Domain1D:
cdef class Boundary1D(Domain1D):
""" Base class for boundary domains. """
"""
Base class for boundary domains.
:param phase:
The (gas) phase corresponding to the adjacent flow domain
"""
cdef CxxBdry1D* boundary
cdef _SolutionBase phase
def __cinit__(self, *args, **kwargs):
self.boundary = NULL
def __init__(self, *args, **kwargs):
def __init__(self, *args, _SolutionBase phase, **kwargs):
if self.boundary is NULL:
raise TypeError("Can't instantiate abstract class Boundary1D.")
self.domain = <CxxDomain1D*>(self.boundary)
self.phase = phase
Domain1D.__init__(self, *args, **kwargs)
property T:
@ -180,7 +189,14 @@ cdef class Boundary1D(Domain1D):
self.boundary.setMdot(mdot)
property X:
""" Species mole fractions at this boundary. """
"""
Species mole fractions at this boundary. May be set as either a string
or as an array.
"""
def __get__(self):
self.phase.TPY = self.phase.T, self.phase.P, self.Y
return self.phase.X
def __set__(self, X):
cdef np.ndarray[np.double_t, ndim=1] data
if isinstance(X, (str, unicode)):
@ -190,7 +206,10 @@ cdef class Boundary1D(Domain1D):
self.boundary.setMoleFractions(&data[0])
property Y:
""" Species mass fractions at this boundary. """
"""
Species mass fractions at this boundary. May be set as either a string
or as an array.
"""
def __get__(self):
cdef int nsp = self.boundary.nSpecies()
cdef np.ndarray[np.double_t, ndim=1] Y = np.empty(nsp)
@ -199,6 +218,10 @@ cdef class Boundary1D(Domain1D):
Y[k] = self.boundary.massFraction(k)
return Y
def __set__(self, Y):
self.phase.TPY = self.phase.T, self.phase.P, Y
self.X = self.phase.X
cdef class Inlet1D(Boundary1D):
"""
@ -978,8 +1001,8 @@ class FreeFlame(FlameBase):
the flame. The three domains comprising the stack are stored as
``self.inlet``, ``self.flame``, and ``self.outlet``.
"""
self.inlet = Inlet1D(name='reactants')
self.outlet = Outlet1D(name='products')
self.inlet = Inlet1D(name='reactants', phase=gas)
self.outlet = Outlet1D(name='products', phase=gas)
self.flame = FreeFlow(gas, name='flame')
super().__init__((self.inlet, self.flame, self.outlet), gas, grid)
@ -1029,9 +1052,9 @@ class BurnerFlame(FlameBase):
stack are stored as ``self.burner``, ``self.flame``, and
``self.outlet``.
"""
self.burner = Inlet1D(name='burner')
self.burner = Inlet1D(name='burner', phase=gas)
self.burner.T = gas.T
self.outlet = Outlet1D(name='outlet')
self.outlet = Outlet1D(name='outlet', phase=gas)
self.flame = AxisymmetricStagnationFlow(gas, name='flame')
super().__init__((self.burner, self.flame, self.outlet), gas, grid)
@ -1081,10 +1104,10 @@ class CounterflowDiffusionFlame(FlameBase):
stack are stored as ``self.fuel_inlet``, ``self.flame``, and
``self.oxidizer_inlet``.
"""
self.fuel_inlet = Inlet1D(name='fuel_inlet')
self.fuel_inlet = Inlet1D(name='fuel_inlet', phase=gas)
self.fuel_inlet.T = gas.T
self.oxidizer_inlet = Inlet1D(name='oxidizer_inlet')
self.oxidizer_inlet = Inlet1D(name='oxidizer_inlet', phase=gas)
self.oxidizer_inlet.T = gas.T
self.flame = AxisymmetricStagnationFlow(gas, name='flame')
@ -1194,15 +1217,15 @@ class ImpingingJet(FlameBase):
created to represent the flow. The three domains comprising the stack
are stored as ``self.inlet``, ``self.flame``, and ``self.surface``.
"""
self.inlet = Inlet1D(name='inlet')
self.inlet = Inlet1D(name='inlet', phase=gas)
self.inlet.T = gas.T
self.flame = AxisymmetricStagnationFlow(gas, name='flame')
if surface is None:
self.surface = Surface1D(name='surface')
self.surface = Surface1D(name='surface', phase=gas)
self.surface.T = gas.T
else:
self.surface = ReactingSurface1D(name='surface')
self.surface = ReactingSurface1D(name='surface', phase=gas)
self.surface.set_kinetics(surface)
self.surface.T = surface.T

View file

@ -20,9 +20,33 @@ class TestOnedim(utilities.CanteraTest):
solid = ct.Solution('diamond.xml', 'diamond')
interface = ct.Solution('diamond.xml', 'diamond_100', (gas, solid))
surface = ct.ReactingSurface1D()
surface = ct.ReactingSurface1D(phase=gas)
surface.set_kinetics(interface)
def test_boundaryProperties(self):
gas1 = ct.Solution('h2o2.xml')
gas2 = ct.Solution('h2o2.xml')
inlet = ct.Inlet1D(name='something', phase=gas1)
flame = ct.FreeFlow(gas1)
sim = ct.Sim1D((inlet, flame))
self.assertEqual(inlet.name, 'something')
gas2.TPX = 400, 101325, 'H2:0.3, O2:0.5, AR:0.2'
Xref = gas2.X
Yref = gas2.Y
inlet.Y = Yref
self.assertArrayNear(inlet.Y, Yref)
self.assertArrayNear(inlet.X, Xref)
gas2.TPX = 400, 101325, 'H2:0.5, O2:0.2, AR:0.3'
Xref = gas2.X
Yref = gas2.Y
inlet.X = Xref
self.assertArrayNear(inlet.X, Xref)
self.assertArrayNear(inlet.Y, Yref)
class TestFreeFlame(utilities.CanteraTest):
def create_sim(self, p, Tin, reactants):