Commit graph

312 commits

Author SHA1 Message Date
Robert C. Helling
1c7bc14af9 Don't do a negative time step in recreational mode when beyond NDL
In recreational mode, we keep adding time at the last depth
until an ascent does violate the ceiling. Then we roll back
the last added time step and record the ascent. The test for
the ceiling violated was before adding the time so if it alreay
failed the first time we tried to unroll a time step that was
never added which resulted in a small kink in the pressure graph.

This patch corrects this logic by changin a while to a do {} while.

Furthermore, it removes the computation of deco state during the
final ascent since that is not used anywhere later.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-12 13:46:51 -07:00
Rick Walsh
26cab60518 Revert "VPM-B restore deco state before calculating next gradient"
This reverts commit 3d8e5b638a.

Calculating the next gradient should be based on the tissue loading at the end
of the previous iteration, so it was wrong to restore the deco state first.
This has a tiny affect on the calculated profile, and makes one of the tests
fail.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-04 13:45:32 +01:00
Dirk Hohndel
ae854ff822 Remove pointless assignment
In every code path stopping is overwritten before it is ever accessed.

Coverity CID 1325278

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-02 17:41:02 -04:00
Dirk Hohndel
12c83b744e Avoid possible uninitialized memory read
This looks like possibly a false positive in the Coverity scan, but we can
always assume that the first point of the dive plan has been entered by
the user.

Coverity CID 1325285

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-01 21:11:59 -04:00
Dirk Hohndel
b41773734b Avoid resource leak
Coverity CID 1325288

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-01 21:11:23 -04:00
Lubomir I. Ivanov
03b2674a13 planner.c: fix missing brances warning
for a 'struct gasmix' initialization, the 'permille' value
from franction_t should have it's own braces.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-23 09:15:10 -07:00
Lubomir I. Ivanov
a3421a08f0 planner.c: fix warnings about unused variables
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-23 09:14:59 -07:00
Rick Walsh
899427079e VPMB: Reset ceiling pressures at start of planned dive
We do not want to remember max_bottom_ceiling_pressure from the previous planned
dive - it makes the Boyle's law compensation incorrect if the previous planned
dive was a deeper deep-to-shallow multi-level dive.

E.g. Plan these dives (without applying this patch) with VPM-B nominal
conservatism:
	Plan 30 m for 20 min (total run time = 28 min)
	Now plan 100 m for 20 min, followed by 70 m @ 23 min and 70 m at 30 min
	Re-plan 30 m for 20 min (total run time = 50 min)

With this change, the re-planned dive run time is 28 min, as it should be.

We probably don't have to reset first_ceiling_pressure too, but it's cleaner if
we do.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-20 08:00:09 -07:00
Rick Walsh
3d8e5b638a VPM-B restore deco state before calculating next gradient
The next gradient calculation at the start of the CVA loop should be performed
using the tissue loading before starting the iterations, rather than the loading
at the end of the previous iteration.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-16 21:16:58 -07:00
Salvador Cuñat
9fd7fc8b45 Use Bühlmann in all strings shown to the user
Unify spelling of this name in strings shown to the user, as commented
in mailing list. Internal coding use untouched.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-16 21:16:58 -07:00
Robert C. Helling
4a19145e04 Use the correct setpoint in planner
There is an unfortunate convention that the sample structure contains a setpoint
at its end rather than during its duration which causes the expression
sample[-1].setpoint in several places. This adds another one for the planner
to use the correct setpoint during the manually entered leg of the dive.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-15 07:07:19 -07:00
Rick Walsh
304edb63ce VPM-B: Calculate ceiling in deepest portion of dive
The Boyle's law compensation compares the ambient pressure to a baseline value,
and adjusts the theory bubble radius accordingly.  Currently we use the ceiling
at the last user-entered waypoint (the start of the decompression phase) as the
baseline value.  However, in a deep to shallow multi-level dive, decompression
can start earlier, and taking a shallower ceiling leads to a more aggressive
ascent.  This is particularly noticeable if the user enters stops during ascent.

With this commit, we take the baseline ambient pressure for Boyle's law
compensation as the deeper of the:
(1) Ceiling prior to ascending during a user-entered portion of the dive, and
(2) Ceiling at the start of the last user-entered waypoint.

This makes the calculated profile more conservative for some deep to shallow
multi-level dives.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-12 08:20:10 -07:00
Rick Walsh
bc3a2ff89b Planner notes: Show VPM-B conservatism
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-07 17:26:55 -07:00
Robert C. Helling
e32896c2bc Introduce double depth_to_bar()
as it leads to significant cleanup.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-31 15:18:40 -07:00
Robert C. Helling
bd8126a709 Calculate ceiling only when it is needed
So far, add_segment() returned a tissue tolerance (i.e. ceiling)
computed just in its return statement. This tissue_tolerance
needed to be dragged around until it was needed or be dropped
if not needed at all.

As for VPM-B, this ceiling computation is a bit expensive, this patch
calls the computation function tissue_tolerance_calc() when the
value is actually needed and not before.

This changes the signature of some functions.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-31 15:17:39 -07:00
Robert C. Helling
d9306125d9 Do the Boyle compensation when the gradient is needed
and not some time before and store the result in a global variable.

This stores only the bottom gradients and computes the Boyle compensation
when computing the allowed ambient pressure.

As the Boyle compensation needs a reference ambient pressure, to find the ceiling,
we have to iterate this computation until the reference pressure is close enough to
the ceiling.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-31 15:15:19 -07:00
Rick Walsh
4a9433864e VPM-B: Don't break the ceiling due to ongassing on ascent
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-29 20:06:53 -07:00
Rick Walsh
e2178c0e55 VPM-B: Remove obsolete first_ceiling_pressure calculation
We now do the first_ceiling_pressure calculation at the start of the CVA loop.
We don't need to do it before.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-29 20:06:49 -07:00
Rick Walsh
27ba48a09e Planner: Change where we clear deco and reset gradients
We should run clear_deco as early as we can.  We should calculate the nuclear
regeneration and start gradient after calculating tissue tolerance.  We don't
need to redo nuclear regeration and start gradient after that.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-29 20:06:46 -07:00
Rick Walsh
2d45e587ba VPM-B: Calculate crushing pressure on descent
By calculating crushing pressure after the manually entered phase, we were doing
it wrong for multi-level dives.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-29 20:06:43 -07:00
Robert C. Helling
c5f92c7501 Rename variable to better reflect what it does
The pressure for the Boyle compensation is of the first ceiling,
i.e. the ceiling seen from the bottom rather than the first
stop.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-27 07:03:53 -07:00
Robert C. Helling
fe00abc774 Compute first stop pressure for each round of CVA
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-27 07:03:41 -07:00
Robert C. Helling
41349c29dd Prepare global state of VPM-B when starting to plan
Otherwise, the results of the calculations tend to be rather
random and irreproducible...

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-23 07:30:23 -07:00
Rick Walsh
634e698664 VPM-B: Calculate first_stop_pressure before starting ascent
The Boyle's law compensation depends on first_stop_pressure.  To produce
profiles similar to other VPM-B implementations, we should calculate it as the
ceiling before starting the ascent.

Commit 159c9eb2c1, Compare ceiling to next stop
rather than try to ascent for VPM-B, changed (VPM-B) to consider the current
ceiling rather than an incremental ascent between one stop level and the next.
However, the initial ascent generally steps through several stop levels, so
first_stop_pressure was still not calculated as the ceiling prior to commencing
the calculated ascent.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-23 07:21:17 -07:00
Dirk Hohndel
c7d8e72607 Use our pressure type to avoid bar / mbar confusion
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-21 10:16:06 -07:00
Robert C. Helling
0bb65a17cb Use boyle_compensation in profile
otherwise VPM-B planned profiles seem to violate the ceiling. This needs
the first_stop_pressure to be available also in the profile, so I made
it global in planner.c

Important lesson: If you want to use deco_allowed_depth on a tissue_tolerance
that comes from a VPM-B planned dive, you have to call boyles_law() before
add_segment()!

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-20 07:28:00 -07:00
Robert C. Helling
72806e42bc Replace global in_planner variable by helper function
as promised earlier

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-18 06:42:01 -07:00
Robert C. Helling
4e89a6020e Get rid of is_ok_vpmb
Since a8ce8, that made deco_allowed_depth work for VPM-B as well, this
function became obsolete but was reintroduced by one of Jan's latest patches.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-18 06:40:50 -07:00
Robert C. Helling
159c9eb2c1 Compare ceiling to next stop rather than try to ascent for VPM-B
For VPM-B, to stay within the reference implementation, to decide if we
need to stop we check if the current ceiling is above the next stop depth
rather than trying to ascent and check if we violate a ceiling. This
leads to more conservative profiles.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-18 06:40:45 -07:00
Dirk Hohndel
f2b883865c Revert "Pref. to ascent to next stop only when stop is below ceiling"
This reverts commit a6ed36fb73.
2015-08-18 06:40:35 -07:00
Jan Darowski
39794d3478 VPM-B: Fix calculating Boyles compensation on gas change stops.
Previously we were calculating the compensation only on the deco
stops, gas change stops appearing before the first deco stop were
ommited.

Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-18 06:34:54 -07:00
Robert C. Helling
a6ed36fb73 Pref. to ascent to next stop only when stop is below ceiling
Usually, we try to ascent to the next stop and check if we break the
ceiling while doing that. This patch adds a preference value to rather
check if the ceiling is above the next stop before attempting to ascent.

The difference if off-gasing during the ascent is taken into account.

Logically, it does not sound like it could be relevant to ignore that
off-gasing but it leads to more conservative schedules and it seems
the original Fortran VPM-B implementation does just this. So one could
argue it is part of that model (if it makes sense or not), so we should
at least give users the possibility to turn this on.

Maybe we should even make this the default for VPM-B.

This patch just addes the code to have the value in the preferences and
the planner to act accordingly. There is no UI for it, yet. To test, you
have to set it in the code. There could be a later patch with a UI if people
like to have it.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-17 21:58:09 -07:00
Dirk Hohndel
d93984448c Merge branch 'boyle-ready' of https://github.com/Slagvi/subsurface
Fixed merge conflicts in
	deco.c
	dive.h
	planner.c

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-17 21:45:51 -07:00
Robert C. Helling
a8ce8c3ef1 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>
2015-08-15 09:10:29 -07:00
Jan Darowski
499ec9af2f VPM-B: Add surface decompression time.
Now, we calculate the volume of free gas not only based on the deco
time but also time on the surface, needed for the full desaturation.

Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-08-15 14:32:36 +02:00
Jan Darowski
c0fde4f50f VPM-B: Add Boyles compensation to the planner.
Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-08-15 14:21:18 +02:00
Jan Darowski
a3e87bf1a1 VPM-B: Fix trial_ascent() for vpm-b.
Previously, current depth was checked, instead of the depth after the move.

Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-08-15 13:45:42 +02:00
Lubomir I. Ivanov
342479586d Planner: use the heap for note buffers
The default stack size on Windows per thread is 1024kb.
Using the heap prevents a stack overflow in add_plan_to_notes().

The alternative is to tell the linker to use N bytes of stack:
-Wl,--stack,N

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-10 00:04:17 -07:00
Robert C. Helling
e79cae577d Decrease gaschange index even if we are already breathing the new mix
This fixes a bug where we would not do any gas changes at all if at the end of
bottom time we were deeper than the MOD of the bottom mix. Instead we would
constantly try to switch to that gas and find we are already breathing it.

A test case would be a dive with air and EAN50 to more than 66m. That would
have never switched to EAN50.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-03 22:23:17 -07:00
Rick Walsh
87c35e19e2 Planner: Add comments to document the code
The purpose of parts of the planner code is not not always obvious.  This is
especially true of the conditional statements in the add_plan_to_notes function.
Annotate the code with comments to explain the logic.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-27 06:31:30 -07:00
Dirk Hohndel
72e6c52b06 Remove bogus fix
In commit 156ad42a3c ("snprintf is happier if it has an explicit string
literal format argument") I got a little too aggressive making sure there
are string literal format strings...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:06 -07:00
Rick Walsh
4d3cefc70b Planner: Add parentheses to output condition
Aids reading the code, doesn't alter the logic.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:06 -07:00
Rick Walsh
90d15c20c4 Planner: Count the minimum stop time towards o2time
When doing backgas breaks, count the minimum stop time towards o2time.
Previously, the initial minimum stop wasn't counted, so the time of the first
segment on oxygen was min_switch_duration + 12 minutes.

E.g. with 1 minute minimum switch duration.

Previously:
depth   duration        runtime gas
40m     1min    1min    air
40m     34min   35min
21m     2min    37min
21m     1min    38min   EAN50
18m     1min    39min
15m     3min    42min
12m     4min    46min
9m      5min    51min
6m      13min   64min   oxygen	<--13 minutes on O2
6m      6min    70min   air
6m      2min    72min   oxygen
0m      1min    73min

Now:
depth	duration	runtime	gas
40m	1min	1min	air
40m	34min	35min	 
21m	2min	37min	 
21m	1min	38min	EAN50
18m	1min	39min	 
15m	3min	42min	 
12m	4min	46min	 
9m	5min	51min	 
6m	12min	63min	oxygen
6m	6min	69min	air
6m	2min	71min	oxygen
0m	1min	72min	 

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:06 -07:00
Rick Walsh
4f05622846 Planner: Hide unwanted transition between deco stops
If display transitions in deco isn't selected, then we shouldn't show the
transition segment between two deco stops, even if there is a gas change.  We
should still show the ascent segment up to the first deco stop.  The
(gaschange_after && !isascent) condition is necessary to pick up backgas breaks.
An example plan is shown below.

Previously:
depth	duration	runtime	gas
40m	1min	1min	air
40m	34min	35min	 
21m	2min	37min	 	<--meaningful ascent segment
21m	1min	38min	EAN50
18m	1min	39min	 
15m	3min	42min	 
12m	4min	46min	 
9m	5min	51min	 
6m	0min	51min	 	<--unnecessary ascent segment
6m	13min	64min	oxygen
6m	6min	70min	air
6m	2min	72min	oxygen
0m	1min	73min	 

depth	duration	runtime	gas
40m	1min	1min	air
40m	34min	35min	 
21m	2min	37min	 	<--meaningful ascent segment
21m	1min	38min	EAN50
18m	1min	39min	 
15m	3min	42min	 
12m	4min	46min	 
9m	5min	51min	 
6m	13min	64min	oxygen
6m	6min	70min	air
6m	2min	72min	oxygen
0m	1min	73min	 

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:06 -07:00
Rick Walsh
1885eccc49 Planner: use pointer to deco stop level array instead of memcpy
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:06 -07:00
Rick Walsh
036e992d14 Planner: Change 3m stop to zero if last stop is 6m
When the last stop at 6m/20ft option is selected, replace the 3m/10ft stop with
zero depth, rather than doubling up on the 6m/20ft stop.  This removes the need
to differentiate between 6m (=6000mm) and 20ft (=6096mm) and saves calling a
helper function.  It does not alter the calculated profile at all.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:05 -07:00
Dirk Hohndel
156ad42a3c snprintf is happier if it has an explicit string literal format argument
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-25 13:43:44 -07:00
Rick Walsh
361ddd9634 Planner: correct output of planner mode
Previously we used strncat to output VPM mode without correctly defining the
length of the string, and didn't do anything for recreational mode.  This
resulted in the output being junk recycled from the previous temp string.

We could use strncat if the string length were defined, but using snprintf will
make it simpler to include the VPM conservatism when that has been implemented.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-23 08:12:29 -07:00
Joakim Bygdell
ff6bf497c8 Planner: update disclamer
Update the disclamer text to reflect which algorithm where used.

[Dirk Hohndel: cleaned up coding style & replaced snprintf with strncat]

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-08 06:52:02 -07:00
Dirk Hohndel
b1538c809d Code cleanup
Make precedence of && over || explicit.
Explicitly convert between char * and unsigned char *.
Don't assign potentially negative return code to an unsigend variable.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-06 13:59:14 -07:00