Mercurial > public > ostc4
annotate Discovery/Src/buehlmann.c @ 1050:88b6ab90c55a GasConsumption
Added separate LLC view for surface GF:
A new LLC view has been added. In addition the surface GF is now clipped to a value of 9.99 => 999% in the visualization
| author | Ideenmodellierer |
|---|---|
| date | Wed, 19 Nov 2025 21:34:18 +0100 |
| parents | d91345e9c009 |
| children |
| rev | line source |
|---|---|
|
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
1 /* getrennte Gase f�r die verschiedenen Modi |
|
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
2 um Gaswechsel Eintr�ge zu vereinfachen |
| 38 | 3 das heisst: |
| 4 oc == bailout in cc mode | |
| 5 */ | |
| 6 | |
| 7 /* Konvention: | |
| 8 float extExample_variable_can_be_used_with_extern; | |
| 9 */ | |
| 10 | |
| 11 #include <string.h> | |
| 12 #include <math.h> | |
| 13 #include <stdbool.h> | |
| 14 #include "buehlmann.h" | |
| 15 #include "decom.h" | |
| 16 | |
| 17 extern const float buehlmann_N2_a[]; | |
| 18 extern const float buehlmann_N2_b[]; | |
| 19 extern const float buehlmann_He_a[]; | |
| 20 extern const float buehlmann_He_b[]; | |
| 21 | |
| 22 typedef struct | |
| 23 { | |
| 24 float depth; | |
| 25 int id; | |
| 26 } SStop; | |
| 27 | |
| 28 #define DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS 59940 // 999 minuten; before: 18000 // 5(h) * 60(min) * 60 sec = 18000 sec | |
| 29 #define DECO_STOPS_MAX_TTS_FOR_EVERY_SECOND_CALC_IN_SECONDS 7200 | |
| 30 #define NINETY_NINE_MINUTES_IN_SECONDS 59940 | |
| 31 | |
| 32 # define PRESSURE_TEN_METER 1.0f | |
| 33 # define PRESSURE_THREE_METER 0.333334f | |
| 34 # define PRESSURE_150_CM 0.15f | |
| 35 # define PRESSURE_HALF_METER 0.05f | |
| 36 | |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
37 static void buehlmann_backup_and_restore(_Bool backup_restore_otherwise); |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
38 static float tissue_tolerance(void); |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
39 static void ambient_bar_to_deco_stop_depth_bar(SDiveSettings *pDiveSettings, float ceiling); |
|
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
40 static int ascend_with_all_gaschanges(SDiveSettings *pDiveSettings, float pressure_decrease); |
|
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
41 static float next_stop_depth_input_is_actual_stop_id(SDiveSettings *pDiveSettings, int actual_id); |
|
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
42 static float get_gf_at_pressure(SDiveSettings *pDiveSettings, float pressure); |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
43 static int buehlmann_calc_ndl(SDiveSettings *pDiveSettings); |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
44 static _Bool dive1_check_deco(SDiveSettings *pDiveSettings); |
| 38 | 45 |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
46 static float gSurface_pressure_bar; |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
47 static float gPressure; |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
48 static int gGas_id; |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
49 static float gTissue_nitrogen_bar[16]; |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
50 static float gTissue_helium_bar[16]; |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
51 static float gGF_value; |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
52 static float gCNS; |
| 38 | 53 |
| 54 float gGF_low_depth_bar; | |
| 55 SStop gStop; | |
| 56 | |
| 57 void buehlmann_init(void) | |
| 58 { | |
| 59 } | |
| 60 | |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
61 static void buehlmann_backup_and_restore(_Bool backup_restore_otherwise) |
| 38 | 62 { |
| 63 static float pressure; | |
| 64 static float gas_id; | |
| 65 static float tissue_nitrogen_bar[16]; | |
| 66 static float tissue_helium_bar[16]; | |
| 67 static float gf_value; | |
| 68 static float cns; | |
| 69 | |
| 70 if(backup_restore_otherwise) | |
| 71 { | |
| 72 pressure = gPressure; | |
| 73 gas_id = gGas_id; | |
| 74 gf_value = gGF_value; | |
| 75 cns = gCNS; | |
| 76 memcpy(tissue_nitrogen_bar, gTissue_nitrogen_bar, (4*16)); | |
| 77 memcpy(tissue_helium_bar, gTissue_helium_bar, (4*16)); | |
| 78 } | |
| 79 else | |
| 80 { | |
| 81 gPressure = pressure; | |
| 82 gGas_id = gas_id; | |
| 83 gGF_value = gf_value; | |
| 84 gCNS = cns; | |
| 85 memcpy(gTissue_nitrogen_bar, tissue_nitrogen_bar, (4*16)); | |
| 86 memcpy(gTissue_helium_bar, tissue_helium_bar, (4*16)); | |
| 87 } | |
| 88 | |
| 89 } | |
| 90 | |
| 91 float buehlmann_get_gCNS(void) | |
| 92 { | |
| 93 return gCNS; | |
| 94 } | |
| 95 | |
| 96 void buehlmann_calc_deco(SLifeData* pLifeData, SDiveSettings * pDiveSettings, SDecoinfo * pDecoInfo) | |
| 97 { | |
| 98 float ceiling; | |
| 99 int ascend_time; | |
| 100 int tts_seconds; | |
| 101 float pressure_delta; | |
| 102 float next_depth; | |
| 103 _Bool deco_reached = false; | |
| 104 unsigned short *stoplist; | |
| 105 int i; | |
| 106 | |
| 107 gCNS = 0; | |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
108 pDecoInfo->output_time_to_surface_seconds = 0; |
| 38 | 109 pDecoInfo->output_ndl_seconds = 0; |
| 110 for(int i=0;i<DECOINFO_STRUCT_MAX_STOPS;i++) | |
| 111 { | |
| 112 pDecoInfo->output_stop_length_seconds[i] = 0; | |
| 113 } | |
| 114 | |
| 115 /* internal copying */ | |
| 116 gSurface_pressure_bar = pLifeData->pressure_surface_bar; | |
| 117 | |
| 118 gPressure = pLifeData->pressure_ambient_bar; | |
| 119 gGas_id = 0; | |
| 120 memcpy(gTissue_nitrogen_bar, pLifeData->tissue_nitrogen_bar, (4*16)); | |
| 121 memcpy(gTissue_helium_bar, pLifeData->tissue_helium_bar, (4*16)); | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
122 gGF_value = ((float)pDiveSettings->gf_low) / 100.0f; |
| 38 | 123 |
|
258
0087d6251f59
Buehlmann: factor out another global gDecotable
Jan Mulder <jlmulder@xs4all.nl>
parents:
257
diff
changeset
|
124 stoplist = pDecoInfo->output_stop_length_seconds; |
| 38 | 125 |
|
305
305f251cc981
bugfix, consistency: show deco/NDL really after 1 minute divetime
Jan Mulder <jlmulder@xs4all.nl>
parents:
291
diff
changeset
|
126 if(pLifeData->dive_time_seconds_without_surface_time < 60) |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
127 return; |
| 38 | 128 |
| 129 // clean stop list | |
| 130 for(i = 0; i < DECOINFO_STRUCT_MAX_STOPS; i++) | |
| 131 stoplist[i] = 0; | |
| 132 | |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
133 if(pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero >= (gPressure - PRESSURE_150_CM)) |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
134 { |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
135 deco_reached = true; |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
136 } |
| 38 | 137 |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
138 gGF_value = ((float)pDiveSettings->gf_high) / 100.0f; |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
139 buehlmann_backup_and_restore(true); |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
140 if(!dive1_check_deco(pDiveSettings) ) |
| 38 | 141 { |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
142 buehlmann_backup_and_restore(false); |
| 38 | 143 // no deco |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
144 pDecoInfo->output_time_to_surface_seconds = 0; |
| 38 | 145 for(i = 0; i < DECOINFO_STRUCT_MAX_STOPS; i++) |
|
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
146 pDecoInfo->output_stop_length_seconds[i] = 0; |
| 38 | 147 // calc NDL |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
148 pDecoInfo->output_ndl_seconds = buehlmann_calc_ndl(pDiveSettings);; |
| 38 | 149 return; |
| 150 } | |
| 151 buehlmann_backup_and_restore(false); | |
|
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
152 pDecoInfo->output_ndl_seconds = 0; |
| 38 | 153 |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
154 gGF_value = get_gf_at_pressure(pDiveSettings, gPressure); |
| 38 | 155 //current ceiling at actual position |
| 156 ceiling = tissue_tolerance(); | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
157 ambient_bar_to_deco_stop_depth_bar(pDiveSettings, ceiling); |
| 38 | 158 |
| 159 // set the base for all upcoming parameters | |
| 160 ceiling = gStop.depth + gSurface_pressure_bar; | |
| 161 tts_seconds = 0; | |
| 162 | |
| 163 // modify parameters if there is ascend or parameter fine adjustment | |
| 164 if(ceiling < (gPressure - PRESSURE_150_CM)) // more than 1.5 meter below ceiling | |
| 165 { | |
| 166 // ascend within 10 mtr to GF_low // speed 12 mtr/min -> 50 sec / 10 mtr; 15 sec / 3 mtr. | |
| 167 if(ceiling < (gPressure - PRESSURE_TEN_METER) ) | |
| 168 { do { | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
169 ascend_time = ascend_with_all_gaschanges(pDiveSettings, PRESSURE_TEN_METER); |
| 38 | 170 tts_seconds += ascend_time; |
| 171 ceiling = tissue_tolerance(); | |
| 172 if(tts_seconds > DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS) | |
| 173 { | |
|
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
174 pDecoInfo->output_time_to_surface_seconds = NINETY_NINE_MINUTES_IN_SECONDS; |
| 38 | 175 return;// NINETY_NINE_MINUTES_IN_SECONDS; |
| 176 } | |
| 177 } while ((ascend_time > 0 ) && ((gPressure - PRESSURE_TEN_METER ) > gSurface_pressure_bar) && (ceiling < (gPressure - PRESSURE_TEN_METER))); | |
| 178 } | |
| 179 do { | |
| 180 buehlmann_backup_and_restore(true); | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
181 ascend_time = ascend_with_all_gaschanges(pDiveSettings, PRESSURE_THREE_METER); |
| 38 | 182 tts_seconds += ascend_time; |
| 183 ceiling = tissue_tolerance(); | |
| 184 if(tts_seconds > DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS) | |
| 185 { | |
|
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
186 pDecoInfo->output_time_to_surface_seconds = NINETY_NINE_MINUTES_IN_SECONDS; |
| 38 | 187 return;// NINETY_NINE_MINUTES_IN_SECONDS; |
| 188 } | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
189 ambient_bar_to_deco_stop_depth_bar(pDiveSettings, ceiling); |
| 38 | 190 } while ((ascend_time > 0 ) && ((gStop.depth + gSurface_pressure_bar) < gPressure)); |
| 191 | |
| 192 if(gStop.depth + gSurface_pressure_bar > gPressure) | |
| 193 { | |
| 194 gPressure += PRESSURE_THREE_METER; | |
| 195 buehlmann_backup_and_restore(false); | |
| 196 tts_seconds -= ascend_time; | |
| 197 } | |
| 198 // calculate first stop based on tissue saturation within 10 meters of stop | |
| 199 //ambient_bar_to_deco_stop_depth_bar(ceiling); | |
| 200 } | |
| 201 else | |
| 202 { | |
| 203 // initial values, upper code might not be executed (is within 150 cm) | |
| 204 } | |
| 205 | |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
206 if (ceiling > gSurface_pressure_bar) |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
207 { |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
208 ceiling = gStop.depth + gSurface_pressure_bar; |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
209 // ascend the last meters to first stop (especially consider any gas changes around) |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
210 pressure_delta = gPressure - ceiling; |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
211 ascend_time = (int) ceil(pressure_delta * 50.0f); |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
212 tts_seconds += ascend_with_all_gaschanges(pDiveSettings, pressure_delta); |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
213 } |
| 38 | 214 // NDL check |
| 215 if(ceiling <= gSurface_pressure_bar) | |
| 216 { | |
| 217 // NDL with GF_low | |
|
254
a17f7fb3b2b5
Buehlmann: cleanup, remove global pDecolistBuehlmann
Jan Mulder <jlmulder@xs4all.nl>
parents:
253
diff
changeset
|
218 pDecoInfo->output_time_to_surface_seconds = 0; |
| 38 | 219 return; |
| 220 } | |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
221 if (ceiling > pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero) |
|
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
222 pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = ceiling; |
| 38 | 223 |
| 224 // calc gf loop | |
| 225 if(deco_reached) | |
| 226 gGF_low_depth_bar = pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero - gSurface_pressure_bar; | |
| 227 else | |
| 228 gGF_low_depth_bar = ceiling - gSurface_pressure_bar; | |
| 229 | |
| 230 while(gStop.depth > 0) | |
| 231 { | |
| 232 do | |
| 233 { | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
234 next_depth = next_stop_depth_input_is_actual_stop_id(pDiveSettings, gStop.id); |
|
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
235 gGF_value = get_gf_at_pressure(pDiveSettings, next_depth + gSurface_pressure_bar); |
| 38 | 236 buehlmann_backup_and_restore(true); |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
237 ascend_time = ascend_with_all_gaschanges(pDiveSettings, gStop.depth - next_depth); |
| 38 | 238 ceiling = tissue_tolerance(); |
| 239 /* pre check actual limit */ | |
|
258
0087d6251f59
Buehlmann: factor out another global gDecotable
Jan Mulder <jlmulder@xs4all.nl>
parents:
257
diff
changeset
|
240 if(pDecoInfo->output_stop_length_seconds[gStop.id] >= 999*60) |
| 38 | 241 { |
|
258
0087d6251f59
Buehlmann: factor out another global gDecotable
Jan Mulder <jlmulder@xs4all.nl>
parents:
257
diff
changeset
|
242 tts_seconds -= 999*60 - pDecoInfo->output_stop_length_seconds[gStop.id]; |
|
0087d6251f59
Buehlmann: factor out another global gDecotable
Jan Mulder <jlmulder@xs4all.nl>
parents:
257
diff
changeset
|
243 pDecoInfo->output_stop_length_seconds[gStop.id] = 999*60; |
| 38 | 244 } |
| 245 else | |
| 246 /* more deco on the actual depth */ | |
| 247 if(ceiling > next_depth + gSurface_pressure_bar) | |
| 248 { | |
| 249 next_depth = -1; | |
| 250 buehlmann_backup_and_restore(false); | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
251 decom_tissues_exposure2(10, &pDiveSettings->decogaslist[gGas_id], gPressure,gTissue_nitrogen_bar,gTissue_helium_bar); // some seconds at least at each stop |
|
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
252 decom_oxygen_calculate_cns_exposure(10, &pDiveSettings->decogaslist[gGas_id], gPressure, &gCNS); |
|
258
0087d6251f59
Buehlmann: factor out another global gDecotable
Jan Mulder <jlmulder@xs4all.nl>
parents:
257
diff
changeset
|
253 pDecoInfo->output_stop_length_seconds[gStop.id] += 10; |
| 38 | 254 tts_seconds += 10; |
| 255 } | |
| 256 } while(next_depth == -1); | |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
257 tts_seconds += ascend_time; |
| 38 | 258 gStop.depth = next_depth; |
| 259 for(i = gGas_id + 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++) | |
| 260 { | |
| 983 | 261 if(pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero == 0) |
|
862
974648b5ccfe
Only use deco gas for calculation if option is enabled:
Ideenmodellierer
parents:
833
diff
changeset
|
262 { |
| 38 | 263 break; |
|
862
974648b5ccfe
Only use deco gas for calculation if option is enabled:
Ideenmodellierer
parents:
833
diff
changeset
|
264 } |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
265 float pressureChange = ((float)pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero) / 10; |
| 38 | 266 if(gStop.depth <= pressureChange + 0.00001f) |
| 267 { | |
| 268 gGas_id = i; | |
| 269 } | |
| 270 else | |
| 271 { | |
| 272 break; | |
| 273 } | |
| 274 } | |
| 275 gStop.id--; | |
| 276 } | |
| 277 | |
|
258
0087d6251f59
Buehlmann: factor out another global gDecotable
Jan Mulder <jlmulder@xs4all.nl>
parents:
257
diff
changeset
|
278 pDecoInfo->output_time_to_surface_seconds = tts_seconds; |
| 38 | 279 } |
| 280 | |
| 281 | |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
282 static float tissue_tolerance(void) |
| 38 | 283 { |
| 284 float tissue_inertgas_saturation; | |
| 285 float inertgas_a; | |
| 286 float inertgas_b; | |
| 287 float ceiling; | |
| 288 float global_ceiling; | |
| 289 int ci; | |
| 290 | |
| 291 global_ceiling = -1; | |
| 292 | |
| 293 for (ci = 0; ci < 16; ci++) | |
| 294 { | |
| 295 if(gTissue_helium_bar[ci] == 0) | |
| 296 { | |
| 297 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci]; | |
| 298 // | |
| 299 inertgas_a = buehlmann_N2_a[ci]; | |
| 300 inertgas_b = buehlmann_N2_b[ci]; | |
| 301 } | |
| 302 else | |
| 303 { | |
| 304 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci] + gTissue_helium_bar[ci]; | |
| 305 // | |
| 306 inertgas_a = ( ( buehlmann_N2_a[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_a[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
| 307 inertgas_b = ( ( buehlmann_N2_b[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_b[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
| 308 } | |
| 309 // | |
| 310 ceiling = (inertgas_b * ( tissue_inertgas_saturation - gGF_value * inertgas_a ) ) / (gGF_value - (inertgas_b * gGF_value) + inertgas_b); | |
| 311 if(ceiling > global_ceiling) | |
| 312 global_ceiling = ceiling; | |
| 313 } | |
| 314 return global_ceiling; | |
| 315 } | |
| 316 | |
|
246
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
317 void buehlmann_super_saturation_calculator(SLifeData* pLifeData, SDecoinfo * pDecoInfo) |
| 38 | 318 { |
| 319 float tissue_inertgas_saturation; | |
| 320 float inertgas_a; | |
| 321 float inertgas_b; | |
| 322 float ceiling; | |
| 1049 | 323 float M_surf,gf_surf; |
|
246
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
324 float super_saturation; |
|
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
325 float pres_respiration = pLifeData->pressure_ambient_bar; |
| 1049 | 326 float pres_surface = pLifeData->pressure_surface_bar; |
| 38 | 327 int ci; |
| 328 | |
|
246
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
329 pDecoInfo->super_saturation = 0; |
| 1049 | 330 pDecoInfo->gf_surf = 0; |
| 38 | 331 |
| 332 for (ci = 0; ci < 16; ci++) | |
| 333 { | |
| 334 if(gTissue_helium_bar[ci] == 0) | |
| 335 { | |
| 336 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci]; | |
| 337 inertgas_a = buehlmann_N2_a[ci]; | |
| 338 inertgas_b = buehlmann_N2_b[ci]; | |
| 339 } | |
| 340 else | |
| 341 { | |
| 342 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci] + gTissue_helium_bar[ci]; | |
| 343 inertgas_a = ( ( buehlmann_N2_a[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_a[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
| 344 inertgas_b = ( ( buehlmann_N2_b[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_b[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
| 345 } | |
|
246
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
346 |
| 1049 | 347 M_surf = inertgas_a + inertgas_b * pres_surface; |
| 348 if (M_surf > pres_surface) | |
| 349 { | |
| 350 gf_surf = (tissue_inertgas_saturation - pres_surface) / (M_surf - pres_surface); | |
| 1050 | 351 if(M_surf > 9.99) |
| 352 { | |
| 353 M_surf = 9.99; /* only intended to be used with 3 digit visualizations */ | |
| 354 } | |
| 1049 | 355 if(gf_surf > pDecoInfo->gf_surf) |
| 356 { | |
| 357 pDecoInfo->gf_surf = gf_surf; | |
| 358 } | |
| 359 } | |
| 360 | |
|
246
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
361 ceiling = pres_respiration / inertgas_b + inertgas_a; |
|
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
362 if(tissue_inertgas_saturation > pres_respiration) |
| 38 | 363 { |
|
246
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
364 super_saturation = |
|
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
365 (tissue_inertgas_saturation - pres_respiration) / (ceiling - pres_respiration); |
|
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
366 |
|
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
367 if (super_saturation > pDecoInfo->super_saturation) |
|
ff0d23625cd5
feature: replace Relative GF by saturation, computational only
Jan Mulder <jlmulder@xs4all.nl>
parents:
224
diff
changeset
|
368 pDecoInfo->super_saturation = super_saturation; |
| 38 | 369 } |
| 370 } | |
| 371 } | |
| 372 | |
| 373 | |
|
253
1663b3b204d7
Buehlmann: cleanup, whitespace, static
Jan Mulder <jlmulder@xs4all.nl>
parents:
250
diff
changeset
|
374 static float buehlmann_tissue_test_tolerance(float depth_in_bar_absolute) |
| 38 | 375 { |
| 376 float tissue_inertgas_saturation; | |
| 377 float inertgas_a; | |
| 378 float inertgas_b; | |
| 379 float inertgas_tolerance; | |
| 380 float gf_minus_1; | |
| 381 | |
| 382 gf_minus_1 = gGF_value - 1.0f; | |
| 383 | |
| 384 for (int ci = 0; ci < 16; ci++) | |
| 385 { | |
| 386 if(gTissue_helium_bar[ci] == 0) | |
| 387 { | |
| 388 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci]; | |
| 389 inertgas_a = buehlmann_N2_a[ci]; | |
| 390 inertgas_b = buehlmann_N2_b[ci]; | |
| 391 } | |
| 392 else | |
| 393 { | |
| 394 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci] + gTissue_helium_bar[ci]; | |
| 395 inertgas_a = ( ( buehlmann_N2_a[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_a[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
| 396 inertgas_b = ( ( buehlmann_N2_b[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_b[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation; | |
| 397 } | |
| 398 inertgas_tolerance = ( (gGF_value / inertgas_b - gf_minus_1) * depth_in_bar_absolute ) + ( gGF_value * inertgas_a ); | |
| 399 if(inertgas_tolerance < tissue_inertgas_saturation) | |
|
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
400 return tissue_inertgas_saturation - inertgas_tolerance; // positive |
| 38 | 401 } |
|
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
402 return tissue_inertgas_saturation - inertgas_tolerance; // negative |
| 38 | 403 } |
| 404 | |
| 405 | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
406 static void ambient_bar_to_deco_stop_depth_bar(SDiveSettings *pDiveSettings, float ceiling) |
| 38 | 407 { |
| 408 int i; | |
| 409 | |
| 410 ceiling -= gSurface_pressure_bar; | |
| 411 | |
| 412 if(ceiling <= 0) | |
| 413 { | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
414 gStop.depth = pDiveSettings->last_stop_depth_bar; |
| 38 | 415 gStop.id = 0; |
| 416 return; | |
| 417 } | |
| 418 | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
419 if((ceiling - pDiveSettings->last_stop_depth_bar) <= 0) |
| 38 | 420 { |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
421 gStop.depth = pDiveSettings->last_stop_depth_bar; |
| 38 | 422 gStop.id = 0; |
| 423 return; | |
| 424 } | |
| 425 | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
426 gStop.depth = pDiveSettings->input_second_to_last_stop_depth_bar; |
| 38 | 427 gStop.id = 1; |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
428 ceiling -= pDiveSettings->input_second_to_last_stop_depth_bar; |
| 38 | 429 |
| 430 if(ceiling <= 0) | |
| 431 return; | |
| 432 | |
| 433 for(i = 1; i < (DECOINFO_STRUCT_MAX_STOPS - 2); i++) | |
| 434 { | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
435 ceiling -= pDiveSettings->input_next_stop_increment_depth_bar; |
| 38 | 436 if(ceiling <= 0) |
| 437 break; | |
| 438 } | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
439 gStop.depth += i * pDiveSettings->input_next_stop_increment_depth_bar; |
| 38 | 440 gStop.id += i; |
| 441 return; | |
| 442 } | |
| 443 | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
444 static float next_stop_depth_input_is_actual_stop_id(SDiveSettings *pDiveSettings, int actual_id) |
| 38 | 445 { |
| 446 if(actual_id == 0) | |
| 447 return 0; | |
| 448 | |
| 449 if(actual_id == 1) | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
450 return pDiveSettings->last_stop_depth_bar; |
| 38 | 451 |
| 452 actual_id -= 2; | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
453 return pDiveSettings->input_second_to_last_stop_depth_bar + (actual_id * pDiveSettings->input_next_stop_increment_depth_bar); |
| 38 | 454 } |
| 455 | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
456 static int ascend_with_all_gaschanges(SDiveSettings *pDiveSettings, float pressure_decrease) |
| 38 | 457 { |
| 458 float pressureTop, pressureTop_tmp, pressureBottom, pressureChange, ascendrate_in_seconds_for_one_bar, pressure_difference; | |
|
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
459 int time_for_ascend = 0; |
| 38 | 460 int seconds; |
| 461 int i; | |
| 462 | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
463 ascendrate_in_seconds_for_one_bar = 60 * 10 / pDiveSettings->ascentRate_meterperminute; |
| 38 | 464 |
| 465 if(fabsf(gPressure - gSurface_pressure_bar) < PRESSURE_HALF_METER) | |
| 466 { | |
| 467 gPressure = gSurface_pressure_bar; | |
| 468 return 0; | |
| 469 } | |
| 470 | |
| 471 pressureTop = gPressure - pressure_decrease; | |
| 472 if( gSurface_pressure_bar > pressureTop) | |
| 473 pressureTop = gSurface_pressure_bar; | |
| 474 pressureBottom = gPressure; | |
| 475 seconds = 0; | |
| 476 do{ | |
| 477 pressureTop_tmp = pressureTop; | |
| 478 for(i = gGas_id + 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++) | |
| 479 { | |
| 983 | 480 if(pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero == 0) |
|
862
974648b5ccfe
Only use deco gas for calculation if option is enabled:
Ideenmodellierer
parents:
833
diff
changeset
|
481 { |
| 38 | 482 break; |
|
862
974648b5ccfe
Only use deco gas for calculation if option is enabled:
Ideenmodellierer
parents:
833
diff
changeset
|
483 } |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
484 pressureChange = gSurface_pressure_bar + ((float)pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero) / 10; |
| 38 | 485 if(pressureBottom <= pressureChange) |
| 486 { | |
| 487 gGas_id = i; | |
| 488 } | |
| 489 else | |
| 490 { | |
| 491 break; | |
| 492 } | |
| 493 | |
| 494 } | |
| 495 for(i = gGas_id + 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++) | |
| 496 { | |
| 983 | 497 if(pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero == 0) |
|
862
974648b5ccfe
Only use deco gas for calculation if option is enabled:
Ideenmodellierer
parents:
833
diff
changeset
|
498 { |
| 38 | 499 break; |
|
862
974648b5ccfe
Only use deco gas for calculation if option is enabled:
Ideenmodellierer
parents:
833
diff
changeset
|
500 } |
|
974648b5ccfe
Only use deco gas for calculation if option is enabled:
Ideenmodellierer
parents:
833
diff
changeset
|
501 |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
502 pressureChange = gSurface_pressure_bar + ((float)pDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero)/ 10; |
| 38 | 503 if((pressureChange < pressureBottom) && (pressureChange > pressureTop)) |
| 504 { | |
| 505 pressureTop_tmp = pressureChange; | |
| 506 } | |
| 507 } | |
| 508 pressure_difference = pressureBottom - pressureTop_tmp; | |
| 509 if(pressure_difference > 0.0001f) | |
| 510 { | |
| 511 time_for_ascend = (int)ceilf(pressure_difference * ascendrate_in_seconds_for_one_bar); | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
512 decom_tissues_exposure_stage_schreiner(time_for_ascend, &pDiveSettings->decogaslist[gGas_id], |
| 38 | 513 pressureBottom, pressureTop_tmp, gTissue_nitrogen_bar, gTissue_helium_bar); |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
514 decom_oxygen_calculate_cns_stage_SchreinerStyle(time_for_ascend,&pDiveSettings->decogaslist[gGas_id], |
| 38 | 515 pressureBottom, pressureTop_tmp, &gCNS); |
| 516 } | |
| 517 pressureBottom = pressureTop_tmp; | |
| 518 seconds += time_for_ascend; | |
| 519 }while(pressureTop_tmp > pressureTop); | |
| 520 gPressure = pressureTop; | |
| 521 return seconds; | |
| 522 } | |
| 523 | |
| 524 | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
525 static float get_gf_at_pressure(SDiveSettings *pDiveSettings, float pressure) |
| 38 | 526 { |
| 527 float gfSteigung = 0.0f; | |
| 528 | |
| 529 if(gGF_low_depth_bar < 0) | |
| 530 gGF_low_depth_bar = PRESSURE_THREE_METER; // just to prevent erratic behaviour if variable is not set | |
| 531 | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
532 gfSteigung = ((float)(pDiveSettings->gf_high - pDiveSettings->gf_low))/ gGF_low_depth_bar; |
| 38 | 533 |
| 534 | |
| 535 if((pressure - gSurface_pressure_bar) <= PRESSURE_HALF_METER) | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
536 return ((float)pDiveSettings->gf_high) / 100.0f; |
| 38 | 537 |
| 538 if(pressure >= gSurface_pressure_bar + gGF_low_depth_bar) | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
539 return ((float)pDiveSettings->gf_low) / 100.0f; |
| 38 | 540 |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
541 return (pDiveSettings->gf_high - gfSteigung * (pressure - gSurface_pressure_bar) )/ 100.0f; |
| 38 | 542 } |
| 543 | |
|
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
261
diff
changeset
|
544 #define MAX_NDL 240 |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
545 static int buehlmann_calc_ndl(SDiveSettings *pDiveSettings) |
| 38 | 546 { |
| 547 float local_tissue_nitrogen_bar[16]; | |
| 548 float local_tissue_helium_bar[16]; | |
| 549 int i; | |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
550 int ndl = 0; |
| 38 | 551 |
| 552 //Check ndl always use gHigh | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
553 gGF_value = ((float)pDiveSettings->gf_high) / 100.0f; |
| 38 | 554 //10 minutes steps |
|
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
261
diff
changeset
|
555 while(ndl < (MAX_NDL * 60)) |
| 38 | 556 { |
| 557 memcpy(local_tissue_nitrogen_bar, gTissue_nitrogen_bar, (4*16)); | |
| 558 memcpy(local_tissue_helium_bar, gTissue_helium_bar, (4*16)); | |
| 559 // | |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
560 ndl += 600; |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
561 decom_tissues_exposure2(600, &pDiveSettings->decogaslist[gGas_id], gPressure,gTissue_nitrogen_bar,gTissue_helium_bar); |
|
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
562 decom_oxygen_calculate_cns_exposure(600,&pDiveSettings->decogaslist[gGas_id],gPressure,&gCNS); |
| 38 | 563 buehlmann_backup_and_restore(true); |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
564 if(dive1_check_deco(pDiveSettings)) |
| 38 | 565 { |
| 566 buehlmann_backup_and_restore(false); | |
| 567 break; | |
| 568 } | |
| 569 buehlmann_backup_and_restore(false); | |
| 570 } | |
| 571 | |
|
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
261
diff
changeset
|
572 if(ndl < (MAX_NDL * 60)) |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
573 ndl -= 600; |
| 38 | 574 |
|
291
24ff72e627f4
Deco Models: limit NDL to 240 minutes
Jan Mulder <jlmulder@xs4all.nl>
parents:
261
diff
changeset
|
575 if(ndl > (MAX_NDL/2 * 60)) |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
576 return ndl; |
| 38 | 577 |
| 578 // refine | |
| 579 memcpy(gTissue_nitrogen_bar, local_tissue_nitrogen_bar, (4*16)); | |
| 580 memcpy(gTissue_helium_bar, local_tissue_helium_bar, (4*16)); | |
| 581 | |
| 582 //One minutes step | |
|
256
d10f53e39374
Buehlmann: trivial performance improvement (NDL)
Jan Mulder <jlmulder@xs4all.nl>
parents:
255
diff
changeset
|
583 for(i = 0; i < 10; i++) |
| 38 | 584 { |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
585 ndl += 60; |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
586 decom_tissues_exposure2(60, &pDiveSettings->decogaslist[gGas_id], gPressure,gTissue_nitrogen_bar,gTissue_helium_bar); |
|
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
587 decom_oxygen_calculate_cns_exposure(60,&pDiveSettings->decogaslist[gGas_id],gPressure,&gCNS); |
| 38 | 588 buehlmann_backup_and_restore(true); |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
589 if(dive1_check_deco(pDiveSettings)) |
| 38 | 590 break; |
| 591 buehlmann_backup_and_restore(false); | |
| 592 } | |
|
257
21387d7e786f
Buehlmann: factor out gNDL and gTTS
Jan Mulder <jlmulder@xs4all.nl>
parents:
256
diff
changeset
|
593 return ndl; |
| 38 | 594 } |
| 595 | |
| 596 | |
| 597 // =============================================================================== | |
| 598 // dive1_check_deco | |
| 599 /// @brief for NDL calculations | |
| 600 /// 160614 using ceilingOther and not ceiling | |
| 601 // =============================================================================== | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
602 static _Bool dive1_check_deco(SDiveSettings *pDiveSettings) |
| 38 | 603 { |
| 604 // gGF_value is set in call routine; | |
| 605 // internes Backup! | |
| 606 | |
| 607 // calc like in deco | |
| 608 float ceiling; | |
| 609 float ceilingOther; // new hw 160614 | |
| 610 | |
| 611 ceiling = tissue_tolerance(); | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
612 ambient_bar_to_deco_stop_depth_bar(pDiveSettings, ceiling); // this will set gStop.depth :-) (and gStop.id) |
| 38 | 613 |
| 614 // set the base for all upcoming parameters | |
| 615 ceilingOther = gStop.depth + gSurface_pressure_bar; | |
| 616 | |
| 617 // modify parameters if there is ascend or parameter fine adjustment | |
| 618 if(ceilingOther < (gPressure - PRESSURE_150_CM)) // more than 1.5 meter below ceiling | |
| 619 { | |
| 620 // ascend within 10 mtr to GF_low // speed 12 mtr/min -> 50 sec / 10 mtr; 15 sec / 3 mtr. | |
| 621 while(((gPressure - PRESSURE_TEN_METER ) > gSurface_pressure_bar) && (ceiling < (gPressure - PRESSURE_TEN_METER))) | |
| 622 { | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
623 ascend_with_all_gaschanges(pDiveSettings, PRESSURE_TEN_METER); |
| 38 | 624 ceiling = tissue_tolerance(); |
| 625 } | |
| 626 while(((gPressure - PRESSURE_THREE_METER )> gSurface_pressure_bar) && (ceiling < gPressure)) | |
| 627 { | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
628 ascend_with_all_gaschanges(pDiveSettings, PRESSURE_THREE_METER); |
| 38 | 629 ceiling = tissue_tolerance(); |
| 630 } | |
| 631 } | |
|
255
dcf7a3435fe1
Buehlmann: cleanup, factor out pBuDiveSettings
Jan Mulder <jlmulder@xs4all.nl>
parents:
254
diff
changeset
|
632 return ceiling > gSurface_pressure_bar; |
| 38 | 633 } |
| 634 | |
|
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
635 // compute ceiling recursively, with a resolution of 10cm. Notice |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
636 // that the initial call shall guarantee that the found ceiling |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
637 // is between low and high parameters. |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
638 static float compute_ceiling(float low, float high) |
| 38 | 639 { |
|
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
640 if ((high - low) < 0.01) |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
641 return low; |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
642 else { |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
643 float next_pressure_absolute = (low + high)/2; |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
644 float test_result = buehlmann_tissue_test_tolerance(next_pressure_absolute); |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
645 if (test_result < 0) |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
646 return compute_ceiling(low, next_pressure_absolute); |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
647 else |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
648 return compute_ceiling(next_pressure_absolute, high); |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
649 } |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
650 } |
| 38 | 651 |
|
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
652 void buehlmann_ceiling_calculator(SLifeData *pLifeData, SDecoinfo *pDecoInfo) |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
653 { |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
654 float ceiling; |
|
224
ceecabfddb57
Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
130
diff
changeset
|
655 |
|
261
cc2406b835ff
Bugfix: do not reset saturation on surfacing
Jan Mulder <jlmulder@xs4all.nl>
parents:
258
diff
changeset
|
656 memcpy(gTissue_nitrogen_bar, pLifeData->tissue_nitrogen_bar, (4*16)); |
|
cc2406b835ff
Bugfix: do not reset saturation on surfacing
Jan Mulder <jlmulder@xs4all.nl>
parents:
258
diff
changeset
|
657 memcpy(gTissue_helium_bar, pLifeData->tissue_helium_bar, (4*16)); |
|
cc2406b835ff
Bugfix: do not reset saturation on surfacing
Jan Mulder <jlmulder@xs4all.nl>
parents:
258
diff
changeset
|
658 |
|
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
659 // this is just performance optimizing. The code below runs just fine |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
660 // without this. There is never a ceiling in NDL deco state |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
661 if (!pDecoInfo->output_time_to_surface_seconds) { |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
662 pDecoInfo->output_ceiling_meter = 0; |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
663 return; |
| 38 | 664 } |
| 665 | |
|
250
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
666 ceiling = compute_ceiling(pLifeData->pressure_surface_bar, 1.0f + pLifeData->max_depth_meter/10.0f); |
|
822416168585
Buelmann: new implementation for ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
667 pDecoInfo->output_ceiling_meter = (ceiling - pLifeData->pressure_surface_bar) * 10.0f; |
| 38 | 668 } |
