[Cython] Added molar_fluxes method to DustyGasTransport

This commit is contained in:
Ray Speth 2013-02-01 23:40:13 +00:00
parent 15a45de820
commit 609b3e6e47
3 changed files with 56 additions and 0 deletions

View file

@ -184,6 +184,7 @@ cdef extern from "cantera/transport/DustyGasTransport.h" namespace "Cantera":
void setMeanPoreRadius(double) except +
void setMeanParticleDiameter(double) except +
void setPermeability(double) except +
void getMolarFluxes(double*, double*, double, double*) except +
cdef extern from "cantera/equil/MultiPhase.h" namespace "Cantera":

View file

@ -47,6 +47,7 @@ class TestTransport(utilities.CanteraTest):
class TestDustyGas(utilities.CanteraTest):
def setUp(self):
self.phase = ct.DustyGas('h2o2.xml')
self.phase.TPX = 500.0, ct.one_atm, "O2:2.0, H2:1.0, H2O:1.0"
self.phase.porosity = 0.2
self.phase.tortuosity = 0.3
self.phase.mean_pore_radius = 1e-4
@ -65,3 +66,21 @@ class TestDustyGas(utilities.CanteraTest):
# The other parameters don't have such simple relationships to the diffusion
# coefficients, so we can't test them as easily
def test_molar_fluxes(self):
T1, rho1, Y1 = self.phase.TDY
self.phase.TPX = 500.0, ct.one_atm, "O2:2.0, H2:1.001, H2O:0.999"
T2, rho2, Y2 = self.phase.TDY
fluxes0 = self.phase.molar_fluxes(T1, T1, rho1, rho1, Y1, Y1, 1e-4)
self.assertArrayNear(fluxes0, np.zeros(self.phase.n_species))
fluxes1 = self.phase.molar_fluxes(T1, T2, rho1, rho2, Y1, Y2, 1e-4)
kH2 = self.phase.species_index('H2')
kH2O = self.phase.species_index('H2O')
self.assertTrue(fluxes1[kH2] < 0)
self.assertTrue(fluxes1[kH2O] > 0)
# Not sure why the following condition is not satisfied:
# self.assertNear(sum(fluxes1) / sum(abs(fluxes1)), 0.0)

View file

@ -135,3 +135,39 @@ cdef class DustyGasTransport(Transport):
"""Permeability of the porous medium [m^2]."""
def __set__(self, value):
(<CxxDustyGasTransport*>self.transport).setPermeability(value)
def molar_fluxes(self, T1, T2, rho1, rho2, Y1, Y2, delta):
"""
Get the molar fluxes [kmol/m^2/s], given the thermodynamic state at
two nearby points.
:param T1:
Temperature [K] at the first point
:param T2:
Temperature [K] at the second point
:param rho1:
Density [kg/m^3] at the first point
:param rho2:
Density [kg/m^3] at the second point
:param Y1:
Array of mass fractions at the first point. Length `n_species`.
:param Y2:
Array of mass fractions at the second point. Length `n_species`.
:param delta:
Distance [m] between the two points.
"""
cdef np.ndarray[np.double_t, ndim=1] state1 = np.empty(self.n_species + 2)
cdef np.ndarray[np.double_t, ndim=1] state2 = np.empty(self.n_species + 2)
cdef np.ndarray[np.double_t, ndim=1] fluxes = np.empty(self.n_species)
state1[0] = T1
state1[1] = rho1
state1[2:] = Y1
state2[0] = T2
state2[1] = rho2
state2[2:] = Y2
(<CxxDustyGasTransport*>self.transport).getMolarFluxes(&state1[0],
&state2[0], delta, &fluxes[0])
return fluxes