Skip to content

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 alpha(T_r) factor of the attractive term.

a_pure

Attractive parameter a(T) for one or more pure components (J m^3 / mol^2).

b_pure

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

Mixture compressibility factor Z for the requested phase.

ln_phi_mixture

Log fugacity coefficients ln(phi_i) of every component, and Z.

ln_phi_pure

Log fugacity coefficient and Z of a single pure component.

molar_volume

Mixture molar volume V = Z R T / P (m^3/mol).

pressure

Pressure from the explicit cubic EOS at given T and molar volume V.

CubicEOS dataclass

CubicEOS(
    name: str,
    omega_a: float,
    omega_b: float,
    u: float,
    w: float,
    alpha_kind: str,
)

Specification of a two-parameter cubic equation of state.

Attributes:

Name Type Description
name str

Human-readable name.

omega_a float

Attraction constant Omega_a in a_c = Omega_a R**2 Tc**2 / Pc.

omega_b float

Repulsion constant Omega_b in b = Omega_b R Tc / Pc.

u float

Linear coefficient of the cubic denominator V**2 + u b V + w b**2.

w float

Constant coefficient of the cubic denominator.

alpha_kind str

Which alpha(T_r, omega) law to use ("one", "rk", "soave" or "pr").

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

compress_factor(
    big_a: Array,
    big_b: Array,
    u: float,
    w: float,
    largest: bool,
) -> Array

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, Z) where ln_phi is a 1-D array aligned with x.

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.

molar_volume

molar_volume(
    eos: CubicEOS,
    t: ArrayLike,
    p: ArrayLike,
    x: Array,
    tc: Array,
    pc: Array,
    omega: Array,
    *,
    phase: str = "vapor",
    kij: Array | None = None,
) -> Array

Mixture molar volume V = Z R T / P (m^3/mol).

pressure

pressure(
    eos: CubicEOS,
    t: ArrayLike,
    v: ArrayLike,
    x: Array,
    tc: Array,
    pc: Array,
    omega: Array,
    *,
    kij: Array | None = None,
) -> Array

Pressure from the explicit cubic EOS at given T and molar volume V.