Commit graph

14 commits

Author SHA1 Message Date
Robert C. Helling
4c13f1f6b4 Adjust GFlow to apply at deepest ceiling instead of at max depth
This moves the point where GF_low applies up which implies that at all
shallower depth (i.e. during deco) a lower GF results which makes the deco
longer compared to the previous implementation.

Of course, "GF_low" applies at first deco stop is a bit tricky since the
depth of the first deco stop again depends on GF_low, i.e. there is
another equation to solve. You can do this by inverting the equation for
the ambient pressure and use GF_low as the gradient factor. This yields

amb = (b * M_value_corrected - GF_low * a * b) / ((1-b) * GF_low + b)

Signed-off-by: Robert C. Helling helling@atdotde.de
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10 09:14:55 -08:00
Dirk Hohndel
f5b62c0356 Undo unintentional change to deco.c
In commit d163a68ac69e "Clean up the rewritten deco.c" I apparently made
one more change than I intended - I changed the last deco stop back to 3m
instead of allowing the smooth mode to go all the way back to 0 without
any discrete steps.

This fixes that mistake.

Reported-by: Robert C. Helling <helling@lmu.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08 14:28:44 -08:00
Dirk Hohndel
77f4802ed6 Minor cleanups
Coding style in deco.c.
Unneccessary if clause in profile.c (the loop starts with i = 1)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08 13:47:01 -08:00
Dirk Hohndel
fc8b37d86b Clean up the rewritten deco.c
In commit a7902f279a57 "Rewrite of the deco code" Robert kept the old code
that he replaced around; I removed all that as it's in the git history if
we ever need to look at it again but doesn't really help us in the file as
it is.

I also removed constants, variables and config parameters that aren't used
in the new implementation and did some coding style / formatting changes
to make deco.c more consistent with the rest of Subsurface. I also updated
the comments at the top of the file to reflect reality.

I did one change that actually affects the code. In the explanation of his
changes Robert said that gf_low_pressure_this_dive is initialized to the
exquivalent of 20m, yet his code added the surface pressure twice. I
decided to change the default config value from 3 (bar) to 2 so that this
indeed reflects (about) 20m (as in the code below surface_pressure is
added to this value).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08 09:33:47 -08:00
Robert C. Helling
67d59ff018 Rewrite of the deco code
o) Instead of using gradient factors as means of comparison, I now use
   pressure (as in: maximal ambient pressure).

o) tissue_tolerance_calc() now computes the maximal ambient pressure now
   respecting gradient factors. For this, it needs to know about the
   surface pressure (as refernce for GF_high), thus gets *dive as an
   argument. It is called from add_segment() which this also needs *dive
   as an additional argument.

o) This implies deco_allowed_depth is now mainly a ambient-pressure to
   depth conversion with decorations to avoid negative depth (i.e. no deco
   obliation), implementation of quantization (!smooth => multiples of 3m)
   and explicit setting of last deco depth (e.g. 6m for O2 deco).

o) gf_low_pressure_this_dive (slight change of name), the max depth in
   pressure units is updated in add_segment. I set the minimal value in
   buehlmann_config to the equivalent of 20m as otherwise good values of
   GF_low add a lot of deco to shallow dives which do not need deep stops
   in the first place.

o) The bogus loop is gone as well as actual_gradient_limit() and
   gradient_factor_calculation() and large parts of deco_allowed_depth()
   although I did not delete the code but put it in comments.

o) The meat is in the formula in lines 147-154 of deco.c. Here is the
   rationale:

   Without gradient factors, the M-value (i.e the maximal tissue pressure)
   at a given depth is given by ambient_pressure / buehlmann_b + a.

   According to "Clearing Up The Confusion About "Deep Stops" by Erik C.
   Baker (as found via google) the effect of the gradient factors is no
   replace this by a reduced affine relation (i.e. another line) such that
   at the surface the difference between M-value and ambient pressure is
   reduced by a factor GF_high and at the maximal depth by a factor
   GF_low.

   That is, we are looking for parameters alpha and beta such that

   alpha surface + beta = surface + gf_high * (surface/b + a - surface)

   and

   alpha max_p + beta = max_p + gf_low * (max_p/b + a - max_p)

   This can be solved for alpha and beta and then inverted to obtain the
   max ambient pressure given tissue loadings. The result is the above
   mentioned formula.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08 08:59:20 -08:00
Dirk Hohndel
e47e37e5a6 Add bailout code to prevent infinite loop in deco calculation
This appears to happen if we have impossible dive sequences in the
dive_list (i.e., merging XML files from two different divers with
overlapping trips).

We need to fix the underlying cause for this issue (i.e., only pick the
'right' dives to calculate the residual tissue saturation), but at least
this code prevents the hang in an infinite loop.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07 13:50:53 -08:00
Dirk Hohndel
c8830ffe48 Add the ability to cache our deco state
We kept reduing all the deco calculations, including the previous dives
(if any) for each segment we add to the dive plan. This simply remembers
the last stage and then just adds to that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 11:40:21 -08:00
Dirk Hohndel
641c0d252b Fix bug in smooth ceiling mode
The ceiling calculations for the gradient factors still had a 3m increment
hardcoded. This is now also conditional on the smooth parameter.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-05 10:06:14 -08:00
Dirk Hohndel
d87a606039 Correctly handle air in the deco code
We mark air with o2.permille = 0. But it's actually 20.9% O2.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04 23:09:04 -08:00
Dirk Hohndel
6dc247ff78 Fix deco calculations to correctly use GF values and add CC support
The old implementation was broken in several ways.

For one thing the GF values are percentages, so they should normally be
0 < GF < 1 (well, some crazy people like to go above that).

With this most of the Bühlmann config constants were wrong.

Furthermore, after we adjust the pressure tolerance based on the gradient
factors, we need to convert this back into a depth (instead of passing
back the unmodified depth - oops).

Finally, this commit adds closed circuit support to the deco calculations.

Major progress and much more useful at this stage.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04 11:13:14 -08:00
Dirk Hohndel
9cd18c43aa Make GF values configurable
There are a couple of issues with this commit:

GtkEntry should emit the 'changed' signal when it is modified (so that
changes in the preferences get applied right away) - but that doesn't
appear to be working consistently.

Also, this doesn't appear to affect the deco of any dives that I try it
with. So my guess is something is wrong with the underlying deco
algorithm. That's diappointing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 21:41:35 -08:00
Dirk Hohndel
2c33603256 Consider previous dives when calculating deco
This also initializes the N2 tissue saturations to correct numbers
(setting them to zero was clearly silly).

With this commit we walk back in the dive_table until we find a surface
intervall that's longer than 48h. Or a dive that comes after the last one
we looked at; that would indicate that this is a divelist that contains
dives from multiple divers or dives that for other reasons are not
ordered. In a sane environment one would assume that the dives that need
to be taken into account when doing deco calculations are organized as one
trip in the XML file and so this logic should work.

One major downside of the current implementation is that we recalculate
everything whenever the plot_info is recreated - which happens quite
frequently, for example when resizing the window or even when we go into
loup mode. While this isn't all that compute intensive, this is an utter
waste and we should at least cache the saturation inherited from previous
dives (and clear that number when the selected dive changes). We don't
want to cache all of it as the recreation of the plot_info may be
triggered by the user changing equipment (and most importantly, gasmix)
information. In that case the deco data for this dive does indeed have to
be recreated. But without changing the current dive the saturation after
the last surface intervall should stay the same.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 20:45:20 -08:00
Dirk Hohndel
5ba250bd48 Use gradient factors in deco calculation
Usually dive computers show the ceiling in terms of the next deco stop -
and those are in 3m increments. This commit also adds the ability to chose
either the typical 3m increments or the smooth ceiling that the Bühlmann
algorithm actually calculates.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 20:44:37 -08:00
Dirk Hohndel
3c31d0401d First stab at deco calculations
This seems to give us roughly the right data but needs a lot more testing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-03 20:43:14 -08:00