[19780] | 1 | function solve(md,solutionenum){
|
---|
| 2 | //SOLVE - apply solution sequence for this model
|
---|
| 3 | //
|
---|
| 4 | // Usage:
|
---|
| 5 | // solve(md,solutionenum,varargin)
|
---|
| 6 | // where varargin is a lit of paired arguments of string OR enums
|
---|
| 7 | //
|
---|
| 8 | // solution types available comprise:
|
---|
| 9 | // - StressbalanceSolutionEnum
|
---|
| 10 | // - MasstransportSolutionEnum
|
---|
| 11 | // - ThermalSolutionEnum
|
---|
| 12 | // - SteadystateSolutionEnum
|
---|
| 13 | // - TransientSolutionEnum
|
---|
| 14 | // - BalancethicknessSolutionEnum
|
---|
| 15 | // - BedSlopeSolutionEnum
|
---|
| 16 | // - SurfaceSlopeSolutionEnum
|
---|
| 17 | // - HydrologySolutionEnum
|
---|
| 18 | // - FlaimSolutionEnum
|
---|
| 19 | //
|
---|
| 20 | // extra options:
|
---|
| 21 | // - loadonly : does not solve. only load results
|
---|
| 22 | // - runtimename : true or false (default is true), makes name unique
|
---|
| 23 | // - checkconsistency : 'yes' or 'no' (default is 'yes'), ensures checks on consistency of model
|
---|
| 24 | // - restart: 'directory name (relative to the execution directory) where the restart file is located.
|
---|
[20270] | 25 | // - callback: callback function to be called upon receiving the results from the server, or local computations.
|
---|
[19780] | 26 | //
|
---|
| 27 | // Examples:
|
---|
| 28 | // md=solve(md,StressbalanceSolutionEnum);
|
---|
| 29 |
|
---|
| 30 | solutionstring=EnumToString(solutionenum);
|
---|
| 31 |
|
---|
| 32 | //recover and process solve options
|
---|
| 33 | if (solutionstring.slice(-8) !== 'Solution'){
|
---|
| 34 | throw Error(sprintf("%s%s%s\n",'solutionenum ',solutionstring,' not supported!'));
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | //Process options
|
---|
| 38 | var args = Array.prototype.slice.call(arguments);
|
---|
| 39 | var options = new pairoptions(args.slice(2,args.length));
|
---|
| 40 | options.addfield('solutionenum',solutionenum);
|
---|
| 41 |
|
---|
| 42 | //recover some fields
|
---|
[19824] | 43 | md.priv.solution=solutionenum;
|
---|
[19780] | 44 | cluster=md.cluster;
|
---|
| 45 |
|
---|
| 46 | //check model consistency
|
---|
| 47 | if (options.getfieldvalue('checkconsistency','yes') == 'yes'){
|
---|
| 48 | if (md.verbose.solution){
|
---|
| 49 | console.log('checking model consistency');
|
---|
| 50 | }
|
---|
| 51 | if (solutionenum == FlaimSolutionEnum()){
|
---|
[19824] | 52 | md.priv.isconsistent=true;
|
---|
[19780] | 53 | md.mesh.checkconsistency(md,solutionenum);
|
---|
| 54 | md.flaim.checkconsistency(md,solutionenum);
|
---|
[19824] | 55 | if (md.priv.isconsistent==false){
|
---|
[19780] | 56 | throw error('solve error message: model not consistent, see messages above');
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | else{
|
---|
| 60 | ismodelselfconsistent(md);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | //If we are restarting, actually use the provided runtime name:
|
---|
| 65 | restart=options.getfieldvalue('restart','');
|
---|
[20269] | 66 |
|
---|
[19780] | 67 | //First, build a runtime name that is unique
|
---|
| 68 | if (restart==1 ){
|
---|
| 69 | //Leave the runtimename as is
|
---|
| 70 | }
|
---|
| 71 | else{
|
---|
| 72 | if (!(restart == '')){
|
---|
[19824] | 73 | md.priv.runtimename=restart;
|
---|
[19780] | 74 | }
|
---|
| 75 | else if (options.getfieldvalue('runtimename',true)){
|
---|
| 76 | c=new Date().getTime();
|
---|
[19824] | 77 | md.priv.runtimename=sprintf('%s-%g',md.miscellaneous.name,c);
|
---|
[19780] | 78 | }
|
---|
| 79 | else{
|
---|
[19824] | 80 | md.priv.runtimename=md.miscellaneous.name;
|
---|
[19780] | 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | //if running qmu analysis, some preprocessing of dakota files using models
|
---|
| 85 | //fields needs to be carried out.
|
---|
| 86 | if (md.qmu.isdakota){
|
---|
| 87 | throw Error("solve error message: qmu runs not supported yet!");
|
---|
| 88 | //md.preqmu(options);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | //Do we load results only?
|
---|
| 93 | if (options.getfieldvalue('loadonly',false)){
|
---|
| 94 | loadresultsfromcluster(md);
|
---|
| 95 | return;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[20269] | 98 | //Marshall into a binary array (fid) all the fields of model.
|
---|
| 99 | var fid = marshall(md); // bin file
|
---|
| 100 |
|
---|
| 101 | //deal with toolkits options:
|
---|
[19793] | 102 | toolkitsstring= md.toolkits.ToolkitsFile(md.miscellaneous.name + '.toolkits'); // toolkits file
|
---|
[19780] | 103 |
|
---|
[20270] | 104 | //callback function:
|
---|
[21028] | 105 | function callbackfunction(){solving=false;}; //default, do nothing if no callback function requested.
|
---|
[20823] | 106 | if (options.getfieldvalue('callbackfunction',false)){
|
---|
| 107 | callbackfunction=options.getfieldvalue('callbackfunction');
|
---|
[20270] | 108 | }
|
---|
[20823] | 109 |
|
---|
[20995] | 110 | //callback error function:
|
---|
[21028] | 111 | function callbackerrorfunction(){solving=false;}; //default, do nothing if no callback function requested.
|
---|
[20995] | 112 | if (options.getfieldvalue('callbackerrorfunction',false)){
|
---|
| 113 | callbackerrorfunction=options.getfieldvalue('callbackerrorfunction');
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[20823] | 116 | //callback id:
|
---|
| 117 | var callbackid = '.run-button'; //default, update .run-button elements with progress updates.
|
---|
| 118 | if (options.getfieldvalue('callbackid',false)){
|
---|
| 119 | callbackid=options.getfieldvalue('callbackid');
|
---|
| 120 | }
|
---|
[19793] | 121 |
|
---|
[20269] | 122 | if (cluster.classname() == 'local'){ //{{{
|
---|
[19793] | 123 |
|
---|
| 124 | /*We are running locally on the machine, using the issm module:*/
|
---|
| 125 | console.log('running issm locally');
|
---|
| 126 |
|
---|
| 127 | //Call issm:
|
---|
[19816] | 128 | var outputs = issm(fid, toolkitsstring, solutionstring, md.miscellaneous.name);
|
---|
| 129 |
|
---|
| 130 | //Recover output arguments:
|
---|
| 131 | var outputbuffer = outputs[0]; var outputbuffersize = outputs[1];
|
---|
| 132 |
|
---|
| 133 | //Load results:
|
---|
[20299] | 134 | md = loadresultsfrombuffer(md,outputbuffer,outputbuffersize);
|
---|
[20269] | 135 |
|
---|
[20270] | 136 | //Call back?
|
---|
| 137 | callbackfunction();
|
---|
| 138 |
|
---|
[20269] | 139 | return md;
|
---|
[19816] | 140 |
|
---|
[20269] | 141 | } //}}}
|
---|
| 142 | else { //{{{
|
---|
[19831] | 143 |
|
---|
[20269] | 144 | /*We are running somewhere else on a computational server. Send the buffer to that server and retrieve output: */
|
---|
[20995] | 145 | cluster.UploadAndRun(md,callbackfunction,callbackerrorfunction,callbackid,fid,toolkitsstring,solutionstring,md.miscellaneous.name,md.priv.runtimename);
|
---|
[20269] | 146 |
|
---|
| 147 | return md;
|
---|
| 148 |
|
---|
| 149 | } //}}}
|
---|
[19780] | 150 | }
|
---|