From c9b0bce8b99000099763aedb088dddb80f7047a1 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 9 Mar 2018 19:30:17 -0500 Subject: [PATCH] [Thermo] Preserve constant property pair when multiplying Quantity --- interfaces/cython/cantera/composite.py | 4 ++-- interfaces/cython/cantera/test/test_thermo.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/interfaces/cython/cantera/composite.py b/interfaces/cython/cantera/composite.py index a1d0fd8f10..b7b78e23c9 100644 --- a/interfaces/cython/cantera/composite.py +++ b/interfaces/cython/cantera/composite.py @@ -235,10 +235,10 @@ def __imul__(self, other): return self def __mul__(self, other): - return Quantity(self.phase, mass=self.mass * other) + return Quantity(self.phase, mass=self.mass * other, constant=self.constant) def __rmul__(self, other): - return Quantity(self.phase, mass=self.mass * other) + return Quantity(self.phase, mass=self.mass * other, constant=self.constant) def __iadd__(self, other): if (self._id != other._id): diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index c383fa609a..1dc919b153 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -1137,6 +1137,16 @@ def test_multiply(self): self.assertNear(q1.entropy * 2.5, q2.entropy) self.assertArrayNear(q1.X, q2.X) + def test_multiply_HP(self): + self.gas.TPX = 500, 101325, 'CH4:1.0, O2:0.4' + q1 = ct.Quantity(self.gas, mass=2, constant='HP') + q2 = ct.Quantity(self.gas, mass=1, constant='HP') + q2.equilibrate('HP') + q3 = 0.2 * q1 + q2 * 0.4 + self.assertNear(q1.P, q3.P) + self.assertNear(q1.enthalpy_mass, q3.enthalpy_mass) + self.assertNear(q2.enthalpy_mass, q3.enthalpy_mass) + def test_iadd(self): q0 = ct.Quantity(self.gas, mass=5) q1 = ct.Quantity(self.gas, mass=5)