MIXTURE_FLASH
This function performs a mixture flash calculation with the thermo package from component identifiers, composition, temperature, and pressure, then returns key bulk properties such as phase, vapor fraction, density, enthalpy, and entropy.
Input mole fractions are normalized before calculation so they sum to unity:
z_i^{*} = \frac{z_i}{\sum_j z_j}
The normalized composition and specified state variables are then used to solve for equilibrium state-dependent mixture properties.
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.
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.000039208 |
| Enthalpy | -37819.6 |
| Entropy | -97.7244 |
| Density | 817.228 |
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.0000180683 |
| Enthalpy | -43985.7 |
| Entropy | -118.728 |
| Density | 997.064 |
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.0246172 |
| Enthalpy | 53.9815 |
| Entropy | 4.45377 |
| Density | 1.17196 |
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.0000718494 |
| Enthalpy | -32604.2 |
| Entropy | -87.9393 |
| Density | 830.679 |
Python Code
Show 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
Range of chemical identifiers (names, CAS).
Range of mole fractions.
Temperature [K].
Pressure [Pa].