Some unification between Buehlmann and VPM-B

This patch makes deco_allowed_depth() work both for Buehlmann as well as
VPM-B (as long as the VPM-B internal variable total_gradient[] is valid).
As a bonus, in VPM-B mode, in the planner, the ceilings are VPM-B ceilings
and not Buehlmann GF.

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-08-12 12:06:52 +02:00 committed by Dirk Hohndel
parent 2455a5dec7
commit a8ce8c3ef1
5 changed files with 54 additions and 51 deletions

28
deco.c
View file

@ -19,6 +19,7 @@
#include <string.h>
#include "dive.h"
#include <assert.h>
#include <planner.h>
//! Option structure for Buehlmann decompression.
struct buehlmann_config {
@ -125,6 +126,7 @@ static double tissue_tolerance_calc(const struct dive *dive)
double lowest_ceiling = 0.0;
double tissue_lowest_ceiling[16];
if (prefs.deco_mode != VPMB || !in_planner) {
for (ci = 0; ci < 16; ci++) {
tissue_inertgas_saturation[ci] = tissue_n2_sat[ci] + tissue_he_sat[ci];
buehlmann_inertgas_a[ci] = ((buehlmann_N2_a[ci] * tissue_n2_sat[ci]) + (buehlmann_He_a[ci] * tissue_he_sat[ci])) / tissue_inertgas_saturation[ci];
@ -164,6 +166,17 @@ static double tissue_tolerance_calc(const struct dive *dive)
ret_tolerance_limit_ambient_pressure = tolerated;
}
}
} else {
// VPM-B ceiling
for (ci = 0; ci < 16; ci++) {
double tolerated = tissue_n2_sat[ci] + tissue_he_sat[ci] + vpmb_config.other_gases_pressure - total_gradient[ci];
if (tolerated >= ret_tolerance_limit_ambient_pressure) {
ci_pointing_to_guiding_tissue = ci;
ret_tolerance_limit_ambient_pressure = tolerated;
}
tolerated_by_tissue[ci] = tolerated;
}
}
return ret_tolerance_limit_ambient_pressure;
}
@ -210,21 +223,6 @@ double he_factor(int period_in_seconds, int ci)
return cache[ci].last_factor;
}
bool is_vpmb_ok(double pressure)
{
int ci;
double gradient;
double gas_tension;
for (ci = 0; ci < 16; ++ci) {
gas_tension = tissue_n2_sat[ci] + tissue_he_sat[ci] + vpmb_config.other_gases_pressure;
gradient = gas_tension - pressure;
if (gradient > total_gradient[ci])
return false;
}
return true;
}
void vpmb_start_gradient()
{
int ci;

1
dive.h
View file

@ -801,7 +801,6 @@ extern double restore_deco_state(char *data);
extern void nuclear_regeneration(double time);
extern void vpmb_start_gradient();
extern void vpmb_next_gradient(double deco_time);
extern bool is_vpmb_ok(double pressure);
/* this should be converted to use our types */
struct divedatapoint {

View file

@ -33,6 +33,14 @@ int decostoplevels_imperial[] = { 0, 3048, 6096, 9144, 12192, 15240, 18288, 2133
double plangflow, plangfhigh;
bool plan_verbatim, plan_display_runtime, plan_display_duration, plan_display_transitions;
/* This is a bit round about: Currently, we only support VPM-B in the planner,
* so, when we compute ceilings we have to know if we are in planning mode since
* the maximally allowed gradient in the tissues is determined by the critical volume algorithm for
* which we currently have no version for logged dives. But the information about the application state
* is only available in the C++/Qt part. So this global variable is a way to leak this info. */
bool in_planner = false;
const char *disclaimer;
#if DEBUG_PLAN
@ -879,15 +887,11 @@ bool trial_ascent(int trial_depth, int stoplevel, int avg_depth, int bottom_time
tissue_tolerance = add_segment(depth_to_mbar(trial_depth, &displayed_dive) / 1000.0,
gasmix,
TIMESTEP, po2, &displayed_dive, prefs.decosac);
if (prefs.deco_mode != VPMB && deco_allowed_depth(tissue_tolerance, surface_pressure, &displayed_dive, 1) > trial_depth - deltad) {
if (deco_allowed_depth(tissue_tolerance, surface_pressure, &displayed_dive, 1) > trial_depth - deltad) {
/* We should have stopped */
clear_to_ascend = false;
break;
}
if (prefs.deco_mode == VPMB && (!is_vpmb_ok(depth_to_mbar(trial_depth, &displayed_dive) / 1000.0))){
clear_to_ascend = false;
break;
}
trial_depth -= deltad;
}
restore_deco_state(trial_cache);

View file

@ -25,7 +25,7 @@ extern struct dive *planned_dive;
extern char *cache_data;
extern const char *disclaimer;
extern double plangflow, plangfhigh;
extern bool in_planner;
#ifdef __cplusplus
}

View file

@ -1716,6 +1716,8 @@ void MainWindow::setApplicationState(const QByteArray& state) {
return;
currentApplicationState = state;
in_planner = (state == "PlanDive" || state == "EditPlannedDive");
#define SET_CURRENT_INDEX( X ) \
if (applicationState[state].X) { \
ui.X->setCurrentWidget( applicationState[state].X); \