Changeset 57ee5a5 in subsurface


Ignore:
Timestamp:
May 26, 2017, 3:44:36 PM (3 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
7b18be2a
Parents:
b1ccd2f
git-author:
Robert C. Helling <helling@…> (05/25/17 13:29:25)
git-committer:
Dirk Hohndel <dirk@…> (05/26/17 15:44:36)
Message:

Assemble global state of planner in a struct

Signed-off-by: Robert C. Helling <helling@…>

Location:
core
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • core/deco.c

    r6399eaf r57ee5a5  
    155155#define NITROGEN_FRACTION 0.79
    156156
    157 double tissue_n2_sat[16];
    158 double tissue_he_sat[16];
    159 int ci_pointing_to_guiding_tissue;
    160 double gf_low_pressure_this_dive;
    161 #define TISSUE_ARRAY_SZ sizeof(tissue_n2_sat)
    162 
    163 double tolerated_by_tissue[16];
    164 double tissue_inertgas_saturation[16];
    165 double buehlmann_inertgas_a[16], buehlmann_inertgas_b[16];
    166 
    167 double max_n2_crushing_pressure[16];
    168 double max_he_crushing_pressure[16];
    169 
    170 double crushing_onset_tension[16];            // total inert gas tension in the t* moment
    171 double n2_regen_radius[16];                   // rs
    172 double he_regen_radius[16];
    173 double max_ambient_pressure;                  // last moment we were descending
    174 
    175 double bottom_n2_gradient[16];
    176 double bottom_he_gradient[16];
    177 
    178 double initial_n2_gradient[16];
    179 double initial_he_gradient[16];
     157struct deco_state global_deco_state;
     158
     159struct deco_state *deco_state = &global_deco_state;
     160
     161#define TISSUE_ARRAY_SZ sizeof(deco_state->tissue_n2_sat)
    180162
    181163int sumx, sum1;
     
    233215
    234216        if (reference_pressure >= first_ceiling_pressure.mbar / 1000.0 || !first_ceiling_pressure.mbar) {
    235                 n2_gradient = bottom_n2_gradient[ci];
    236                 he_gradient = bottom_he_gradient[ci];
     217                n2_gradient = deco_state->bottom_n2_gradient[ci];
     218                he_gradient = deco_state->bottom_he_gradient[ci];
    237219        } else {
    238                 n2_gradient = update_gradient(reference_pressure, bottom_n2_gradient[ci]);
    239                 he_gradient = update_gradient(reference_pressure, bottom_he_gradient[ci]);
    240         }
    241 
    242         total_gradient = ((n2_gradient * tissue_n2_sat[ci]) + (he_gradient * tissue_he_sat[ci])) / (tissue_n2_sat[ci] + tissue_he_sat[ci]);
    243 
    244         return tissue_n2_sat[ci] + tissue_he_sat[ci] + vpmb_config.other_gases_pressure - total_gradient;
     220                n2_gradient = update_gradient(reference_pressure, deco_state->bottom_n2_gradient[ci]);
     221                he_gradient = update_gradient(reference_pressure, deco_state->bottom_he_gradient[ci]);
     222        }
     223
     224        total_gradient = ((n2_gradient * deco_state->tissue_n2_sat[ci]) + (he_gradient * deco_state->tissue_he_sat[ci])) / (deco_state->tissue_n2_sat[ci] + deco_state->tissue_he_sat[ci]);
     225
     226        return deco_state->tissue_n2_sat[ci] + deco_state->tissue_he_sat[ci] + vpmb_config.other_gases_pressure - total_gradient;
    245227}
    246228
     
    257239
    258240        for (ci = 0; ci < 16; ci++) {
    259                 buehlmann_inertgas_a[ci] = ((buehlmann_N2_a[ci] * tissue_n2_sat[ci]) + (buehlmann_He_a[ci] * tissue_he_sat[ci])) / tissue_inertgas_saturation[ci];
    260                 buehlmann_inertgas_b[ci] = ((buehlmann_N2_b[ci] * tissue_n2_sat[ci]) + (buehlmann_He_b[ci] * tissue_he_sat[ci])) / tissue_inertgas_saturation[ci];
     241                deco_state->buehlmann_inertgas_a[ci] = ((buehlmann_N2_a[ci] * deco_state->tissue_n2_sat[ci]) + (buehlmann_He_a[ci] * deco_state->tissue_he_sat[ci])) / deco_state->tissue_inertgas_saturation[ci];
     242                deco_state->buehlmann_inertgas_b[ci] = ((buehlmann_N2_b[ci] * deco_state->tissue_n2_sat[ci]) + (buehlmann_He_b[ci] * deco_state->tissue_he_sat[ci])) / deco_state->tissue_inertgas_saturation[ci];
    261243        }
    262244
     
    266248                        /* tolerated = (tissue_inertgas_saturation - buehlmann_inertgas_a) * buehlmann_inertgas_b; */
    267249
    268                         tissue_lowest_ceiling[ci] = (buehlmann_inertgas_b[ci] * tissue_inertgas_saturation[ci] - gf_low * buehlmann_inertgas_a[ci] * buehlmann_inertgas_b[ci]) /
    269                                                      ((1.0 - buehlmann_inertgas_b[ci]) * gf_low + buehlmann_inertgas_b[ci]);
     250                        tissue_lowest_ceiling[ci] = (deco_state->buehlmann_inertgas_b[ci] * deco_state->tissue_inertgas_saturation[ci] - gf_low * deco_state->buehlmann_inertgas_a[ci] * deco_state->buehlmann_inertgas_b[ci]) /
     251                                                     ((1.0 - deco_state->buehlmann_inertgas_b[ci]) * gf_low + deco_state->buehlmann_inertgas_b[ci]);
    270252                        if (tissue_lowest_ceiling[ci] > lowest_ceiling)
    271253                                lowest_ceiling = tissue_lowest_ceiling[ci];
    272254                        if (!buehlmann_config.gf_low_at_maxdepth) {
    273                                 if (lowest_ceiling > gf_low_pressure_this_dive)
    274                                         gf_low_pressure_this_dive = lowest_ceiling;
     255                                if (lowest_ceiling > deco_state->gf_low_pressure_this_dive)
     256                                        deco_state->gf_low_pressure_this_dive = lowest_ceiling;
    275257                        }
    276258                }
     
    278260                        double tolerated;
    279261
    280                         if ((surface / buehlmann_inertgas_b[ci] + buehlmann_inertgas_a[ci] - surface) * gf_high + surface <
    281                             (gf_low_pressure_this_dive / buehlmann_inertgas_b[ci] + buehlmann_inertgas_a[ci] - gf_low_pressure_this_dive) * gf_low + gf_low_pressure_this_dive)
    282                                 tolerated = (-buehlmann_inertgas_a[ci] * buehlmann_inertgas_b[ci] * (gf_high * gf_low_pressure_this_dive - gf_low * surface) -
    283                                              (1.0 - buehlmann_inertgas_b[ci]) * (gf_high - gf_low) * gf_low_pressure_this_dive * surface +
    284                                              buehlmann_inertgas_b[ci] * (gf_low_pressure_this_dive - surface) * tissue_inertgas_saturation[ci]) /
    285                                             (-buehlmann_inertgas_a[ci] * buehlmann_inertgas_b[ci] * (gf_high - gf_low) +
    286                                              (1.0 - buehlmann_inertgas_b[ci]) * (gf_low * gf_low_pressure_this_dive - gf_high * surface) +
    287                                              buehlmann_inertgas_b[ci] * (gf_low_pressure_this_dive - surface));
     262                        if ((surface / deco_state->buehlmann_inertgas_b[ci] + deco_state->buehlmann_inertgas_a[ci] - surface) * gf_high + surface <
     263                            (deco_state->gf_low_pressure_this_dive / deco_state->buehlmann_inertgas_b[ci] + deco_state->buehlmann_inertgas_a[ci] - deco_state->gf_low_pressure_this_dive) * gf_low + deco_state->gf_low_pressure_this_dive)
     264                                tolerated = (-deco_state->buehlmann_inertgas_a[ci] * deco_state->buehlmann_inertgas_b[ci] * (gf_high * deco_state->gf_low_pressure_this_dive - gf_low * surface) -
     265                                             (1.0 - deco_state->buehlmann_inertgas_b[ci]) * (gf_high - gf_low) * deco_state->gf_low_pressure_this_dive * surface +
     266                                             deco_state->buehlmann_inertgas_b[ci] * (deco_state->gf_low_pressure_this_dive - surface) * deco_state->tissue_inertgas_saturation[ci]) /
     267                                            (-deco_state->buehlmann_inertgas_a[ci] * deco_state->buehlmann_inertgas_b[ci] * (gf_high - gf_low) +
     268                                             (1.0 - deco_state->buehlmann_inertgas_b[ci]) * (gf_low * deco_state->gf_low_pressure_this_dive - gf_high * surface) +
     269                                             deco_state->buehlmann_inertgas_b[ci] * (deco_state->gf_low_pressure_this_dive - surface));
    288270                        else
    289271                                tolerated = ret_tolerance_limit_ambient_pressure;
    290272
    291273
    292                         tolerated_by_tissue[ci] = tolerated;
     274                        deco_state->tolerated_by_tissue[ci] = tolerated;
    293275
    294276                        if (tolerated >= ret_tolerance_limit_ambient_pressure) {
    295                                 ci_pointing_to_guiding_tissue = ci;
     277                                deco_state->ci_pointing_to_guiding_tissue = ci;
    296278                                ret_tolerance_limit_ambient_pressure = tolerated;
    297279                        }
     
    309291                                double tolerated = vpmb_tolerated_ambient_pressure(reference_pressure, ci);
    310292                                if (tolerated >= ret_tolerance_limit_ambient_pressure) {
    311                                         ci_pointing_to_guiding_tissue = ci;
     293                                        deco_state->ci_pointing_to_guiding_tissue = ci;
    312294                                        ret_tolerance_limit_ambient_pressure = tolerated;
    313295                                }
    314                                 tolerated_by_tissue[ci] = tolerated;
     296                                deco_state->tolerated_by_tissue[ci] = tolerated;
    315297                        }
    316298                // We are doing ok if the gradient was computed within ten centimeters of the ceiling.
     
    322304                        sumxx += plot_depth * plot_depth;
    323305                        double n2_gradient, he_gradient, total_gradient;
    324                         n2_gradient = update_gradient(depth_to_bar(plot_depth, &displayed_dive), bottom_n2_gradient[ci_pointing_to_guiding_tissue]);
    325                         he_gradient = update_gradient(depth_to_bar(plot_depth, &displayed_dive), bottom_he_gradient[ci_pointing_to_guiding_tissue]);
    326                         total_gradient = ((n2_gradient * tissue_n2_sat[ci_pointing_to_guiding_tissue]) + (he_gradient * tissue_he_sat[ci_pointing_to_guiding_tissue]))
    327                                         / (tissue_n2_sat[ci_pointing_to_guiding_tissue] + tissue_he_sat[ci_pointing_to_guiding_tissue]);
    328 
    329                         double buehlmann_gradient = (1.0 / buehlmann_inertgas_b[ci_pointing_to_guiding_tissue] - 1.0) * depth_to_bar(plot_depth, &displayed_dive) + buehlmann_inertgas_a[ci_pointing_to_guiding_tissue];
     306                        n2_gradient = update_gradient(depth_to_bar(plot_depth, &displayed_dive), deco_state->bottom_n2_gradient[deco_state->ci_pointing_to_guiding_tissue]);
     307                        he_gradient = update_gradient(depth_to_bar(plot_depth, &displayed_dive), deco_state->bottom_he_gradient[deco_state->ci_pointing_to_guiding_tissue]);
     308                        total_gradient = ((n2_gradient * deco_state->tissue_n2_sat[deco_state->ci_pointing_to_guiding_tissue]) + (he_gradient * deco_state->tissue_he_sat[deco_state->ci_pointing_to_guiding_tissue]))
     309                                        / (deco_state->tissue_n2_sat[deco_state->ci_pointing_to_guiding_tissue] + deco_state->tissue_he_sat[deco_state->ci_pointing_to_guiding_tissue]);
     310
     311                        double buehlmann_gradient = (1.0 / deco_state->buehlmann_inertgas_b[deco_state->ci_pointing_to_guiding_tissue] - 1.0) * depth_to_bar(plot_depth, &displayed_dive) + deco_state->buehlmann_inertgas_a[deco_state->ci_pointing_to_guiding_tissue];
    330312                        double gf = (total_gradient - vpmb_config.other_gases_pressure) / buehlmann_gradient;
    331313                        sumxy += gf * plot_depth;
     
    403385
    404386        for (ci = 0; ci < 16; ++ci) {
    405                 initial_n2_gradient[ci] = bottom_n2_gradient[ci] = 2.0 * (vpmb_config.surface_tension_gamma / vpmb_config.skin_compression_gammaC) * ((vpmb_config.skin_compression_gammaC - vpmb_config.surface_tension_gamma) / n2_regen_radius[ci]);
    406                 initial_he_gradient[ci] = bottom_he_gradient[ci] = 2.0 * (vpmb_config.surface_tension_gamma / vpmb_config.skin_compression_gammaC) * ((vpmb_config.skin_compression_gammaC - vpmb_config.surface_tension_gamma) / he_regen_radius[ci]);
     387                deco_state->initial_n2_gradient[ci] = deco_state->bottom_n2_gradient[ci] = 2.0 * (vpmb_config.surface_tension_gamma / vpmb_config.skin_compression_gammaC) * ((vpmb_config.skin_compression_gammaC - vpmb_config.surface_tension_gamma) / deco_state->n2_regen_radius[ci]);
     388                deco_state->initial_he_gradient[ci] = deco_state->bottom_he_gradient[ci] = 2.0 * (vpmb_config.surface_tension_gamma / vpmb_config.skin_compression_gammaC) * ((vpmb_config.skin_compression_gammaC - vpmb_config.surface_tension_gamma) / deco_state->he_regen_radius[ci]);
    407389        }
    408390}
     
    417399
    418400        for (ci = 0; ci < 16; ++ci) {
    419                 desat_time = deco_time + calc_surface_phase(surface_pressure, tissue_he_sat[ci], tissue_n2_sat[ci], log(2.0) / buehlmann_He_t_halflife[ci], log(2.0) / buehlmann_N2_t_halflife[ci]);
    420 
    421                 n2_b = initial_n2_gradient[ci] + (vpmb_config.crit_volume_lambda * vpmb_config.surface_tension_gamma) / (vpmb_config.skin_compression_gammaC * desat_time);
    422                 he_b = initial_he_gradient[ci] + (vpmb_config.crit_volume_lambda * vpmb_config.surface_tension_gamma) / (vpmb_config.skin_compression_gammaC * desat_time);
    423 
    424                 n2_c = vpmb_config.surface_tension_gamma * vpmb_config.surface_tension_gamma * vpmb_config.crit_volume_lambda * max_n2_crushing_pressure[ci];
     401                desat_time = deco_time + calc_surface_phase(surface_pressure, deco_state->tissue_he_sat[ci], deco_state->tissue_n2_sat[ci], log(2.0) / buehlmann_He_t_halflife[ci], log(2.0) / buehlmann_N2_t_halflife[ci]);
     402
     403                n2_b = deco_state->initial_n2_gradient[ci] + (vpmb_config.crit_volume_lambda * vpmb_config.surface_tension_gamma) / (vpmb_config.skin_compression_gammaC * desat_time);
     404                he_b = deco_state->initial_he_gradient[ci] + (vpmb_config.crit_volume_lambda * vpmb_config.surface_tension_gamma) / (vpmb_config.skin_compression_gammaC * desat_time);
     405
     406                n2_c = vpmb_config.surface_tension_gamma * vpmb_config.surface_tension_gamma * vpmb_config.crit_volume_lambda * deco_state->max_n2_crushing_pressure[ci];
    425407                n2_c = n2_c / (vpmb_config.skin_compression_gammaC * vpmb_config.skin_compression_gammaC * desat_time);
    426                 he_c = vpmb_config.surface_tension_gamma * vpmb_config.surface_tension_gamma * vpmb_config.crit_volume_lambda * max_he_crushing_pressure[ci];
     408                he_c = vpmb_config.surface_tension_gamma * vpmb_config.surface_tension_gamma * vpmb_config.crit_volume_lambda * deco_state->max_he_crushing_pressure[ci];
    427409                he_c = he_c / (vpmb_config.skin_compression_gammaC * vpmb_config.skin_compression_gammaC * desat_time);
    428410
    429                 bottom_n2_gradient[ci] = 0.5 * ( n2_b + sqrt(n2_b * n2_b - 4.0 * n2_c));
    430                 bottom_he_gradient[ci] = 0.5 * ( he_b + sqrt(he_b * he_b - 4.0 * he_c));
     411                deco_state->bottom_n2_gradient[ci] = 0.5 * ( n2_b + sqrt(n2_b * n2_b - 4.0 * n2_c));
     412                deco_state->bottom_he_gradient[ci] = 0.5 * ( he_b + sqrt(he_b * he_b - 4.0 * he_c));
    431413        }
    432414}
     
    461443        for (ci = 0; ci < 16; ++ci) {
    462444                //rm
    463                 crushing_radius_N2 = 1.0 / (max_n2_crushing_pressure[ci] / (2.0 * (vpmb_config.skin_compression_gammaC - vpmb_config.surface_tension_gamma)) + 1.0 / get_crit_radius_N2());
    464                 crushing_radius_He = 1.0 / (max_he_crushing_pressure[ci] / (2.0 * (vpmb_config.skin_compression_gammaC - vpmb_config.surface_tension_gamma)) + 1.0 / get_crit_radius_He());
     445                crushing_radius_N2 = 1.0 / (deco_state->max_n2_crushing_pressure[ci] / (2.0 * (vpmb_config.skin_compression_gammaC - vpmb_config.surface_tension_gamma)) + 1.0 / get_crit_radius_N2());
     446                crushing_radius_He = 1.0 / (deco_state->max_he_crushing_pressure[ci] / (2.0 * (vpmb_config.skin_compression_gammaC - vpmb_config.surface_tension_gamma)) + 1.0 / get_crit_radius_He());
    465447                //rs
    466                 n2_regen_radius[ci] = crushing_radius_N2 + (get_crit_radius_N2() - crushing_radius_N2) * (1.0 - exp (-time / vpmb_config.regeneration_time));
    467                 he_regen_radius[ci] = crushing_radius_He + (get_crit_radius_He() - crushing_radius_He) * (1.0 - exp (-time / vpmb_config.regeneration_time));
     448                deco_state->n2_regen_radius[ci] = crushing_radius_N2 + (get_crit_radius_N2() - crushing_radius_N2) * (1.0 - exp (-time / vpmb_config.regeneration_time));
     449                deco_state->he_regen_radius[ci] = crushing_radius_He + (get_crit_radius_He() - crushing_radius_He) * (1.0 - exp (-time / vpmb_config.regeneration_time));
    468450        }
    469451}
     
    495477
    496478        for (ci = 0; ci < 16; ++ci) {
    497                 gas_tension = tissue_n2_sat[ci] + tissue_he_sat[ci] + vpmb_config.other_gases_pressure;
     479                gas_tension = deco_state->tissue_n2_sat[ci] + deco_state->tissue_he_sat[ci] + vpmb_config.other_gases_pressure;
    498480                gradient = pressure - gas_tension;
    499481
    500482                if (gradient <= vpmb_config.gradient_of_imperm) {       // permeable situation
    501483                        n2_crushing_pressure = he_crushing_pressure = gradient;
    502                         crushing_onset_tension[ci] = gas_tension;
     484                        deco_state->crushing_onset_tension[ci] = gas_tension;
    503485                }
    504486                else {  // impermeable
    505                         if (max_ambient_pressure >= pressure)
     487                        if (deco_state->max_ambient_pressure >= pressure)
    506488                                return;
    507489
    508                         n2_inner_pressure = calc_inner_pressure(get_crit_radius_N2(), crushing_onset_tension[ci], pressure);
    509                         he_inner_pressure = calc_inner_pressure(get_crit_radius_He(), crushing_onset_tension[ci], pressure);
     490                        n2_inner_pressure = calc_inner_pressure(get_crit_radius_N2(), deco_state->crushing_onset_tension[ci], pressure);
     491                        he_inner_pressure = calc_inner_pressure(get_crit_radius_He(), deco_state->crushing_onset_tension[ci], pressure);
    510492
    511493                        n2_crushing_pressure = pressure - n2_inner_pressure;
    512494                        he_crushing_pressure = pressure - he_inner_pressure;
    513495                }
    514                 max_n2_crushing_pressure[ci] = MAX(max_n2_crushing_pressure[ci], n2_crushing_pressure);
    515                 max_he_crushing_pressure[ci] = MAX(max_he_crushing_pressure[ci], he_crushing_pressure);
    516         }
    517         max_ambient_pressure = MAX(pressure, max_ambient_pressure);
     496                deco_state->max_n2_crushing_pressure[ci] = MAX(deco_state->max_n2_crushing_pressure[ci], n2_crushing_pressure);
     497                deco_state->max_he_crushing_pressure[ci] = MAX(deco_state->max_he_crushing_pressure[ci], he_crushing_pressure);
     498        }
     499        deco_state->max_ambient_pressure = MAX(pressure, deco_state->max_ambient_pressure);
    518500}
    519501
     
    528510                       gasmix, (double) ccpo2 / 1000.0, dive->dc.divemode);
    529511
    530         if (buehlmann_config.gf_low_at_maxdepth && pressure > gf_low_pressure_this_dive)
    531                 gf_low_pressure_this_dive = pressure;
     512        if (buehlmann_config.gf_low_at_maxdepth && pressure > deco_state->gf_low_pressure_this_dive)
     513                deco_state->gf_low_pressure_this_dive = pressure;
    532514
    533515        for (ci = 0; ci < 16; ci++) {
    534                 double pn2_oversat = pressures.n2 - tissue_n2_sat[ci];
    535                 double phe_oversat = pressures.he - tissue_he_sat[ci];
     516                double pn2_oversat = pressures.n2 - deco_state->tissue_n2_sat[ci];
     517                double phe_oversat = pressures.he - deco_state->tissue_he_sat[ci];
    536518                double n2_f = n2_factor(period_in_seconds, ci);
    537519                double he_f = he_factor(period_in_seconds, ci);
     
    539521                double he_satmult = phe_oversat > 0 ? buehlmann_config.satmult : buehlmann_config.desatmult;
    540522
    541                 tissue_n2_sat[ci] += n2_satmult * pn2_oversat * n2_f;
    542                 tissue_he_sat[ci] += he_satmult * phe_oversat * he_f;
    543                 tissue_inertgas_saturation[ci] = tissue_n2_sat[ci] + tissue_he_sat[ci];
     523                deco_state->tissue_n2_sat[ci] += n2_satmult * pn2_oversat * n2_f;
     524                deco_state->tissue_he_sat[ci] += he_satmult * phe_oversat * he_f;
     525                deco_state->tissue_inertgas_saturation[ci] = deco_state->tissue_n2_sat[ci] + deco_state->tissue_he_sat[ci];
    544526
    545527        }
     
    554536        printf("N2 tissues:");
    555537        for (ci = 0; ci < 16; ci++)
    556                 printf(" %6.3e", tissue_n2_sat[ci]);
     538                printf(" %6.3e", deco_state->tissue_n2_sat[ci]);
    557539        printf("\nHe tissues:");
    558540        for (ci = 0; ci < 16; ci++)
    559                 printf(" %6.3e", tissue_he_sat[ci]);
     541                printf(" %6.3e", deco_state->tissue_he_sat[ci]);
    560542        printf("\n");
    561543}
     
    564546        int ci;
    565547        for (ci = 0; ci < 16; ci++) {
    566                 max_n2_crushing_pressure[ci] = 0.0;
    567                 max_he_crushing_pressure[ci] = 0.0;
    568         }
    569         max_ambient_pressure = 0;
     548                deco_state->max_n2_crushing_pressure[ci] = 0.0;
     549                deco_state->max_he_crushing_pressure[ci] = 0.0;
     550        }
     551        deco_state->max_ambient_pressure = 0;
    570552}
    571553
     
    575557        clear_vpmb_state();
    576558        for (ci = 0; ci < 16; ci++) {
    577                 tissue_n2_sat[ci] = (surface_pressure - ((in_planner() && (decoMode() == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE)) * N2_IN_AIR / 1000;
    578                 tissue_he_sat[ci] = 0.0;
    579                 max_n2_crushing_pressure[ci] = 0.0;
    580                 max_he_crushing_pressure[ci] = 0.0;
    581                 n2_regen_radius[ci] = get_crit_radius_N2();
    582                 he_regen_radius[ci] = get_crit_radius_He();
    583         }
    584         gf_low_pressure_this_dive = surface_pressure;
     559                deco_state->tissue_n2_sat[ci] = (surface_pressure - ((in_planner() && (decoMode() == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE)) * N2_IN_AIR / 1000;
     560                deco_state->tissue_he_sat[ci] = 0.0;
     561                deco_state->max_n2_crushing_pressure[ci] = 0.0;
     562                deco_state->max_he_crushing_pressure[ci] = 0.0;
     563                deco_state->n2_regen_radius[ci] = get_crit_radius_N2();
     564                deco_state->he_regen_radius[ci] = get_crit_radius_He();
     565        }
     566        deco_state->gf_low_pressure_this_dive = surface_pressure;
    585567        if (!buehlmann_config.gf_low_at_maxdepth)
    586                 gf_low_pressure_this_dive += buehlmann_config.gf_low_position_min;
    587         max_ambient_pressure = 0.0;
     568                deco_state->gf_low_pressure_this_dive += buehlmann_config.gf_low_position_min;
     569        deco_state->max_ambient_pressure = 0.0;
    588570}
    589571
     
    596578                *cached_datap = data;
    597579        }
    598         memcpy(data, tissue_n2_sat, TISSUE_ARRAY_SZ);
     580        memcpy(data, deco_state->tissue_n2_sat, TISSUE_ARRAY_SZ);
    599581        data += TISSUE_ARRAY_SZ;
    600         memcpy(data, tissue_he_sat, TISSUE_ARRAY_SZ);
     582        memcpy(data, deco_state->tissue_he_sat, TISSUE_ARRAY_SZ);
    601583        data += TISSUE_ARRAY_SZ;
    602         memcpy(data, &gf_low_pressure_this_dive, sizeof(double));
     584        memcpy(data, &deco_state->gf_low_pressure_this_dive, sizeof(double));
    603585        data += sizeof(double);
    604         memcpy(data, &ci_pointing_to_guiding_tissue, sizeof(int));
     586        memcpy(data, &deco_state->ci_pointing_to_guiding_tissue, sizeof(int));
    605587}
    606588
    607589void restore_deco_state(char *data)
    608590{
    609         memcpy(tissue_n2_sat, data, TISSUE_ARRAY_SZ);
     591        memcpy(deco_state->tissue_n2_sat, data, TISSUE_ARRAY_SZ);
    610592        data += TISSUE_ARRAY_SZ;
    611         memcpy(tissue_he_sat, data, TISSUE_ARRAY_SZ);
     593        memcpy(deco_state->tissue_he_sat, data, TISSUE_ARRAY_SZ);
    612594        data += TISSUE_ARRAY_SZ;
    613         memcpy(&gf_low_pressure_this_dive, data, sizeof(double));
     595        memcpy(&deco_state->gf_low_pressure_this_dive, data, sizeof(double));
    614596        data += sizeof(double);
    615         memcpy(&ci_pointing_to_guiding_tissue, data, sizeof(int));
     597        memcpy(&deco_state->ci_pointing_to_guiding_tissue, data, sizeof(int));
    616598}
    617599
     
    660642        double gf_high = buehlmann_config.gf_high;
    661643        double gf;
    662         if (gf_low_pressure_this_dive > surface_pressure_bar)
     644        if (deco_state->gf_low_pressure_this_dive > surface_pressure_bar)
    663645                gf = MAX((double)gf_low, (ambpressure_bar - surface_pressure_bar) /
    664                         (gf_low_pressure_this_dive - surface_pressure_bar) * (gf_low - gf_high) + gf_high);
     646                        (deco_state->gf_low_pressure_this_dive - surface_pressure_bar) * (gf_low - gf_high) + gf_high);
    665647        else
    666648                gf = gf_low;
  • core/deco.h

    r6399eaf r57ee5a5  
    77#endif
    88
    9 extern double tolerated_by_tissue[];
    109extern double buehlmann_N2_t_halflife[];
    11 extern double tissue_inertgas_saturation[16];
    12 extern double buehlmann_inertgas_a[16], buehlmann_inertgas_b[16];
    13 extern double gf_low_pressure_this_dive;
     10extern struct deco_state *deco_state;
    1411
    1512extern int deco_allowed_depth(double tissues_tolerance, double surface_pressure, struct dive *dive, bool smooth);
  • core/dive.h

    r0dfa448 r57ee5a5  
    833833#define FRACTION(n, x) ((unsigned)(n) / (x)), ((unsigned)(n) % (x))
    834834
     835struct deco_state {
     836        double tissue_n2_sat[16];
     837        double tissue_he_sat[16];
     838        double tolerated_by_tissue[16];
     839        double tissue_inertgas_saturation[16];
     840        double buehlmann_inertgas_a[16];
     841        double buehlmann_inertgas_b[16];
     842
     843        double max_n2_crushing_pressure[16];
     844        double max_he_crushing_pressure[16];
     845
     846        double crushing_onset_tension[16];            // total inert gas tension in the t* moment
     847        double n2_regen_radius[16];                   // rs
     848        double he_regen_radius[16];
     849        double max_ambient_pressure;                  // last moment we were descending
     850
     851        double bottom_n2_gradient[16];
     852        double bottom_he_gradient[16];
     853
     854        double initial_n2_gradient[16];
     855        double initial_he_gradient[16];
     856        int ci_pointing_to_guiding_tissue;
     857        double gf_low_pressure_this_dive;
     858
     859};
     860
    835861extern void add_segment(double pressure, const struct gasmix *gasmix, int period_in_seconds, int setpoint, const struct dive *dive, int sac);
    836862extern void clear_deco(double surface_pressure);
  • core/profile.c

    rb368ecd r57ee5a5  
    10191019                        }
    10201020                        for (j = 0; j < 16; j++) {
    1021                                 double m_value = buehlmann_inertgas_a[j] + entry->ambpressure / buehlmann_inertgas_b[j];
    1022                                 entry->ceilings[j] = deco_allowed_depth(tolerated_by_tissue[j], surface_pressure, dive, 1);
    1023                                 entry->percentages[j] = tissue_inertgas_saturation[j] < entry->ambpressure ?
    1024                                         lrint(tissue_inertgas_saturation[j] / entry->ambpressure * AMB_PERCENTAGE) :
    1025                                         lrint(AMB_PERCENTAGE + (tissue_inertgas_saturation[j] - entry->ambpressure) / (m_value - entry->ambpressure) * (100.0 - AMB_PERCENTAGE));
     1021                                double m_value = deco_state->buehlmann_inertgas_a[j] + entry->ambpressure / deco_state->buehlmann_inertgas_b[j];
     1022                                entry->ceilings[j] = deco_allowed_depth(deco_state->tolerated_by_tissue[j], surface_pressure, dive, 1);
     1023                                entry->percentages[j] = deco_state->tissue_inertgas_saturation[j] < entry->ambpressure ?
     1024                                        lrint(deco_state->tissue_inertgas_saturation[j] / entry->ambpressure * AMB_PERCENTAGE) :
     1025                                        lrint(AMB_PERCENTAGE + (deco_state->tissue_inertgas_saturation[j] - entry->ambpressure) / (m_value - entry->ambpressure) * (100.0 - AMB_PERCENTAGE));
    10261026                        }
    10271027
Note: See TracChangeset for help on using the changeset viewer.