Skip to content

Commit 79fff9d

Browse files
committed
move B_mixture and B_pure to properties.pvt
1 parent b9ae1d1 commit 79fff9d

9 files changed

Lines changed: 142 additions & 126 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# polykin.properties.pvt
2+
3+
::: polykin.properties.pvt.virial
4+
options:
5+
members:
6+
- B_mixture
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# polykin.properties.pvt
2+
3+
::: polykin.properties.pvt.virial
4+
options:
5+
members:
6+
- B_pure

docs/reference/properties/pvt/_SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
* [](index.md)
2+
* [B_mixture](B_mixture.md)
3+
* [B_pure](B_pure.md)
24
* [geometric_interaction_mixing](geometric_interaction_mixing.md)
35
* [pseudocritical_properties](pseudocritical_properties.md)
46
* [quadratic_mixing](quadratic_mixing.md)

docs/reference/thermo/eos/B_mixture.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/reference/thermo/eos/B_pure.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/reference/thermo/eos/_SUMMARY.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@
55
* [RedlichKwong](RedlichKwong.md)
66
* [SoaveRedlichKwong](SoaveRedlichKwong.md)
77
* [Virial](Virial.md)
8-
* [B_mixture](B_mixture.md)
9-
* [B_pure](B_pure.md)
108
* [Z_cubic_roots](Z_cubic_roots.md)

src/polykin/properties/pvt/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
from .mixing_rules import *
1010
from .tait import *
11+
from .virial import *
1112
from .volume import *
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# PolyKin: A polymerization kinetics library for Python.
2+
#
3+
# Copyright Hugo Vale 2025
4+
5+
6+
import numpy as np
7+
from numpy import sqrt
8+
from scipy.constants import R
9+
10+
from polykin.utils.types import (
11+
FloatArray,
12+
FloatSquareMatrix,
13+
FloatVector,
14+
)
15+
16+
__all__ = ["B_pure", "B_mixture"]
17+
18+
19+
def B_pure(
20+
T: float | FloatArray,
21+
Tc: float,
22+
Pc: float,
23+
w: float,
24+
) -> float | FloatArray:
25+
r"""Estimate the second virial coefficient of a nonpolar or slightly polar
26+
gas.
27+
28+
$$ \frac{B P_c}{R T_c} = B^{(0)}(T_r) + \omega B^{(1)}(T_r) $$
29+
30+
where $B$ is the second virial coefficient, $P_c$ is the critical pressure,
31+
$T_c$ is the critical temperature, $T_r=T/T_c$ is the reduced temperature,
32+
and $\omega$ is the acentric factor.
33+
34+
**References**
35+
36+
* RC Reid, JM Prausniz, and BE Poling. The properties of gases & liquids
37+
4th edition, 1986, p. 40.
38+
39+
Parameters
40+
----------
41+
T : float | FloatArray
42+
Temperature [K].
43+
Tc : float
44+
Critical temperature [K].
45+
Pc : float
46+
Critical pressure [Pa].
47+
w : float
48+
Acentric factor.
49+
50+
Returns
51+
-------
52+
float | FloatArray
53+
Second virial coefficient, $B$ [m³/mol].
54+
"""
55+
Tr = T / Tc
56+
B0 = 0.083 - 0.422 / Tr**1.6
57+
B1 = 0.139 - 0.172 / Tr**4.2
58+
return R * Tc / Pc * (B0 + w * B1)
59+
60+
61+
def B_mixture(
62+
T: float,
63+
Tc: FloatVector,
64+
Pc: FloatVector,
65+
Zc: FloatVector,
66+
w: FloatVector,
67+
) -> FloatSquareMatrix:
68+
r"""Calculate the matrix of interaction virial coefficients using the
69+
mixing rules of Prausnitz.
70+
71+
\begin{aligned}
72+
B_{ij} &= B(T,T_{cij},P_{cij},\omega_{ij}) \\
73+
v_{cij} &= \frac{(v_{ci}^{1/3}+v_{cj}^{1/3})^3}{8} \\
74+
k_{ij} &= 1 -\frac{\sqrt{v_{ci}v_{cj}}}{v_{cij}} \\
75+
T_{cij} &= \sqrt{T_{ci}T_{cj}}(1-k_{ij}) \\
76+
Z_{cij} &= \frac{Z_{ci}+Z_{cj}}{2} \\
77+
\omega_{ij} &= \frac{\omega_{i}+\omega_{j}}{2} \\
78+
P_{cij} &= \frac{Z_{cij} R T_{cij}}{v_{cij}}
79+
\end{aligned}
80+
81+
The calculation of the individual coefficients is handled by
82+
[`B_pure`](B_pure.md).
83+
84+
**References**
85+
86+
* RC Reid, JM Prausniz, and BE Poling. The properties of gases & liquids
87+
4th edition, 1986, p. 80.
88+
89+
Parameters
90+
----------
91+
T : float
92+
Temperature [K].
93+
Tc : FloatVector (N)
94+
Critical temperatures of all components [K].
95+
Pc : FloatVector (N)
96+
Critical pressures of all components [Pa].
97+
Zc : FloatVector (N)
98+
Critical compressibility factors of all components.
99+
w : FloatVector (N)
100+
Acentric factors of all components.
101+
102+
Returns
103+
-------
104+
FloatSquareMatrix (N,N)
105+
Matrix of interaction virial coefficients $B_{ij}$ [m³/mol].
106+
"""
107+
vc = Zc * R * Tc / Pc
108+
N = Tc.size
109+
B = np.empty((N, N), dtype=np.float64)
110+
for i in range(N):
111+
for j in range(i, N):
112+
if i == j:
113+
B[i, j] = B_pure(T, Tc[i], Pc[i], w[i])
114+
else:
115+
vcm = (vc[i] ** (1 / 3) + vc[j] ** (1 / 3)) ** 3 / 8
116+
km = 1 - sqrt(vc[i] * vc[j]) / vcm
117+
Tcm = sqrt(Tc[i] * Tc[j]) * (1 - km)
118+
Zcm = (Zc[i] + Zc[j]) / 2
119+
wm = (w[i] + w[j]) / 2
120+
Pcm = Zcm * R * Tcm / vcm
121+
B[i, j] = B_pure(T, Tcm, Pcm, wm)
122+
B[j, i] = B[i, j]
123+
return B

src/polykin/thermo/eos/virial.py

Lines changed: 4 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44

55
import functools
66

7-
import numpy as np
8-
from numpy import dot, exp, log, sqrt
7+
from numpy import dot, exp, log
98
from scipy.constants import R
109

1110
from polykin.properties.pvt.mixing_rules import quadratic_mixing
11+
from polykin.properties.pvt.virial import B_mixture
1212
from polykin.utils.math import convert_FloatOrVectorLike_to_FloatVector
1313
from polykin.utils.types import (
14-
FloatArray,
1514
FloatSquareMatrix,
1615
FloatVector,
1716
FloatVectorLike,
1817
)
1918

2019
from .base import GasEoS
2120

22-
__all__ = ["Virial", "B_pure", "B_mixture"]
21+
__all__ = ["Virial"]
2322

2423

2524
class Virial(GasEoS):
@@ -116,7 +115,7 @@ def Bij(
116115
) -> FloatSquareMatrix:
117116
r"""Calculate the matrix of interaction virial coefficients.
118117
119-
The calculation is handled by [`B_mixture`](B_mixture.md).
118+
The calculation is handled by [`B_mixture`](../../properties/pvt/B_mixture.md).
120119
121120
Parameters
122121
----------
@@ -242,110 +241,3 @@ def DA(
242241
y = n / nT
243242
Bm = self.Bm(T, y)
244243
return -nT * R * T * log((V - nT * Bm) / (nT * v0))
245-
246-
247-
def B_pure(
248-
T: float | FloatArray,
249-
Tc: float,
250-
Pc: float,
251-
w: float,
252-
) -> float | FloatArray:
253-
r"""Estimate the second virial coefficient of a nonpolar or slightly polar
254-
gas.
255-
256-
$$ \frac{B P_c}{R T_c} = B^{(0)}(T_r) + \omega B^{(1)}(T_r) $$
257-
258-
where $B$ is the second virial coefficient, $P_c$ is the critical pressure,
259-
$T_c$ is the critical temperature, $T_r=T/T_c$ is the reduced temperature,
260-
and $\omega$ is the acentric factor.
261-
262-
**References**
263-
264-
* RC Reid, JM Prausniz, and BE Poling. The properties of gases & liquids
265-
4th edition, 1986, p. 40.
266-
267-
Parameters
268-
----------
269-
T : float | FloatArray
270-
Temperature [K].
271-
Tc : float
272-
Critical temperature [K].
273-
Pc : float
274-
Critical pressure [Pa].
275-
w : float
276-
Acentric factor.
277-
278-
Returns
279-
-------
280-
float | FloatArray
281-
Second virial coefficient, $B$ [m³/mol].
282-
"""
283-
Tr = T / Tc
284-
B0 = 0.083 - 0.422 / Tr**1.6
285-
B1 = 0.139 - 0.172 / Tr**4.2
286-
return R * Tc / Pc * (B0 + w * B1)
287-
288-
289-
def B_mixture(
290-
T: float,
291-
Tc: FloatVector,
292-
Pc: FloatVector,
293-
Zc: FloatVector,
294-
w: FloatVector,
295-
) -> FloatSquareMatrix:
296-
r"""Calculate the matrix of interaction virial coefficients using the
297-
mixing rules of Prausnitz.
298-
299-
\begin{aligned}
300-
B_{ij} &= B(T,T_{cij},P_{cij},\omega_{ij}) \\
301-
v_{cij} &= \frac{(v_{ci}^{1/3}+v_{cj}^{1/3})^3}{8} \\
302-
k_{ij} &= 1 -\frac{\sqrt{v_{ci}v_{cj}}}{v_{cij}} \\
303-
T_{cij} &= \sqrt{T_{ci}T_{cj}}(1-k_{ij}) \\
304-
Z_{cij} &= \frac{Z_{ci}+Z_{cj}}{2} \\
305-
\omega_{ij} &= \frac{\omega_{i}+\omega_{j}}{2} \\
306-
P_{cij} &= \frac{Z_{cij} R T_{cij}}{v_{cij}}
307-
\end{aligned}
308-
309-
The calculation of the individual coefficients is handled by
310-
[`B_pure`](B_pure.md).
311-
312-
**References**
313-
314-
* RC Reid, JM Prausniz, and BE Poling. The properties of gases & liquids
315-
4th edition, 1986, p. 80.
316-
317-
Parameters
318-
----------
319-
T : float
320-
Temperature [K].
321-
Tc : FloatVector (N)
322-
Critical temperatures of all components [K].
323-
Pc : FloatVector (N)
324-
Critical pressures of all components [Pa].
325-
Zc : FloatVector (N)
326-
Critical compressibility factors of all components.
327-
w : FloatVector (N)
328-
Acentric factors of all components.
329-
330-
Returns
331-
-------
332-
FloatSquareMatrix (N,N)
333-
Matrix of interaction virial coefficients $B_{ij}$ [m³/mol].
334-
"""
335-
vc = Zc * R * Tc / Pc
336-
N = Tc.size
337-
B = np.empty((N, N), dtype=np.float64)
338-
for i in range(N):
339-
for j in range(i, N):
340-
if i == j:
341-
B[i, j] = B_pure(T, Tc[i], Pc[i], w[i])
342-
else:
343-
vcm = (vc[i] ** (1 / 3) + vc[j] ** (1 / 3)) ** 3 / 8
344-
km = 1 - sqrt(vc[i] * vc[j]) / vcm
345-
Tcm = sqrt(Tc[i] * Tc[j]) * (1 - km)
346-
Zcm = (Zc[i] + Zc[j]) / 2
347-
wm = (w[i] + w[j]) / 2
348-
Pcm = Zcm * R * Tcm / vcm
349-
B[i, j] = B_pure(T, Tcm, Pcm, wm)
350-
B[j, i] = B[i, j]
351-
return B

0 commit comments

Comments
 (0)