| 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...,,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 strcmp(meshtype(md.mesh),'3D'),
|
|---|
| 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 strcmp(meshtype(md.mesh),'3D'),
|
|---|
| 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': 'stressbalance','thermal','masstransport','transient'
|
|---|
| 217 | %
|
|---|
| 218 | % Examples:
|
|---|
| 219 | % obj=solve(obj,'analysis_type','stressbalance');
|
|---|
| 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 | %now, tar all the files and then erase them.
|
|---|
| 274 | eval(['!find -iname ''' name '-*'' > file_list.txt']);
|
|---|
| 275 | !tar zcvf ModelList.tar.gz --files-from file_list.txt
|
|---|
| 276 | !rm -rf *.bin *.queue file_list.txt
|
|---|
| 277 |
|
|---|
| 278 | %still have to build a launching script.
|
|---|
| 279 | BuildMultipleQueueingScript(cluster,name,executionpath,codepath);
|
|---|
| 280 |
|
|---|
| 281 | %launch jobs on remote cluster
|
|---|
| 282 | LaunchMultipleQueueJob(cluster,name,executionpath);
|
|---|
| 283 |
|
|---|
| 284 | %erase files:
|
|---|
| 285 | delete([name '.queue']);
|
|---|
| 286 | delete('ModelList.tar.gz');
|
|---|
| 287 |
|
|---|
| 288 | %save name:
|
|---|
| 289 | obj.name=name;
|
|---|
| 290 | end % }}}
|
|---|
| 291 | end
|
|---|
| 292 | end
|
|---|
| 293 |
|
|---|
| 294 | function BuildMultipleQueueingScript(cluster,name,executionpath,codepath)% {{{
|
|---|
| 295 | %BUILDMULTIPLEQUEUEINGSCRIPT -
|
|---|
| 296 | %
|
|---|
| 297 | % Usage:
|
|---|
| 298 | % BuildMultipleQueueingScript(executionpath,codepath)
|
|---|
| 299 |
|
|---|
| 300 | disp('building queueing script');
|
|---|
| 301 |
|
|---|
| 302 | %First try and figure out if there is a special script for this particular cluster
|
|---|
| 303 | function_name=['BuildMultipleQueueingScript' cluster]
|
|---|
| 304 |
|
|---|
| 305 | %some specific treatment of identical cluster, gemini, castor and pollux
|
|---|
| 306 | if strcmpi(cluster,'castor') || strcmpi(cluster,'pollux'),
|
|---|
| 307 | function_name='BuildMultipleQueueingScriptgemini';
|
|---|
| 308 | end
|
|---|
| 309 |
|
|---|
| 310 | if exist(function_name,'file'),
|
|---|
| 311 | %Call this function:
|
|---|
| 312 | eval([function_name '(name,executionpath,codepath);']);
|
|---|
| 313 | else
|
|---|
| 314 | %Call the generic BuildQueueingScript:
|
|---|
| 315 | BuildMultipleQueueingScriptGeneric(name,executionpath,codepath);
|
|---|
| 316 | end
|
|---|
| 317 | end % }}}
|
|---|
| 318 | function BuildQueueingScriptgemini(name,executionpath,codepath)% {{{
|
|---|
| 319 | %BUILDQUEUEINGSCRIPTGEMINI - ...
|
|---|
| 320 | %
|
|---|
| 321 | % Usage:
|
|---|
| 322 | % BuildQueueingScriptgemini(md,executionpath,codepath)
|
|---|
| 323 |
|
|---|
| 324 | scriptname=[name '.queue'];
|
|---|
| 325 |
|
|---|
| 326 | fid=fopen(scriptname,'w');
|
|---|
| 327 | if fid==-1,
|
|---|
| 328 | error(['BuildQueueingScriptgeminierror message: could not open ' scriptname ' file for ascii writing']);
|
|---|
| 329 | end
|
|---|
| 330 |
|
|---|
| 331 | fprintf(fid,'#!/bin/sh\n');
|
|---|
| 332 | fprintf(fid,'cd %s\n',executionpath);
|
|---|
| 333 | fprintf(fid,'mkdir %s\n',name);
|
|---|
| 334 | fprintf(fid,'cd %s\n',name);
|
|---|
| 335 | fprintf(fid,'mv ../ModelList.tar.gz ./\n');
|
|---|
| 336 | fprintf(fid,'tar -zxvf ModelList.tar.gz\n');
|
|---|
| 337 | fprintf(fid,'foreach i (%s-*vs*.queue)\n',name);
|
|---|
| 338 | fprintf(fid,'qsub $i\n');
|
|---|
| 339 | fprintf(fid,'end\n');
|
|---|
| 340 | fclose(fid);
|
|---|
| 341 | end% }}}
|
|---|
| 342 | function LaunchMultipleQueueJob(cluster,name,executionpath)% {{{
|
|---|
| 343 | %LAUNCHMULTIPLEQUEUEJOB - ...
|
|---|
| 344 | %
|
|---|
| 345 | % Usage:
|
|---|
| 346 | % LaunchMultipleQueueJob(executionpath)
|
|---|
| 347 |
|
|---|
| 348 | %First try and figure out if there is a special script for thie particular cluster
|
|---|
| 349 | function_name=['LaunchMultipleQueueJob' cluster]
|
|---|
| 350 |
|
|---|
| 351 | %some specific treatment of identical cluster, gemini, castor and pollux
|
|---|
| 352 | if strcmpi(cluster,'castor') || strcmpi(cluster,'pollux'),
|
|---|
| 353 | function_name='LaunchMultipleQueueJobgemini';
|
|---|
| 354 | end
|
|---|
| 355 |
|
|---|
| 356 | if exist(function_name,'file'),
|
|---|
| 357 | %Call this function:
|
|---|
| 358 | eval([function_name '(cluster,name,executionpath);']);
|
|---|
| 359 | else
|
|---|
| 360 | %Call the generic LaunchMultipleQueueJob:
|
|---|
| 361 | LaunchMultipleQueueJobGeneric(cluster,name,executionpath);
|
|---|
| 362 | end
|
|---|
| 363 | end% }}}
|
|---|
| 364 | function md=LaunchMultipleQueueJobgemini(cluster,name,executionpath)% {{{
|
|---|
| 365 | %LAUNCHMULTIPLEQUEUEJOBGEMINI - Launch multiple queueing script on Gemini cluster
|
|---|
| 366 | %
|
|---|
| 367 | % Usage:
|
|---|
| 368 | % LaunchMultipleQueueJobgemini(cluster,name,executionpath)
|
|---|
| 369 |
|
|---|
| 370 | %first, check we have the binary file and the queueing script
|
|---|
| 371 | if ~exist([ name '.queue'],'file'),
|
|---|
| 372 | error('LaunchMultipleQueueJobgemini error message: queueing script issing, cannot go forward');
|
|---|
| 373 | end
|
|---|
| 374 |
|
|---|
| 375 | if ~exist('ModelList.tar.gz','file'),
|
|---|
| 376 | error('LaunchMultipleQueueJobgemini error message: inputs models file missing, cannot go forward');
|
|---|
| 377 | end
|
|---|
| 378 |
|
|---|
| 379 | %upload both files to cluster
|
|---|
| 380 | disp('uploading input file, queueing script and variables script');
|
|---|
| 381 | eval(['!scp ModelList.tar.gz ' name '.queue ' cluster ':' executionpath]);
|
|---|
| 382 |
|
|---|
| 383 | disp('launching solution sequence on remote cluster');
|
|---|
| 384 | issmssh(cluster,login,['"cd ' executionpath ' && source ' name '.queue "']);
|
|---|
| 385 | end% }}}
|
|---|