Commit graph

52 commits

Author SHA1 Message Date
Berthold Stoeger
642d9c80b3 planner: pass in_planner argument to decoMode()
To remove reliance on global state, pass an "in_planner" argument
to decoMode(). Thus, calls to in_planner() can be removed.

This is a more-or-less automated change. Ultimately it would
probably be better to pass the current deco-mode to the affected
functions instead of calling decoMode() with an in_planner
parameter.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
03a7e65cf0 planner: pass in_planner argument to clear_deco()
To remove reliance on global state, pass an "in_planner" argument
to clear_deco(). Thus, calls to in_planner() can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
8103e947aa planner: pass in_planner argument to vpmb_next_gradient()
To remove reliance on global state, pass an "in_planner" argument
to vpmb_next_gradient(). Thus, calls to in_planner() can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
93ecad1b04 planner: pass in_planner argument to add_segment()
To remove reliance on global state, pass an "in_planner" argument
to add_segment(). Thus, calls to in_planner() can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
34730b898b core: make gas type enum globally available
The deco-routines used an enum to pass around the inert gas
type. Make that globally available and make it include O2.
This will be used in a future commit to generalize access
of gas fractions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03 10:29:15 -07:00
Berthold Stoeger
33b4ecf055 cleanup: move the inertgas enum from qthelper.hpp to deco.c
There are no outside users.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 00:22:31 +02:00
Berthold Stoeger
123937901f planner: remove Bühlmann factor cache
The Bühlmann factors were cached in a thread-safe hashmap. It seemed
somewhat dubious that entering a critical section and doing a hash-lookup
would be significantly faster than a simple exp() call.

Indeed, in a very cache friendly test (16 entries, tight loop) calling the
factor() function 32 000 000 times from a different translation units we get:
  - with cache: 604 ms
  - without cache: 266 ms
Therefore, remove the cache. Given that 32 000 000 calls take only 266 ms,
it appears not sensible to try to optimize this function anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 00:22:31 +02:00
Berthold Stoeger
ddff68ddae Parser: remove global state
The parser had global state in the form of a linear regression
and the "plot_depth" variable. Collect that in the deco_state struct and
pass it down the call-chain. Move out the code to update the
regression data to not bother other callers of tissue_tolerance_calc().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-08-08 16:26:31 -07:00
Berthold Stoeger
52e5d9c605 Cleanup: move planner/deco related declarations planner/deco.h
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:31 -07:00
Berthold Stoeger
594d1d3514 Cleanup: move file-related function declarations to file.h
A number of architecture-dependent functions were declared in
dive.h. Move them to file.h so that not all file-manipulating
translation units have to include dive.h. This is a small step
in avoiding mass-recompilation on every change to dive.h

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:31 -07:00
Berthold Stoeger
5da09a21bb Cleanup: move error reporting function declarations to errorhelper.h
Move the declarations of the "report_error()" and "set_error_cb()"
functions and the "verbose" variable to errorhelper.h.
Thus, error-reporting translation units don't have to import the
big dive.h header file.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:30 -07:00
Berthold Stoeger
821f68550d Cleanup: make local variables and functions in deco.c static
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Dirk Hohndel
2feedf46fa Cleanup: small coding style fixes
And addressing a cut and paste error in a comment.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-05-15 07:42:14 -07:00
Berthold Stoeger
9ed5cf16a4 Coding style: remove Java-style function definition
Remove a few cases of
	void fun() {
		...
	}

While touching these functions, fix a few other whitespace
coding style violations.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Dirk Hohndel
2d26300402 Core: cast before multiplication to avoid potential overflow
Found via LGTM.com

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-03-17 15:11:31 -07:00
Linus Torvalds
a2028cd6ef deco: _really_ make sure the deco state is fully initialized
I incorrectly thought that 'ci_pointing_to_guiding_tissue' was the only
missing initialization, because that is the only one valgrind pointed at.

... that is, until I started looking at a few more dives, which showed
that there were other parts tht weren't initialized either, like

        double tolerated_by_tissue[16];
        double tissue_inertgas_saturation[16];
        double crushing_onset_tension[16];            // total inert gas tension in the t* moment

so just make sure to clear the whole data structure, to avoid any random
behavior due to uninitialized deco state.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-15 20:57:25 -04:00
Linus Torvalds
193a7d3a56 deco: make sure deco state is fully initialized
This shouldn't have caused any issues, but it made for valgrind noise. So fix it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-15 21:21:05 +02:00
Berthold Stoeger
605e1e19ed Cleanup: const-ify functions taking pointers to events
This is another entry in the series to make more things
"const-clean" with the ultimate goal of merge_dive() take
const pointers.

This concerns functions taking pointers to events and
the fallout from making these const.

The somewhat debatable part of this commit might be
that get_next_event() is split in a two distinct
(const and non-const) versions with different names,
since C doesn't allow overloading. The linker should
recognize that these functions are identical and remove
one of them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23 05:16:38 -07:00
Berthold Stoeger
360f07e453 Cleanup: pass gasmix by value
In a previous commit, the get_gasmix_* functions were changed to
return by value. For consistency, also pass gasmix by value.

Note that on common 64-bit platforms struct gasmix is the size
of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the
same space on the stack. On 32-bit platforms, the stack use
is probably doubled, but in return a dereference is avoided.

Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an
invasive change that going back to pointers is probably the
least of our worries.

This commit is a step in const-ifying input parameters (passing
by value is the ultimate way of signaling that the input parameter
will not be changed [unless there are references to said parameter]).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23 05:16:38 -07:00
jan Iversen
061be82e31 core: replace (void) with UNUSED(x) and include ssrf.h
Unused parameters in C are "silenced" by adding UNUSED(x)

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-24 08:34:14 -07:00
Robert C. Helling
969dfee9ec Rename enum dive_comp_type to divemode_t
...as the usuage is not anymore about a computer but
a momentary dive mode. Rename the end indicator as well.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14 23:47:00 +03:00
Willem Ferguson
27a0542220 Implement bailout outside of the dive planner
This is the second step for implementing bailout. The indirect
calls to fill_pressures through add_segment() (in deco.c) are
addressed. Bailout is now fully implemented in the dive log but
not in the dive planner.
1) The parameters to add_segment() are changed to take a
   divemode as the second last parameter, and not a *dive.
2) Call to add_segment() in profile.c and in divelist.c are
   adapted. In divelist.c some calls to add_segment were left
   using dc-> divemode instead of possible bailout. This appears
   tp be the most appropriate route.
3) The functions get_divemode_from_time() and get_next_divemodechange()
   in dive.c have had some small changes.
4) The calls to get_segment(0 in planner.c were changed to reflect
   the new parameter list, but not updated to reflect bailout. This
   is the next step.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Dirk Hohndel
d577467f97 Core: introduce new subsurface-string header
First small step to shrinking dive.h.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Robert C. Helling
ece714556f Look for actual isobaric counter diffusion
Identify segements that fullfill the folllowing criteria for
the leading compartment:

He is off-gasing while N2 is on-gasing
Overall there is on-gasing

Add a line to the info box for those segments

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-04-11 21:15:38 +02:00
Berthold Stoeger
cd5e17cf79 Cleanup: Unify qthelper.h and qthelperfromc.h
Since all qt-helpers are defined in qthelper.cpp, there seems to be
no reason to have two include files. By unifying the two files,
duplication and inconsistencies are removed. The C++-only part is
simply compiled away with #ifdefs.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-26 19:06:02 +02:00
Robert C. Helling
ca38644005 Prevent overflow in effective GF calculation
For deep dives with long deco, the sum of deco stops could
overflow. This is prevent by turning it into long.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-25 19:47:45 +01:00
Stefan Fuchs
337f82c876 Code cleanup: Indentation mistake plus simplification
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-24 00:01:39 +01:00
Robert C. Helling
c38e0f225f Remove unnecessary #include and correct whitespace
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Stefan Fuchs
4e36b2509c Compile dump_tissues function only if needed based on define
Compile it only when DECO_CALC_DEBUG is defined.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-27 22:40:16 +01:00
Robert C. Helling
8e21a65653 Localize global planner state
For UI responsiveness, we need to be able to run the planner in the background. This needs the
planner state to be localized (and we need to pass a pointer around).

In order to not let too many lines overrun (and to save typing in the future)
I have renamed instances of struct deco_state to ds. Yes this should have gone
to a separate commit but I accidentally commit --amend'ed it.

Computing of planner variations is temporarily disabled.

Unlock the planner when returning early

So we don't deadlock in add dive and recreational mode (which
use the planner without actually planning).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25 20:13:01 +01:00
Robert C. Helling
1f50485732 More VPMB state in special structure
... and reset deco information in profile ceiling computation.

The planner test then needs to know about the struct holding the deco
state.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-01 23:58:55 +03:00
Robert C. Helling
5b080bedde Remove option to apply GFlow at maxdepth
This option should have never been there. This is not how
gradient factors are supposed to work. It would only trick
users to use the wrong value..

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-09-20 08:54:41 -07:00
Stefan Fuchs
6a4b44a3d4 Correct comment for deco subsurface_conservatism_factor
This adapts the comment according to the change done in
bd89e33e76

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-09-20 08:52:36 -07:00
Robert C. Helling
456e2cec89 Cache all Buehlmann factors
not just the last one.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29 06:49:44 -07:00
Robert C. Helling
7b18be2a50 Adopt planner state caching to new struct
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26 15:44:36 -07:00
Robert C. Helling
57ee5a5477 Assemble global state of planner in a struct
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26 15:44:36 -07:00
Dirk Hohndel
6399eaf271 Add SPDX header to core C files
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Dirk Hohndel
08284275e7 Merge branch 'master' of https://github.com/dje29/subsurface 2017-03-11 08:41:41 -08:00
Martin Měřinský
dcf2542215 Use abbreviations with dots. 2017-03-11 08:09:07 -08:00
Jeremie Guichard
2b06a0b223 Fix potential double/float to int rounding errors
Not using lrint(f) when converting double/float to int
creates rounding errors.
This error was detected by TestParse::testParseDM4 failure
on Windows. It was creating rounding inconsistencies
on Linux too, see change in TestDiveDM4.xml.

Enable -Wfloat-conversion for gcc version greater than 4.9.0

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-09 23:07:30 +07:00
Robert C. Helling
bd89e33e76 Fix typo in saturation/desatureation rates
This patch eliminates the difference between the saturation and
desaturation rates. This was probably once meant as a conservative
measure but the desaturation rate was increased rather than the
saturation rate (which is probably a typo, as reported by Stefan).

Since there is no good basis for this anyway, this patch sets
both factors to 1.0 (and if accepted the whole factor business
should be removed).

This makes our deco times slightly longer. But in the past,
we had introduced a 1.2% fudge factor in the critical radius
calculation to add conservatism and match the benchmark better.

Removing this fudge factor brings us close to the benchmarks.
Expected test values updated.

Reported-by: Stefan <sjti@gmx.net>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-02-19 15:29:40 -08:00
Robert C. Helling
032c3258ed Reset VPM-B state between repetitive dives
This resets the maximum crushing pressures and the maximal
ambient pressure between repetitive dives to prevent anomalies
that a dive produces a shorter deco when following another one
than without.

Reported-by: sfuchs@gmx.de
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-02-10 06:41:24 -08:00
Robert C. Helling
bb4bf639c3 Fix deco_mode confusion
We have two prefernces determining the deco_mode (BUEHLMANN vs VPMB
vs RECREATIONAL): One for the planner (deco_mode) and one for
displaying dives (display_deco_mode). The former is set in the planner
settings while the latter is set in the preferences.

This patch clears up a confusion which of the two to use by introducing
a helper function that selects the correct variable.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-01-06 20:43:23 -08:00
Robert C. Helling
f03acb9e9a Fix effective GFs in notes
This patch fixes two bugs:

1) It first computes the effective gradient factors and then
composes the notes with the diveplan rather than the other way
around.

2) It does not try to fit a line through a single point.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-12-04 05:32:08 +09:00
Robert C. Helling
4d0d37b690 Show effective gradient factors for VPMB-plans
For each stop, this computes an effective gradient factor
that gives the same ceiling. Then, it does linear regression
to find values for GFlow and GFhigh that give a similar deco
profile.

Note that this optimises the average gradient factor. The
runtime however depends strongly at the gradient factor at
the last depth. So we don't necessarily to get the runtime
right.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-11-24 09:59:42 +09:00
Rick Walsh
ebddf95252 ToolTipItem: show gf line based on correct gradient factor preferences
Calculate gfline using the gradient factor that is set by the planner
preferences when in the planner, and by the general prefs when not in the
planner. This is achieved by doing the gradient factor calculation in dive.c,
where buehlmann_config is defined.

Previously, the gfline was calculated using the general preferences gfhigh and
gflow, even when in the planner.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-10-27 20:36:14 -07:00
Robert C. Helling
aa3067c0f8 Compute weighted Buehlmann coefficients for all deco models
... as those are needed for the heatmap and not only
for Buehlmann ceilings.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-10-03 12:44:16 -07:00
Rick Walsh
7e09a6c7bc Separate VPM-B conservatism preference for planner and profile
Separate the VPM-B conservatism preference into diveplan.vpmb_conservatism for
planning dives and prefs.vpmb_conservatism for profile ceiling display of
saved dives.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-24 08:30:11 -07:00
Rick Walsh
7b891904e7 Rename conservatism_level to vpmb_conservatism
Make the variable purpose less ambiguous

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-24 08:29:56 -07:00
Robert C. Helling
ed11dab7fb Compute total tissue saturation for all deco models
... and not just for Buehlmann. This makes the saturation
graphs meaningful for VPM-B.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-17 13:43:28 -07:00