1 | %MODELLIST class definition
|
---|
2 | %
|
---|
3 | % Usage:
|
---|
4 | % modellist=modellist({md1 md2 md3});
|
---|
5 |
|
---|
6 | classdef modellist
|
---|
7 | properties (SetAccess=public)
|
---|
8 | models = cell(0,1);
|
---|
9 | cluster = generic();
|
---|
10 | end
|
---|
11 | methods
|
---|
12 | function md_list=modelsextract(md,flags,minel,varargin) % {{{
|
---|
13 | %modelsextract - extract several self contained models according to a list of element flags.
|
---|
14 | %
|
---|
15 | % The difference between this routine and the modelextract.m routine (without an 's') is that
|
---|
16 | % as many models are extracted as there are closed contours defined in area.
|
---|
17 | % This routine is needed for example when doing data assimilation of ice shelves in Antarctica.
|
---|
18 | % Many independent ice shelves are present, and we don't want data assimilation on one ice shelf
|
---|
19 | % to be hindered by another totally independent ice shelf.
|
---|
20 | %
|
---|
21 | % Usage:
|
---|
22 | % md_list=modelsextract(md,elementfalgs,minel);
|
---|
23 | %
|
---|
24 | % Examples:
|
---|
25 | % md_list=modelsextract(md,md.mask.elementonfloatingice,1000);
|
---|
26 | %
|
---|
27 | % See also: EXTRUDE, COLLAPSE, MODELEXTRACT
|
---|
28 |
|
---|
29 | disp('selecting pools of elements');
|
---|
30 | %go through flags and build as many independent element flags as there are groups of connected 1s
|
---|
31 | %in flags.
|
---|
32 |
|
---|
33 | %2D or 3D?
|
---|
34 | if md.mesh.dimension==3,
|
---|
35 | numberofelements=md.mesh.numberofelements2d; %this will be forgotten when we get out.
|
---|
36 | flags=project2d(md,flags,1);
|
---|
37 | else
|
---|
38 | numberofelements=md.mesh.numberofelements;
|
---|
39 | end
|
---|
40 |
|
---|
41 | %recover extra arguments:
|
---|
42 | distance=0;
|
---|
43 | if nargin==4,
|
---|
44 | distance=varargin{1};
|
---|
45 | end
|
---|
46 |
|
---|
47 | flag_list=cell(0,1);
|
---|
48 |
|
---|
49 | for i=1:size(flags,1),
|
---|
50 |
|
---|
51 | if (flags(i)),
|
---|
52 |
|
---|
53 | %ok, we are sure element i is part of a new pool.
|
---|
54 | pool=zeros(numberofelements,1);
|
---|
55 | pool=PropagateFlagsFromConnectivity(md.mesh.elementconnectivity,pool,i,flags);
|
---|
56 | flag_list{end+1,1}=pool;
|
---|
57 |
|
---|
58 | %speed up rest of computation by taking pool out of flags:
|
---|
59 | pos=find(pool);flags(pos)=0;
|
---|
60 |
|
---|
61 | end
|
---|
62 | end
|
---|
63 |
|
---|
64 | %go through flag_list and discard any pool of less than minel elements:
|
---|
65 | ex_pos=[];
|
---|
66 | for i=1:length(flag_list),
|
---|
67 | if length(find(flag_list{i}))<minel,
|
---|
68 | ex_pos=[ex_pos; i];
|
---|
69 | end
|
---|
70 | end
|
---|
71 | flag_list(ex_pos)=[];
|
---|
72 |
|
---|
73 | %now, if distance was specified, expand the flag_list by distance km:
|
---|
74 | if distance,
|
---|
75 | for i=1:length(flag_list),
|
---|
76 | flag_list{i}=PropagateFlagsUntilDistance(md,flag_list{i},distance);
|
---|
77 | end
|
---|
78 | end
|
---|
79 |
|
---|
80 | %now, go use the pools of flags to extract models:
|
---|
81 | disp(['extracting ' num2str(size(flag_list,1)) ' models']);
|
---|
82 | models=cell(0,1);
|
---|
83 |
|
---|
84 | for i=1:size(flag_list,1),
|
---|
85 | disp([' ' num2str(i) '/' num2str(size(flag_list,1))]);
|
---|
86 | if md.mesh.dimension==3,
|
---|
87 | flags2d=flag_list{i};
|
---|
88 | realflags=project3d(md,flags2d,'element');
|
---|
89 | else
|
---|
90 | realflags=flag_list{i};
|
---|
91 | end
|
---|
92 | models{end+1,1}=modelextract(md,realflags);
|
---|
93 | end
|
---|
94 |
|
---|
95 | %return model list
|
---|
96 | md_list=modellist(models);
|
---|
97 |
|
---|
98 | end %end of this function }}}
|
---|
99 | function md_list=modelsextractfromdomains(md,directory) % {{{
|
---|
100 | %modelsextractfromdomains- extract several self contained models according to a list of domains
|
---|
101 | %
|
---|
102 | % Usage:
|
---|
103 | % md_list=modelsextractfromdomains(md,'Basins/');
|
---|
104 | %
|
---|
105 | % Examples:
|
---|
106 | % md_list=modelsextract(md,'Basins/');
|
---|
107 | %
|
---|
108 | % See also: MODELSEXTRACTS, MODELEXTRACT
|
---|
109 |
|
---|
110 | %go into directory and get list of files.
|
---|
111 | cd(directory);
|
---|
112 | basins=listfiles;
|
---|
113 | cd ..
|
---|
114 |
|
---|
115 | models=cell(0,1);
|
---|
116 | for i=1:length(basins),
|
---|
117 | models{end+1,1}=modelextract(md,[directory '/' basins{i}]);
|
---|
118 | end
|
---|
119 |
|
---|
120 | %return model list:
|
---|
121 | md_list=modellist(models);
|
---|
122 |
|
---|
123 | end % }}}
|
---|
124 | function obj = modellist(varargin) % {{{
|
---|
125 |
|
---|
126 | %initialize list
|
---|
127 | if nargin==0,
|
---|
128 | %Do nothing,
|
---|
129 | elseif nargin==1,
|
---|
130 | if ~isa(varargin{1},'cell'),
|
---|
131 | error('not supported yet');
|
---|
132 | end
|
---|
133 |
|
---|
134 | celllist=varargin{1};
|
---|
135 |
|
---|
136 | %check on size of cell list:
|
---|
137 | if (size(celllist,2)~=1),
|
---|
138 | error('modellist constructor error message: list of models should be a cell list of column size 1');
|
---|
139 | end
|
---|
140 |
|
---|
141 | %check that only models are in the celllist:
|
---|
142 | for i=1:size(celllist,1),
|
---|
143 | if ~isa(celllist{i},'model')
|
---|
144 | error(['modellist constructor error message: element ' num2str(i) ' of cell list is not a model!']);
|
---|
145 | end
|
---|
146 | end
|
---|
147 |
|
---|
148 | obj.models = celllist;
|
---|
149 | obj.cluster = obj.models{1}.cluster;
|
---|
150 | end
|
---|
151 | end % }}}
|
---|
152 | function val = get(obj, propName)% {{{
|
---|
153 | %GET - gets model propertie from a specified object ans returns the value
|
---|
154 | %
|
---|
155 | % Usage:
|
---|
156 | % val = get(a, propName)
|
---|
157 |
|
---|
158 | switch propName
|
---|
159 | case 'numberofelements'
|
---|
160 | val = obj.numberofelements;
|
---|
161 | case 'numberofnodes'
|
---|
162 | val = obj.numberofnodes;
|
---|
163 | case 'elements'
|
---|
164 | val = obj.elements;
|
---|
165 | case 'x'
|
---|
166 | val = obj.x;
|
---|
167 | case 'y'
|
---|
168 | val = obj.y;
|
---|
169 | case 'z'
|
---|
170 | val = obj.z;
|
---|
171 | otherwise
|
---|
172 | error(['get error message: ' propName,' is not a valid model property'])
|
---|
173 | end
|
---|
174 | end % }}}
|
---|
175 | function obj = loadmultipleresultsfromcluster(obj) % {{{
|
---|
176 | %LOADMULTIPLERESULTSFROMCLUSTER - load multiple results of solution sequences from cluster
|
---|
177 | %
|
---|
178 | % Usage:
|
---|
179 | % obj=loadresultsfromcluster(obj);
|
---|
180 |
|
---|
181 | nummodels=length(obj.models);
|
---|
182 |
|
---|
183 | %Get cluster settings
|
---|
184 | cluster=obj.cluster;
|
---|
185 | name=obj.name;
|
---|
186 | cluster_rc_location=which('cluster.rc');
|
---|
187 | [codepath,executionpath]=ClusterParameters(cluster,cluster_rc_location);
|
---|
188 |
|
---|
189 | %Remote tar:
|
---|
190 | disp('tarring results');
|
---|
191 | issmssh(cluster,['"cd ' executionpath '/' name ' && rm -rf file_list.txt ModelResults.tar.gz && find -iname ''*-*vs*.outbin'' > file_list.txt && tar zcvf ModelResults.tar.gz --files-from file_list.txt && rm -rf file_list.txt "']);
|
---|
192 |
|
---|
193 | %copy results from cluster to present directory
|
---|
194 | scpin(cluster, [executionpath '/' name], {'ModelResults.tar.gz'});
|
---|
195 |
|
---|
196 | %untar:
|
---|
197 | !tar -zxvf ModelResults.tar.gz
|
---|
198 |
|
---|
199 | %ok, go through list and load results from disk:
|
---|
200 | for i=1:nummodels,
|
---|
201 | %load results for this model
|
---|
202 | obj.models{i}=loadresultsfromdisk(obj.models{i},[name '-' num2str(i) 'vs' num2str(nummodels) '.outbin']);
|
---|
203 |
|
---|
204 | delete([name '-' num2str(i) 'vs' num2str(nummodels) '.outbin']);
|
---|
205 | end
|
---|
206 |
|
---|
207 | %erase files
|
---|
208 | delete('ModelResults.tar.gz');
|
---|
209 | end % }}}
|
---|
210 | function obj = solve(obj,varargin)% {{{
|
---|
211 | %SOLVE - apply solution sequence for a list of models. Used in batch mode.
|
---|
212 | %
|
---|
213 | % Usage:
|
---|
214 | % obj=solve(obj,varargin)
|
---|
215 | % where varargin is a lit of paired arguments.
|
---|
216 | % arguments can be: 'analysis_type': 'diagnostic','thermal','prognostic','transient'
|
---|
217 | %
|
---|
218 | % Examples:
|
---|
219 | % obj=solve(obj,'analysis_type','diagnostic');
|
---|
220 |
|
---|
221 | %recover options
|
---|
222 | options=pairoptions(varargin{:});
|
---|
223 |
|
---|
224 | %add default options
|
---|
225 | options=process_solve_options(options);
|
---|
226 |
|
---|
227 | %length of list
|
---|
228 | nummodels=length(obj.models);
|
---|
229 |
|
---|
230 | %name of queue: to make it unique, add a time stamp
|
---|
231 | name=[obj.name '-' datestr(now,1) '-' datestr(now,'HH-MM-SS') ];
|
---|
232 |
|
---|
233 | %name of cluster will be first name of list
|
---|
234 | cluster=obj.cluster;
|
---|
235 |
|
---|
236 | %Figure out parameters for this particular cluster
|
---|
237 | cluster_rc_location=which('cluster.rc');
|
---|
238 | [codepath,executionpath]=ClusterParameters(cluster,cluster_rc_location);
|
---|
239 |
|
---|
240 | %solve in batch mode:
|
---|
241 | for i=1:nummodels,
|
---|
242 |
|
---|
243 | %model
|
---|
244 | mdex=obj.models{i};
|
---|
245 |
|
---|
246 | %recover some fields
|
---|
247 | mdex.analysis_type=options.analysis_type;
|
---|
248 |
|
---|
249 | mdex.name=[name '-' num2str(i) 'vs' num2str(nummodels)];
|
---|
250 | mdex.time=obj.time;
|
---|
251 | mdex.queue=obj.queue;
|
---|
252 | mdex.cluster=obj.cluster;
|
---|
253 | if ~isnan(obj.np),
|
---|
254 | mdex.np=obj.np;
|
---|
255 | end
|
---|
256 |
|
---|
257 | %call solve in batch mode:
|
---|
258 | if strcmpi(cluster,oshostname),
|
---|
259 | mdex=solve(mdex,varargin{:});
|
---|
260 | else
|
---|
261 | mdex=solve(mdex,varargin{:},'batch','yes','directory',name);
|
---|
262 | end
|
---|
263 |
|
---|
264 | %feed back
|
---|
265 | obj.models{i}=mdex;
|
---|
266 | end
|
---|
267 |
|
---|
268 | %locally, we are done.
|
---|
269 | if strcmpi(cluster,oshostname),
|
---|
270 | return
|
---|
271 | end
|
---|
272 |
|
---|
273 |
|
---|
274 | %now, tar all the files and then erase them.
|
---|
275 | eval(['!find -iname ''' name '-*'' > file_list.txt']);
|
---|
276 | !tar zcvf ModelList.tar.gz --files-from file_list.txt
|
---|
277 | !rm -rf *.bin *.queue file_list.txt
|
---|
278 |
|
---|
279 | %still have to build a launching script.
|
---|
280 | BuildMultipleQueueingScript(cluster,name,executionpath,codepath);
|
---|
281 |
|
---|
282 | %launch jobs on remote cluster
|
---|
283 | LaunchMultipleQueueJob(cluster,name,executionpath);
|
---|
284 |
|
---|
285 | %erase files:
|
---|
286 | delete([name '.queue']);
|
---|
287 | delete('ModelList.tar.gz');
|
---|
288 |
|
---|
289 | %save name:
|
---|
290 | obj.name=name;
|
---|
291 | end % }}}
|
---|
292 | end
|
---|
293 | end
|
---|
294 |
|
---|
295 | function BuildMultipleQueueingScript(cluster,name,executionpath,codepath)% {{{
|
---|
296 | %BUILDMULTIPLEQUEUEINGSCRIPT -
|
---|
297 | %
|
---|
298 | % Usage:
|
---|
299 | % BuildMultipleQueueingScript(executionpath,codepath)
|
---|
300 |
|
---|
301 | disp('building queueing script');
|
---|
302 |
|
---|
303 | %First try and figure out if there is a special script for this particular cluster
|
---|
304 | function_name=['BuildMultipleQueueingScript' cluster];
|
---|
305 |
|
---|
306 | %some specific treatment of identical cluster, gemini, castor and pollux
|
---|
307 | if strcmpi(cluster,'castor') || strcmpi(cluster,'pollux'),
|
---|
308 | function_name='BuildMultipleQueueingScriptgemini';
|
---|
309 | end
|
---|
310 |
|
---|
311 | if exist(function_name,'file'),
|
---|
312 | %Call this function:
|
---|
313 | eval([function_name '(name,executionpath,codepath);']);
|
---|
314 | else
|
---|
315 | %Call the generic BuildQueueingScript:
|
---|
316 | BuildMultipleQueueingScriptGeneric(name,executionpath,codepath);
|
---|
317 | end
|
---|
318 | end % }}}
|
---|
319 | function BuildQueueingScriptgemini(name,executionpath,codepath)% {{{
|
---|
320 | %BUILDQUEUEINGSCRIPTGEMINI - ...
|
---|
321 | %
|
---|
322 | % Usage:
|
---|
323 | % BuildQueueingScriptgemini(md,executionpath,codepath)
|
---|
324 |
|
---|
325 | scriptname=[name '.queue'];
|
---|
326 |
|
---|
327 | fid=fopen(scriptname,'w');
|
---|
328 | if fid==-1,
|
---|
329 | error(['BuildQueueingScriptgeminierror message: could not open ' scriptname ' file for ascii writing']);
|
---|
330 | end
|
---|
331 |
|
---|
332 | fprintf(fid,'#!/bin/sh\n');
|
---|
333 | fprintf(fid,'cd %s\n',executionpath);
|
---|
334 | fprintf(fid,'mkdir %s\n',name);
|
---|
335 | fprintf(fid,'cd %s\n',name);
|
---|
336 | fprintf(fid,'mv ../ModelList.tar.gz ./\n');
|
---|
337 | fprintf(fid,'tar -zxvf ModelList.tar.gz\n');
|
---|
338 | fprintf(fid,'foreach i (%s-*vs*.queue)\n',name);
|
---|
339 | fprintf(fid,'qsub $i\n');
|
---|
340 | fprintf(fid,'end\n');
|
---|
341 | fclose(fid);
|
---|
342 | end% }}}
|
---|
343 | function LaunchMultipleQueueJob(cluster,name,executionpath)% {{{
|
---|
344 | %LAUNCHMULTIPLEQUEUEJOB - ...
|
---|
345 | %
|
---|
346 | % Usage:
|
---|
347 | % LaunchMultipleQueueJob(executionpath)
|
---|
348 |
|
---|
349 | %First try and figure out if there is a special script for thie particular cluster
|
---|
350 | function_name=['LaunchMultipleQueueJob' cluster];
|
---|
351 |
|
---|
352 | %some specific treatment of identical cluster, gemini, castor and pollux
|
---|
353 | if strcmpi(cluster,'castor') || strcmpi(cluster,'pollux'),
|
---|
354 | function_name='LaunchMultipleQueueJobgemini';
|
---|
355 | end
|
---|
356 |
|
---|
357 | if exist(function_name,'file'),
|
---|
358 | %Call this function:
|
---|
359 | eval([function_name '(cluster,name,executionpath);']);
|
---|
360 | else
|
---|
361 | %Call the generic LaunchMultipleQueueJob:
|
---|
362 | LaunchMultipleQueueJobGeneric(cluster,name,executionpath);
|
---|
363 | end
|
---|
364 | end% }}}
|
---|
365 | function md=LaunchMultipleQueueJobgemini(cluster,name,executionpath)% {{{
|
---|
366 | %LAUNCHMULTIPLEQUEUEJOBGEMINI - Launch multiple queueing script on Gemini cluster
|
---|
367 | %
|
---|
368 | % Usage:
|
---|
369 | % LaunchMultipleQueueJobgemini(cluster,name,executionpath)
|
---|
370 |
|
---|
371 |
|
---|
372 | %first, check we have the binary file and the queueing script
|
---|
373 | if ~exist([ name '.queue'],'file'),
|
---|
374 | error('LaunchMultipleQueueJobgemini error message: queueing script issing, cannot go forward');
|
---|
375 | end
|
---|
376 |
|
---|
377 | if ~exist('ModelList.tar.gz','file'),
|
---|
378 | error('LaunchMultipleQueueJobgemini error message: inputs models file missing, cannot go forward');
|
---|
379 | end
|
---|
380 |
|
---|
381 | %upload both files to cluster
|
---|
382 | disp('uploading input file, queueing script and variables script');
|
---|
383 | eval(['!scp ModelList.tar.gz ' name '.queue ' cluster ':' executionpath]);
|
---|
384 |
|
---|
385 | disp('launching solution sequence on remote cluster');
|
---|
386 | issmssh(cluster,login,['"cd ' executionpath ' && source ' name '.queue "']);
|
---|
387 | end% }}}
|
---|