[PATCH] Unify ceiling calculation between Buehlmann and VPM-B

Dirk Hohndel dirk at hohndel.org
Sat Aug 15 04:49:29 PDT 2015


On Wed, Aug 12, 2015 at 12:44:50PM +0200, Robert Helling wrote:
> From cb8aa7d60ba419cb7c0b50276df336557f359b3f Mon Sep 17 00:00:00 2001
> From: "Robert C. Helling" <helling at atdotde.de>
> Date: Wed, 12 Aug 2015 12:06:52 +0200
> Subject: [PATCH] Some unification between Buehlmann and VPM-B
> 
> as a bonus, in VPM-B mode, in the planner, the ceilings are VPM-B ceilings and not GF.

Please remind me, what is missing to be able to show VPM-B ceilings for
logged dives? I remember there was something about the way VPM-B makes
assumptions about remainder of the dive...

> diff --git a/deco.c b/deco.c
> index a801221..7b0aa54 100644
> --- a/deco.c
> +++ b/deco.c
> @@ -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,43 +126,55 @@ static double tissue_tolerance_calc(const struct dive *dive)
>  	double lowest_ceiling = 0.0;
>  	double tissue_lowest_ceiling[16];
>  
> -	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];
> -		buehlmann_inertgas_b[ci] = ((buehlmann_N2_b[ci] * tissue_n2_sat[ci]) + (buehlmann_He_b[ci] * tissue_he_sat[ci])) / tissue_inertgas_saturation[ci];
> +	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];
> +			buehlmann_inertgas_b[ci] = ((buehlmann_N2_b[ci] * tissue_n2_sat[ci]) + (buehlmann_He_b[ci] * tissue_he_sat[ci])) / tissue_inertgas_saturation[ci];
>  
>  
> -		/* tolerated = (tissue_inertgas_saturation - buehlmann_inertgas_a) * buehlmann_inertgas_b; */
> +			/* tolerated = (tissue_inertgas_saturation - buehlmann_inertgas_a) * buehlmann_inertgas_b; */
>  
> -		tissue_lowest_ceiling[ci] = (buehlmann_inertgas_b[ci] * tissue_inertgas_saturation[ci] - gf_low * buehlmann_inertgas_a[ci] * buehlmann_inertgas_b[ci]) /
> -					     ((1.0 - buehlmann_inertgas_b[ci]) * gf_low + buehlmann_inertgas_b[ci]);
> -		if (tissue_lowest_ceiling[ci] > lowest_ceiling)
> -			lowest_ceiling = tissue_lowest_ceiling[ci];
> -		if (!buehlmann_config.gf_low_at_maxdepth) {
> -			if (lowest_ceiling > gf_low_pressure_this_dive)
> -				gf_low_pressure_this_dive = lowest_ceiling;
> +			tissue_lowest_ceiling[ci] = (buehlmann_inertgas_b[ci] * tissue_inertgas_saturation[ci] - gf_low * buehlmann_inertgas_a[ci] * buehlmann_inertgas_b[ci]) /
> +						     ((1.0 - buehlmann_inertgas_b[ci]) * gf_low + buehlmann_inertgas_b[ci]);
> +			if (tissue_lowest_ceiling[ci] > lowest_ceiling)
> +				lowest_ceiling = tissue_lowest_ceiling[ci];
> +			if (!buehlmann_config.gf_low_at_maxdepth) {
> +				if (lowest_ceiling > gf_low_pressure_this_dive)
> +					gf_low_pressure_this_dive = lowest_ceiling;
> +			}
>  		}
> -	}
> -	for (ci = 0; ci <16; ci++) {
> -		double tolerated;
> -
> -		if ((surface / buehlmann_inertgas_b[ci] + buehlmann_inertgas_a[ci] - surface) * gf_high + surface <
> -		    (gf_low_pressure_this_dive / buehlmann_inertgas_b[ci] + buehlmann_inertgas_a[ci] - gf_low_pressure_this_dive) * gf_low + gf_low_pressure_this_dive)
> -			tolerated = (-buehlmann_inertgas_a[ci] * buehlmann_inertgas_b[ci] * (gf_high * gf_low_pressure_this_dive - gf_low * surface) -
> -				     (1.0 - buehlmann_inertgas_b[ci]) * (gf_high - gf_low) * gf_low_pressure_this_dive * surface +
> -				     buehlmann_inertgas_b[ci] * (gf_low_pressure_this_dive - surface) * tissue_inertgas_saturation[ci]) /
> -				    (-buehlmann_inertgas_a[ci] * buehlmann_inertgas_b[ci] * (gf_high - gf_low) +
> -				     (1.0 - buehlmann_inertgas_b[ci]) * (gf_low * gf_low_pressure_this_dive - gf_high * surface) +
> -				     buehlmann_inertgas_b[ci] * (gf_low_pressure_this_dive - surface));
> -		else
> -			tolerated = ret_tolerance_limit_ambient_pressure;
> -
> -
> -		tolerated_by_tissue[ci] = tolerated;
> -
> -		if (tolerated >= ret_tolerance_limit_ambient_pressure) {
> -			ci_pointing_to_guiding_tissue = ci;
> -			ret_tolerance_limit_ambient_pressure = tolerated;
> +		for (ci = 0; ci < 16; ci++) {
> +			double tolerated;
> +
> +			if ((surface / buehlmann_inertgas_b[ci] + buehlmann_inertgas_a[ci] - surface) * gf_high + surface <
> +			    (gf_low_pressure_this_dive / buehlmann_inertgas_b[ci] + buehlmann_inertgas_a[ci] - gf_low_pressure_this_dive) * gf_low + gf_low_pressure_this_dive)
> +				tolerated = (-buehlmann_inertgas_a[ci] * buehlmann_inertgas_b[ci] * (gf_high * gf_low_pressure_this_dive - gf_low * surface) -
> +					     (1.0 - buehlmann_inertgas_b[ci]) * (gf_high - gf_low) * gf_low_pressure_this_dive * surface +
> +					     buehlmann_inertgas_b[ci] * (gf_low_pressure_this_dive - surface) * tissue_inertgas_saturation[ci]) /
> +					    (-buehlmann_inertgas_a[ci] * buehlmann_inertgas_b[ci] * (gf_high - gf_low) +
> +					     (1.0 - buehlmann_inertgas_b[ci]) * (gf_low * gf_low_pressure_this_dive - gf_high * surface) +
> +					     buehlmann_inertgas_b[ci] * (gf_low_pressure_this_dive - surface));
> +			else
> +				tolerated = ret_tolerance_limit_ambient_pressure;
> +
> +
> +			tolerated_by_tissue[ci] = tolerated;
> +
> +			if (tolerated >= ret_tolerance_limit_ambient_pressure) {
> +				ci_pointing_to_guiding_tissue = ci;
> +				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;
>  		}
>  	}

Yet another case where I wish that there was a diff that handled
indentation changes better. It's really hard to see what was actually done
here. :-)

> diff --git a/dive.h b/dive.h
> index 69a0112..d0ef47d 100644
> --- a/dive.h
> +++ b/dive.h
> @@ -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 {
> diff --git a/planner.c b/planner.c
> index 9c0c95f..3c09a61 100644
> --- a/planner.c
> +++ b/planner.c
> @@ -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;

Sure, that's a way to do that. We have way too many global variables that
hold some state like that :-(

You could just as easily have a helper function that queries the state and
is callable from C. That way we only have to keep the actual state once
and can simply access it from the C routines as well.

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

Can you explain this part, please? So with the changes made above
deco_allowed_depth() now works in both VPM-B and Buehlmann mode?
I'm guessing that's the side effect of adjusting tissue_tolerance_calc()
but it would be nice to have that explicitly explained in the commit
message.

> diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
> index db1d8c8..f22884a 100644
> --- a/qt-ui/mainwindow.cpp
> +++ b/qt-ui/mainwindow.cpp
> @@ -1716,6 +1716,8 @@ void MainWindow::setApplicationState(const QByteArray& state) {
>  		return;
>  
>  	currentApplicationState = state;
> +	in_planner = (state == "PlanDive" || state == "EditPlannedDive");
> +

OK, admittedly that should keep things in sync. Still, it seems rather
awkward to me.


/D


More information about the subsurface mailing list