[Thermo] add setter TPX to PureFluid
* setter for `PureFluid.TPX` property is added to allow for automatic restoration of consistent thermodynamic data * alternative to 'TP', 'TX' or 'PX' which may not uniquely describe a valid thermodynamic state * add unit test
This commit is contained in:
parent
69f33a8631
commit
378c6da18b
2 changed files with 24 additions and 4 deletions
|
|
@ -149,11 +149,16 @@ class TestPureFluid(utilities.CanteraTest):
|
|||
|
||||
def test_TPX(self):
|
||||
self.water.TX = 400, 0.8
|
||||
T,P,X = self.water.TPX
|
||||
T, P, X = self.water.TPX
|
||||
self.assertNear(T, 400)
|
||||
self.assertNear(X, 0.8)
|
||||
with self.assertRaises(AttributeError):
|
||||
self.water.TPX = 500, 101325, 0.3
|
||||
|
||||
self.water.TPX = T, P, X
|
||||
self.assertNear(X, 0.8)
|
||||
with self.assertRaises(ValueError):
|
||||
self.water.TPX = T, .999*P, X
|
||||
with self.assertRaises(ValueError):
|
||||
self.water.TPX = T, 1.001*P, X
|
||||
|
||||
|
||||
# To minimize errors when transcribing tabulated data, the input units here are:
|
||||
|
|
|
|||
|
|
@ -1564,9 +1564,24 @@ cdef class PureFluid(ThermoPhase):
|
|||
return self.T, self.density, self.X
|
||||
|
||||
property TPX:
|
||||
"""Get the temperature [K], pressure [Pa], and vapor fraction."""
|
||||
"""
|
||||
Get/Set the temperature [K], pressure [Pa], and vapor fraction of a
|
||||
PureFluid.
|
||||
|
||||
An Exception is raised if the thermodynamic state is not consistent.
|
||||
"""
|
||||
def __get__(self):
|
||||
return self.T, self.P, self.X
|
||||
def __set__(self, values):
|
||||
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 np.isclose(P, self.thermo.satPressure(T)):
|
||||
self.TX = T, X
|
||||
elif np.isclose(X, 0.) or np.isclose(X, 1.):
|
||||
self.TP = T, P
|
||||
else:
|
||||
raise ValueError('invalid thermodynamic state')
|
||||
|
||||
property UVX:
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue