UNIFAC Gibbs Excess Model (thermo.unifac)¶
This module contains functions and classes related to the UNIFAC and its many variants. The bulk of the code relates to calculating derivativies, or is tables of data.
For reporting bugs, adding feature requests, or submitting pull requests, please use the GitHub issue tracker or contact the author at Caleb.Andrew.Bell@gmail.com.
Main Model (Object-Oriented)¶
- class thermo.unifac.UNIFAC(*, xs, rs, qs, Qs, vs, T=298.15, psi_coeffs=None, psi_abc=None, psi_a=None, psi_b=None, psi_c=None, version=0)[source]¶
Class for representing an a liquid with excess gibbs energy represented by the UNIFAC equation. This model is capable of representing VL and LL behavior, provided the correct interaction parameters are used. [1] and [2] are good references on this model.
- Parameters
- T
float
Temperature, [K]
- xs
list
[float
] Mole fractions, [-]
- rs
list
[float
] r parameters , [-]
- qs
list
[float
] q parameters , [-]
- Qs
list
[float
] Q parameter for each subgroup; subgroups are not required to but are suggested to be sorted from lowest number to highest number, [-]
- vs
list
[list
[float
]] Indexed by [subgroup][count], this variable is the count of each subgroups in each compound, [-]
- psi_abc
tuple
(list
[list
[float
]], 3),optional
psi interaction parameters between each subgroup; indexed [subgroup][subgroup], not symmetrical; first arg is the matrix for a, then b, and then c. Only one of psi_abc or psi_coeffs or psi_a and psi_b and psi_c is required, [-]
- psi_coeffs
list
[list
[tuple
(float
, 3)]],optional
psi interaction parameters between each subgroup; indexed [subgroup][subgroup][letter], not symmetrical. Only one of psi_abc or psi_coeffs or psi_a and psi_b and psi_c is required, [-]
- psi_a
list
[list
[float
]],optional
psi a term interaction parameters between each subgroup; indexed [subgroup][subgroup]. Only one of psi_abc or psi_coeffs or psi_a and psi_b and psi_c is required, [-]
- psi_b
list
[list
[float
]],optional
psi b term interaction parameters between each subgroup; indexed [subgroup][subgroup]. Only one of psi_abc or psi_coeffs or psi_a and psi_b and psi_c is required, [-]
- psi_c
list
[list
[float
]],optional
psi c term interaction parameters between each subgroup; indexed [subgroup][subgroup]. Only one of psi_abc or psi_coeffs or psi_a and psi_b and psi_c is required, [-]
- version
int
,optional
Which version of the model to use [-]
0 - original UNIFAC, OR UNIFAC LLE
1 - Dortmund UNIFAC (adds T dept, 3/4 power)
2 - PSRK (original with T dept function)
3 - VTPR (drops combinatorial term, Dortmund UNIFAC otherwise)
4 - Lyngby/Larsen has different combinatorial, 2/3 power
5 - UNIFAC KT (2 params for psi, Lyngby/Larsen formulation; otherwise same as original)
- T
Notes
In addition to the methods presented here, the methods of its base class
thermo.activity.GibbsExcess
are available as well.References
- 1
Poling, Bruce E., John M. Prausnitz, and John P. O`Connell. The Properties of Gases and Liquids. 5th edition. New York: McGraw-Hill Professional, 2000.
- 2(1,2)
Gmehling, Jürgen, Michael Kleiber, Bärbel Kolbe, and Jürgen Rarey. Chemical Thermodynamics for Process Simulation. John Wiley & Sons, 2019.
Examples
The DDBST has published numerous sample problems using UNIFAC; a simple binary system from example P05.22a in [2] with n-hexane and butanone-2 is shown below:
>>> from thermo.unifac import UFIP, UFSG >>> GE = UNIFAC.from_subgroups(chemgroups=[{1:2, 2:4}, {1:1, 2:1, 18:1}], T=60+273.15, xs=[0.5, 0.5], version=0, interaction_data=UFIP, subgroups=UFSG) >>> GE.gammas() [1.4276025835, 1.3646545010] >>> GE.GE(), GE.dGE_dT(), GE.d2GE_dT2() (923.641197, 0.206721488, -0.00380070204) >>> GE.HE(), GE.SE(), GE.dHE_dT(), GE.dSE_dT() (854.77193363, -0.2067214889, 1.266203886, 0.0038007020460)
The solution given by the DDBST has the same values [1.428, 1.365], and can be found here: http://chemthermo.ddbst.com/Problems_Solutions/Mathcad_Files/05.22a%20VLE%20of%20Hexane-Butanone-2%20Via%20UNIFAC%20-%20Step%20by%20Step.xps
Methods
CpE
()Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.
Fis
()Calculate the terms used in calculating the combinatorial part.
Fs
()Computes the following:
Fs_pure
()Computes the following:
GE
()Calculate the excess Gibbs energy with the UNIFAC model.
Gs
()Computes the following:
Gs_pure
()Computes the following:
HE
()Calculate and return the excess entropy of a liquid phase using an activity coefficient model.
Hs
()Computes the following:
Hs_pure
()Computes the following:
SE
()Calculates the excess entropy of a liquid phase using an activity coefficient model.
Computes the following term for each group k, size number of groups.
Computes the following term for each group k, size number of groups.
Computes the following term for each group k, size number of groups.
Thetas
()Calculate the parameters used in calculating the residual part.
Calculate the parameters for each chemical in the mixture as a pure species, used in calculating the residual part.
Vis
()Calculate the terms used in calculating the combinatorial part.
Calculate the terms used in calculating the combinatorial part.
Ws
()Computes the following for each k and each i, indexed by [k][i] k is in groups, and i is in components.
Xs
()Calculate the parameters used in calculating the residual part.
Xs_pure
()Calculate the parameters for each chemical in the mixture as a pure species, used in calculating the residual part.
as_json
([cache, option])Method to create a JSON-friendly representation of the Gibbs Excess model which can be stored, and reloaded later.
Calculate the second mole fraction derivative of the terms used in calculating the combinatorial part.
d2GE_dT2
()Calculate the second temperature derivative of excess Gibbs energy with the UNIFAC model.
d2GE_dTdns
()Calculate and return the mole number derivative of the first temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
Calculate the first composition derivative and temperature derivative of excess Gibbs energy with the UNIFAC model.
Calculate the second composition derivative of excess Gibbs energy with the UNIFAC model.
Calculate the mole fraction derivatives of the parameters.
Calculate the second mole fraction derivative of the terms used in calculating the combinatorial part.
Calculate the second mole fraction derivative of the terms used in calculating the combinatorial part.
Calculate the second temperature derivative of the parameters for the phase; depends on the phases's composition and temperature.
Calculate the temperature and mole fraction derivatives of the parameters for the phase; depends on the phases's composition and temperature.
Calculate the second mole fraction derivatives of the parameters for the phase; depends on the phases's composition and temperature.
Calculate the second temperature derivative of pure component parameters for the phase; depends on the phases's temperature only.
Second temperature derivatives of the combinatorial part of the UNIFAC model.
Second temperature derivative and first mole fraction derivative of the combinatorial part of the UNIFAC model.
Second composition derivative of the combinatorial part of the UNIFAC model.
Calculates the second temperature derivative of the residual part of the UNIFAC model.
Calculates the second temperature derivative of the residual part of the UNIFAC model.
Calculates the first mole fraction derivative of the temperature derivative of the residual part of the UNIFAC model.
Calculates the second mole fraction derivative of the residual part of the UNIFAC model.
d2nGE_dTdns
()Calculate and return the partial mole number derivative of the first temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
d2nGE_dninjs
()Calculate and return the second partial mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
Calculate the term second temperature derivative matrix for all groups interacting with all other groups.
Calculate the third mole fraction derivative of the terms used in calculating the combinatorial part.
d3GE_dT3
()Calculate the third temperature derivative of excess Gibbs energy with the UNIFAC model.
Calculate the third mole fraction derivative of the terms used in calculating the combinatorial part.
Calculate the third mole fraction derivative of the terms used in calculating the combinatorial part.
Calculate the third temperature derivative of the parameters for the phase; depends on the phases's composition and temperature.
Calculate the third temperature derivative of pure component parameters for the phase; depends on the phases's temperature only.
Third temperature derivatives of the combinatorial part of the UNIFAC model.
Third composition derivative of the combinatorial part of the UNIFAC model.
Calculates the third temperature derivative of the residual part of the UNIFAC model.
Calculates the third temperature derivative of the residual part of the UNIFAC model.
Calculate the term third temperature derivative matrix for all groups interacting with all other groups.
dFis_dxs
()Calculate the mole fraction derivative of the terms used in calculating the combinatorial part.
dGE_dT
()Calculate the first temperature derivative of excess Gibbs energy with the UNIFAC model.
dGE_dns
()Calculate and return the mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
dGE_dxs
()Calculate the first composition derivative of excess Gibbs energy with the UNIFAC model.
dHE_dT
()Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.
dHE_dns
()Calculate and return the mole number derivative of excess enthalpy of a liquid phase using an activity coefficient model.
dHE_dxs
()Calculate and return the mole fraction derivative of excess enthalpy of a liquid phase using an activity coefficient model.
dSE_dT
()Calculate and return the first temperature derivative of excess entropy of a liquid phase using an activity coefficient model.
dSE_dns
()Calculate and return the mole number derivative of excess entropy of a liquid phase using an activity coefficient model.
dSE_dxs
()Calculate and return the mole fraction derivative of excess entropy of a liquid phase using an activity coefficient model.
Calculate the mole fraction derivatives of the parameters.
dVis_dxs
()Calculate the mole fraction derivative of the terms used in calculating the combinatorial part.
Calculate the mole fraction derivative of the terms used in calculating the combinatorial part.
Calculates the first temperature derivative of activity coefficients with the UNIFAC model.
Calculate and return the mole number derivative of activity coefficients of a liquid phase using an activity coefficient model.
Calculates the first mole fraction derivative of activity coefficients with the UNIFAC model.
Calculate the first temperature derivative of the parameters for the phase; depends on the phases's composition and temperature.
Calculate the mole fraction derivatives of the parameters for the phase; depends on the phases's composition and temperature.
Calculate the first temperature derivative of pure component parameters for the phase; depends on the phases's temperature only.
Temperature derivatives of the combinatorial part of the UNIFAC model.
First composition derivative of the combinatorial part of the UNIFAC model.
Calculates the first temperature derivative of the residual part of the UNIFAC model.
Calculates the first temperature derivative of the residual part of the UNIFAC model.
Calculates the first mole fraction derivative of the residual part of the UNIFAC model.
dnGE_dns
()Calculate and return the partial mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
dnHE_dns
()Calculate and return the partial mole number derivative of excess enthalpy of a liquid phase using an activity coefficient model.
dnSE_dns
()Calculate and return the partial mole number derivative of excess entropy of a liquid phase using an activity coefficient model.
dpsis_dT
()Calculate the term first temperature derivative matrix for all groups interacting with all other groups.
exact_hash
()Method to calculate and return a hash representing the exact state of the object.
from_json
(json_repr[, cache])Method to create a Gibbs Excess model from a JSON-friendly serialization of another Gibbs Excess model.
from_subgroups
(T, xs, chemgroups[, ...])Method to construct a UNIFAC object from a dictionary of interaction parameters parameters and a list of dictionaries of UNIFAC keys.
gammas
()Calculates the activity coefficients with the UNIFAC model.
gammas_args
([T])Return a tuple of arguments at the specified tempearture that can be used to efficiently compute gammas at the specified temperature but with varying compositions.
gammas_infinite_dilution
()Calculate and return the infinite dilution activity coefficients of each component.
Calculate the parameters for the phase; depends on the phases's composition and temperature.
Calculate the pure component parameters for the phase; depends on the phases's temperature only.
lngammas
()Calculate and return the natural logarithm of the activity coefficients of a liquid phase using an activity coefficient model.
Calculates the combinatorial part of the UNIFAC model.
Calculates the residual part of the UNIFAC model.
model_hash
()Basic method to calculate a hash of the non-state parts of the model This is useful for comparing to models to determine if they are the same, i.e. in a VLL flash it is important to know if both liquids have the same model.
psis
()Calculate the term matrix for all groups interacting with all other groups.
state_hash
()Basic method to calculate a hash of the state of the model and its model parameters.
to_T_xs
(T, xs)Method to construct a new
UNIFAC
instance at temperature T, and mole fractions xs with the same parameters as the existing object.Theta_pure_Psi_sums
Thetas_sum_inv
VSXS
Xs_sum_inv
d2GE_dT2_numerical
d2GE_dTdxs_numerical
d2GE_dxixjs_numerical
d3GE_dT2dxs_numerical
d3GE_dT3_numerical
d3GE_dTdxixjs_numerical
d4GE_dT2dxixjs_numerical
d4GE_dT3dxs_numerical
d4GE_dT4_numerical
d5GE_dT3dxixjs_numerical
dGE_dT_numerical
dGE_dxs_numerical
gammas_dGE_dxs
gammas_from_args
gammas_numerical
- Fis()[source]¶
Calculate the terms used in calculating the combinatorial part. A function of mole fractions and the parameters q only.
This is used in the UNIFAC, UNIFAC-LLE, UNIFAC Dortmund, UNIFAC-NIST, and PSRK models.
- GE()[source]¶
Calculate the excess Gibbs energy with the UNIFAC model.
For the VTPR model, the combinatorial component is set to zero.
- Returns
- GE
float
Excess Gibbs energy, [J/mol]
- GE
- Theta_pure_Psi_sum_invs()[source]¶
Computes the following term for each group k, size number of groups.
- Thetas()[source]¶
Calculate the parameters used in calculating the residual part. A function of mole fractions and group counts only.
- Thetas_pure()[source]¶
Calculate the parameters for each chemical in the mixture as a pure species, used in calculating the residual part. A function of group counts only.
- Vis()[source]¶
Calculate the terms used in calculating the combinatorial part. A function of mole fractions and the parameters r only.
This is used in the UNIFAC, UNIFAC-LLE, UNIFAC Dortmund, UNIFAC-NIST, and PSRK models.
- Vis_modified()[source]¶
Calculate the terms used in calculating the combinatorial part. A function of mole fractions and the parameters r only.
This is used in the UNIFAC Dortmund and UNIFAC-NIST model with n=0.75, and the Lyngby model with n=2/3.
- Ws()[source]¶
Computes the following for each k and each i, indexed by [k][i] k is in groups, and i is in components.
- Xs()[source]¶
Calculate the parameters used in calculating the residual part. A function of mole fractions and group counts only.
- Xs_pure()[source]¶
Calculate the parameters for each chemical in the mixture as a pure species, used in calculating the residual part. A function of group counts only, not even mole fractions or temperature.
- d2Fis_dxixjs()[source]¶
Calculate the second mole fraction derivative of the terms used in calculating the combinatorial part. A function of mole fractions and the parameters q only.
This is used in the UNIFAC, UNIFAC-LLE, UNIFAC Dortmund, UNIFAC-NIST, and PSRK models.
- d2GE_dT2()[source]¶
Calculate the second temperature derivative of excess Gibbs energy with the UNIFAC model.
- Returns
- d2GE_dT2
float
Second temperature derivative of excess Gibbs energy, [J/mol/K^2]
- d2GE_dT2
- d2GE_dTdxs()[source]¶
Calculate the first composition derivative and temperature derivative of excess Gibbs energy with the UNIFAC model.
- d2GE_dxixjs()[source]¶
Calculate the second composition derivative of excess Gibbs energy with the UNIFAC model.
- d2Thetas_dxixjs()[source]¶
Calculate the mole fraction derivatives of the parameters. A function of mole fractions and group counts only.
- d2Vis_dxixjs()[source]¶
Calculate the second mole fraction derivative of the terms used in calculating the combinatorial part. A function of mole fractions and the parameters r only.
This is used in the UNIFAC, UNIFAC-LLE, UNIFAC Dortmund, UNIFAC-NIST, and PSRK models.
- d2Vis_modified_dxixjs()[source]¶
Calculate the second mole fraction derivative of the terms used in calculating the combinatorial part. A function of mole fractions and the parameters r only.
This is used in the UNIFAC Dortmund and UNIFAC-NIST model with n=0.75, and the Lyngby model with n=2/3.
- d2lnGammas_subgroups_dT2()[source]¶
Calculate the second temperature derivative of the parameters for the phase; depends on the phases’s composition and temperature.
- d2lnGammas_subgroups_dTdxs()[source]¶
Calculate the temperature and mole fraction derivatives of the parameters for the phase; depends on the phases’s composition and temperature.
The following groups are used as follows to simplfy the number of evaluations:
In the below expression, k` refers to a group, and i refers to a component.
- d2lnGammas_subgroups_dxixjs()[source]¶
Calculate the second mole fraction derivatives of the parameters for the phase; depends on the phases’s composition and temperature.
The following groups are used as follows to simplfy the number of evaluations:
- d2lnGammas_subgroups_pure_dT2()[source]¶
Calculate the second temperature derivative of pure component parameters for the phase; depends on the phases’s temperature only.
In this model, the values come from the
UNIFAC.Thetas_pure
method, where each compound is assumed to be pure.
- d2lngammas_c_dT2()[source]¶
Second temperature derivatives of the combinatorial part of the UNIFAC model. Zero in all variations.
- d2lngammas_c_dTdx()[source]¶
Second temperature derivative and first mole fraction derivative of the combinatorial part of the UNIFAC model. Zero in all variations.
- d2lngammas_c_dxixjs()[source]¶
Second composition derivative of the combinatorial part of the UNIFAC model. For the modified UNIFAC model, the equation is as follows; for the original UNIFAC and UNIFAC LLE, replace with .
For the Lyngby model, the following equations are used:
- d2lngammas_dT2()¶
Calculates the second temperature derivative of the residual part of the UNIFAC model.
where the second Gamma is the pure-component Gamma of group k in component i.
- d2lngammas_r_dT2()[source]¶
Calculates the second temperature derivative of the residual part of the UNIFAC model.
where the second Gamma is the pure-component Gamma of group k in component i.
- d2lngammas_r_dTdxs()[source]¶
Calculates the first mole fraction derivative of the temperature derivative of the residual part of the UNIFAC model.
- d2lngammas_r_dxixjs()[source]¶
Calculates the second mole fraction derivative of the residual part of the UNIFAC model.
- d2psis_dT2()[source]¶
Calculate the term second temperature derivative matrix for all groups interacting with all other groups.
The main model calculates the derivative as a function of three coefficients;
Only the first, a coefficient, is used in the original UNIFAC model as well as the UNIFAC-LLE model, so the expression simplifies to:
For the Lyngby model, the second temperature derivative is:
with K and the a coefficients are specific to each pair of main groups, and they are asymmetric, so .
- d3Fis_dxixjxks()[source]¶
Calculate the third mole fraction derivative of the terms used in calculating the combinatorial part. A function of mole fractions and the parameters q only.
This is used in the UNIFAC, UNIFAC-LLE, UNIFAC Dortmund, UNIFAC-NIST, and PSRK models.
- d3GE_dT3()[source]¶
Calculate the third temperature derivative of excess Gibbs energy with the UNIFAC model.
- Returns
- d3GE_dT3
float
Third temperature derivative of excess Gibbs energy, [J/mol/K^3]
- d3GE_dT3
- d3Vis_dxixjxks()[source]¶
Calculate the third mole fraction derivative of the terms used in calculating the combinatorial part. A function of mole fractions and the parameters r only.
This is used in the UNIFAC, UNIFAC-LLE, UNIFAC Dortmund, UNIFAC-NIST, and PSRK models.
- d3Vis_modified_dxixjxks()[source]¶
Calculate the third mole fraction derivative of the terms used in calculating the combinatorial part. A function of mole fractions and the parameters r only.
This is used in the UNIFAC Dortmund and UNIFAC-NIST model with n=0.75, and the Lyngby model with n=2/3.