From 859aee18ef102eba4afc2ea8f3f14ccde5fdcf5a Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 28 May 2015 12:21:46 -0400 Subject: [PATCH] [Python] ThermoPhase.species() returns all Species objects --- interfaces/cython/cantera/test/test_thermo.py | 4 ++++ interfaces/cython/cantera/thermo.pyx | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index 023df57b7..58c0dc980 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -693,6 +693,10 @@ class TestSpecies(utilities.CanteraTest): for m,n in s.composition.items(): self.assertEqual(n, self.gas.n_atoms(k,m)) + def test_species_noargs(self): + for k,s in enumerate(self.gas.species()): + self.assertEqual(s.name, self.gas.species_name(k)) + def test_name_accessor(self): for name in self.gas.species_names: s = self.gas.species(name) diff --git a/interfaces/cython/cantera/thermo.pyx b/interfaces/cython/cantera/thermo.pyx index 8d46eef15..e2c391592 100644 --- a/interfaces/cython/cantera/thermo.pyx +++ b/interfaces/cython/cantera/thermo.pyx @@ -425,7 +425,15 @@ cdef class ThermoPhase(_SolutionBase): return index - def species(self, k): + def species(self, k=None): + """ + Return the `Species` object for species *k*, where *k* is either the + species index or the species name. If *k* is not specified, a list of + all species objects is returned. + """ + if k is None: + return [self.species(i) for i in range(self.n_species)] + s = Species(init=False) if isinstance(k, (str, unicode, bytes)): s._assign(self.thermo.species(stringify(k)))