fix: correct multi-liquid selection flag in pure-component flash - #182
Merged
Merged
Conversation
one_liquid/one_other/one_solid were assigned len(x) instead of a boolean, so the truthy check on any count > 1 skipped the lowest-Gibbs-energy phase selection and just took index 0. A count of 0 fell through to the else branch and left lowest_phase as None, which crashes on the following .fugacities() call. Affects TVF_pure_newton, TVF_pure_secant, PVF_pure_newton, PVF_pure_secant, TSF_pure_newton, and PSF_pure_newton in thermo/flash/flash_utils.py. Signed-off-by: Mike German <mike@stepsventures.com>
Owner
|
Hi, yes this is a typo. |
Contributor
Author
|
Hey there - This is Mike the human in the loop on the other side of the PR
- with some assistance in the loop. Just trying to help folks out.
…On Sun, Jul 12, 2026 at 1:58 AM Caleb Bell ***@***.***> wrote:
*CalebBell* left a comment (CalebBell/thermo#182)
<#182 (comment)>
Hi, yes this is a typo.
Is there a person on the other side of this PR?
—
Reply to this email directly, view it on GitHub
<#182?email_source=notifications&email_token=AVWM7DEKIM3EAIWMZGVBW335EMSIXA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOJVGAYTKNRQGY3KM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-4950156066>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVWM7DBKET5DOHVC3NQWUST5EMSIXAVCNFSNUABEKJSXA33TNF2G64TZHM3DENBQGQ3DINZ3JFZXG5LFHM2DQNRUG44TENRXHGQXMAQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Owner
|
Hey Mike, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
In
thermo/flash/flash_utils.py, six pure-component flash helpers set a selection flag from a count instead of a boolean:len(liquids)is truthy for any count greater than zero, so theif one_liquid:branch runs whenever there is at least one liquid phase, not just when there is exactly one. With two or more liquid phases, this skips the Gibbs-energy comparison entirely and always returnsliquids[0], regardless of which phase is actually stable. With zero liquids, it falls to theelsebranch, the phase list comprehension is empty,lowest_phasestaysNone, and the next line crashes calling.fugacities()onNone.Same pattern for
one_other = len(other_phases)andone_solid = len(solids)inTSF_pure_newtonandPSF_pure_newton.Fix
Make the flags actual booleans:
applied to all six functions:
TVF_pure_newton,TVF_pure_secant,PVF_pure_newton,PVF_pure_secant,TSF_pure_newton,PSF_pure_newton. This preserves the fast path for the single-phase case and correctly runs the Gibbs-energy comparison whenever there's more than one candidate phase.Testing
I wrote a standalone repro using lightweight fake phase objects (mocking
to_TP_zs,G,fugacities,dfugacities_dP/dT) to isolate the selection logic from the full EOS/data stack, since these functions don't have dedicated unit tests. With two liquid phases passed inliquids[0]= high Gibbs energy,liquids[1]= low Gibbs energy, and gas fugacity matched to the low-Gibbs phase:master,TVF_pure_secantraisesfluids.numerics.SamePointErrorbecause it locks ontoliquids[0](the wrong, high-Gibbs phase) and the solver never converges.TVF_pure_*/PVF_pure_*functions correctly select the low-Gibbs phase and converge.len == 1fast path is unaffected.I also confirmed
git blameshows this line unchanged since it was introduced in 2021.