feos-org / feos

FeOs - A Framework for Equations of State and Classical Density Functional Theory
Other
110 stars 22 forks source link

Can I use this package to calculate the critical points of binary mixture? #159

Closed RayleighSun closed 1 year ago

RayleighSun commented 1 year ago

Hi, thanks for your efforts. I'm very interested in the SAFT, and I'd like to use PC-SAFT to calculate the critical points of binary mixture. Can the package calculate the critical temperature and critical pressure of a binary mixture under certain composition? For example, ethane+propane, the molar fraction is 0.5 and 0.5? Is there a similar example?

Thanks!

prehner commented 1 year ago

Hello, you absolutely can do that. Here is an example:

from feos.eos import State, EquationOfState
from feos.pcsaft import PcSaftParameters
from feos.si import MOL
import numpy as np

params = PcSaftParameters.from_json(['ethane', 'propane'], '../../Code/feos/feos/parameters/pcsaft/gross2001.json')
eos = EquationOfState.pcsaft(params)
state = State.critical_point(eos, np.array([0.5, 0.5])*MOL)
print(f"Tc = {state.temperature}\npc = {state.pressure()}")
Tc = 348.1942845383163 K
pc = 5.270609715267454 MPa

gross2001.json contains the parameters from the original publication on PC-SAFT. You can downlad the file from this repository.

RayleighSun commented 1 year ago

Thanks for replying so quickly, it works perfectly, and it is very concise and easy to understand! But I have a small question, if I already have a binary interaction parameter kij, e.g. kij = 0.1, how should I set it for improving the results?

prehner commented 1 year ago

In general you can provide binary interaction parameters in a json file. For binary system, a more convenient way is to use:

from feos.eos import State, EquationOfState
from feos.pcsaft import PcSaftParameters
from feos.si import MOL
import numpy as np

params = PcSaftParameters.from_json(['ethane', 'propane'], '../../Code/feos/feos/parameters/pcsaft/gross2001.json')
kij = 0.1
params_kij = PcSaftParameters.new_binary(params.pure_records, kij)
eos = EquationOfState.pcsaft(params_kij)
state = State.critical_point(eos, np.array([0.5, 0.5])*MOL)
print(f"Tc = {state.temperature}\npc = {state.pressure()}")
Tc = 331.18585210347027 K
pc = 5.176779553533068 MPa
RayleighSun commented 1 year ago

Thanks!

RayleighSun commented 1 year ago

Hi, I got another question on critical point calculation of binary mixtures by the feos: What algorithm is used to calculate the critical point of the mixture? Such as the Heidemann-Khalil approach, or the defination of critical points (the first and second derivatives of pressure with respect to volume)?

prehner commented 1 year ago

Hello, the algorithm that is used is based on the Michelsen variant of the Heidemann-Khalil approach as outlined in the Michelsen and Mollerup book on thermodynamic models. The adaptation to our code, which uses automatic differentiation for all derivatives including Jacobians, is outlined in the appendix of our publication on the Application of Generalized (Hyper-) Dual Numbers in Equation of State Modeling.

Please be aware that for a mixture, vanishing first and second derivatives of the pressure with respect to volume or density are actually not criteria for critical points.

RayleighSun commented 1 year ago

Hello, the algorithm that is used is based on the Michelsen variant of the Heidemann-Khalil approach as outlined in the Michelsen and Mollerup book on thermodynamic models. The adaptation to our code, which uses automatic differentiation for all derivatives including Jacobians, is outlined in the appendix of our publication on the Application of Generalized (Hyper-) Dual Numbers in Equation of State Modeling.

Please be aware that for a mixture, vanishing first and second derivatives of the pressure with respect to volume or density are actually not criteria for critical points.

Thanks! So if it is pure substance, the critical point is calculated by the defination (the first and second derivatives of pressure with respect to volume)?

prehner commented 1 year ago

No, the same algorithm is used for pure components and mixtures.

RayleighSun commented 1 year ago

No, the same algorithm is used for pure components and mixtures.

Thanks!

MajorDUT commented 9 months ago

Hi, prehenr. Thanks for your efforts. May I ask how to execute the above code? Sorry, I am a newer. Also, I found some .rs file in the tests/pcsaft, for example critical_point.rs. In fact, I also want to calculate the critical point of binary mixutre, but I don't know how to execute it. Could you help me about this? Thanks, please.

g-bauer commented 9 months ago

Hello MajorDUT,

the code example given above is Python code. If you have Python and FeOs installed (e.g. using pip install feos) you should be able to use the code given above in a Python file or a jupyter notebook. Note that you might have to adjust the path to the parameter file (which you can find here).

FeOs can be used in Rust (.rs files) or Python. The example folder contains lots of jupyter notebooks for various things you can do with the library using Python.

MajorDUT commented 9 months ago

Hello MajorDUT,

the code example given above is Python code. If you have Python and FeOs installed (e.g. using pip install feos) you should be able to use the code given above in a Python file or a jupyter notebook. Note that you might have to adjust the path to the parameter file (which you can find here).

FeOs can be used in Rust (.rs files) or Python. The example folder contains lots of jupyter notebooks for various things you can do with the library using Python.

Thank you very much for your help, Bauer. I have done it.