UNIQUAC Gibbs Excess Model (thermo.uniquac)¶
This module contains a class UNIQUAC
for performing activity coefficient
calculations with the UNIQUAC model. An older, functional calculation for
activity coefficients only is also present, UNIQUAC_gammas
.
For reporting bugs, adding feature requests, or submitting pull requests, please use the GitHub issue tracker.
UNIQUAC Class¶
- class thermo.uniquac.UNIQUAC(*, xs, rs, qs, T=298.15, tau_coeffs=None, ABCDEF=None, tau_as=None, tau_bs=None, tau_cs=None, tau_ds=None, tau_es=None, tau_fs=None)[source]¶
Bases:
thermo.activity.GibbsExcess
Class for representing an a liquid with excess gibbs energy represented by the UNIQUAC equation. This model is capable of representing VL and LL behavior.
- Parameters
- T
float
Temperature, [K]
- xs
list
[float
] Mole fractions, [-]
- rs
list
[float
] r parameters if from UNIFAC, otherwise regressed, [-]
- qs
list
[float
] q parameters if from UNIFAC, otherwise regressed, [-]
- tau_coeffs
list
[list
[list
[float
]]],optional
UNIQUAC parameters, indexed by [i][j] and then each value is a 6 element list with parameters [a, b, c, d, e, f]; either tau_coeffs or ABCDEF are required, [-]
- ABCDEF
tuple
[list
[list
[float
]], 6],optional
Contains the following. One of tau_coeffs or ABCDEF or some of the tau_as, etc parameters are required, [-]
- tau_as
list
[list
[float
]]or
None
,optional
a parameters used in calculating
UNIQUAC.taus
, [-]- tau_bs
list
[list
[float
]]or
None
,optional
b parameters used in calculating
UNIQUAC.taus
, [K]- tau_cs
list
[list
[float
]]or
None
,optional
c parameters used in calculating
UNIQUAC.taus
, [-]- tau_ds
list
[list
[float
]]or
None
,optional
d paraemeters used in calculating
UNIQUAC.taus
, [1/K]- tau_es
list
[list
[float
]]or
None
,optional
e parameters used in calculating
UNIQUAC.taus
, [K^2]- tau_fs
list
[list
[float
]]or
None
,optional
f parameters used in calculating
UNIQUAC.taus
, [1/K^2]
- T
Notes
In addition to the methods presented here, the methods of its base class
thermo.activity.GibbsExcess
are available as well.Warning
There is no such thing as a missing parameter in the UNIQUAC model. It is possible to find and which make and , but those tau values depend on rs, qs, and xs - the composition, which obviously will change. It is therefore impossible to make an interaction parameter “missing”; whatever value it has will always impact the phase equilibria problem. At best, the tau values can produce close to ideal behavior.
References
- 1(1,2)
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
Example 1
Example 5.19 in [2] includes the calculation of liquid-liquid activity coefficients for the water-ethanol-benzene system. Two calculations are reproduced accurately here. Note that the DDBST-style coefficients assume a negative sign; for compatibility, their coefficients need to have their sign flipped.
>>> N = 3 >>> T = 25.0 + 273.15 >>> xs = [0.7273, 0.0909, 0.1818] >>> rs = [.92, 2.1055, 3.1878] >>> qs = [1.4, 1.972, 2.4] >>> tausA = tausC = tausD = tausE = tausF = [[0.0]*N for i in range(N)] >>> tausB = [[0, 526.02, 309.64], [-318.06, 0, -91.532], [1325.1, 302.57, 0]] >>> tausB = [[-v for v in r] for r in tausB] # Flip the sign to come into UNIQUAC convention >>> ABCDEF = (tausA, tausB, tausC, tausD, tausE, tausF) >>> GE = UNIQUAC(T=T, xs=xs, rs=rs, qs=qs, ABCDEF=ABCDEF) >>> GE.gammas() [1.570393328, 0.2948241614, 18.114329048]
The given values in [2] are [1.570, 0.2948, 18.11], matching exactly. The second phase has a different composition; the expected values are [8.856, 0.860, 1.425]. Once the
UNIQUAC
object has been constructed, it is very easy to obtain properties at different conditions:>>> GE.to_T_xs(T=T, xs=[1/6., 1/6., 2/3.]).gammas() [8.8559908058, 0.8595242462, 1.42546014081]
The string representation of the object presents enough information to reconstruct it as well.
>>> GE UNIQUAC(T=298.15, xs=[0.7273, 0.0909, 0.1818], rs=[0.92, 2.1055, 3.1878], qs=[1.4, 1.972, 2.4], ABCDEF=([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], [[0, -526.02, -309.64], [318.06, 0, 91.532], [-1325.1, -302.57, 0]], [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]))
The phase exposes many properties and derivatives as well.
>>> GE.GE(), GE.dGE_dT(), GE.d2GE_dT2() (1843.96486834, 6.69851118521, -0.015896025970) >>> GE.HE(), GE.SE(), GE.dHE_dT(), GE.dSE_dT() (-153.19624152, -6.69851118521, 4.7394001431, 0.0158960259705)
Example 2
Another problem is 8.32 in [1] - acetonitrile, benzene, n-heptane at 45 °C. The sign flip is needed here as well to convert their single temperature-dependent values into the correct form, but it has already been done to the coefficients:
>>> N = 3 >>> T = 45 + 273.15 >>> xs = [.1311, .0330, .8359] >>> rs = [1.87, 3.19, 5.17] >>> qs = [1.72, 2.4, 4.4] >>> tausA = tausC = tausD = tausE = tausF = [[0.0]*N for i in range(N)] >>> tausB = [[0.0, -60.28, -23.71], [-89.57, 0.0, 135.9], [-545.8, -245.4, 0.0]] >>> ABCDEF = (tausA, tausB, tausC, tausD, tausE, tausF) >>> GE = UNIQUAC(T=T, xs=xs, rs=rs, qs=qs, ABCDEF=ABCDEF) >>> GE.gammas() [7.1533533992, 1.25052436922, 1.060392792605]
The given values in [1] are [7.15, 1.25, 1.06].
Example 3
ChemSep is a program for modeling distillation. Chemsep ships with a permissive license several sets of binary interaction parameters. The UNIQUAC parameters in it can be accessed from Thermo as follows. In the following case, we compute activity coefficients of the ethanol-water system at mole fractions of [.252, 0.748].
>>> from thermo.interaction_parameters import IPDB >>> CAS1, CAS2 = '64-17-5', '7732-18-5' >>> xs = [0.252, 0.748] >>> rs = [2.11, 0.92] >>> qs = [1.97, 1.400] >>> N = 2 >>> T = 343.15 >>> tau_bs = IPDB.get_ip_asymmetric_matrix(name='ChemSep UNIQUAC', CASs=['64-17-5', '7732-18-5'], ip='bij') >>> GE = UNIQUAC(T=T, xs=xs, rs=rs, qs=qs, tau_bs=tau_bs) >>> GE.gammas() [1.977454, 1.1397696]
In ChemSep, the form of the UNIQUAC tau equation is
The parameters were converted to the form used by Thermo as follows:
This system was chosen because there is also a sample problem for the same components from the DDBST which can be found here: http://chemthermo.ddbst.com/Problems_Solutions/Mathcad_Files/P05.01c%20VLE%20Behavior%20of%20Ethanol%20-%20Water%20Using%20UNIQUAC.xps
In that example, with different data sets and parameters, they obtain at the same conditions activity coefficients of [2.359, 1.244].
Methods
GE
()Calculate and return the excess Gibbs energy of a liquid phase using the UNIQUAC model.
d2GE_dT2
()Calculate and return the second temperature derivative of excess Gibbs energy of a liquid phase using the UNIQUAC model.
Calculate and return the temperature derivative of mole fraction derivatives of excess Gibbs energy using the UNIQUAC model.
Calculate and return the second mole fraction derivatives of excess Gibbs energy using the UNIQUAC model.
Calculate and return the second temperature derivative of the tau
d3GE_dT3
()Calculate and return the third temperature derivative of excess Gibbs energy of a liquid phase using the UNIQUAC model.
Calculate and return the third temperature derivative of the tau terms for the UNIQUAC model for a specified temperature.
dGE_dT
()Calculate and return the temperature derivative of excess Gibbs energy of a liquid phase using the UNIQUAC model.
dGE_dxs
()Calculate and return the mole fraction derivatives of excess Gibbs energy using the UNIQUAC model.
dtaus_dT
()Calculate and return the temperature derivative of the tau terms for the UNIQUAC model for a specified temperature.
phis
()Calculate and return the phi parameters at the system composition and temperature.
regress_binary_parameters
(gammas, xs, rs, qs)Perform a basic regression to determine the values of the tau terms in the UNIQUAC model, given a series of known or predicted activity coefficients and mole fractions.
taus
()Calculate and return the tau terms for the UNIQUAC model for the system temperature.
thetas
()Calculate and return the theta parameters at the system composition and temperature.
to_T_xs
(T, xs)Method to construct a new
UNIQUAC
instance at temperature T, and mole fractions xs with the same parameters as the existing object.- GE()[source]¶
Calculate and return the excess Gibbs energy of a liquid phase using the UNIQUAC model.
- Returns
- GE
float
Excess Gibbs energy, [J/mol]
- GE
- d2GE_dT2()[source]¶
Calculate and return the second temperature derivative of excess Gibbs energy of a liquid phase using the UNIQUAC model.
- Returns
- d2GE_dT2
float
Second temperature derivative of excess Gibbs energy, [J/(mol*K^2)]
- d2GE_dT2
- d2GE_dTdxs()[source]¶
Calculate and return the temperature derivative of mole fraction derivatives of excess Gibbs energy using the UNIQUAC model.
- d2GE_dxixjs()[source]¶
Calculate and return the second mole fraction derivatives of excess Gibbs energy using the UNIQUAC model.
- Returns
Notes
The formula is extremely long and painful; see the source code for details.
- d2taus_dT2()[source]¶
- Calculate and return the second temperature derivative of the tau
terms for the UNIQUAC model for a specified temperature.
- Returns
Notes
These values (and the coefficients) are NOT symmetric.
- d3GE_dT3()[source]¶
Calculate and return the third temperature derivative of excess Gibbs energy of a liquid phase using the UNIQUAC model.
- Returns
- d3GE_dT3
float
Third temperature derivative of excess Gibbs energy, [J/(mol*K^3)]
- d3GE_dT3
- d3taus_dT3()[source]¶
Calculate and return the third temperature derivative of the tau terms for the UNIQUAC model for a specified temperature.
- Returns
Notes
These values (and the coefficients) are NOT symmetric.
- dGE_dT()[source]¶
Calculate and return the temperature derivative of excess Gibbs energy of a liquid phase using the UNIQUAC model.
- Returns
- dGE_dT
float
First temperature derivative of excess Gibbs energy, [J/(mol*K)]
- dGE_dT
- dGE_dxs()[source]¶
Calculate and return the mole fraction derivatives of excess Gibbs energy using the UNIQUAC model.
- dtaus_dT()[source]¶
Calculate and return the temperature derivative of the tau terms for the UNIQUAC model for a specified temperature.
- Returns
Notes
These values (and the coefficients) are NOT symmetric.
- classmethod regress_binary_parameters(gammas, xs, rs, qs, use_numba=False, do_statistics=True, **kwargs)[source]¶
Perform a basic regression to determine the values of the tau terms in the UNIQUAC model, given a series of known or predicted activity coefficients and mole fractions.
- Parameters
- gammas
list
[list
[float
, 2]] List of activity coefficient pairs, [-]
- xs
list
[list
[float
, 2]] List of binary mole fraction pairs, [-]
- rs
list
[float
] Van der Waals volume parameters for each species, [-]
- qs
list
[float
] Surface area parameters for each species, [-]
- use_numbabool,
optional
Whether or not to try to use numba to speed up the computation, [-]
- do_statisticsbool,
optional
Whether or not to compute statistical measures on the outputs, [-]
- kwargs
dict
Extra parameters to be passed to the fitting function (not yet documented), [-]
- gammas
- Returns
Notes
Notes on getting fitting coefficients that yield gammas of 1:
This is possible some of the time to a pretty high accuracy
This is not possible whatsoever in some cases
The values of rs, and qs determine how close the fitting can be
If rs and qs are close to each other, it may well fit nicely
If they are distant (1.2-1.5x) they usually will not fit
Examples
In the following example, the tau values required to zero-out the coefficients for the n-pentane and n-hexane system are calculated. The parameters are converted back into aij parameters as used by this activity coefficient object, and then the calculated values are verified to be fairly nearly one.
>>> from thermo import UNIQUAC >>> import numpy as np >>> pts = 30 >>> rs = [3.8254, 4.4998] >>> qs = [3.316, 3.856] >>> xs = [[xi, 1.0 - xi] for xi in np.linspace(1e-7, 1-1e-7, pts)] >>> gammas = [[1, 1] for i in range(pts)] >>> coeffs, stats = UNIQUAC.regress_binary_parameters(gammas, xs, rs, qs) >>> coeffs {'tau12': 1.04220685, 'tau21': 0.95538082} >>> assert stats['MAE'] < 1e-6 >>> tausB = tausC = tausD = tausE = tausF = [[0.0]*2 for i in range(2)] >>> tausA = [[0, np.log(coeffs['tau12'])], [np.log(coeffs['tau21']), 0]] >>> ABCDEF = (tausA, tausB, tausC, tausD, tausE, tausF) >>> GE = UNIQUAC(T=300, xs=[.5, .5], rs=rs, qs=qs, ABCDEF=ABCDEF) >>> GE.gammas() [1.000000466, 1.000000180]
Note how the tau coefficients need to be converted into the a parameters of the tau equation. They could also have been converted into any of the other parameters, but then the activity coefficients predicted would no longer be close to 1 at other temperatures.
The UNIQUAC model’s r and q parameters create their own biases in the model, based on the structure of each of the pure species. Water and n-pentane are not miscible liquids; they will form two liquid phases except when one component is present in trace amounts. No matter the values of tau, it is not possible to make the UNIQUAC equation predict activity coefficients very close to one for this system, as shown in the following sample.
>>> rs = [3.8254, 0.92] >>> qs = [3.316, 1.4] >>> pts = 6 >>> xs = [[xi, 1.0 - xi] for xi in np.linspace(1e-7, 1-1e-7, pts)] >>> gammas = [[1, 1] for i in range(pts)] >>> coeffs, stats = UNIQUAC.regress_binary_parameters(gammas, xs, rs, qs) >>> stats['MAE'] 0.0254
- taus()[source]¶
Calculate and return the tau terms for the UNIQUAC model for the system temperature.
Notes
These tau ij values (and the coefficients) are NOT symmetric.
- thetas()[source]¶
Calculate and return the theta parameters at the system composition and temperature.
- to_T_xs(T, xs)[source]¶
Method to construct a new
UNIQUAC
instance at temperature T, and mole fractions xs with the same parameters as the existing object.- Parameters
- Returns
Notes
If the new temperature is the same temperature as the existing temperature, if the tau terms or their derivatives have been calculated, they will be set to the new object as well.
UNIQUAC Functional Calculations¶
- thermo.uniquac.UNIQUAC_gammas(xs, rs, qs, taus)[source]¶
Calculates the activity coefficients of each species in a mixture using the Universal quasi-chemical (UNIQUAC) equation, given their mole fractions, rs, qs, and dimensionless interaction parameters. The interaction parameters are normally correlated with temperature, and need to be calculated separately.
- Parameters
- Returns
Notes
This model needs N^2 parameters.
The original expression for the interaction parameters is as follows:
However, it is seldom used. Most correlations for the interaction parameters include some of the terms shown in the following form:
This model is recast in a slightly more computationally efficient way in [2], as shown below:
There is no global set of parameters which will make this model yield ideal acitivty coefficients (gammas = 1) for this model.
References
- 1
Abrams, Denis S., and John M. Prausnitz. “Statistical Thermodynamics of Liquid Mixtures: A New Expression for the Excess Gibbs Energy of Partly or Completely Miscible Systems.” AIChE Journal 21, no. 1 (January 1, 1975): 116-28. doi:10.1002/aic.690210115.
- 2
Gmehling, Jurgen, Barbel Kolbe, Michael Kleiber, and Jurgen Rarey. Chemical Thermodynamics for Process Simulation. 1st edition. Weinheim: Wiley-VCH, 2012.
- 3
Maurer, G., and J. M. Prausnitz. “On the Derivation and Extension of the Uniquac Equation.” Fluid Phase Equilibria 2, no. 2 (January 1, 1978): 91-99. doi:10.1016/0378-3812(78)85002-X.
Examples
Ethanol-water example, at 343.15 K and 1 MPa:
>>> UNIQUAC_gammas(xs=[0.252, 0.748], rs=[2.1055, 0.9200], qs=[1.972, 1.400], ... taus=[[1.0, 1.0919744384510301], [0.37452902779205477, 1.0]]) [2.35875137797083, 1.2442093415968987]