Fix edge cases for saturated PureFluid states / illustrate saturated water properties#907
Conversation
Codecov Report
@@ Coverage Diff @@
## main #907 +/- ##
==========================================
+ Coverage 71.22% 71.26% +0.04%
==========================================
Files 377 377
Lines 46272 46296 +24
==========================================
+ Hits 32955 32991 +36
+ Misses 13317 13305 -12
Continue to review full report at Codecov.
|
17d9b27 to
97d9bc3
Compare
bec5c81 to
e065c43
Compare
speth
left a comment
There was a problem hiding this comment.
Unfortunately, I think fixing this problem is more complicated than just changing the comparisons in the state setters. With this change, the state of the mixture when setting the state to be a saturated state at the critical temperature does not end up at the critical point, and the resulting state depends on the previous state of the mixture. For example:
>>> w = ct.Water()
>>> w.TP = 300, 101325
>>> w.TQ = w.critical_temperature, 0
>>> w.TP
(647.286, 1089571723.7984445) # not even close
>>> w.TQ = w.critical_temperature, 1
>>> w.TP
(647.286, 7623.02783606933) # wrong, and different
>>> w.TP = 645, 101325
>>> w.TQ = w.critical_temperature, 0
(647.286, 22304442.572488125) # closer, but still wrong|
That’s actually much worse than what I recall for the tests I ran - I saw an insignificant discrepancy depending on whether I set Q equal to 0 or 1, but nothing of that magnitude. Based on what you are showing, this is likely due to having marched along saturated liquid and vapor lines, meaning that I was reasonably close to the correct result, which led me to believe that the simple fix worked as expected. Update: located the bug - see #915 - and added the fix to this PR.
|
|
PS: it may still make sense to change the error message, as it clearly doesn’t apply to the critical point itself; I’ll likely push a suggestion before long. |
I think the example is valuable, so I'd be in favor of fixing it up.
This was also my concern about the proposed change that I never got around to writing up. |
|
@speth / @bryanwweber ... I replaced the 'fix' by just changing the error message, and updated the example. On a separate note, I think that this is the last pending PR from my side - unless there's interest in resurrecting #888 (a simplification of PS: I haven't forgotten about Cantera/cantera-website#104 and Cantera/cantera-jupyter#27, which I'll get to one of these days. Update: Adding a unit test surfaced a previously unknown issue for the |
f7d7144 to
8220104
Compare
|
Added fixes for #915. This should open the option to allow for |
49af410 to
cbfe1ae
Compare
|
I added a couple of tests to the suite. Work on this PR is done, except for review. |
I'm not convinced that it's mathematically ill defined just because any value of Q corresponds to the same state. I think it's just that there's no longer a natural inverse (that is, a way to determine Q from the intrinsic state) based on the physical definition of Q. That doesn't preclude defining Q in a consistent way at the critical point or even outside the vapor dome. Of course, we wouldn't want to add this complication unless it were useful, but I think the |
|
@speth ... the convenience argument is what made me file the issue and this PR in the first place, so it’s not difficult to persuade me here 😉 ... I’ll push an update shortly. Regarding definitions, it’s no longer possible to differentiate liquid from vapor at the critical point, so it actually becomes impossible to define Q. It’s a different discussion (#916) though and won’t affect the implementation here. |
|
@speth ... thanks for the review, I believe I addressed everything. Since triple point properties are currently not broken out (Python's current PS: I can rebase once #946 is merged, so CI will give expected results. |
- Logic is updated for PQ setter in order to avoid 'no convergence' at critical point and clarify error for supercritical conditions - Error message is updated to properly describe failure for an attempt to assign the critical state via TQ setters.
- Avoid illegal temperatures in saturation pressure gradient - Fix logic at critical point
- do not allow for for silent failure of Substance::update_sat for illegal temperatures - small formatting changes of error messages
- TP setters cannot be used at saturated conditions - Update logic for saturated properties that are based on finite differences
The calculation of Substance::Tsat should check for pressures below the triple point and raise a corresponding exception. A bug causing low temperature TP setting of heptane (GitHub issue Cantera#605) to fail prevents an implementation of this check at the moment.
Saturated liquid and saturated vapor form the boundary of the vapor dome and are included in the phase-of-matter labeled 'liquid-vapor-mix'. At the same time, properties that are based on finite difference calculations of a pure liquid or pure vapor can be calculated. This approach corresponds to the implementation of the CoolProp package (http://www.coolprop.org).
41c0499 to
04ec6dc
Compare
|
close/reopen to trigger checks |
speth
left a comment
There was a problem hiding this comment.
I think this looks fine, and your suggestions for a few fine points that can resolved later are reasonable. My only suggestion is to flag a couple of these things in the code with @todo so they're easier to find later, although keeping track of them in the related Github issue is probably also a good idea.
@speth ... thanks! Your suggestions are straightforward (as long as there isn't a preference for upper/lowercase - I used |
Changes proposed in this pull request
TQ/PQassignment at critical pointTPsetter for saturated mixturesIf applicable, fill in the issue number this pull request is fixing
Fixes #906, fixes #915, fixes #917, fixes #919, fixes #920
Checklist
scons build&scons test) and unit tests address code coverageThoughts
I generated a digital version of a saturated steam table for an exam; i am including it here as it could be considered as an example and potentially expanded upon (otherwise I’ll simply drop it).