source: issm/trunk-jpl/src/m/solve/solve.js@ 22831

Last change on this file since 22831 was 22831, checked in by jdquinn, 7 years ago

CHG: Modified JS version of solve() to allow for progress bar.

File size: 7.4 KB
RevLine 
[22831]1function 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') {
[21139]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."));
[21065]44 }
45
[19780]46 //recover and process solve options
[22831]47 if ((solutionstring.toLowerCase() === 'sb') || (solutionstring.toLowerCase() === 'stressbalance')) {
[21065]48 solutionstring = 'StressbalanceSolution';
[22831]49 } else if ((solutionstring.toLowerCase() === 'mt') || (solutionstring.toLowerCase() === 'masstransport')) {
[21065]50 solutionstring = 'MasstransportSolution';
[22831]51 } else if ((solutionstring.toLowerCase() === 'th') || (solutionstring.toLowerCase() === 'thermal')) {
[21065]52 solutionstring = 'ThermalSolution';
[22831]53 } else if ((solutionstring.toLowerCase() === 'st') || (solutionstring.toLowerCase() === 'steadystate')) {
[21065]54 solutionstring = 'SteadystateSolution';
[22831]55 } else if ((solutionstring.toLowerCase() === 'tr') || (solutionstring.toLowerCase() === 'transient')) {
[21065]56 solutionstring = 'TransientSolution';
[22831]57 } else if ((solutionstring.toLowerCase() === 'mc') || (solutionstring.toLowerCase() === 'balancethickness')) {
[21065]58 solutionstring = 'BalancethicknessSolution';
[22831]59 } else if ((solutionstring.toLowerCase() === 'bv') || (solutionstring.toLowerCase() === 'balancevelocity')) {
[21065]60 solutionstring = 'BalancevelocitySolution';
[22831]61 } else if ((solutionstring.toLowerCase() === 'bsl') || (solutionstring.toLowerCase() === 'bedslope')) {
[21065]62 solutionstring = 'BedSlopeSolution';
[22831]63 } else if ((solutionstring.toLowerCase() === 'ssl') || (solutionstring.toLowerCase() === 'surfaceslope')) {
[21065]64 solutionstring = 'SurfaceSlopeSolution';
[22831]65 } else if ((solutionstring.toLowerCase() === 'hy') || (solutionstring.toLowerCase() === 'hydrology')) {
[21065]66 solutionstring = 'HydrologySolution';
[22831]67 } else if ((solutionstring.toLowerCase() === 'da') || (solutionstring.toLowerCase() === 'damageevolution')) {
[21065]68 solutionstring = 'DamageEvolutionSolution';
[22831]69 } else if ((solutionstring.toLowerCase() === 'gia') || (solutionstring.toLowerCase() === 'gia')) {
[21584]70 solutionstring = 'GiaSolution';
[22831]71 } else if ((solutionstring.toLowerCase() === 'slr') || (solutionstring.toLowerCase() === 'sealevelrise')) {
[21065]72 solutionstring = 'SealevelriseSolution';
[22831]73 } else {
[21065]74 throw Error(sprintf("%s%s%s\n",'solutionstring ',solutionstring,' not supported!'));
[19780]75 }
76
77 //Process options
78 var args = Array.prototype.slice.call(arguments);
79 var options = new pairoptions(args.slice(2,args.length));
[21069]80 options.addfield('solutionstring',solutionstring);
[19780]81
82 //recover some fields
[21069]83 md.priv.solution=solutionstring;
[19780]84 cluster=md.cluster;
85
86 //check model consistency
87 if (options.getfieldvalue('checkconsistency','yes') == 'yes'){
88 if (md.verbose.solution){
89 console.log('checking model consistency');
90 }
[21097]91 ismodelselfconsistent(md);
[19780]92 }
93
94 //If we are restarting, actually use the provided runtime name:
95 restart=options.getfieldvalue('restart','');
[20269]96
[19780]97 //First, build a runtime name that is unique
98 if (restart==1 ){
99 //Leave the runtimename as is
100 }
101 else{
102 if (!(restart == '')){
[19824]103 md.priv.runtimename=restart;
[19780]104 }
105 else if (options.getfieldvalue('runtimename',true)){
106 c=new Date().getTime();
[19824]107 md.priv.runtimename=sprintf('%s-%g',md.miscellaneous.name,c);
[19780]108 }
109 else{
[19824]110 md.priv.runtimename=md.miscellaneous.name;
[19780]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){
117 throw Error("solve error message: qmu runs not supported yet!");
118 //md.preqmu(options);
119 }
120
121
122 //Do we load results only?
123 if (options.getfieldvalue('loadonly',false)){
124 loadresultsfromcluster(md);
125 return;
126 }
127
[20269]128 //Marshall into a binary array (fid) all the fields of model.
129 var fid = marshall(md); // bin file
130
131 //deal with toolkits options:
[19793]132 toolkitsstring= md.toolkits.ToolkitsFile(md.miscellaneous.name + '.toolkits'); // toolkits file
[19780]133
[22824]134
135 /*
136 Set success callback function
137 */
138 //{{{
139
140 // Default: do nothing if no success callback function requested
[22831]141 function successCallbackDefault() {
[22824]142 solving = false;
143 };
144
[22831]145 let successCallback = options.getfieldvalue('successCallback', successCallbackDefault);
[22824]146 //}}}
[20823]147
[22824]148
149 /*
150 Set error callback function
151 */
152 //{{{
153
154 // Default: do nothing if no error callback function requested
[22831]155 function errorCallbackDefault() {
[22824]156 solving = false;
157 };
158
[22831]159 let errorCallback = options.getfieldvalue('errorCallback', errorCallbackDefault);
[22824]160 //}}}
[20995]161
[22824]162
163 /*
164 Set solve button ID
165 */
166 //{{{
167
168 // Default: update #solve-button element with progress updates
[22831]169 let solveButtonId = options.getfieldvalue('solveButtonId', '#solve-button');
170 //}}}
[22824]171
[22831]172
173 /*
174 Set Callout
175 */
176 //{{{
177 var callout = {};
178
179 // Default: Callout is an empty object
180 callout = options.getfieldvalue('callout', {});
[22824]181 //}}}
[22831]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 //}}}
[19793]191
192
[22831]193 if (cluster.classname() == 'local'){ //{{{
194
[19793]195 /*We are running locally on the machine, using the issm module:*/
196 console.log('running issm locally');
197
198 //Call issm:
[19816]199 var outputs = issm(fid, toolkitsstring, solutionstring, md.miscellaneous.name);
200
201 //Recover output arguments:
202 var outputbuffer = outputs[0]; var outputbuffersize = outputs[1];
203
204 //Load results:
[22831]205 md = loadresultsfrombuffer(md, outputbuffer, outputbuffersize);
[20269]206
[22824]207 // Call success callback
208 successCallback();
[20270]209
[20269]210 return md;
[22831]211 //}}}
212 } else { //{{{
213 // We are running somewhere else on a computational server. Send the buffer to that server and retrieve output.
[22716]214 console.log('running issm remotely');
[22831]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 );
[20269]229
230 return md;
[22831]231 //}}}
232 }
233//}}}
[19780]234}
Note: See TracBrowser for help on using the repository browser.