CalebBell / thermo

Thermodynamics and Phase Equilibrium component of Chemical Engineering Design Library (ChEDL)
MIT License
594 stars 114 forks source link

Gas phase mixture enthalpy values decreasing with increased pressure #126

Closed OdhranOOC closed 1 year ago

OdhranOOC commented 1 year ago

Hi @CalebBell,

I was recently working with an air mixture in a thermodynamic system (calculating enthalpies, specific works, etc). I noticed that the gas phase enthalpy for an air mixture actually decreases with increased pressure. For example:

from chemicals import normalize
from thermo import ChemicalConstantsPackage, CEOSGas, CEOSLiquid, PRMIXTranslatedConsistent, FlashVL
from thermo.interaction_parameters import IPDB
import numpy as np
import matplotlib.pyplot as plt

constants, properties = ChemicalConstantsPackage.from_IDs(['nitrogen', 'oxygen', 'argon'])
kijs = IPDB.get_ip_asymmetric_matrix('ChemSep PR', constants.CASs, 'kij')
eos_kwargs = {'Pcs': constants.Pcs, 'Tcs': constants.Tcs, 'omegas': constants.omegas, 'kijs': kijs}
gas = CEOSGas(PRMIXTranslatedConsistent, eos_kwargs=eos_kwargs, HeatCapacityGases=properties.HeatCapacityGases)
liquid = CEOSLiquid(PRMIXTranslatedConsistent, eos_kwargs=eos_kwargs, HeatCapacityGases=properties.HeatCapacityGases)
flasher = FlashVL(constants, properties, liquid=liquid, gas=gas)
zs = normalize([78.08, 20.95, .93])

x = np.linspace(500000,20000000, 100)
gas_H = np.zeros_like(x)

k=0
for i in x:
    # print("i = ", i)
    gas_H[k] = flasher.flash(T=500, P=i, zs=zs, retry=True).H()
    k=k+1

plt.figure()
plt.plot(x,gas_H, label = "gas_H")
plt.xlabel("Pressure")
plt.ylabel("Enthalpy")
plt.legend()
plt.show()
Screenshot 2022-09-01 at 09 54 25

Is there possibly an alternative approach that would not show this behaviour? Unless I'm mistaken and this behaviour is actually correct?

Thanks and Regards, Odhran

CalebBell commented 1 year ago

Hi Odhran!

Yes, this is expected behavior. By the way, there is now a high-accuracy gas-only pseudo-pure model specifically for air in Thermo.

from thermo import *
import numpy as np
from thermo.phases import DryAirLemmon
import matplotlib.pyplot as plt
from thermo.chemical_package import lemmon2000_constants, lemmon2000_correlations
T, P = 298.15, 101325.0
gas = DryAirLemmon(T=T, P=P)
flasher = FlashPureVLS(constants=lemmon2000_constants, correlations=lemmon2000_correlations,
                   gas=gas, liquids=[], solids=[])
Ps = np.linspace(500000,20000000, 100)
gas_H = np.zeros_like(Ps)

k=0
for P in Ps:
    gas_H[k] = flasher.flash(T=500, P=float(P)).H()
    k=k+1

plt.figure()
plt.plot(Ps,gas_H, label = "gas_H")
plt.xlabel("Pressure")
plt.ylabel("Enthalpy")
plt.legend()
plt.show()

image

It also shows the same behavior. Note that when compressing air in real life, the temperature increases as the process is isentropic, which results in the significant compression duty.

OdhranOOC commented 1 year ago

Much appreciated Caleb! Ah interesting I did read that Lemmon paper a few years back actually. So can I swap out the current gas phase EOS then for the improved Lemmon one, and leave the liquid phase as it is? How would that look?

My current code for reference:

constants, properties = ChemicalConstantsPackage.from_IDs(['nitrogen', 'oxygen', 'argon'])
kijs = IPDB.get_ip_asymmetric_matrix('ChemSep PR', constants.CASs, 'kij')
eos_kwargs = {'Pcs': constants.Pcs, 'Tcs': constants.Tcs, 'omegas': constants.omegas, 'kijs': kijs}
gas = CEOSGas(PRMIXTranslatedConsistent, eos_kwargs=eos_kwargs, HeatCapacityGases=properties.HeatCapacityGases)
liquid = CEOSLiquid(PRMIXTranslatedConsistent, eos_kwargs=eos_kwargs, HeatCapacityGases=properties.HeatCapacityGases)
flasher = FlashVL(constants, properties, liquid=liquid, gas=gas)
zs = normalize([78.08, 20.95, .93])

Also, do you know if the Lemmon model is faster than the alternative I have above, or is it actually slower due to the increased accuracy?

Much appreciated

CalebBell commented 1 year ago

Hi Odhran, Unfortunately the Lemmon model is pseudo-pure, i.e. incapable of participating in vapor-liquid equilibrium. In thermo, you can only use it for obtaining vapor properties. Adding a liquid phase would not work with it. Additionally, it is slower due to its complexity. Sincerely, Caleb