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

Last change on this file since 20270 was 20270, checked in by Eric.Larour, 9 years ago

CHG (JS):

  • successful processing of the results when calling a remote cluster that returns the .outbin file as a typed array

buffer.

  • implementing a callback function in the solve.js routine, because the oReq Post routine that retrieves the outbin

typed array buffer from the server during the http request is an async call, which can therefore not be controlled
serially.

File size: 4.1 KB
Line 
1function 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(){}; //default, do nothing if no callback requested.
106 if (options.getfieldvalue('callback',false)){
107 callbackfunction=options.getfieldvalue('callback');
108 }
109
110 if (cluster.classname() == 'local'){ //{{{
111
112 /*We are running locally on the machine, using the issm module:*/
113 console.log('running issm locally');
114
115 //Call issm:
116 var outputs = issm(fid, toolkitsstring, solutionstring, md.miscellaneous.name);
117
118 //Recover output arguments:
119 var outputbuffer = outputs[0]; var outputbuffersize = outputs[1];
120
121 //Load results:
122 md.results = loadresultsfrombuffer(md,outputbuffer,outputbuffersize);
123
124 //Call back?
125 callbackfunction();
126
127 return md;
128
129 } //}}}
130 else { //{{{
131
132 /*We are running somewhere else on a computational server. Send the buffer to that server and retrieve output: */
133 cluster.UploadAndRun(md,callbackfunction,fid,toolkitsstring,solutionstring,md.miscellaneous.name);
134
135 return md;
136
137 } //}}}
138}
Note: See TracBrowser for help on using the repository browser.