diff --git a/Cargo.lock b/Cargo.lock index fd33369..ad823d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,7 +168,7 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "dive-deco" -version = "2.1.0" +version = "2.1.1" dependencies = [ "criterion", ] diff --git a/Cargo.toml b/Cargo.toml index 2a67a17..85c1ce4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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)" diff --git a/src/buehlmann/buehlmann_model.rs b/src/buehlmann/buehlmann_model.rs index 3aebebd..7f5b70a 100644 --- a/src/buehlmann/buehlmann_model.rs +++ b/src/buehlmann/buehlmann_model.rs @@ -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 { + model.compartments.clone().into_iter().map(|comp| { + comp.supersaturation(model.config().surface_pressure, 0.) + }).collect::>() + } + + 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); + } } diff --git a/src/buehlmann/compartment.rs b/src/buehlmann/compartment.rs index a061c51..b2ed8d3 100644 --- a/src/buehlmann/compartment.rs +++ b/src/buehlmann/compartment.rs @@ -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; @@ -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(), } @@ -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] @@ -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); } } diff --git a/tests/buehlmann_tests.rs b/tests/buehlmann_tests.rs index 87a37c3..89ce044 100644 --- a/tests/buehlmann_tests.rs +++ b/tests/buehlmann_tests.rs @@ -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] @@ -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] @@ -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] @@ -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] diff --git a/tests/deco_tests.rs b/tests/deco_tests.rs index cf7f044..9149dcf 100644 --- a/tests/deco_tests.rs +++ b/tests/deco_tests.rs @@ -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![ @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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, expected_deco_stages: Vec) { diff --git a/tests/gradient_factors_tests.rs b/tests/gradient_factors_tests.rs index c3de73b..09898df 100644 --- a/tests/gradient_factors_tests.rs +++ b/tests/gradient_factors_tests.rs @@ -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), ]; diff --git a/tests/helium_tests.rs b/tests/helium_tests.rs index 79a7a00..598cd51 100644 --- a/tests/helium_tests.rs +++ b/tests/helium_tests.rs @@ -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] @@ -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); } @@ -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.); }