BioSTEAMDevelopmentGroup / thermosteam

BioSTEAM's Premier Thermodynamic Engine
Other
57 stars 12 forks source link

Entropy setter sometimes does not work on `MultiStream` objects #68

Closed BenPortner closed 1 year ago

BenPortner commented 1 year ago

The newly implemented entropy setter function does not seem to work properly in some cases. For example:

import thermosteam as tmo
tmo.settings.set_thermo(["H2O"])
feed = tmo.MultiStream(T=372.75, P=1e5, l=[('H2O', 0.1)], g=[('H2O', 0.9)]) # water in two-phase region
print(feed.S) # 185, correct
out = feed.copy()
print(out.S) # 185, correct
out.P = 100e5
out.S = feed.S # superheated steam
print(out.S) # 161, should be 185
out.S = feed.S # let's repeat
print(out.S) # 185, twice is the charm?!
yoelcortes commented 1 year ago

Nice, thanks for testing!

The reason it failed was because the molar heat capacity (Cn) for liquid water at high temperatures becomes very high, but the solver was still using an old Cn value as an estimate. I updated the solver to use updated Cn values after a couple of tries and make it raise an error when the solver fails.

import thermosteam as tmo
tmo.settings.set_thermo(["H2O"])
feed = tmo.MultiStream(T=372.75, P=1e5, l=[('H2O', 0.1)], g=[('H2O', 0.9)]) # water in two-phase region
print(feed.S) # 185, correct
out = feed.copy()
print(out.S) # 185, correct
print(out.Cn) # ~38 (good)
out.P = 100e5
out.S = feed.S # should be superheated steam, but it is partially liquid (need to run VLE)
print(out.S) # now its 185 (yay, correct!)
print(out.Cn) # ~645 (very high, but expected due to liquid Cn model)

Thanks,

BenPortner commented 1 year ago

Amazing work! Thanks @yoelcortes. Closing this issue.

yoelcortes commented 1 year ago

@BenPortner, I introduced a silly bug in my last commit (it is fixed now). Please pull again when you get a chance :)