Skip to content

polykin.thermo.acm¤

UNIQUAC ¤

Bases: MolecularACM

UNIQUAC multicomponent activity coefficient model.

This model is based on the following molar excess Gibbs energy expression:

\[\begin{aligned} g^E &= g^R + g^C \\ \frac{g^R}{R T} &= -\sum_i q_i x_i \ln{\left ( \sum_j \theta_j \tau_{ji} \right )} \\ \frac{g^C}{R T} &= \sum_i x_i \ln{\frac{\Phi_i}{x_i}} + 5\sum_i q_ix_i \ln{\frac{\theta_i}{\Phi_i}} \end{aligned}\]

with:

\[\begin{aligned} \Phi_i =\frac{x_i r_i}{\sum_j x_j r_j} \\ \theta_i =\frac{x_i q_i}{\sum_j x_j q_j} \end{aligned}\]

where \(x_i\) are the mole fractions, \(q_i\) (a relative surface) and \(r_i\) (a relative volume) denote the pure-component parameters, and \(\tau_{ij}\) are the interaction parameters.

In this particular implementation, the interaction parameters are allowed to depend on temperature according to the following empirical relationship (as done in Aspen Plus):

\[ \tau_{ij} = \exp( a_{ij} + b_{ij}/T + c_{ij} \ln{T} + d_{ij} T ) \]

Moreover, \(\tau_{ij} \neq \tau_{ji}\) and \(\tau_{ii}=1\).

References

  • Abrams, D.S. and Prausnitz, J.M. (1975), Statistical thermodynamics of liquid mixtures: A new expression for the excess Gibbs energy of partly or completely miscible systems. AIChE J., 21: 116-128.
PARAMETER DESCRIPTION
N

Number of components.

TYPE: int

q

Relative surface areas of all components.

TYPE: FloatVectorLike(N)

r

Relative volumes of all components.

TYPE: FloatVectorLike(N)

a

Matrix of interaction parameters, by default 0.

TYPE: FloatSquareMatrix(N, N) | None DEFAULT: None

b

Matrix of interaction parameters [K], by default 0.

TYPE: FloatSquareMatrix(N, N) | None DEFAULT: None

c

Matrix of interaction parameters, by default 0.

TYPE: FloatSquareMatrix(N, N) | None DEFAULT: None

d

Matrix of interaction parameters [1/K], by default 0.

TYPE: FloatSquareMatrix(N, N) | None DEFAULT: None

name

Name of the model instance.

TYPE: str DEFAULT: ''

See Also
Source code in src/polykin/thermo/acm/uniquac.py
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
class UNIQUAC(MolecularACM):
    r"""[UNIQUAC](https://en.wikipedia.org/wiki/UNIQUAC) multicomponent
    activity coefficient model.

    This model is based on the following molar excess Gibbs energy
    expression:

    \begin{aligned}
    g^E &= g^R + g^C \\
    \frac{g^R}{R T} &= -\sum_i q_i x_i \ln{\left ( \sum_j \theta_j \tau_{ji} \right )} \\
    \frac{g^C}{R T} &= \sum_i x_i \ln{\frac{\Phi_i}{x_i}} + 5\sum_i q_ix_i \ln{\frac{\theta_i}{\Phi_i}}
    \end{aligned}

    with:

    \begin{aligned}
    \Phi_i =\frac{x_i r_i}{\sum_j x_j r_j} \\
    \theta_i =\frac{x_i q_i}{\sum_j x_j q_j}
    \end{aligned}

    where $x_i$ are the mole fractions, $q_i$ (a relative surface) and $r_i$
    (a relative volume) denote the pure-component parameters, and $\tau_{ij}$
    are the interaction parameters.

    In this particular implementation, the interaction parameters are allowed
    to depend on temperature according to the following empirical relationship
    (as done in Aspen Plus):

    $$ \tau_{ij} = \exp( a_{ij} + b_{ij}/T + c_{ij} \ln{T} + d_{ij} T ) $$

    Moreover, $\tau_{ij} \neq \tau_{ji}$ and $\tau_{ii}=1$.

    **References**

    *   Abrams, D.S. and Prausnitz, J.M. (1975), Statistical thermodynamics of
        liquid mixtures: A new expression for the excess Gibbs energy of partly
        or completely miscible systems. AIChE J., 21: 116-128.

    Parameters
    ----------
    N : int
        Number of components.
    q : FloatVectorLike (N)
        Relative surface areas of all components.
    r : FloatVectorLike (N)
        Relative volumes of all components.
    a : FloatSquareMatrix (N,N) | None
        Matrix of interaction parameters, by default 0.
    b : FloatSquareMatrix (N,N) | None
        Matrix of interaction parameters [K], by default 0.
    c : FloatSquareMatrix (N,N) | None
        Matrix of interaction parameters, by default 0.
    d : FloatSquareMatrix (N,N) | None
        Matrix of interaction parameters [1/K], by default 0.
    name : str
        Name of the model instance.

    See Also
    --------
    * [`UNIQUAC_gamma`](UNIQUAC_gamma.md): Related activity coefficient method.
    """

    _q: FloatVector
    _r: FloatVector
    _a: FloatSquareMatrix
    _b: FloatSquareMatrix
    _c: FloatSquareMatrix
    _d: FloatSquareMatrix

    def __init__(
        self,
        N: int,
        q: FloatVectorLike,
        r: FloatVectorLike,
        a: FloatSquareMatrix | None = None,
        b: FloatSquareMatrix | None = None,
        c: FloatSquareMatrix | None = None,
        d: FloatSquareMatrix | None = None,
        name: str = "",
    ) -> None:

        # Set default values
        if a is None:
            a = np.zeros((N, N))
        if b is None:
            b = np.zeros((N, N))
        if c is None:
            c = np.zeros((N, N))
        if d is None:
            d = np.zeros((N, N))

        # Check shapes
        q = np.asarray(q, dtype=float)
        r = np.asarray(r, dtype=float)
        check_shape(q, (N,), "q")
        check_shape(r, (N,), "r")
        check_shape(a, (N, N), "a")
        check_shape(b, (N, N), "b")
        check_shape(c, (N, N), "c")
        check_shape(d, (N, N), "d")

        # Check bounds (same as Aspen Plus)
        check_bounds(a, -50.0, 50.0, "a")
        check_bounds(b, -1.5e4, 1.5e4, "b")

        # Ensure tau_ii=1
        for array in [a, b, c, d]:
            np.fill_diagonal(array, 0.0)

        super().__init__(N, name)
        self._q = q
        self._r = r
        self._a = a
        self._b = b
        self._c = c
        self._d = d

    @functools.cache
    def tau(self, T: float) -> FloatSquareMatrix:
        r"""Calculate the matrix of interaction parameters.

        $$ \tau_{ij} = \exp( a_{ij} + b_{ij}/T + c_{ij} \ln{T} + d_{ij} T ) $$

        Parameters
        ----------
        T : float
            Temperature [K].

        Returns
        -------
        FloatSquareMatrix (N,N)
            Interaction parameters.
        """
        return exp(self._a + self._b / T + self._c * ln(T) + self._d * T)

    def gE(self, T: float, x: FloatVector) -> float:

        r = self._r
        q = self._q
        tau = self.tau(T)

        phi = x * r
        phi /= phi.sum()
        theta = x * q
        theta /= theta.sum()

        p = x > 0.0
        gC = np.sum(x[p] * (ln(phi[p] / x[p]) + 5 * q[p] * ln(theta[p] / phi[p])))
        gR = -np.sum(q[p] * x[p] * ln(dot(theta, tau)[p]))

        return R * T * (gC + gR)

    @override
    def gamma(self, T: float, x: FloatVector) -> FloatVector:
        return UNIQUAC_gamma(x, self._q, self._r, self.tau(T))

Dgmix ¤

Dgmix(T: float, x: FloatVector) -> float

Calculate the molar Gibbs energy of mixing.

\[ \Delta_{mix} g = g^E + R T \sum_i {x_i \ln{x_i}} \]
PARAMETER DESCRIPTION
T

Temperature [K].

TYPE: float

x

Mole fractions of all components [mol/mol].

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar Gibbs energy of mixing [J/mol].

Source code in src/polykin/thermo/acm/base.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def Dgmix(self, T: float, x: FloatVector) -> float:
    r"""Calculate the molar Gibbs energy of mixing.

    $$ \Delta_{mix} g = g^E + R T \sum_i {x_i \ln{x_i}} $$

    Parameters
    ----------
    T : float
        Temperature [K].
    x : FloatVector (N)
        Mole fractions of all components [mol/mol].

    Returns
    -------
    float
        Molar Gibbs energy of mixing [J/mol].
    """
    return self.gE(T, x) - T * self._Dsmix_ideal(T, x)

Dhmix ¤

Dhmix(T: float, x: FloatVector) -> float

Calculate the molar enthalpy of mixing.

\[ \Delta_{mix} h = h^{E} \]
PARAMETER DESCRIPTION
T

Temperature [K].

TYPE: float

x

Mole fractions of all components [mol/mol].

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar enthalpy of mixing [J/mol].

Source code in src/polykin/thermo/acm/base.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
def Dhmix(self, T: float, x: FloatVector) -> float:
    r"""Calculate the molar enthalpy of mixing.

    $$ \Delta_{mix} h = h^{E} $$

    Parameters
    ----------
    T : float
        Temperature [K].
    x : FloatVector (N)
        Mole fractions of all components [mol/mol].

    Returns
    -------
    float
        Molar enthalpy of mixing [J/mol].
    """
    return self.hE(T, x)

Dsmix ¤

Dsmix(T: float, x: FloatVector) -> float

Calculate the molar entropy of mixing.

\[ \Delta_{mix} s = s^{E} - R \sum_i {x_i \ln{x_i}} \]
PARAMETER DESCRIPTION
T

Temperature [K].

TYPE: float

x

Mole fractions of all components [mol/mol].

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar entropy of mixing [J/(mol·K)].

Source code in src/polykin/thermo/acm/base.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def Dsmix(self, T: float, x: FloatVector) -> float:
    r"""Calculate the molar entropy of mixing.

    $$ \Delta_{mix} s = s^{E} - R \sum_i {x_i \ln{x_i}} $$

    Parameters
    ----------
    T : float
        Temperature [K].
    x : FloatVector (N)
        Mole fractions of all components [mol/mol].

    Returns
    -------
    float
        Molar entropy of mixing [J/(mol·K)].
    """
    return self.sE(T, x) + self._Dsmix_ideal(T, x)

N property ¤

N: int

Number of components.

activity ¤

activity(T: float, x: FloatVector) -> FloatVector

Calculate the activities.

\[ a_i = x_i \gamma_i \]
PARAMETER DESCRIPTION
T

Temperature [K].

TYPE: float

x

Mole fractions of all components [mol/mol].

TYPE: FloatVector(N)

RETURNS DESCRIPTION
FloatVector(N)

Activities of all components.

Source code in src/polykin/thermo/acm/base.py
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
def activity(self, T: float, x: FloatVector) -> FloatVector:
    r"""Calculate the activities.

    $$ a_i = x_i \gamma_i $$

    Parameters
    ----------
    T : float
        Temperature [K].
    x : FloatVector (N)
        Mole fractions of all components [mol/mol].

    Returns
    -------
    FloatVector (N)
        Activities of all components.
    """
    return x * self.gamma(T, x)

gE ¤

gE(T: float, x: FloatVector) -> float

Calculate the molar excess Gibbs energy.

\[ g^{E} \equiv g - g^{id} \]
PARAMETER DESCRIPTION
T

Temperature [K].

TYPE: float

x

Mole fractions of all components [mol/mol].

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar excess Gibbs energy [J/mol].

Source code in src/polykin/thermo/acm/uniquac.py
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def gE(self, T: float, x: FloatVector) -> float:

    r = self._r
    q = self._q
    tau = self.tau(T)

    phi = x * r
    phi /= phi.sum()
    theta = x * q
    theta /= theta.sum()

    p = x > 0.0
    gC = np.sum(x[p] * (ln(phi[p] / x[p]) + 5 * q[p] * ln(theta[p] / phi[p])))
    gR = -np.sum(q[p] * x[p] * ln(dot(theta, tau)[p]))

    return R * T * (gC + gR)

gamma ¤

gamma(T: float, x: FloatVector) -> FloatVector

Calculate the activity coefficients based on mole fraction.

\[ \ln \gamma_i = \frac{1}{RT} \left( \frac{\partial (n g^E)}{\partial n_i} \right)_{T,P,n_j} \]
PARAMETER DESCRIPTION
T

Temperature [K].

TYPE: float

x

Mole fractions of all components [mol/mol].

TYPE: FloatVector(N)

RETURNS DESCRIPTION
FloatVector(N)

Activity coefficients of all components.

Source code in src/polykin/thermo/acm/uniquac.py
177
178
179
@override
def gamma(self, T: float, x: FloatVector) -> FloatVector:
    return UNIQUAC_gamma(x, self._q, self._r, self.tau(T))

hE ¤

hE(T: float, x: FloatVector) -> float

Calculate the molar excess enthalpy.

\[ h^{E} = g^{E} + T s^{E} \]
PARAMETER DESCRIPTION
T

Temperature [K].

TYPE: float

x

Mole fractions of all components [mol/mol].

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar excess enthalpy [J/mol].

Source code in src/polykin/thermo/acm/base.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
def hE(self, T: float, x: FloatVector) -> float:
    r"""Calculate the molar excess enthalpy.

    $$ h^{E} = g^{E} + T s^{E} $$

    Parameters
    ----------
    T : float
        Temperature [K].
    x : FloatVector (N)
        Mole fractions of all components [mol/mol].

    Returns
    -------
    float
        Molar excess enthalpy [J/mol].
    """
    return self.gE(T, x) + T * self.sE(T, x)

sE ¤

sE(T: float, x: FloatVector) -> float

Calculate the molar excess entropy.

\[ s^{E} = -\left(\frac{\partial g^{E}}{\partial T}\right)_{P,x_i} \]
PARAMETER DESCRIPTION
T

Temperature [K].

TYPE: float

x

Mole fractions of all components [mol/mol].

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar excess entropy [J/(mol·K)].

Source code in src/polykin/thermo/acm/base.py
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
def sE(self, T: float, x: FloatVector) -> float:
    r"""Calculate the molar excess entropy.

    $$ s^{E} = -\left(\frac{\partial g^{E}}{\partial T}\right)_{P,x_i} $$

    Parameters
    ----------
    T : float
        Temperature [K].
    x : FloatVector (N)
        Mole fractions of all components [mol/mol].

    Returns
    -------
    float
        Molar excess entropy [J/(mol·K)].
    """
    return -1 * derivative_complex(lambda T_: self.gE(T_, x), T)[0]

tau cached ¤

tau(T: float) -> FloatSquareMatrix

Calculate the matrix of interaction parameters.

\[ \tau_{ij} = \exp( a_{ij} + b_{ij}/T + c_{ij} \ln{T} + d_{ij} T ) \]
PARAMETER DESCRIPTION
T

Temperature [K].

TYPE: float

RETURNS DESCRIPTION
FloatSquareMatrix(N, N)

Interaction parameters.

Source code in src/polykin/thermo/acm/uniquac.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
@functools.cache
def tau(self, T: float) -> FloatSquareMatrix:
    r"""Calculate the matrix of interaction parameters.

    $$ \tau_{ij} = \exp( a_{ij} + b_{ij}/T + c_{ij} \ln{T} + d_{ij} T ) $$

    Parameters
    ----------
    T : float
        Temperature [K].

    Returns
    -------
    FloatSquareMatrix (N,N)
        Interaction parameters.
    """
    return exp(self._a + self._b / T + self._c * ln(T) + self._d * T)