BioSTEAMDevelopmentGroup / thermosteam

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

Enthalpy calculation #11

Closed yalinli2 closed 4 years ago

yalinli2 commented 4 years ago

Description For the following code, I'm not sure why having HMF in the stream raises error when calculating enthalpy, especially when I used copy_missing_slots_from function

import thermosteam as tmo

chems = tmo.Chemicals(['Water', 'Ethanol', 'CH4', 'HMF', 'Furfural'])
tmo.settings.set_thermo(chems)

chems.HMF.Hfus = 19.8
chems.Furfural.Hfus = 14370
chems.HMF.copy_missing_slots_from(chems.Furfural)

ms_no_HMF = tmo.Stream('ms_no_HMF', units='kmol/hr', T=300, P=101325,
                       Water=4.649e+04, Ethanol=50, CH4=800, Furfural=0.5)
ms_with_HMF = tmo.Stream('ms_with_HMF', units='kmol/hr', T=300, P=101325,
                         Water=4.649e+04, Ethanol=50, CH4=800, Furfural=0.5,
                         HMF=0.5)

print('No HMF: '+str(ms_no_HMF.H))
print('With HMF: '+str(ms_with_HMF.H))
Screen Shot 2020-04-21 at 4 58 55 PM

What confuses me most, is that in return H_ref + H_int_T_ref_to_Tm_s + Hfus + Cn_l.integrate_by_T(Tm, T), seems like Hfus is None (I let the function print H_ref, H_int_T_ref_to_Tm_s, Hfus, and Cn_l.integrate_by_T(Tm, T)), but:

for chem in chems:
    print(str(chem.ID)+': '+str(chem.Hfus))

All chemicals have Hfus

Screen Shot 2020-04-21 at 5 04 22 PM

Environment: OS: macOS Catalina 10.15.4 biosteam: v2.12.8 thermosteam: v0.12.16

Thanks!!!

yoelcortes commented 4 years ago

Ahh, yeah, I see the problem:

  1. In general, changes to the chemicals should be made before setting the thermo property packages. But its OK to reorder models and/or change the model coefficients after set_thermo. Future versions of thermo will be more flexible/robust regarding this matter (so for now let's stick with this guideline).
  2. After setting properties, you'll need to run <Chemical>.load_free_energies() to reload the free energy objects. For future versions we won't have to do this, but it'll be a while.

This is how the code would look like:

import thermosteam as tmo
chems = tmo.Chemicals(['Water', 'Ethanol', 'CH4', 'HMF', 'Furfural'])
chems.HMF.Hfus = 19.8
chems.Furfural.Hfus = 14370
chems.HMF.copy_missing_slots_from(chems.Furfural)
chems.HMF.load_free_energies()
tmo.settings.set_thermo(chems)
ms_no_HMF = tmo.Stream('ms_no_HMF', units='kmol/hr', T=300, P=101325,
                       Water=4.649e+04, Ethanol=50, CH4=800, Furfural=0.5)
ms_with_HMF = tmo.Stream('ms_with_HMF', units='kmol/hr', T=300, P=101325,
                         Water=4.649e+04, Ethanol=50, CH4=800, Furfural=0.5,
                         HMF=0.5)
print('No HMF: '+str(ms_no_HMF.H))
# No HMF: 2382786.3922599712
print('With HMF: '+str(ms_with_HMF.H))
# With HMF: 2382794.990691943
# Note that this value is slightly higher cause it has HMF

An alternative is to set Hfus to the free energy objects directly (instead of running load_free_energies):

H = chems.HMF.H
H.g.Hfus = H.l.Hfus = 19.8

:)

yalinli2 commented 4 years ago

👏 Aha! I see, thanks!!!