chmarti1 / PYroMat

PYroMat thermodynamic properties in Python
http://pyromat.org
Other
71 stars 13 forks source link

Different result using substance.p() and substance.ps() in multiphase substance #89

Closed juanjpnv closed 2 months ago

juanjpnv commented 4 months ago

Hello! While working with multi-phase water, I observed that the saturated pressure methods substance.ps() yield different results compared to the regular pressure method substance.p() when the quality is set to zero or one.

Exemple:

water = pm.get('mp.H2O')

water.ps(T=400)       # return 2.457652635418225 bar
water.p(T=400, x=0) # return 2.45743614 bar

The discrepancy is quite small, appearing in the 4th decimal place. However, other thermodynamic properties do not exhibit similar divergence.

Regarding the pressure case, is this variation expected? Could it be related to floating-point arithmetic or Pyromat's internal calculations?

chmarti1 commented 2 months ago

That's a really good question, and thanks for your patience - it took me quite a while to get you an answer. Yes, this variation is expected. Here's why...

The model used to calculate the saturation points is actually a different equation than the one used to calculate all other points. See the original source for all the details, but that's quite a bit of reading. Here's the short version:

There is a global model that is used to calculate all data points that are not saturated. It is formulated as A(T,d) (helmholtz free energy as a function of temperature and density). It is possible to calculate the equilibrium saturation points, but that is a computationally expensive operation. Instead, the original sources also supply polynomial models for the saturation line. See the PYroMat handbook Section 7.2.7 page 112.

These two models agree with one another very closely, but as you point out, it is not numerically possible for them to be exactly the same. This is tolerated because they agree to within better than the reported model precision.

Does this cause a problem? Not usually, but it is something we have to be aware of sometimes. For example, I need to be aware that the saturation line is not precise when I am writing numerical iteration routines. I sometimes need to allow the algorithm to wander just a little to either side of the saturation line even though I know that isn't strictly where the solution will lie.

Thanks for your question!