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
Line 
1function 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') {
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
38 //recover and process solve options
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!'));
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
75 md.priv.solution=solutionenum;
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 }
83 if (solutionstring === 'FlaimSolution'){
84 md.priv.isconsistent=true;
85 md.mesh.checkconsistency(md,solutionenum);
86 md.flaim.checkconsistency(md,solutionenum);
87 if (md.priv.isconsistent==false){
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','');
98
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 == '')){
105 md.priv.runtimename=restart;
106 }
107 else if (options.getfieldvalue('runtimename',true)){
108 c=new Date().getTime();
109 md.priv.runtimename=sprintf('%s-%g',md.miscellaneous.name,c);
110 }
111 else{
112 md.priv.runtimename=md.miscellaneous.name;
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
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:
134 toolkitsstring= md.toolkits.ToolkitsFile(md.miscellaneous.name + '.toolkits'); // toolkits file
135
136 //callback function:
137 function callbackfunction(){solving=false;}; //default, do nothing if no callback function requested.
138 if (options.getfieldvalue('callbackfunction',false)){
139 callbackfunction=options.getfieldvalue('callbackfunction');
140 }
141
142 //callback error function:
143 function callbackerrorfunction(){solving=false;}; //default, do nothing if no callback function requested.
144 if (options.getfieldvalue('callbackerrorfunction',false)){
145 callbackerrorfunction=options.getfieldvalue('callbackerrorfunction');
146 }
147
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 }
153
154 if (cluster.classname() == 'local'){ //{{{
155
156 /*We are running locally on the machine, using the issm module:*/
157 console.log('running issm locally');
158
159 //Call issm:
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:
166 md = loadresultsfrombuffer(md,outputbuffer,outputbuffersize);
167
168 //Call back?
169 callbackfunction();
170
171 return md;
172
173 } //}}}
174 else { //{{{
175
176 /*We are running somewhere else on a computational server. Send the buffer to that server and retrieve output: */
177 cluster.UploadAndRun(md,callbackfunction,callbackerrorfunction,callbackid,fid,toolkitsstring,solutionstring,md.miscellaneous.name,md.priv.runtimename);
178
179 return md;
180
181 } //}}}
182}
Note: See TracBrowser for help on using the repository browser.