Skip to content

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 ​

r=Ps,absPf,absF=rFs+(1−r)Ft
  • Ps,abs, Pf,abs: start and final absolute pressure, bar.
  • Fs, Ft: 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 pHe and pO2 solve a 2×2 linear system (the top-up share is whatever pressure remains):

[1−FHe,t−FHe,t−FO2,t1−FO2,t][pHepO2]=[FHePf−FHe,sPs−FHe,t(Pf−Ps)FO2Pf−FO2,sPs−FO2,t(Pf−Ps)]
  • Ps, Pf: start and final gauge pressure, bar.
  • FHe, FO2: target fractions. FHe,s, FO2,s: start-gas fractions. FHe,t, FO2,t: top-up gas fractions.
  • pHe, pO2: pressure of pure helium and pure oxygen to add, bar. The top-up gas adds ptop=Pf−Ps−pHe−pO2.

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 Ps, so each is a straight line in Ps. The library rebuilds each line from two evaluations (Ps=0 and the real start pressure) and takes the highest bleed target that keeps all three partials at or above zero. No search or iteration is needed.

Nitrox stick ​

QO2=QairF−0.2091−F
  • QO2: oxygen injection rate. Qair: air flow. Both in the same units (for example L/min).
  • F: 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.

ReasonMeaning
top-up-unusableThe top-up gas has no usable O₂/inert direction, so the system is singular.
drain-insufficientEven 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 n=Pabs):

  • Final contents: the final mix is the target, so nf=n(Ftarget,Pf+1.01325). Start contents: ns=n(Fs,Ps+1.01325).
  • The system above is solved with nf and ns in place of Pf and Ps, giving moles of pure He, pure O₂ and top-up (ntop=nf−ns−nHe−nO2).
  • The additions are replayed in order. After each one the tank mix and total moles are known, and the gauge reading is realPressureForIdealEquivalent(mixSoFar, nSoFar) − 1.01325. steps[].toBar is that reading, and pHe, pO2, pTop (and steps[].addBar) are the gauge increments between steps, so they depend on order.
  • Bleed-down works on ns exactly as in ideal mode (the partials are affine in ns; an empty cylinder still holds n(Fs,1.01325)), and bleedTo is realPressureForIdealEquivalent(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.
  • order sets 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 ​

ts
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.97

API ​

See the blending API reference.

Reference only — verify every fill and dive plan independently.