Skip to content

Commit

Permalink
Merge pull request #23 from KG32/fix/initial-surface-interval-equality
Browse files Browse the repository at this point in the history
fix: initial model tissues saturation considers alveolar water vapor …
  • Loading branch information
KG32 authored Aug 20, 2024
2 parents 2111df6 + e99258b commit 2c0c000
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dive-deco"
version = "2.1.0"
version = "2.1.1"
edition = "2021"
license = "MIT"
description = "A dive decompression models library (Buehlmann ZH-L 16C)"
Expand Down
19 changes: 19 additions & 0 deletions src/buehlmann/buehlmann_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,23 @@ mod tests {
let slope_point = model.gf_slope_point(gf, 33.528, 30.48);
assert_eq!(slope_point, 35);
}

#[test]
fn test_initial_supersaturation() {
fn extract_supersaturations(model: BuehlmannModel) -> Vec<Supersaturation> {
model.compartments.clone().into_iter().map(|comp| {
comp.supersaturation(model.config().surface_pressure, 0.)
}).collect::<Vec<Supersaturation>>()
}

let model_initial = BuehlmannModel::default();

let mut model_with_surface_interval = BuehlmannModel::default();
model_with_surface_interval.step(0., 999999, &Gas::air());

let initial_gfs = extract_supersaturations(model_initial);
let surface_interval_gfs = extract_supersaturations(model_with_surface_interval);

assert_eq!(initial_gfs, surface_interval_gfs);
}
}
19 changes: 11 additions & 8 deletions src/buehlmann/compartment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ impl Compartment {
model_config: BuehlmannConfig,
) -> Self {
let init_gas = Gas::air();
let init_gas_compound_pressures = init_gas.gas_pressures_compound(1.);
let init_gas_compound_pressures = init_gas.inspired_partial_pressures(
0.,
model_config.surface_pressure
);
let n2_ip = init_gas_compound_pressures.n2;
let he_ip = init_gas_compound_pressures.he;

Expand Down Expand Up @@ -179,11 +182,11 @@ mod tests {
comp,
Compartment {
no: 1,
params: (4., 1.2599, 0.5050, 1.51, 01.7424, 0.4245),
he_ip: 0.,
n2_ip: 0.79,
total_ip: 0.79,
min_tolerable_amb_pressure: -0.2372995,
min_tolerable_amb_pressure: -0.257127315,
he_ip: 0.0,
n2_ip: 0.750737,
total_ip: 0.750737,
params: (4.0, 1.2599, 0.505, 1.51, 1.7424, 0.4245),
// mocked config and state
model_config: BuehlmannConfig::default(),
}
Expand All @@ -196,7 +199,7 @@ mod tests {
let air = Gas::new(0.21, 0.);
let step = StepData { depth: 30., time: (10 * 60), gas: &air };
comp.recalculate(&step, 100, 1000);
assert_eq!(comp.total_ip, 1.315391144211091);
assert_eq!(comp.total_ip, 1.2850179204911072);
}

#[test]
Expand All @@ -213,7 +216,7 @@ mod tests {
let step = StepData { depth: 30., time: (10 * 60), gas: &air };
comp.recalculate(&step, 100, 100);
let min_tolerable_pressure = comp.min_tolerable_amb_pressure;
assert_eq!(min_tolerable_pressure, 0.4342609809161748);
assert_eq!(min_tolerable_pressure, 0.40957969932131577);
}

}
10 changes: 5 additions & 5 deletions tests/buehlmann_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ fn test_gfs() {
let air = Gas::new(0.21, 0.);

model.step(50., 20 * 60, &air);
assert_eq!(model.supersaturation(), Supersaturation { gf_99: 0., gf_surf: 194.3055827400852 });
assert_eq!(model.supersaturation(), Supersaturation { gf_99: 0., gf_surf: 193.8554997961134 });

model.step(40., 10 * 60, &air);
assert_eq!(model.supersaturation(), Supersaturation { gf_99: 0., gf_surf: 209.1025059770294 });
assert_eq!(model.supersaturation(), Supersaturation { gf_99: 0., gf_surf: 208.00431699178796 });
}

#[test]
Expand Down Expand Up @@ -117,7 +117,7 @@ fn test_altitude() {
let air = Gas::new(0.21, 0.);
model.step(40., 60 * 60, &air);
let Supersaturation { gf_surf, ..} = model.supersaturation();
assert_eq!(gf_surf, 314.27462637570085);
assert_eq!(gf_surf, 299.023204474694);
}

#[test]
Expand All @@ -133,7 +133,7 @@ fn test_example_deco_start() {

// instant drop to 40m on air for 10min
model.step(40., 10 * 60, &air);
assert_eq!(model.ceiling(), 12.906758687930836);
assert_eq!(model.ceiling(), 12.85312294790554);
}

#[test]
Expand All @@ -151,7 +151,7 @@ fn test_example_deco() {
model.step(30., 3 * 60, &air);
model.step(21., 10 * 60, &ean_50);

assert_eq!(model.ceiling(), 11.744868181179458);
assert_eq!(model.ceiling(), 12.455491216740299);
}

#[test]
Expand Down
14 changes: 7 additions & 7 deletions tests/deco_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn test_deco_single_gas() {
tts
} = model.deco(vec![air]);

assert_close_to_percent!(tts as f64, 800., 1.); // 13.(3) min todo round to 14
assert_close_to_percent!(tts as f64, 754., 1.); // 13.(3) min todo round to 14
assert_eq!(deco_stages.len(), 5);

let expected_deco_stages = vec![
Expand All @@ -39,7 +39,7 @@ fn test_deco_single_gas() {
stage_type: DecoStageType::DecoStop,
start_depth: 6.0,
end_depth: 6.0,
duration: 95,
duration: 88,
gas: air
},
DecoStage {
Expand All @@ -53,7 +53,7 @@ fn test_deco_single_gas() {
stage_type: DecoStageType::DecoStop,
start_depth: 3.0,
end_depth: 3.0,
duration: 436,
duration: 400,
gas: air
},
DecoStage {
Expand Down Expand Up @@ -108,7 +108,7 @@ fn test_deco_multi_gas() {
stage_type: DecoStageType::DecoStop,
start_depth: 6.0,
end_depth: 6.0,
duration: 39,
duration: 34,
gas: ean_50
},
DecoStage {
Expand All @@ -122,7 +122,7 @@ fn test_deco_multi_gas() {
stage_type: DecoStageType::DecoStop,
start_depth: 3.0,
end_depth: 3.0,
duration: 301,
duration: 291,
gas: ean_50
},
DecoStage {
Expand Down Expand Up @@ -168,7 +168,7 @@ fn test_deco_with_deco_mod_at_bottom() {
stage_type: DecoStageType::DecoStop,
start_depth: 3.0,
end_depth: 3.0,
duration: 300,
duration: 268,
gas: ean_36,
},
DecoStage {
Expand All @@ -181,7 +181,7 @@ fn test_deco_with_deco_mod_at_bottom() {
];

assert_deco_stages_eq(deco_stages, expected_deco_stages);
assert_eq!(tts, 500);
assert_eq!(tts, 468);
}

fn assert_deco_stages_eq(deco_stages: Vec<DecoStage>, expected_deco_stages: Vec<DecoStage>) {
Expand Down
4 changes: 2 additions & 2 deletions tests/gradient_factors_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ fn test_ndl() {
let test_cases: Vec<(GradientFactors, Depth, Minutes)> = vec![
// 100/100
((100, 100), 21., 40),
((100, 100), 15., 88),
((100, 100), 15., 90),

// 70/70
((70, 70), 21., 18),
((70, 70), 21., 19),
((70, 70), 15., 47),
];

Expand Down
6 changes: 3 additions & 3 deletions tests/helium_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn test_tmx_gf_surf() {

let Supersaturation { gf_surf, .. } = model.supersaturation();

assert_close_to_percent!(gf_surf, 335.77, 0.5);
assert_close_to_percent!(gf_surf, 335.77, 1.);
}

#[test]
Expand All @@ -24,7 +24,7 @@ fn test_tmx_ndl() {
let step = StepData { depth: 20., time: 0, gas: &tmx };
model.step(step.depth, step.time, step.gas);

assert_eq!(model.ndl(), 16);
assert_eq!(model.ndl(), 17);
}


Expand All @@ -40,5 +40,5 @@ fn test_heliox_gf_surf() {

let Supersaturation { gf_surf, .. } = model.supersaturation();

assert_close_to_percent!(gf_surf, 201.16, 0.5);
assert_close_to_percent!(gf_surf, 197.93, 1.);
}

0 comments on commit 2c0c000

Please sign in to comment.