#decompression #diving #scuba #buehlmann #buhlmann

dive-deco

A dive decompression models library (Buehlmann ZH-L 16C)

7 releases (4 breaking)

new 0.5.1 Apr 28, 2024
0.5.0 Apr 28, 2024
0.4.0 Apr 20, 2024
0.3.0 Mar 3, 2024
0.1.1 Feb 18, 2024

#277 in Algorithms

Download history 226/week @ 2024-02-17 169/week @ 2024-02-24 108/week @ 2024-03-02 25/week @ 2024-03-09 2/week @ 2024-03-16 24/week @ 2024-03-30 5/week @ 2024-04-06 108/week @ 2024-04-20

137 downloads per month

MIT license

26KB
474 lines

dive-deco

A dive decompression models library.

Buehlmann ZH-L16C

The Bühlmann decompression set of parameters is an Haldanian mathematical model of the way in which inert gases enter and leave the human body as the ambient pressure changes. Versions are used to create Bühlmann decompression tables and in personal dive computers to compute no-decompression limits and decompression schedules for dives in real-time.^1

Features

  • step-by-step decompression model (ZH-L16C params version) calculations using depth, time and used gas
  • current NDL (no-decompression limit)
  • current decompression ceiling
  • current gradient factors
    • current gradient factor (the raw percentage of the Bühlmann allowable supersaturation at the current depth, i.e. super-saturation percent gradient, a.k.a GF99)
    • surface gradient factor (the surfacing gradient factor, i.e. super-saturation percentage gradient relative to the surface)

Planned features

  • non-uniform gradient factors settings (currently model only supports uniform GF (GFHi = GFlo))
  • helium support
  • extended deco model config (water density, metric/imprial units, surface ambient pressure)
  • optimizations

API

Usage

Model initialization

Using default config
use dive_deco::{ BuehlmannConfig, BuehlmannModel, DecoModel };

fn main() {
    // model with default config (GF 100/100)
    let default_config = BuehlmannConfig::default();
    let model = BuehlmannModel::new(default_config);
    println!("{:?}", model.config()); // BuehlmannConfig { gf: (100, 100) }
}
Using config builder

Current config options

  • gradient_factors - gradient factors settings ([GFlow], [GFhigh])default: (100, 100)). Currently only uniform gradient factors settings are supported
    // model with configurable config
    let config_with_gf = BuehlmannConfig::new().gradient_factors(70, 70);
    let model = BuehlmannModel::new(config_with_gf);
    println!("{:?}", model.config()); // BuehlmannConfig { gf: (70, 70) }

NDL (no-decompression limit)

The NDL is a theoretical time obtained by calculating inert gas uptake and release in the body that determines a time interval a diver may theoretically spend at given depth without aquiring any decompression obligations (given constant depth and gas mix).

  • ndl() - no-decompression limit for current model state in minutes, assuming constant depth and gas mix
use dive_deco::{DecoModel, BuehlmannModel, BuehlmannConfig, Gas};

fn main() {
    // initialize a Buehlmann ZHL-16C deco model with default config (GF 100/100)
    let config = BuehlmannConfig::default();
    let mut model = BuehlmannModel::new(config);

    let air = Gas::new(0.21, 0.);
    let depth = 30.;
    let bottom_time_minutes = 10;

    // a simulated instantaneous drop to 20m with a single step simulating 20 minutes bottom time using air
    model.step(&depth, &(bottom_time_minutes * 60), &air);
    // model.step(....)
    // model.step(....)

    // current NDL (no-decompression limit)
    let current_ndl = model.ndl();
    println!("NDL: {} min", current_ndl); // output: NDL: 5 min
}

Decompression Ceiling

Minimum theoretical depth that can be reached at the moment without breaking the decompression obligation. In case of Buehlmann algorithm, a depth restricted by M-value given leading tissue saturation and gradient factors setting.

  • ceiling() - current decompression ceiling in msw, given current model state and gradient factors settings
use dive_deco::{ BuehlmannConfig, BuehlmannModel, DecoModel, Gas };

fn main() {
    let mut model = BuehlmannModel::new(BuehlmannConfig::default());

    let nitrox_32 = Gas::new(0.32, 0.);

    // ceiling after 20 min at 20 meters using EAN32 - ceiling at 0m
    model.step(&20., &(20 * 60), &nitrox_32);
    println!("Ceiling: {}m", model.ceiling()); // Ceiling: 0m

    // ceiling after another 42 min at 30 meters using EAN32 - ceiling at 3m
    model.step(&30., &(42 * 60), &nitrox_32);
    println!("Ceiling: {},", model.ceiling()); // Ceiling: 3.004(..)m
}
Current tissues oversaturation (gradient factors)

Current tissue oversaturation as gradient factors.

  • gfs_current() -> (now, surf) - oversaturation in % relative to M-value
    • now (f64) - a.k.a GF99, current oversaturation relative to ambient pressure
    • surf (f64) - a.k.a surfGF, current oversaturation relative to surface pressure
  // given model state after 120 seconds at 40 msw breathing air
  // (...)

  // on-gassing, gf99: 0%, surfGF: 71%
  let (gf_now, gf_surf) = model.gfs_current(); // (0.0, 71.09852831834125)

Common

Step

Represents a single model step as a datapoint.

  • new(depth, time, gas)
    • depth - current depth in msw
    • time - duration in seconds
    • gas - breathing mix inspired in this step
let depth = 20.;
let time = 1;
let nitrox = Gas::new(0.32, 0.);
// register 1 second at 20 msw breathing nitrox 32
model.step(&depth, &time, &nitrox);
Gas

Breathing gas used in the model.

  • new(o2, he)
    • o2 - oxygen partial pressure
    • he - helium partial pressure (TMX not supported yet)
  • partial_pressures(depth) - compounded gas's components partial pressures at certain depth
  • inspired_partial_pressures(depth) - inspired gas partial pressures in alveoli taking into account alveolar water vapor pressure
let mix = Gas::new(0.21, 0.);
mix.partial_pressures(&10.); // PartialPressures { o2: 0.42, n2: 1.58, he: 0.0 }
mix.inspired_partial_pressures(&10.); // PartialPressures { o2: 0.406833, n2: 1.530467, he: 0.0 }

References

⚠️ Disclaimer: Not Suitable for Dive Planning, Work-in-Progress Model This decompression model is currently in a developmental stage and should be treated as a work in progress. Users are advised that the information generated by this model may not be accurate and could contain errors. It is important to exercise caution and verify any critical information provided by the model through alternative sources. This model is not designed or intended to be used as a dive planning software. Diving involves inherent risks, and accurate planning is crucial for safety. Users are strongly advised to rely on specialized dive planning software and consult with certified dive professionals for accurate and reliable information related to diving activities. By using this model, users acknowledge that it is not a substitute for professional advice or dedicated tools designed for specific tasks, and the developers take no responsibility for any consequences arising from the use of information generated by this model.

No runtime deps