Equations of state¶
Cubic equations of state (van der Waals, Redlich-Kwong, Soave-Redlich-Kwong,
and Peng-Robinson) with their fugacity-coefficient and molar-volume routines.
Each CubicEOS is a static descriptor, so switching models is a one-object
swap that keeps a flowsheet differentiable.
eos
¶
Differentiable cubic equations of state (van der Waals, RK, SRK, Peng-Robinson).
All four classic cubics share one pressure-explicit form::
P = R*T / (V - b) - a(T) / (V**2 + u*b*V + w*b**2)
and differ only in the constants (Omega_a, Omega_b, u, w) and the
temperature dependence of the attractive term a(T) = a_c * alpha(T_r). This
module implements that single generalized cubic and exposes the four families as
ready-made PR, SRK, RK, VDW specifications.
In dimensionless form the molar compressibility Z = P V / (R T) is the root
of::
Z**3 - (1 + B - u*B) Z**2 + (A + w*B**2 - u*B - u*B**2) Z
- (A*B + w*B**2 + w*B**3) = 0
with A = a P / (R T)**2 and B = b P / (R T).
Differentiability. Selecting the physically correct root (smallest for a
liquid, largest for a vapour) is inherently non-smooth, so rather than
differentiate through the closed-form cubic solution we compute Z by the
analytic trigonometric/Cardano method and attach exact derivatives through the
implicit function theorem applied to the cubic residual (a jax.custom_jvp
rule). The result is clean, cheap gradients of Z (and therefore of every
downstream property and fugacity coefficient) with respect to T, P,
composition, and the EOS parameters themselves.
Classes:
| Name | Description |
|---|---|
CubicEOS |
Specification of a two-parameter cubic equation of state. |
Functions:
| Name | Description |
|---|---|
alpha |
Temperature-dependent |
a_pure |
Attractive parameter |
b_pure |
Repulsive (co-volume) parameter |
compress_factor |
Compressibility factor |
compressibility |
Mixture compressibility factor |
ln_phi_mixture |
Log fugacity coefficients |
ln_phi_pure |
Log fugacity coefficient and |
molar_volume |
Mixture molar volume |
pressure |
Pressure from the explicit cubic EOS at given |
CubicEOS
dataclass
¶
Specification of a two-parameter cubic equation of state.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable name. |
omega_a |
float
|
Attraction constant |
omega_b |
float
|
Repulsion constant |
u |
float
|
Linear coefficient of the cubic denominator |
w |
float
|
Constant coefficient of the cubic denominator. |
alpha_kind |
str
|
Which |
alpha
¶
alpha(
eos: CubicEOS,
t: ArrayLike,
tc: ArrayLike,
omega: ArrayLike,
) -> Array
Temperature-dependent alpha(T_r) factor of the attractive term.
a_pure
¶
a_pure(
eos: CubicEOS,
t: ArrayLike,
tc: ArrayLike,
pc: ArrayLike,
omega: ArrayLike,
) -> Array
Attractive parameter a(T) for one or more pure components (J m^3 / mol^2).
b_pure
¶
b_pure(
eos: CubicEOS, tc: ArrayLike, pc: ArrayLike
) -> Array
Repulsive (co-volume) parameter b for one or more pure components (m^3/mol).
compress_factor
¶
Compressibility factor Z from the dimensionless A, B (implicitly diff'd).
compressibility
¶
compressibility(
eos: CubicEOS,
t: ArrayLike,
p: ArrayLike,
x: Array,
tc: Array,
pc: Array,
omega: Array,
*,
phase: str = "vapor",
kij: Array | None = None,
) -> Array
Mixture compressibility factor Z for the requested phase.
ln_phi_mixture
¶
ln_phi_mixture(
eos: CubicEOS,
t: ArrayLike,
p: ArrayLike,
x: Array,
tc: Array,
pc: Array,
omega: Array,
*,
phase: str = "vapor",
kij: Array | None = None,
) -> tuple[Array, Array]
Log fugacity coefficients ln(phi_i) of every component, and Z.
Uses the van der Waals one-fluid mixing rule with binary interaction
parameters kij (defaults to all zeros).
Returns:
| Type | Description |
|---|---|
tuple[Array, Array]
|
|
ln_phi_pure
¶
ln_phi_pure(
eos: CubicEOS,
t: ArrayLike,
p: ArrayLike,
tc: ArrayLike,
pc: ArrayLike,
omega: ArrayLike,
*,
phase: str = "vapor",
) -> tuple[Array, Array]
Log fugacity coefficient and Z of a single pure component.