summaryrefslogtreecommitdiffstats
path: root/deco.c
AgeCommit message (Collapse)Author
2015-10-04VPM-B: Adjust Subsurface conservatismGravatar Rick Walsh
Reverting commit 3d8e5b638ad4c1fbb43f6dd5f535bf0b33a51f0b makes the CVA calculation marginally less conservative, and one of the tests fails as a result. This tiny adjustment to the conservatism fixes that. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-23deco.c: fix warnings about unused variablesGravatar Lubomir I. Ivanov
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-20Only calculate crushing pressure in VPM-B modeGravatar Robert C. Helling
Don't do this expensive calculation when not needed. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-16VPMB gradient of imperm: don't confuse atm and barGravatar Rick Walsh
Other VPM-B implementations (V-Planner, MultiDeco, Fortran code) take the default gradient of onset of impermeability as 8.2 atm. We use bar as the pressure unit, and 8.2 atm = 8.30865 bar. This has negligible effect on all of the calculated plans I've tested, resulting in a maximum decrease of 1 minute in total dive time for ~150 m deep dives, but we should get unit conversions correct anyway. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-02VPM-B: Add 1 percent conservatism to pass testsGravatar Rick Walsh
Subsurface appears to produce marginally less conservative plans than our benchmarks. Introduce 1% additional conservatism. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-31Calculate ceiling only when it is neededGravatar Robert C. Helling
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-31Do the Boyle compensation when the gradient is neededGravatar Robert C. Helling
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-29Use Schreiner water vapour pressure for VPM-BGravatar Rick Walsh
Inspired gas loading equations depend on the partial pressure of inert gas in the alveolar. P_alv = (P_amb - P_H2O + (1 - Rq) / Rq * P_CO2) * f where: P_alv alveolar partial pressure of inert gas P_amb ambient pressure P_H2O water vapour partial pressure = ~0.0627 bar P_CO2 carbon dioxide partial pressure = ~0.0534 bar Rq respiratory quotient (O2 consumption / CO2 production) f fraction of inert gas In our calculations, we simplify this to use an effective water vapour pressure WV = P_H20 - (1 - Rq) / Rq * P_CO2 Buhlmann ignored the contribution of CO2 (i.e. Rq = 1.0), whereas Schreiner adopted Rq = 0.8. WV_Buhlmann = PP_H2O = 0.0627 bar WV_Schreiner = 0.0627 - (1 - 0.8) / Rq * 0.0534 = 0.0493 bar Buhlmann calculations use the Buhlmann value, VPM-B calculations use the Schreiner value. Concept explained here: http://www.divetable.de/workshop/V1_e.htm Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-29VPM-B: Use correct gamma valuesGravatar Rick Walsh
In other implementations of VPM-B, surface_tension_gamma and skin_compression_gammaC are taken as 0.0179 N/msw and 0.257 N/msw respectively. We do pressure calculations in bar, not msw, so our gamma values need to reflect that. Previously we had used 0.179 and 2.57, which are close but not quite correct (10 msw == 1.01325 bar). Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-27Rename variable to better reflect what it doesGravatar Robert C. Helling
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-23Prepare global state of VPM-B when starting to planGravatar Robert C. Helling
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-23dump_tissues() should be available regardless of macro settingsGravatar Robert C. Helling
this does not increas binary size increadably but is usefull when trying to figure out what the planner is doing. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-23Simplified Boyle's law correction and new cubic rootGravatar Robert C. Helling
This uses a bit of algebra to simplify the formula for Boyle's law correction and introduces another algebraic cubic root solver that can also deal with negative discriminants thanks to a trigonometric formula from Wikipedia. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-21Use our pressure type to avoid bar / mbar confusionGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-21Don't do computationally expensive Boyle compensation when not using VPM-BGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-21Don't do Boyle compensation when still on first stopGravatar Robert C. Helling
There is nothing to compensate but we would hit a 0/0 numerical instability there. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-20Use boyle_compensation in profileGravatar Robert C. Helling
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-20Leftovers from introduction of in_planner() helper functionGravatar Robert C. Helling
I have no idea how these could have been left behind Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-18VPM-B: Update critical_volume_lambdaGravatar Rick Walsh
The default value for critical_volume_lambda is 6500 fsw.min (= 199.58 bar.min) for VPM-B, rather than 7500 fsw.min (= 230.284 bar.min) for VPM. This is consistent with V-Planner, MultiDeco, GUE DecoPlanner, HLPlanner and the comments in the Fortran code explanation. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-18Get rid of is_ok_vpmbGravatar Robert C. Helling
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-17Explicit names for initialization of deco constantsGravatar Robert C. Helling
This patch is purely cosmetic except for the fact it changes the critical radii to the V-planner with Boyle compensation values. These values would have been set anyway by Jan's commit "VPM-B: Set radius constants to values reccomended by V-Planner" which will conflict with this anyway. This way, the last chunk of Jan's patch can just be discarded. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-17Factor out root of cubic to be used also for update_gradientGravatar Robert C. Helling
We can use the analytic solution of a cubic in two different places. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-17Merge branch 'boyle-ready' of https://github.com/Slagvi/subsurfaceGravatar Dirk Hohndel
Fixed merge conflicts in deco.c dive.h planner.c Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-15Some unification between Buehlmann and VPM-BGravatar Robert C. Helling
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-15VPM-B: Set radius constants to values reccomended by V-Planner.Gravatar Jan Darowski
V-Planner reccomends smaller values for the VPM with the Boyles compensation. Also missing units comments were added. Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-08-15VPM-B: Add conservatism levels to deco.cGravatar Jan Darowski
Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-08-15VPM-B: Add surface decompression time.Gravatar Jan Darowski
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-15VPM-B: Add simple Boyle's law compensation.Gravatar Jan Darowski
This is a very basic implementation that uses bin search for solving the cubic. It's not called anywhere at this stage, needs to be changed to analytic solution. Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-07Include units in VPM config structure definitionGravatar Rick Walsh
Include units in the comments of VPM structure definition. We should confirm the units surface_tension_gamma and skin_compression_gammaC. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-07Use common VPM configuration parametersGravatar Rick Walsh
Adopt the same critical radii used by Eric Baker's original VPM Fortran code and V-Planner. Standard critical volume lambda = 7500 fsw-min (numerous sources). We need to convert it properly. λ = 7500 fsw-min = 7500/33 = 227.2727 ata-min = 227.2727 * 1.01325 bar-min = 230.284 bar-min Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-03VPM-B: add next gradient calculation.Gravatar Jan Darowski
It improves (increases) gradients for all the compartments, so more free gas can be created in the divers body. Next gradients will converge, so the volume won't exceed the safe limit, indicated by the crit_volume_lambda parameter. Function takes time of the last deco in seconds. Requires vpmb_start_gradient() to be run before. Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-03VPM-B: add vpm-b based deco checking.Gravatar Jan Darowski
Check during the trial_ascent() if existing pressure gradient is smaller than previously calculated max gradient. If not, ascent is impossible from the vpm-b's point of view. Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-03VPM-B: add initial gradient calculation.Gravatar Jan Darowski
Calculate the max difference between tissue saturation and ambient pressure that can be accepted during the ascent. Partial results are kept for later improving in next CVA iterations Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-03VPM-B: add nuclei size calculation and nuclear regeneration.Gravatar Jan Darowski
This function calculates the size of nuclei at the end of deco, then simulates their regeneration, to the moment before the deco. This is redundant as nuclear regeneration is a very slow process. Function should be called with time in seconds, just before the ascent. Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-03VPM-B: use an analytic solution for nucleon inner pressure instead of binary ↵Gravatar Robert C. Helling
root search According to mathematica In[4]:= f[x_] := x^3 - b x^2 - c In[18]:= Solve[f[x] == 0, x] Out[18]= {{x -> 1/3 (b + ( 2^(1/3) b^2)/(2 b^3 + 27 c + 3 Sqrt[3] Sqrt[4 b^3 c + 27 c^2])^( 1/3) + (2 b^3 + 27 c + 3 Sqrt[3] Sqrt[4 b^3 c + 27 c^2])^(1/3)/ 2^(1/3))}, {x -> b/3 - ((1 + I Sqrt[3]) b^2)/( 3 2^(2/3) (2 b^3 + 27 c + 3 Sqrt[3] Sqrt[4 b^3 c + 27 c^2])^( 1/3)) - ((1 - I Sqrt[3]) (2 b^3 + 27 c + 3 Sqrt[3] Sqrt[4 b^3 c + 27 c^2])^(1/3))/(6 2^(1/3))}, {x -> b/3 - ((1 - I Sqrt[3]) b^2)/( 3 2^(2/3) (2 b^3 + 27 c + 3 Sqrt[3] Sqrt[4 b^3 c + 27 c^2])^( 1/3)) - ((1 + I Sqrt[3]) (2 b^3 + 27 c + 3 Sqrt[3] Sqrt[4 b^3 c + 27 c^2])^(1/3))/(6 2^(1/3))}} For the values of b and c encounterd in the algorithm, the first solution is in fact the only real one that we are after. So we can use this solution instead of doing a binary search for the root of the cubic. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-03VPM-B: add initial values for crushing pressure variables.Gravatar Jan Darowski
Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-03VPM-B: add crushin pressure calculation.Gravatar Jan Darowski
Add new structures holding vpm-b state. Add function calculating current crushing pressure. Call it from add_segment() on every ambient pressure change. It determines what pressure acts on nuclei during the descent and thus their size at the beggining of the deco. Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-03VPM-B: add calculating nucleons inner pressure.Gravatar Jan Darowski
This function calculates the pressure inside the nucleon during the impermeable phase. In the original code, Newton's method is used, for simplicity, we use binary search for finding cubic equations root. Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-03VPM-B: add basic algorithm settings.Gravatar Jan Darowski
Created vpmb_config structure based on buehlmann_config. Set it's default values to ones taken from the existing C implementation. Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-01-20Use SAC from preferences for PSCR oxygen dropGravatar Robert C. Helling
The ratio between SAC and oxygen metabolism rate can be assumed constant but not the metabolism rate. So we better base our calculation on the ratio that uses the SAC from the preferences as that pairs well with the O2 consumption from the preferences. Hence we ran remove the sac parameter from fill_pressures(). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-17Use correct divemode (PSCR in particular) in deco calculationGravatar Robert C. Helling
I had forgotten this dead code. Sorry. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-04Prepare for PSCR calculationsGravatar Robert C. Helling
Calculations for passive semi-closed rebreathers are pretty much like OC except the pO2 is lower bey a certain (SAC dependent) factor. This patch introduces the corresponding calculations in case dctype == PSCR which is so far never set and there is currently no UI for these calculations. As pO2 is SAC dependent it takes a certain attempt at getting it and drops to defaults from the prefs otherwise. As there is no UI at this point and I also don't have any dives, this has not received much testing, yet, but it compiles. At least. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-27deco.c: remove unused variables in add_segment()Gravatar Lubomir I. Ivanov
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-26Take water vapor pressure into account again for decoGravatar Robert C. Helling
In the transition to the partial pressure helper function, the water vapor component of the breathing gas had been dropped. This had a significant effect on deco times for deep dives. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-13CCR patch: Reorganise the oxygen partial pressure calculationsGravatar willem ferguson
This patch responds to the side effects that the CCR code has had with respect to ceilings in OC dives and dive plans. Dive ceilings are now calculated correctly again. The following were performed: 1) remove the oxygen sensor and setpoint fields from the gas_pressures structure. 2) Re-insert setpoint and oxygen sensor fields in the plot_data structure. 3) Remove the algorithm that reads the o2 sensor data and calculates the pressures.po2 value from function fill_pressures() in dive.c and save it as a separate function calc_ccr_po2() in profile.c. 4) Activate calc_ccr_po2 from function fill_pressures() in profile.c. 5) Move the relative position of the call to fill_pressures() within the function create_polt_info_new() in profile.c. Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-12CCR patch: Oxygen partial pressuresGravatar willem ferguson
This patch does three things: 1) A new function fill_o2_values() is added to profile.c. This fills all oxygen sesnsor and setpoint values that have been zeroed before in order to save space in the dive log. This recreates the full set of sensor values obtained from the original CCR xml log file. 2) Function fill_o2_values() is activated in function create_ plot_info_new() in profile.c 3) The calling parameters to function fill_pressures() in dive.c are changed. The last parameter is now a pointer to a structure of divecomputer. This will be needed in the last patch of the present series of three patches. [Dirk Hohndel: minor whitespace cleanup] Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-09-19Tissue saturation plot a la Sherwater PretelGravatar Robert C. Helling
This adds a toolbox icon to turn on a tissue plot inspired by the bar graph of the Sherwater Petrel, It shows the inert gas partial pressures for individual compartments. If they are below the ambient pressure (grey line) they are shown in units of the ambient pressure, if they are above, the excess is shown as a percentage of the allowed overpressure for plain Buehlmann. So it has the same units as a gradient factor. Thus also the a gradient factor line (for the current depth) is shown. The different tissues get different colors, greener for the faster ones and bluer for the slower ones. Positioning and on/off icon action still need some tender loving care. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-09-18Helper function for partial pressure calculationGravatar Robert C. Helling
This patch introduces a new structure holding partial pressures (doubles in bar) for all three gases and a helper function to compute them from gasmix (which holds fractions) and ambient pressure. Currentlty this works for OC and CCR, to be extended later to PSCR. Currently the dive_comp_type argument is unused. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-25Deco artefacts with low GFlowGravatar Robert C. Helling
In a dive, when you choose a very low GFlow (like 5 or 9) and a trimix with quite some He (12/48 in the example) and descend fast, the ceiling seems to do strange things in the first minutes of the dive (very very deep for example or jumping around). To understand what is going on we have to recall what gradient factors do in detail: Plain Buehlmann gives you for each tissue a maximal inert gas pressure that is a straight line when plotted against the ambient pressure. So for each depth (=ambient pressure) there is a maximally allowed over-pressure. The idea of gradient factors is that one does not use all the possible over-pressure that Buehlmann gives us but only a depth dependent fraction. GFhigh is the fraction of the possible over-pressure at the surface while GFlow is the fraction at the first deco stop. In between, the fraction is linearly interpolated. As the Buehlmann over-pressure is increasing with depth and typically also the allowed overpressure after applications of gradient factors increases with depth or said differently: the tissue saturation has to be lower if the diver wants to ascent. The main problem is: What is the first stop (where to apply GFlow)? In a planned dive, we could take the first deco stop, but in a real dive from a dive computer download it is impossible to say what constitutes a stop and what is only a slow ascent? What I have used so far is not exactly the first stop but rather the first theoretical stop: During all of the dive, I have calculated the ceiling under the assumption that GFlow applies everywhere (and not just at a single depth). The deepest of these ceilings I have used as the “first stop depth”, the depth at which GFlow applies. Even more, I only wanted to use the information that a diver has during the dive, so I actually only considered the ceilings in the past (and not in the future of a given sample). But this brings with it the problem that early in the dive, in particular during the descent the lowest ceiling so far is very shallow (as not much gas has built up in the body so far). This problem now interferes with a second one: If at the start of the dive when the all compartments have 790mbar N2 the diver starts breathing a He-heavy mix (like 12/48) and descents fast the He builds up in the tissues before the N2 can diffuse out. So right at the start, we already encounter high tissue loadings. If now we have a large difference between GFhigh and GFlow but they apply at very similar depth (the surface and a very shallow depth of the deepest ceiling (which for a non-decompression dive would be theoretically at negative depth) so far) it can happen that the linear interpolation as opposite slope then in the typical case above: The allowed over-pressure is degreasing with depth, shallower depth do not require lower gas loading in the tissue (i.e. can be reached after further off-gasing) but but tolerate higher loadings. In that situation the ceiling disappears (or is rather a floor). So far, I got rid of that problem, by stating that the minimum depth for GFlow was 20m (after all, GFlow is about deep stops, so it should better not be too shallow). Now the dive reported in ticket #549 takes values to an extreme in such away that 20m (which is determined by buehlmann_config.gf_low_position_min in deco.c) was not enough to prevent this inversion problem (or in a milder form that the interpolation of gradient factors is in fact an extrapolation with quite extreme values). This patch that gets rid of the problem for the dive described above but still it is possible to find (more extreme) parameter choices that lead to non-realistic ceilings. Let me close by pointing out that all this is only about the descent, as it is about too shallow depth for GFlow. So no real deco (i.e. later part of the dive) is inflicted. This is only about a theoretical ceiling displayed possibly in the first minutes of a dive. So this is more an aesthetically than a practical problem. Fixes #549 Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-23Be more consistent in partial pressure namingGravatar Henrik Brautaset Aronsen
Lets just use pO₂ instead of PO2, ppO2, ppO₂, PO₂. They all mean the same, but it's better to be consistent Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>