Use SAC from preferences for PSCR oxygen drop

The ratio between SAC and oxygen metabolism rate can be assumed constant
but not the metabolism rate. So we better base our calculation on the ratio
that uses the SAC from the preferences as that pairs well with the O2
consumption from the preferences.

Hence we ran remove the sac parameter from fill_pressures().

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2015-01-19 11:32:27 +01:00 committed by Dirk Hohndel
parent 86c961614b
commit 837dcde0c1
4 changed files with 10 additions and 16 deletions

2
deco.c
View file

@ -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;

17
dive.c
View file

@ -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;
}
}
}

2
dive.h
View file

@ -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);

View file

@ -442,9 +442,8 @@ static void check_setpoint_events(struct dive *dive, struct divecomputer *dc, st
}
struct plot_info calculate_max_limits_new(struct dive *dive)
struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer *dc)
{
struct divecomputer *dc = &dive->dc;
static struct plot_info pi;
int maxdepth = dive->maxdepth.mm;
int maxtime = 0;
@ -946,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);