[Python] Add Kinetics.reactions() method which returns all Reactions
This commit is contained in:
parent
859aee18ef
commit
e292caa187
3 changed files with 10 additions and 8 deletions
|
|
@ -41,8 +41,7 @@ while t < 0.02:
|
|||
plt.plot(tt, TT, label='K=53, R=325', color='k', lw=3, zorder=100)
|
||||
|
||||
# Get the reaction objects, and sort them so the most active reactions are first
|
||||
R = [(Rmax[i],gas.reaction(i)) for i in range(gas.n_reactions)]
|
||||
R.sort(key=lambda x: -x[0])
|
||||
R = sorted(zip(Rmax, gas.reactions()), key=lambda x: -x[0])
|
||||
|
||||
# Test reduced mechanisms with different numbers of reactions
|
||||
C = plt.cm.winter(np.linspace(0,1,5))
|
||||
|
|
|
|||
|
|
@ -80,6 +80,12 @@ cdef class Kinetics(_SolutionBase):
|
|||
"""
|
||||
return wrapReaction(self.kinetics.reaction(i_reaction))
|
||||
|
||||
def reactions(self):
|
||||
"""
|
||||
Return a list of all `Reaction` objects
|
||||
"""
|
||||
return [self.reaction(i) for i in range(self.n_reactions)]
|
||||
|
||||
def modify_reaction(self, int irxn, Reaction rxn):
|
||||
"""
|
||||
Modify the `Reaction` with index ``irxn`` to have the same rate
|
||||
|
|
|
|||
|
|
@ -626,22 +626,19 @@ class TestReaction(utilities.CanteraTest):
|
|||
def test_listFromFile(self):
|
||||
R = ct.Reaction.listFromFile('h2o2.xml')
|
||||
eq1 = [r.equation for r in R]
|
||||
eq2 = [self.gas.reaction(i).equation
|
||||
for i in range(self.gas.n_reactions)]
|
||||
eq2 = [r.equation for r in self.gas.reactions()]
|
||||
self.assertEqual(eq1, eq2)
|
||||
|
||||
def test_listFromCti(self):
|
||||
R = ct.Reaction.listFromCti(open('../../build/data/h2o2.cti').read())
|
||||
eq1 = [r.equation for r in R]
|
||||
eq2 = [self.gas.reaction(i).equation
|
||||
for i in range(self.gas.n_reactions)]
|
||||
eq2 = [r.equation for r in self.gas.reactions()]
|
||||
self.assertEqual(eq1, eq2)
|
||||
|
||||
def test_listFromXml(self):
|
||||
R = ct.Reaction.listFromCti(open('../../build/data/h2o2.xml').read())
|
||||
eq1 = [r.equation for r in R]
|
||||
eq2 = [self.gas.reaction(i).equation
|
||||
for i in range(self.gas.n_reactions)]
|
||||
eq2 = [r.equation for r in self.gas.reactions()]
|
||||
self.assertEqual(eq1, eq2)
|
||||
|
||||
def test_elementary(self):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue