Mercurial > public > ostc4
annotate Discovery/Src/vpm.c @ 837:18946846b95b Evo_2_23
Bugfixes and code cleanup for BF views:
BF views gauge and apnoe were using "dive computer" T3 view functions which caused some problem because these legacy views were not intended to work with customer view selection. A switch condition has been added to skip these kind of functions in case a design other T3 is in use.
Another potential problem was that there were two definitions for T3 and T7 views which were basically the same. If they wold not be the same the switching functionality wold not work properly. To avoid this problem in futur the arrays have been merged => the view are handled sing the (newer) cv_view arrays instead of the standard_views which were in used before the user could the views which should be shown.
author | ideenmodellierer |
---|---|
date | Wed, 27 Dec 2023 19:37:17 +0100 |
parents | b7d93ff6b3b2 |
children | 0c89c6fa949c |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/vpm.c | |
5 /// \brief critical_volume comment by hw | |
6 /// \author Heinrichs Weikamp, Erik C. Baker | |
7 /// \date 19-April-2014 | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 /// \par Varying Permeability Model (VPM) Decompression Program in c (converted from FORTRAN) | |
29 /// | |
30 /// Author: Erik C. Baker | |
31 /// | |
32 /// "DISTRIBUTE FREELY - CREDIT THE AUTHORS" | |
33 /// | |
34 /// This program extends the 1986 VPM algorithm (Yount & Hoffman) to include | |
35 /// mixed gas, repetitive, and altitude diving. Developments to the algorithm | |
36 /// were made by David E. Yount, Eric B. Maiken, and Erik C. Baker over a | |
37 /// period from 1999 to 2001. This work is dedicated in remembrance of | |
38 /// Professor David E. Yount who passed away on April 27, 2000. | |
39 /// | |
40 /// Notes: | |
41 /// 1. This program uses the sixteen (16) half-time compartments of the | |
42 /// Buhlmann ZH-L16 model. The optional Compartment 1b is used here with | |
43 /// half-times of 1.88 minutes for helium and 5.0 minutes for nitrogen. | |
44 /// | |
45 /// 2. This program uses various DEC, IBM, and Microsoft extensions which | |
46 /// may not be supported by all FORTRAN compilers. Comments are made with | |
47 /// a capital "C" in the first column or an exclamation point "!" placed | |
48 /// in a line after code. An asterisk "*" in column 6 is a continuation | |
49 /// of the previous line. All code, except for line numbers, starts in | |
50 /// column 7. | |
51 /// | |
52 /// 3. Comments and suggestions for improvements are welcome. Please | |
53 /// respond by e-mail to: EBaker@se.aeieng.com | |
54 /// | |
55 /// Acknowledgment: Thanks to Kurt Spaugh for recommendations on how to clean | |
56 /// up the code. | |
57 /// =============================================================================== | |
58 /// Converted to vpmdeco.c using f2c; R.McGinnis (CABER Swe) 5/01 | |
59 /// =============================================================================== | |
60 /// | |
61 /// ************************ Heirichs Weipkamp ************************************** | |
62 /// | |
63 /// The original Yount & Baker code has been adjusted for real life calculation. | |
64 /// | |
65 /// 1) The original main function has been split in several functions | |
66 /// | |
67 /// 2) When the deco zone is reached (while ascending) the gradient factors are kept fix | |
68 /// and critical volume algorithm is switched of. maxfirststopdepth is kept fix | |
69 /// to make shure Boeyls Law algorithm works correctly | |
70 /// | |
71 /// 4) gas_loadings_ascent_descend heeds all gaschanges and CCR support has been added | |
72 /// | |
73 | |
74 #include <stdio.h> | |
75 #include <stdlib.h> | |
76 #include <string.h> | |
77 #include <math.h> | |
78 #include <time.h> | |
79 | |
80 #include "vpm.h" | |
81 #include "decom.h" | |
82 | |
83 #define GAS_N2 0 | |
84 #define GAS_HE 1 | |
85 | |
290 | 86 static const _Bool buehlmannSafety = true; |
38 | 87 /* Common Block Declarations */ |
88 | |
89 extern const float SURFACE_TENSION_GAMMA; //!Adj. Range: 0.015 to 0.065 N/m | |
90 extern const float SKIN_COMPRESSION_GAMMAC; //!Adj. Range: 0.160 to 0.290 N/m | |
91 extern const float UNITS_FACTOR; | |
92 extern const float WATER_VAPOR_PRESSURE; // (Schreiner value) based on respiratory quotien | |
93 extern const float CRIT_VOLUME_PARAMETER_LAMBDA; //!Adj. Range: 6500 to 8300 fsw-min | |
290 | 94 //extern const float GRADIENT_ONSET_OF_IMPERM_ATM; //!Adj. Range: 5.0 to 10.0 atm |
38 | 95 extern const float REGENERATION_TIME_CONSTANT; //!Adj. Range: 10080 to 51840 min |
290 | 96 //extern const float PRESSURE_OTHER_GASES_MMHG; //!Constant value for PO2 up to 2 atm |
38 | 97 extern const float CONSTANT_PRESSURE_OTHER_GASES; // PRESSURE_OTHER_GASES_MMHG / 760. * UNITS_FACTOR; |
98 | |
99 extern const float HELIUM_TIME_CONSTANT[]; | |
100 extern const float NITROGEN_TIME_CONSTANT[]; | |
101 | |
290 | 102 static float minimum_deco_stop_time; |
103 static float run_time, run_time_first_stop; | |
104 static float segment_time; | |
105 static short mix_number; | |
106 static float barometric_pressure; | |
107 static _Bool altitude_dive_algorithm_off; | |
108 static _Bool units_equal_fsw, units_equal_msw; | |
38 | 109 |
110 /* by hw 11.06.2015 to allow */ | |
290 | 111 static float gCNS_VPM; |
38 | 112 |
290 | 113 static float helium_pressure[16], nitrogen_pressure[16]; |
114 static float surface_phase_volume_time[16]; | |
115 static float regenerated_radius_he[16], regenerated_radius_n2[16]; | |
116 static float allowable_gradient_he[16], allowable_gradient_n2[16]; | |
38 | 117 |
118 //_Bool deco_zone_reached; | |
290 | 119 static _Bool critical_volume_algorithm_off; |
120 static float max_first_stop_depth; | |
121 static float max_deco_ceiling_depth; | |
38 | 122 //Boylslaw compensation |
290 | 123 static float deco_gradient_he[16]; |
124 static float deco_gradient_n2[16]; | |
125 static int vpm_calc_what; | |
126 static int count_critical_volume_iteration; | |
127 static short number_of_changes; | |
128 static float depth_change[11]; | |
129 static float step_size_change[11]; | |
130 static float rate_change[11]; | |
131 static short mix_change[11]; | |
38 | 132 |
290 | 133 static const _Bool vpm_b = true; |
38 | 134 |
135 extern const float float_buehlmann_N2_factor_expositon_20_seconds[]; | |
136 extern const float float_buehlmann_He_factor_expositon_20_seconds[]; | |
137 extern const float float_buehlmann_N2_factor_expositon_one_minute[]; | |
138 extern const float float_buehlmann_He_factor_expositon_one_minute[]; | |
139 extern const float float_buehlmann_N2_factor_expositon_five_minutes[]; | |
140 extern const float float_buehlmann_He_factor_expositon_five_minutes[]; | |
141 extern const float float_buehlmann_N2_factor_expositon_one_hour[]; | |
142 extern const float float_buehlmann_He_factor_expositon_one_hour[]; | |
143 | |
290 | 144 static float depth_start_of_deco_calc; |
145 static float depth_start_of_deco_zone; | |
146 static float first_stop_depth; | |
147 static float run_time_start_of_deco_zone; | |
38 | 148 |
290 | 149 static float r_nint(float *x); |
150 static float r_int(float *x); | |
151 static _Bool nullzeit_unter60; | |
152 static int vpm_calc_status; | |
153 static _Bool buehlmann_wait_exceeded = false; | |
38 | 154 |
290 | 155 static SLifeData* pInput = NULL; |
156 static SVpm* pVpm = NULL; | |
157 static SDecoinfo* pDecoInfo = NULL; | |
158 static SDiveSettings* pDiveSettings = NULL; | |
159 | |
160 static float r_nint(float *x) | |
38 | 161 { |
162 return( (*x)>=0 ? | |
163 floorf(*x + 0.5f) : -floorf(0.5f - *x) ); | |
164 } | |
165 | |
290 | 166 static float r_int(float *x) |
38 | 167 { |
168 return( (*x>0) ? floorf(*x) : -floorf(- *x) ); | |
169 } | |
170 | |
171 /** private functions | |
172 */ | |
290 | 173 extern int radius_root_finder (float *a, float *b, float *c,float *low_bound, float *high_bound, float *ending_radius); |
38 | 174 |
290 | 175 static int nuclear_regeneration(float *dive_time);// clock_(); |
176 static int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowablw); | |
177 static int critical_volume(float *deco_phase_volume_time); ; | |
178 static int calc_start_of_deco_zone(float *starting_depth, float *rate, float *depth_start_of_deco_zone); | |
179 static int calc_initial_allowable_gradient(void); | |
180 static void decompression_stop(float *deco_stop_depth, float *step_size, _Bool final_deco_calculation); | |
181 static int gas_loadings_ascent_descen(float* helium_pressure, float* nitrogen_pressure, float starting_depth,float ending_depth, float rate,_Bool check_gas_change); | |
182 static int calc_surface_phase_volume_time(void); | |
183 static int calc_max_actual_gradient(float *deco_stop_depth); | |
184 static int projected_ascent(float *starting_depth, float *rate, float *deco_stop_depth, float *step_size); | |
185 static void vpm_calc_deco(void); | |
186 static int vpm_calc_critcal_volume(_Bool begin,_Bool calc_nulltime); | |
187 static int vpm_check_converged(_Bool calc_nulltime); | |
188 static int vpm_calc_final_deco(_Bool begin); | |
189 static void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth,float * Deco_Stop_Depth,float* Step_Size); | |
292 | 190 static int vpm_calc_ndl(void); |
290 | 191 static void vpm_init_1(void); |
192 static void vpm_calc_deco_ceiling(void); | |
38 | 193 |
290 | 194 static void vpm_init_1(void) |
38 | 195 { |
196 units_equal_msw = true; | |
197 units_equal_fsw = false; | |
198 altitude_dive_algorithm_off= true; //!Options: ON or OFF | |
199 minimum_deco_stop_time=1.0; //!Options: float positive number | |
200 critical_volume_algorithm_off= false; //!Options: ON or OFF | |
201 run_time = 0.; | |
202 //barometric_pressure = dive_data.surface * 10; | |
203 | |
204 //mix_number = dive_data.selected_gas + 1; | |
205 | |
206 max_first_stop_depth = 0; | |
207 max_deco_ceiling_depth = 0; | |
208 //deco_zone_reached = false; | |
209 depth_start_of_deco_calc = 0; | |
210 depth_start_of_deco_zone = 0; | |
211 first_stop_depth = 0; | |
212 run_time_start_of_deco_zone = 0; | |
213 | |
214 gCNS_VPM = 0; | |
215 } | |
216 | |
217 float vpm_get_CNS(void) | |
218 { | |
219 return gCNS_VPM; | |
220 } | |
221 | |
222 int vpm_calc(SLifeData* pINPUT, | |
223 SDiveSettings* pSettings, | |
224 SVpm* pVPM, | |
225 SDecoinfo* | |
226 pDECOINFO, | |
227 int calc_what) | |
228 { | |
229 vpm_init_1(); | |
230 //decom_CreateGasChangeList(pSettings, pINPUT); | |
231 vpm_calc_what = calc_what; | |
232 /**clear decoInfo*/ | |
233 pDECOINFO->output_time_to_surface_seconds = 0; | |
234 pDECOINFO->output_ndl_seconds = 0; | |
235 pDECOINFO->output_ceiling_meter = 0; | |
247
3949781096d4
feature: Relative GF to Saturation renames
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
236 pDECOINFO->super_saturation = 0; |
38 | 237 uint8_t tmp_calc_status; |
238 for(int i=0;i<DECOINFO_STRUCT_MAX_STOPS;i++) | |
239 { | |
240 pDECOINFO->output_stop_length_seconds[i] = 0; | |
241 } | |
242 | |
305
305f251cc981
bugfix, consistency: show deco/NDL really after 1 minute divetime
Jan Mulder <jlmulder@xs4all.nl>
parents:
293
diff
changeset
|
243 if(pINPUT->dive_time_seconds_without_surface_time < 60) |
38 | 244 { |
292 | 245 vpm_calc_status = CALC_NDL; |
38 | 246 return vpm_calc_status; |
247 } | |
248 pVpm = pVPM; | |
249 pInput = pINPUT; | |
250 pDecoInfo = pDECOINFO; | |
251 pDiveSettings = pSettings; | |
252 | |
292 | 253 if(vpm_calc_status == CALC_NDL) |
38 | 254 { |
292 | 255 tmp_calc_status = vpm_calc_ndl(); |
38 | 256 } |
257 else | |
258 { | |
259 tmp_calc_status = CALC_BEGIN; | |
260 } | |
261 //Normal Deco calculation | |
292 | 262 if(tmp_calc_status != CALC_NDL) |
38 | 263 { |
264 max_first_stop_depth = pVpm->max_first_stop_depth_save; | |
265 run_time_start_of_deco_zone = pVpm->run_time_start_of_deco_zone_save; | |
266 depth_start_of_deco_zone = pVpm->depth_start_of_deco_zone_save; | |
267 for (int i = 0; i < 16; ++i) { | |
268 helium_pressure[i] = pInput->tissue_helium_bar[i] * 10; | |
269 nitrogen_pressure[i] = pInput->tissue_nitrogen_bar[i] * 10; | |
270 } | |
271 vpm_calc_deco(); | |
272 tmp_calc_status = vpm_calc_critcal_volume(true,false); | |
273 if(vpm_calc_what == DECOSTOPS) | |
274 { | |
275 pVpm->max_first_stop_depth_save = max_first_stop_depth; | |
276 pVpm->run_time_start_of_deco_zone_save = run_time_start_of_deco_zone; | |
277 pVpm->depth_start_of_deco_zone_save = depth_start_of_deco_zone; | |
278 } | |
279 } | |
280 | |
281 //Only Decostops not futute stops | |
282 if(vpm_calc_what == DECOSTOPS) | |
283 vpm_calc_status = tmp_calc_status; | |
284 return vpm_calc_status; | |
285 } | |
286 | |
287 void vpm_saturation_after_ascent(SLifeData* input) | |
288 { | |
289 int i = 0; | |
290 for (i = 0; i < 16; ++i) { | |
291 pInput->tissue_helium_bar[i] = helium_pressure[i] / 10; | |
292 pInput->tissue_nitrogen_bar[i] = nitrogen_pressure[i] / 10; | |
293 } | |
294 pInput->pressure_ambient_bar = pInput->pressure_surface_bar; | |
295 } | |
296 /* =============================================================================== */ | |
297 /* NOTE ABOUT PRESSURE UNITS USED IN CALCULATIONS: */ | |
298 /* It is the convention in decompression calculations to compute all gas */ | |
299 /* loadings, absolute pressures, partial pressures, etc., in the units of */ | |
300 /* depth pressure that you are diving - either feet of seawater (fsw) or */ | |
301 /* meters of seawater (msw). This program follows that convention with the */ | |
302 /* the exception that all VPM calculations are performed in SI units (by */ | |
303 /* necessity). Accordingly, there are several conversions back and forth */ | |
304 /* between the diving pressure units and the SI units. */ | |
305 /* =============================================================================== */ | |
306 /* =============================================================================== */ | |
307 /* FUNCTION SUBPROGRAM FOR GAS LOADING CALCULATIONS - ASCENT AND DESCENT */ | |
308 /* =============================================================================== */ | |
309 | |
310 | |
311 | |
312 /* =============================================================================== */ | |
313 /* SUBROUTINE GAS_LOADINGS_ASCENT_DESCENT */ | |
314 /* Purpose: This subprogram applies the Schreiner equation to update the */ | |
315 /* gas loadings (partial pressures of helium and nitrogen) in the half-time */ | |
316 /* compartments due to a linear ascent or descent segment at a constant rate. */ | |
317 /* =============================================================================== */ | |
318 | |
290 | 319 static int gas_loadings_ascent_descen(float* helium_pressure, |
38 | 320 float* nitrogen_pressure, |
321 float starting_depth, | |
322 float ending_depth, | |
323 float rate,_Bool check_gas_change) | |
324 { | |
325 short i; | |
326 float initial_inspired_n2_pressure, | |
327 initial_inspired_he_pressure, nitrogen_rate, | |
328 last_run_time, | |
329 starting_ambient_pressure, | |
330 ending_ambient_pressure; | |
331 float initial_helium_pressure[16]; | |
332 float initial_nitrogen_pressure[16]; | |
333 float helium_rate; | |
334 float fraction_helium_begin; | |
335 float fraction_helium_end; | |
336 float fraction_nitrogen_begin; | |
337 float fraction_nitrogen_end; | |
338 float ending_depth_tmp = ending_depth; | |
339 float segment_time_tmp = 0; | |
340 /* loop */ | |
341 /* =============================================================================== */ | |
342 /* CALCULATIONS */ | |
343 /* =============================================================================== */ | |
344 segment_time = (ending_depth_tmp - starting_depth) / rate; | |
345 last_run_time = run_time; | |
346 run_time = last_run_time + segment_time; | |
347 do { | |
348 ending_depth_tmp = ending_depth; | |
349 if (starting_depth > ending_depth && check_gas_change && number_of_changes > 1) | |
350 { | |
351 for (i = 1; i < number_of_changes; ++i) | |
352 { | |
353 if (depth_change[i] < starting_depth && depth_change[i] > ending_depth) | |
354 { | |
355 ending_depth_tmp = depth_change[i]; | |
356 break; | |
357 } | |
358 } | |
359 for (i = 1; i < number_of_changes; ++i) | |
360 { | |
361 if (depth_change[i] >= starting_depth) | |
362 { | |
363 mix_number = mix_change[i]; | |
364 } | |
365 } | |
366 } | |
367 segment_time_tmp = (ending_depth_tmp - starting_depth) / rate; | |
368 ending_ambient_pressure = ending_depth_tmp + barometric_pressure; | |
369 starting_ambient_pressure = starting_depth + barometric_pressure; | |
370 decom_get_inert_gases( starting_ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_begin, &fraction_helium_begin ); | |
371 decom_get_inert_gases( ending_ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_end, &fraction_helium_end ); | |
372 | |
373 initial_inspired_he_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin; | |
374 initial_inspired_n2_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_nitrogen_begin; | |
375 //helium_rate = *rate * fraction_helium[mix_number - 1]; | |
376 helium_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_helium_end - initial_inspired_he_pressure)/segment_time_tmp; | |
377 //nitrogen_rate2 = *rate * fraction_nitrogen[mix_number - 1]; | |
378 nitrogen_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_nitrogen_end - initial_inspired_n2_pressure)/segment_time_tmp; | |
379 | |
380 | |
381 decom_oxygen_calculate_cns_stage_SchreinerStyle(segment_time_tmp,&pDiveSettings->decogaslist[mix_number],starting_ambient_pressure/10,ending_ambient_pressure/10,&gCNS_VPM); | |
382 //if(fabs(nitrogen_rate - nitrogen_rate2) > 0.000001) | |
383 //return -2; | |
384 for (i = 1; i <= 16; ++i) | |
385 { | |
386 initial_helium_pressure[i - 1] = helium_pressure[i - 1]; | |
387 initial_nitrogen_pressure[i - 1] = nitrogen_pressure[i - 1]; | |
388 helium_pressure[i - 1] = | |
389 schreiner_equation__2(&initial_inspired_he_pressure, | |
390 &helium_rate, | |
391 &segment_time, | |
392 &HELIUM_TIME_CONSTANT[i - 1], | |
393 &initial_helium_pressure[i - 1]); | |
394 nitrogen_pressure[i - 1] = | |
395 schreiner_equation__2(&initial_inspired_n2_pressure, | |
396 &nitrogen_rate, | |
397 &segment_time, | |
398 &NITROGEN_TIME_CONSTANT[i - 1], | |
399 &initial_nitrogen_pressure[i - 1]); | |
400 | |
401 //nextround??? | |
402 | |
403 } | |
404 starting_depth = ending_depth_tmp; | |
405 } while(ending_depth_tmp > ending_depth); | |
406 | |
407 return 0; | |
408 } /* gas_loadings_ascent_descen */ | |
409 | |
290 | 410 static float last_phase_volume_time[16]; |
411 static float n2_pressure_start_of_deco_zone[16]; | |
412 static float he_pressure_start_of_deco_zone[16]; | |
413 static float phase_volume_time[16]; | |
414 static float n2_pressure_start_of_ascent[16]; | |
415 static float he_pressure_start_of_ascent[16]; | |
416 static float run_time_start_of_deco_calc; | |
417 static float starting_depth; | |
418 static float last_run_time; | |
419 static float deco_phase_volume_time; | |
420 static float run_time_start_of_ascent; | |
421 static float rate; | |
422 static float step_size; | |
423 static _Bool vpm_violates_buehlmann; | |
38 | 424 |
290 | 425 static void vpm_calc_deco(void) |
38 | 426 { |
427 /* System generated locals */ | |
428 | |
429 //float deepest_possible_stop_depth; | |
430 // altitude_of_dive, | |
431 short i; | |
432 int j = 0; | |
433 | |
434 // float rounding_operation; | |
435 | |
436 /* =============================================================================== */ | |
437 /* INPUT PARAMETERS TO BE USED FOR STAGED DECOMPRESSION AND SAVE IN ARRAYS. */ | |
438 /* ASSIGN INITAL PARAMETERS TO BE USED AT START OF ASCENT */ | |
439 /* The user has the ability to change mix, ascent rate, and step size in any */ | |
440 /* combination at any depth during the ascent. */ | |
441 /* =============================================================================== */ | |
442 | |
443 run_time = ((float)pInput->dive_time_seconds )/ 60; | |
444 count_critical_volume_iteration = 0; | |
445 number_of_changes = 1; | |
446 | |
447 barometric_pressure = pInput->pressure_surface_bar * 10; | |
448 depth_change[0] =(pInput->pressure_ambient_bar - pInput->pressure_surface_bar)* 10; | |
449 mix_change[0] = 0; | |
450 rate_change[0 ] = -10;// neu 160215 hw, zuvor: -12; | |
451 step_size_change[0] = 3; | |
452 vpm_violates_buehlmann = false; | |
453 | |
454 for (i = 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++) | |
455 { | |
456 depth_change[i] = 0; | |
457 mix_change[i] = 0; | |
458 } | |
459 j = 0; | |
460 | |
461 for (i = 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++) | |
462 { | |
830
b7d93ff6b3b2
Added selection if an active gas shall be used for deco calculation or not:
Ideenmodellierer
parents:
305
diff
changeset
|
463 if((pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero >= depth_change[0] + 1) |
b7d93ff6b3b2
Added selection if an active gas shall be used for deco calculation or not:
Ideenmodellierer
parents:
305
diff
changeset
|
464 && (pDiveSettings->gas[pDiveSettings->decogaslist[i].GasIdInSettings].note.ub.decocalc)) |
38 | 465 continue; |
466 | |
830
b7d93ff6b3b2
Added selection if an active gas shall be used for deco calculation or not:
Ideenmodellierer
parents:
305
diff
changeset
|
467 if((pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero <= 0) |
b7d93ff6b3b2
Added selection if an active gas shall be used for deco calculation or not:
Ideenmodellierer
parents:
305
diff
changeset
|
468 || (pDiveSettings->gas[pDiveSettings->decogaslist[i].GasIdInSettings].note.ub.decocalc == 0)) |
38 | 469 break; |
470 | |
471 j++; | |
472 number_of_changes ++; | |
473 depth_change[j] = pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero ; | |
474 mix_change[j] = i; | |
475 rate_change[j] = -10;// neu 160215 hw, zuvor: -12; | |
476 step_size_change[j] = 3; | |
477 } | |
478 | |
479 starting_depth = depth_change[0] ; | |
480 mix_number = mix_change[0] ; | |
481 rate = rate_change[0]; | |
482 step_size = step_size_change[0]; | |
483 | |
484 for (i = 0; i < 16; ++i) { | |
485 he_pressure_start_of_ascent[i ] = helium_pressure[i]; | |
486 n2_pressure_start_of_ascent[i] = nitrogen_pressure[i]; | |
487 } | |
488 run_time_start_of_ascent = run_time; | |
489 if(starting_depth <= depth_start_of_deco_zone && vpm_calc_what == DECOSTOPS) | |
490 { | |
491 pVpm->deco_zone_reached = true; | |
492 depth_start_of_deco_calc = starting_depth; | |
493 critical_volume_algorithm_off = true; | |
494 } | |
495 else | |
496 { | |
497 //if(deco_zone_reached) | |
498 //{ | |
499 pVpm->deco_zone_reached = false; | |
500 critical_volume_algorithm_off = false; | |
501 //max_first_stop_depth = 0; | |
502 //max_first_stop_depth_save = 0; | |
503 //} | |
504 /* =============================================================================== */ | |
505 /* BEGIN PROCESS OF ASCENT AND DECOMPRESSION */ | |
506 /* First, calculate the regeneration of critical radii that takes place over */ | |
507 /* the dive time. The regeneration time constant has a time scale of weeks */ | |
508 /* so this will have very little impact on dives of normal length, but will */ | |
509 /* have major impact for saturation dives. */ | |
510 /* =============================================================================== */ | |
511 | |
512 nuclear_regeneration(&run_time); | |
513 | |
514 /* =============================================================================== */ | |
515 /* CALCULATE INITIAL ALLOWABLE GRADIENTS FOR ASCENT */ | |
516 /* This is based on the maximum effective crushing pressure on critical radii */ | |
517 /* in each compartment achieved during the dive profile. */ | |
518 /* =============================================================================== */ | |
519 | |
520 calc_initial_allowable_gradient(); | |
521 | |
522 /* =============================================================================== */ | |
523 /* SAVE VARIABLES AT START OF ASCENT (END OF BOTTOM TIME) SINCE THESE WILL */ | |
524 /* BE USED LATER TO COMPUTE THE FINAL ASCENT PROFILE THAT IS WRITTEN TO THE */ | |
525 /* OUTPUT FILE. */ | |
526 /* The VPM uses an iterative process to compute decompression schedules so */ | |
527 /* there will be more than one pass through the decompression loop. */ | |
528 /* =============================================================================== */ | |
529 | |
530 /* =============================================================================== */ | |
531 /* CALCULATE THE DEPTH WHERE THE DECOMPRESSION ZONE BEGINS FOR THIS PROFILE */ | |
532 /* BASED ON THE INITIAL ASCENT PARAMETERS AND WRITE THE DEEPEST POSSIBLE */ | |
533 /* DECOMPRESSION STOP DEPTH TO THE OUTPUT FILE */ | |
534 /* Knowing where the decompression zone starts is very important. Below */ | |
535 /* that depth there is no possibility for bubble formation because there */ | |
536 /* will be no supersaturation gradients. Deco stops should never start */ | |
537 /* below the deco zone. The deepest possible stop deco stop depth is */ | |
538 /* defined as the next "standard" stop depth above the point where the */ | |
539 /* leading compartment enters the deco zone. Thus, the program will not */ | |
540 /* base this calculation on step sizes larger than 10 fsw or 3 msw. The */ | |
541 /* deepest possible stop depth is not used in the program, per se, rather */ | |
542 /* it is information to tell the diver where to start putting on the brakes */ | |
543 /* during ascent. This should be prominently displayed by any deco program. */ | |
544 /* =============================================================================== */ | |
545 | |
546 calc_start_of_deco_zone(&starting_depth, &rate, &depth_start_of_deco_zone); | |
547 /* =============================================================================== */ | |
548 /* TEMPORARILY ASCEND PROFILE TO THE START OF THE DECOMPRESSION ZONE, SAVE */ | |
549 /* VARIABLES AT THIS POINT, AND INITIALIZE VARIABLES FOR CRITICAL VOLUME LOOP */ | |
550 /* The iterative process of the VPM Critical Volume Algorithm will operate */ | |
551 /* only in the decompression zone since it deals with excess gas volume */ | |
552 /* released as a result of supersaturation gradients (not possible below the */ | |
553 /* decompression zone). */ | |
554 /* =============================================================================== */ | |
555 gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, starting_depth, depth_start_of_deco_zone, rate, true); | |
556 | |
557 run_time_start_of_deco_zone = run_time; | |
558 depth_start_of_deco_calc = depth_start_of_deco_zone; | |
559 | |
560 for (i = 0; i < 16; ++i) | |
561 { | |
562 pVpm->max_actual_gradient[i] = 0.; | |
563 } | |
564 } | |
565 | |
566 for (i = 0; i < 16; ++i) | |
567 { | |
568 surface_phase_volume_time[i] = 0.; | |
569 last_phase_volume_time[i] = 0.; | |
570 he_pressure_start_of_deco_zone[i] = helium_pressure[i]; | |
571 n2_pressure_start_of_deco_zone[i] = nitrogen_pressure[i]; | |
572 //pVpm->max_actual_gradient[i] = 0.; | |
573 } | |
574 run_time_start_of_deco_calc = run_time; | |
575 } | |
576 /* =============================================================================== */ | |
577 /* START OF CRITICAL VOLUME LOOP */ | |
578 /* This loop operates between Lines 50 and 100. If the Critical Volume */ | |
579 /* Algorithm is toggled "off" in the program settings, there will only be */ | |
580 /* one pass through this loop. Otherwise, there will be two or more passes */ | |
581 /* through this loop until the deco schedule is "converged" - that is when a */ | |
582 /* comparison between the phase volume time of the present iteration and the */ | |
583 /* last iteration is less than or equal to one minute. This implies that */ | |
584 /* the volume of released gas in the most recent iteration differs from the */ | |
585 /* "critical" volume limit by an acceptably small amount. The critical */ | |
586 /* volume limit is set by the Critical Volume Parameter Lambda in the program */ | |
587 /* settings (default setting is 7500 fsw-min with adjustability range from */ | |
588 /* from 6500 to 8300 fsw-min according to Bruce Wienke). */ | |
589 /* =============================================================================== */ | |
590 /* L50: */ | |
591 | |
290 | 592 static float deco_stop_depth; |
593 static int vpm_calc_critcal_volume(_Bool begin, | |
38 | 594 _Bool calc_nulltime) |
595 { /* loop will run continuous there is an exit stateme */ | |
596 | |
597 short i; | |
598 | |
599 float rounding_operation2; | |
600 //float ending_depth; | |
601 float deco_ceiling_depth; | |
602 | |
603 //float deco_time; | |
604 int count = 0; | |
605 _Bool first_stop; | |
606 int dp = 0; | |
607 float tissue_He_saturation[16]; | |
608 float tissue_N2_saturation[16]; | |
609 float vpm_buehlmann_safety_gradient = 1.0f - (((float)pDiveSettings->vpm_conservatism) / 40); | |
610 /* =============================================================================== */ | |
611 /* CALCULATE CURRENT DECO CEILING BASED ON ALLOWABLE SUPERSATURATION */ | |
612 /* GRADIENTS AND SET FIRST DECO STOP. CHECK TO MAKE SURE THAT SELECTED STEP */ | |
613 /* SIZE WILL NOT ROUND UP FIRST STOP TO A DEPTH THAT IS BELOW THE DECO ZONE. */ | |
614 /* =============================================================================== */ | |
615 if(begin) | |
616 { | |
617 if(depth_start_of_deco_calc < max_first_stop_depth ) | |
618 { | |
619 if(vpm_b) | |
620 { | |
621 BOYLES_LAW_COMPENSATION(&max_first_stop_depth, &depth_start_of_deco_calc, &step_size); | |
622 } | |
623 calc_deco_ceiling(&deco_ceiling_depth, false); | |
624 } | |
625 else | |
626 calc_deco_ceiling(&deco_ceiling_depth, true); | |
627 | |
628 | |
629 if (deco_ceiling_depth <= 0.0f) { | |
630 deco_stop_depth = 0.0f; | |
631 } else { | |
632 rounding_operation2 = deco_ceiling_depth / step_size + ( float)0.5f; | |
633 deco_stop_depth = r_nint(&rounding_operation2) * step_size; | |
634 } | |
635 | |
636 // buehlmann safety | |
637 if(buehlmannSafety) | |
638 { | |
639 for (i = 0; i < 16; i++) | |
640 { | |
641 tissue_He_saturation[i] = helium_pressure[i] / 10; | |
642 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10; | |
643 } | |
644 | |
645 if(!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_stop_depth / 10.0f) + pInput->pressure_surface_bar)) | |
646 { | |
647 | |
648 vpm_violates_buehlmann = true; | |
649 do { | |
650 deco_stop_depth += 3; | |
651 } while (!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_stop_depth / 10.0f) + pInput->pressure_surface_bar)); | |
652 } | |
653 } | |
654 | |
655 /* =============================================================================== */ | |
656 /* PERFORM A SEPARATE "PROJECTED ASCENT" OUTSIDE OF THE MAIN PROGRAM TO MAKE */ | |
657 /* SURE THAT AN INCREASE IN GAS LOADINGS DURING ASCENT TO THE FIRST STOP WILL */ | |
658 /* NOT CAUSE A VIOLATION OF THE DECO CEILING. IF SO, ADJUST THE FIRST STOP */ | |
659 /* DEEPER BASED ON STEP SIZE UNTIL A SAFE ASCENT CAN BE MADE. */ | |
660 /* Note: this situation is a possibility when ascending from extremely deep */ | |
661 /* dives or due to an unusual gas mix selection. */ | |
662 /* CHECK AGAIN TO MAKE SURE THAT ADJUSTED FIRST STOP WILL NOT BE BELOW THE */ | |
663 /* DECO ZONE. */ | |
664 /* =============================================================================== */ | |
665 if (deco_stop_depth < depth_start_of_deco_calc) | |
666 { | |
667 projected_ascent(&depth_start_of_deco_calc, &rate, &deco_stop_depth, &step_size); | |
668 } | |
669 | |
670 /*if (deco_stop_depth > depth_start_of_deco_zone) { | |
671 printf("\t\n"); | |
672 printf(fmt_905); | |
673 printf(fmt_900); | |
674 printf("\nPROGRAM TERMINATED\n"); | |
675 exit(1); | |
676 }*/ | |
677 | |
678 /* =============================================================================== */ | |
679 /* HANDLE THE SPECIAL CASE WHEN NO DECO STOPS ARE REQUIRED - ASCENT CAN BE */ | |
680 /* MADE DIRECTLY TO THE SURFACE */ | |
681 /* Write ascent data to output file and exit the Critical Volume Loop. */ | |
682 /* =============================================================================== */ | |
683 | |
684 if (deco_stop_depth == 0.0f) | |
685 { | |
686 if(calc_nulltime) | |
687 { | |
688 return CALC_END; | |
689 } | |
690 if(pVpm->deco_zone_reached) | |
691 { | |
692 for(dp = 0;dp < DECOINFO_STRUCT_MAX_STOPS;dp++) | |
693 { | |
694 pDecoInfo->output_stop_length_seconds[dp] = 0; | |
695 } | |
696 pDecoInfo->output_ndl_seconds = 0; | |
697 } | |
698 | |
292 | 699 return CALC_NDL; |
38 | 700 /* exit the critical volume l */ |
701 } | |
702 | |
703 /* =============================================================================== */ | |
704 /* ASSIGN VARIABLES FOR ASCENT FROM START OF DECO ZONE TO FIRST STOP. SAVE */ | |
705 /* FIRST STOP DEPTH FOR LATER USE WHEN COMPUTING THE FINAL ASCENT PROFILE */ | |
706 /* =============================================================================== */ | |
707 deco_stop_depth = fmaxf(deco_stop_depth,(float)pDiveSettings->last_stop_depth_bar * 10); | |
708 starting_depth = depth_start_of_deco_calc; | |
709 first_stop_depth = deco_stop_depth; | |
710 first_stop = true; | |
711 } | |
712 /* =============================================================================== */ | |
713 /* DECO STOP LOOP BLOCK WITHIN CRITICAL VOLUME LOOP */ | |
714 /* This loop computes a decompression schedule to the surface during each */ | |
715 /* iteration of the critical volume loop. No output is written from this */ | |
716 /* loop, rather it computes a schedule from which the in-water portion of the */ | |
717 /* total phase volume time (Deco_Phase_Volume_Time) can be extracted. Also, */ | |
718 /* the gas loadings computed at the end of this loop are used the subroutine */ | |
719 /* which computes the out-of-water portion of the total phase volume time */ | |
720 /* (Surface_Phase_Volume_Time) for that schedule. */ | |
721 | |
722 /* Note that exit is made from the loop after last ascent is made to a deco */ | |
723 /* stop depth that is less than or equal to zero. A final deco stop less */ | |
724 /* than zero can happen when the user makes an odd step size change during */ | |
725 /* ascent - such as specifying a 5 msw step size change at the 3 msw stop! */ | |
726 /* =============================================================================== */ | |
727 | |
728 while(true) /* loop will run continuous there is an break statement */ | |
729 { | |
730 if(starting_depth > deco_stop_depth ) | |
731 gas_loadings_ascent_descen(helium_pressure, nitrogen_pressure, starting_depth, deco_stop_depth, rate,first_stop); | |
732 | |
733 first_stop = false; | |
734 if (deco_stop_depth <= 0.0f) | |
735 { | |
736 break; | |
737 } | |
738 if (number_of_changes > 1) | |
739 { | |
740 int i1 = number_of_changes; | |
741 for (i = 2; i <= i1; ++i) { | |
742 if (depth_change[i - 1] >= deco_stop_depth) | |
743 { | |
744 mix_number = mix_change[i - 1]; | |
745 rate = rate_change[i - 1]; | |
746 step_size = step_size_change[i - 1]; | |
747 } | |
748 } | |
749 } | |
750 if(vpm_b) | |
751 { | |
752 float fist_stop_depth2 = fmaxf(first_stop_depth,max_first_stop_depth); | |
753 BOYLES_LAW_COMPENSATION(&fist_stop_depth2, &deco_stop_depth, &step_size); | |
754 } | |
755 decompression_stop(&deco_stop_depth, &step_size, false); | |
756 starting_depth = deco_stop_depth; | |
757 | |
758 if(deco_stop_depth == (float)pDiveSettings->last_stop_depth_bar * 10) | |
759 deco_stop_depth = 0; | |
760 else | |
761 { | |
762 deco_stop_depth = deco_stop_depth - step_size; | |
763 deco_stop_depth = fmaxf(deco_stop_depth,(float)pDiveSettings->last_stop_depth_bar * 10); | |
764 } | |
765 | |
766 count++; | |
767 //if(count > 14) | |
768 //return CALC_CRITICAL2; | |
769 /* L60: */ | |
770 } | |
771 | |
772 return vpm_check_converged(calc_nulltime); | |
773 } | |
774 /* =============================================================================== */ | |
775 /* COMPUTE TOTAL PHASE VOLUME TIME AND MAKE CRITICAL VOLUME COMPARISON */ | |
776 /* The deco phase volume time is computed from the run time. The surface */ | |
777 /* phase volume time is computed in a subroutine based on the surfacing gas */ | |
778 /* loadings from previous deco loop block. Next the total phase volume time */ | |
779 /* (in-water + surface) for each compartment is compared against the previous */ | |
780 /* total phase volume time. The schedule is converged when the difference is */ | |
781 /* less than or equal to 1 minute in any one of the 16 compartments. */ | |
782 | |
783 /* Note: the "phase volume time" is somewhat of a mathematical concept. */ | |
784 /* It is the time divided out of a total integration of supersaturation */ | |
785 /* gradient x time (in-water and surface). This integration is multiplied */ | |
786 /* by the excess bubble number to represent the amount of free-gas released */ | |
787 /* as a result of allowing a certain number of excess bubbles to form. */ | |
788 /* =============================================================================== */ | |
789 /* end of deco stop loop */ | |
790 | |
290 | 791 static int vpm_check_converged(_Bool calc_nulltime) |
38 | 792 { |
793 | |
794 short i; | |
795 float critical_volume_comparison; | |
796 float r1; | |
797 _Bool schedule_converged = false; | |
798 | |
799 | |
800 deco_phase_volume_time = run_time - run_time_start_of_deco_zone; | |
801 calc_surface_phase_volume_time(); | |
802 | |
803 for (i = 1; i <= 16; ++i) | |
804 { | |
805 phase_volume_time[i - 1] = | |
806 deco_phase_volume_time + surface_phase_volume_time[i - 1]; | |
807 critical_volume_comparison = (r1 = phase_volume_time[i - 1] - last_phase_volume_time[i - 1], fabs(r1)); | |
808 | |
809 if (critical_volume_comparison <= 1.0f) | |
810 { | |
811 schedule_converged = true; | |
812 } | |
813 } | |
814 | |
815 /* =============================================================================== */ | |
816 /* CRITICAL VOLUME DECISION TREE BETWEEN LINES 70 AND 99 */ | |
817 /* There are two options here. If the Critical Volume Agorithm setting is */ | |
818 /* "on" and the schedule is converged, or the Critical Volume Algorithm */ | |
819 /* setting was "off" in the first place, the program will re-assign variables */ | |
820 /* to their values at the start of ascent (end of bottom time) and process */ | |
821 /* a complete decompression schedule once again using all the same ascent */ | |
822 /* parameters and first stop depth. This decompression schedule will match */ | |
823 /* the last iteration of the Critical Volume Loop and the program will write */ | |
824 /* the final deco schedule to the output file. */ | |
825 | |
826 /* Note: if the Critical Volume Agorithm setting was "off", the final deco */ | |
827 /* schedule will be based on "Initial Allowable Supersaturation Gradients." */ | |
828 /* If it was "on", the final schedule will be based on "Adjusted Allowable */ | |
829 /* Supersaturation Gradients" (gradients that are "relaxed" as a result of */ | |
830 /* the Critical Volume Algorithm). */ | |
831 | |
832 /* If the Critical Volume Agorithm setting is "on" and the schedule is not */ | |
833 /* converged, the program will re-assign variables to their values at the */ | |
834 /* start of the deco zone and process another trial decompression schedule. */ | |
835 /* =============================================================================== */ | |
836 /* L70: */ | |
837 //Not more than 4 iteration allowed | |
838 count_critical_volume_iteration++; | |
839 if(count_critical_volume_iteration > 4) | |
840 { | |
841 //return CALC_FINAL_DECO; | |
842 if(calc_nulltime) | |
843 return CALC_FINAL_DECO; | |
844 else | |
845 return vpm_calc_final_deco(true); | |
846 } | |
847 if (schedule_converged || critical_volume_algorithm_off) | |
848 { | |
849 | |
850 //return CALC_FINAL_DECO; | |
851 if(calc_nulltime) | |
852 return CALC_FINAL_DECO; | |
853 else | |
854 return vpm_calc_final_deco(true); | |
855 /* final deco schedule */ | |
856 /* exit critical volume l */ | |
857 | |
858 /* =============================================================================== */ | |
859 /* IF SCHEDULE NOT CONVERGED, COMPUTE RELAXED ALLOWABLE SUPERSATURATION */ | |
860 /* GRADIENTS WITH VPM CRITICAL VOLUME ALGORITHM AND PROCESS ANOTHER */ | |
861 /* ITERATION OF THE CRITICAL VOLUME LOOP */ | |
862 /* =============================================================================== */ | |
863 | |
864 } else { | |
865 critical_volume(&deco_phase_volume_time); | |
866 deco_phase_volume_time = 0.; | |
867 run_time = run_time_start_of_deco_calc; | |
868 starting_depth = depth_start_of_deco_calc; | |
869 mix_number = mix_change[0]; | |
870 rate = rate_change[0]; | |
871 step_size = step_size_change[0]; | |
872 for (i = 1; i <= 16; ++i) | |
873 { | |
874 last_phase_volume_time[i - 1] = phase_volume_time[i - 1]; | |
875 helium_pressure[i - 1] = he_pressure_start_of_deco_zone[i - 1]; | |
876 nitrogen_pressure[i - 1] = n2_pressure_start_of_deco_zone[i - 1]; | |
877 } | |
878 if(calc_nulltime) | |
879 return CALC_CRITICAL; | |
880 else | |
881 return vpm_calc_critcal_volume(true, false); | |
882 } | |
883 /* end of critical volume decision */ | |
884 /* L100: */ | |
885 // }/* end of critical vol loop */ | |
886 } | |
887 | |
290 | 888 static void vpm_calc_deco_ceiling(void) |
38 | 889 { |
890 | |
891 short i; | |
892 // hw 1601209 float r1; | |
893 // hw 1601209 float stop_time; | |
894 // hw 1601209 int count = 0; | |
895 //static int dp_max; | |
896 //static float surfacetime; | |
897 // _Bool first_stop = false; | |
898 float tissue_He_saturation[16]; | |
899 float tissue_N2_saturation[16]; | |
900 float vpm_buehlmann_safety_gradient = 1.0f - (((float)pDiveSettings->vpm_conservatism) / 40); | |
901 //max_first_stop_depth = fmaxf(first_stop_depth,max_first_stop_depth); | |
902 | |
903 /** CALC DECO Ceiling ******************************************************************/ | |
904 /** Not when Future stops */ | |
905 if(vpm_calc_what == DECOSTOPS) | |
906 { | |
907 | |
908 for (i = 1; i <= 16; ++i) | |
909 { | |
910 helium_pressure[i - 1] = he_pressure_start_of_deco_zone[i - 1]; | |
911 nitrogen_pressure[i - 1] = n2_pressure_start_of_deco_zone[i - 1]; | |
912 } | |
913 run_time = run_time_start_of_ascent;// run_time_start_of_ascent; | |
914 starting_depth = depth_change[0]; | |
915 mix_number = mix_change[0]; | |
916 rate = rate_change[0]; | |
917 //gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, starting_depth, depth_start_of_deco_calc, rate, true); | |
918 | |
919 float deco_ceiling_depth = 0.0f; | |
920 if(depth_start_of_deco_calc > max_deco_ceiling_depth) | |
921 { | |
922 calc_deco_ceiling(&deco_ceiling_depth, true); | |
923 } | |
924 if(buehlmannSafety) | |
925 { | |
926 for (i = 0; i < 16; i++) | |
927 { | |
928 tissue_He_saturation[i] = helium_pressure[i] / 10; | |
929 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10; | |
930 } | |
931 | |
932 if(!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar)) | |
933 { | |
934 | |
935 vpm_violates_buehlmann = true; | |
936 do { | |
937 deco_ceiling_depth += 0.1f; | |
938 } while (!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar)); | |
939 } | |
940 } | |
941 | |
942 if (deco_ceiling_depth < depth_start_of_deco_calc) | |
943 { | |
944 projected_ascent(&depth_start_of_deco_calc, &rate, &deco_ceiling_depth, &step_size); | |
945 } | |
946 | |
947 max_deco_ceiling_depth = fmaxf(max_deco_ceiling_depth,deco_ceiling_depth); | |
948 | |
949 if(depth_start_of_deco_calc > deco_ceiling_depth) | |
950 { | |
951 gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, depth_start_of_deco_calc,deco_ceiling_depth, rate, true); | |
952 //surfacetime += segment_time; | |
953 } | |
954 | |
955 if(vpm_b) | |
956 { | |
957 BOYLES_LAW_COMPENSATION(&max_deco_ceiling_depth, &deco_ceiling_depth, &step_size); | |
958 } | |
959 calc_deco_ceiling(&deco_ceiling_depth, false); | |
960 | |
961 // buehlmann safety | |
962 if(vpm_violates_buehlmann) | |
963 { | |
964 for (i = 0; i < 16; i++) | |
965 { | |
966 tissue_He_saturation[i] = helium_pressure[i] / 10; | |
967 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10; | |
968 } | |
969 | |
970 if(!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar)) | |
971 { | |
972 | |
973 vpm_violates_buehlmann = true; | |
974 do { | |
975 deco_ceiling_depth += 0.1f; | |
976 } while (!decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (deco_ceiling_depth / 10.0f) + pInput->pressure_surface_bar)); | |
977 } | |
978 } | |
979 // output_ceiling_meter | |
980 if(deco_ceiling_depth > first_stop_depth) | |
981 deco_ceiling_depth = first_stop_depth; | |
982 pDecoInfo->output_ceiling_meter = deco_ceiling_depth ; | |
983 } | |
984 else | |
985 { | |
986 pDecoInfo->output_ceiling_meter = 0; | |
987 } | |
988 | |
989 // fix hw 160627 | |
990 if(pDecoInfo->output_ceiling_meter < 0) | |
991 pDecoInfo->output_ceiling_meter = 0; | |
992 | |
993 /*** End CALC ceiling ***************************************************/ | |
994 } | |
995 | |
996 | |
997 /* =============================================================================== */ | |
998 /* DECO STOP LOOP BLOCK FOR FINAL DECOMPRESSION SCHEDULE */ | |
999 /* =============================================================================== */ | |
1000 | |
290 | 1001 static int vpm_calc_final_deco(_Bool begin) |
38 | 1002 { |
1003 short i; | |
1004 float r1; | |
1005 float stop_time; | |
1006 int count = 0; | |
1007 static int dp_max; | |
1008 static float surfacetime; | |
1009 _Bool first_stop = false; | |
1010 max_first_stop_depth = fmaxf(first_stop_depth,max_first_stop_depth); | |
1011 if(begin) | |
1012 { | |
1013 gCNS_VPM = 0; | |
1014 dp_max = 0; | |
1015 for (i = 1; i <= 16; ++i) | |
1016 { | |
1017 helium_pressure[i - 1] = | |
1018 he_pressure_start_of_ascent[i - 1]; | |
1019 nitrogen_pressure[i - 1] = | |
1020 n2_pressure_start_of_ascent[i - 1]; | |
1021 } | |
1022 run_time = run_time_start_of_ascent;// run_time_start_of_ascent; | |
1023 starting_depth = depth_change[0]; | |
1024 mix_number = mix_change[0]; | |
1025 rate = rate_change[0]; | |
1026 step_size = step_size_change[0]; | |
1027 deco_stop_depth = first_stop_depth; | |
1028 max_first_stop_depth = fmaxf(first_stop_depth,max_first_stop_depth); | |
1029 last_run_time = 0.; | |
1030 | |
1031 | |
1032 | |
1033 /* =============================================================================== */ | |
1034 /* DECO STOP LOOP BLOCK FOR FINAL DECOMPRESSION SCHEDULE */ | |
1035 /* =============================================================================== */ | |
1036 surfacetime = 0; | |
1037 first_stop = true; | |
1038 } | |
1039 | |
1040 while(true) /* loop will run continuous until there is an break statement */ | |
1041 { | |
1042 if(starting_depth > deco_stop_depth) | |
1043 { | |
1044 gas_loadings_ascent_descen(helium_pressure,nitrogen_pressure, starting_depth,deco_stop_depth, rate, first_stop); | |
1045 surfacetime += segment_time; | |
1046 } | |
1047 | |
1048 /* =============================================================================== */ | |
1049 /* DURING FINAL DECOMPRESSION SCHEDULE PROCESS, COMPUTE MAXIMUM ACTUAL */ | |
1050 /* SUPERSATURATION GRADIENT RESULTING IN EACH COMPARTMENT */ | |
1051 /* If there is a repetitive dive, this will be used later in the VPM */ | |
1052 /* Repetitive Algorithm to adjust the values for critical radii. */ | |
1053 /* =============================================================================== */ | |
1054 if(vpm_calc_what == DECOSTOPS) | |
1055 calc_max_actual_gradient(&deco_stop_depth); | |
1056 | |
1057 if (deco_stop_depth <= 0.0f) { | |
1058 break; | |
1059 } | |
1060 if (number_of_changes > 1) | |
1061 { | |
1062 int i1 = number_of_changes; | |
1063 for (i = 2; i <= i1; ++i) | |
1064 { | |
1065 if (depth_change[i - 1] >= deco_stop_depth) | |
1066 { | |
1067 mix_number = mix_change[i - 1]; | |
1068 rate = rate_change[i - 1]; | |
1069 step_size = step_size_change[i - 1]; | |
1070 } | |
1071 } | |
1072 } | |
1073 | |
1074 if(first_stop) | |
1075 { | |
1076 run_time_first_stop = run_time; | |
1077 first_stop = false; | |
1078 } | |
1079 if(vpm_b) | |
1080 { | |
1081 BOYLES_LAW_COMPENSATION(&max_first_stop_depth, &deco_stop_depth, &step_size); | |
1082 } | |
1083 decompression_stop(&deco_stop_depth, &step_size, true); | |
1084 | |
1085 /* =============================================================================== */ | |
1086 /* This next bit justs rounds up the stop time at the first stop to be in */ | |
1087 /* whole increments of the minimum stop time (to make for a nice deco table). */ | |
1088 /* =============================================================================== */ | |
1089 | |
1090 if (last_run_time == 0.0f) | |
1091 { | |
1092 r1 = segment_time / minimum_deco_stop_time + 0.5f; | |
1093 stop_time = r_int(&r1) * minimum_deco_stop_time; | |
1094 } else { | |
1095 stop_time = run_time - last_run_time; | |
1096 } | |
1097 stop_time = segment_time; | |
1098 surfacetime += stop_time; | |
1099 if((vpm_calc_what == DECOSTOPS) || (vpm_calc_what == BAILOUTSTOPS)) | |
1100 { | |
1101 int dp = 0; | |
1102 if(deco_stop_depth == (float)pDiveSettings->last_stop_depth_bar * 10) | |
1103 { | |
1104 dp = 0; | |
1105 } | |
1106 else | |
1107 { | |
1108 dp = 1 + (int)((deco_stop_depth - (pDiveSettings->input_second_to_last_stop_depth_bar * 10)) / step_size); | |
1109 } | |
1110 dp_max = (int)fmaxf(dp_max,dp); | |
1111 if(dp < DECOINFO_STRUCT_MAX_STOPS) | |
1112 { | |
1113 int stop_time_seconds = fminf((999 * 60), (int)(stop_time *60)); | |
1114 // | |
1115 | |
1116 //if(vpm_calc_what == DECOSTOPS) | |
1117 pDecoInfo->output_stop_length_seconds[dp] = (unsigned short)stop_time_seconds; | |
1118 //else | |
1119 //decostop_bailout[dp] = (unsigned short)stop_time_seconds; | |
1120 } | |
1121 } | |
1122 | |
1123 | |
1124 /* =============================================================================== */ | |
1125 /* DURING FINAL DECOMPRESSION SCHEDULE, IF MINIMUM STOP TIME PARAMETER IS A */ | |
1126 /* WHOLE NUMBER (i.e. 1 minute) THEN WRITE DECO SCHEDULE USING short */ | |
1127 /* NUMBERS (looks nicer). OTHERWISE, USE DECIMAL NUMBERS. */ | |
1128 /* Note: per the request of a noted exploration diver(!), program now allows */ | |
1129 /* a minimum stop time of less than one minute so that total ascent time can */ | |
1130 /* be minimized on very long dives. In fact, with step size set at 1 fsw or */ | |
1131 /* 0.2 msw and minimum stop time set at 0.1 minute (6 seconds), a near */ | |
1132 /* continuous decompression schedule can be computed. */ | |
1133 /* =============================================================================== */ | |
1134 | |
1135 starting_depth = deco_stop_depth; | |
1136 if(deco_stop_depth == (float)pDiveSettings->last_stop_depth_bar * 10) | |
1137 deco_stop_depth = 0; | |
1138 else | |
1139 { | |
1140 deco_stop_depth = deco_stop_depth - step_size; | |
1141 deco_stop_depth = fmaxf(deco_stop_depth,(float)pDiveSettings->last_stop_depth_bar * 10); | |
1142 } | |
1143 | |
1144 last_run_time = run_time; | |
1145 count++; | |
1146 //if(count > 14) | |
1147 //return CALC_FINAL_DECO2; | |
1148 /* L80: */ | |
1149 } /* for final deco sche */ | |
1150 | |
1151 if( (vpm_calc_what == DECOSTOPS) || (vpm_calc_what == BAILOUTSTOPS)) | |
1152 { | |
1153 for(int dp = dp_max +1;dp < DECOINFO_STRUCT_MAX_STOPS;dp++) | |
1154 { | |
1155 //if(vpm_calc_what == DECOSTOPS) | |
1156 pDecoInfo->output_stop_length_seconds[dp] = 0; | |
1157 //else | |
1158 //decostop_bailout[dp] = 0; | |
1159 } | |
1160 } | |
1161 pDecoInfo->output_time_to_surface_seconds = (int)(surfacetime * 60); | |
1162 pDecoInfo->output_ndl_seconds = 0; | |
1163 | |
1164 vpm_calc_deco_ceiling(); | |
1165 /* end of deco stop lo */ | |
1166 return CALC_END; | |
1167 } | |
1168 | |
1169 /* =============================================================================== */ | |
1170 /* SUBROUTINE NUCLEAR_REGENERATION */ | |
1171 /* Purpose: This subprogram calculates the regeneration of VPM critical */ | |
1172 /* radii that takes place over the dive time. The regeneration time constant */ | |
1173 /* has a time scale of weeks so this will have very little impact on dives of */ | |
1174 /* normal length, but will have a major impact for saturation dives. */ | |
1175 /* =============================================================================== */ | |
1176 | |
290 | 1177 static int nuclear_regeneration(float *dive_time) |
38 | 1178 { |
1179 /* Local variables */ | |
1180 float crush_pressure_adjust_ratio_he, | |
1181 ending_radius_n2, | |
1182 ending_radius_he; | |
1183 short i; | |
1184 float crushing_pressure_pascals_n2, | |
1185 crushing_pressure_pascals_he, | |
1186 adj_crush_pressure_n2_pascals, | |
1187 adj_crush_pressure_he_pascals, | |
1188 crush_pressure_adjust_ratio_n2; | |
1189 | |
1190 /* loop */ | |
1191 /* =============================================================================== */ | |
1192 /* CALCULATIONS */ | |
1193 /* First convert the maximum crushing pressure obtained for each compartment */ | |
1194 /* to Pascals. Next, compute the ending radius for helium and nitrogen */ | |
1195 /* critical nuclei in each compartment. */ | |
1196 /* =============================================================================== */ | |
1197 | |
1198 for (i = 1; i <= 16; ++i) | |
1199 { | |
1200 crushing_pressure_pascals_he = | |
1201 pVpm->max_crushing_pressure_he[i - 1] / UNITS_FACTOR * 101325.0f; | |
1202 crushing_pressure_pascals_n2 = | |
1203 pVpm->max_crushing_pressure_n2[i - 1] / UNITS_FACTOR * 101325.0f; | |
1204 ending_radius_he = | |
1205 1.0f / (crushing_pressure_pascals_he / | |
1206 ((SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) * 2.0f) + | |
1207 1.0f / pVpm->adjusted_critical_radius_he[i - 1]); | |
1208 ending_radius_n2 = | |
1209 1.0f / (crushing_pressure_pascals_n2 / | |
1210 ((SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) * 2.0f) + | |
1211 1.0f / pVpm->adjusted_critical_radius_n2[i - 1]); | |
1212 | |
1213 /* =============================================================================== */ | |
1214 /* A "regenerated" radius for each nucleus is now calculated based on the */ | |
1215 /* regeneration time constant. This means that after application of */ | |
1216 /* crushing pressure and reduction in radius, a nucleus will slowly grow */ | |
1217 /* back to its original initial radius over a period of time. This */ | |
1218 /* phenomenon is probabilistic in nature and depends on absolute temperature. */ | |
1219 /* It is independent of crushing pressure. */ | |
1220 /* =============================================================================== */ | |
1221 | |
1222 regenerated_radius_he[i - 1] = | |
1223 pVpm->adjusted_critical_radius_he[i - 1] + | |
1224 (ending_radius_he - pVpm->adjusted_critical_radius_he[i - 1]) * | |
1225 expf(-(*dive_time) / REGENERATION_TIME_CONSTANT); | |
1226 regenerated_radius_n2[i - 1] = | |
1227 pVpm->adjusted_critical_radius_n2[i - 1] + | |
1228 (ending_radius_n2 - pVpm->adjusted_critical_radius_n2[i - 1]) * | |
1229 expf(-(*dive_time) / REGENERATION_TIME_CONSTANT); | |
1230 | |
1231 /* =============================================================================== */ | |
1232 /* In order to preserve reference back to the initial critical radii after */ | |
1233 /* regeneration, an "adjusted crushing pressure" for the nuclei in each */ | |
1234 /* compartment must be computed. In other words, this is the value of */ | |
1235 /* crushing pressure that would have reduced the original nucleus to the */ | |
1236 /* to the present radius had regeneration not taken place. The ratio */ | |
1237 /* for adjusting crushing pressure is obtained from algebraic manipulation */ | |
1238 /* of the standard VPM equations. The adjusted crushing pressure, in lieu */ | |
1239 /* of the original crushing pressure, is then applied in the VPM Critical */ | |
1240 /* Volume Algorithm and the VPM Repetitive Algorithm. */ | |
1241 /* =============================================================================== */ | |
1242 | |
1243 crush_pressure_adjust_ratio_he = | |
1244 ending_radius_he * (pVpm->adjusted_critical_radius_he[i - 1] - | |
1245 regenerated_radius_he[i - 1]) / | |
1246 (regenerated_radius_he[i - 1] * | |
1247 (pVpm->adjusted_critical_radius_he[i - 1] - | |
1248 ending_radius_he)); | |
1249 crush_pressure_adjust_ratio_n2 = | |
1250 ending_radius_n2 * (pVpm->adjusted_critical_radius_n2[i - 1] - | |
1251 regenerated_radius_n2[i - 1]) / | |
1252 (regenerated_radius_n2[i - 1] * | |
1253 (pVpm->adjusted_critical_radius_n2[i - 1] - | |
1254 ending_radius_n2)); | |
1255 adj_crush_pressure_he_pascals = | |
1256 crushing_pressure_pascals_he * crush_pressure_adjust_ratio_he; | |
1257 adj_crush_pressure_n2_pascals = | |
1258 crushing_pressure_pascals_n2 * crush_pressure_adjust_ratio_n2; | |
1259 pVpm->adjusted_crushing_pressure_he[i - 1] = | |
1260 adj_crush_pressure_he_pascals / 101325.0f * UNITS_FACTOR; | |
1261 pVpm->adjusted_crushing_pressure_n2[i - 1] = | |
1262 adj_crush_pressure_n2_pascals / 101325.0f * UNITS_FACTOR; | |
1263 } | |
1264 return 0; | |
1265 } /* nuclear_regeneration */ | |
1266 | |
1267 /* =============================================================================== */ | |
1268 /* SUBROUTINE CALC_INITIAL_ALLOWABLE_GRADIENT */ | |
1269 /* Purpose: This subprogram calculates the initial allowable gradients for */ | |
1270 /* helium and nitrogren in each compartment. These are the gradients that */ | |
1271 /* will be used to set the deco ceiling on the first pass through the deco */ | |
1272 /* loop. If the Critical Volume Algorithm is set to "off", then these */ | |
1273 /* gradients will determine the final deco schedule. Otherwise, if the */ | |
1274 /* Critical Volume Algorithm is set to "on", these gradients will be further */ | |
1275 /* "relaxed" by the Critical Volume Algorithm subroutine. The initial */ | |
1276 /* allowable gradients are referred to as "PssMin" in the papers by Yount */ | |
1277 /* and colleauges, i.e., the minimum supersaturation pressure gradients */ | |
1278 /* that will probe bubble formation in the VPM nuclei that started with the */ | |
1279 /* designated minimum initial radius (critical radius). */ | |
1280 | |
1281 /* The initial allowable gradients are computed directly from the */ | |
1282 /* "regenerated" radii after the Nuclear Regeneration subroutine. These */ | |
1283 /* gradients are tracked separately for helium and nitrogen. */ | |
1284 /* =============================================================================== */ | |
1285 | |
290 | 1286 static int calc_initial_allowable_gradient() |
38 | 1287 { |
1288 float initial_allowable_grad_n2_pa, | |
1289 initial_allowable_grad_he_pa; | |
1290 short i; | |
1291 | |
1292 /* loop */ | |
1293 /* =============================================================================== */ | |
1294 /* CALCULATIONS */ | |
1295 /* The initial allowable gradients are computed in Pascals and then converted */ | |
1296 /* to the diving pressure units. Two different sets of arrays are used to */ | |
1297 /* save the calculations - Initial Allowable Gradients and Allowable */ | |
1298 /* Gradients. The Allowable Gradients are assigned the values from Initial */ | |
1299 /* Allowable Gradients however the Allowable Gradients can be changed later */ | |
1300 /* by the Critical Volume subroutine. The values for the Initial Allowable */ | |
1301 /* Gradients are saved in a global array for later use by both the Critical */ | |
1302 /* Volume subroutine and the VPM Repetitive Algorithm subroutine. */ | |
1303 /* =============================================================================== */ | |
1304 | |
1305 for (i = 1; i <= 16; ++i) | |
1306 { | |
1307 initial_allowable_grad_n2_pa = | |
1308 SURFACE_TENSION_GAMMA * 2.0f * | |
1309 (SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) / | |
1310 (regenerated_radius_n2[i - 1] * SKIN_COMPRESSION_GAMMAC); | |
1311 | |
1312 initial_allowable_grad_he_pa = | |
1313 SURFACE_TENSION_GAMMA * 2.0f * | |
1314 (SKIN_COMPRESSION_GAMMAC - SURFACE_TENSION_GAMMA) / | |
1315 (regenerated_radius_he[i - 1] * SKIN_COMPRESSION_GAMMAC); | |
1316 | |
1317 pVpm->initial_allowable_gradient_n2[i - 1] = | |
1318 initial_allowable_grad_n2_pa / 101325.0f * UNITS_FACTOR; | |
1319 | |
1320 pVpm->initial_allowable_gradient_he[i - 1] = | |
1321 initial_allowable_grad_he_pa / 101325.0f * UNITS_FACTOR; | |
1322 | |
1323 allowable_gradient_he[i - 1] = | |
1324 pVpm->initial_allowable_gradient_he[i - 1]; | |
1325 | |
1326 allowable_gradient_n2[i - 1] = | |
1327 pVpm->initial_allowable_gradient_n2[i - 1]; | |
1328 } | |
1329 return 0; | |
1330 } /* calc_initial_allowable_gradient */ | |
1331 | |
1332 /* =============================================================================== */ | |
1333 /* SUBROUTINE CALC_DECO_CEILING */ | |
1334 /* Purpose: This subprogram calculates the deco ceiling (the safe ascent */ | |
1335 /* depth) in each compartment, based on the allowable gradients, and then */ | |
1336 /* finds the deepest deco ceiling across all compartments. This deepest */ | |
1337 /* value (Deco Ceiling Depth) is then used by the Decompression Stop */ | |
1338 /* subroutine to determine the actual deco schedule. */ | |
1339 /* =============================================================================== */ | |
1340 | |
290 | 1341 static int calc_deco_ceiling(float *deco_ceiling_depth,_Bool fallowable) |
38 | 1342 { |
1343 /* System generated locals */ | |
1344 float r1, r2; | |
1345 /* Local variables */ | |
1346 float weighted_allowable_gradient; | |
1347 short i; | |
1348 float compartment_deco_ceiling[16], | |
1349 gas_loading, | |
1350 tolerated_ambient_pressure; | |
1351 float gradient_he, gradient_n2; | |
1352 | |
1353 if(!vpm_b) | |
1354 fallowable = true; | |
1355 /* loop */ | |
1356 /* =============================================================================== */ | |
1357 /* CALCULATIONS */ | |
1358 /* Since there are two sets of allowable gradients being tracked, one for */ | |
1359 /* helium and one for nitrogen, a "weighted allowable gradient" must be */ | |
1360 /* computed each time based on the proportions of helium and nitrogen in */ | |
1361 /* each compartment. This proportioning follows the methodology of */ | |
1362 /* Buhlmann/Keller. If there is no helium and nitrogen in the compartment, */ | |
1363 /* such as after extended periods of oxygen breathing, then the minimum value */ | |
1364 /* across both gases will be used. It is important to note that if a */ | |
1365 /* compartment is empty of helium and nitrogen, then the weighted allowable */ | |
1366 /* gradient formula cannot be used since it will result in division by zero. */ | |
1367 /* =============================================================================== */ | |
1368 | |
1369 for (i = 1; i <= 16; ++i) | |
1370 { | |
1371 | |
1372 // abfrage raus und pointer stattdessen | |
1373 if(fallowable){ | |
1374 gradient_he = allowable_gradient_he[i-1]; | |
1375 gradient_n2 = allowable_gradient_n2[i-1]; | |
1376 } | |
1377 else{ | |
1378 gradient_he = deco_gradient_he[i-1]; | |
1379 gradient_n2 = deco_gradient_n2[i-1]; | |
1380 } | |
1381 | |
1382 gas_loading = helium_pressure[i - 1] + nitrogen_pressure[i - 1]; | |
1383 | |
1384 if (gas_loading > 0) | |
1385 { | |
1386 weighted_allowable_gradient = | |
1387 (gradient_he * helium_pressure[i - 1] + | |
1388 gradient_n2 * nitrogen_pressure[i - 1]) / | |
1389 (helium_pressure[i - 1] + nitrogen_pressure[i - 1]); | |
1390 | |
1391 tolerated_ambient_pressure = | |
1392 gas_loading + | |
1393 CONSTANT_PRESSURE_OTHER_GASES - | |
1394 weighted_allowable_gradient; | |
1395 } | |
1396 else | |
1397 { | |
1398 /* Computing MIN */ | |
1399 r1 = gradient_he; | |
1400 r2 = gradient_n2; | |
1401 weighted_allowable_gradient = fminf(r1,r2); | |
1402 | |
1403 tolerated_ambient_pressure = | |
1404 CONSTANT_PRESSURE_OTHER_GASES - weighted_allowable_gradient; | |
1405 } | |
1406 | |
1407 /* =============================================================================== */ | |
1408 /* The tolerated ambient pressure cannot be less than zero absolute, i.e., */ | |
1409 /* the vacuum of outer space! */ | |
1410 /* =============================================================================== */ | |
1411 | |
1412 if (tolerated_ambient_pressure < 0) { | |
1413 tolerated_ambient_pressure = 0; | |
1414 } | |
1415 compartment_deco_ceiling[i - 1] = | |
1416 tolerated_ambient_pressure - barometric_pressure; | |
1417 } | |
1418 | |
1419 /* =============================================================================== */ | |
1420 /* The Deco Ceiling Depth is computed in a loop after all of the individual */ | |
1421 /* compartment deco ceilings have been calculated. It is important that the */ | |
1422 /* Deco Ceiling Depth (max deco ceiling across all compartments) only be */ | |
1423 /* extracted from the compartment values and not be compared against some */ | |
1424 /* initialization value. For example, if MAX(Deco_Ceiling_Depth . .) was */ | |
1425 /* compared against zero, this could cause a program lockup because sometimes */ | |
1426 /* the Deco Ceiling Depth needs to be negative (but not less than zero */ | |
1427 /* absolute ambient pressure) in order to decompress to the last stop at zero */ | |
1428 /* depth. */ | |
1429 /* =============================================================================== */ | |
1430 | |
1431 *deco_ceiling_depth = compartment_deco_ceiling[0]; | |
1432 for (i = 2; i <= 16; ++i) | |
1433 { | |
1434 /* Computing MAX */ | |
1435 r1 = *deco_ceiling_depth; | |
1436 r2 = compartment_deco_ceiling[i - 1]; | |
1437 *deco_ceiling_depth = fmaxf(r1,r2); | |
1438 } | |
1439 return 0; | |
1440 } /* calc_deco_ceiling */ | |
1441 | |
1442 | |
1443 | |
1444 /* =============================================================================== */ | |
1445 /* SUBROUTINE CALC_MAX_ACTUAL_GRADIENT */ | |
1446 /* Purpose: This subprogram calculates the actual supersaturation gradient */ | |
1447 /* obtained in each compartment as a result of the ascent profile during */ | |
1448 /* decompression. Similar to the concept with crushing pressure, the */ | |
1449 /* supersaturation gradients are not cumulative over a multi-level, staged */ | |
1450 /* ascent. Rather, it will be the maximum value obtained in any one discrete */ | |
1451 /* step of the overall ascent. Thus, the program must compute and store the */ | |
1452 /* maximum actual gradient for each compartment that was obtained across all */ | |
1453 /* steps of the ascent profile. This subroutine is invoked on the last pass */ | |
1454 /* through the deco stop loop block when the final deco schedule is being */ | |
1455 /* generated. */ | |
1456 /* */ | |
1457 /* The max actual gradients are later used by the VPM Repetitive Algorithm to */ | |
1458 /* determine if adjustments to the critical radii are required. If the max */ | |
1459 /* actual gradient did not exceed the initial alllowable gradient, then no */ | |
1460 /* adjustment will be made. However, if the max actual gradient did exceed */ | |
1461 /* the intitial allowable gradient, such as permitted by the Critical Volume */ | |
1462 /* Algorithm, then the critical radius will be adjusted (made larger) on the */ | |
1463 /* repetitive dive to compensate for the bubbling that was allowed on the */ | |
1464 /* previous dive. The use of the max actual gradients is intended to prevent */ | |
1465 /* the repetitive algorithm from being overly conservative. */ | |
1466 /* =============================================================================== */ | |
1467 | |
290 | 1468 static int calc_max_actual_gradient(float *deco_stop_depth) |
38 | 1469 { |
1470 /* System generated locals */ | |
1471 float r1; | |
1472 | |
1473 /* Local variables */ | |
1474 short i; | |
1475 float compartment_gradient; | |
1476 | |
1477 /* loop */ | |
1478 /* =============================================================================== */ | |
1479 /* CALCULATIONS */ | |
1480 /* Note: negative supersaturation gradients are meaningless for this */ | |
1481 /* application, so the values must be equal to or greater than zero. */ | |
1482 /* =============================================================================== */ | |
1483 | |
1484 for (i = 1; i <= 16; ++i) | |
1485 { | |
1486 compartment_gradient = | |
1487 helium_pressure[i - 1] + | |
1488 nitrogen_pressure[i - 1] + | |
1489 CONSTANT_PRESSURE_OTHER_GASES - | |
1490 (*deco_stop_depth + barometric_pressure); | |
1491 if (compartment_gradient <= 0.0f) { | |
1492 compartment_gradient = 0.0f; | |
1493 } | |
1494 /* Computing MAX */ | |
1495 r1 = pVpm->max_actual_gradient[i - 1]; | |
1496 pVpm->max_actual_gradient[i - 1] = fmaxf(r1, compartment_gradient); | |
1497 } | |
1498 return 0; | |
1499 } /* calc_max_actual_gradient */ | |
1500 | |
1501 /* =============================================================================== */ | |
1502 /* SUBROUTINE CALC_SURFACE_PHASE_VOLUME_TIME */ | |
1503 /* Purpose: This subprogram computes the surface portion of the total phase */ | |
1504 /* volume time. This is the time factored out of the integration of */ | |
1505 /* supersaturation gradient x time over the surface interval. The VPM */ | |
1506 /* considers the gradients that allow bubbles to form or to drive bubble */ | |
1507 /* growth both in the water and on the surface after the dive. */ | |
1508 | |
1509 /* This subroutine is a new development to the VPM algorithm in that it */ | |
1510 /* computes the time course of supersaturation gradients on the surface */ | |
1511 /* when both helium and nitrogen are present. Refer to separate write-up */ | |
1512 /* for a more detailed explanation of this algorithm. */ | |
1513 /* =============================================================================== */ | |
1514 | |
290 | 1515 static int calc_surface_phase_volume_time() |
38 | 1516 { |
1517 /* Local variables */ | |
1518 float decay_time_to_zero_gradient; | |
1519 short i; | |
1520 float integral_gradient_x_time, | |
1521 surface_inspired_n2_pressure; | |
1522 | |
1523 /* loop */ | |
1524 /* =============================================================================== */ | |
1525 /* CALCULATIONS */ | |
1526 /* =============================================================================== */ | |
1527 | |
1528 surface_inspired_n2_pressure = | |
1529 (barometric_pressure - WATER_VAPOR_PRESSURE) * 0.79f; | |
1530 for (i = 1; i <= 16; ++i) | |
1531 { | |
1532 if (nitrogen_pressure[i - 1] > surface_inspired_n2_pressure) | |
1533 { | |
1534 surface_phase_volume_time[i - 1] = | |
1535 (helium_pressure[i - 1] / HELIUM_TIME_CONSTANT[i - 1] + | |
1536 (nitrogen_pressure[i - 1] - surface_inspired_n2_pressure) / | |
1537 NITROGEN_TIME_CONSTANT[i - 1]) / | |
1538 (helium_pressure[i - 1] + nitrogen_pressure[i - 1] - | |
1539 surface_inspired_n2_pressure); | |
1540 } else if (nitrogen_pressure[i - 1] <= surface_inspired_n2_pressure && | |
1541 helium_pressure[i - 1] + nitrogen_pressure[i - 1] >= surface_inspired_n2_pressure) | |
1542 { | |
1543 decay_time_to_zero_gradient = | |
1544 1.0f / (NITROGEN_TIME_CONSTANT[i - 1] - HELIUM_TIME_CONSTANT[i - 1]) * | |
1545 log((surface_inspired_n2_pressure - nitrogen_pressure[i - 1]) / | |
1546 helium_pressure[i - 1]); | |
1547 integral_gradient_x_time = | |
1548 helium_pressure[i - 1] / | |
1549 HELIUM_TIME_CONSTANT[i - 1] * | |
1550 (1.0f - expf(-HELIUM_TIME_CONSTANT[i - 1] * | |
1551 decay_time_to_zero_gradient)) + | |
1552 (nitrogen_pressure[i - 1] - surface_inspired_n2_pressure) / | |
1553 NITROGEN_TIME_CONSTANT[i - 1] * | |
1554 (1.0f - expf(-NITROGEN_TIME_CONSTANT[i - 1] * | |
1555 decay_time_to_zero_gradient)); | |
1556 surface_phase_volume_time[i - 1] = | |
1557 integral_gradient_x_time / | |
1558 (helium_pressure[i - 1] + | |
1559 nitrogen_pressure[i - 1] - | |
1560 surface_inspired_n2_pressure); | |
1561 } else { | |
1562 surface_phase_volume_time[i - 1] = 0.0f; | |
1563 } | |
1564 } | |
1565 return 0; | |
1566 } /* calc_surface_phase_volume_time */ | |
1567 | |
1568 /* =============================================================================== */ | |
1569 /* SUBROUTINE CRITICAL_VOLUME */ | |
1570 /* Purpose: This subprogram applies the VPM Critical Volume Algorithm. This */ | |
1571 /* algorithm will compute "relaxed" gradients for helium and nitrogen based */ | |
1572 /* on the setting of the Critical Volume Parameter Lambda. */ | |
1573 /* =============================================================================== */ | |
1574 | |
290 | 1575 static int critical_volume(float *deco_phase_volume_time) |
38 | 1576 { |
1577 /* System generated locals */ | |
1578 float r1; | |
1579 | |
1580 /* Local variables */ | |
1581 float initial_allowable_grad_n2_pa, | |
1582 initial_allowable_grad_he_pa, | |
1583 parameter_lambda_pascals, b, | |
1584 c; | |
1585 short i; | |
1586 float new_allowable_grad_n2_pascals, | |
1587 phase_volume_time[16], | |
1588 new_allowable_grad_he_pascals, | |
1589 adj_crush_pressure_n2_pascals, | |
1590 adj_crush_pressure_he_pascals; | |
1591 | |
1592 /* loop */ | |
1593 /* =============================================================================== */ | |
1594 /* CALCULATIONS */ | |
1595 /* Note: Since the Critical Volume Parameter Lambda was defined in units of */ | |
1596 /* fsw-min in the original papers by Yount and colleauges, the same */ | |
1597 /* convention is retained here. Although Lambda is adjustable only in units */ | |
1598 /* of fsw-min in the program settings (range from 6500 to 8300 with default */ | |
1599 /* 7500), it will convert to the proper value in Pascals-min in this */ | |
1600 /* subroutine regardless of which diving pressure units are being used in */ | |
1601 /* the main program - feet of seawater (fsw) or meters of seawater (msw). */ | |
1602 /* The allowable gradient is computed using the quadratic formula (refer to */ | |
1603 /* separate write-up posted on the Deco List web site). */ | |
1604 /* =============================================================================== */ | |
1605 | |
1606 /** | |
1607 ****************************************************************************** | |
1608 * @brief critical_volume comment by hw | |
1609 * @version V0.0.1 | |
1610 * @date 19-April-2014 | |
1611 * @retval global: allowable_gradient_he[i], allowable_gradient_n2[i] | |
1612 ****************************************************************************** | |
1613 */ | |
1614 | |
1615 parameter_lambda_pascals = | |
1616 CRIT_VOLUME_PARAMETER_LAMBDA / 33.0f * 101325.0f; | |
1617 for (i = 1; i <= 16; ++i) | |
1618 { | |
1619 phase_volume_time[i - 1] = | |
1620 *deco_phase_volume_time + surface_phase_volume_time[i - 1]; | |
1621 } | |
1622 for (i = 1; i <= 16; ++i) | |
1623 { | |
1624 | |
1625 adj_crush_pressure_he_pascals = | |
1626 pVpm->adjusted_crushing_pressure_he[i - 1] / UNITS_FACTOR * 101325.0f; | |
1627 | |
1628 initial_allowable_grad_he_pa = | |
1629 pVpm->initial_allowable_gradient_he[i - 1] / UNITS_FACTOR * 101325.0f; | |
1630 | |
1631 b = initial_allowable_grad_he_pa + parameter_lambda_pascals * | |
1632 SURFACE_TENSION_GAMMA / ( | |
1633 SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1]); | |
1634 | |
1635 c = SURFACE_TENSION_GAMMA * ( | |
1636 SURFACE_TENSION_GAMMA * ( | |
1637 parameter_lambda_pascals * adj_crush_pressure_he_pascals)) / | |
1638 (SKIN_COMPRESSION_GAMMAC * | |
1639 (SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1])); | |
1640 /* Computing 2nd power */ | |
1641 | |
1642 r1 = b; | |
1643 | |
1644 new_allowable_grad_he_pascals = | |
1645 (b + sqrtf(r1 * r1 - c * 4.0f)) / 2.0f; | |
1646 | |
1647 /* modify global variable */ | |
1648 allowable_gradient_he[i - 1] = | |
1649 new_allowable_grad_he_pascals / 101325.0f * UNITS_FACTOR; | |
1650 } | |
1651 | |
1652 for (i = 1; i <= 16; ++i) | |
1653 { | |
1654 adj_crush_pressure_n2_pascals = | |
1655 pVpm->adjusted_crushing_pressure_n2[i - 1] / UNITS_FACTOR * 101325.0f; | |
1656 | |
1657 initial_allowable_grad_n2_pa = | |
1658 pVpm->initial_allowable_gradient_n2[i - 1] / UNITS_FACTOR * 101325.0f; | |
1659 | |
1660 b = initial_allowable_grad_n2_pa + parameter_lambda_pascals * | |
1661 SURFACE_TENSION_GAMMA / ( | |
1662 SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1]); | |
1663 | |
1664 c = SURFACE_TENSION_GAMMA * | |
1665 (SURFACE_TENSION_GAMMA * | |
1666 (parameter_lambda_pascals * adj_crush_pressure_n2_pascals)) / | |
1667 (SKIN_COMPRESSION_GAMMAC * | |
1668 (SKIN_COMPRESSION_GAMMAC * phase_volume_time[i - 1])); | |
1669 /* Computing 2nd power */ | |
1670 | |
1671 r1 = b; | |
1672 | |
1673 new_allowable_grad_n2_pascals = | |
1674 (b + sqrtf(r1 * r1 - c * 4.0f)) / 2.0f; | |
1675 | |
1676 /* modify global variable */ | |
1677 allowable_gradient_n2[i - 1] = | |
1678 new_allowable_grad_n2_pascals / 101325.0f * UNITS_FACTOR; | |
1679 } | |
1680 return 0; | |
1681 } /* critical_volume */ | |
1682 | |
1683 /* =============================================================================== */ | |
1684 /* SUBROUTINE CALC_START_OF_DECO_ZONE */ | |
1685 /* Purpose: This subroutine uses the Bisection Method to find the depth at */ | |
1686 /* which the leading compartment just enters the decompression zone. */ | |
1687 /* Source: "Numerical Recipes in Fortran 77", Cambridge University Press, */ | |
1688 /* 1992. */ | |
1689 /* =============================================================================== */ | |
1690 | |
290 | 1691 static int calc_start_of_deco_zone(float *starting_depth, |
38 | 1692 float *rate, |
1693 float *depth_start_of_deco_zone) | |
1694 { | |
1695 /* Local variables */ | |
1696 float last_diff_change, | |
1697 initial_helium_pressure, | |
1698 mid_range_nitrogen_pressure; | |
1699 short i, j; | |
1700 float initial_inspired_n2_pressure, | |
1701 cpt_depth_start_of_deco_zone, | |
1702 low_bound, | |
1703 initial_inspired_he_pressure, | |
1704 high_bound_nitrogen_pressure, | |
1705 nitrogen_rate, | |
1706 function_at_mid_range, | |
1707 function_at_low_bound, | |
1708 high_bound, | |
1709 mid_range_helium_pressure, | |
1710 mid_range_time, | |
1711 starting_ambient_pressure, | |
1712 initial_nitrogen_pressure, | |
1713 function_at_high_bound; | |
1714 | |
1715 float time_to_start_of_deco_zone, | |
1716 high_bound_helium_pressure, | |
1717 helium_rate, | |
1718 differential_change; | |
1719 float fraction_helium_begin; | |
1720 float fraction_helium_end; | |
1721 float fraction_nitrogen_begin; | |
1722 float fraction_nitrogen_end; | |
1723 float ending_ambient_pressure; | |
1724 float time_test; | |
1725 | |
1726 | |
1727 /* loop */ | |
1728 /* =============================================================================== */ | |
1729 /* CALCULATIONS */ | |
1730 /* First initialize some variables */ | |
1731 /* =============================================================================== */ | |
1732 | |
1733 *depth_start_of_deco_zone = 0.0f; | |
1734 starting_ambient_pressure = *starting_depth + barometric_pressure; | |
1735 | |
1736 //>>>>>>>>>>>>>>>>>>>> | |
1737 //Test depth to calculate helium_rate and nitrogen_rate | |
1738 ending_ambient_pressure = starting_ambient_pressure/2; | |
1739 | |
1740 time_test = (ending_ambient_pressure - starting_ambient_pressure) / *rate; | |
1741 decom_get_inert_gases(starting_ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_begin, &fraction_helium_begin ); | |
1742 decom_get_inert_gases(ending_ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_end, &fraction_helium_end ); | |
1743 initial_inspired_he_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin; | |
1744 initial_inspired_n2_pressure = (starting_ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_nitrogen_begin; | |
1745 helium_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_helium_end - initial_inspired_he_pressure)/time_test; | |
1746 nitrogen_rate = ((ending_ambient_pressure - WATER_VAPOR_PRESSURE)* fraction_nitrogen_end - initial_inspired_n2_pressure)/time_test; | |
1747 //>>>>>>>>>>>>>>>>>>>>> | |
1748 /*initial_inspired_he_pressure = | |
1749 (starting_ambient_pressure - water_vapor_pressure) * | |
1750 fraction_helium[mix_number - 1]; | |
1751 initial_inspired_n2_pressure = | |
1752 (starting_ambient_pressure - water_vapor_pressure) * | |
1753 fraction_nitrogen[mix_number - 1]; | |
1754 helium_rate = *rate * fraction_helium[mix_number - 1]; | |
1755 nitrogen_rate = *rate * fraction_nitrogen[mix_number - 1];*/ | |
1756 | |
1757 /* =============================================================================== */ | |
1758 /* ESTABLISH THE BOUNDS FOR THE ROOT SEARCH USING THE BISECTION METHOD */ | |
1759 /* AND CHECK TO MAKE SURE THAT THE ROOT WILL BE WITHIN BOUNDS. PROCESS */ | |
1760 /* EACH COMPARTMENT INDIVIDUALLY AND FIND THE MAXIMUM DEPTH ACROSS ALL */ | |
1761 /* COMPARTMENTS (LEADING COMPARTMENT) */ | |
1762 /* In this case, we are solving for time - the time when the gas tension in */ | |
1763 /* the compartment will be equal to ambient pressure. The low bound for time */ | |
1764 /* is set at zero and the high bound is set at the time it would take to */ | |
1765 /* ascend to zero ambient pressure (absolute). Since the ascent rate is */ | |
1766 /* negative, a multiplier of -1.0 is used to make the time positive. The */ | |
1767 /* desired point when gas tension equals ambient pressure is found at a time */ | |
1768 /* somewhere between these endpoints. The algorithm checks to make sure that */ | |
1769 /* the solution lies in between these bounds by first computing the low bound */ | |
1770 /* and high bound function values. */ | |
1771 /* =============================================================================== */ | |
1772 | |
1773 low_bound = 0.; | |
1774 high_bound = starting_ambient_pressure / *rate * -1.0f; | |
1775 for (i = 1; i <= 16; ++i) | |
1776 { | |
1777 initial_helium_pressure = helium_pressure[i - 1]; | |
1778 initial_nitrogen_pressure = nitrogen_pressure[i - 1]; | |
1779 function_at_low_bound = | |
1780 initial_helium_pressure + | |
1781 initial_nitrogen_pressure + | |
1782 CONSTANT_PRESSURE_OTHER_GASES - | |
1783 starting_ambient_pressure; | |
1784 high_bound_helium_pressure = | |
1785 schreiner_equation__2(&initial_inspired_he_pressure, | |
1786 &helium_rate, | |
1787 &high_bound, | |
1788 &HELIUM_TIME_CONSTANT[i - 1], | |
1789 &initial_helium_pressure); | |
1790 high_bound_nitrogen_pressure = | |
1791 schreiner_equation__2(&initial_inspired_n2_pressure, | |
1792 &nitrogen_rate, | |
1793 &high_bound, | |
1794 &NITROGEN_TIME_CONSTANT[i - 1], | |
1795 &initial_nitrogen_pressure); | |
1796 function_at_high_bound = high_bound_helium_pressure + | |
1797 high_bound_nitrogen_pressure + | |
1798 CONSTANT_PRESSURE_OTHER_GASES; | |
1799 if (function_at_high_bound * function_at_low_bound >= 0.0f) | |
1800 { | |
1801 printf("\nERROR! ROOT IS NOT WITHIN BRACKETS"); | |
1802 } | |
1803 | |
1804 /* =============================================================================== */ | |
1805 /* APPLY THE BISECTION METHOD IN SEVERAL ITERATIONS UNTIL A SOLUTION WITH */ | |
1806 /* THE DESIRED ACCURACY IS FOUND */ | |
1807 /* Note: the program allows for up to 100 iterations. Normally an exit will */ | |
1808 /* be made from the loop well before that number. If, for some reason, the */ | |
1809 /* program exceeds 100 iterations, there will be a pause to alert the user. */ | |
1810 /* =============================================================================== */ | |
1811 | |
1812 if (function_at_low_bound < 0.0f) | |
1813 { | |
1814 time_to_start_of_deco_zone = low_bound; | |
1815 differential_change = high_bound - low_bound; | |
1816 } else { | |
1817 time_to_start_of_deco_zone = high_bound; | |
1818 differential_change = low_bound - high_bound; | |
1819 } | |
1820 for (j = 1; j <= 100; ++j) | |
1821 { | |
1822 last_diff_change = differential_change; | |
1823 differential_change = last_diff_change * 0.5f; | |
1824 mid_range_time = | |
1825 time_to_start_of_deco_zone + | |
1826 differential_change; | |
1827 mid_range_helium_pressure = | |
1828 schreiner_equation__2(&initial_inspired_he_pressure, | |
1829 &helium_rate, | |
1830 &mid_range_time, | |
1831 &HELIUM_TIME_CONSTANT[i - 1], | |
1832 &initial_helium_pressure); | |
1833 mid_range_nitrogen_pressure = | |
1834 schreiner_equation__2(&initial_inspired_n2_pressure, | |
1835 &nitrogen_rate, | |
1836 &mid_range_time, | |
1837 &NITROGEN_TIME_CONSTANT[i - 1], | |
1838 &initial_nitrogen_pressure); | |
1839 function_at_mid_range = | |
1840 mid_range_helium_pressure + | |
1841 mid_range_nitrogen_pressure + | |
1842 CONSTANT_PRESSURE_OTHER_GASES - | |
1843 (starting_ambient_pressure + *rate * mid_range_time); | |
1844 if (function_at_mid_range <= 0.0f) { | |
1845 time_to_start_of_deco_zone = mid_range_time; | |
1846 } | |
1847 if( fabs(differential_change) < 0.001f | |
1848 || function_at_mid_range == 0.0f) | |
1849 { | |
1850 goto L170; | |
1851 } | |
1852 /* L150: */ | |
1853 } | |
1854 printf("\nERROR! ROOT SEARCH EXCEEDED MAXIMUM ITERATIONS"); | |
1855 //pause(); | |
1856 | |
1857 /* =============================================================================== */ | |
1858 /* When a solution with the desired accuracy is found, the program jumps out */ | |
1859 /* of the loop to Line 170 and assigns the solution value for the individual */ | |
1860 /* compartment. */ | |
1861 /* =============================================================================== */ | |
1862 | |
1863 L170: | |
1864 cpt_depth_start_of_deco_zone = | |
1865 starting_ambient_pressure + | |
1866 *rate * time_to_start_of_deco_zone - | |
1867 barometric_pressure; | |
1868 | |
1869 /* =============================================================================== */ | |
1870 /* The overall solution will be the compartment with the maximum depth where */ | |
1871 /* gas tension equals ambient pressure (leading compartment). */ | |
1872 /* =============================================================================== */ | |
1873 | |
1874 *depth_start_of_deco_zone = | |
1875 fmaxf(*depth_start_of_deco_zone, cpt_depth_start_of_deco_zone); | |
1876 /* L200: */ | |
1877 } | |
1878 return 0; | |
1879 } /* calc_start_of_deco_zone */ | |
1880 | |
1881 /* =============================================================================== */ | |
1882 /* SUBROUTINE PROJECTED_ASCENT */ | |
1883 /* Purpose: This subprogram performs a simulated ascent outside of the main */ | |
1884 /* program to ensure that a deco ceiling will not be violated due to unusual */ | |
1885 /* gas loading during ascent (on-gassing). If the deco ceiling is violated, */ | |
1886 /* the stop depth will be adjusted deeper by the step size until a safe */ | |
1887 /* ascent can be made. */ | |
1888 /* =============================================================================== */ | |
1889 | |
290 | 1890 static int projected_ascent(float *starting_depth, |
38 | 1891 float *rate, |
1892 float *deco_stop_depth, | |
1893 float *step_size) | |
1894 { | |
1895 /* Local variables */ | |
1896 float weighted_allowable_gradient, | |
1897 ending_ambient_pressure, | |
1898 temp_gas_loading[16]; | |
1899 int i; | |
1900 float allowable_gas_loading[16]; | |
1901 float temp_nitrogen_pressure[16]; | |
1902 float temp_helium_pressure[16]; | |
1903 float run_time_save = 0; | |
1904 | |
1905 /* loop */ | |
1906 /* =============================================================================== */ | |
1907 /* CALCULATIONS */ | |
1908 /* =============================================================================== */ | |
1909 | |
1910 | |
1911 L665: | |
1912 ending_ambient_pressure = *deco_stop_depth + barometric_pressure; | |
1913 for (i = 1; i <= 16; ++i) { | |
1914 temp_helium_pressure[i - 1] = helium_pressure[i - 1]; | |
1915 temp_nitrogen_pressure[i - 1] = nitrogen_pressure[i - 1]; | |
1916 } | |
1917 run_time_save = run_time; | |
1918 gas_loadings_ascent_descen(temp_helium_pressure, temp_nitrogen_pressure, *starting_depth,*deco_stop_depth,*rate,true); | |
1919 run_time = run_time_save; | |
1920 | |
1921 for (i = 1; i <= 16; ++i) | |
1922 { | |
1923 temp_gas_loading[i - 1] = | |
1924 temp_helium_pressure[i - 1] + | |
1925 temp_nitrogen_pressure[i - 1]; | |
1926 if (temp_gas_loading[i - 1] > 0.0f) | |
1927 { | |
1928 weighted_allowable_gradient = | |
1929 (allowable_gradient_he[i - 1] * | |
1930 temp_helium_pressure[i - 1] + | |
1931 allowable_gradient_n2[i - 1] * | |
1932 temp_nitrogen_pressure[i - 1]) / temp_gas_loading[i - 1]; | |
1933 } else { | |
1934 /* Computing MIN */ | |
1935 weighted_allowable_gradient = fminf(allowable_gradient_he[i - 1],allowable_gradient_n2[i - 1]); | |
1936 } | |
1937 allowable_gas_loading[i - 1] = | |
1938 ending_ambient_pressure + | |
1939 weighted_allowable_gradient - | |
1940 CONSTANT_PRESSURE_OTHER_GASES; | |
1941 /* L670: */ | |
1942 } | |
1943 for (i = 1; i <= 16; ++i) { | |
1944 if (temp_gas_loading[i - 1] > allowable_gas_loading[i - 1]) { | |
1945 *deco_stop_depth += *step_size; | |
1946 goto L665; | |
1947 } | |
1948 /* L671: */ | |
1949 } | |
1950 return 0; | |
1951 } /* projected_ascent */ | |
1952 | |
1953 /* =============================================================================== */ | |
1954 /* SUBROUTINE DECOMPRESSION_STOP */ | |
1955 /* Purpose: This subprogram calculates the required time at each */ | |
1956 /* decompression stop. */ | |
1957 /* =============================================================================== */ | |
1958 | |
290 | 1959 static void decompression_stop(float *deco_stop_depth, |
38 | 1960 float *step_size, |
1961 _Bool final_deco_calculation) | |
1962 { | |
1963 /* Local variables */ | |
1964 float inspired_nitrogen_pressure; | |
1965 // short last_segment_number; | |
1966 // float weighted_allowable_gradient; | |
1967 float initial_helium_pressure[16]; | |
1968 /* by hw */ | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
1969 float initial_CNS = gCNS_VPM; |
38 | 1970 |
1971 //static float time_counter; | |
1972 short i; | |
1973 float ambient_pressure; | |
1974 float inspired_helium_pressure, | |
1975 next_stop; | |
1976 //last_run_time, | |
1977 //temp_segment_time; | |
1978 | |
1979 float deco_ceiling_depth, | |
1980 initial_nitrogen_pressure[16]; | |
1981 //round_up_operation; | |
1982 float fraction_helium_begin; | |
1983 float fraction_nitrogen_begin; | |
1984 int count = 0; | |
1985 _Bool buehlmann_wait = false; | |
1986 float tissue_He_saturation[16]; | |
1987 float tissue_N2_saturation[16]; | |
1988 float vpm_buehlmann_safety_gradient = 1.0f - (((float)pDiveSettings->vpm_conservatism) / 40); | |
1989 /* loop */ | |
1990 /* =============================================================================== */ | |
1991 /* CALCULATIONS */ | |
1992 /* =============================================================================== */ | |
1993 | |
1994 segment_time = 0; | |
1995 // temp_segment_time = segment_time; | |
1996 ambient_pressure = *deco_stop_depth + barometric_pressure; | |
1997 //ending_ambient_pressure = ambient_pressure; | |
1998 decom_get_inert_gases(ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]), &fraction_nitrogen_begin, &fraction_helium_begin ); | |
1999 | |
2000 if(*deco_stop_depth == (float)(pDiveSettings->last_stop_depth_bar * 10)) | |
2001 next_stop = 0; | |
2002 else | |
2003 { | |
2004 next_stop = *deco_stop_depth - *step_size; | |
2005 next_stop = fmaxf(next_stop,(float)pDiveSettings->last_stop_depth_bar * 10); | |
2006 } | |
2007 | |
2008 inspired_helium_pressure = | |
2009 (ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin; | |
2010 inspired_nitrogen_pressure = | |
2011 (ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_nitrogen_begin; | |
2012 | |
2013 /* =============================================================================== */ | |
2014 /* Check to make sure that program won't lock up if unable to decompress */ | |
2015 /* to the next stop. If so, write error message and terminate program. */ | |
2016 /* =============================================================================== */ | |
2017 | |
2018 //deco_ceiling_depth = next_stop +1; //deco_ceiling_depth = next_stop + 1; | |
2019 if(!vpm_violates_buehlmann) | |
149 | 2020 { |
38 | 2021 calc_deco_ceiling(&deco_ceiling_depth, false); //weg, weil auf jeden Fall schleife für safety und so konservativer |
149 | 2022 } |
38 | 2023 else |
149 | 2024 { |
38 | 2025 deco_ceiling_depth = next_stop + 1; |
149 | 2026 } |
38 | 2027 if(deco_ceiling_depth > next_stop) |
2028 { | |
2029 while (deco_ceiling_depth > next_stop) | |
2030 { | |
2031 | |
2032 segment_time += 60; | |
2033 if(segment_time >= 999 ) | |
2034 { | |
2035 segment_time = 999 ; | |
2036 run_time += segment_time; | |
2037 return; | |
2038 } | |
2039 //goto L700; | |
2040 initial_CNS = gCNS_VPM; | |
2041 decom_oxygen_calculate_cns_exposure(60*60,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM); | |
2042 for (i = 0; i < 16; i++) | |
2043 { | |
2044 initial_helium_pressure[i] = helium_pressure[i]; | |
2045 initial_nitrogen_pressure[i] = nitrogen_pressure[i]; | |
2046 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_one_hour[i]; | |
2047 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_one_hour[i]; | |
2048 } | |
2049 calc_deco_ceiling(&deco_ceiling_depth, false); | |
2050 } | |
2051 if(deco_ceiling_depth < next_stop) | |
2052 { | |
2053 segment_time -= 60; | |
2054 gCNS_VPM = initial_CNS; | |
2055 for (i = 0; i < 16; i++) | |
2056 { | |
2057 helium_pressure[i] = initial_helium_pressure[i]; | |
2058 nitrogen_pressure[i] = initial_nitrogen_pressure[i]; | |
2059 } | |
2060 deco_ceiling_depth = next_stop +1; | |
2061 } | |
2062 count = 0; | |
2063 while (deco_ceiling_depth > next_stop && count < 13) | |
2064 { | |
2065 count++; | |
2066 segment_time += 5; | |
2067 //goto L700; | |
2068 initial_CNS = gCNS_VPM; | |
2069 decom_oxygen_calculate_cns_exposure(60*5,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM); | |
2070 for (i = 0; i < 16; i++) | |
2071 { | |
2072 initial_helium_pressure[i] = helium_pressure[i]; | |
2073 initial_nitrogen_pressure[i] = nitrogen_pressure[i]; | |
2074 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_five_minutes[i]; | |
2075 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_five_minutes[i]; | |
2076 } | |
2077 calc_deco_ceiling(&deco_ceiling_depth, false); | |
2078 } | |
2079 if(deco_ceiling_depth < next_stop) | |
2080 { | |
2081 segment_time -= 5; | |
2082 gCNS_VPM = initial_CNS; | |
2083 for (i = 0; i < 16; i++) { | |
2084 helium_pressure[i] = initial_helium_pressure[i]; | |
2085 nitrogen_pressure[i] = initial_nitrogen_pressure[i]; | |
2086 } | |
2087 deco_ceiling_depth = next_stop +1; | |
2088 } | |
2089 buehlmann_wait = false; | |
2090 while (buehlmann_wait || (deco_ceiling_depth > next_stop)) | |
2091 { | |
2092 //time_counter = temp_segment_time; | |
2093 segment_time += 1; | |
2094 | |
2095 if(segment_time >= 999 ) | |
2096 { | |
2097 segment_time = 999 ; | |
2098 run_time += segment_time; | |
2099 return; | |
2100 } | |
2101 //goto L700; | |
2102 initial_CNS = gCNS_VPM; | |
2103 decom_oxygen_calculate_cns_exposure(60*1,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM); | |
2104 for (i = 0; i < 16; i++) | |
2105 { | |
2106 initial_helium_pressure[i] = helium_pressure[i]; | |
2107 initial_nitrogen_pressure[i] = nitrogen_pressure[i]; | |
2108 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_one_minute[i]; | |
2109 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_one_minute[i]; | |
2110 } | |
2111 if(!buehlmann_wait) | |
2112 calc_deco_ceiling(&deco_ceiling_depth, false); | |
2113 | |
2114 if(buehlmannSafety && final_deco_calculation && !(deco_ceiling_depth > next_stop)) | |
2115 { | |
2116 for (i = 0; i < 16; i++) | |
2117 { | |
2118 tissue_He_saturation[i] = helium_pressure[i] / 10; | |
2119 tissue_N2_saturation[i] = nitrogen_pressure[i] / 10; | |
2120 } | |
2121 if( (fabsf(nitrogen_pressure[15] - inspired_nitrogen_pressure) < 0.00001f) && (fabsf(helium_pressure[15] - inspired_helium_pressure) < 0.00001f) | |
2122 && (fabsf(nitrogen_pressure[0] - inspired_nitrogen_pressure) < 0.00001f) && (fabsf(helium_pressure[0] - inspired_helium_pressure) < 0.00001f)) | |
2123 { | |
2124 buehlmann_wait_exceeded = true; | |
2125 break; | |
2126 } | |
2127 | |
2128 if(decom_tissue_test_tolerance(tissue_N2_saturation, tissue_He_saturation, vpm_buehlmann_safety_gradient, (next_stop / 10.0f) + pInput->pressure_surface_bar)) | |
2129 break; | |
2130 | |
2131 buehlmann_wait = true; | |
2132 } | |
2133 } | |
2134 if(buehlmann_wait) | |
149 | 2135 { |
38 | 2136 vpm_violates_buehlmann = true; |
149 | 2137 } |
2138 if(!buehlmann_wait) | |
38 | 2139 { |
2140 if(deco_ceiling_depth < next_stop) | |
2141 { | |
2142 segment_time -= 1; | |
2143 gCNS_VPM = initial_CNS; | |
2144 for (i = 0; i < 16; i++) { | |
2145 helium_pressure[i] = initial_helium_pressure[i]; | |
2146 nitrogen_pressure[i] = initial_nitrogen_pressure[i]; | |
2147 } | |
2148 deco_ceiling_depth = next_stop +1; | |
2149 } | |
2150 while (deco_ceiling_depth > next_stop) | |
2151 { | |
2152 //time_counter = temp_segment_time; | |
2153 segment_time += (float) 1.0f / 3.0f; | |
2154 //goto L700; | |
2155 initial_CNS = gCNS_VPM; | |
2156 decom_oxygen_calculate_cns_exposure(20,&pDiveSettings->decogaslist[mix_number],ambient_pressure/10,&gCNS_VPM); | |
2157 for (i = 0; i < 16; i++) | |
2158 { | |
2159 helium_pressure[i] += (inspired_helium_pressure - helium_pressure[i]) * float_buehlmann_He_factor_expositon_20_seconds[i]; | |
2160 nitrogen_pressure[i] += (inspired_nitrogen_pressure - nitrogen_pressure[i]) * float_buehlmann_N2_factor_expositon_20_seconds[i]; | |
2161 } | |
2162 calc_deco_ceiling(&deco_ceiling_depth, false); | |
2163 } | |
2164 } | |
2165 } | |
2166 | |
2167 /*float pressure_save =dive_data.pressure; | |
2168 dive_data.pressure = ambient_pressure/10; | |
2169 tissues_exposure_stage(st_deco_test,(int)(segment_time * 60), &dive_data, &gaslist); | |
2170 dive_data.pressure = pressure_save;*/ | |
2171 run_time += segment_time; | |
2172 return; | |
2173 } /* decompression_stop */ | |
2174 | |
2175 /* =============================================================================== */ | |
2176 // SUROUTINE BOYLES_LAW_COMPENSATION | |
2177 // Purpose: This subprogram calculates the reduction in allowable gradients | |
2178 // with decreasing ambient pressure during the decompression profile based | |
2179 // on Boyle's Law considerations. | |
2180 //=============================================================================== | |
290 | 2181 static void BOYLES_LAW_COMPENSATION (float* First_Stop_Depth, |
38 | 2182 float* Deco_Stop_Depth, |
2183 float* Step_Size) | |
2184 { | |
2185 short i; | |
2186 | |
2187 float Next_Stop; | |
2188 float Ambient_Pressure_First_Stop, Ambient_Pressure_Next_Stop; | |
2189 float Amb_Press_First_Stop_Pascals, Amb_Press_Next_Stop_Pascals; | |
2190 float A, B, C, Low_Bound, High_Bound, Ending_Radius; | |
2191 float Deco_Gradient_Pascals; | |
2192 float Allow_Grad_First_Stop_He_Pa, Radius_First_Stop_He; | |
2193 float Allow_Grad_First_Stop_N2_Pa, Radius_First_Stop_N2; | |
2194 | |
2195 //=============================================================================== | |
2196 // LO//AL ARRAYS | |
2197 //=============================================================================== | |
2198 // float Radius1_He[16], Radius2_He[16]; | |
2199 // float Radius1_N2[16], Radius2_N2[16]; | |
2200 float root_factor; | |
2201 | |
2202 //=============================================================================== | |
2203 // CALCULATIONS | |
2204 //=============================================================================== | |
2205 Next_Stop = *Deco_Stop_Depth - *Step_Size; | |
2206 | |
2207 Ambient_Pressure_First_Stop = *First_Stop_Depth + | |
2208 barometric_pressure; | |
2209 | |
2210 Ambient_Pressure_Next_Stop = Next_Stop + barometric_pressure; | |
2211 | |
2212 Amb_Press_First_Stop_Pascals = (Ambient_Pressure_First_Stop/UNITS_FACTOR) * 101325.0f; | |
2213 | |
2214 Amb_Press_Next_Stop_Pascals = | |
2215 (Ambient_Pressure_Next_Stop/UNITS_FACTOR) * 101325.0f; | |
2216 root_factor = powf(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals,1.0f / 3.0f); | |
2217 | |
2218 for( i = 0; i < 16;i++) | |
2219 { | |
2220 Allow_Grad_First_Stop_He_Pa = | |
2221 (allowable_gradient_he[i]/UNITS_FACTOR) * 101325.0f; | |
2222 | |
2223 Radius_First_Stop_He = (2.0f * SURFACE_TENSION_GAMMA) / | |
2224 Allow_Grad_First_Stop_He_Pa; | |
2225 | |
2226 // Radius1_He[i] = Radius_First_Stop_He; | |
2227 A = Amb_Press_Next_Stop_Pascals; | |
2228 B = -2.0f * SURFACE_TENSION_GAMMA; | |
2229 C = (Amb_Press_First_Stop_Pascals + (2.0f * SURFACE_TENSION_GAMMA)/ | |
2230 Radius_First_Stop_He)* Radius_First_Stop_He* | |
2231 (Radius_First_Stop_He*(Radius_First_Stop_He)); | |
2232 Low_Bound = Radius_First_Stop_He; | |
2233 High_Bound = Radius_First_Stop_He * root_factor; | |
2234 //*pow(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals,1.0/3.0); | |
2235 //*(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals)**(1.0/3.0); | |
2236 | |
2237 radius_root_finder(&A,&B,&C, &Low_Bound, &High_Bound, | |
2238 &Ending_Radius); | |
2239 | |
2240 // Radius2_He[i] = Ending_Radius; | |
2241 Deco_Gradient_Pascals = (2.0f * SURFACE_TENSION_GAMMA) / | |
2242 Ending_Radius; | |
2243 | |
2244 deco_gradient_he[i] = (Deco_Gradient_Pascals / 101325.0f)* | |
2245 UNITS_FACTOR; | |
2246 | |
2247 } | |
2248 | |
2249 for( i = 0; i < 16;i++) | |
2250 { | |
2251 Allow_Grad_First_Stop_N2_Pa = | |
2252 (allowable_gradient_n2[i]/UNITS_FACTOR) * 101325.0f; | |
2253 | |
2254 Radius_First_Stop_N2 = (2.0f * SURFACE_TENSION_GAMMA) / | |
2255 Allow_Grad_First_Stop_N2_Pa; | |
2256 | |
2257 // Radius1_N2[i] = Radius_First_Stop_N2; | |
2258 A = Amb_Press_Next_Stop_Pascals; | |
2259 B = -2.0f * SURFACE_TENSION_GAMMA; | |
2260 C = (Amb_Press_First_Stop_Pascals + (2.0f * SURFACE_TENSION_GAMMA)/ | |
2261 Radius_First_Stop_N2)* Radius_First_Stop_N2* | |
2262 (Radius_First_Stop_N2*(Radius_First_Stop_N2)); | |
2263 Low_Bound = Radius_First_Stop_N2; | |
2264 High_Bound = Radius_First_Stop_N2* root_factor;//pow(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals,1.0/3.0); | |
2265 | |
2266 //High_Bound = Radius_First_Stop_N2*exp(log(Amb_Press_First_Stop_Pascals/Amb_Press_Next_Stop_Pascals)/3); | |
2267 radius_root_finder(&A,&B,&C, &Low_Bound, &High_Bound, | |
2268 &Ending_Radius); | |
2269 | |
2270 // Radius2_N2[i] = Ending_Radius; | |
2271 Deco_Gradient_Pascals = (2.0f * SURFACE_TENSION_GAMMA) / | |
2272 Ending_Radius; | |
2273 | |
2274 deco_gradient_n2[i] = (Deco_Gradient_Pascals / 101325.0f)* | |
2275 UNITS_FACTOR; | |
2276 } | |
2277 } | |
2278 | |
2279 /* =============================================================================== */ | |
292 | 2280 // vpm_calc_ndl |
2281 // Purpose: This function computes NDL (time where no decostops are needed) | |
38 | 2282 //=============================================================================== |
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2283 #define MAX_NDL 240 |
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2284 |
292 | 2285 static int vpm_calc_ndl(void) |
38 | 2286 { |
2287 static float future_helium_pressure[16]; | |
2288 static float future_nitrogen_pressure[16]; | |
2289 static int temp_segment_time; | |
2290 static int mix_number; | |
2291 static float inspired_helium_pressure; | |
2292 static float inspired_nitrogen_pressure; | |
2293 | |
2294 float previous_helium_pressure[16]; | |
2295 float previous_nitrogen_pressure[16]; | |
2296 float ambient_pressure; | |
2297 float fraction_helium_begin; | |
2298 float fraction_nitrogen_begin; | |
2299 int i = 0; | |
2300 int count = 0; | |
2301 int status = CALC_END; | |
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2302 |
38 | 2303 for(i = 0; i < 16;i++) |
2304 { | |
2305 future_helium_pressure[i] = pInput->tissue_helium_bar[i] * 10;//tissue_He_saturation[st_dive][i] * 10; | |
2306 future_nitrogen_pressure[i] = pInput->tissue_nitrogen_bar[i] * 10; | |
2307 } | |
2308 temp_segment_time = 0; | |
2309 | |
2310 mix_number = 0; | |
2311 ambient_pressure = pInput->pressure_ambient_bar * 10; | |
2312 decom_get_inert_gases( ambient_pressure / 10, (&pDiveSettings->decogaslist[mix_number]) , &fraction_nitrogen_begin, &fraction_helium_begin ); | |
2313 inspired_helium_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) * fraction_helium_begin; | |
2314 inspired_nitrogen_pressure =(ambient_pressure - WATER_VAPOR_PRESSURE) *fraction_nitrogen_begin; | |
2315 | |
2316 status = CALC_END; | |
2317 while (status == CALC_END) | |
2318 { | |
2319 count++; | |
2320 temp_segment_time += 60; | |
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2321 if(temp_segment_time >= MAX_NDL) |
38 | 2322 { |
2323 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; | |
292 | 2324 return CALC_NDL; |
38 | 2325 } |
2326 run_time += 60; | |
2327 //goto L700; | |
2328 for (i = 1; i <= 16; ++i) { | |
2329 previous_helium_pressure[i-1] = future_helium_pressure[i - 1]; | |
2330 previous_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1]; | |
2331 future_helium_pressure[i - 1] = future_helium_pressure[i - 1] + (inspired_helium_pressure - future_helium_pressure[i - 1]) * float_buehlmann_He_factor_expositon_one_hour[i-1]; | |
2332 future_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1] + (inspired_nitrogen_pressure - future_nitrogen_pressure[i - 1]) * float_buehlmann_N2_factor_expositon_one_hour[i-1]; | |
2333 helium_pressure[i - 1] = future_helium_pressure[i - 1]; | |
2334 nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1]; | |
2335 } | |
2336 vpm_calc_deco(); | |
2337 while((status = vpm_calc_critcal_volume(true,true)) == CALC_CRITICAL); | |
2338 | |
2339 } | |
2340 | |
2341 temp_segment_time -= 60; | |
2342 run_time -= 60; | |
2343 for (i = 1; i <= 16; ++i) | |
2344 { | |
2345 future_helium_pressure[i - 1] = previous_helium_pressure[i-1]; | |
2346 future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1]; | |
2347 } | |
2348 | |
2349 status = CALC_END; | |
2350 if(temp_segment_time < 60) | |
2351 nullzeit_unter60 = true; | |
2352 | |
2353 while (status == CALC_END) | |
2354 { | |
2355 temp_segment_time += 5; | |
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2356 if(temp_segment_time >= MAX_NDL) |
38 | 2357 { |
2358 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; | |
292 | 2359 return CALC_NDL; |
38 | 2360 } |
2361 if(nullzeit_unter60 && temp_segment_time > 60) | |
2362 { | |
2363 nullzeit_unter60 = false; | |
292 | 2364 return CALC_NDL; |
38 | 2365 } |
2366 run_time += 5; | |
2367 //goto L700; | |
2368 for (i = 1; i <= 16; ++i) { | |
2369 previous_helium_pressure[i-1] = future_helium_pressure[i - 1]; | |
2370 previous_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1]; | |
2371 future_helium_pressure[i - 1] = future_helium_pressure[i - 1] + (inspired_helium_pressure - future_helium_pressure[i - 1]) * float_buehlmann_He_factor_expositon_five_minutes[i-1]; | |
2372 future_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1] + (inspired_nitrogen_pressure - future_nitrogen_pressure[i - 1]) * float_buehlmann_N2_factor_expositon_five_minutes[i-1]; | |
2373 helium_pressure[i - 1] = future_helium_pressure[i - 1]; | |
2374 nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1]; | |
2375 } | |
2376 vpm_calc_deco(); | |
2377 while((status =vpm_calc_critcal_volume(true,true)) == CALC_CRITICAL); | |
2378 } | |
2379 temp_segment_time -= 5; | |
2380 run_time -= 5; | |
2381 for (i = 1; i <= 16; ++i) { | |
2382 future_helium_pressure[i - 1] = previous_helium_pressure[i-1]; | |
2383 future_nitrogen_pressure[i - 1] = previous_nitrogen_pressure[i - 1]; | |
2384 } | |
2385 status = CALC_END; | |
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
290
diff
changeset
|
2386 |
38 | 2387 if(temp_segment_time <= 20) |
2388 { | |
2389 while (status == CALC_END) | |
2390 { | |
2391 temp_segment_time += minimum_deco_stop_time; | |
2392 run_time += minimum_deco_stop_time; | |
2393 //goto L700; | |
2394 for (i = 1; i <= 16; ++i) { | |
2395 future_helium_pressure[i - 1] = future_helium_pressure[i - 1] + (inspired_helium_pressure - future_helium_pressure[i - 1]) * float_buehlmann_He_factor_expositon_one_minute[i-1]; | |
2396 future_nitrogen_pressure[i - 1] = future_nitrogen_pressure[i - 1] + (inspired_nitrogen_pressure - future_nitrogen_pressure[i - 1]) * float_buehlmann_N2_factor_expositon_one_minute[i-1]; | |
2397 helium_pressure[i - 1] = future_helium_pressure[i - 1]; | |
2398 nitrogen_pressure[i - 1] =future_nitrogen_pressure[i - 1]; | |
2399 | |
2400 } | |
2401 vpm_calc_deco(); | |
2402 while((status =vpm_calc_critcal_volume(true,true)) == CALC_CRITICAL); | |
2403 | |
2404 } | |
2405 } | |
2406 else | |
2407 temp_segment_time += 5; | |
2408 pDecoInfo->output_ndl_seconds = temp_segment_time * 60; | |
2409 if(temp_segment_time > 1) | |
292 | 2410 return CALC_NDL; |
38 | 2411 else |
2412 return CALC_BEGIN; | |
2413 } |