aboutsummaryrefslogtreecommitdiffstats
path: root/core/deco.c
AgeCommit message (Collapse)Author
2020-10-03core: make gas type enum globally availableGravatar Berthold Stoeger
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-05-06cleanup: move the inertgas enum from qthelper.hpp to deco.cGravatar Berthold Stoeger
There are no outside users. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06planner: remove Bühlmann factor cacheGravatar Berthold Stoeger
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>
2019-08-08Parser: remove global stateGravatar Berthold Stoeger
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-08Cleanup: move planner/deco related declarations planner/deco.hGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Cleanup: move file-related function declarations to file.hGravatar Berthold Stoeger
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-08Cleanup: move error reporting function declarations to errorhelper.hGravatar Berthold Stoeger
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-06-19Cleanup: make local variables and functions in deco.c staticGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-15Cleanup: small coding style fixesGravatar Dirk Hohndel
And addressing a cut and paste error in a comment. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-04-12Coding style: remove Java-style function definitionGravatar Berthold Stoeger
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-03-17Core: cast before multiplication to avoid potential overflowGravatar Dirk Hohndel
Found via LGTM.com Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-10-15deco: _really_ make sure the deco state is fully initializedGravatar Linus Torvalds
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-15deco: make sure deco state is fully initializedGravatar Linus Torvalds
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-08-23Cleanup: const-ify functions taking pointers to eventsGravatar Berthold Stoeger
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-23Cleanup: pass gasmix by valueGravatar Berthold Stoeger
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-05-24core: replace (void) with UNUSED(x) and include ssrf.hGravatar jan Iversen
Unused parameters in C are "silenced" by adding UNUSED(x) Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-14Rename enum dive_comp_type to divemode_tGravatar Robert C. Helling
...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-14Implement bailout outside of the dive plannerGravatar Willem Ferguson
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-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-04-11Look for actual isobaric counter diffusionGravatar Robert C. Helling
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-02-26Cleanup: Unify qthelper.h and qthelperfromc.hGravatar Berthold Stoeger
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>
2017-12-25Prevent overflow in effective GF calculationGravatar Robert C. Helling
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-24Code cleanup: Indentation mistake plus simplificationGravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-01Remove unnecessary #include and correct whitespaceGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-27Compile dump_tissues function only if needed based on defineGravatar Stefan Fuchs
Compile it only when DECO_CALC_DEBUG is defined. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-25Localize global planner stateGravatar Robert C. Helling
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-10-01More VPMB state in special structureGravatar Robert C. Helling
... 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-09-20Remove option to apply GFlow at maxdepthGravatar Robert C. Helling
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-20Correct comment for deco subsurface_conservatism_factorGravatar Stefan Fuchs
This adapts the comment according to the change done in bd89e33e765d73aa2b48419031d6922b8bf5eb37 Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-08-29Cache all Buehlmann factorsGravatar Robert C. Helling
not just the last one. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26Adopt planner state caching to new structGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26Assemble global state of planner in a structGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-04-29Add SPDX header to core C filesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-11Merge branch 'master' of https://github.com/dje29/subsurfaceGravatar Dirk Hohndel
2017-03-11Use abbreviations with dots.Gravatar Martin Měřinský
2017-03-09Fix potential double/float to int rounding errorsGravatar Jeremie Guichard
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-02-19Fix typo in saturation/desatureation ratesGravatar Robert C. Helling
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-10Reset VPM-B state between repetitive divesGravatar Robert C. Helling
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-01-06Fix deco_mode confusionGravatar Robert C. Helling
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>
2016-12-04Fix effective GFs in notesGravatar Robert C. Helling
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-11-24Show effective gradient factors for VPMB-plansGravatar Robert C. Helling
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-10-27ToolTipItem: show gf line based on correct gradient factor preferencesGravatar Rick Walsh
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-03Compute weighted Buehlmann coefficients for all deco modelsGravatar Robert C. Helling
... 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-09-24Separate VPM-B conservatism preference for planner and profileGravatar Rick Walsh
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-24Rename conservatism_level to vpmb_conservatismGravatar Rick Walsh
Make the variable purpose less ambiguous Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-17Compute total tissue saturation for all deco modelsGravatar Robert C. Helling
... 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-17Cosmetic changes to Buehlmann codeGravatar Robert C. Helling
Change runtime table string from ZHL-16B to ZHL-16C to reflect he fact that we use 5min as half-time for the fastest compartment rather than 4min. Further more trade pow(2.0, ...) for exp(). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04Move subsurface-core to core and qt-mobile to mobile-widgetsGravatar Dirk Hohndel
Having subsurface-core as a directory name really messes with autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an autocomplete conflict and also was inconsistent with the desktop-widget name for the directory containing the "other" UI. And while cleaning up the resulting change in the path name for include files, I decided to clean up those even more to make them consistent overall. This could have been handled in more commits, but since this requires a make clean before the build, it seemed more sensible to do it all in one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>