[Cython] Added interface to Reactor.component_index

This commit is contained in:
Ray Speth 2013-05-23 19:32:25 +00:00
parent 85b763538c
commit 57685799ad
3 changed files with 24 additions and 0 deletions

View file

@ -17,6 +17,7 @@ cdef extern from "cantera/base/ctml.h" namespace "ctml":
cdef extern from "cantera/base/global.h" namespace "Cantera":
cdef void CxxAddDirectory "Cantera::addDirectory" (string)
cdef size_t CxxNpos "Cantera::npos"
cdef extern from "cantera/thermo/mix_defs.h":
cdef int thermo_type_ideal_gas "Cantera::cIdealGas"
@ -253,6 +254,7 @@ cdef extern from "cantera/zeroD/Reactor.h":
void setKineticsMgr(CxxKinetics&)
void setEnergy(int)
cbool energyEnabled()
size_t componentIndex(string&)
void addSensitivityReaction(size_t) except +
size_t nSensParams()

View file

@ -196,6 +196,20 @@ cdef class Reactor(ReactorBase):
def add_sensitivity_reaction(self, m):
self.reactor.addSensitivityReaction(m)
def component_index(self, name):
"""
Returns the index of the component named *name* in the system. This
determines the (relative) index of the component in the vector of
sensitivity coefficients. *name* is either a species name or the name
of a reactor state variable, e.g. 'U', 'T', depending on the reactor's
equations.
"""
k = self.reactor.componentIndex(stringify(name))
if k == CxxNpos:
raise IndexError('No such component: {!r}'.format(name))
return k
cdef class Reservoir(ReactorBase):
"""

View file

@ -58,6 +58,14 @@ class TestReactor(utilities.CanteraTest):
self.r1.name = 'hello'
self.assertEqual(self.r1.name, 'hello')
def test_component_index(self):
self.make_reactors(n_reactors=1)
self.net.step(1.0)
N0 = self.net.n_vars - self.gas1.n_species
for i, name in enumerate(self.gas1.species_names):
self.assertEqual(i + N0, self.r1.component_index(name))
def test_disjoint(self):
T1, P1 = 300, 101325
T2, P2 = 500, 300000