source: issm/trunk-jpl/src/m/classes/modellist.m@ 11865

Last change on this file since 11865 was 11865, checked in by Mathieu Morlighem, 13 years ago

removed all old matlab classes

File size: 4.8 KB
Line 
1%MODELLIST class definition
2%
3% Usage:
4% modellist=modellist({md1 md2 md3});
5
6classdef modellist
7 properties (SetAccess=public)
8 models = cell(0,1);
9 cluster = none();
10 end
11 methods
12 function obj = modellist(varargin) % {{{
13
14 %initialize list
15 if nargin==0,
16 %Do nothing,
17 elseif nargin==1,
18 if ~isa(varargin{1},'cell'),
19 error('not supported yet');
20 end
21
22 celllist=varargin{1};
23
24 %check on size of cell list:
25 if (size(celllist,2)~=1),
26 error('modellist constructor error message: list of models should be a cell list of column size 1');
27 end
28
29 %check that only models are in the celllist:
30 for i=1:size(celllist,1),
31 if ~isa(celllist{i},'model')
32 error(['modellist constructor error message: element ' num2str(i) ' of cell list is not a model!']);
33 end
34 end
35
36 obj.models = celllist;
37 obj.cluster = obj.models{1}.cluster;
38 end
39 end % }}}
40 function val = get(obj, propName)% {{{
41 %GET - gets model propertie from a specified object ans returns the value
42 %
43 % Usage:
44 % val = get(a, propName)
45
46 switch propName
47 case 'numberofelements'
48 val = obj.numberofelements;
49 case 'numberofnodes'
50 val = obj.numberofnodes;
51 case 'elements'
52 val = obj.elements;
53 case 'x'
54 val = obj.x;
55 case 'y'
56 val = obj.y;
57 case 'z'
58 val = obj.z;
59 otherwise
60 error(['get error message: ' propName,' is not a valid model property'])
61 end
62 end % }}}
63 function obj = loadmultipleresultsfromcluster(obj) % {{{
64 %LOADMULTIPLERESULTSFROMCLUSTER - load multiple results of solution sequences from cluster
65 %
66 % Usage:
67 % obj=loadresultsfromcluster(obj);
68
69 nummodels=length(obj.models);
70
71 %Get cluster settings
72 cluster=obj.cluster;
73 name=obj.name;
74 cluster_rc_location=which('cluster.rc');
75 [codepath,executionpath]=ClusterParameters(cluster,cluster_rc_location);
76
77 %Remote tar:
78 disp('tarring results');
79 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 "']);
80
81 %copy results from cluster to present directory
82 scpin(cluster, [executionpath '/' name], {'ModelResults.tar.gz'});
83
84 %untar:
85 !tar -zxvf ModelResults.tar.gz
86
87 %ok, go through list and load results from disk:
88 for i=1:nummodels,
89 %load results for this model
90 obj.models{i}=loadresultsfromdisk(obj.models{i},[name '-' num2str(i) 'vs' num2str(nummodels) '.outbin']);
91
92 delete([name '-' num2str(i) 'vs' num2str(nummodels) '.outbin']);
93 end
94
95 %erase files
96 delete('ModelResults.tar.gz');
97 end % }}}
98 function obj = solve(obj,varargin)% {{{
99 %SOLVE - apply solution sequence for a list of models. Used in batch mode.
100 %
101 % Usage:
102 % obj=solve(obj,varargin)
103 % where varargin is a lit of paired arguments.
104 % arguments can be: 'analysis_type': 'diagnostic','thermal','prognostic','transient'
105 %
106 % Examples:
107 % obj=solve(obj,'analysis_type','diagnostic');
108
109 %recover options
110 options=pairoptions(varargin{:});
111
112 %add default options
113 options=process_solve_options(options);
114
115 %length of list
116 nummodels=length(obj.models);
117
118 %name of queue: to make it unique, add a time stamp
119 name=[obj.name '-' datestr(now,1) '-' datestr(now,'HH-MM-SS') ];
120
121 %name of cluster will be first name of list
122 cluster=obj.cluster;
123
124 %Figure out parameters for this particular cluster
125 cluster_rc_location=which('cluster.rc');
126 [codepath,executionpath]=ClusterParameters(cluster,cluster_rc_location);
127
128 %solve in batch mode:
129 for i=1:nummodels,
130
131 %model
132 mdex=obj.models{i};
133
134 %recover some fields
135 mdex.analysis_type=options.analysis_type;
136
137 mdex.name=[name '-' num2str(i) 'vs' num2str(nummodels)];
138 mdex.time=obj.time;
139 mdex.queue=obj.queue;
140 mdex.cluster=obj.cluster;
141 if ~isnan(obj.np),
142 mdex.np=obj.np;
143 end
144
145 %call solve in batch mode:
146 if strcmpi(cluster,oshostname),
147 mdex=solve(mdex,varargin{:});
148 else
149 mdex=solve(mdex,varargin{:},'batch','yes','directory',name);
150 end
151
152 %feed back
153 obj.models{i}=mdex;
154 end
155
156 %locally, we are done.
157 if strcmpi(cluster,oshostname),
158 return
159 end
160
161
162 %now, tar all the files and then erase them.
163 eval(['!find -iname ''' name '-*'' > file_list.txt']);
164 !tar zcvf ModelList.tar.gz --files-from file_list.txt
165 !rm -rf *.bin *.queue file_list.txt
166
167 %still have to build a launching script.
168 BuildMultipleQueueingScript(cluster,name,executionpath,codepath);
169
170 %launch jobs on remote cluster
171 LaunchMultipleQueueJob(cluster,name,executionpath);
172
173 %erase files:
174 delete([name '.queue']);
175 delete('ModelList.tar.gz');
176
177 %save name:
178 obj.name=name;
179 end % }}}
180 end
181end
Note: See TracBrowser for help on using the repository browser.