mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
VPMB profile: use bottom_time to calculate deco_time in planner
This corrects the issue where the displayed ceiling in the profile was "broken" by the planner, especially for shorter and shallower dives. Also fixes issue outside of planner where the deepest VPM-B ceiling was shown too early, messing up the deco_time calculation. VPM-B plans respond to change in O2% in gas as expected (in my testing) Fixes: #630 Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
This commit is contained in:
parent
d470ef05e0
commit
04383e27e5
2 changed files with 24 additions and 13 deletions
|
@ -31,6 +31,7 @@ static struct plot_data *last_pi_entry_new = NULL;
|
|||
void populate_pressure_information(struct dive *, struct divecomputer *, struct plot_info *, int);
|
||||
|
||||
extern bool in_planner();
|
||||
extern int bottom_time;
|
||||
|
||||
#ifdef DEBUG_PI
|
||||
/* debugging tool - not normally used */
|
||||
|
@ -954,19 +955,25 @@ static void calculate_ndl_tts(struct dive *dive, struct plot_data *entry, struct
|
|||
*/
|
||||
void calculate_deco_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode)
|
||||
{
|
||||
int i, count_iteration = 0;
|
||||
int i, count_iteration = 0, deco_time;
|
||||
double surface_pressure = (dc->surface_pressure.mbar ? dc->surface_pressure.mbar : get_surface_pressure_in_mbar(dive, true)) / 1000.0;
|
||||
bool first_iteration = true;
|
||||
int deco_time = 0, prev_deco_time = 10000000;
|
||||
int prev_deco_time = 10000000, time_deep_ceiling = 0;
|
||||
if (in_planner())
|
||||
deco_time = pi->maxtime - bottom_time;
|
||||
else
|
||||
deco_time = 0;
|
||||
struct deco_state *cache_data_initial = NULL;
|
||||
/* For VPM-B outside the planner, cache the initial deco state for CVA iterations */
|
||||
if (decoMode() == VPMB && !in_planner())
|
||||
if (decoMode() == VPMB) {
|
||||
cache_deco_state(&cache_data_initial);
|
||||
}
|
||||
/* For VPM-B outside the planner, iterate until deco time converges (usually one or two iterations after the initial)
|
||||
* Set maximum number of iterations to 10 just in case */
|
||||
while ((abs(prev_deco_time - deco_time) >= 30) && (count_iteration < 10)) {
|
||||
int last_ndl_tts_calc_time = 0, first_ceiling = 0, current_ceiling, last_ceiling, final_tts = 0 , time_clear_ceiling = 0, time_deep_ceiling = 0;
|
||||
deco_state->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
|
||||
int last_ndl_tts_calc_time = 0, first_ceiling = 0, current_ceiling, last_ceiling, final_tts = 0 , time_clear_ceiling = 0;
|
||||
if (decoMode() == VPMB)
|
||||
deco_state->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
|
||||
struct gasmix *gasmix = NULL;
|
||||
struct event *ev = NULL;
|
||||
|
||||
|
@ -1001,9 +1008,9 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
|
|||
if (decoMode() == VPMB && last_ceiling >= first_ceiling && first_iteration == true) {
|
||||
nuclear_regeneration(t1);
|
||||
vpmb_start_gradient();
|
||||
/* For CVA calculations, start by guessing deco time = dive time remaining */
|
||||
deco_time = pi->maxtime - t1;
|
||||
vpmb_next_gradient(deco_time, surface_pressure / 1000.0);
|
||||
/* For CVA iterations, calculate next gradient */
|
||||
if (!first_iteration || in_planner())
|
||||
vpmb_next_gradient(deco_time, surface_pressure / 1000.0);
|
||||
}
|
||||
entry->ceiling = deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_bar(entry->depth, dive)), surface_pressure, dive, !prefs.calcceiling3m);
|
||||
if (prefs.calcceiling3m)
|
||||
|
@ -1011,9 +1018,10 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
|
|||
else
|
||||
current_ceiling = entry->ceiling;
|
||||
last_ceiling = current_ceiling;
|
||||
/* If using VPM-B outside the planner, take first_ceiling_pressure as the deepest ceiling */
|
||||
/* If using VPM-B, take first_ceiling_pressure as the deepest ceiling */
|
||||
if (decoMode() == VPMB) {
|
||||
if (current_ceiling > first_ceiling) {
|
||||
if (current_ceiling >= first_ceiling ||
|
||||
time_deep_ceiling == t0 && entry->depth == (entry - 1)->depth) {
|
||||
time_deep_ceiling = t1;
|
||||
first_ceiling = current_ceiling;
|
||||
deco_state->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
|
||||
|
@ -1021,7 +1029,8 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
|
|||
nuclear_regeneration(t1);
|
||||
vpmb_start_gradient();
|
||||
/* For CVA calculations, start by guessing deco time = dive time remaining */
|
||||
deco_time = pi->maxtime - t1;
|
||||
if (!in_planner())
|
||||
deco_time = pi->maxtime - t1;
|
||||
vpmb_next_gradient(deco_time, surface_pressure / 1000.0);
|
||||
}
|
||||
}
|
||||
|
@ -1083,7 +1092,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru
|
|||
count_iteration ++;
|
||||
restore_deco_state(cache_data_initial, true);
|
||||
} else {
|
||||
// With Buhlmann, or not in planner, iterating isn't needed. This makes the while condition false.
|
||||
// With Buhlmann iterating isn't needed. This makes the while condition false.
|
||||
prev_deco_time = deco_time = 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue