Skip to content

Commit 8861ab7

Browse files
authored
Merge pull request #38 from KG32/fix/deco-runtime-gas-switches
Fix/deco runtime gas switches
2 parents 660c753 + 88eb459 commit 8861ab7

File tree

6 files changed

+45
-12
lines changed

6 files changed

+45
-12
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dive-deco"
3-
version = "4.3.0"
3+
version = "4.3.1"
44
edition = "2021"
55
license = "MIT"
66
description = "A dive decompression models library (Buehlmann ZH-L 16C)"

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ The Bühlmann decompression set of parameters is an Haldanian mathematical model
3434
### Planned features
3535

3636
- extended deco model config [metric/imperial units, water density and more] (currently metric and density assumed to be 1.03kg/l as salt water)
37-
- OTU (Oxygen Toxicity Units)
3837
- travel records optimization (linear ascent / descent records using Schreiner equation instead of iterative Haldane equation)
3938
- other deco algorithms (VPM-B)
4039
- other optimizations

src/common/deco.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,12 @@ impl Deco {
303303
} else {
304304
// ascent to next gas switch depth if next gas' MOD below ceiling
305305
if let Some(next_switch_gas) = next_switch_gas {
306-
return Ok((
307-
Some(DecoAction::AscentToGasSwitchDepth),
308-
Some(next_switch_gas),
309-
));
306+
if next_switch_gas.max_operating_depth(1.6) >= ceiling {
307+
return Ok((
308+
Some(DecoAction::AscentToGasSwitchDepth),
309+
Some(next_switch_gas),
310+
));
311+
}
310312
}
311313
Ok((Some(DecoAction::AscentToCeil), None))
312314
}

tests/buehlmann_tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ fn test_example_ceiling_start() {
174174
);
175175

176176
let air = Gas::air();
177-
// let ean_50 = Gas::new(0.50, 0.);
178177

179178
// instant drop to 40m on air for 10min
180179
model.record(40., 10 * 60, &air);
@@ -218,15 +217,15 @@ fn test_gradual_ascent_with_deco() {
218217
.with_surface_pressure(1013),
219218
);
220219
let air = Gas::air();
221-
let ean50 = Gas::new(0.21, 0.50);
220+
let ean_50 = Gas::new(0.50, 0.);
222221
model.record(45., 30 * 60, &air);
223222
loop {
224223
let depth = model.dive_state().depth;
225224
if depth <= 0. {
226225
break;
227226
}
228227
model.record_travel_with_rate(depth - 3., 10., &air);
229-
model.deco(vec![air, ean50]).unwrap();
228+
model.deco(vec![air, ean_50]).unwrap();
230229
}
231230
}
232231

tests/deco_tests.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use dive_deco::{
2-
BuehlmannConfig, BuehlmannModel, DecoModel, DecoRuntime, DecoStage, DecoStageType, Depth, Gas,
3-
MinutesSigned,
2+
BuehlmannConfig, BuehlmannModel, CeilingType, DecoModel, DecoRuntime, DecoStage, DecoStageType,
3+
Depth, Gas, MinutesSigned,
44
};
55

66
pub mod fixtures;
@@ -248,6 +248,39 @@ fn test_runtime_on_missed_stop() {
248248
}
249249
}
250250

251+
#[test]
252+
fn test_deco_runtime_integrity() {
253+
let config = BuehlmannConfig::new()
254+
.with_gradient_factors(30, 70)
255+
.with_ceiling_type(CeilingType::Adaptive);
256+
let mut model = BuehlmannModel::new(config);
257+
let air = Gas::air();
258+
let ean_50 = Gas::new(0.50, 0.);
259+
let oxygen = Gas::new(1., 0.);
260+
model.record(40., 20 * 60, &air);
261+
262+
let deco_runtime = model.deco(vec![air, ean_50, oxygen]).unwrap();
263+
let deco_stages = deco_runtime.deco_stages;
264+
265+
deco_stages.iter().reduce(|a, b| {
266+
// validate depth order
267+
assert!(
268+
b.start_depth == a.end_depth,
269+
"next stage start depth ({:?}@{}m) should equal previous stage end depth ({:?}@{}m)",
270+
b.stage_type,
271+
b.start_depth,
272+
a.stage_type,
273+
a.end_depth
274+
);
275+
// validate gas switch MOD
276+
if a.stage_type == DecoStageType::GasSwitch {
277+
let gas_switch_target_mod = a.gas.max_operating_depth(1.6);
278+
assert!(a.start_depth <= gas_switch_target_mod);
279+
}
280+
b
281+
});
282+
}
283+
251284
fn get_first_deco_stop_depth(deco: DecoRuntime) -> Option<Depth> {
252285
let first_stop = deco
253286
.deco_stages

0 commit comments

Comments
 (0)