UNPKG

dive-deco

Version:

A TypeScript implementation of decompression calculation algorithms for scuba diving, featuring Bühlmann ZH-L16C algorithm with gradient factors, gas management, and oxygen toxicity tracking.

80 lines (79 loc) 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Gas = void 0; const depth_1 = require("./depth"); // Alveolar water vapor pressure assuming 47 mm Hg at 37C (Buhlmann's value) const ALVEOLI_WATER_VAPOR_PRESSURE = 0.0627; class Gas { o2Pp; n2Pp; hePp; constructor(o2Pp, hePp) { if (o2Pp < 0 || o2Pp > 1) { throw new Error('Invalid O2 partial pressure'); } if (hePp < 0 || hePp > 1) { throw new Error(`Invalid He partial pressure [${hePp}]`); } if (o2Pp + hePp > 1) { throw new Error("Invalid partial pressures, can't exceed 1ATA in total"); } this.o2Pp = o2Pp; this.hePp = hePp; this.n2Pp = Math.round((1 - (o2Pp + hePp)) * 10000) / 10000; } static air() { return new Gas(0.21, 0); } get o2() { return this.o2Pp; } get n2() { return this.n2Pp; } get he() { return this.hePp; } id() { return `${Math.round(this.o2Pp * 100)}/${Math.round(this.hePp * 100)}`; } partialPressures(depth, surfacePressure) { const gasPressure = surfacePressure / 1000 + depth.asMeters() / 10; return this.gasPressuresCompound(gasPressure); } inspiredPartialPressures(depth, surfacePressure) { const gasPressure = surfacePressure / 1000 + depth.asMeters() / 10 - ALVEOLI_WATER_VAPOR_PRESSURE; return this.gasPressuresCompound(gasPressure); } gasPressuresCompound(gasPressure) { return { o2: this.o2Pp * gasPressure, n2: this.n2Pp * gasPressure, he: this.hePp * gasPressure, }; } maxOperatingDepth(ppO2Limit) { return depth_1.Depth.fromMeters(10 * (ppO2Limit / this.o2Pp - 1)); } equivalentNarcoticDepth(depth) { let end = depth .add(depth_1.Depth.fromMeters(10)) .multiply(1 - this.hePp) .subtract(depth_1.Depth.fromMeters(10)); if (end.lessThan(depth_1.Depth.zero())) { end = depth_1.Depth.zero(); } return end; } toString() { return `${Math.round(this.o2Pp * 100)}/${Math.round(this.hePp * 100)}`; } equals(other) { return (this.o2Pp === other.o2Pp && this.n2Pp === other.n2Pp && this.hePp === other.hePp); } } exports.Gas = Gas;