ISOTHERMAL_WORK

Overview

Calculate work of compression or expansion for a gas in an isothermal process.

Excel Usage

=ISOTHERMAL_WORK(p_inlet, p_outlet, temp, comp_factor)
  • p_inlet (float, required): Inlet pressure [Pa]
  • p_outlet (float, required): Outlet pressure [Pa]
  • temp (float, required): Temperature of the gas [K]
  • comp_factor (float, optional, default: 1): Compressibility factor of the gas, [-]

Returns (float): Work performed per mole of gas compressed/expanded [J/mol]

Examples

Example 1: Compression with 10x pressure ratio

Inputs:

p_inlet p_outlet temp
100000 1000000 300

Excel formula:

=ISOTHERMAL_WORK(100000, 1000000, 300)

Expected output:

5743.427304244769

Example 2: Expansion (negative work)

Inputs:

p_inlet p_outlet temp
1000000 100000 300

Excel formula:

=ISOTHERMAL_WORK(1000000, 100000, 300)

Expected output:

-5743.427304244768

Example 3: Compression with compressibility factor

Inputs:

p_inlet p_outlet temp comp_factor
100000 1000000 300 0.95

Excel formula:

=ISOTHERMAL_WORK(100000, 1000000, 300, 0.95)

Expected output:

5456.25593903253

Example 4: Small pressure ratio compression

Inputs:

p_inlet p_outlet temp
100000 150000 350

Excel formula:

=ISOTHERMAL_WORK(100000, 150000, 350)

Expected output:

1179.9285695157782

Python Code

import micropip
await micropip.install(["fluids"])
from fluids.compressible import isothermal_work_compression as fluids_isothermal_work

def isothermal_work(p_inlet, p_outlet, temp, comp_factor=1):
    """
    Calculate work of compression or expansion for a gas in an isothermal process.

    See: https://fluids.readthedocs.io/fluids.compressible.html#fluids.compressible.isothermal_work_compression

    This example function is provided as-is without any representation of accuracy.

    Args:
        p_inlet (float): Inlet pressure [Pa]
        p_outlet (float): Outlet pressure [Pa]
        temp (float): Temperature of the gas [K]
        comp_factor (float, optional): Compressibility factor of the gas, [-] Default is 1.

    Returns:
        float: Work performed per mole of gas compressed/expanded [J/mol]
    """
    # Validate and convert inputs
    try:
        p_inlet = float(p_inlet)
    except (ValueError, TypeError):
        return "Invalid input: p_inlet must be a number."

    try:
        p_outlet = float(p_outlet)
    except (ValueError, TypeError):
        return "Invalid input: p_outlet must be a number."

    try:
        temp = float(temp)
    except (ValueError, TypeError):
        return "Invalid input: temp must be a number."

    try:
        comp_factor = float(comp_factor)
    except (ValueError, TypeError):
        return "Invalid input: comp_factor must be a number."

    # Validation: pressures must be positive
    if p_inlet <= 0:
        return "Invalid input: p_inlet must be positive."
    if p_outlet <= 0:
        return "Invalid input: p_outlet must be positive."
    if temp <= 0:
        return "Invalid input: temp must be positive."
    if comp_factor <= 0:
        return "Invalid input: comp_factor must be positive."

    try:
        result = fluids_isothermal_work(P1=p_inlet, P2=p_outlet, T=temp, Z=comp_factor)
        return float(result)
    except Exception as e:
        return f"Error: Failed to compute isothermal work: {str(e)}"

Online Calculator