MIXTURE_STRING
This function constructs a CoolProp-compatible HEOS mixture identifier string from fluid names and mole fractions supplied in Excel ranges or scalar inputs. It flattens 2D inputs, removes blanks, and joins component terms into the required backend format.
For components i=1,\dots,n, the constructed mixture string corresponds to:
exttt{HEOS::Fluid}_1[z_1]\&\texttt{Fluid}_2[z_2]\&\cdots\&\texttt{Fluid}_n[z_n]
where each z_i is the provided mole fraction associated with fluid i.
Excel Usage
=MIXTURE_STRING(fluids, fractions)
fluids(list[list], required): List or range of fluid names (strings).fractions(list[list], required): List or range of mole fractions (floats).
Returns (str): Formatted mixture string.
Example 1: Water Ethanol Mixture
Inputs:
| fluids | fractions | ||
|---|---|---|---|
| Water | Ethanol | 0.4 | 0.6 |
Excel formula:
=MIXTURE_STRING({"Water","Ethanol"}, {0.4,0.6})
Expected output:
"HEOS::Water[0.4]&Ethanol[0.6]"
Example 2: Input from Excel 2D Range
Inputs:
| fluids | fractions |
|---|---|
| Nitrogen | 0.7 |
| Argon | 0.3 |
Excel formula:
=MIXTURE_STRING({"Nitrogen";"Argon"}, {0.7;0.3})
Expected output:
"HEOS::Nitrogen[0.7]&Argon[0.3]"
Example 3: R410A Definitions (50/50 R32/R125)
Inputs:
| fluids | fractions | ||
|---|---|---|---|
| R32 | R125 | 0.5 | 0.5 |
Excel formula:
=MIXTURE_STRING({"R32","R125"}, {0.5,0.5})
Expected output:
"HEOS::R32[0.5]&R125[0.5]"
Example 4: Artificial Air (Approximate)
Inputs:
| fluids | fractions | ||||
|---|---|---|---|---|---|
| Nitrogen | Oxygen | Argon | 0.78 | 0.21 | 0.01 |
Excel formula:
=MIXTURE_STRING({"Nitrogen","Oxygen","Argon"}, {0.78,0.21,0.01})
Expected output:
"HEOS::Nitrogen[0.78]&Oxygen[0.21]&Argon[0.01]"
Python Code
Show Code
# No external imports needed for string formatting
def mixture_string(fluids, fractions):
"""
Create a formatted CoolProp mixture string from component fluids and mole fractions.
See: https://coolprop.org/fluid_properties/Mixtures.html
This example function is provided as-is without any representation of accuracy.
Args:
fluids (list[list]): List or range of fluid names (strings).
fractions (list[list]): List or range of mole fractions (floats).
Returns:
str: Formatted mixture string.
"""
def flatten(data):
if isinstance(data, list):
flat = []
for item in data:
if isinstance(item, list):
flat.extend(flatten(item))
else:
flat.append(item)
return flat
return [data]
try:
names = flatten(fluids)
fracs = flatten(fractions)
# Filter out empty strings or None values which might come from larger Excel ranges
names = [str(n).strip() for n in names if n is not None and str(n).strip() != ""]
fracs = [float(f) for f in fracs if f is not None and str(f).strip() != ""]
if len(names) != len(fracs):
return f"Error: Number of fluids ({len(names)}) does not match number of fractions ({len(fracs)})"
if not names:
return "Error: No fluids provided"
# Validate sum of fractions?
# CoolProp might not strictly require sum=1.0 for all backends, but usually for mixtures it should be close.
# We will just format the string and let CoolProp validate the physics later.
components = []
for n, f in zip(names, fracs):
components.append(f"{n}[{f}]")
return "HEOS::" + "&".join(components)
except Exception as e:
return f"Error: {str(e)}"