LI_JOHNS_AHMADI
This function solves the Li-Johns-Ahmadi flash equation, an alternative to classical Rachford-Rice formulations, for vapor fraction and phase compositions.
It uses overall composition and K-values and can accept an optional initial guess.
Excel Usage
=LI_JOHNS_AHMADI(zs, ks, guess)
zs(list[list], required): Overall mole fractions as a selected range (-).ks(list[list], required): Equilibrium K-values as a selected range (-).guess(float, optional, default: null): Initial guess for the solution (-).
Returns (list[list]): 2D array containing vapor fraction and phase compositions.
Example 1: Base Li-Johns-Ahmadi solve
Inputs:
| zs | ks | ||||
|---|---|---|---|---|---|
| 0.5 | 0.3 | 0.2 | 1.685 | 0.742 | 0.532 |
Excel formula:
=LI_JOHNS_AHMADI({0.5,0.3,0.2}, {1.685,0.742,0.532})
Expected output:
| Property | Value |
|---|---|
| VF | 0.69073 |
| xs | [0.33940869696634357, 0.3650560590371706, 0.2955352439964858] |
| ys | [0.5719036543882889, 0.27087159580558057, 0.15722474980613044] |
Example 2: Alternate composition and K-values
Inputs:
| zs | ks | ||||
|---|---|---|---|---|---|
| 0.45 | 0.35 | 0.2 | 1.7 | 0.75 | 0.5 |
Excel formula:
=LI_JOHNS_AHMADI({0.45,0.35,0.2}, {1.7,0.75,0.5})
Expected output:
| Property | Value |
|---|---|
| VF | 0.5 |
| xs | [0.33333333333333337, 0.39999999999999997, 0.26666666666666666] |
| ys | [0.5666666666666668, 0.3, 0.13333333333333333] |
Example 3: Solve with a custom guess
Inputs:
| zs | ks | guess | ||||
|---|---|---|---|---|---|---|
| 0.4 | 0.4 | 0.2 | 1.9 | 0.82 | 0.45 | 0.5 |
Excel formula:
=LI_JOHNS_AHMADI({0.4,0.4,0.2}, {1.9,0.82,0.45}, 0.5)
Expected output:
| Property | Value |
|---|---|
| VF | 0.561159 |
| xs | [0.26577314719086675, 0.44494307181957643, 0.2892837809895568] |
| ys | [0.5049689796626468, 0.36485331889205264, 0.13017770144530058] |
Example 4: Three-component mixture case
Inputs:
| zs | ks | ||||
|---|---|---|---|---|---|
| 0.2 | 0.5 | 0.3 | 3 | 0.9 | 0.2 |
Excel formula:
=LI_JOHNS_AHMADI({0.2,0.5,0.3}, {3,0.9,0.2})
Expected output:
| Property | Value |
|---|---|
| VF | 0.128591 |
| xs | [0.1590859595994075, 0.5065133044595129, 0.33440073594107966] |
| ys | [0.47725787879822246, 0.45586197401356165, 0.06688014718821593] |
Python Code
Show Code
from chemicals.rachford_rice import Li_Johns_Ahmadi_solution as chemicals_li_johns_ahmadi_solution
def li_johns_ahmadi(zs, ks, guess=None):
"""
Solve the Li-Johns-Ahmadi flash equation for vapor fraction and phase compositions.
See: https://chemicals.readthedocs.io/chemicals.rachford_rice.html#chemicals.rachford_rice.Li_Johns_Ahmadi_solution
This example function is provided as-is without any representation of accuracy.
Args:
zs (list[list]): Overall mole fractions as a selected range (-).
ks (list[list]): Equilibrium K-values as a selected range (-).
guess (float, optional): Initial guess for the solution (-). Default is None.
Returns:
list[list]: 2D array containing vapor fraction and phase compositions.
"""
try:
def to_list(x):
if isinstance(x, list):
out = []
for row in x:
if isinstance(row, list):
for val in row:
if val is not None and val != "":
out.append(float(val))
elif row is not None and row != "":
out.append(float(row))
return out
if x is None or x == "":
return []
return [float(x)]
z_vals = to_list(zs)
k_vals = to_list(ks)
if len(z_vals) == 0 or len(z_vals) != len(k_vals):
return "Error: zs and ks must be non-empty and have the same length"
vf, xs, ys = chemicals_li_johns_ahmadi_solution(zs=z_vals, Ks=k_vals, guess=guess)
return [["Property", "Value"], ["VF", vf], ["xs", str(xs)], ["ys", str(ys)]]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
Overall mole fractions as a selected range (-).
Equilibrium K-values as a selected range (-).
Initial guess for the solution (-).