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 | //
|
---|
26 | // Examples:
|
---|
27 | // md=solve(md,StressbalanceSolutionEnum);
|
---|
28 |
|
---|
29 | solutionstring=EnumToString(solutionenum);
|
---|
30 |
|
---|
31 | //recover and process solve options
|
---|
32 | if (solutionstring.slice(-8) !== 'Solution'){
|
---|
33 | throw Error(sprintf("%s%s%s\n",'solutionenum ',solutionstring,' not supported!'));
|
---|
34 | }
|
---|
35 |
|
---|
36 | //Process options
|
---|
37 | var args = Array.prototype.slice.call(arguments);
|
---|
38 | var options = new pairoptions(args.slice(2,args.length));
|
---|
39 | options.addfield('solutionenum',solutionenum);
|
---|
40 |
|
---|
41 | //recover some fields
|
---|
42 | md.private.solution=solutionenum;
|
---|
43 | cluster=md.cluster;
|
---|
44 |
|
---|
45 | //check model consistency
|
---|
46 | if (options.getfieldvalue('checkconsistency','yes') == 'yes'){
|
---|
47 | if (md.verbose.solution){
|
---|
48 | console.log('checking model consistency');
|
---|
49 | }
|
---|
50 | if (solutionenum == FlaimSolutionEnum()){
|
---|
51 | md.private.isconsistent=true;
|
---|
52 | md.mesh.checkconsistency(md,solutionenum);
|
---|
53 | md.flaim.checkconsistency(md,solutionenum);
|
---|
54 | if (md.private.isconsistent==false){
|
---|
55 | throw error('solve error message: model not consistent, see messages above');
|
---|
56 | }
|
---|
57 | }
|
---|
58 | else{
|
---|
59 | ismodelselfconsistent(md);
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | //If we are restarting, actually use the provided runtime name:
|
---|
64 | restart=options.getfieldvalue('restart','');
|
---|
65 | //First, build a runtime name that is unique
|
---|
66 | if (restart==1 ){
|
---|
67 | //Leave the runtimename as is
|
---|
68 | }
|
---|
69 | else{
|
---|
70 | if (!(restart == '')){
|
---|
71 | md.private.runtimename=restart;
|
---|
72 | }
|
---|
73 | else if (options.getfieldvalue('runtimename',true)){
|
---|
74 | c=new Date().getTime();
|
---|
75 | md.private.runtimename=sprintf('%s-%g',md.miscellaneous.name,c);
|
---|
76 | }
|
---|
77 | else{
|
---|
78 | md.private.runtimename=md.miscellaneous.name;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | //if running qmu analysis, some preprocessing of dakota files using models
|
---|
83 | //fields needs to be carried out.
|
---|
84 | if (md.qmu.isdakota){
|
---|
85 | throw Error("solve error message: qmu runs not supported yet!");
|
---|
86 | //md.preqmu(options);
|
---|
87 | }
|
---|
88 |
|
---|
89 | //flaim analysis (To be removed?)
|
---|
90 | if (solutionenum == FlaimSolutionEnum()){
|
---|
91 | //fmdir = options.getfieldvalue('fmdir',['fm' num2str(feature('GetPid'))]);
|
---|
92 | //overwrite = options.getfieldvalue('overwrite','n');
|
---|
93 | //keep = options.getfieldvalue('keep','y');
|
---|
94 | //latsgn = options.getfieldvalue('latsgn',0);
|
---|
95 | //cmap = options.getfieldvalue('cmap',[]);
|
---|
96 | throw Error("solve error message: flaim runs not supported yet!");
|
---|
97 | //flaim_sol(md,options);
|
---|
98 | //md.private.solution=EnumToString(solutionenum);
|
---|
99 | //return;
|
---|
100 | }
|
---|
101 |
|
---|
102 | //Do we load results only?
|
---|
103 | if (options.getfieldvalue('loadonly',false)){
|
---|
104 | loadresultsfromcluster(md);
|
---|
105 | return;
|
---|
106 | }
|
---|
107 |
|
---|
108 | //Write all input files
|
---|
109 | fid = marshall(md); // bin file
|
---|
110 | toolkitsstring= md.toolkits.ToolkitsFile(md.miscellaneous.name + '.toolkits'); // toolkits file
|
---|
111 |
|
---|
112 | if (cluster.classname() != 'local'){ //{{{
|
---|
113 |
|
---|
114 | throw Error('non local clusters not supported yet!');
|
---|
115 |
|
---|
116 | cluster.BuildQueueScript(md.private.runtimename,md.miscellaneous.name,md.private.solution,md.settings.io_gather,md.debug.valgrind,md.debug.gprof,md.qmu.isdakota); // queue file
|
---|
117 |
|
---|
118 | //Stop here if batch mode
|
---|
119 | if (options.getfieldvalue('batch','no') === 'yes'){
|
---|
120 | if (md.verbose.solution){
|
---|
121 | console.log('batch mode requested: not launching job interactively');
|
---|
122 | console.log('launch solution sequence on remote cluster by hand');
|
---|
123 | }
|
---|
124 | return;
|
---|
125 | }
|
---|
126 |
|
---|
127 | //Upload all required files
|
---|
128 | modelname = md.miscellaneous.name;
|
---|
129 | filelist = [modelname + '.bin ',modelname + '.toolkits '];
|
---|
130 | if (ispc){
|
---|
131 | filelist.push(modelname + '.bat ');
|
---|
132 | }
|
---|
133 | else{
|
---|
134 | filelist.push(modelname + '.queue ');
|
---|
135 | }
|
---|
136 |
|
---|
137 | if (md.qmu.isdakota){
|
---|
138 | filelist.push(modelname + '.qmu.in');
|
---|
139 | }
|
---|
140 |
|
---|
141 | if (restart == ''){
|
---|
142 | cluster.UploadQueueJob(md.miscellaneous.name,md.private.runtimename,filelist);
|
---|
143 | }
|
---|
144 |
|
---|
145 | //launch queue job:
|
---|
146 | cluster.LaunchQueueJob(md.miscellaneous.name,md.private.runtimename,filelist,restart);
|
---|
147 |
|
---|
148 | //wait on lock
|
---|
149 | if (md.settings.waitonlock == 'NaN'){
|
---|
150 | //load when user enters 'y'
|
---|
151 | console.log('solution launched on remote cluster. log in to detect job completion.');
|
---|
152 | throw Error("solve error message: user detection of successfull completion of job not support yet!");
|
---|
153 | /*choice=input('Is the job successfully completed? (y/n)','s');
|
---|
154 | if ~strcmp(choice,'y'),
|
---|
155 | console.log('Results not loaded... exiting');
|
---|
156 | else
|
---|
157 | md=loadresultsfromcluster(md);
|
---|
158 | end*/
|
---|
159 | }
|
---|
160 | else if (md.settings.waitonlock>0){
|
---|
161 | //we wait for the done file
|
---|
162 | done=waitonlock(md);
|
---|
163 | if (md.verbose.solution){
|
---|
164 | console.log('loading results from cluster');
|
---|
165 | }
|
---|
166 | loadresultsfromcluster(md);
|
---|
167 | }
|
---|
168 | else if (md.settings.waitonlock==0){
|
---|
169 | console.log('Model results must be loaded manually with md=loadresultsfromcluster(md);');
|
---|
170 | }
|
---|
171 |
|
---|
172 | //post processes qmu results if necessary
|
---|
173 | if (md.qmu.isdakota){
|
---|
174 | /*if ~strncmpi(options.getfieldvalue('keep','y'),'y',1)
|
---|
175 | system(['rm -rf qmu' num2str(feature('GetPid'))]);
|
---|
176 | end*/
|
---|
177 | }
|
---|
178 | } //}}}
|
---|
179 | else{ //if (cluster.classname() == 'local')
|
---|
180 |
|
---|
181 | /*We are running locally on the machine, using the issm module:*/
|
---|
182 | console.log('running issm locally');
|
---|
183 |
|
---|
184 | //Call issm:
|
---|
185 | issm(fid, toolkitsstring, solutionstring, md.miscellaneous.name);
|
---|
186 | }
|
---|
187 | }
|
---|