summaryrefslogtreecommitdiffstats
path: root/deco.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2013-02-08 21:42:34 +1100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-08 22:14:53 +1100
commit3e66319e822a148ef4487aa459d7c99d2b09474f (patch)
treeef72d6ae99293d3451a934b336238b230f71473c /deco.c
parent74ff9f1eadb4381506b7f3b3e24697da6a5dec4f (diff)
downloadsubsurface-3e66319e822a148ef4487aa459d7c99d2b09474f.tar.gz
Remove the tissue_tolerated_ambient_pressure[] array
It wasn't really used. The only reader of that array was the same thing that wrote the entry, so instead of storing it in the array (and never using it ever after), just use the calculation directly, and remove the array entirely. This makes it much easier to see that the gradient factors are not used for any long-term state. We use them only for the pressure tolerance calculations at that particular point, and there is no "history" associated with it. This matters mainly because it means that we can do all the deco initialization and setup without worrying about exactly which gradient factors we will use. And we can use different gradient factors for diving and planning and no-fly calculations without the GF choice affecting the tissue state. Acked-by: Robert C. Helling <helling@lmu.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'deco.c')
-rw-r--r--deco.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/deco.c b/deco.c
index 023a20f72..4bddad576 100644
--- a/deco.c
+++ b/deco.c
@@ -79,7 +79,6 @@ const double buehlmann_He_factor_expositon_one_second[] = {
double tissue_n2_sat[16];
double tissue_he_sat[16];
-double tissue_tolerated_ambient_pressure[16];
int ci_pointing_to_guiding_tissue;
double gf_low_pressure_this_dive;
#define TISSUE_ARRAY_SZ sizeof(tissue_n2_sat)
@@ -96,11 +95,13 @@ static double tissue_tolerance_calc(const struct dive *dive)
for (ci = 0; ci < 16; ci++)
{
+ double tolerated;
+
tissue_inertgas_saturation = tissue_n2_sat[ci] + tissue_he_sat[ci];
buehlmann_inertgas_a = ((buehlmann_N2_a[ci] * tissue_n2_sat[ci]) + (buehlmann_He_a[ci] * tissue_he_sat[ci])) / tissue_inertgas_saturation;
buehlmann_inertgas_b = ((buehlmann_N2_b[ci] * tissue_n2_sat[ci]) + (buehlmann_He_b[ci] * tissue_he_sat[ci])) / tissue_inertgas_saturation;
- /* tissue_tolerated_ambient_pressure[ci] = (tissue_inertgas_saturation - buehlmann_inertgas_a) * buehlmann_inertgas_b; */
+ /* tolerated = (tissue_inertgas_saturation - buehlmann_inertgas_a) * buehlmann_inertgas_b; */
#if !GF_LOW_AT_MAXDEPTH
lowest_ceiling = (buehlmann_inertgas_b * tissue_inertgas_saturation - gf_low * buehlmann_inertgas_a * buehlmann_inertgas_b) /
@@ -109,17 +110,17 @@ static double tissue_tolerance_calc(const struct dive *dive)
gf_low_pressure_this_dive = lowest_ceiling;
#endif
- tissue_tolerated_ambient_pressure[ci] = (-buehlmann_inertgas_a * buehlmann_inertgas_b * (gf_high * gf_low_pressure_this_dive - gf_low * surface) -
- (1.0 - buehlmann_inertgas_b) * (gf_high - gf_low) * gf_low_pressure_this_dive * surface +
- buehlmann_inertgas_b * (gf_low_pressure_this_dive - surface) * tissue_inertgas_saturation) /
- (-buehlmann_inertgas_a * buehlmann_inertgas_b * (gf_high - gf_low) +
- (1.0 - buehlmann_inertgas_b)*(gf_low * gf_low_pressure_this_dive - gf_high * surface) +
- buehlmann_inertgas_b * (gf_low_pressure_this_dive - surface));
+ tolerated = (-buehlmann_inertgas_a * buehlmann_inertgas_b * (gf_high * gf_low_pressure_this_dive - gf_low * surface) -
+ (1.0 - buehlmann_inertgas_b) * (gf_high - gf_low) * gf_low_pressure_this_dive * surface +
+ buehlmann_inertgas_b * (gf_low_pressure_this_dive - surface) * tissue_inertgas_saturation) /
+ (-buehlmann_inertgas_a * buehlmann_inertgas_b * (gf_high - gf_low) +
+ (1.0 - buehlmann_inertgas_b)*(gf_low * gf_low_pressure_this_dive - gf_high * surface) +
+ buehlmann_inertgas_b * (gf_low_pressure_this_dive - surface));
- if (tissue_tolerated_ambient_pressure[ci] > ret_tolerance_limit_ambient_pressure)
+ if (tolerated > ret_tolerance_limit_ambient_pressure)
{
ci_pointing_to_guiding_tissue = ci;
- ret_tolerance_limit_ambient_pressure = tissue_tolerated_ambient_pressure[ci];
+ ret_tolerance_limit_ambient_pressure = tolerated;
}
}
return ret_tolerance_limit_ambient_pressure;
@@ -203,7 +204,6 @@ void clear_deco(double surface_pressure)
for (ci = 0; ci < 16; ci++) {
tissue_n2_sat[ci] = (surface_pressure - WV_PRESSURE) * N2_IN_AIR / 1000;
tissue_he_sat[ci] = 0.0;
- tissue_tolerated_ambient_pressure[ci] = 0.0;
}
gf_low_pressure_this_dive = surface_pressure + buehlmann_config.gf_low_position_min;
}
@@ -213,15 +213,13 @@ void cache_deco_state(double tissue_tolerance, char **cached_datap)
char *data = *cached_datap;
if (!data) {
- data = malloc(3 * TISSUE_ARRAY_SZ + 2 * sizeof(double) + sizeof(int));
+ data = malloc(2 * TISSUE_ARRAY_SZ + 2 * sizeof(double) + sizeof(int));
*cached_datap = data;
}
memcpy(data, tissue_n2_sat, TISSUE_ARRAY_SZ);
data += TISSUE_ARRAY_SZ;
memcpy(data, tissue_he_sat, TISSUE_ARRAY_SZ);
data += TISSUE_ARRAY_SZ;
- memcpy(data, tissue_tolerated_ambient_pressure, TISSUE_ARRAY_SZ);
- data += TISSUE_ARRAY_SZ;
memcpy(data, &gf_low_pressure_this_dive, sizeof(double));
data += sizeof(double);
memcpy(data, &tissue_tolerance, sizeof(double));
@@ -237,8 +235,6 @@ double restore_deco_state(char *data)
data += TISSUE_ARRAY_SZ;
memcpy(tissue_he_sat, data, TISSUE_ARRAY_SZ);
data += TISSUE_ARRAY_SZ;
- memcpy(tissue_tolerated_ambient_pressure, data, TISSUE_ARRAY_SZ);
- data += TISSUE_ARRAY_SZ;
memcpy(&gf_low_pressure_this_dive, data, sizeof(double));
data += sizeof(double);
memcpy(&tissue_tolerance, data, sizeof(double));