Skip to content

Commit

Permalink
[Thermo] Preserve constant property pair when multiplying Quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Mar 10, 2018
1 parent de3ec3d commit c9b0bce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions interfaces/cython/cantera/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions interfaces/cython/cantera/test/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c9b0bce

Please sign in to comment.