comparison src/p2_deco.c @ 656:8af5aefbcdaf default tip

Update to 3.31 beta
author heinrichsweikamp
date Thu, 27 Nov 2025 18:32:58 +0100
parents 75e90cd0c2c3
children
comparison
equal deleted inserted replaced
655:c7b7b8a358cd 656:8af5aefbcdaf
1480 // the duration of the deco stop itself. 1480 // the duration of the deco stop itself.
1481 if( 0 < internal_deco_depth[stop_index] ) 1481 if( 0 < internal_deco_depth[stop_index] )
1482 if( char_depth_sim > internal_deco_depth[stop_index] ) 1482 if( char_depth_sim > internal_deco_depth[stop_index] )
1483 char_depth_sim = internal_deco_depth[stop_index]; 1483 char_depth_sim = internal_deco_depth[stop_index];
1484 1484
1485 // if using straight Buhlmann: done, stop needed 1485 // using straight Buhlmann?
1486 if( char_I_model == 0 ) return(1); 1486 if( char_I_model == 0 )
1487 1487 {
1488 // yes, reached surface?
1489 if( char_depth_sim == 0 ) return(0); // yes, no stop when at the surface
1490 else return(1); // no, stop needed
1491 }
1488 // ----------------------------------------------------------------------- 1492 // -----------------------------------------------------------------------
1489 // we need to make or hold a stop and we are using the GF extension 1493 // we need to make or hold a stop and we are using the GF extension
1490 // ----------------------------------------------------------------------- 1494 // -----------------------------------------------------------------------
1491 1495
1492 // is the stop_depth deeper than the GF low depth reference used up to now? 1496 // is the stop_depth deeper than the GF low depth reference used up to now?
2046 2050
2047 // also clear any time++ request 2051 // also clear any time++ request
2048 char_I_sim_advance_time = 0; 2052 char_I_sim_advance_time = 0;
2049 } 2053 }
2050 2054
2055 //////////////////////////////////////////////////////////////////////////////
2056 // calc_GF_surface
2057 //
2058 // Calculates the instantaneous surface GF (GF_surf) for the leading compartment.
2059 //
2060 // Definition:
2061 // GF_surf = (P_tissue - pres_surface) / (M_surf - pres_surface)
2062 //
2063 // - P_tissue : current inert gas tissue pressure (N2 + He) in bar
2064 // - pres_surface : pres_surface (Ambient pressure at the surface, in bar)
2065 // - M_surf : M-value on the surface (per calc_M_value_at_pressure)
2066 //
2067 // The maximum across all compartments is taken as GF_surf.
2068 // The result is written in percent (0..250) in int_O_GF_surface.
2069 //
2070 static float calc_M_value_at_pressure(float pres_surface)
2071 {
2072 float a, b;
2073 read_Buhlmann_coefficients();
2074 #ifdef _helium
2075 adopt_Buhlmann_coefficients();
2076 a = var_a;
2077 b = var_b;
2078 #else
2079 a = var_N2_a;
2080 b = var_N2_b;
2081 #endif
2082 return a + b * pres_surface;
2083 }
2084
2085 static void calc_GF_surface(void)
2086 {
2087 overlay float P_tissue;
2088 overlay float M_surf;
2089 overlay float gf_surf;
2090 overlay float gf_surf_max = 0.0f;
2091
2092 // Pass through all compartments
2093 for (ci = 0; ci < NUM_COMP; ci++)
2094 {
2095 #ifdef _helium
2096 P_tissue = real_pres_tissue_N2[ci] + real_pres_tissue_He[ci];
2097 #else
2098 P_tissue = real_pres_tissue_N2[ci];
2099 #endif
2100
2101 // M-value on the surface for this compartment
2102 M_surf = calc_M_value_at_pressure(pres_surface);
2103
2104 // Filtering out unnecessary cases
2105 if (M_surf <= pres_surface)
2106 continue;
2107
2108 // Surface-GF of this compartment
2109 gf_surf = (P_tissue - pres_surface) / (M_surf - pres_surface);
2110
2111 // Keep biggest result in gf_surf
2112 if (gf_surf > gf_surf_max)
2113 gf_surf_max = gf_surf;
2114 }
2115
2116 // Convert to %
2117 if (gf_surf_max <= 0.0f)
2118 {
2119 int_O_GF_surface = 0;
2120 }
2121 else
2122 {
2123 unsigned int tmp;
2124
2125 tmp = (unsigned int)(gf_surf_max * 100.0f + 0.5f);
2126
2127 if (tmp > 999)
2128 tmp = 999;
2129
2130 int_O_GF_surface = tmp;
2131 }
2132 }
2051 2133
2052 ////////////////////////////////////////////////////////////////////////////// 2134 //////////////////////////////////////////////////////////////////////////////
2053 // Reset all tissues to surface pressure equilibrium state 2135 // Reset all tissues to surface pressure equilibrium state
2054 // 2136 //
2055 // Input: int_I_pres_surface current surface pressure in hPa (mbar) 2137 // Input: int_I_pres_surface current surface pressure in hPa (mbar)
2305 // convert the saturation value of the leading tissue to integer 2387 // convert the saturation value of the leading tissue to integer
2306 convert_sat_for_display(); 2388 convert_sat_for_display();
2307 2389
2308 // convert the CNS value to integer 2390 // convert the CNS value to integer
2309 convert_cur_CNS_for_display(); 2391 convert_cur_CNS_for_display();
2392
2393 // compute the surface GF
2394 calc_GF_surface();
2310 2395
2311 } // tasks every 2 seconds 2396 } // tasks every 2 seconds
2312 2397
2313 2398
2314 // Tasks every second, if more than 1 invocation per second: on the first section of the second. 2399 // Tasks every second, if more than 1 invocation per second: on the first section of the second.