Skip to content

kups.mcmc.fugacity

Fugacity calculations for real gas mixtures.

This module provides fugacity coefficient calculations for non-ideal gases and mixtures. Fugacity is a measure of chemical potential that accounts for deviations from ideal gas behavior, essential for accurate phase equilibria and grand canonical Monte Carlo simulations.

Currently implements the Peng-Robinson cubic equation of state, which provides good accuracy for hydrocarbons and many other fluids. The framework supports extension to other equations of state (e.g., Soave-Redlich-Kwong, virial equations).

LogFugacityResult

Bases: NamedTuple

Result of fugacity calculation.

Attributes:

Name Type Description
log_fugacity Array

Natural logarithm of fugacity for each component [ln(Pa)]

compressibility Array

Compressibility factor Z = PV/(nRT) [-]

Source code in src/kups/mcmc/fugacity.py
class LogFugacityResult(NamedTuple):
    """Result of fugacity calculation.

    Attributes:
        log_fugacity: Natural logarithm of fugacity for each component [ln(Pa)]
        compressibility: Compressibility factor Z = PV/(nRT) [-]
    """

    log_fugacity: Array
    compressibility: Array

peng_robinson_log_fugacity(pressure, temperature, critical_pressure, critical_temperature, acentric_factor, composition=jnp.ones((1,)), interaction=jnp.zeros((1, 1)))

Compute log fugacity coefficients using Peng-Robinson equation of state.

Public API for Peng-Robinson fugacity calculations with automatic vectorization over batched inputs. This function wraps the internal implementation with convenient defaults for single-component systems.

The Peng-Robinson equation of state is:

\[ P = \frac{RT}{V-b} - \frac{a\alpha(T)}{V^2 + 2bV - b^2} \]

where \(a\) and \(b\) are component-specific parameters, and \(\alpha(T)\) is a temperature- dependent correction factor based on the acentric factor.

Parameters:

Name Type Description Default
pressure Array

System pressure [Pa]

required
temperature Array

System temperature [K]

required
critical_pressure Array

Critical pressure for each component [Pa], shape (n,)

required
critical_temperature Array

Critical temperature for each component [K], shape (n,)

required
acentric_factor Array

Acentric factor for each component [-], shape (n,)

required
composition Array

Mole fraction of each component [-], shape (n,). Default: pure component

ones((1,))
interaction Array

Binary interaction parameters [-], shape (n, n). Default: ideal mixing

zeros((1, 1))

Returns:

Type Description
LogFugacityResult

LogFugacityResult containing log fugacity and compressibility factor

Example
import jax.numpy as jnp
from kups.mcmc.fugacity import peng_robinson_log_fugacity

# CO2 properties
P = 1e6  # 10 bar in Pa
T = 300.0  # K
Pc = jnp.array([7.38e6])  # Critical pressure
Tc = jnp.array([304.2])   # Critical temperature
omega = jnp.array([0.228])  # Acentric factor

result = peng_robinson_log_fugacity(P, T, Pc, Tc, omega)
fugacity = jnp.exp(result.log_fugacity)  # Convert from log
Z = result.compressibility
Source code in src/kups/mcmc/fugacity.py
def peng_robinson_log_fugacity(
    pressure: Array,
    temperature: Array,
    critical_pressure: Array,
    critical_temperature: Array,
    acentric_factor: Array,
    composition: Array = jnp.ones((1,)),
    interaction: Array = jnp.zeros((1, 1)),
) -> LogFugacityResult:
    """Compute log fugacity coefficients using Peng-Robinson equation of state.

    Public API for Peng-Robinson fugacity calculations with automatic vectorization
    over batched inputs. This function wraps the internal implementation with
    convenient defaults for single-component systems.

    The Peng-Robinson equation of state is:

    $$
    P = \\frac{RT}{V-b} - \\frac{a\\alpha(T)}{V^2 + 2bV - b^2}
    $$

    where $a$ and $b$ are component-specific parameters, and $\\alpha(T)$ is a temperature-
    dependent correction factor based on the acentric factor.

    Args:
        pressure: System pressure [Pa]
        temperature: System temperature [K]
        critical_pressure: Critical pressure for each component [Pa], shape `(n,)`
        critical_temperature: Critical temperature for each component [K], shape `(n,)`
        acentric_factor: Acentric factor for each component [-], shape `(n,)`
        composition: Mole fraction of each component [-], shape `(n,)`. Default: pure component
        interaction: Binary interaction parameters [-], shape `(n, n)`. Default: ideal mixing

    Returns:
        LogFugacityResult containing log fugacity and compressibility factor

    Example:
        ```python
        import jax.numpy as jnp
        from kups.mcmc.fugacity import peng_robinson_log_fugacity

        # CO2 properties
        P = 1e6  # 10 bar in Pa
        T = 300.0  # K
        Pc = jnp.array([7.38e6])  # Critical pressure
        Tc = jnp.array([304.2])   # Critical temperature
        omega = jnp.array([0.228])  # Acentric factor

        result = peng_robinson_log_fugacity(P, T, Pc, Tc, omega)
        fugacity = jnp.exp(result.log_fugacity)  # Convert from log
        Z = result.compressibility
        ```
    """
    return LogFugacityResult(
        *_peng_robinson_log_fugacity(
            pressure,
            temperature,
            critical_pressure,
            critical_temperature,
            acentric_factor,
            composition,
            interaction,
        )
    )