Skip to content

polykin.thermo.acm¤

NRTL ¤

NRTL multicomponent activity coefficient model.

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

\[ \frac{g^{E}}{RT} = \sum_i x_i \frac{\displaystyle\sum_j x_j \tau_{ji} G_{ji}} {\displaystyle\sum_j x_j G_{ji}} \]

where \(x_i\) are the mole fractions, \(\tau_{ij}\) are the interaction parameters, \(\alpha_{ij}\) are the non-randomness parameters, and \(G_{ij}=\exp(-\alpha_{ij} \tau_{ij})\).

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

\[\begin{aligned} \tau_{ij} &= a_{ij} + b_{ij}/T + e_{ij} \ln{T} + f_{ij} T \\ \alpha_{ij} &= c_{ij} + d_{ij}(T - 273.15) \end{aligned}\]

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

References

  • Renon, H. and Prausnitz, J.M. (1968), Local compositions in thermodynamic excess functions for liquid mixtures. AIChE J., 14: 135-144.
PARAMETER DESCRIPTION
N

Number of components.

TYPE: int

a

Matrix of interaction parameters, by default 0.

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

b

Matrix of interaction parameters, by default 0. Unit = K.

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

c

Matrix of interaction parameters, by default 0.3. Only the upper triangle must be supplied.

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

d

Matrix of interaction parameters, by default 0. Only the upper triangle must be supplied. Unit = 1/K.

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

e

Matrix of interaction parameters, by default 0.

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

f

Matrix of interaction parameters, by default 0.

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

name

Name.

TYPE: str DEFAULT: ''

See also
  • NRTL_gamma: related activity coefficient method.
Source code in src/polykin/thermo/acm/nrtl.py
 22
 23
 24
 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
180
181
182
183
184
185
186
187
188
189
190
191
192
class NRTL(SmallSpeciesActivityModel):
    r"""[NRTL](https://en.wikipedia.org/wiki/Non-random_two-liquid_model)
    multicomponent activity coefficient model.

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

    $$ \frac{g^{E}}{RT} = 
        \sum_i x_i \frac{\displaystyle\sum_j x_j \tau_{ji} G_{ji}}
        {\displaystyle\sum_j x_j G_{ji}} $$

    where $x_i$ are the mole fractions, $\tau_{ij}$ are the interaction
    parameters, $\alpha_{ij}$ are the non-randomness parameters, and
    $G_{ij}=\exp(-\alpha_{ij} \tau_{ij})$. 

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

    \begin{aligned}
    \tau_{ij} &= a_{ij} + b_{ij}/T + e_{ij} \ln{T} + f_{ij} T \\
    \alpha_{ij} &= c_{ij} + d_{ij}(T - 273.15)
    \end{aligned}

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

    **References**

    *   Renon, H. and Prausnitz, J.M. (1968), Local compositions in
        thermodynamic excess functions for liquid mixtures. AIChE J.,
        14: 135-144.

    Parameters
    ----------
    N : int
        Number of components.
    a : FloatSquareMatrix (N,N) | None
        Matrix of interaction parameters, by default 0.
    b : FloatSquareMatrix (N,N) | None
        Matrix of interaction parameters, by default 0. Unit = K.
    c : FloatSquareMatrix (N,N) | None
        Matrix of interaction parameters, by default 0.3. Only the upper
        triangle must be supplied.
    d : FloatSquareMatrix (N,N) | None
        Matrix of interaction parameters, by default 0. Only the upper triangle
        must be supplied. Unit = 1/K.
    e : FloatSquareMatrix (N,N) | None
        Matrix of interaction parameters, by default 0.
    f : FloatSquareMatrix (N,N) | None
        Matrix of interaction parameters, by default 0.
    name: str
        Name.

    See also
    --------
    * [`NRTL_gamma`](NRTL_gamma.md): related activity coefficient method.

    """

    _a: FloatSquareMatrix
    _b: FloatSquareMatrix
    _c: FloatSquareMatrix
    _d: FloatSquareMatrix
    _e: FloatSquareMatrix
    _f: FloatSquareMatrix

    def __init__(self,
                 N: int,
                 a: Optional[FloatSquareMatrix] = None,
                 b: Optional[FloatSquareMatrix] = None,
                 c: Optional[FloatSquareMatrix] = None,
                 d: Optional[FloatSquareMatrix] = None,
                 e: Optional[FloatSquareMatrix] = None,
                 f: Optional[FloatSquareMatrix] = 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.full((N, N), 0.3)
        if d is None:
            d = np.zeros((N, N))
        if e is None:
            e = np.zeros((N, N))
        if f is None:
            f = np.zeros((N, N))

        # Check shapes
        for array in [a, b, c, d, e, f]:
            if array.shape != (N, N):
                raise ShapeError(
                    f"The shape of matrix {array} is invalid: {array.shape}.")

        # Check bounds (same as Aspen Plus)
        check_bounds(a, -1e2, 1e2, 'a')
        check_bounds(b, -3e4, 3e4, 'b')
        check_bounds(c, 0., 1., 'c')
        check_bounds(d, -0.02, 0.02, 'd')

        # Ensure tau_ii=0
        for array in [a, b, e, f]:
            np.fill_diagonal(array, 0.)

        # Ensure alpha_ij=alpha_ji
        for array in [c, d]:
            np.fill_diagonal(array, 0.)
            enforce_symmetry(array)

        super().__init__(N, name)
        self._a = a
        self._b = b
        self._c = c
        self._d = d
        self._e = e
        self._f = f

    @functools.cache
    def alpha(self,
              T: float
              ) -> FloatSquareMatrix:
        r"""Compute matrix of non-randomness parameters.

        $$ \alpha_{ij} = c_{ij} + d_{ij}(T - 273.15) $$

        Parameters
        ----------
        T : float
            Temperature. Unit = K.

        Returns
        -------
        FloatSquareMatrix (N,N)
            Non-randomness parameters.
        """
        return self._c + self._d*(T - 273.15)

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

        $$ \tau_{ij} = a_{ij} + b_{ij}/T + e_{ij} \ln{T} + f_{ij} T $$

        Parameters
        ----------
        T : float
            Temperature. Unit = K.

        Returns
        -------
        FloatSquareMatrix (N,N)
            Interaction parameters.
        """
        return self._a + self._b/T + self._e*log(T) + self._f*T

    def gE(self, T: float, x: FloatVector) -> float:
        tau = self.tau(T)
        alpha = self.alpha(T)
        G = exp(-alpha*tau)
        A = dot(x, tau*G)
        B = dot(x, G)
        return R*T*dot(x, A/B)

    def gamma(self, T: float, x: FloatVector) -> FloatVector:
        return NRTL_gamma(x, self.tau(T), self.alpha(T))

Dgmix ¤

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

Molar Gibbs energy of mixing, \(\Delta g_{mix}\).

\[ \Delta g_{mix} = \Delta h_{mix} -T \Delta s_{mix} \]
PARAMETER DESCRIPTION
T

Temperature. Unit = K.

TYPE: float

x

Mole fractions of all components. Unit = mol/mol.

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar Gibbs energy of mixing. Unit = J/mol.

Source code in src/polykin/thermo/acm/base.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def Dgmix(self,
          T: float,
          x: FloatVector
          ) -> float:
    r"""Molar Gibbs energy of mixing, $\Delta g_{mix}$.

    $$ \Delta g_{mix} = \Delta h_{mix} -T \Delta s_{mix} $$

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

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

Dhmix ¤

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

Molar enthalpy of mixing, \(\Delta h_{mix}\).

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

Temperature. Unit = K.

TYPE: float

x

Mole fractions of all components. Unit = mol/mol.

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar enthalpy of mixing. Unit = J/mol.

Source code in src/polykin/thermo/acm/base.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def Dhmix(self,
          T: float,
          x: FloatVector
          ) -> float:
    r"""Molar enthalpy of mixing, $\Delta h_{mix}$.

    $$ \Delta h_{mix} = h^{E} $$

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

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

Dsmix ¤

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

Molar entropy of mixing, \(\Delta s_{mix}\).

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

Temperature. Unit = K.

TYPE: float

x

Mole fractions of all components. Unit = mol/mol.

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar entropy of mixing. Unit = J/(mol·K).

Source code in src/polykin/thermo/acm/base.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def Dsmix(self,
          T: float,
          x: FloatVector
          ) -> float:
    r"""Molar entropy of mixing, $\Delta s_{mix}$.

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

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

    Returns
    -------
    float
        Molar entropy of mixing. Unit = 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

Activities, \(a_i\).

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

Temperature. Unit = K.

TYPE: float

x

Mole fractions of all components. Unit = mol/mol.

TYPE: FloatVector(N)

RETURNS DESCRIPTION
FloatVector(N)

Activities of all components.

Source code in src/polykin/thermo/acm/base.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
def activity(self,
             T: float,
             x: FloatVector
             ) -> FloatVector:
    r"""Activities, $a_i$.

    $$ a_i = x_i \gamma_i $$

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

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

alpha cached ¤

alpha(T: float) -> FloatSquareMatrix

Compute matrix of non-randomness parameters.

\[ \alpha_{ij} = c_{ij} + d_{ij}(T - 273.15) \]
PARAMETER DESCRIPTION
T

Temperature. Unit = K.

TYPE: float

RETURNS DESCRIPTION
FloatSquareMatrix(N, N)

Non-randomness parameters.

Source code in src/polykin/thermo/acm/nrtl.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
@functools.cache
def alpha(self,
          T: float
          ) -> FloatSquareMatrix:
    r"""Compute matrix of non-randomness parameters.

    $$ \alpha_{ij} = c_{ij} + d_{ij}(T - 273.15) $$

    Parameters
    ----------
    T : float
        Temperature. Unit = K.

    Returns
    -------
    FloatSquareMatrix (N,N)
        Non-randomness parameters.
    """
    return self._c + self._d*(T - 273.15)

gE ¤

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

Molar excess Gibbs energy, \(g^{E}\).

PARAMETER DESCRIPTION
T

Temperature. Unit = K.

TYPE: float

x

Mole fractions of all components. Unit = mol/mol.

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar excess Gibbs energy. Unit = J/mol.

Source code in src/polykin/thermo/acm/nrtl.py
183
184
185
186
187
188
189
def gE(self, T: float, x: FloatVector) -> float:
    tau = self.tau(T)
    alpha = self.alpha(T)
    G = exp(-alpha*tau)
    A = dot(x, tau*G)
    B = dot(x, G)
    return R*T*dot(x, A/B)

gamma ¤

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

Activity coefficients based on mole fraction, \(\gamma_i\).

PARAMETER DESCRIPTION
T

Temperature. Unit = K.

TYPE: float

x

Mole fractions of all components. Unit = mol/mol.

TYPE: FloatVector(N)

RETURNS DESCRIPTION
FloatVector(N)

Activity coefficients of all components.

Source code in src/polykin/thermo/acm/nrtl.py
191
192
def gamma(self, T: float, x: FloatVector) -> FloatVector:
    return NRTL_gamma(x, self.tau(T), self.alpha(T))

hE ¤

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

Molar excess enthalpy, \(h^{E}\).

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

Temperature. Unit = K.

TYPE: float

x

Mole fractions of all components. Unit = mol/mol.

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar excess enthalpy. Unit = J/mol.

Source code in src/polykin/thermo/acm/base.py
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
def hE(self,
       T: float,
       x: FloatVector
       ) -> float:
    r"""Molar excess enthalpy, $h^{E}$.

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

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

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

sE ¤

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

Molar excess entropy, \(s^{E}\).

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

Temperature. Unit = K.

TYPE: float

x

Mole fractions of all components. Unit = mol/mol.

TYPE: FloatVector(N)

RETURNS DESCRIPTION
float

Molar excess entropy. Unit = J/(mol·K).

Source code in src/polykin/thermo/acm/base.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
def sE(self,
       T: float,
       x: FloatVector
       ) -> float:
    r"""Molar excess entropy, $s^{E}$.

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

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

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

tau cached ¤

tau(T: float) -> FloatSquareMatrix

Compute the matrix of interaction parameters.

\[ \tau_{ij} = a_{ij} + b_{ij}/T + e_{ij} \ln{T} + f_{ij} T \]
PARAMETER DESCRIPTION
T

Temperature. Unit = K.

TYPE: float

RETURNS DESCRIPTION
FloatSquareMatrix(N, N)

Interaction parameters.

Source code in src/polykin/thermo/acm/nrtl.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
@functools.cache
def tau(self,
        T: float
        ) -> FloatSquareMatrix:
    r"""Compute the matrix of interaction parameters.

    $$ \tau_{ij} = a_{ij} + b_{ij}/T + e_{ij} \ln{T} + f_{ij} T $$

    Parameters
    ----------
    T : float
        Temperature. Unit = K.

    Returns
    -------
    FloatSquareMatrix (N,N)
        Interaction parameters.
    """
    return self._a + self._b/T + self._e*log(T) + self._f*T