[Python] Fix setting mass/mole fractions for single-species phases

This commit is contained in:
Ray Speth 2017-01-31 17:41:50 -05:00
parent 6a52908d85
commit ed8de04e5b
2 changed files with 9 additions and 0 deletions

View file

@ -210,6 +210,12 @@ class TestThermoPhase(utilities.CanteraTest):
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]

View file

@ -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):