BioSTEAMDevelopmentGroup / thermosteam

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

Proper way to set Cn methods? #72

Closed BenPortner closed 1 year ago

BenPortner commented 1 year ago

What is the "proper" way to change the heat capacity calculation method in thermosteam? I tried the following:

import thermosteam as tmo
from thermo import HeatCapacityGas, HeatCapacityLiquid, HeatCapacitySolid

Cns = HeatCapacitySolid(CASRN="1333-74-0", MW=2.01588, similarity_variable=0.9921225469770025, extrapolation="linear", method="LASTOVKA_S")
Cng = HeatCapacityGas(CASRN="1333-74-0", MW=2.01588, similarity_variable=0.9921225469770025, extrapolation=None, method="COOLPROP")
Cnl = HeatCapacityLiquid(CASRN="1333-74-0", MW=2.01588, similarity_variable=0.9921225469770025, Tc=33.2, omega=-0.22,
                         Cpgm=Cng, extrapolation="linear", method="VDI_TABULAR")
Cn = tmo.base.PhaseTHandle("Cn", Cns, Cnl, Cng)

# this doesn't work
h2 = tmo.Chemical('H2', Cn=Cn) # ValueError: must specify phase to set Cn model

# this doesn't work
h2 = tmo.Chemical('H2', Cn=Cn, phase='g')
thermo = tmo.Thermo([h2])
tmo.settings.set_thermo(thermo)
S1 = tmo.Stream(H2=1, T=30, P=101325, phase='g')
S1.vle(V=0, P=S1.P) # ValueError: max() arg is an empty sequence

# this doesn't work
h2 = tmo.Chemical('H2') 
h2.Cn.g = Cng # TypeError: 'PhaseTHandle' object is read-only
thermo = tmo.Thermo([h2])
tmo.settings.set_thermo(thermo)

# this doesn't work: no errors but wrong results because Chemical._init_energies is called with old Cn methods
h2 = tmo.Chemical('H2') 
h2.Cn.g.method = "CoolProp"
thermo = tmo.Thermo([h2])
tmo.settings.set_thermo(thermo)

# this works but is rather cumbersome, also no way to change interpolation method
h2 = tmo.Chemical('H2')
h2.Cn.g.method = "CoolProp"
h2._init_energies(h2.Cn, h2.Hvap, h2.Psat, h2.Hfus, h2.Sfus, h2.Tm, h2.Tb, h2.eos, h2.phase_ref)
thermo = tmo.Thermo([h2])
tmo.settings.set_thermo(thermo)
yoelcortes commented 1 year ago

@BenPortner, thanks for posting this.

For now you can use the following:

import thermosteam as tmo
h2 = tmo.Chemical('H2')
Cng = h2.Cn.g
Cng.method = "CoolProp"
Cng.extrapolation = None
h2.reset_free_energies()
tmo.settings.set_thermo([h2])

I'll try to get the following to work for all properties later on:

h2 = tmo.Chemical('H2', Cn) # Where Cn can be a function, constant, TDependentProperty (if phase given) or PhaseHandle (if no phase given)
h2 = tmo.Chemical('H2', Cnl=Cnl, Cng=Cng, Cns=Cns) # Where Cn{x} can be a function, constant, or TDependentProperty

Thanks, Have a nice day!