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.
|
---|
25 | // - callback: callback function to be called upon receiving the results from the server, or local computations.
|
---|
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
|
---|
43 | md.priv.solution=solutionenum;
|
---|
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()){
|
---|
52 | md.priv.isconsistent=true;
|
---|
53 | md.mesh.checkconsistency(md,solutionenum);
|
---|
54 | md.flaim.checkconsistency(md,solutionenum);
|
---|
55 | if (md.priv.isconsistent==false){
|
---|
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','');
|
---|
66 |
|
---|
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 == '')){
|
---|
73 | md.priv.runtimename=restart;
|
---|
74 | }
|
---|
75 | else if (options.getfieldvalue('runtimename',true)){
|
---|
76 | c=new Date().getTime();
|
---|
77 | md.priv.runtimename=sprintf('%s-%g',md.miscellaneous.name,c);
|
---|
78 | }
|
---|
79 | else{
|
---|
80 | md.priv.runtimename=md.miscellaneous.name;
|
---|
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 |
|
---|
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:
|
---|
102 | toolkitsstring= md.toolkits.ToolkitsFile(md.miscellaneous.name + '.toolkits'); // toolkits file
|
---|
103 |
|
---|
104 | //callback function:
|
---|
105 | function callbackfunction(){solving=false;}; //default, do nothing if no callback function requested.
|
---|
106 | if (options.getfieldvalue('callbackfunction',false)){
|
---|
107 | callbackfunction=options.getfieldvalue('callbackfunction');
|
---|
108 | }
|
---|
109 |
|
---|
110 | //callback error function:
|
---|
111 | function callbackerrorfunction(){solving=false;}; //default, do nothing if no callback function requested.
|
---|
112 | if (options.getfieldvalue('callbackerrorfunction',false)){
|
---|
113 | callbackerrorfunction=options.getfieldvalue('callbackerrorfunction');
|
---|
114 | }
|
---|
115 |
|
---|
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 | }
|
---|
121 |
|
---|
122 | if (cluster.classname() == 'local'){ //{{{
|
---|
123 |
|
---|
124 | /*We are running locally on the machine, using the issm module:*/
|
---|
125 | console.log('running issm locally');
|
---|
126 |
|
---|
127 | //Call issm:
|
---|
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:
|
---|
134 | md = loadresultsfrombuffer(md,outputbuffer,outputbuffersize);
|
---|
135 |
|
---|
136 | //Call back?
|
---|
137 | callbackfunction();
|
---|
138 |
|
---|
139 | return md;
|
---|
140 |
|
---|
141 | } //}}}
|
---|
142 | else { //{{{
|
---|
143 |
|
---|
144 | /*We are running somewhere else on a computational server. Send the buffer to that server and retrieve output: */
|
---|
145 | cluster.UploadAndRun(md,callbackfunction,callbackerrorfunction,callbackid,fid,toolkitsstring,solutionstring,md.miscellaneous.name,md.priv.runtimename);
|
---|
146 |
|
---|
147 | return md;
|
---|
148 |
|
---|
149 | } //}}}
|
---|
150 | }
|
---|