From 65a11a660ed85deeb63b7808ebfc6e8aa0c037c8 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Sun, 18 Jan 2015 13:15:43 +0100 Subject: [PATCH] Don't use current SAC for PSCR calculation To compute the oxygen drop in a PSCR one needs the ratio of SAC/o2metabolism_rate. The latter is preconfigured but the former is known as a function of time. Still, we should use the SAC from the preferences as (according to wikipedia) the ratio is a constant even when the SAC is changing as the body increases the SAC to balance a higher o2 consumption. Signed-off-by: Robert C. Helling --- deco.c | 2 +- dive.c | 17 ++++++----------- dive.h | 2 +- planner.c | 2 +- profile.c | 2 +- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/deco.c b/deco.c index 14f88f6..9d0ec9d 100644 --- a/deco.c +++ b/deco.c @@ -190,7 +190,7 @@ double add_segment(double pressure, const struct gasmix *gasmix, int period_in_s int ci; struct gas_pressures pressures; - fill_pressures(&pressures, pressure - WV_PRESSURE, gasmix, (double) ccpo2 / 1000.0, dive->dc.divemode, sac); + fill_pressures(&pressures, pressure - WV_PRESSURE, gasmix, (double) ccpo2 / 1000.0, dive->dc.divemode); if (buehlmann_config.gf_low_at_maxdepth && pressure > gf_low_pressure_this_dive) gf_low_pressure_this_dive = pressure; diff --git a/dive.c b/dive.c index 33e3fb2..a5dc152 100644 --- a/dive.c +++ b/dive.c @@ -1665,13 +1665,8 @@ int gasmix_distance(const struct gasmix *a, const struct gasmix *b) * *mix = structure containing cylinder gas mixture information. * This function called by: calculate_gas_information_new() in profile.c; add_segment() in deco.c. */ -extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, const struct gasmix *mix, double po2, enum dive_comp_type divemode, int sac) +extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, const struct gasmix *mix, double po2, enum dive_comp_type divemode) { - if (!sac) { - /* The SAC has not yet been computer, so use the default * - * We might try harder... */ - sac = prefs.bottomsac; - } if (po2) { // This is probably a CCR dive where pressures->o2 is defined if (po2 >= amb_pressure) { pressures->o2 = amb_pressure; @@ -1687,14 +1682,14 @@ extern void fill_pressures(struct gas_pressures *pressures, const double amb_pre } } else { if (divemode == PSCR) { /* The steady state approximation should be good enough */ - pressures->o2 = get_o2(mix) / 1000.0 * amb_pressure - (1.0 - get_o2(mix) / 1000.0) * prefs.o2consumption / (sac * prefs.pscr_ratio / 1000.0); + pressures->o2 = get_o2(mix) / 1000.0 * amb_pressure - (1.0 - get_o2(mix) / 1000.0) * prefs.o2consumption / (prefs.bottomsac * prefs.pscr_ratio / 1000.0); pressures->he = (amb_pressure - pressures->o2) * get_he(mix) / (1000.0 - get_o2(mix)); pressures->n2 = (amb_pressure - pressures->o2) * (1000 - get_o2(mix) - get_he(mix)) / (1000.0 - get_o2(mix)); } else { - // Open circuit dives: no gas pressure values available, they need to be calculated - pressures->o2 = get_o2(mix) / 1000.0 * amb_pressure; // These calculations are also used if the CCR calculation above.. - pressures->he = get_he(mix) / 1000.0 * amb_pressure; // ..returned a po2 of zero (i.e. o2 sensor data not resolvable) - pressures->n2 = (1000 - get_o2(mix) - get_he(mix)) / 1000.0 * amb_pressure; + // Open circuit dives: no gas pressure values available, they need to be calculated + pressures->o2 = get_o2(mix) / 1000.0 * amb_pressure; // These calculations are also used if the CCR calculation above.. + pressures->he = get_he(mix) / 1000.0 * amb_pressure; // ..returned a po2 of zero (i.e. o2 sensor data not resolvable) + pressures->n2 = (1000 - get_o2(mix) - get_he(mix)) / 1000.0 * amb_pressure; } } } diff --git a/dive.h b/dive.h index 327598b..56f38f9 100644 --- a/dive.h +++ b/dive.h @@ -143,7 +143,7 @@ struct gas_pressures { double o2, n2, he; }; -extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, const struct gasmix *mix, double po2, enum dive_comp_type dctype, int sac); +extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, const struct gasmix *mix, double po2, enum dive_comp_type dctype); extern void sanitize_gasmix(struct gasmix *mix); extern int gasmix_distance(const struct gasmix *a, const struct gasmix *b); diff --git a/planner.c b/planner.c index 8cd786e..d660660 100644 --- a/planner.c +++ b/planner.c @@ -749,7 +749,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool if (dp->time != 0) { struct gas_pressures pressures; fill_pressures(&pressures, depth_to_atm(dp->depth, dive), &dp->gasmix, 0.0, - dive->dc.divemode, dp->entered ? prefs.bottomsac : prefs.decosac); + dive->dc.divemode); if (pressures.o2 > (dp->entered ? prefs.bottompo2 : prefs.decopo2) / 1000.0) { const char *depth_unit; diff --git a/profile.c b/profile.c index 05e84cd..026b871 100644 --- a/profile.c +++ b/profile.c @@ -945,7 +945,7 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p amb_pressure = depth_to_mbar(entry->depth, dive) / 1000.0; - fill_pressures(&entry->pressures, amb_pressure, &dive->cylinder[cylinderindex].gasmix, entry->o2pressure.mbar / 1000.0, dive->dc.divemode, entry->sac); + fill_pressures(&entry->pressures, amb_pressure, &dive->cylinder[cylinderindex].gasmix, entry->o2pressure.mbar / 1000.0, dive->dc.divemode); fn2 = (int)(1000.0 * entry->pressures.n2 / amb_pressure); fhe = (int)(1000.0 * entry->pressures.he / amb_pressure); -- 1.9.3 (Apple Git-50)