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

Last change on this file since 21065 was 21065, checked in by agscott1, 9 years ago

CHG: Replaced all javascript enums with solution strings and analyses strings to match matlab and python code

File size: 6.8 KB
RevLine 
[21065]1function 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') {
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.");
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));
72 options.addfield('solutionenum',solutionenum);
73
74 //recover some fields
[19824]75 md.priv.solution=solutionenum;
[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 }
[21065]83 if (solutionstring === 'FlaimSolution'){
[19824]84 md.priv.isconsistent=true;
[19780]85 md.mesh.checkconsistency(md,solutionenum);
86 md.flaim.checkconsistency(md,solutionenum);
[19824]87 if (md.priv.isconsistent==false){
[19780]88 throw error('solve error message: model not consistent, see messages above');
89 }
90 }
91 else{
92 ismodelselfconsistent(md);
93 }
94 }
95
96 //If we are restarting, actually use the provided runtime name:
97 restart=options.getfieldvalue('restart','');
[20269]98
[19780]99 //First, build a runtime name that is unique
100 if (restart==1 ){
101 //Leave the runtimename as is
102 }
103 else{
104 if (!(restart == '')){
[19824]105 md.priv.runtimename=restart;
[19780]106 }
107 else if (options.getfieldvalue('runtimename',true)){
108 c=new Date().getTime();
[19824]109 md.priv.runtimename=sprintf('%s-%g',md.miscellaneous.name,c);
[19780]110 }
111 else{
[19824]112 md.priv.runtimename=md.miscellaneous.name;
[19780]113 }
114 }
115
116 //if running qmu analysis, some preprocessing of dakota files using models
117 //fields needs to be carried out.
118 if (md.qmu.isdakota){
119 throw Error("solve error message: qmu runs not supported yet!");
120 //md.preqmu(options);
121 }
122
123
124 //Do we load results only?
125 if (options.getfieldvalue('loadonly',false)){
126 loadresultsfromcluster(md);
127 return;
128 }
129
[20269]130 //Marshall into a binary array (fid) all the fields of model.
131 var fid = marshall(md); // bin file
132
133 //deal with toolkits options:
[19793]134 toolkitsstring= md.toolkits.ToolkitsFile(md.miscellaneous.name + '.toolkits'); // toolkits file
[19780]135
[20270]136 //callback function:
[21028]137 function callbackfunction(){solving=false;}; //default, do nothing if no callback function requested.
[20823]138 if (options.getfieldvalue('callbackfunction',false)){
139 callbackfunction=options.getfieldvalue('callbackfunction');
[20270]140 }
[20823]141
[20995]142 //callback error function:
[21028]143 function callbackerrorfunction(){solving=false;}; //default, do nothing if no callback function requested.
[20995]144 if (options.getfieldvalue('callbackerrorfunction',false)){
145 callbackerrorfunction=options.getfieldvalue('callbackerrorfunction');
146 }
147
[20823]148 //callback id:
149 var callbackid = '.run-button'; //default, update .run-button elements with progress updates.
150 if (options.getfieldvalue('callbackid',false)){
151 callbackid=options.getfieldvalue('callbackid');
152 }
[19793]153
[20269]154 if (cluster.classname() == 'local'){ //{{{
[19793]155
156 /*We are running locally on the machine, using the issm module:*/
157 console.log('running issm locally');
158
159 //Call issm:
[19816]160 var outputs = issm(fid, toolkitsstring, solutionstring, md.miscellaneous.name);
161
162 //Recover output arguments:
163 var outputbuffer = outputs[0]; var outputbuffersize = outputs[1];
164
165 //Load results:
[20299]166 md = loadresultsfrombuffer(md,outputbuffer,outputbuffersize);
[20269]167
[20270]168 //Call back?
169 callbackfunction();
170
[20269]171 return md;
[19816]172
[20269]173 } //}}}
174 else { //{{{
[19831]175
[20269]176 /*We are running somewhere else on a computational server. Send the buffer to that server and retrieve output: */
[20995]177 cluster.UploadAndRun(md,callbackfunction,callbackerrorfunction,callbackid,fid,toolkitsstring,solutionstring,md.miscellaneous.name,md.priv.runtimename);
[20269]178
179 return md;
180
181 } //}}}
[19780]182}
Note: See TracBrowser for help on using the repository browser.