Skip to content

Commit

Permalink
[Python] Fix setting mass/mole fractions for single-species phases
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Jan 31, 2017
1 parent 6a52908 commit ed8de04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions interfaces/cython/cantera/test/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ def test_setCompositionSlice(self):
self.assertNear(X[0], 0.1)
self.assertNear(X[3], 0.9)

def test_setCompositionSingleSpecies(self):
gas = ct.Solution('argon.xml')
gas.X = [1]
gas.Y = np.array([[1.001]])
self.assertEqual(gas.Y[0], 1.0)

def test_setCompositionSlice_bad(self):
with self.assertRaises(ValueError):
self.phase['H2','O2'].Y = [0.1, 0.2, 0.3]
Expand Down
3 changes: 3 additions & 0 deletions interfaces/cython/cantera/thermo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ cdef class ThermoPhase(_SolutionBase):
cdef np.ndarray[np.double_t, ndim=1] data

values = np.squeeze(values)
if values.ndim == 0:
values = values[np.newaxis] # corner case for single-species phases

if len(values) == self.n_species:
data = np.ascontiguousarray(values, dtype=np.double)
elif len(values) == len(self._selected_species):
Expand Down

0 comments on commit ed8de04

Please sign in to comment.