Changeset 7b18be2a in subsurface


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

Adopt planner state caching to new struct

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

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • core/deco.c

    r57ee5a5 r7b18be2a  
    570570}
    571571
    572 void cache_deco_state(char **cached_datap)
    573 {
    574         char *data = *cached_datap;
     572void cache_deco_state(struct deco_state **cached_datap)
     573{
     574        struct deco_state *data = *cached_datap;
    575575
    576576        if (!data) {
    577                 data = malloc(2 * TISSUE_ARRAY_SZ + sizeof(double) + sizeof(int));
     577                data = malloc(sizeof(struct deco_state));
    578578                *cached_datap = data;
    579579        }
    580         memcpy(data, deco_state->tissue_n2_sat, TISSUE_ARRAY_SZ);
    581         data += TISSUE_ARRAY_SZ;
    582         memcpy(data, deco_state->tissue_he_sat, TISSUE_ARRAY_SZ);
    583         data += TISSUE_ARRAY_SZ;
    584         memcpy(data, &deco_state->gf_low_pressure_this_dive, sizeof(double));
    585         data += sizeof(double);
    586         memcpy(data, &deco_state->ci_pointing_to_guiding_tissue, sizeof(int));
    587 }
    588 
    589 void restore_deco_state(char *data)
    590 {
    591         memcpy(deco_state->tissue_n2_sat, data, TISSUE_ARRAY_SZ);
    592         data += TISSUE_ARRAY_SZ;
    593         memcpy(deco_state->tissue_he_sat, data, TISSUE_ARRAY_SZ);
    594         data += TISSUE_ARRAY_SZ;
    595         memcpy(&deco_state->gf_low_pressure_this_dive, data, sizeof(double));
    596         data += sizeof(double);
    597         memcpy(&deco_state->ci_pointing_to_guiding_tissue, data, sizeof(int));
     580        *data = *deco_state;
     581}
     582
     583void restore_deco_state(struct deco_state *data, bool keep_vpmb_state)
     584{
     585        if (keep_vpmb_state) {
     586                int ci;
     587                for (ci = 0; ci < 16; ci++) {
     588                        data->bottom_n2_gradient[ci] = deco_state->bottom_n2_gradient[ci];
     589                        data->bottom_he_gradient[ci] = deco_state->bottom_he_gradient[ci];
     590                        data->initial_n2_gradient[ci] = deco_state->initial_n2_gradient[ci];
     591                        data->initial_he_gradient[ci] = deco_state->initial_he_gradient[ci];
     592                }
     593        }
     594        *deco_state = *data;
     595
    598596}
    599597
  • core/dive.h

    r57ee5a5 r7b18be2a  
    864864extern void set_gf(short gflow, short gfhigh, bool gf_low_at_maxdepth);
    865865extern void set_vpmb_conservatism(short conservatism);
    866 extern void cache_deco_state(char **datap);
    867 extern void restore_deco_state(char *data);
     866extern void cache_deco_state(struct deco_state **datap);
     867extern void restore_deco_state(struct deco_state *data, bool keep_vpmb_state);
    868868extern void nuclear_regeneration(double time);
    869869extern void vpmb_start_gradient();
     
    901901void dump_plan(struct diveplan *diveplan);
    902902#endif
    903 bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool show_disclaimer);
     903bool plan(struct diveplan *diveplan, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer);
    904904void calc_crushing_pressure(double pressure);
    905905void vpmb_start_gradient();
  • core/planner.c

    rb1ccd2f r7b18be2a  
    131131
    132132/* returns the tissue tolerance at the end of this (partial) dive */
    133 unsigned int tissue_at_end(struct dive *dive, char **cached_datap)
     133unsigned int tissue_at_end(struct dive *dive, struct deco_state **cached_datap)
    134134{
    135135        struct divecomputer *dc;
     
    144144                return 0;
    145145        if (*cached_datap) {
    146                 restore_deco_state(*cached_datap);
     146                restore_deco_state(*cached_datap, true);
    147147        } else {
    148148                surface_interval = init_decompression(dive);
     
    564564
    565565        bool clear_to_ascend = true;
    566         char *trial_cache = NULL;
     566        struct deco_state *trial_cache = NULL;
    567567
    568568        // For consistency with other VPM-B implementations, we should not start the ascent while the ceiling is
    569569        // deeper than the next stop (thus the offgasing during the ascent is ignored).
    570570        // However, we still need to make sure we don't break the ceiling due to on-gassing during ascent.
     571        cache_deco_state(&trial_cache);
    571572        if (decoMode() == VPMB && (deco_allowed_depth(tissue_tolerance_calc(&displayed_dive,
    572573                                                                                 depth_to_bar(stoplevel, &displayed_dive)),
    573                                                            surface_pressure, &displayed_dive, 1) > stoplevel))
     574                                                           surface_pressure, &displayed_dive, 1) > stoplevel)) {
     575                restore_deco_state(trial_cache, false);
     576                free(trial_cache);
    574577                return false;
    575 
    576         cache_deco_state(&trial_cache);
     578        }
     579
    577580        while (trial_depth > stoplevel) {
    578581                int deltad = ascent_velocity(trial_depth, avg_depth, bottom_time) * TIMESTEP;
     
    590593                trial_depth -= deltad;
    591594        }
    592         restore_deco_state(trial_cache);
     595        restore_deco_state(trial_cache, false);
    593596        free(trial_cache);
    594597        return clear_to_ascend;
     
    614617// Work out the stops. Return value is if there were any mandatory stops.
    615618
    616 bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool show_disclaimer)
     619bool plan(struct diveplan *diveplan, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer)
    617620{
    618621        int bottom_depth;
     
    622625        int deco_time;
    623626        int previous_deco_time;
    624         char *bottom_cache = NULL;
     627        struct deco_state *bottom_cache = NULL;
    625628        struct sample *sample;
    626629        int po2;
     
    808811
    809812                previous_deco_time = deco_time;
    810                 restore_deco_state(bottom_cache);
     813                restore_deco_state(bottom_cache, true);
    811814
    812815                depth = bottom_depth;
  • core/profile.c

    r57ee5a5 r7b18be2a  
    951951        bool first_iteration = true;
    952952        int deco_time = 0, prev_deco_time = 10000000;
    953         char *cache_data_initial = NULL;
     953        struct deco_state *cache_data_initial = NULL;
    954954        /* For VPM-B outside the planner, cache the initial deco state for CVA iterations */
    955955        if (decoMode() == VPMB && !in_planner())
     
    10441044
    10451045                                /* We are going to mess up deco state, so store it for later restore */
    1046                                 char *cache_data = NULL;
     1046                                struct deco_state *cache_data = NULL;
    10471047                                cache_deco_state(&cache_data);
    10481048                                calculate_ndl_tts(entry, dive, surface_pressure);
     
    10501050                                        final_tts = entry->tts_calc;
    10511051                                /* Restore "real" deco state for next real time step */
    1052                                 restore_deco_state(cache_data);
     1052                                restore_deco_state(cache_data, false);
    10531053                                free(cache_data);
    10541054                        }
     
    10671067                        first_iteration = false;
    10681068                        count_iteration ++;
    1069                         restore_deco_state(cache_data_initial);
     1069                        restore_deco_state(cache_data_initial, false);
    10701070                } else {
    10711071                        // With Buhlmann, or not in planner, iterating isn't needed.  This makes the while condition false.
  • qt-models/diveplannermodel.cpp

    r5372f12 r7b18be2a  
    824824
    825825        // what does the cache do???
    826         char *cache = NULL;
     826        struct deco_state *cache = NULL;
    827827        struct divedatapoint *dp = NULL;
    828828        for (int i = 0; i < MAX_CYLINDERS; i++) {
     
    872872{
    873873        // Ok, so, here the diveplan creates a dive
    874         char *cache = NULL;
     874        struct deco_state *cache = NULL;
    875875        bool oldRecalc = setRecalc(false);
    876876        removeDeco();
  • tests/testplan.cpp

    ree1bf18 r7b18be2a  
    1111
    1212// testing the dive plan algorithm
    13 extern bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool show_disclaimer);
     13extern bool plan(struct diveplan *diveplan, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer);
    1414
    1515extern pressure_t first_ceiling_pressure;
     
    355355void TestPlan::testMetric()
    356356{
    357         char *cache = NULL;
     357        struct deco_state *cache = NULL;
    358358
    359359        setupPrefs();
     
    395395void TestPlan::testImperial()
    396396{
    397         char *cache = NULL;
     397        struct deco_state *cache = NULL;
    398398
    399399        setupPrefs();
     
    435435void TestPlan::testVpmbMetric45m30minTx()
    436436{
    437         char *cache = NULL;
     437        struct deco_state *cache = NULL;
    438438
    439439        setupPrefsVpmb();
     
    465465void TestPlan::testVpmbMetric60m10minTx()
    466466{
    467         char *cache = NULL;
     467        struct deco_state *cache = NULL;
    468468
    469469        setupPrefsVpmb();
     
    495495void TestPlan::testVpmbMetric60m30minAir()
    496496{
    497         char *cache = NULL;
     497        struct deco_state *cache = NULL;
    498498
    499499        setupPrefsVpmb();
     
    525525void TestPlan::testVpmbMetric60m30minEan50()
    526526{
    527         char *cache = NULL;
     527        struct deco_state *cache = NULL;
    528528
    529529        setupPrefsVpmb();
     
    561561void TestPlan::testVpmbMetric60m30minTx()
    562562{
    563         char *cache = NULL;
     563        struct deco_state *cache = NULL;
    564564
    565565        setupPrefsVpmb();
     
    597597void TestPlan::testVpmbMetric100m60min()
    598598{
    599         char *cache = NULL;
     599        struct deco_state *cache = NULL;
    600600
    601601        setupPrefsVpmb();
     
    639639void TestPlan::testVpmbMetricMultiLevelAir()
    640640{
    641         char *cache = NULL;
     641        struct deco_state *cache = NULL;
    642642
    643643        setupPrefsVpmb();
     
    669669void TestPlan::testVpmbMetric100m10min()
    670670{
    671         char *cache = NULL;
     671        struct deco_state *cache = NULL;
    672672
    673673        setupPrefsVpmb();
     
    715715void TestPlan::testVpmbMetricRepeat()
    716716{
    717         char *cache = NULL;
     717        struct deco_state *cache = NULL;
    718718
    719719        setupPrefsVpmb();
Note: See TracChangeset for help on using the changeset viewer.