rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
lin_evol_opt_rb_operators_separate_bases.m
1 function [LL_I, LL_E, bb, M_E, M_b, M_EE, M_Eb, M_bb, M_I, M_II, M_IE, M_Ib, ...
2  varargout] = lin_evol_opt_rb_operators_separate_bases(model, detailed_data)
3 %function [LL_I, LL_E, bb, M_E, M_b, M_EE, M_Eb, M_bb, M_I, M_II, M_IE, M_Ib, ...
4 % {M_EdEd, M_IdId, M_bdbd, M_Ed, M_Id, M_bd, M_IEd, M_IId, M_Ibd, M_EEd, ...
5 % M_EId, M_Ebd, M_EdId, M_Edbd, M_Idbd]} = ...
6 % lin_evol_opt_rb_operators_separate_bases(model, detailed_data)
7 %
8 %
9 % function computing the time-dependent reduced basis operators and
10 % vectors (Galerkin Projection) including derivative operators.
11 % Splittet into different decomp modes for returning operators, components
12 % or coefficients.
13 % We assume different reduced bases for the original solution and the
14 % derivative solutions.
15 % The derivative reduced bases are stores in detailed_data.RB_der{i}.
16 %
17 % In contrast to lin_evol_rb_operators the time step (I+dt*L) is not
18 % included in the operators.
19 %
20 % When choosing decomp mode = 1, it gives back projections on ALL available
21 % bases in RB_der. A selection of parameters to optimize is not done.
22 % When choosing decomp_mode = 2, it gives back the coefficients to ALL
23 % parameters in the model. A selection of parameters to optimize is not
24 % done.
25 %
26 % required fields of model
27 % operators_algorithm: name of function for computing the
28 % L_E,L_I,b-operators with arguments (grid, params)
29 % example fv_operators_implicit
30 % compute_derivative_info: 1 if derivative information is wanted
31 % 0 if derivative information is not wanted
32 %
33 %
34 % optional fields of model:
35 % mu_names : names of fields to be regarded as parameters in vector mu
36 % decomp_mode: operation mode of the function
37 % -0= 'complete' (default): no parameter dependence or decomposition is
38 % performed. output is as described above.
39 % -1= 'components': For each output argument a cell array of output
40 % arguments is returned representing the q-th component
41 % independent of the parameters given in mu_names
42 % -2= 'coefficients': For each output argument a cell array of output
43 % arguments is returned representing the q-th coefficient
44 % dependent of the parameters given in mu_names
45 %
46 % required fields of detailed_data:
47 % RB: the reduced basis for the original solution
48 % RB_der: cell array of derivative reduced bases
49 %
50 % generated fields of varargout:
51 % L_E_dd: galerkin projection on derivative space
52 % L_I_dd:
53 % dL_E_sd: galerkin projection of operator applied on solution on
54 % derivative space
55 % dL_I_sd:
56 % db: b projected on derivative space
57 % K...: K error matrices (formulas in detail in Paper)
58 %
59 % In 'coefficients' mode the detailed data is empty.
60 
61 % Markus Dihlmann 24.03.2011
62 
63 % determine affine_decomposition_mode as integer
64 decomp_mode = model.decomp_mode;
65 
66 
67 
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 %%% decomp_mode 0 %%%
70 %%% complete calculation matrices %%%
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 if decomp_mode == 0 % complete: simple projection on RB
73 
74  %eval('u0 = ',params.init_value_algorithm,'(grid,params)']);
75  [L_I, L_E, b] = model.operators_ptr(model,detailed_data);
76 
77  % apply all operator contributions to RB:
78  %$L_E_RB = L_E * detailed_data.RB;
79  %$L_I_RB = L_I * detailed_data.RB;
80 
81  % fill output quantities
82  % LL_I : matrix
83  A = detailed_data.W;
84 
85  %reduced Operators
86  LL_I = detailed_data.RB' * A * L_I * detailed_data.RB;
87 
88  % LL_E : matrix
89  LL_E = detailed_data.RB' * A * L_E * detailed_data.RB;
90 
91  % bb : vector
92  bb = detailed_data.RB' * A * b;
93 
94 
95  %Error estimation operators
96 
97  % often used /Phi^T L_E^T A
98  RB_L_E = detailed_data.RB' * L_E' * A;
99 
100  M_E = RB_L_E * detailed_data.RB;
101  M_b = b' * A * detailed_data.RB;
102  M_EE = RB_L_E * L_E * detailed_data.RB;
103  M_Eb = RB_L_E * b;
104  M_bb = b' * A * b;
105 
106 
107  % Implicit operators
108  % often used /Phi^T L_I^T A
109  RB_L_I = detailed_data.RB' * L_I' * A ;
110 
111  M_I = RB_L_I * detailed_data.RB;
112  M_II = RB_L_I * L_I * detailed_data.RB;
113  M_IE = RB_L_I * L_E * detailed_data.RB;
114  M_Ib = RB_L_I * b;
115 
116 
117  % creation of derivative matrices
118  % get components and coefficients and do linear combination
119 % if model.compute_derivative_info
120 % if isfield(model.optimization,'params_to_optimize')
121 % indx_mu_i = find(model.optimization.params_to_optimize); %indexes i of \mu_i for which derivative information is needed
122 % else
123 % indx_mu_i = 1:length(get_mu(model));
124 % end
125 % nr_indx_mu_i= length(indx_mu_i); %nr of parameters to be optimized
126 %
127 % % create dummy files for derivative matrices --> memory
128 % % preallocation
129 % if ~isfield(model,'t')
130 % model.t=1;
131 % end
132 %
133 % model.decomp_mode = 1;
134 % [dummy_LL_I, dummy_LL_E, dummy_bb, dummy_M_E, dummy_M_b, dummy_M_EE, ...
135 % dummy_M_Eb, dummy_M_bb, dummy_M_I, dummy_M_II, dummy_M_IE, ...
136 % dummy_M_Ib, dummy_M_EdEd, dummy_M_IdId, dummy_M_bdbd, ...
137 % dummy_M_Ed, dummy_M_Id, dummy_M_bd, dummy_M_IEd, dummy_M_IId, ...
138 % dummy_M_Ibd, dummy_M_EEd, dummy_M_EId, dummy_M_Ebd, dummy_M_EdId,...
139 % ]=rb_operators(model,detailed_data); %dummy_M_Edbd, dummy_M_Idbd] = rb_operators(model,detailed_data); --> MEdbd, M_Idbd not needed
140 %
141 % if isempty(dummy_M_EdEd)
142 % M_EdEd = zeros(1,1,nr_indx_mu_i);
143 % else
144 % M_EdEd = zeros(nRB,nRB,nr_indx_mu_i);
145 % end
146 %
147 % if isempty(dummy_M_IdId)
148 % M_IdId = zeros(1,1,nr_indx_mu_i);
149 % else
150 % M_IdId = zeros(nRB,nRB,nr_indx_mu_i);
151 % end
152 %
153 % if isempty(dummy_M_Ed)
154 % M_Ed = zeros(1,1,nr_indx_mu_i);
155 % else
156 % M_Ed = zeros(nRB,nRB,nr_indx_mu_i);
157 % end
158 %
159 % if isempty(dummy_M_Id)
160 % M_Id = zeros(1,1,nr_indx_mu_i);
161 % else
162 % M_Id = zeros(nRB,nRB,nr_indx_mu_i);
163 % end
164 %
165 % if isempty(dummy_M_IEd)
166 % M_IEd = zeros(1,1,nr_indx_mu_i);
167 % else
168 % M_IEd = zeros(nRB,nRB,nr_indx_mu_i);
169 % end
170 %
171 % if isempty(dummy_M_IId)
172 % M_IId = zeros(1,1,nr_indx_mu_i);
173 % else
174 % M_Id = zeros(nRB,nRB,nr_indx_mu_i);
175 % end
176 %
177 % if isempty(dummy_M_EEd)
178 % M_EEd = zeros(1,1,nr_indx_mu_i);
179 % else
180 % M_EEd = zeros(nRB,nRB,nr_indx_mu_i);
181 % end
182 %
183 % if isempty(dummy_M_EId)
184 % M_EId = zeros(1,1,nr_indx_mu_i);
185 % else
186 % M_EId = zeros(nRB,nRB,nr_indx_mu_i);
187 % end
188 %
189 % if isempty(dummy_M_EdId)
190 % M_EdId = zeros(1,1,nr_indx_mu_i);
191 % else
192 % M_EdId = zeros(nRB,nRB,nr_indx_mu_i);
193 % end
194 %
195 % M_bdbd = zeros(1 ,1 ,nr_indx_mu_i);
196 % M_bd = zeros(1 ,nRB,nr_indx_mu_i);
197 % M_Ibd = zeros(nRB,1 ,nr_indx_mu_i);
198 % M_Ebd = zeros(nRB,1 ,nr_indx_mu_i);
199 % M_Edbd = zeros(nRB,1 ,nr_indx_mu_i);
200 % M_Idbd = zeros(nRB,1 ,nr_indx_mu_i);
201 % % end of: create dummy files for derivative matrices --> memory
202 % % preallocation
203 %
204 %
205 % %get components
206 % model.decomp_mode = 1;
207 % [compLL_I, compLL_E, compbb, compM_E, compM_b, compM_EE, compM_Eb,...
208 % compM_bb, compM_I, compM_II, compM_IE, compM_Ib, compM_EdEd,...
209 % compM_IdId, compM_bdbd, compM_Ed, compM_Id, compM_bd, compM_IEd,...
210 % compM_IId, compM_Ibd, compM_EEd, compM_EId, compM_Ebd,...
211 % compM_EdId, compM_Edbd, compM_Idbd] = rb_operators(model,detailed_data);
212 %
213 %
214 % %get coefficients
215 % model.decomp_mode = 2;
216 % [sLL_I, sLL_E, sbb, sM_E, sM_b, sM_EE, sM_Eb, sM_bb, sM_I, sM_II,...
217 % sM_IE, sM_Ib, sM_EdEd, sM_IdId, sM_bdbd, sM_Ed, sM_Id, sM_bd,...
218 % sM_IEd, sM_IId, sM_Ibd, sM_EEd, sM_EId, sM_Ebd, sM_EdId,...
219 % sM_Edbd, sM_Idbd] = rb_operators(model,detailed_data);
220 %
221 %
222 % %do linear combination of components and coefficients
223 % for i=1:nr_indx_mu_i
224 % M_EdEd(:,:,i) = lincomb_sequence(compM_EdEd,sM_EdEd(:,i));
225 % M_IdId(:,:,i) = lincomb_sequence(compM_IdId,sM_IdId(:,i));
226 % M_bdbd(:,:,i) = lincomb_sequence(compM_bdbd,sM_bdbd(:,i));
227 % M_Ed(:,:,i) = lincomb_sequence(compM_Ed ,sM_Ed(:,i));
228 % M_Id(:,:,i) = lincomb_sequence(compM_Id ,sM_Id(:,i));
229 % M_bd(:,:,i) = lincomb_sequence(compM_bd ,sM_bd(:,i));
230 % M_IEd(:,:,i) = lincomb_sequence(compM_IEd ,sM_IEd(:,i));
231 % M_IId(:,:,i) = lincomb_sequence(compM_IId ,sM_IId(:,i));
232 % M_Ibd(:,:,i) = lincomb_sequence(compM_Ibd ,sM_Ibd(:,i));
233 % M_EEd(:,:,i) = lincomb_sequence(compM_EEd ,sM_EEd(:,i));
234 % M_EId(:,:,i) = lincomb_sequence(compM_EId ,sM_EId(:,i));
235 % M_Ebd(:,:,i) = lincomb_sequence(compM_Ebd ,sM_Ebd(:,i));
236 % M_EdId(:,:,i) = lincomb_sequence(compM_EdId,sM_EdId(:,i));
237 % M_Edbd(:,:,i) = lincomb_sequence(compM_Edbd,sM_Edbd(:,i));
238 % M_Idbd(:,:,i) = lincomb_sequence(compM_Idbd,sM_Idbd(:,i));
239 % end
240 %
241 % varargout( 1) = {M_EdEd};
242 % varargout( 2) = {M_IdId};
243 % varargout( 3) = {M_bdbd};
244 % varargout( 4) = {M_Ed};
245 % varargout( 5) = {M_Id};
246 % varargout( 6) = {M_bd};
247 % varargout( 7) = {M_IEd};
248 % varargout( 8) = {M_IId};
249 % varargout( 9) = {M_Ibd};
250 % varargout(10) = {M_EEd};
251 % varargout(11) = {M_EId};
252 % varargout(12) = {M_Ebd};
253 % varargout(13) = {M_EdId};
254 % varargout(14) = {M_Edbd};
255 % varargout(15) = {M_Idbd};
256 %
257 % end %if model.compute_derivative_info
258 
259 
260 %set decomp_mode back to 0
261 model.decomp_mode = 0;
262 
263 
264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 %%% decomp_mode 1 %%%
266 %%% calculation of components %%%
267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268 elseif decomp_mode == 1
269 
270  %eval('u0 = ',params.init_value_algorithm,'(grid,params)']);
271  [L_I, L_E, b] = model.operators_ptr(model, detailed_data);
272 
273  Q_L_I = length(L_I);
274  Q_L_E = length(L_E);
275  Q_b = length(b);
276 
277 
278  Nmax = size(detailed_data.RB,2);
279  H = size(detailed_data.RB,1);
280  A = detailed_data.W;
281 
282 
283  %reduced operator components:
284  % LL_I : matrices
285  LL_I = cell(Q_L_I,1);
286  if ~isempty(L_I)
287  LL_I(:) = {zeros(Nmax,Nmax)};
288  for q = 1:Q_L_I;
289  LL_I{q} = detailed_data.RB' * A * L_I{q} * detailed_data.RB;
290  end;
291  end
292  % LL_E : matrices
293  LL_E = cell(Q_L_E,1);
294  LL_E(:) = {zeros(Nmax,Nmax)};
295  for q = 1:Q_L_E;
296  LL_E{q} = detailed_data.RB' * A * L_E{q} * detailed_data.RB;
297  end;
298 
299  % bb : vectors
300  bb = cell(Q_b,1);
301  bb(:) = {zeros(Nmax,1)};
302  for q = 1:Q_b;
303  bb{q} = detailed_data.RB' * A * b{q};
304  end;
305 
306 
307  % init output quantities
308  M_E = cell(Q_L_E,1); M_E(:) = {zeros(Nmax,Nmax)};
309  M_b = cell(Q_b,1); M_b(:) = {zeros(Nmax,1)};
310  M_EE = cell(Q_L_E*Q_L_E,1); M_EE(:) = {zeros(Nmax,Nmax)};
311  M_Eb = cell(Q_L_E*Q_b,1); M_Eb(:) = {zeros(Nmax,1)};
312  M_bb = cell(Q_b*Q_b,1); M_bb(:) = {zeros(1,1)};
313  M_I = cell(Q_L_I,1); M_I(:) = {zeros(Nmax,Nmax)};
314  M_II = cell(Q_L_I*Q_L_I,1); M_II(:) = {zeros(Nmax,Nmax)};
315  M_IE = cell(Q_L_I*Q_L_E,1); M_IE(:) = {zeros(Nmax,Nmax)};
316  M_Ib = cell(Q_L_I*Q_b,1); M_Ib(:) = {zeros(Nmax,1)};
317 
318 
319  % often used matrices:
320  RB_L_E = cell(Q_L_E,1);
321  RB_L_E(:) = {zeros(Nmax,H)};
322  for q=1:Q_L_E
323  RB_L_E{q}(:,:)= detailed_data.RB' * L_E{q}' * A;
324  end;
325 
326  RB_L_I = cell(Q_L_I,1);
327  RB_L_I(:) = {zeros(Nmax,H)};
328  for q=1:Q_L_I
329  RB_L_I{q}(:,:)= detailed_data.RB' * L_I{q}' * A;
330  end;
331 
332  L_E_RB = cell(Q_L_E,1);
333  L_E_RB(:) = {zeros(H,Nmax)};
334  for q=1:Q_L_E
335  L_E_RB{q} = L_E{q}*detailed_data.RB;
336  end
337 
338  L_I_RB = cell(Q_L_I,1);
339  L_I_RB(:) = {zeros(H,Nmax)};
340  for q=1:Q_L_I
341  L_I_RB{q} = L_I{q}*detailed_data.RB;
342  end
343 
344 
345  % fill output quantities
346  for q=1:Q_L_E
347  M_E{q} = RB_L_E{q} * detailed_data.RB;
348  end
349 
350  for q=1:Q_b
351  M_b{q} = b{q}' * A * detailed_data.RB;
352  end
353 
354  for q1=1:Q_L_E
355  for q2= 1:Q_L_E
356  M_EE{q2+(q1-1)*Q_L_E} = RB_L_E{q1} * L_E_RB{q2};
357  end
358  end
359 
360  for q1=1:Q_L_E
361  for q2=1:Q_b
362  M_Eb{q2+(q1-1)*Q_b} = RB_L_E{q1} * b{q2};
363  end;
364  end
365 
366  for q1=1:Q_b
367  for q2=1:Q_b
368  M_bb{q2+(q1-1)*Q_b} = b{q1}' * A * b{q2};
369  end
370  end
371 
372  for q=1:Q_L_I
373  M_I{q} = RB_L_I{q} * detailed_data.RB;
374  end
375 
376  for q1=1:Q_L_I
377  for q2= 1:Q_L_I
378  M_II{q2+(q1-1)*Q_L_I} = RB_L_I{q1} * L_I_RB{q2};
379  end
380  end
381 
382  for q1=1:Q_L_I
383  for q2= 1:Q_L_E
384  M_IE{q2+(q1-1)*Q_L_E} = RB_L_I{q1} * L_E_RB{q2};
385  end
386  end
387 
388  for q1=1:Q_L_I
389  for q2=1:Q_b
390  M_Ib{q2+(q1-1)*Q_b} = RB_L_I{q1} * b{q2};
391  end;
392  end
393 
394 
395  if model.compute_derivative_info
396 
397  if ~isfield(detailed_data,'RB_der')
398  error('No derivative bases in detailed_data')
399  end
400 
401 % %Projection on which bases is actually needed?
402 % if isfield(model,'compute_derivative_indices')
403 % indx_mu_i = find(model.compute_derivative_indices); %indexes i of \mu_i for which derivative information is needed
404 % else
405 % indx_mu_i = 1:length(get_mu(model));
406 % end
407 % nr_indx_mu_i= length(indx_mu_i);
408 % RB_der=detailed_data.RB_der(indx_mu_i);
409 
410  RB_der=detailed_data.RB_der;
411  nr_indx_mu_i = length(RB_der);
412 
413  %initialize cells
414  L_E_dd = cell(nr_indx_mu_i,1);
415  L_I_dd = cell(nr_indx_mu_i,1);
416  dL_E_sd = cell(nr_indx_mu_i,1);
417  dL_I_sd = cell(nr_indx_mu_i,1);
418  db = cell(nr_indx_mu_i,1);
419  K_E = cell(nr_indx_mu_i,1);
420  K_I = cell(nr_indx_mu_i,1);
421  K_EE = cell(nr_indx_mu_i,1);
422  %K_Eb = cell(nr_indx_mu,1);
423  %K_bb = cell(nr_indx_mu,1);
424  K_II = cell(nr_indx_mu_i,1);
425  %K_Ib = cell(nr_indx_mu,1);
426  K_IE = cell(nr_indx_mu_i,1);
427  K_EdEd = cell(nr_indx_mu_i,1);
428  K_IdId = cell(nr_indx_mu_i,1);
429  K_bdbd = cell(nr_indx_mu_i,1);
430  K_Ed = cell(nr_indx_mu_i,1);
431  K_Id = cell(nr_indx_mu_i,1);
432  K_bd = cell(nr_indx_mu_i,1);
433  K_IEd = cell(nr_indx_mu_i,1);
434  K_IId = cell(nr_indx_mu_i,1);
435  K_Ibd = cell(nr_indx_mu_i,1);
436  K_EEd = cell(nr_indx_mu_i,1);
437  K_EId = cell(nr_indx_mu_i,1);
438  K_Ebd = cell(nr_indx_mu_i,1);
439  K_EdId = cell(nr_indx_mu_i,1);
440  K_Edbd = cell(nr_indx_mu_i,1);
441  K_Idbd = cell(nr_indx_mu_i,1);
442 
443 
444 
445 
446  for i=1:length(RB_der)
447 
448  NRB = size(RB_der{i},2);
449  %make Galerkin projection for every reduced basis
450 
451  % dL_E_dd : components
452  L_E_dd{i} = cell(Q_L_E,1);
453  L_E_dd{i}(:) = {zeros(NRB,NRB)};
454  for q = 1:Q_L_E;
455  L_E_dd{i}{q} = RB_der{i}' * A * L_E{q} * RB_der{i};
456  end;
457 
458  % dL_I_dd : components
459  L_I_dd{i} = cell(Q_L_I,1);
460  if ~isempty(L_I)
461  L_I_dd{i}(:) = {zeros(NRB,NRB)};
462  for q = 1:Q_L_I;
463  L_I_dd{i}{q} = RB_der{i}' * A * L_I{q} * RB_der{i};
464  end;
465  end
466 
467  % dL_E_sd : components
468  dL_E_sd{i} = cell(Q_L_E,1);
469  dL_E_sd{i}(:) = {zeros(NRB,Nmax)};
470  for q = 1:Q_L_E;
471  dL_E_sd{i}{q} = RB_der{i}' * A * L_E{q} * detailed_data.RB;
472  end;
473 
474  % dL_I_sd : components
475  dL_I_sd{i} = cell(Q_L_I,1);
476  if ~isempty(L_I)
477  dL_I_sd{i}(:) = {zeros(NRB,Nmax)};
478  for q = 1:Q_L_I;
479  dL_I_sd{i}{q} = RB_der{i}' * A * L_I{q} * detailed_data.RB;
480  end;
481  end
482 
483  % db : vectors
484  db{i} = cell(Q_b,1);
485  db{i}(:) = {zeros(NRB,1)};
486  for q = 1:Q_b;
487  db{i}{q} = RB_der{i}' * A * b{q};
488  end;
489 
490 
491 
492  % K_E
493  K_E{i} = cell(Q_L_E,1);
494  K_E{i}(:) = {zeros(NRB,NRB)};
495  for q=1:Q_L_E
496  K_E{i}{q} = (RB_der{i}'*L_E{q}'*A)*RB_der{i};
497  end
498 
499  % K_b
500  %K_b{i} = cell(Q_b,1);
501  %K_b(:) = {zeros(1,NRB)};
502  %for q=1:Q_b
503  % K_b{i}{q} = b{q}'*A*RB_der{i}
504  %end
505 
506  % K_I
507  K_I{i} = cell(Q_L_I,1);
508  K_I{i}(:) = {zeros(NRB,NRB)};
509  for q=1:Q_L_I
510  K_I{i}{q} = (RB_der{i}'*L_I{q}'*A)*RB_der{i};
511  end
512 
513  % K_EE
514  K_EE{i} = cell(Q_L_E*Q_L_E,1);
515  K_EE{i}(:) = {zeros(NRB,NRB)};
516  for q1=1:Q_L_E
517  for q2= 1:Q_L_E
518  K_EE{i}{q2+(q1-1)*Q_L_E} = (RB_der{i}'*L_E{q1}'*A)*(L_E{q2}*RB_der{i});
519  end
520  end
521 
522  %K_II
523  K_II{i} = cell(Q_L_I*Q_L_I,1);
524  K_II{i}(:) = {zeros(NRB,NRB)};
525  for q1=1:Q_L_I
526  for q2= 1:Q_L_I
527  K_II{i}{q2+(q1-1)*Q_L_I} = (RB_der{i}' *L_I{q1}'*A)*(L_I{q2}*RB_der{i});
528  end
529  end
530 
531  % K_IE
532  K_IE{i} = cell(Q_L_I*Q_L_E,1);
533  K_IE{i}(:) = {zeros(NRB,NRB)};
534  for q1=1:Q_L_I
535  for q2= 1:Q_L_E
536  K_IE{i}{q2+(q1-1)*Q_L_E} = (RB_der{i}'*L_I{q1}'* A) * (L_E{q2} * RB_der{i});
537  end
538  end
539 
540  %erster buchstabe---aeussere schleife
541  %K_EdEd
542  K_EdEd{i} = cell(Q_L_E*Q_L_E,1);
543  K_EdEd{i}(:) = {zeros(Nmax,Nmax)};
544  for q1=1:Q_L_E
545  for q2=1:Q_L_E
546  K_EdEd{i}{q2+(q1-1)*Q_L_E} = (detailed_data.RB'*L_E{q1}'*A)*(L_E{q2}*detailed_data.RB);
547  end
548  end
549 
550  % K_IdId
551  K_IdId{i} = cell(Q_L_I*Q_L_I,1);
552  K_IdId{i}(:) = {zeros(Nmax,Nmax)};
553  for q1=1:Q_L_I
554  for q2=1:Q_L_I
555  K_IdId{i}{q2+(q1-1)*Q_L_I} = (detailed_data.RB'*L_I{q1}'*A)*(L_I{q2}*detailed_data.RB);
556  end
557  end
558 
559  %K_bdbd
560  K_bdbd{i} = cell(Q_b*Q_b,1);
561  K_bdbd{i} = {0};
562  for q1 = 1:Q_b
563  for q2 = 1:Q_b
564  K_bdbd{i}{q2+(q1-1)*Q_b} = b{q1}'*A*b{q2};
565  end
566  end
567 
568  % K_Ed
569  K_Ed{i} = cell(Q_L_E,1);
570  K_Ed{i}(:) = {zeros(NRB,Nmax)};
571  for q = 1:Q_L_E
572  K_Ed{i}{q} = (detailed_data.RB'*L_E{q}'*A)*(RB_der{i});
573  end
574 
575  %K_Id
576  K_Id{i} = cell(Q_L_I,1);
577  K_Id{i}(:) = {zeros(NRB,Nmax)};
578  for q = 1:Q_L_I
579  K_Id{i}{q} = RB_der{i}'*A*L_I{q}*detailed_data.RB;
580  end
581 
582  %K_bd
583  K_bd{i} = cell(Q_b,1);
584  K_bd{i}(:) = {zeros(1,NRB)};
585  for q= 1:Q_b
586  K_bd{i}{q} = b{q}'*A*RB_der{i};
587  end
588 
589  %K_IEd
590  K_IEd{i} = cell(Q_L_I * Q_L_E,1);
591  K_IEd{i}(:) = {zeros(NRB,Nmax)};
592  for q1=1:Q_L_I
593  for q2=1:Q_L_E
594  K_IEd{i}{q2+(q1-1)*Q_L_E} = (RB_der{i}' * L_I{q1}'*A)*(L_E{q2}*detailed_data.RB);
595  end
596  end
597 
598  %K_IId
599  K_IId{i} = cell(Q_L_I*Q_L_I,1);
600  K_IId{i}(:) = {zeros(NRB,Nmax)};
601  for q1=1:Q_L_I
602  for q2=1:Q_L_I
603  K_IId{i}{q2+(q1-1)*Q_L_I} = (RB_der{i}' * L_I{q1}'*A)*(L_I{q2}*detailed_data.RB);
604  end
605  end
606 
607  %K_Ibd
608  K_Ibd{i} = cell(Q_L_I*Q_b,1);
609  K_Ibd{i}(:) = {zeros(NRB,1)};
610  for q1 = 1:Q_L_I
611  for q2 = 1: Q_b
612  K_Ibd{i}{q2+(q1-1)*Q_b} = (RB_der{i}'*L_I{q1}') * A * b{q2};
613  end
614  end
615 
616  %K_EEd
617  K_EEd{i} = cell(Q_L_E*Q_L_E,1);
618  K_EEd{i}(:) = {zeros(NRB,Nmax)};
619  for q1=1:Q_L_E
620  for q2=1:Q_L_E
621  K_EEd{i}{q2+(q1-1)*Q_L_E} = (RB_der{i}' * L_E{q1}'*A)*(L_E{q2}*detailed_data.RB);
622  end
623  end
624 
625  %K_EId
626  K_EId{i} = cell(Q_L_E*Q_L_I,1);
627  K_EId{i}(:) = {zeros(NRB,Nmax)};
628  for q1=1:Q_L_E
629  for q2=1:Q_L_I
630  K_EId{i}{q2+(q1-1)*Q_L_I} = (RB_der{i}' * L_E{q1}'*A)*(L_I{q2}*detailed_data.RB);
631  end
632  end
633 
634  %K_Ebd
635  K_Ebd{i} = cell(Q_L_E*Q_b,1);
636  K_Ebd{i}(:) = {zeros(NRB,1)};
637  for q1 = 1:Q_L_E
638  for q2 = 1:Q_b
639  K_Ebd{i}{q2+(q1-1)*Q_b} = RB_der{i}' * L_E{q1}' * A * b{q2};
640  end
641  end
642 
643  %K_EdId
644  K_EdId{i} = cell(Q_L_E*Q_L_I,1);
645  K_EdId{i}(:) = {zeros(Nmax,Nmax)};
646  for q1 = 1:Q_L_E
647  for q2 = 1:Q_L_I
648  K_EdId{i}{q2+(q1-1)*Q_L_I} = (detailed_data.RB'*L_E{q1}' * A) * (L_I{q2}'* detailed_data.RB);
649  end
650  end
651 
652  %K_Edbd
653  K_Edbd{i} = cell(Q_L_E*Q_b,1);
654  K_Edbd{i}(:) = {zeros(Nmax,1)};
655  for q1 = 1:Q_L_E
656  for q2 = 1:Q_b
657  K_Edbd{i}{q2+(q1-1)*Q_b} = detailed_data.RB'*L_E{q1}'*A*b{q2};
658  end
659  end
660 
661  %K_Idbd
662  K_Idbd{i} = cell(Q_L_I*Q_b,1);
663  K_Idbd{i}(:) = {zeros(Nmax,1)};
664  for q1 = 1:Q_L_I
665  for q2 = 1:Q_b
666  K_Idbd{i}{q2+(q1-1)*Q_b} = detailed_data.RB'*L_I{q1}'*A*b{q2};
667  end
668  end
669 
670  end %for over all RB_der
671 
672 
673  varargout(1) = {L_E_dd};
674  varargout(2) = {L_I_dd};
675  varargout(3) = {dL_E_sd};
676  varargout(4) = {dL_I_sd};
677  varargout(5) = {db};
678  varargout(6) = {K_E};
679  varargout(7) = {K_I};
680  varargout(8) = {K_EE};
681  varargout(9) = {K_II};
682  varargout(10) = {K_IE};
683  varargout(11) = {K_EdEd};
684  varargout(12) = {K_IdId};
685  varargout(13) = {K_bdbd};
686  varargout(14) = {K_Ed};
687  varargout(15) = {K_Id};
688  varargout(16) = {K_bd};
689  varargout(17) = {K_IEd};
690  varargout(18) = {K_IId};
691  varargout(19) = {K_Ibd};
692  varargout(20) = {K_EEd};
693  varargout(21) = {K_EId};
694  varargout(22) = {K_Ebd};
695  varargout(23) = {K_EdId};
696  varargout(24) = {K_Edbd};
697  varargout(25) = {K_Idbd};
698 
699 
700 % varargout( 1) = {M_EE}; % M_EdEd
701 % varargout( 2) = {M_II}; % M_IdId
702 % varargout( 3) = {M_bb}; % M_bdbd
703 % varargout( 4) = {M_E} ; % M_Ed
704 % varargout( 5) = {M_I} ; % M_Id
705 % varargout( 6) = {M_b} ; % M_bd
706 % varargout( 7) = {M_IE}; % M_IEd
707 % varargout( 8) = {M_II}; % M_IId
708 % varargout( 9) = {M_Ib}; % M_Ibd
709 % varargout(10) = {M_EE}; % M_EEd
710 % varargout(11) = {M_IE'}; % M_EId
711 % varargout(12) = {M_Eb}; % M_Ebd
712 % varargout(13) = {M_IE'}; % M_EdId
713 % varargout(14) = {M_Eb}; % M_Edbd
714 % varargout(15) = {M_Ib}; % M_Idbd
715  end
716 
717 
718 
719 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
720 %%% decomp_mode 2
721 %%% calculation of coefficients
722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
723 else % decomp_mode== 2 -> coefficients
724  [L_I, L_E, b] = model.operators_ptr(model,[]);
725  [sLi,sLe,sb] = model.rb_derivative_operators_coefficients_ptr(model); %gives coefficients to all the parameters in the model!
726 
727  Q_L_I = length(L_I(:));
728  Q_L_E = length(L_E(:));
729  Q_b = length(b(:));
730 
731  % rb-operator coefficients can simply be forwarded
732  LL_E = L_E;
733  LL_I = L_I;
734  bb = b;
735 
736 
737  % rb error operators -coefficients
738  M_E = L_E;
739  M_b = b;
740  M_I = L_I;
741  M_EE = repmatrows(L_E(:),Q_L_E) .* repmat(L_E(:),Q_L_E,1);
742  M_Eb = repmatrows(L_E, Q_b) .* repmat(b,Q_L_E,1);
743  M_bb = repmatrows(b, Q_b) .* repmat(b,Q_b,1);
744  M_II = repmatrows(L_I(:),Q_L_I) .* repmat(L_I(:),Q_L_I,1);
745  M_Ib = repmatrows(L_I, Q_b) .* repmat(b,Q_L_I,1);
746  M_IE = repmatrows(L_I(:),Q_L_E) .* repmat(L_E(:),Q_L_I,1);
747 
748  % computation of derivative coefficients
749  if model.compute_derivative_info
750 %
751 % if isfield(model.optimization,'params_to_optimize')
752 % indx_mu_i = find(model.optimization.params_to_optimize); %indexes i of \mu_i for which derivative information is needed
753 % else
754 % indx_mu_i = length(get_mu(model));
755 % end
756 % nr_indx_mu_i= length(indx_mu_i); %nr of parameters to be optimized
757 
758 % if isfield(model,'compute_derivative_indices')
759 % nr_indx_mu_i = length(model.compute_derivative_indices);
760 % else
761 % nr_indx_mu_i = length(get_mu(model));
762 % end
763 
764  nr_indx_mu_i=length(get_mu(model));
765  %obsolete: use only those coefficients of parameters which are to be optimimzed
766  %sLe = sLe';%sLe(indx_mu_i,:)';
767  %sb = sb';%(indx_mu_i,:)';
768  % in case of no implicit operator (e.g. sLi=[]) repmat does not work!
769  if ~isempty(sLi)
770  %sLi = sLi(indx_mu_i,:)';
771  else
772  sLi=repmat(repmatrows(L_I(:),Q_L_I),1,nr_indx_mu_i); %sLi ist a 0xn empty matrix, not only a 0x1 empty matrix
773  end
774 
775  varargout(1) = {L_E};
776  varargout(2) = {L_I};
777  varargout(3) = {sLe'};
778  varargout(4) = {sLi'};
779  varargout(5) = {sb'};
780 
781  %error matrices
782  varargout(6)= {L_E}; %K_E
783  %varargout(7) = b;%K_b
784  varargout(7) = {L_I}; %K_I
785  varargout(8) = {repmatrows(L_E(:),Q_L_E) .* repmat(L_E(:),Q_L_E,1)}; %K_EE
786  %varargout(9) = repmatrows(L_E, Q_b) .* repmat(b,Q_L_E,1); %K_Eb
787  %varargout(10) = repmatrows(b, Q_b) .* repmat(b,Q_b,1); %K_bb
788  varargout(9) = {repmatrows(L_I(:),Q_L_I) .* repmat(L_I(:),Q_L_I,1)}; %K_II
789  %varargout(12) = repmatrows(L_I, Q_b) .* repmat(b,Q_L_I,1); %K_Ib
790  varargout(10) = {repmatrows(L_I(:),Q_L_E) .* repmat(L_E(:),Q_L_I,1)}; %K_IE
791  varargout(11) = {repmatrows(sLe',Q_L_E) .* repmat(sLe',Q_L_E,1)}; % K_EdEd
792  varargout(12) = {repmatrows(sLi',Q_L_I) .* repmat(sLi',Q_L_I,1)}; % K_IdId
793  varargout(13) = {repmatrows(sb',Q_b) .* repmat(sb',Q_b,1)}; % K_bdbd
794  varargout(14) = {sLe'}; % K_Ed
795  varargout(15) = {sLi'}; % K_Id
796  varargout(16) = {sb'}; % K_bd
797  varargout(17) = {repmat(repmatrows(L_I(:),Q_L_E),1,nr_indx_mu_i) .* repmat(sLe',Q_L_I,1)}; % K_IEd
798  varargout(18) = {repmat(repmatrows(L_I(:),Q_L_I),1,nr_indx_mu_i) .* repmat(sLi',Q_L_I,1)}; % K_IId
799  varargout(19) = {repmat(repmatrows(L_I(:),Q_b ),1,nr_indx_mu_i) .* repmat(sb',Q_L_I,1)}; % K_Ibd
800  varargout(20) = {repmat(repmatrows(L_E(:),Q_L_E),1,nr_indx_mu_i) .* repmat(sLe',Q_L_E,1)}; % K_EEd
801  varargout(21) = {repmat(repmatrows(L_E(:),Q_L_I),1,nr_indx_mu_i) .* repmat(sLi',Q_L_E,1)}; % K_EId
802  varargout(22) = {repmat(repmatrows(L_E(:),Q_b ),1,nr_indx_mu_i) .* repmat(sb',Q_L_E,1)}; % K_Ebd
803  varargout(23) = {repmatrows(sLe',Q_L_I) .* repmat(sLi',Q_L_E,1)}; % K_EdId
804  varargout(24) = {repmatrows(sLe',Q_b) .* repmat(sb',Q_L_E,1)}; % K_Edbd
805  varargout(25) = {repmatrows(sLi',Q_b) .* repmat(sb',Q_L_I,1)}; % K_Idbd
806 
807  end %if model.compute_derivative_info
808 
809 end
function [ opt_data , model ] = optimize(model, model_data, detailed_data, reduced_data)
opt_data = optimize(model, model_data, detailed_data, reduced_data)
Definition: optimize.m:17