BioSTEAMDevelopmentGroup / thermosteam

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

Enthalpy balance violated mixing liquid and gaseous phases #22

Closed fwitte closed 3 years ago

fwitte commented 3 years ago

E.g. mixing two streams of water (one liquid and one gaseous), the enthalpy of the mixed stream is not equal to the sum of the enthalpy of the incoming streams. I checked within the method mix_from, the enthalpy value assigned to the mixed Stream seems to be correct at that point (https://github.com/BioSTEAMDevelopmentGroup/thermosteam/blob/master/thermosteam/_stream.py#L896).

Maybe there is something wrong in my code?

import thermosteam as tmo

chemicals = tmo.Chemicals(['Water', 'Ethanol'])
thermo = tmo.Thermo(chemicals)
tmo.settings.set_thermo(thermo)
s3 = tmo.Stream('s3', T=300, P=1e5, Water=10, units='kg/hr')
s4 = tmo.Stream('s4', phase='g', T=400, P=1e5, Water=10, units='kg/hr')
s_eq = tmo.Stream('s34_mixture')
s_eq.mix_from([s3, s4])

print('MultiStream with enthalpy added by mix_from')
s_eq.vle(H=s_eq.H, P=1e5)
s_eq.show(composition=True)
print('Absolute deviation in enthalpy:', s_eq.H - (s3.H + s4.H))

print('MultiStream with Enthalpy summed individually')
s_eq.vle(H=s3.H + s4.H, P=1e5)
s_eq.show(composition=True)

yields

MultiStream with enthalpy added by mix_from
MultiStream: s34_mixture
 phases: ('g', 'l'), T: 372.79 K, P: 100000 Pa
 composition: (g) Water  1
                  -----  0.538 kmol/hr
              (l) Water  1
                  -----  0.572 kmol/hr
Absolute deviation in enthalpy: 1802.331630182045
MultiStream with Enthalpy summed individually
MultiStream: s34_mixture
 phases: ('g', 'l'), T: 372.79 K, P: 100000 Pa
 composition: (g) Water  1
                  -----  0.497 kmol/hr
              (l) Water  1
                  -----  0.614 kmol/hr
yoelcortes commented 3 years ago

Thanks for the bug report! It's been taken care of. You should get the following using your code:

MultiStream with enthalpy added by mix_from
MultiStream: s34_mixture
 phases: ('g', 'l'), T: 372.79 K, P: 100000 Pa
 composition: (g) Water  1
                  -----  0.497 kmol/hr
              (l) Water  1
                  -----  0.614 kmol/hr
Absolute deviation in enthalpy: -2.382876118645072e-09
MultiStream with Enthalpy summed individually
MultiStream: s34_mixture
 phases: ('g', 'l'), T: 372.79 K, P: 100000 Pa
 composition: (g) Water  1
                  -----  0.497 kmol/hr
              (l) Water  1
                  -----  0.614 kmol/hr

Edit: You can "pip install thermosteam==0.21.6" for convenience or use the github repo