Changeset 22880


Ignore:
Timestamp:
06/28/18 10:05:28 (7 years ago)
Author:
jdquinn
Message:

CHG: Cleanup (in particular, no need to call string.toLowerCase() repeatedly)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/m/solve/solve.js

    r22831 r22880  
    1 function solve(md, solutionstring) { //{{{
     1function solve(md, solutionstring) {//{{{
    22/**
    33 * SOLVE - apply solution sequence for this model
     
    4545
    4646        //recover and process solve options
    47         if ((solutionstring.toLowerCase() === 'sb') || (solutionstring.toLowerCase() === 'stressbalance')) {
     47        let solutionStringLowerCase = solutionstring.toLowerCase();
     48       
     49        if ((solutionStringLowerCase === 'sb') || (solutionStringLowerCase === 'stressbalance')) {
    4850                solutionstring = 'StressbalanceSolution';
    49         } else if ((solutionstring.toLowerCase() === 'mt') || (solutionstring.toLowerCase() === 'masstransport')) {
     51        } else if ((solutionStringLowerCase === 'mt') || (solutionStringLowerCase === 'masstransport')) {
    5052                solutionstring = 'MasstransportSolution';       
    51         } else if ((solutionstring.toLowerCase() === 'th') || (solutionstring.toLowerCase() === 'thermal')) {
     53        } else if ((solutionStringLowerCase === 'th') || (solutionStringLowerCase === 'thermal')) {
    5254                solutionstring = 'ThermalSolution';
    53         } else if ((solutionstring.toLowerCase() === 'st') || (solutionstring.toLowerCase() === 'steadystate')) {
     55        } else if ((solutionStringLowerCase === 'st') || (solutionStringLowerCase === 'steadystate')) {
    5456                solutionstring = 'SteadystateSolution';
    55         } else if ((solutionstring.toLowerCase() === 'tr') || (solutionstring.toLowerCase() === 'transient')) {
     57        } else if ((solutionStringLowerCase === 'tr') || (solutionStringLowerCase === 'transient')) {
    5658                solutionstring = 'TransientSolution';
    57         } else if ((solutionstring.toLowerCase() === 'mc') || (solutionstring.toLowerCase() === 'balancethickness')) {
     59        } else if ((solutionStringLowerCase === 'mc') || (solutionStringLowerCase === 'balancethickness')) {
    5860                solutionstring = 'BalancethicknessSolution';
    59         } else if ((solutionstring.toLowerCase() === 'bv') || (solutionstring.toLowerCase() === 'balancevelocity')) {
     61        } else if ((solutionStringLowerCase === 'bv') || (solutionStringLowerCase === 'balancevelocity')) {
    6062                solutionstring = 'BalancevelocitySolution';
    61         } else if ((solutionstring.toLowerCase() === 'bsl') || (solutionstring.toLowerCase() === 'bedslope')) {
     63        } else if ((solutionStringLowerCase === 'bsl') || (solutionStringLowerCase === 'bedslope')) {
    6264                solutionstring = 'BedSlopeSolution';
    63         } else if ((solutionstring.toLowerCase() === 'ssl') || (solutionstring.toLowerCase() === 'surfaceslope')) {
     65        } else if ((solutionStringLowerCase === 'ssl') || (solutionStringLowerCase === 'surfaceslope')) {
    6466                solutionstring = 'SurfaceSlopeSolution';
    65         } else if ((solutionstring.toLowerCase() === 'hy') || (solutionstring.toLowerCase() === 'hydrology')) {
     67        } else if ((solutionStringLowerCase === 'hy') || (solutionStringLowerCase === 'hydrology')) {
    6668                solutionstring = 'HydrologySolution';
    67         } else if ((solutionstring.toLowerCase() === 'da') || (solutionstring.toLowerCase() === 'damageevolution')) {
     69        } else if ((solutionStringLowerCase === 'da') || (solutionStringLowerCase === 'damageevolution')) {
    6870                solutionstring = 'DamageEvolutionSolution';
    69         } else if ((solutionstring.toLowerCase() === 'gia') || (solutionstring.toLowerCase() === 'gia')) {
     71        } else if ((solutionStringLowerCase === 'gia') || (solutionStringLowerCase === 'gia')) {
    7072                solutionstring = 'GiaSolution';
    71         } else if ((solutionstring.toLowerCase() === 'slr') || (solutionstring.toLowerCase() === 'sealevelrise')) {
     73        } else if ((solutionStringLowerCase === 'slr') || (solutionStringLowerCase === 'sealevelrise')) {
    7274                solutionstring = 'SealevelriseSolution';
    7375        } else {
     
    7577        }
    7678       
    77         //Process options
    78         var args = Array.prototype.slice.call(arguments);
    79         var options = new pairoptions(args.slice(2,args.length));
    80         options.addfield('solutionstring',solutionstring);
    81 
    82         //recover some fields
    83         md.priv.solution=solutionstring;
    84         cluster=md.cluster;
     79        // Process options
     80        let args        = Array.prototype.slice.call(arguments);
     81        let options = new pairoptions(args.slice(2, args.length));
     82        options.addfield('solutionstring', solutionstring);
     83
     84        // recover some fields
     85        md.priv.solution        = solutionstring;
     86        cluster                         = md.cluster;
    8587
    8688        //check model consistency
    87         if (options.getfieldvalue('checkconsistency','yes') == 'yes'){
    88                 if (md.verbose.solution){
     89        if (options.getfieldvalue('checkconsistency', 'yes') === 'yes') {
     90                if (md.verbose.solution) {
    8991                        console.log('checking model consistency');
    9092                }
     93               
    9194                ismodelselfconsistent(md);
    9295        }
    9396
    94         //If we are restarting, actually use the provided runtime name:
    95         restart=options.getfieldvalue('restart','');
    96 
    97         //First, build a runtime name that is unique
    98         if (restart==1 ){
    99                 //Leave the runtimename as is
     97        // If we are restarting, actually use the provided runtime name:
     98        restart = options.getfieldvalue('restart', '');
     99
     100        // First, build a runtime name that is unique
     101        if (restart === 1 ) {
     102                // Leave the runtimename as is
     103        } else {
     104                if (!(restart === '')) {
     105                        md.priv.runtimename=restart;
     106                } else if (options.getfieldvalue('runtimename',true)) {
     107                        let c = new Date().getTime();
     108                        md.priv.runtimename = sprintf('%s-%g', md.miscellaneous.name, c);
     109                } else {
     110                        md.priv.runtimename = md.miscellaneous.name;
    100111                }
    101         else{
    102                 if (!(restart == '')){
    103                         md.priv.runtimename=restart;
    104                 }
    105                 else if (options.getfieldvalue('runtimename',true)){
    106                         c=new Date().getTime();
    107                         md.priv.runtimename=sprintf('%s-%g',md.miscellaneous.name,c);
    108                 }
    109                 else{
    110                         md.priv.runtimename=md.miscellaneous.name;
    111                 }
    112         }
    113 
    114         //if running qmu analysis, some preprocessing of dakota files using models
    115         //fields needs to be carried out.
    116         if (md.qmu.isdakota){
     112        }
     113
     114        // If running qmu analysis, some preprocessing of dakota files using models fields needs to be carried out
     115        if (md.qmu.isdakota) {
    117116                throw Error("solve error message: qmu runs not supported yet!");
    118117                //md.preqmu(options);
    119118        }
    120119
    121 
    122         //Do we load results only?
    123         if (options.getfieldvalue('loadonly',false)){
     120        // Do we load results only?
     121        if (options.getfieldvalue('loadonly', false)){
    124122                loadresultsfromcluster(md);
    125123                return;
    126124        }
    127125
    128         //Marshall into a binary array (fid) all the fields of model.
    129         var fid = marshall(md);                                          // bin file
     126        // Marshall into a binary array (fid) all the fields of model
     127        let fid = marshall(md); // bin file
    130128       
    131129        //deal with toolkits options:
    132         toolkitsstring= md.toolkits.ToolkitsFile(md.miscellaneous.name + '.toolkits'); // toolkits file
     130        toolkitsstring = md.toolkits.ToolkitsFile(md.miscellaneous.name + '.toolkits'); // toolkits file
    133131
    134132
    135133        /*
    136134                Set success callback function
    137         */
    138         //{{{
    139        
    140         // Default: do nothing if no success callback function requested
     135               
     136                Default: do nothing if no success callback function requested
     137        */
     138        //{{{
    141139        function successCallbackDefault() {
    142140                solving = false;
     
    149147        /*
    150148                Set error callback function
    151         */
    152         //{{{
    153        
    154         // Default: do nothing if no error callback function requested
     149               
     150                Default: do nothing if no error callback function requested
     151        */
     152        //{{{
    155153        function errorCallbackDefault() {
    156154                solving = false;
     
    163161        /*
    164162                Set solve button ID
    165         */
    166         //{{{
    167        
    168         // Default: update #solve-button element with progress updates
     163               
     164                Default: update #solve-button element with progress updates
     165        */
     166        //{{{
    169167        let solveButtonId = options.getfieldvalue('solveButtonId', '#solve-button');
    170168        //}}}
     
    184182        /*
    185183                Set progress bar display boolean
    186         */
    187         //{{{
    188         // Default: no progress bar; NOTE: must have supplied a callout for progress bar to display
     184               
     185                Default: no progress bar
     186               
     187                NOTE: must have supplied a callout for progress bar to display
     188        */
     189        //{{{
    189190        let withProgressBar = options.getfieldvalue('withProgressBar', false);
    190191        //}}}
    191192
    192193
    193         if (cluster.classname() == 'local'){ //{{{
    194 
    195                 /*We are running locally on the machine, using the issm module:*/
     194        if (cluster.classname() === 'local') {//{{{
     195
     196                // We are running locally on the machine, using the issm module
    196197                console.log('running issm locally');
    197198               
    198                 //Call issm:
    199                 var outputs = issm(fid, toolkitsstring, solutionstring, md.miscellaneous.name);
    200                
    201                 //Recover output arguments:
    202                 var outputbuffer = outputs[0]; var outputbuffersize = outputs[1];
     199                // Call issm
     200                let outputs = issm(fid, toolkitsstring, solutionstring, md.miscellaneous.name);
     201               
     202                // Recover output arguments:
     203                let outputbuffer                = outputs[0];
     204                let outputbuffersize    = outputs[1];
    203205                       
    204                 //Load results:
     206                // Load results
    205207                md = loadresultsfrombuffer(md, outputbuffer, outputbuffersize);
    206208               
     
    210212                return md;
    211213        //}}}
    212         } else { //{{{
     214        } else {//{{{
    213215                // We are running somewhere else on a computational server. Send the buffer to that server and retrieve output.
    214216                console.log('running issm remotely');
     
    229231
    230232                return md;
    231         //}}}
    232         }
    233 //}}}
    234 }
     233        }//}}}
     234}//}}}
Note: See TracChangeset for help on using the changeset viewer.