[21065] | 1 | function solve(md,solutionstring){
|
---|
[19780] | 2 | //SOLVE - apply solution sequence for this model
|
---|
| 3 | //
|
---|
| 4 | // Usage:
|
---|
[21065] | 5 | // solve(md,solutionstring,varargin)
|
---|
[19780] | 6 | // where varargin is a lit of paired arguments of string OR enums
|
---|
| 7 | //
|
---|
| 8 | // solution types available comprise:
|
---|
[21065] | 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'
|
---|
[19780] | 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.
|
---|
[20270] | 28 | // - callback: callback function to be called upon receiving the results from the server, or local computations.
|
---|
[19780] | 29 | //
|
---|
| 30 | // Examples:
|
---|
[21065] | 31 | // md=solve(md,'Stressbalance');
|
---|
| 32 | // md=solve(md,'sb');
|
---|
[19780] | 33 |
|
---|
[21065] | 34 | if(typeof solutionstring !== 'string') {
|
---|
[21139] | 35 | 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] | 36 | }
|
---|
| 37 |
|
---|
[19780] | 38 | //recover and process solve options
|
---|
[21065] | 39 | if((solutionstring.toUpperCase() === 'sb') || (solutionstring.toUpperCase() === 'stressbalance')){
|
---|
| 40 | solutionstring = 'StressbalanceSolution';
|
---|
| 41 | }else if((solutionstring.toUpperCase() === 'mt') || (solutionstring.toUpperCase() === 'masstransport')){
|
---|
| 42 | solutionstring = 'MasstransportSolution';
|
---|
| 43 | }else if((solutionstring.toUpperCase() === 'th') || (solutionstring.toUpperCase() === 'thermal')){
|
---|
| 44 | solutionstring = 'ThermalSolution';
|
---|
| 45 | }else if((solutionstring.toUpperCase() === 'st') || (solutionstring.toUpperCase() === 'steadystate')){
|
---|
| 46 | solutionstring = 'SteadystateSolution';
|
---|
| 47 | }else if((solutionstring.toUpperCase() === 'tr') || (solutionstring.toUpperCase() === 'transient')){
|
---|
| 48 | solutionstring = 'TransientSolution';
|
---|
| 49 | }else if((solutionstring.toUpperCase() === 'mc') || (solutionstring.toUpperCase() === 'balancethickness')){
|
---|
| 50 | solutionstring = 'BalancethicknessSolution';
|
---|
| 51 | }else if((solutionstring.toUpperCase() === 'bv') || (solutionstring.toUpperCase() === 'balancevelocity')){
|
---|
| 52 | solutionstring = 'BalancevelocitySolution';
|
---|
| 53 | }else if((solutionstring.toUpperCase() === 'bsl') || (solutionstring.toUpperCase() === 'bedslope')){
|
---|
| 54 | solutionstring = 'BedSlopeSolution';
|
---|
| 55 | }else if((solutionstring.toUpperCase() === 'ssl') || (solutionstring.toUpperCase() === 'surfaceslope')){
|
---|
| 56 | solutionstring = 'SurfaceSlopeSolution';
|
---|
| 57 | }else if((solutionstring.toUpperCase() === 'hy') || (solutionstring.toUpperCase() === 'hydrology')){
|
---|
| 58 | solutionstring = 'HydrologySolution';
|
---|
| 59 | }else if((solutionstring.toUpperCase() === 'da') || (solutionstring.toUpperCase() === 'damageevolution')){
|
---|
| 60 | solutionstring = 'DamageEvolutionSolution';
|
---|
| 61 | }else if((solutionstring.toUpperCase() === 'gia') || (solutionstring.toUpperCase() === 'gia')){
|
---|
| 62 | solutionstring = 'GiaSolution';
|
---|
| 63 | }else if((solutionstring.toUpperCase() === 'slr') || (solutionstring.toUpperCase() === 'sealevelrise')){
|
---|
| 64 | solutionstring = 'SealevelriseSolution';
|
---|
| 65 | }else{
|
---|
| 66 | throw Error(sprintf("%s%s%s\n",'solutionstring ',solutionstring,' not supported!'));
|
---|
[19780] | 67 | }
|
---|
| 68 |
|
---|
| 69 | //Process options
|
---|
| 70 | var args = Array.prototype.slice.call(arguments);
|
---|
| 71 | var options = new pairoptions(args.slice(2,args.length));
|
---|
[21069] | 72 | options.addfield('solutionstring',solutionstring);
|
---|
[19780] | 73 |
|
---|
| 74 | //recover some fields
|
---|
[21069] | 75 | md.priv.solution=solutionstring;
|
---|
[19780] | 76 | cluster=md.cluster;
|
---|
| 77 |
|
---|
| 78 | //check model consistency
|
---|
| 79 | if (options.getfieldvalue('checkconsistency','yes') == 'yes'){
|
---|
| 80 | if (md.verbose.solution){
|
---|
| 81 | console.log('checking model consistency');
|
---|
| 82 | }
|
---|
[21097] | 83 | ismodelselfconsistent(md);
|
---|
[19780] | 84 | }
|
---|
| 85 |
|
---|
| 86 | //If we are restarting, actually use the provided runtime name:
|
---|
| 87 | restart=options.getfieldvalue('restart','');
|
---|
[20269] | 88 |
|
---|
[19780] | 89 | //First, build a runtime name that is unique
|
---|
| 90 | if (restart==1 ){
|
---|
| 91 | //Leave the runtimename as is
|
---|
| 92 | }
|
---|
| 93 | else{
|
---|
| 94 | if (!(restart == '')){
|
---|
[19824] | 95 | md.priv.runtimename=restart;
|
---|
[19780] | 96 | }
|
---|
| 97 | else if (options.getfieldvalue('runtimename',true)){
|
---|
| 98 | c=new Date().getTime();
|
---|
[19824] | 99 | md.priv.runtimename=sprintf('%s-%g',md.miscellaneous.name,c);
|
---|
[19780] | 100 | }
|
---|
| 101 | else{
|
---|
[19824] | 102 | md.priv.runtimename=md.miscellaneous.name;
|
---|
[19780] | 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | //if running qmu analysis, some preprocessing of dakota files using models
|
---|
| 107 | //fields needs to be carried out.
|
---|
| 108 | if (md.qmu.isdakota){
|
---|
| 109 | throw Error("solve error message: qmu runs not supported yet!");
|
---|
| 110 | //md.preqmu(options);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | //Do we load results only?
|
---|
| 115 | if (options.getfieldvalue('loadonly',false)){
|
---|
| 116 | loadresultsfromcluster(md);
|
---|
| 117 | return;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[20269] | 120 | //Marshall into a binary array (fid) all the fields of model.
|
---|
| 121 | var fid = marshall(md); // bin file
|
---|
| 122 |
|
---|
| 123 | //deal with toolkits options:
|
---|
[19793] | 124 | toolkitsstring= md.toolkits.ToolkitsFile(md.miscellaneous.name + '.toolkits'); // toolkits file
|
---|
[19780] | 125 |
|
---|
[20270] | 126 | //callback function:
|
---|
[21028] | 127 | function callbackfunction(){solving=false;}; //default, do nothing if no callback function requested.
|
---|
[20823] | 128 | if (options.getfieldvalue('callbackfunction',false)){
|
---|
| 129 | callbackfunction=options.getfieldvalue('callbackfunction');
|
---|
[20270] | 130 | }
|
---|
[20823] | 131 |
|
---|
[20995] | 132 | //callback error function:
|
---|
[21028] | 133 | function callbackerrorfunction(){solving=false;}; //default, do nothing if no callback function requested.
|
---|
[20995] | 134 | if (options.getfieldvalue('callbackerrorfunction',false)){
|
---|
| 135 | callbackerrorfunction=options.getfieldvalue('callbackerrorfunction');
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[20823] | 138 | //callback id:
|
---|
| 139 | var callbackid = '.run-button'; //default, update .run-button elements with progress updates.
|
---|
| 140 | if (options.getfieldvalue('callbackid',false)){
|
---|
| 141 | callbackid=options.getfieldvalue('callbackid');
|
---|
| 142 | }
|
---|
[19793] | 143 |
|
---|
[20269] | 144 | if (cluster.classname() == 'local'){ //{{{
|
---|
[19793] | 145 |
|
---|
| 146 | /*We are running locally on the machine, using the issm module:*/
|
---|
| 147 | console.log('running issm locally');
|
---|
| 148 |
|
---|
| 149 | //Call issm:
|
---|
[19816] | 150 | var outputs = issm(fid, toolkitsstring, solutionstring, md.miscellaneous.name);
|
---|
| 151 |
|
---|
| 152 | //Recover output arguments:
|
---|
| 153 | var outputbuffer = outputs[0]; var outputbuffersize = outputs[1];
|
---|
| 154 |
|
---|
| 155 | //Load results:
|
---|
[20299] | 156 | md = loadresultsfrombuffer(md,outputbuffer,outputbuffersize);
|
---|
[20269] | 157 |
|
---|
[20270] | 158 | //Call back?
|
---|
| 159 | callbackfunction();
|
---|
| 160 |
|
---|
[20269] | 161 | return md;
|
---|
[19816] | 162 |
|
---|
[20269] | 163 | } //}}}
|
---|
| 164 | else { //{{{
|
---|
[19831] | 165 |
|
---|
[20269] | 166 | /*We are running somewhere else on a computational server. Send the buffer to that server and retrieve output: */
|
---|
[20995] | 167 | cluster.UploadAndRun(md,callbackfunction,callbackerrorfunction,callbackid,fid,toolkitsstring,solutionstring,md.miscellaneous.name,md.priv.runtimename);
|
---|
[20269] | 168 |
|
---|
| 169 | return md;
|
---|
| 170 |
|
---|
| 171 | } //}}}
|
---|
[19780] | 172 | }
|
---|