Changeset 22831
- Timestamp:
- 06/06/18 16:00:06 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/solve/solve.js
r22824 r22831 1 function solve(md,solutionstring){ 2 //SOLVE - apply solution sequence for this model 3 // 4 // Usage: 5 // solve(md,solutionstring,varargin) 6 // where varargin is a lit of paired arguments of string OR enums 7 // 8 // solution types available comprise: 9 // - 'Stressbalance' or 'sb' 10 // - 'Masstransport' or 'mt' 11 // - 'Thermal' or 'th' 12 // - 'Steadystate' or 'ss' 13 // - 'Transient' or 'tr' 14 // - 'Balancethickness' or 'mc' 15 // - 'Balancevelocity' or 'bv' 16 // - 'BedSlope' or 'bsl' 17 // - 'SurfaceSlope' or 'ssl' 18 // - 'Hydrology' or 'hy' 19 // - 'DamageEvolution' or 'da' 20 // - 'Gia' or 'gia' 21 // - 'Sealevelrise' or 'slr' 22 // 23 // extra options: 24 // - loadonly : does not solve. only load results 25 // - runtimename : true or false (default is true), makes name unique 26 // - checkconsistency : 'yes' or 'no' (default is 'yes'), ensures checks on consistency of model 27 // - restart: 'directory name (relative to the execution directory) where the restart file is located. 28 // - callback: callback function to be called upon receiving the results from the server, or local computations. 29 // 30 // Examples: 31 // md=solve(md,'Stressbalance'); 32 // md=solve(md,'sb'); 33 34 if(typeof solutionstring !== 'string') { 1 function solve(md, solutionstring) { //{{{ 2 /** 3 * SOLVE - apply solution sequence for this model 4 * 5 * Usage: 6 * solve(md, solutionstring, varargin); 7 * where varargin is a list of paired arguments of string OR enums 8 * 9 * solution types available comprise: 10 * - 'Stressbalance' or 'sb' 11 * - 'Masstransport' or 'mt' 12 * - 'Thermal' or 'th' 13 * - 'Steadystate' or 'ss' 14 * - 'Transient' or 'tr' 15 * - 'Balancethickness' or 'mc' 16 * - 'Balancevelocity' or 'bv' 17 * - 'BedSlope' or 'bsl' 18 * - 'SurfaceSlope' or 'ssl' 19 * - 'Hydrology' or 'hy' 20 * - 'DamageEvolution' or 'da' 21 * - 'Gia' or 'gia' 22 * - 'Sealevelrise' or 'slr' 23 * 24 * extra options: 25 * - loadonly : do not solve, only load results 26 * - runtimename : true or false (default is true), makes name unique 27 * - checkconsistency : 'yes' or 'no' (default is 'yes'), ensures checks on consistency of model 28 * - restart : directory name (relative to the execution directory) where the restart file is located 29 * - successCallback : callback function to be called on success 30 * - errorCallback : callback function to be called on error 31 * 32 * reporting: 33 * With no optional arguments for reporting, progress and error reporting is written to the DOM element with ID 'solve-button'. 34 * - solveButtonId : overrides default solve button ID 35 * - callout : Callout to report progress/errors to; overrides reporting to solve button 36 * - withProgressBar : reports progress of certain solution stages with a progress bar; will not display if a Callout has not been provided 37 * 38 * Examples: 39 * md = solve(md, 'Stressbalance'); 40 * md = solve(md, 'sb'); 41 */ 42 if (typeof solutionstring !== 'string') { 35 43 throw Error(sprintf("%s\n", "ISSM's solve function only accepts strings for solution sequences. Type help solve to get a list of supported solutions.")); 36 44 } 37 45 38 46 //recover and process solve options 39 if ((solutionstring.toLowerCase() === 'sb') || (solutionstring.toLowerCase() === 'stressbalance')){47 if ((solutionstring.toLowerCase() === 'sb') || (solutionstring.toLowerCase() === 'stressbalance')) { 40 48 solutionstring = 'StressbalanceSolution'; 41 } else if((solutionstring.toLowerCase() === 'mt') || (solutionstring.toLowerCase() === 'masstransport')){49 } else if ((solutionstring.toLowerCase() === 'mt') || (solutionstring.toLowerCase() === 'masstransport')) { 42 50 solutionstring = 'MasstransportSolution'; 43 } else if((solutionstring.toLowerCase() === 'th') || (solutionstring.toLowerCase() === 'thermal')){51 } else if ((solutionstring.toLowerCase() === 'th') || (solutionstring.toLowerCase() === 'thermal')) { 44 52 solutionstring = 'ThermalSolution'; 45 } else if((solutionstring.toLowerCase() === 'st') || (solutionstring.toLowerCase() === 'steadystate')){53 } else if ((solutionstring.toLowerCase() === 'st') || (solutionstring.toLowerCase() === 'steadystate')) { 46 54 solutionstring = 'SteadystateSolution'; 47 } else if((solutionstring.toLowerCase() === 'tr') || (solutionstring.toLowerCase() === 'transient')){55 } else if ((solutionstring.toLowerCase() === 'tr') || (solutionstring.toLowerCase() === 'transient')) { 48 56 solutionstring = 'TransientSolution'; 49 } else if((solutionstring.toLowerCase() === 'mc') || (solutionstring.toLowerCase() === 'balancethickness')){57 } else if ((solutionstring.toLowerCase() === 'mc') || (solutionstring.toLowerCase() === 'balancethickness')) { 50 58 solutionstring = 'BalancethicknessSolution'; 51 } else if((solutionstring.toLowerCase() === 'bv') || (solutionstring.toLowerCase() === 'balancevelocity')){59 } else if ((solutionstring.toLowerCase() === 'bv') || (solutionstring.toLowerCase() === 'balancevelocity')) { 52 60 solutionstring = 'BalancevelocitySolution'; 53 } else if((solutionstring.toLowerCase() === 'bsl') || (solutionstring.toLowerCase() === 'bedslope')){61 } else if ((solutionstring.toLowerCase() === 'bsl') || (solutionstring.toLowerCase() === 'bedslope')) { 54 62 solutionstring = 'BedSlopeSolution'; 55 } else if((solutionstring.toLowerCase() === 'ssl') || (solutionstring.toLowerCase() === 'surfaceslope')){63 } else if ((solutionstring.toLowerCase() === 'ssl') || (solutionstring.toLowerCase() === 'surfaceslope')) { 56 64 solutionstring = 'SurfaceSlopeSolution'; 57 } else if((solutionstring.toLowerCase() === 'hy') || (solutionstring.toLowerCase() === 'hydrology')){65 } else if ((solutionstring.toLowerCase() === 'hy') || (solutionstring.toLowerCase() === 'hydrology')) { 58 66 solutionstring = 'HydrologySolution'; 59 } else if((solutionstring.toLowerCase() === 'da') || (solutionstring.toLowerCase() === 'damageevolution')){67 } else if ((solutionstring.toLowerCase() === 'da') || (solutionstring.toLowerCase() === 'damageevolution')) { 60 68 solutionstring = 'DamageEvolutionSolution'; 61 } else if((solutionstring.toLowerCase() === 'gia') || (solutionstring.toLowerCase() === 'gia')){69 } else if ((solutionstring.toLowerCase() === 'gia') || (solutionstring.toLowerCase() === 'gia')) { 62 70 solutionstring = 'GiaSolution'; 63 } else if((solutionstring.toLowerCase() === 'slr') || (solutionstring.toLowerCase() === 'sealevelrise')){71 } else if ((solutionstring.toLowerCase() === 'slr') || (solutionstring.toLowerCase() === 'sealevelrise')) { 64 72 solutionstring = 'SealevelriseSolution'; 65 } else{73 } else { 66 74 throw Error(sprintf("%s%s%s\n",'solutionstring ',solutionstring,' not supported!')); 67 75 } … … 131 139 132 140 // Default: do nothing if no success callback function requested 133 function successCallback () {141 function successCallbackDefault() { 134 142 solving = false; 135 143 }; 136 144 137 if (options.getfieldvalue('successCallback',false)){ 138 successCallback = options.getfieldvalue('successCallback'); 139 } 145 let successCallback = options.getfieldvalue('successCallback', successCallbackDefault); 140 146 //}}} 141 147 … … 147 153 148 154 // Default: do nothing if no error callback function requested 149 function errorCallback () {155 function errorCallbackDefault() { 150 156 solving = false; 151 157 }; 152 158 153 if (options.getfieldvalue('errorCallback',false)){ 154 errorCallback = options.getfieldvalue('errorCallback'); 155 } 159 let errorCallback = options.getfieldvalue('errorCallback', errorCallbackDefault); 156 160 //}}} 157 161 … … 163 167 164 168 // Default: update #solve-button element with progress updates 165 var solveButtonId = '#solve-button'; 166 167 if (options.getfieldvalue('solveButtonId', false)){ 168 solveButtonId = options.getfieldvalue('solveButtonId'); 169 } 170 //}}} 171 172 if (cluster.classname() == 'local'){ //{{{ 169 let solveButtonId = options.getfieldvalue('solveButtonId', '#solve-button'); 170 //}}} 171 172 173 /* 174 Set Callout 175 */ 176 //{{{ 177 var callout = {}; 178 179 // Default: Callout is an empty object 180 callout = options.getfieldvalue('callout', {}); 181 //}}} 182 183 184 /* 185 Set progress bar display boolean 186 */ 187 //{{{ 188 // Default: no progress bar; NOTE: must have supplied a callout for progress bar to display 189 let withProgressBar = options.getfieldvalue('withProgressBar', false); 190 //}}} 191 192 193 if (cluster.classname() == 'local'){ //{{{ 173 194 174 195 /*We are running locally on the machine, using the issm module:*/ … … 182 203 183 204 //Load results: 184 md = loadresultsfrombuffer(md, outputbuffer,outputbuffersize);205 md = loadresultsfrombuffer(md, outputbuffer, outputbuffersize); 185 206 186 207 // Call success callback … … 188 209 189 210 return md; 190 191 } //}}} 192 else { //{{{ 193 194 /*We are running somewhere else on a computational server. Send the buffer to that server and retrieve output: */ 211 //}}} 212 } else { //{{{ 213 // We are running somewhere else on a computational server. Send the buffer to that server and retrieve output. 195 214 console.log('running issm remotely'); 196 cluster.UploadAndRun(md,successCallback,errorCallback,solveButtonId,fid,toolkitsstring,solutionstring,md.miscellaneous.name,md.priv.runtimename); 215 216 cluster.UploadAndRun( 217 md, 218 fid, 219 toolkitsstring, 220 solutionstring, 221 md.miscellaneous.name, 222 md.priv.runtimename, 223 successCallback, 224 errorCallback, 225 solveButtonId, 226 callout, 227 withProgressBar 228 ); 197 229 198 230 return md; 199 200 } //}}} 231 //}}} 232 } 233 //}}} 201 234 }
Note:
See TracChangeset
for help on using the changeset viewer.