Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/reorganize.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % REOGANIZE rearranges a ssm object for fast input to BODE, SIMULATE, PSD. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: rearranges a ssm object for fast input to BODE, SIMULATE, PSD. | |
5 % | |
6 % CALL: sys = reshuffle(sys, plist) | |
7 % | |
8 % INPUTS: | |
9 % 'sys' - ssm object | |
10 % 'plist' - plist object | |
11 % | |
12 % The inputs/states/outputs can only be indexed using a cellstr containing | |
13 % block names or port names. | |
14 % Then the object can be passed to BODE, SIMULATE, PSD, CPSD, RESP with | |
15 % the option "rearrange" turned to "false". These functions will run | |
16 % significantly faster. | |
17 % | |
18 % OUTPUTS: | |
19 % | |
20 % 'sys' - a ssm object. | |
21 % | |
22 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'reorganize')">Parameters Description</a> | |
23 % | |
24 % VERSION : $Id: reorganize.m,v 1.19 2011/05/23 14:15:44 adrien Exp $ | |
25 % | |
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
27 | |
28 function varargout = reorganize(varargin) | |
29 %% starting initial checks | |
30 | |
31 % Check if this is a call for parameters | |
32 if utils.helper.isinfocall(varargin{:}) | |
33 varargout{1} = getInfo(varargin{3}); | |
34 return | |
35 end | |
36 | |
37 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]); | |
38 | |
39 % Collect input variable names | |
40 in_names = cell(size(varargin)); | |
41 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
42 | |
43 % Collect all SSMs and plists | |
44 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names); | |
45 [pli, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
46 if ~isempty(rest) | |
47 pli = pli.combine(plist(rest{:})); | |
48 end | |
49 | |
50 if numel(sys)~=1 | |
51 error(['There should be only one input object to ' mfilename]) | |
52 end | |
53 | |
54 %%% Internal call: Only one object + don't look for a plist | |
55 internal = strcmp(varargin{end}, 'internal'); | |
56 | |
57 set = pli.find('set'); | |
58 | |
59 pli = pli.combine(getDefaultPlist(set)); | |
60 | |
61 sys = copy(sys, nargout); | |
62 | |
63 switch(lower(set)) | |
64 case 'none' | |
65 error('the options "set" HAS to be specified'); | |
66 case 'for bode' | |
67 inputnames = pli.find('inputs'); | |
68 statenames = pli.find('states'); | |
69 outputnames = pli.find('outputs'); | |
70 sys.reshuffle(inputnames, {}, {}, 'ALL', outputnames, statenames); | |
71 case 'for resp' | |
72 inputnames = pli.find('inputs'); | |
73 statenames = pli.find('states'); | |
74 outputnames = pli.find('outputs'); | |
75 sys.reshuffle( inputnames, {}, {}, 'ALL', outputnames, statenames); | |
76 case 'for simulate' | |
77 aos_varnames = find(pli, 'aos variable names'); | |
78 cov_varnames = find(pli, 'covariance variable names'); | |
79 cpsd_varnames = find(pli, 'CPSD variable names'); | |
80 constants_varnames = find(pli, 'constant variable names'); | |
81 return_states = find(pli, 'return states'); | |
82 return_outputs = find(pli, 'return outputs'); | |
83 sys.reshuffle( aos_varnames, [cov_varnames cpsd_varnames], constants_varnames, 'ALL', return_outputs, return_states ); | |
84 case 'for kalman' | |
85 aos_varnames = find(pli, 'aos variable names'); | |
86 cov_varnames = find(pli, 'covariance variable names'); | |
87 cpsd_varnames = find(pli, 'cpsd variable names'); | |
88 constants_varnames = find(pli, 'constant variable names'); | |
89 return_states = find(pli, 'return states'); | |
90 return_outputs = find(pli, 'return outputs'); | |
91 known_outputs = find(pli, 'known output variable names'); | |
92 sys_est = copy(sys,true); | |
93 sys_exp = copy(sys,true); | |
94 sys_est = reshuffle(sys_est, aos_varnames, [cov_varnames cpsd_varnames], constants_varnames, 'ALL', return_outputs, return_states ); | |
95 sys_exp = reshuffle(sys_exp, aos_varnames, [cov_varnames cpsd_varnames], constants_varnames, 'ALL', known_outputs, 'none' ); | |
96 sys = [sys_est sys_exp]; | |
97 case 'for cpsd' | |
98 aos_varnames = find(pli, 'aos variable names'); | |
99 cov_varnames = find(pli, 'covariance variable names'); | |
100 cpsd_varnames = find(pli, 'CPSD variable names'); | |
101 PZmodels_varnames = find(pli, 'PZmodel variable names'); | |
102 return_states = find(pli, 'return states'); | |
103 return_outputs = find(pli, 'return outputs'); | |
104 sys.reshuffle( aos_varnames, [cov_varnames cpsd_varnames], PZmodels_varnames, 'ALL', return_outputs, return_states ); | |
105 case 'for psd' | |
106 aos_varnames = find(pli, 'aos variable names'); | |
107 cov_varnames = find(pli, 'variance variable names'); | |
108 cpsd_varnames = find(pli, 'PSD variable names'); | |
109 PZmodels_varnames = find(pli, 'PZmodel variable names'); | |
110 return_states = find(pli, 'return states'); | |
111 return_outputs = find(pli, 'return outputs'); | |
112 sys.reshuffle( aos_varnames, [cov_varnames cpsd_varnames], PZmodels_varnames, 'ALL', return_outputs, return_states ); | |
113 case 'for cpsdforcorrelatedinputs' | |
114 aos_varnames = find(pli, 'aos variable names'); | |
115 cov_varnames = find(pli, 'covariance variable names'); | |
116 cpsd_varnames = find(pli, 'CPSD variable names'); | |
117 PZmodels_varnames = find(pli, 'PZmodel variable names'); | |
118 return_states = find(pli, 'return states'); | |
119 return_outputs = find(pli, 'return outputs'); | |
120 sys.reshuffle( aos_varnames, [cov_varnames cpsd_varnames], PZmodels_varnames, 'ALL', return_outputs, return_states ); | |
121 case 'for cpsdforindependentinputs' | |
122 aos_varnames = find(pli, 'aos variable names'); | |
123 cov_varnames = find(pli, 'variance variable names'); | |
124 cpsd_varnames = find(pli, 'PSD variable names'); | |
125 PZmodels_varnames = find(pli, 'PZmodel variable names'); | |
126 return_states = find(pli, 'return states'); | |
127 return_outputs = find(pli, 'return outputs'); | |
128 sys.reshuffle( aos_varnames, [cov_varnames cpsd_varnames], PZmodels_varnames, 'ALL', return_outputs, return_states ); | |
129 case 'none' | |
130 error('please set the parameter "set"') | |
131 otherwise | |
132 error('unknown parameter "set"') | |
133 end | |
134 | |
135 if ~internal | |
136 for i_sys = 1:numel(sys) | |
137 sys(i_sys).addHistory(getInfo('None'), pli, ssm_invars, sys(i_sys).hist ); | |
138 end | |
139 end | |
140 | |
141 sys.validate; | |
142 varargout = {sys}; | |
143 end | |
144 | |
145 | |
146 %-------------------------------------------------------------------------- | |
147 % Get Info Object | |
148 %-------------------------------------------------------------------------- | |
149 function ii = getInfo(varargin) | |
150 | |
151 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
152 sets = {}; | |
153 pl = []; | |
154 elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1}) | |
155 sets{1} = varargin{1}; | |
156 pl = getDefaultPlist(sets{1}); | |
157 else | |
158 sets = getSets; | |
159 pl = plist.initObjectWithSize(1,numel(sets)); | |
160 for i=1:numel(sets) | |
161 pl(i) = getDefaultPlist(sets{i}); | |
162 end | |
163 end | |
164 % Build info object | |
165 ii = minfo(mfilename, 'reorganize', 'ltpda', utils.const.categories.op, '$Id: reorganize.m,v 1.19 2011/05/23 14:15:44 adrien Exp $', sets, pl); | |
166 end | |
167 | |
168 function sets = getSets | |
169 sets = {'For bode', 'For simulate', 'For kalman', 'For cpsd', 'For resp', ... | |
170 'For psd', 'for cpsdforindependentinputs', 'for cpsdforcorrelatedinputs', 'none'}; | |
171 end | |
172 | |
173 function pl = getDefaultPlist(set) | |
174 sets = lower(getSets); | |
175 if ~utils.helper.ismember(sets, lower(set)) | |
176 error('### Unknown set [%s]', set); | |
177 end | |
178 | |
179 pl = plist(); | |
180 | |
181 p = param({'set','Choose for which operation the ssm iois re-organized is done'},... | |
182 {7, getSets, paramValue.SINGLE}); | |
183 pl.append(p); | |
184 | |
185 switch lower(set) % Select parameter set | |
186 case 'for bode' | |
187 p = param({'inputs', 'A cell-array of input ports and blocks.'}, 'ALL' ); | |
188 pl.append(p); | |
189 p = param({'outputs', 'A cell-array of output ports and blocks.'}, 'ALL' ); | |
190 pl.append(p); | |
191 p = param({'states', 'A cell-array of states ports and blocks.'}, 'NONE' ); | |
192 pl.append(p); | |
193 case 'for simulate' | |
194 p = param({'covariance variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
195 pl.append(p); | |
196 p = param({'CPSD variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
197 pl.append(p); | |
198 p = param({'aos variable names', 'A cell-array of input port names corresponding to the different input AOs.'}, paramValue.EMPTY_CELL); | |
199 pl.append(p); | |
200 p = param({'constant variable names', 'A cell-array of strings of the desired input variable names.'}, paramValue.EMPTY_CELL); | |
201 pl.append(p); | |
202 p = param({'return states', 'A cell-array of names of state ports to return.'}, paramValue.EMPTY_CELL); | |
203 pl.append(p); | |
204 p = param({'return outputs', 'A cell-array of output ports to return.'}, paramValue.EMPTY_CELL); | |
205 pl.append(p); | |
206 case 'for kalman' | |
207 p = param({'covariance variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
208 pl.append(p); | |
209 p = param({'CPSD variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
210 pl.append(p); | |
211 p = param({'aos variable names', 'A cell-array of input port names corresponding to the different input AOs.'}, paramValue.EMPTY_CELL); | |
212 pl.append(p); | |
213 p = param({'constant variable names', 'A cell-array of strings of the desired input variable names.'}, paramValue.EMPTY_CELL); | |
214 pl.append(p); | |
215 p = param({'return states', 'A cell-array of names of state ports to return.'}, paramValue.EMPTY_CELL); | |
216 pl.append(p); | |
217 p = param({'return outputs', 'A cell-array of output ports to return.'}, paramValue.EMPTY_CELL); | |
218 pl.append(p); | |
219 p = param({'known output variable names', 'A cell-array of strings of the known output variable names.'}, paramValue.EMPTY_CELL); | |
220 pl.append(p); | |
221 case 'for cpsd' | |
222 p = param({'covariance variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
223 pl.append(p); | |
224 p = param({'CPSD variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
225 pl.append(p); | |
226 p = param({'PZmodel variable names', 'A cell-array of strings of the desired input variable names.'}, paramValue.EMPTY_CELL); | |
227 pl.append(p); | |
228 p = param({'aos variable names', 'A cell-array of input defined with AOs spectrums.'}, paramValue.EMPTY_CELL); | |
229 pl.append(p); | |
230 p = param({'return states', 'A cell-array of names of state ports to return.'}, paramValue.EMPTY_CELL); | |
231 pl.append(p); | |
232 p = param({'return outputs', 'A cell-array of output ports to return.'}, paramValue.EMPTY_CELL); | |
233 pl.append(p); | |
234 case 'for resp' | |
235 p = param({'inputs', 'A cell-array of input ports and blocks.'}, 'ALL' ); | |
236 pl.append(p); | |
237 p = param({'outputs', 'A cell-array of output ports and blocks.'}, 'ALL' ); | |
238 pl.append(p); | |
239 p = param({'states', 'A cell-array of states ports and blocks.'}, 'NONE' ); | |
240 pl.append(p); | |
241 case 'for psd' | |
242 p = param({'variance variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
243 pl.append(p); | |
244 p = param({'PSD variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
245 pl.append(p); | |
246 p = param({'PZmodel variable names', 'A cell-array of strings of the desired input variable names.'}, paramValue.EMPTY_CELL); | |
247 pl.append(p); | |
248 p = param({'aos variable names', 'A cell-array of input defined with AOs spectrums.'}, paramValue.EMPTY_CELL); | |
249 pl.append(p); | |
250 p = param({'return states', 'A cell-array of names of state ports to return.'}, paramValue.EMPTY_CELL); | |
251 pl.append(p); | |
252 p = param({'return outputs', 'A cell-array of output ports to return.'}, paramValue.EMPTY_CELL); | |
253 pl.append(p); | |
254 case 'for cpsdforindependentinputs' | |
255 p = param({'variance variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
256 pl.append(p); | |
257 p = param({'PSD variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
258 pl.append(p); | |
259 p = param({'PZmodel variable names', 'A cell-array of strings of the desired input variable names.'}, paramValue.EMPTY_CELL); | |
260 pl.append(p); | |
261 p = param({'aos variable names', 'A cell-array of input defined with AOs spectrums.'}, paramValue.EMPTY_CELL); | |
262 pl.append(p); | |
263 p = param({'return states', 'A cell-array of names of state ports to return.'}, paramValue.EMPTY_CELL); | |
264 pl.append(p); | |
265 p = param({'return outputs', 'A cell-array of output ports to return.'}, paramValue.EMPTY_CELL); | |
266 pl.append(p); | |
267 case 'for cpsdforcorrelatedinputs' | |
268 p = param({'covariance variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
269 pl.append(p); | |
270 p = param({'CPSD variable names', 'A cell-array of strings specifying the desired input variable names.'}, paramValue.EMPTY_CELL ); | |
271 pl.append(p); | |
272 p = param({'PZmodel variable names', 'A cell-array of strings of the desired input variable names.'}, paramValue.EMPTY_CELL); | |
273 pl.append(p); | |
274 p = param({'aos variable names', 'A cell-array of input defined with AOs spectrums.'}, paramValue.EMPTY_CELL); | |
275 pl.append(p); | |
276 p = param({'return states', 'A cell-array of names of state ports to return.'}, paramValue.EMPTY_CELL); | |
277 pl.append(p); | |
278 p = param({'return outputs', 'A cell-array of output ports to return.'}, paramValue.EMPTY_CELL); | |
279 pl.append(p); | |
280 end | |
281 end |