1 | function 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('solutionstring',solutionstring);
|
---|
73 |
|
---|
74 | //recover some fields
|
---|
75 | md.priv.solution=solutionstring;
|
---|
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 | ismodelselfconsistent(md);
|
---|
84 | }
|
---|
85 |
|
---|
86 | //If we are restarting, actually use the provided runtime name:
|
---|
87 | restart=options.getfieldvalue('restart','');
|
---|
88 |
|
---|
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 == '')){
|
---|
95 | md.priv.runtimename=restart;
|
---|
96 | }
|
---|
97 | else if (options.getfieldvalue('runtimename',true)){
|
---|
98 | c=new Date().getTime();
|
---|
99 | md.priv.runtimename=sprintf('%s-%g',md.miscellaneous.name,c);
|
---|
100 | }
|
---|
101 | else{
|
---|
102 | md.priv.runtimename=md.miscellaneous.name;
|
---|
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 |
|
---|
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:
|
---|
124 | toolkitsstring= md.toolkits.ToolkitsFile(md.miscellaneous.name + '.toolkits'); // toolkits file
|
---|
125 |
|
---|
126 | //callback function:
|
---|
127 | function callbackfunction(){solving=false;}; //default, do nothing if no callback function requested.
|
---|
128 | if (options.getfieldvalue('callbackfunction',false)){
|
---|
129 | callbackfunction=options.getfieldvalue('callbackfunction');
|
---|
130 | }
|
---|
131 |
|
---|
132 | //callback error function:
|
---|
133 | function callbackerrorfunction(){solving=false;}; //default, do nothing if no callback function requested.
|
---|
134 | if (options.getfieldvalue('callbackerrorfunction',false)){
|
---|
135 | callbackerrorfunction=options.getfieldvalue('callbackerrorfunction');
|
---|
136 | }
|
---|
137 |
|
---|
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 | }
|
---|
143 |
|
---|
144 | if (cluster.classname() == 'local'){ //{{{
|
---|
145 |
|
---|
146 | /*We are running locally on the machine, using the issm module:*/
|
---|
147 | console.log('running issm locally');
|
---|
148 |
|
---|
149 | //Call issm:
|
---|
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:
|
---|
156 | md = loadresultsfrombuffer(md,outputbuffer,outputbuffersize);
|
---|
157 |
|
---|
158 | //Call back?
|
---|
159 | callbackfunction();
|
---|
160 |
|
---|
161 | return md;
|
---|
162 |
|
---|
163 | } //}}}
|
---|
164 | else { //{{{
|
---|
165 |
|
---|
166 | /*We are running somewhere else on a computational server. Send the buffer to that server and retrieve output: */
|
---|
167 | cluster.UploadAndRun(md,callbackfunction,callbackerrorfunction,callbackid,fid,toolkitsstring,solutionstring,md.miscellaneous.name,md.priv.runtimename);
|
---|
168 |
|
---|
169 | return md;
|
---|
170 |
|
---|
171 | } //}}}
|
---|
172 | }
|
---|