Skip to content

Setting the state of PureLiquidWater with T,P raises a CanteraError #721

@bryanwweber

Description

@bryanwweber

Cantera version

2.5.0a3

Operating System

macOS, but probably not specific

Python/MATLAB version

3.7, but probably not specific

Expected Behavior

Setting the state of PureLiquidWater with T, P works when going from gas to liquid states

Actual Behavior

Setting the state of PureLiquidWater with T, P raises a CanteraError when going from gas to liquid states

Steps to reproduce


In [2]: water = ct.PureFluid('/Users/bryan/GitHub/cantera/build/python/cantera/test/data/liquid-water.xml')

In [3]: water.TP
Out[3]: (300.0, 101325.00046662119)

In [4]: water.TP = 2000, ct.one_atm

In [5]: water.TP = 298, ct.one_atm
---------------------------------------------------------------------------
CanteraError                              Traceback (most recent call last)
<ipython-input-5-c5704cc5079b> in <module>
----> 1 water.TP = 298, ct.one_atm

~/GitHub/cantera/interfaces/cython/cantera/thermo.pyx in cantera._cantera.ThermoPhase.TP.__set__()
   1030             T = values[0] if values[0] is not None else self.T
   1031             P = values[1] if values[1] is not None else self.P
-> 1032             self.thermo.setState_TP(T, P)
   1033
   1034     property TPX:

CanteraError:
***********************************************************************
CanteraError thrown by setPressure:
error: dens = 0.109769, rc = 322, waterState = 0
***********************************************************************

In [6]: water.density
Out[6]: 0.10976927970023702

In [7]: water.critical_density
Out[7]: 322.0

In [8]: water.TP
Out[8]: (298.0, 14910.063602909962)

In [9]: water.TP = 2000, ct.one_atm

In [10]: water.density
Out[10]: 0.10976927970023702

In [11]: water.TP
Out[11]: (2000.0, 101325.00000000144)

(I modified the function to produce more useful error output)

The definition of the relevant function is:

void WaterSSTP::setPressure(doublereal p)
{
double T = temperature();
double dens = density();
int waterState = WATER_GAS;
double rc = m_sub.Rhocrit();
if (dens > rc) {
waterState = WATER_LIQUID;
}
doublereal dd = m_sub.density(T, p, waterState, dens);
if (dd <= 0.0) {
throw CanteraError("setPressure", "error");
}
setDensity(dd);
}

where WATER_GAS is defined as 0.

One possible solution is to check the value of the pressure passed in relative to the saturation pressure at the system temperature and determine the guessed phase that way, depending on how the saturation pressure is defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions