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.
I've been a bit annoyed sometimes that
safe_bubPand friends would sometimes fail, even though the envelope traces worked (specifically for mixtures). I also noticed thatsafe_bubPand friends sometimes ended up returning points well inside the two-phase region without indicating an error.To remedy this, I've implemented a fallback solver that is used if either
safe_[dew/bub][P/T]fails, orThe solver is a naive bracket solver that uses
twoPhaseTPflashto locate the saturation line, so in order to make sure the bracket solver didn't force termination iftwoPhaseTPflashfailed, I also had to maketwoPhaseTPflash_safe, which is the oldtwoPhaseTPflash, except it returns with an error flag instead of terminating if it hits an error. The subroutinetwoPhaseTPflashcallstwoPhaseTPflash_safeand terminates exactly as it used to if it gets an error.On the positive side,
safe_bubPand friends will now never silently return points deep in the two-phase region, and will successfully find the saturation line in a lot of situations where it previously failed. The caveat is that all calls tosafe_bubPand friends will incur a call totwoPhaseTPflashfor multicomponent mixtures, which costs a little runtime. This cost could maybe be reduced by using something from thestabilitymodule to check the solution instead of a full TP-flash.I've attached some figures to illustrate the issue as it was, and that the fallback solver handles them. Note that the fallback solver is never called if the existing saturation functions successfully located the saturation point, or if the system is a pure component.
TP_no fallback.pdf
TP_t_no fallback.pdf
TP_t_with fallback.pdf
TP_with fallback.pdf
TXY_no fallback.pdf
TXY_with fallback.pdf