MIXTURE_FLASH

Overview

Excel Usage

=MIXTURE_FLASH(compounds, fractions, temperature, pressure)
  • compounds (list[list], required): Range of chemical identifiers (names, CAS).
  • fractions (list[list], required): Range of mole fractions.
  • temperature (float, optional, default: 298.15): Temperature [K].
  • pressure (float, optional, default: 101325): Pressure [Pa].

Returns (list[list]): 2D array of property names and values.

Examples

Example 1: Ethanol-Water Mixture Flash

Inputs:

compounds fractions temperature pressure
Ethanol 0.5 350 101325
Water 0.5

Excel formula:

=MIXTURE_FLASH({"Ethanol";"Water"}, {0.5;0.5}, 350, 101325)

Expected output:

Property Value
Vapor Fraction 0
Phase l
Molar Volume 0
Enthalpy -37819.5869
Entropy -97.7244
Density 817.2279

Example 2: Pure Water at Standard Conditions

Inputs:

compounds fractions temperature pressure
Water 1 298.15 101325

Excel formula:

=MIXTURE_FLASH("Water", 1, 298.15, 101325)

Expected output:

Property Value
Vapor Fraction 0
Phase l
Molar Volume 0
Enthalpy -43985.6726
Entropy -118.7281
Density 997.0645

Example 3: Air (N2/O2) Mixture

Inputs:

compounds fractions temperature pressure
Nitrogen 0.79 300 101325
Oxygen 0.21

Excel formula:

=MIXTURE_FLASH({"Nitrogen";"Oxygen"}, {0.79;0.21}, 300, 101325)

Expected output:

Property Value
Vapor Fraction 1
Phase g
Molar Volume 0.0246
Enthalpy 53.9815
Entropy 4.4538
Density 1.172

Example 4: Methanol-Benzene Mixture

Inputs:

compounds fractions temperature pressure
Methanol 0.4 320 50000
Benzene 0.6

Excel formula:

=MIXTURE_FLASH({"Methanol";"Benzene"}, {0.4;0.6}, 320, 50000)

Expected output:

Property Value
Vapor Fraction 0
Phase l
Molar Volume 0.0001
Enthalpy -32604.2062
Entropy -87.9393
Density 830.6794

Python Code

from thermo import Mixture

def mixture_flash(compounds, fractions, temperature=298.15, pressure=101325):
    """
    Perform a flash calculation for a chemical mixture and return key properties.

    See: https://thermo.readthedocs.io/thermo.mixture.html

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

    Args:
        compounds (list[list]): Range of chemical identifiers (names, CAS).
        fractions (list[list]): Range of mole fractions.
        temperature (float, optional): Temperature [K]. Default is 298.15.
        pressure (float, optional): Pressure [Pa]. Default is 101325.

    Returns:
        list[list]: 2D array of property names and values.
    """
    def to_list(x):
        if isinstance(x, list):
            return [val for row in x for val in row if val is not None and val != ""]
        return [x] if x is not None else []

    try:
        ids = to_list(compounds)
        zs_raw = to_list(fractions)
        zs = [float(z) for z in zs_raw]

        if len(ids) != len(zs):
            return f"Error: Count mismatch: {len(ids)} compounds vs {len(zs)} fractions"

        total_z = sum(zs)
        if total_z == 0:
            return "Error: Sum of fractions must be greater than zero"
        zs = [z/total_z for z in zs]

        m = Mixture(ids, zs=zs, T=temperature, P=pressure)

        # Safer property extraction
        def get_prop(obj, attr):
            try:
                val = getattr(obj, attr)
                return float(val) if val is not None else 0.0
            except:
                return 0.0

        results = [
            ["Property", "Value"],
            ["Vapor Fraction", get_prop(m, 'VF')],
            ["Phase", str(m.phase)],
            ["Molar Volume", get_prop(m, 'Vm')],
            ["Enthalpy", get_prop(m, 'Hm')],
            ["Entropy", get_prop(m, 'Sm')],
            ["Density", get_prop(m, 'rho')]
        ]
        return results
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator