BioSTEAMDevelopmentGroup / thermosteam

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

Entropy can not be calculated in SLE #49

Closed fwitte closed 2 years ago

fwitte commented 2 years ago

Hi Yoel,

with python3.8 and the current state of the master branch in my fork (only change numpy dependency) installed, I tried the following solid liquid equilibrium calculation:

from thermosteam import Chemical, indexer, equilibrium, settings
settings.set_thermo(['Water', 'KOH'], cache=True)
imol = indexer.MolarFlowIndexer(l=[('Water', 10), ('KOH', 3)], phases=('s', 'l'))
sle = equilibrium.SLE(imol)
sle('KOH', T=298.15, P=1e5)

sle.mixture.xH(imol, *sle.thermal_condition)
sle.mixture.xmu(imol, *sle.thermal_condition)
sle.mixture.xV(imol, *sle.thermal_condition)
sle.mixture.xS(imol, *sle.thermal_condition)

I do get results for enthalpy, viscosity and specific volume, but for entropy it seems that some value is can not be calculated properly:

Traceback (most recent call last):
  File "fiddle.py", line 15, in <module>
    print(sle.mixture.xS(imol, *sle.thermal_condition))
  File "/home/witte/nextcloud/Documents/Hochschule/Dissertation/Kraftwerkssimulation/thermosteam/thermosteam/mixture/mixture.py", line 356, in xS
    S_total = sum([S(phase, mol, T, P) for phase, mol in phase_mol])
  File "/home/witte/nextcloud/Documents/Hochschule/Dissertation/Kraftwerkssimulation/thermosteam/thermosteam/mixture/mixture.py", line 356, in <listcomp>
    S_total = sum([S(phase, mol, T, P) for phase, mol in phase_mol])
  File "/home/witte/nextcloud/Documents/Hochschule/Dissertation/Kraftwerkssimulation/thermosteam/thermosteam/base/phase_handle.py", line 84, in __call__
    return getattr(self, phase)(z, T, P)
  File "/home/witte/nextcloud/Documents/Hochschule/Dissertation/Kraftwerkssimulation/thermosteam/thermosteam/mixture/ideal_mixture_model.py", line 56, in __call__
    return sum([j * i(T, P) for i, j in zip(self.models, mol) if j])
  File "/home/witte/nextcloud/Documents/Hochschule/Dissertation/Kraftwerkssimulation/thermosteam/thermosteam/mixture/ideal_mixture_model.py", line 56, in <listcomp>
    return sum([j * i(T, P) for i, j in zip(self.models, mol) if j])
  File "/home/witte/nextcloud/Documents/Hochschule/Dissertation/Kraftwerkssimulation/thermosteam/thermosteam/base/functor.py", line 270, in __call__
    return self.function(T, **self.__dict__)
  File "/home/witte/nextcloud/Documents/Hochschule/Dissertation/Kraftwerkssimulation/thermosteam/thermosteam/free_energy.py", line 91, in Liquid_Entropy_Ref_Solid
    return S0 + S_int_T_ref_to_Tm_s + Sfus + Cn_l.T_dependent_property_integral_over_T(Tm, T)
TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'

Can you help me here?

Thanks a lot!

yoelcortes commented 2 years ago

Hi!

The entropy of fusion was missing. I do not have the value, but here is an example for how you can fix the problem:

from thermosteam import Chemical, indexer, equilibrium, settings
KOH = Chemical('KOH')
KOH.Sfus = 0. # Put in correct value here
settings.set_thermo(['Water', KOH], cache=True)
imol = indexer.MolarFlowIndexer(l=[('Water', 10), ('KOH', 3)], phases=('s', 'l'))
sle = equilibrium.SLE(imol)
sle('KOH', T=298.15, P=1e5)

print(sle.mixture.xH(imol, *sle.thermal_condition))
print(sle.mixture.xmu(imol, *sle.thermal_condition))
print(sle.mixture.xV(imol, *sle.thermal_condition))
print(sle.mixture.xS(imol, *sle.thermal_condition))

Output:

14554.79330573155
0.019279623030465657
0.0004451067242990097
921.1987804769778

The default property package in thermosteam will not return accurate values for electrolyte mixtures, which is usually not a problem in the context of preliminary unit operation designs. I'll send you some code separately on setting up better estimation methods for electrolytes soon.

Thanks!