Blending
What it's for
Plans gas fills. partialPressureBlend works out how much helium, oxygen and top-up gas to add. topUp gives the mix you get after topping up. nitroxStickFlowRate and nitroxStickSupplyDraw size continuous nitrox blending.
Formulas
Top-up
, : start and final absolute pressure, bar. , : fraction of a gas in the start gas and the top-up gas. Apply the formula to both O₂ and He.
Partial-pressure blend
Adding pure He, pure O₂ and a top-up gas to a cylinder, the added partial pressures
, : start and final gauge pressure, bar. , : target fractions. , : start-gas fractions. , : top-up gas fractions. , : pressure of pure helium and pure oxygen to add, bar. The top-up gas adds .
Bleed-down
If a solution needs a negative partial, the start gas is in the way and some must be bled off first. Each partial is affine in the start pressure
Nitrox stick
: oxygen injection rate. : air flow. Both in the same units (for example L/min). : target O₂ fraction. 0.209 is the O₂ fraction of AIR.
Reason codes
When no plan exists the result has feasible: false and a reason. It is never thrown.
| Reason | Meaning |
|---|---|
top-up-unusable | The top-up gas has no usable O₂/inert direction, so the system is singular. |
drain-insufficient | Even bleeding the cylinder empty cannot reach the target. |
What useRealGas does
With useRealGas: true, partialPressureBlend solves the same 2×2 system in moles instead of gauge bar. Amounts are expressed as ideal-equivalent absolute pressure $n = $ idealEquivalentPressure(mix, P_abs) (moles per container litre, scaled so an ideal gas gives
- Final contents: the final mix is the target, so
. Start contents: . - The system above is solved with
and in place of and , giving moles of pure He, pure O₂ and top-up ( ). - The additions are replayed in
order. After each one the tank mix and total moles are known, and the gauge reading isrealPressureForIdealEquivalent(mixSoFar, nSoFar) − 1.01325.steps[].toBaris that reading, andpHe,pO2,pTop(andsteps[].addBar) are the gauge increments between steps, so they depend onorder. - Bleed-down works on
exactly as in ideal mode (the partials are affine in ; an empty cylinder still holds ), and bleedToisrealPressureForIdealEquivalent(startGas, n_s) − 1.01325, clamped at 0.
This is an exact mole balance within the virial model, not a Z-scaling approximation. Every pressure in the result is gauge bar. When the result is infeasible there is no real fill to replay, so it reports the ideal-gas solution from the unbled start; its (possibly negative) partials show the shortfall. Real-gas mode can be infeasible where ideal mode is not: the last 1 atm of start gas can never be bled out, so, for example, converting a full 10/70 cylinder to EAN32 at the same pressure would need a drain below 0 bar gauge.
topUp iterates the mole balance with Z of the start and final mix, up to 10 fixed-point steps. See Real gas.
Assumptions and limits
- All pressures in inputs and results are gauge bar unless named
Abs. ordersets the fill sequence and must be a permutation of['he', 'o2', 'top']. It does not change the amounts.- The top-up gas defaults to
AIR. - Temperature effects are not modelled here. See Filling for hot fills.
- The nitrox stick functions assume ideal gas, and a target at or below air returns 0.
Sources
The library cites no external source for these. topUp uses mole balances on absolute pressures, while partialPressureBlend (ideal mode) and the nitrox-stick supply draw are ideal-gas balances in gauge bar. partialPressureBlend with useRealGas is a mole balance on the virial Z model.
Examples
import { AIR, gas } from 'dive-math/gas'
import { partialPressureBlend, topUp, nitroxStickFlowRate } from 'dive-math/blending'
const r = partialPressureBlend({ startBar: 0, startGas: AIR, finalBar: 200, targetGas: gas(0.18, 0.45) })
r.pHe // => 90
r.pO2 // => 16.45
r.feasible // => true
topUp({ startBar: 100, startGas: gas(0.32), topGas: AIR, finalBar: 200 }).gas.fo2 // => 0.2648
nitroxStickFlowRate({ targetFo2: 0.32, airFlow: 300 }) // => 48.97API
See the blending API reference.