Skip to content

Commit

Permalink
[Thermo] improve error messages in PureFluid.TPX setter
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Sep 26, 2019
1 parent ee28ae7 commit 1b9be71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions interfaces/cython/cantera/test/test_purefluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def test_TPX(self):
self.water.TPX = T, .999*P, X
with self.assertRaises(ValueError):
self.water.TPX = T, 1.001*P, X
with self.assertRaises(ValueError):
self.water.TPX = T, P, 'spam'


# To minimize errors when transcribing tabulated data, the input units here are:
Expand Down
9 changes: 7 additions & 2 deletions interfaces/cython/cantera/thermo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import warnings
import weakref
import numbers as _numbers

cdef enum ThermoBasis:
mass_basis = 0
Expand Down Expand Up @@ -1565,7 +1566,7 @@ cdef class PureFluid(ThermoPhase):

property TPX:
"""
Get/Set the temperature [K], pressure [Pa], and vapor fraction of a
Get/Set the temperature [K], pressure [Pa], and vapor fraction of a
PureFluid.
An Exception is raised if the thermodynamic state is not consistent.
Expand All @@ -1576,6 +1577,9 @@ cdef class PureFluid(ThermoPhase):
T = values[0] if values[0] is not None else self.T
P = values[1] if values[1] is not None else self.P
X = values[2] if values[2] is not None else self.X
if not isinstance(X, _numbers.Number):
raise ValueError(
'a numeric value is required for X')
if np.isclose(P, self.thermo.satPressure(T)):
self.TX = T, X
elif np.isclose(X, 0.) or np.isclose(X, 1.):
Expand All @@ -1586,7 +1590,8 @@ cdef class PureFluid(ThermoPhase):
'received a combination of property values that '
'do not represent a valid state. As an alternative, '
'specify the state using two fully independent '
'properties (e.g. TD)')
'properties (e.g. TD) instead of: '
'T={}, P={}, X={}'.format(T, P, X))

property UVX:
"""
Expand Down

0 comments on commit 1b9be71

Please sign in to comment.