comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 236:3dbeacf42e9e

BUGFIX missing deko init in reboot code. + Typo in ppN2 name.
author JeanDo
date Sat, 19 Mar 2011 15:15:17 +0100
parents ade0848c8b8b
children 55178aa1f972
comparison
equal deleted inserted replaced
235:ade0848c8b8b 236:3dbeacf42e9e
164 164
165 static unsigned char ci; 165 static unsigned char ci;
166 static float pres_respiration; 166 static float pres_respiration;
167 static float pres_surface; 167 static float pres_surface;
168 static float temp_deco; 168 static float temp_deco;
169 static float ppO2; 169 static float ppN2;
170 static float ppHe; 170 static float ppHe;
171 static float temp_tissue; 171 static float temp_tissue;
172 static float N2_ratio; // Breathed gas nitrogen ratio. 172 static float N2_ratio; // Breathed gas nitrogen ratio.
173 static float He_ratio; // Breathed gas helium ratio. 173 static float He_ratio; // Breathed gas helium ratio.
174 static float var_N2_a; // Bühlmann a, for current N2 tissue. 174 static float var_N2_a; // Bühlmann a, for current N2 tissue.
644 //---- ZH-L16 + GRADIENT FACTOR model ------------------------------------ 644 //---- ZH-L16 + GRADIENT FACTOR model ------------------------------------
645 if (char_I_deco_model == 1) 645 if (char_I_deco_model == 1)
646 { 646 {
647 // Recompute leading gas limit, at current depth: 647 // Recompute leading gas limit, at current depth:
648 overlay float depth = (temp_deco - pres_surface) / 0.09995; 648 overlay float depth = (temp_deco - pres_surface) / 0.09995;
649 assert( depth >= 0.0 ); 649 assert( depth >= -0.01 ); // -epsilon tolerance.
650 assert( low_depth < 255 ); 650 assert( low_depth < 255 );
651 651
652 if( depth > low_depth ) 652 if( depth > low_depth )
653 sim_limit( GF_low ); 653 sim_limit( GF_low );
654 else 654 else
1004 // 1004 //
1005 // Input: calc_N2_ratio, calc_He_ratio : simulated gas mix. 1005 // Input: calc_N2_ratio, calc_He_ratio : simulated gas mix.
1006 // temp_deco : simulated respiration pressure + security offset (deco_distance) 1006 // temp_deco : simulated respiration pressure + security offset (deco_distance)
1007 // Water-vapor pressure inside lumbs (ppWVapour). 1007 // Water-vapor pressure inside lumbs (ppWVapour).
1008 // 1008 //
1009 // Output: ppO2, ppHe. 1009 // Output: ppN2, ppHe.
1010 // 1010 //
1011 static void sim_alveolar_presures(void) 1011 static void sim_alveolar_presures(void)
1012 { 1012 {
1013 overlay float deco_diluent = temp_deco; // new in v.101 1013 overlay float deco_diluent = temp_deco; // new in v.101
1014 1014
1029 if( deco_diluent > pres_surface ) 1029 if( deco_diluent > pres_surface )
1030 deco_diluent += float_deco_distance; 1030 deco_diluent += float_deco_distance;
1031 1031
1032 if( deco_diluent > ppWVapour ) 1032 if( deco_diluent > ppWVapour )
1033 { 1033 {
1034 ppO2 = calc_N2_ratio * (deco_diluent - ppWVapour); 1034 ppN2 = calc_N2_ratio * (deco_diluent - ppWVapour);
1035 ppHe = calc_He_ratio * (deco_diluent - ppWVapour); 1035 ppHe = calc_He_ratio * (deco_diluent - ppWVapour);
1036 } 1036 }
1037 else 1037 else
1038 { 1038 {
1039 ppO2 = 0.0; 1039 ppN2 = 0.0;
1040 ppHe = 0.0; 1040 ppHe = 0.0;
1041 } 1041 }
1042 assert( 0.0 <= ppO2 && ppO2 < 14.0 ); 1042 assert( 0.0 <= ppN2 && ppN2 < 14.0 );
1043 assert( 0.0 <= ppHe && ppHe < 14.0 ); 1043 assert( 0.0 <= ppHe && ppHe < 14.0 );
1044 } 1044 }
1045 1045
1046 ////////////////////////////////////////////////////////////////////////////// 1046 //////////////////////////////////////////////////////////////////////////////
1047 // clear_tissue 1047 // clear_tissue
1271 if (pres_diluent > pres_respiration) // new in v.101 1271 if (pres_diluent > pres_respiration) // new in v.101
1272 pres_diluent = pres_respiration; // new in v.101 1272 pres_diluent = pres_respiration; // new in v.101
1273 } 1273 }
1274 if (pres_diluent > ppWVapour) // new in v.101 1274 if (pres_diluent > ppWVapour) // new in v.101
1275 { 1275 {
1276 ppO2 = N2_ratio * (pres_diluent - ppWVapour); // changed in v.101 1276 ppN2 = N2_ratio * (pres_diluent - ppWVapour); // changed in v.101
1277 ppHe = He_ratio * (pres_diluent - ppWVapour); // changed in v.101 1277 ppHe = He_ratio * (pres_diluent - ppWVapour); // changed in v.101
1278 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0); 1278 char_O_diluent = (char)(pres_diluent/pres_respiration*100.0);
1279 } 1279 }
1280 else // new in v.101 1280 else // new in v.101
1281 { 1281 {
1282 ppO2 = 0.0; // new in v.101 1282 ppN2 = 0.0; // new in v.101
1283 ppHe = 0.0; // new in v.101 1283 ppHe = 0.0; // new in v.101
1284 char_O_diluent = 0; 1284 char_O_diluent = 0;
1285 } 1285 }
1286 1286
1287 if(!char_I_step_is_1min) 1287 if(!char_I_step_is_1min)
1420 // 1420 //
1421 // optimized in v.101 1421 // optimized in v.101
1422 // 1422 //
1423 static void calc_tissue(PARAMETER unsigned char period) 1423 static void calc_tissue(PARAMETER unsigned char period)
1424 { 1424 {
1425 assert( 0.00 <= ppN2 && ppN2 < 6.40 ); // 80% N2 at 70m
1426 assert( 0.00 <= ppHe && ppHe < 18.9 ); // 90% He at 200m
1427
1425 for (ci=0;ci<16;ci++) 1428 for (ci=0;ci<16;ci++)
1426 { 1429 {
1427 read_buhlmann_coefficients(period); // 2 sec or 1 min period. 1430 read_buhlmann_coefficients(period); // 2 sec or 1 min period.
1428 1431
1429 // N2 1432 // N2
1430 temp_tissue = (ppO2 - pres_tissue[ci]) * var_N2_e; 1433 temp_tissue = (ppN2 - pres_tissue[ci]) * var_N2_e;
1431 temp_tissue_safety(); 1434 temp_tissue_safety();
1432 pres_tissue[ci] += temp_tissue; 1435 pres_tissue[ci] += temp_tissue;
1433 1436
1434 // He 1437 // He
1435 temp_tissue = (ppHe - (pres_tissue+16)[ci]) * var_He_e; 1438 temp_tissue = (ppHe - (pres_tissue+16)[ci]) * var_He_e;
1600 // Function very simular to calc_tissue, but: 1603 // Function very simular to calc_tissue, but:
1601 // + Use a 1min or 10min period. 1604 // + Use a 1min or 10min period.
1602 // + Do it on sim_pres_tissue, instead of pres_tissue. 1605 // + Do it on sim_pres_tissue, instead of pres_tissue.
1603 static void sim_tissue(PARAMETER unsigned char period) 1606 static void sim_tissue(PARAMETER unsigned char period)
1604 { 1607 {
1608 assert( 0.00 <= ppN2 && ppN2 < 6.40 ); // 80% N2 at 70m
1609 assert( 0.00 <= ppHe && ppHe < 18.9 ); // 90% He at 200m
1610
1605 for(ci=0; ci<16; ci++) 1611 for(ci=0; ci<16; ci++)
1606 { 1612 {
1607 read_buhlmann_coefficients(period); // 1 or 10 minute(s) interval 1613 read_buhlmann_coefficients(period); // 1 or 10 minute(s) interval
1608 1614
1609 // N2 1615 // N2
1610 temp_tissue = (ppO2 - sim_pres_tissue[ci]) * var_N2_e; 1616 temp_tissue = (ppN2 - sim_pres_tissue[ci]) * var_N2_e;
1611 temp_tissue_safety(); 1617 temp_tissue_safety();
1612 sim_pres_tissue[ci] += temp_tissue; 1618 sim_pres_tissue[ci] += temp_tissue;
1613 1619
1614 // He 1620 // He
1615 temp_tissue = (ppHe - (sim_pres_tissue+16)[ci]) * var_He_e; 1621 temp_tissue = (ppHe - (sim_pres_tissue+16)[ci]) * var_He_e;
1807 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 ); 1813 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 );
1808 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 ); 1814 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 );
1809 1815
1810 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann 1816 N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann
1811 pres_surface = int_I_pres_surface * 0.001; 1817 pres_surface = int_I_pres_surface * 0.001;
1812 ppO2 = N2_ratio * (pres_surface - ppWVapour); 1818 ppN2 = N2_ratio * (pres_surface - ppWVapour);
1813 int_O_desaturation_time = 0; 1819 int_O_desaturation_time = 0;
1814 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 1820 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
1815 1821
1816 for (ci=0;ci<16;ci++) 1822 for (ci=0;ci<16;ci++)
1817 { 1823 {
1821 // saturation_time (for flight) and N2_saturation in multiples of halftime 1827 // saturation_time (for flight) and N2_saturation in multiples of halftime
1822 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time ) 1828 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time )
1823 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time ) 1829 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time )
1824 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations 1830 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations
1825 // N2 1831 // N2
1826 temp1 = 1.05 * ppO2; 1832 temp1 = 1.05 * ppN2;
1827 temp1 = temp1 - pres_tissue[ci]; 1833 temp1 = temp1 - pres_tissue[ci];
1828 temp2 = ppO2 - pres_tissue[ci]; 1834 temp2 = ppN2 - pres_tissue[ci];
1829 if (temp2 >= 0.0) 1835 if (temp2 >= 0.0)
1830 { 1836 {
1831 temp1 = 0.0; 1837 temp1 = 0.0;
1832 temp2 = 0.0; 1838 temp2 = 0.0;
1833 } 1839 }
1914 } 1920 }
1915 1921
1916 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann 1922 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann
1917 pres_respiration = int_I_pres_respiration * 0.001; // assembler code uses different digit system 1923 pres_respiration = int_I_pres_respiration * 0.001; // assembler code uses different digit system
1918 pres_surface = int_I_pres_surface * 0.001; // the b"uhlmann formula using pres_surface does not use the N2_ratio 1924 pres_surface = int_I_pres_surface * 0.001; // the b"uhlmann formula using pres_surface does not use the N2_ratio
1919 ppO2 = N2_ratio * (pres_respiration - ppWVapour); // ppWVapour is the extra pressure in the body 1925 ppN2 = N2_ratio * (pres_respiration - ppWVapour); // ppWVapour is the extra pressure in the body
1920 ppHe = 0.0; 1926 ppHe = 0.0;
1921 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142) 1927 float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101 (70,42%/100.=142)
1922 float_saturation_multiplier = char_I_saturation_multiplier * 0.01; 1928 float_saturation_multiplier = char_I_saturation_multiplier * 0.01;
1923 1929
1924 calc_tissue(1); // update the pressure in the 32 tissues in accordance with the new ambient pressure 1930 calc_tissue(1); // update the pressure in the 32 tissues in accordance with the new ambient pressure