Skip to content

Fix edge cases for saturated PureFluid states / illustrate saturated water properties#907

Merged
speth merged 17 commits into
Cantera:mainfrom
ischoegl:water-vapor
Jan 19, 2021
Merged

Fix edge cases for saturated PureFluid states / illustrate saturated water properties#907
speth merged 17 commits into
Cantera:mainfrom
ischoegl:water-vapor

Conversation

@ischoegl
Copy link
Copy Markdown
Member

@ischoegl ischoegl commented Jul 30, 2020

Changes proposed in this pull request

  • fix TQ/PQ assignment at critical point
  • add example illustrating saturated water properties / vapor dome
  • fix various bugs for edge case calculations (critical point / triple point)
  • disable TP setter for saturated mixtures

If applicable, fill in the issue number this pull request is fixing

Fixes #906, fixes #915, fixes #917, fixes #919, fixes #920

Checklist

  • There is a clear use-case for this code change
  • The commit message has a short title & references relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • The pull request is ready for review

Thoughts

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).

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 30, 2020

Codecov Report

Merging #907 (41c0499) into main (d8e62ad) will increase coverage by 0.04%.
The diff coverage is 94.40%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
include/cantera/tpx/Sub.h 89.47% <ø> (ø)
src/tpx/Sub.cpp 89.16% <94.35%> (+2.55%) ⬆️
src/tpx/Water.cpp 97.50% <100.00%> (ø)
src/thermo/PureFluidPhase.cpp 59.72% <0.00%> (+0.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8e62ad...864caa0. Read the comment docs.

@ischoegl ischoegl force-pushed the water-vapor branch 3 times, most recently from 17d9b27 to 97d9bc3 Compare July 31, 2020 14:40
@bryanwweber
Copy link
Copy Markdown
Member

FYI the failures in the multiple-sundials job are fixed by 529b799 in #905

@ischoegl ischoegl force-pushed the water-vapor branch 2 times, most recently from bec5c81 to e065c43 Compare August 21, 2020 21:23
Copy link
Copy Markdown
Member

@speth speth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Aug 22, 2020

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.

Since this is just a papercut for an edge case, I’d suggest to close both issue and PR - if there’s interest in the example, I could still modify it as it’s not too difficult to circumnavigate. There’s also the question about the proposed change making physical sense, while being mathematically ill defined (there is no unique value for Q).

@ischoegl
Copy link
Copy Markdown
Member Author

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.

@bryanwweber
Copy link
Copy Markdown
Member

if there’s interest in the example, I could still modify it as it’s not too difficult to circumnavigate.

I think the example is valuable, so I'd be in favor of fixing it up.

There’s also the question about the proposed change making physical sense, while being mathematically ill defined (there is no unique value for Q).

This was also my concern about the proposed change that I never got around to writing up.

@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Aug 22, 2020

@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 .gitignore that has no other technical contribution). #904 is something that I likely cannot push further, and the two 'stubs' depend on other work (or clarifications).

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 PQ setter (the exception was actually not reachable), which is now fixed. Edit: another issue surfaced with #915.

@ischoegl ischoegl force-pushed the water-vapor branch 3 times, most recently from f7d7144 to 8220104 Compare August 22, 2020 18:17
@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Aug 22, 2020

Added fixes for #915.

This should open the option to allow for TQ/PQ convenience setters at the critical point after all (with the mathematical caveat that the value of Q would not matter). At this point, I am leaning against it.

@ischoegl ischoegl force-pushed the water-vapor branch 2 times, most recently from 49af410 to cbfe1ae Compare August 23, 2020 01:57
@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Aug 23, 2020

I added a couple of tests to the suite. There is one last edge case left for discussion: at the critical point, Q can be read, although it cannot be specified in setters and a unique value cannot be defined. Nevermind: this is a larger issue, to be discussed in #916.

Work on this PR is done, except for review.

@ischoegl ischoegl requested a review from speth August 23, 2020 20:04
@speth
Copy link
Copy Markdown
Member

speth commented Aug 24, 2020

There’s also the question about the proposed change making physical sense, while being mathematically ill defined (there is no unique value for Q).

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 vapordome.py example makes a case for being able to set the state to the Tcrit and any value of Q. Otherwise, you're forced to jump through hoops in order to traverse the whole saturation curve.

@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Aug 25, 2020

@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.

@ischoegl
Copy link
Copy Markdown
Member Author

@speth ... TQ/PQ setters are now enabled for the critical point.

I found quite a few irregularities of various solvers for edge cases while working on this PR, and fixed whatever popped up (it didn’t quite extend to #605 though). I also added unit tests to ensure proper behavior.

@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Dec 6, 2020

@speth ... thanks for the review, I believe I addressed everything.

Since triple point properties are currently not broken out (Python's current min_temp is actually T_triple, and there isn't an equivalent min_pressure), I'd suggest leaving a pre-calculation for another time. If you agree, I will open a feature request on Cantera/enhancements ...

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).
@ischoegl ischoegl mentioned this pull request Dec 11, 2020
4 tasks
@ischoegl ischoegl requested a review from speth December 11, 2020 12:32
@ischoegl ischoegl closed this Jan 18, 2021
@ischoegl
Copy link
Copy Markdown
Member Author

close/reopen to trigger checks

@ischoegl ischoegl reopened this Jan 18, 2021
Copy link
Copy Markdown
Member

@speth speth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread interfaces/cython/cantera/test/test_purefluid.py Outdated
Comment thread src/tpx/Sub.cpp Outdated
@ischoegl
Copy link
Copy Markdown
Member Author

ischoegl commented Jan 19, 2021

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 @TODO).

@ischoegl ischoegl mentioned this pull request Jan 19, 2021
4 tasks
@speth speth merged commit 0a69c0a into Cantera:main Jan 19, 2021
@ischoegl ischoegl deleted the water-vapor branch January 29, 2021 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants