CalebBell / thermo

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

Compute speed of sound of a mixture with a cubic eos #121

Closed tbridel closed 1 year ago

tbridel commented 1 year ago

Dear all,

This issue is mostly a question regarding the how to best manipulate the API of thermo.

Let us consider a mixture of N gases (only gases) with a cubic EOS (IG or one of the PR family). Once the thermo.eos_mix is set-up, how can one deduce the speed of sound in the mixture ?

Thank you !

CalebBell commented 1 year ago

You can't do it directly with an eos_mix object, they don't know the heat capacity of the ideal gas. You need at least a Phase object but that's usually not what you want as you also want equilibrium conditions solved. Here is a sample of getting speed of sound with Peng-Robinson for a ternary mixture.

from thermo import ChemicalConstantsPackage, CEOSGas, CEOSLiquid, PRMIX, FlashVL
from thermo.interaction_parameters import IPDB
constants, properties = ChemicalConstantsPackage.from_IDs(['methane', 'ethane', 'nitrogen'])
kijs = IPDB.get_ip_asymmetric_matrix('ChemSep PR', constants.CASs, 'kij')
kijs

eos_kwargs = {'Pcs': constants.Pcs, 'Tcs': constants.Tcs, 'omegas': constants.omegas, 'kijs': kijs}
gas = CEOSGas(PRMIX, eos_kwargs=eos_kwargs, HeatCapacityGases=properties.HeatCapacityGases)
liquid = CEOSLiquid(PRMIX, eos_kwargs=eos_kwargs, HeatCapacityGases=properties.HeatCapacityGases)
flasher = FlashVL(constants, properties, liquid=liquid, gas=gas)
zs = [0.965, 0.018, 0.017]
state = flasher.flash(T=400.0, P=1e5, zs=zs)

state.speed_of_sound_mass()

This returns 502.7488693714694, in units of m/s.

tbridel commented 1 year ago

@CalebBell Thank you for the complete answer ! :)

Your solution works well for multi-atomic species, but I cannot figure out how to make it work for mixtures with non-negligible fractions of mono-atomic species, say a "complex" air made of [N2, O2, O, He, H, Ar, N].

So I am not a specialist but from what I could see, the interaction parameters for monoatomic species are set to 0 which then prevents the flash from happening. Do you know if it is possible at all to get a result ?

CalebBell commented 1 year ago

@tbridel I'll need to see an example to know what is going wrong; interaction parameters can be zero and the calculation still works fine and is meaningful. Maybe one of the species you are trying to use doesn't have a critical parameter available?

tbridel commented 1 year ago

@CalebBell Hmm OK I see, thank you.

From the tests I ran it seems that when using either "monohydrogen" or "17778-88-0" (which is atomic nitrogen) the flash crashes, and after checking, Pcs and Tcs are set to None for those species indeed.

Is that something that is database dependent or is it just something I'll have to live with 😄 ? (I get the constants and properties from ChemicalConstantsPackage.from_IDs([...])).

CalebBell commented 1 year ago

The ChemicalConstantsPackage.from_IDs method loads values from a database, but you can also provide your own values, and create the package yourself. Some documentation is here: https://thermo.readthedocs.io/chemical_package_tutorial.html

The next question would be, what values you would even use? Certainly there are none available in the literature.

I'll try to add a check with a helpful error message for a missing critical property in the future to avoid this.

tbridel commented 1 year ago

Thank you the link ! But, yes, as you say, I am not sure there are any values in the literature ... 🤔

And thank you for the warning, I think it might be easier to understand what is happening indeed.

The application could interest you though, because I saw in your fluids package you also use MSIS and what I am trying to do is just use their data to create a mixture whence I can then compute all the other characteristics (speed of sound, gamma, kinematic viscosity, Cp, enthalpy, etc...). Did you ever tried something like this ?

CalebBell commented 1 year ago

@tbridel for applications like that you should use the ideal-gas model. The atmosphere is reactive, with magnetic impact as well. Those phenomenon can't be modeled with an equilibrium model anyway.

tbridel commented 1 year ago

At the very beginning I was relying on an IGMIX from eos_mix but it was hard to get all the properties I need out of the mixture - speed of sound, ratio of specific heats, enthalpy, kinematic viscosity, etc...

Could you please suggest something to model the mix of IG out of equilibrium ? How would you go about it, broadly ?