rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
lin_evol_rb_derivative_simulation_t_part.m
1 function simulation_data = lin_evol_rb_derivative_simulation_t_part(model, reduced_data)
2 %function simulation_data = lin_evol_rb_derivative_simulation(model, reduced_data)
3 %
4 %performs in parallel a reduced simulation and calculation of the
5 %derivative @f$\partial_{\mu_i}u@f$
6 %
7 % This function is an extension of the \\c lin_evol_rb_simulation function.
8 % Except that in this method the time step is not included in the
9 % operators, but the time integration is conducted here by an explicit Euler.
10 % In parallel to the reduced basis online simulation a calculation of the
11 % derivative @f$\partial_{\mu_i}u@f$.
12 %
13 % It is assumed that the right mu is already set in the model.
14 % (setmu(model,mu))
15 %
16 % The calculation of the derivative is made in parallel by solving in each
17 % time step the ODE @f$\partial_t \partial_{\mu_i} a + L_E \partial_{\mu_i}
18 % a + \sum \partial_{\mu_i}(\Theta^q(\mu))L^q a -\partial_{mu_i} b(x,t,\mu) =
19 % 0@f$ plus derivative of the initial conditions.
20 % All information calculating the derivative is already contained in
21 % reduced_data or is already calculated for the normal rb_simulation except
22 % @f$\partial_{\mu_i}\Theta(\mu)@f$ and @f$\partial_{\mu_i}\Theta_b @f$
23 % which are obtained calling the field \\c model.rb_derivative_operators.
24 % The field \\c model.rb_derivative_init_values points to a method
25 % providing derivative initial values.
26 %
27 % allowed dependency of data: Nmax, N, M, mu
28 % not allowed dependency of data: H
29 % allowed dependency of computation: Nmax, N, M, mu
30 % not allowed dependency of computation: H
31 %
32 % Required fields of model
33 % mu_names : the cell array of names of mu-components and
34 % for each of these stringt, a corresponding
35 % field in model is expected.
36 % T : end-time of simulation
37 % nt : number of timesteps to compute
38 % error_norm : 'l2' or 'energy'
39 % L_I_inv_norm_bound: upper bound on implicit operator inverse norm
40 % constant in time, a single scalar
41 % L_E_norm_bound: upper bounds on explicit operator
42 % constant in time, a single scalar
43 % L_E_der_norm_bound: upper bound on explicit derivative operator
44 % constant in time, a single scalar
45 % L_I_der_norm_bound: upper bound on implicit derivative operator
46 % constant in time, a single scalar
47 % energy_norm_gamma: gamma >= 0 defining the weight in the energy norm
48 % coercivity_bound_name : name of the function, which can
49 % computes a lower bound on the coercivity, e.g.
50 % fv_coercivity_bound
51 % compute_derivative_info: 0 if no derivative information is needed
52 % 1 if derivative information is needed
53 % starting_tim_step: in t-partition case this is the starting time step
54 % for the actual t-partitioni time step
55 % stopping_time_step: in t-partition this is the stopping time step for
56 % the actual t-partition
57 %
58 %
59 % plus fields required by coercivity_bound_name.m
60 %
61 % optional fields of model:
62 % data_const_in_time : if this flag is set, then only operators
63 % for first time instance are computed
64 % name_output_functional: if this field is existent, then an
65 % output estimation is performed and error.estimtations
66 %
67 % generated fields of simulation_data:
68 % a: time sequence of solution coefficients, columns are
69 % 'a(:,k)' = `a^(k-1)`
70 % c: matrix(3-dimensional) of time secquence representing the derivative of a for
71 % @f$\mu_i@f$
72 % Delta:time sequence of `L^2`-posteriori error estimates
73 % 'Delta(k)' = `\Delta^{k-1}_N`
74 % or energy-norm-posterior error estimates
75 % 'Delta_energy(k)' = `\bar \Delta^{k-1}_N`
76 % depending on the field "error_norm" in model.
77 %
78 % if model.name_output_functional is set, then additionally, a
79 % sequence of output estimates 's(U(:,))' and error bound Delta_s is returned
80 %
81 % see the ***_gen_reduced_data() routine for specifications of the
82 % fields of reduced_data
83 
84 % Markus Dihlmann 01.06.2010, Oliver Zeeb 14.10.2010
85 
86 if model.verbose >= 10
87  if model.compute_derivative_info
88  printf('performing simulation and derivative calculation for mu = %s', mat2str(get_mu(model)));
89  else
90  printf('performing simulation');
91  end
92 end;
93 
94 if (~isequal(model.error_norm,'l2')) && ...
95  (~isequal(model.error_norm,'energy'))
96  error('error_norm unknown!!');
97 end;
98 
99 %t_part_preparation
100 if ~isfield(model,'transition_model')
101  model.transition_model = 0;
102 end
103 
104 if isfield(model,'starting_time_step')
105  t_ind_start = model.starting_time_step;
106 else
107  t_ind_start = 0;
108 end
109 
110 if isfield(model, 'stopping_time_step')
111  t_ind_stop = model.stopping_time_step;
112 else
113  t_ind_stop = model.nt;
114 end
115 if ~model.transition_model
116  nRB = length(reduced_data.a0{1});
117 else
118  nRB = size(reduced_data.LL_E{1},2);
119 end
120 
121 
122 %needed for derivative information
123 if ~isfield(model,'optimization')
124  disp('Model has no field optimization.')
125  model.optimization =[];
126 end
127 if isfield(model.optimization,'params_to_optimize')
128  indx_mu_i = find(model.optimization.params_to_optimize); %indexes i of \mu_i for which derivative information is needed
129 else
130  indx_mu_i = 1:length(get_mu(model));
131 end
132 nr_indx_mu_i= length(indx_mu_i); %nr of parameters to be optimized
133 
134 if isfield(model,'compute_derivative_indices')
135  indx_derivatives = find(model.compute_derivative_indices);
136 else
137  indx_derivatives = 1:length(get_mu(model));
138 end
139 
140 %cgrid = grid_geometry(params);
141 %nRB = length(reduced_data.a0{1});
142 a = zeros(nRB,t_ind_stop-t_ind_start+1); % matrix of RB-coefficients
143 Delta = zeros(1,t_ind_stop-t_ind_start+1); % vector of error estimators
144 model.dt = model.T/model.nt;
145 
146 %debug
147 res_u = zeros(1,t_ind_stop-t_ind_start+1);
148 res_u_der = zeros(nr_indx_mu_i,t_ind_stop-t_ind_start+1);
149 %end debug
150 
151 if model.compute_derivative_info
152  Delta_der = zeros(nr_indx_mu_i, t_ind_stop-t_ind_start+1); % vector of derivative error estimators
153  c = zeros(nRB, t_ind_stop-t_ind_start+1,nr_indx_mu_i); %matrix of RB-derivative-coefficients
154 end
155 
156 %initial erro in t-part simulations
157 if isfield(reduced_data,'Delta0')
158  Delta(1) = reduced_data.Delta0;
159 end
160 if isfield(reduced_data,'Delta_der0')
161  Delta_der(:,1) = reduced_data.Delta_der0;
162 end
163 
164 
165 % initial data projection and linear combination
166 model.decomp_mode = 2;
167 sa0 = rb_init_values(model,[]);
168 a0 = lincomb_sequence(reduced_data.a0,sa0);
169 a(:,1) = a0;
170 
171 
172 
173 if model.compute_derivative_info
174  sc_0 = model.rb_derivative_init_values_coefficients(model);
175  if isfield(reduced_data,'c0')
176  for i=1:size(sc_0,1)
177  c_0(:,:,i) = lincomb_sequence(reduced_data.c0{i},sc_0(i,:));
178  end
179  else
180  for i=1:size(sc_0,1)
181  c_0(:,:,i) = lincomb_sequence(reduced_data.a0,sc_0(i,:)');
182  end
183  end
184  %use only parameter derivatives for parameters which are to optimize
185  c(:,1,:)=c_0(:,:,indx_mu_i);
186 
187 end
188 
189 % create dummy files for derivative matrices --> memory preallocation
190 if model.compute_derivative_info
191 model.t=0;
192 [dummy_LL_I, dummy_LL_E, dummy_bb, dummy_M_E, dummy_M_b, dummy_M_EE, ...
193  dummy_M_Eb, dummy_M_bb, dummy_M_I, dummy_M_II, dummy_M_IE, ...
194  dummy_M_Ib, dummy_M_EdEd, dummy_M_IdId, dummy_M_bdbd, ...
195  dummy_M_Ed, dummy_M_Id, dummy_M_bd, dummy_M_IEd, dummy_M_IId, ...
196  dummy_M_Ibd, dummy_M_EEd, dummy_M_EId, dummy_M_Ebd, dummy_M_EdId,...
197  ]= rb_operators(model,[]);%dummy_M_Edbd, dummy_M_Idbd] = rb_operators(model,[]); --> dummy_M_Edbd, dummy_M_Idbd not needed
198 
199  if isempty(dummy_M_EdEd)
200  M_EdEd = zeros(1,1,nr_indx_mu_i);
201  else
202  M_EdEd = zeros(nRB,nRB,nr_indx_mu_i);
203  end
204 
205  if isempty(dummy_M_IdId)
206  M_IdId = zeros(1,1,nr_indx_mu_i);
207  else
208  M_IdId = zeros(nRB,nRB,nr_indx_mu_i);
209  end
210 
211  if isempty(dummy_M_Ed)
212  M_Ed = zeros(1,1,nr_indx_mu_i);
213  else
214  M_Ed = zeros(nRB,nRB,nr_indx_mu_i);
215  end
216 
217  if isempty(dummy_M_Id)
218  M_Id = zeros(1,1,nr_indx_mu_i);
219  else
220  M_Id = zeros(nRB,nRB,nr_indx_mu_i);
221  end
222 
223  if isempty(dummy_M_IEd)
224  M_IEd = zeros(1,1,nr_indx_mu_i);
225  else
226  M_IEd = zeros(nRB,nRB,nr_indx_mu_i);
227  end
228 
229  if isempty(dummy_M_IId)
230  M_IId = zeros(1,1,nr_indx_mu_i);
231  else
232  M_Id = zeros(nRB,nRB,nr_indx_mu_i);
233  end
234 
235  if isempty(dummy_M_EEd)
236  M_EEd = zeros(1,1,nr_indx_mu_i);
237  else
238  M_EEd = zeros(nRB,nRB,nr_indx_mu_i);
239  end
240 
241  if isempty(dummy_M_EId)
242  M_EId = zeros(1,1,nr_indx_mu_i);
243  else
244  M_EId = zeros(nRB,nRB,nr_indx_mu_i);
245  end
246 
247  if isempty(dummy_M_EdId)
248  M_EdId = zeros(1,1,nr_indx_mu_i);
249  else
250  M_EdId = zeros(nRB,nRB,nr_indx_mu_i);
251  end
252 
253  M_bdbd = zeros(1 ,1 ,nr_indx_mu_i);
254  M_bd = zeros(1 ,nRB,nr_indx_mu_i);
255  M_Ibd = zeros(nRB,1 ,nr_indx_mu_i);
256  M_Ebd = zeros(nRB,1 ,nr_indx_mu_i);
257  M_Edbd = zeros(nRB,1 ,nr_indx_mu_i);
258  M_Idbd = zeros(nRB,1 ,nr_indx_mu_i);
259 end %end "if compute_derivative_info"
260 % end of: create dummy files for derivative matrices --> memory
261 % preallocation
262 
263 
264 % loop over time steps: computation of a(t+1)==a^t
265 for t = (t_ind_start+1):t_ind_stop
266  model.t = (t-1)*model.dt;
267  if model.verbose >= 20
268  disp(['entered time-loop step ',num2str(t)]);
269  end;
270 
271  % linear combination of all quantities
272  % only once, if data is const in time
273  if (t==t_ind_start+1) || (~model.data_const_in_time)
274 % 10.11.10 original:
275 % [sLL_I, sLL_E, sbb, sM_E, sM_b, sM_EE, sM_Eb, sM_bb, sM_I, sM_II, sM_IE, sM_Ib, ...
276 % sM_EdEd, sM_IdId, sM_bdbd, sM_Ed, sM_Id, sM_bd, sM_IEd, sM_IId, sM_Ibd, sM_EEd, ...
277 % sM_EId, sM_Ebd, sM_EdId, sM_Edbd, sM_Idbd] = rb_operators(model,[]);
278  % 10.11.10 NEU:
279  if model.compute_derivative_info% NEU
280  [sLL_I, sLL_E, sbb, sM_E, sM_b, sM_EE, sM_Eb, sM_bb, sM_I, sM_II, sM_IE, sM_Ib, ...
281  sM_EdEd, sM_IdId, sM_bdbd, sM_Ed, sM_Id, sM_bd, sM_IEd, sM_IId, sM_Ibd, sM_EEd, ...
282  sM_EId, sM_Ebd, sM_EdId, sM_Edbd, sM_Idbd] = rb_operators(model,[]);
283  else
284  [sLL_I, sLL_E, sbb, sM_E, sM_b, sM_EE, sM_Eb, sM_bb, sM_I, sM_II, sM_IE, sM_Ib] ...
285  = rb_operators(model,[]);
286  end
287  % END 10.11.10 NEU:
288  LL_I = lincomb_sequence(reduced_data.LL_I,sLL_I);
289  LL_E = lincomb_sequence(reduced_data.LL_E,sLL_E);
290  bb = lincomb_sequence(reduced_data.bb,sbb);
291  M_E = lincomb_sequence(reduced_data.M_E,sM_E);
292  M_b = lincomb_sequence(reduced_data.M_b,sM_b);
293  M_EE = lincomb_sequence(reduced_data.M_EE,sM_EE);
294  M_Eb = lincomb_sequence(reduced_data.M_Eb,sM_Eb);
295  M_bb = lincomb_sequence(reduced_data.M_bb,sM_bb);
296  M_I = lincomb_sequence(reduced_data.M_I,sM_I);
297  M_II = lincomb_sequence(reduced_data.M_II,sM_II);
298  M_Ib = lincomb_sequence(reduced_data.M_Ib,sM_Ib);
299  M_IE = lincomb_sequence(reduced_data.M_IE,sM_IE);
300  if model.compute_derivative_info
301  for i=1:nr_indx_mu_i
302  M_EdEd(:,:,i) = lincomb_sequence(reduced_data.M_EdEd,sM_EdEd(:,i));
303  M_IdId(:,:,i) = lincomb_sequence(reduced_data.M_IdId,sM_IdId(:,i));
304  M_bdbd(:,:,i) = lincomb_sequence(reduced_data.M_bdbd,sM_bdbd(:,i));
305  M_Ed(:,:,i) = lincomb_sequence(reduced_data.M_Ed ,sM_Ed(:,i));
306  M_Id(:,:,i) = lincomb_sequence(reduced_data.M_Id ,sM_Id(:,i));
307  M_bd(:,:,i) = lincomb_sequence(reduced_data.M_bd ,sM_bd(:,i));
308  M_IEd(:,:,i) = lincomb_sequence(reduced_data.M_IEd ,sM_IEd(:,i));
309  M_IId(:,:,i) = lincomb_sequence(reduced_data.M_IId ,sM_IId(:,i));
310  M_Ibd(:,:,i) = lincomb_sequence(reduced_data.M_Ibd ,sM_Ibd(:,i));
311  M_EEd(:,:,i) = lincomb_sequence(reduced_data.M_EEd ,sM_EEd(:,i));
312  M_EId(:,:,i) = lincomb_sequence(reduced_data.M_EId ,sM_EId(:,i));
313  M_Ebd(:,:,i) = lincomb_sequence(reduced_data.M_Ebd ,sM_Ebd(:,i));
314  M_EdId(:,:,i) = lincomb_sequence(reduced_data.M_EdId,sM_EdId(:,i));
315  M_Edbd(:,:,i) = lincomb_sequence(reduced_data.M_Edbd,sM_Edbd(:,i));
316  M_Idbd(:,:,i) = lincomb_sequence(reduced_data.M_Idbd,sM_Idbd(:,i));
317  end
318  end
319 
320 
321  if model.data_const_in_time
322  % inverse of implicit matrix! L_I' = Id, L_E' = L_I^(-1) *
323  % L_E, bb = L_I^(-1) bb
324  LL_E = (speye(size(LL_I)) - LL_I) \ LL_E;
325  bb = (speye(size(LL_I)) - LL_I) \ bb;
326  LL_I = zeros(size(LL_I));
327  end;
328  end;
329 
330 
331  % solve (I-dt*LL_I) a(:,t+1) = (I+dt*LL_E) * a(:,t) + bb
332  rhs = (speye(size(LL_E)) + model.dt*LL_E) * a(:,t-t_ind_start) + model.dt*bb;
333 
334  % warning('this does not work for pure space operators (independent of delta t). In that case use the commented line below.');
335  %rhs = a(:,t) + model.dt * (LL_E * a(:,t) + bb);
336  % check whether pure explicit problem:
337  if isequal(LL_I, zeros(size(LL_I)))
338  a(:,t+1-t_ind_start) = rhs;
339  %debug 28.10.10: folgende zeile mit reingenommen, damit
340  %res_norm_times_dt_sqr ein skalar wird
341  M_Ib=zeros(nRB,1);
342  % end debug 28.10.10
343  else % solve linear system
344  a(:,t+1-t_ind_start) = (speye(size(LL_I)) - model.dt*LL_I)\rhs;
345  end;
346 
347 
348  % compute error estimate recursively
349  % Delta^k := |L_I^(k-1)|^-1 * (res_norm(k-1)+
350  % |L_E^(k-1)|*Delta^(k-1))
351  res_norm_times_dt_sqr = a(:,t+1-t_ind_start)'*a(:,t+1-t_ind_start) - 2*a(:,t+1-t_ind_start)' * a(:,t-t_ind_start) + a(:,t-t_ind_start)'*a(:,t-t_ind_start) ...
352  +2*model.dt*( a(:,t-t_ind_start)'*M_E*a(:,t-t_ind_start) - a(:,t-t_ind_start)'*M_E*a(:,t+1-t_ind_start) ...
353  +M_b*a(:,t-t_ind_start) - M_b*a(:,t+1-t_ind_start) ...
354  +a(:,t+1-t_ind_start)'*M_I*a(:,t-t_ind_start) - a(:,t+1-t_ind_start)'*M_I*a(:,t+1-t_ind_start)) ...
355  +((model.dt)^2)* ( a(:,t-t_ind_start)'*M_EE*a(:,t-t_ind_start) + a(:,t+1-t_ind_start)'*M_II*a(:,t+1-t_ind_start) + M_bb ...
356  +2*( a(:,t+1-t_ind_start)'*M_IE*a(:,t-t_ind_start) +a(:,t-t_ind_start)'*M_Eb + a(:,t+1-t_ind_start)'*M_Ib));
357 
358 
359  % ensure real estimators (could be complex due to numerics)
360  if res_norm_times_dt_sqr>=0
361  res_norm_times_dt = sqrt(res_norm_times_dt_sqr);
362  else
363 % keyboard;
364  disp('residual < 0')
365  res_norm_times_dt = 0;
366  end;
367 
368  %debug
369  res_u(t-t_ind_start) = res_norm_times_dt;
370  %end debug
371 
372  if isequal(model.error_norm,'l2')
373  Delta(t+1-t_ind_start) = res_norm_times_dt + model.L_E_norm_bound * Delta(t-t_ind_start);
374  else
375  % only sum up the squares of the residuals, multiplication with coeff
376  % and squareroots are taken at the end.
377  keyboard;
378  Rkplus1sqr = max(res_norm_sqr/(params.dt.^2), 0);
379  Delta(t+1-t_ind_start) = Delta(t-t_ind_start)+Rkplus1sqr;
380  end;
381 
382 
383 
384  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385  %Calculation of derivative \partial_{\mu}a
386  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387  if model.compute_derivative_info
388  model.decomp_mode=2;
389 
390  if (t==t_ind_start) || (~model.data_const_in_time)
391  [sLi,sLe,sb] = model.rb_derivative_operators_coefficients_ptr(model);
392  %sLe = -sLe;
393  %debug 28.10.10
394  if ~isempty(reduced_data.LL_I)
395  LL_I_derived=zeros(size(reduced_data.LL_I{1},1),size(reduced_data.LL_I{1},2),nr_indx_mu_i);
396  else
397  for j=1:nr_indx_mu_i
398  LL_I_derived(:,:,j);
399  end
400  end
401  %end debug 28.10.10
402  LL_E_derived=zeros(size(reduced_data.LL_E{1},1),size(reduced_data.LL_E{1},2),nr_indx_mu_i);
403  bb_derived=zeros(length(reduced_data.bb{1}),nr_indx_mu_i);
404 
405  %LL_E stays the same
406  for i=1:nr_indx_mu_i
407  if ~isempty(sLi) %only do the linear combination if the coefficients sLi are not empty
408  LL_I_derived(:,:,i) = lincomb_sequence(reduced_data.LL_I,sLi(indx_mu_i(i),:));
409  end
410  LL_E_derived(:,:,i) = lincomb_sequence(reduced_data.LL_E,sLe(indx_mu_i(i),:));
411  bb_derived(:,i) = lincomb_sequence(reduced_data.bb,sb(indx_mu_i(i),:));
412  end
413  end
414 
415  % solve d/dt c(:,:,i) = LL_E * c(:,:,i) + LL_E_derived a() +
416  % bb_derived
417  for i=1:nr_indx_mu_i
418  rhs_der = (speye(size(LL_E)) + model.dt*LL_E) * c(:,t-t_ind_start,i) + model.dt*LL_E_derived(:,:,i) * a(:,t-t_ind_start) ...
419  + model.dt*LL_I_derived(:,:,i) * a(:,t+1-t_ind_start) + model.dt*bb_derived(:,i);
420 
421  % check whether pure explicit problem:
422  if isequal(LL_I, zeros(size(LL_I)))
423  c(:,t+1-t_ind_start,i) = rhs_der;
424  else %solve linear system
425  c(:,t+1-t_ind_start,i) = (speye(size(LL_I)) - model.dt*LL_I)\rhs_der;
426  end
427 
428 
429  %compute error estrimator recuresivly
430  res_norm_der_times_dt_sqr = c(:,t+1-t_ind_start,i)'*c(:,t+1-t_ind_start,i) ...
431  + c(:,t-t_ind_start,i)'*c(:,t-t_ind_start,i) - 2*c(:,t+1-t_ind_start,i)'*c(:,t-t_ind_start,i) ...
432  + 2*model.dt*(-c(:,t+1-t_ind_start,i)'*M_I'*c(:,t+1-t_ind_start,i) - c(:,t+1-t_ind_start,i)'*M_E'*c(:,t-t_ind_start,i) ...
433  -c(:,t+1-t_ind_start,i)'*M_Ed(:,:,i)'*a(:,t-t_ind_start) - c(:,t+1-t_ind_start,i)'*M_Id(:,:,i)'*a(:,t+1-t_ind_start)...
434  -c(:,t+1-t_ind_start,i)'*M_bd(:,:,i)' + c(:,t+1-t_ind_start,i)'*M_I*c(:,t-t_ind_start,i) ...
435  +c(:,t-t_ind_start,i)'*M_E*c(:,t-t_ind_start,i) + c(:,t-t_ind_start,i)'*M_Ed(:,:,i)'*a(:,t-t_ind_start) ...
436  +c(:,t-t_ind_start,i)'*M_Id(:,:,i)*a(:,t+1-t_ind_start) + c(:,t-t_ind_start,i)'*M_bd(:,:,i)' ) ... %13.10.10: bei M_bd aufpassen, nur ein Doppelpunkt?!
437  + ((model.dt)^2) * (c(:,t+1-t_ind_start,i)'*M_II*c(:,t+1-t_ind_start,i) + c(:,t-t_ind_start,i)'*M_EE*c(:,t-t_ind_start,i) ...
438  + a(:,t-t_ind_start)'*M_EdEd(:,:,i)*a(:,t-t_ind_start) + a(:,t+1-t_ind_start)'*M_IdId(:,:,i)*a(:,t+1-t_ind_start)...
439  + M_bdbd(:,:,i) + 2*c(:,t+1-t_ind_start,i)'*M_IE*c(:,t-t_ind_start,i) ...
440  + 2*c(:,t+1-t_ind_start,i)'*M_IEd(:,:,i)*a(:,t-t_ind_start) + 2*c(:,t+1-t_ind_start,i)'*M_IId(:,:,i)*a(:,t+1-t_ind_start)...
441  + 2*c(:,t+1-t_ind_start,i)'*M_Ibd(:,:,i) + 2*c(:,t-t_ind_start,i)'*M_EEd(:,:,i)*a(:,t-t_ind_start) ...
442  + 2*c(:,t-t_ind_start,i)'*M_EId(:,:,i)*a(:,t+1-t_ind_start) + 2*c(:,t-t_ind_start,i)'*M_Ebd(:,:,i) ...
443  + 2*a(:,t-t_ind_start)'*M_EdId(:,:,i)*a(:,t+1-t_ind_start) + 2*a(:,t-t_ind_start)'*M_Edbd(:,:,i)...
444  + 2*a(:,t+1-t_ind_start)'*M_Idbd(:,:,i) );
445 
446  % ensure real estimators (could be complex due to numerics)
447  if res_norm_der_times_dt_sqr>=0
448  res_norm_der_times_dt = sqrt(res_norm_der_times_dt_sqr);
449  else
450  res_norm_der_times_dt = 0;
451  end;
452 
453  %debug
454  res_u_der(i,t-t_ind_start) = res_norm_der_times_dt;
455  %end debug
456 
457  if isequal(model.error_norm,'l2')
458  if model.time_const
459  t_old = model.t;
460  model.t=0;
461  end
462  Delta_der(i,t+1-t_ind_start) = model.L_E_norm_bound*Delta_der(i,t-t_ind_start) + model.L_E_der_norm_bound(model,indx_derivatives(i))*Delta(t-t_ind_start) ...
463  + model.L_I_der_norm_bound(model,indx_derivatives(i))*Delta(t+1-t_ind_start) + res_norm_der_times_dt ;
464  if model.time_const
465  model.t = t_old;
466  end
467  end
468 
469 
470  end %for i=1:nr_indx_mu
471  end %if model.compute_derivative_info
472 end;
473 
474 if isequal(model.error_norm,'energy')
475  % now perform scaling and squareroot of energy-error-estimate:
476  alpha = model.coercivity_bound_ptr(model);
477  if max(model.L_E_norm_bound>1) || (alpha == 0)
478  % no reasonable estimation possible
479  Delta(:) = nan;
480  else
481  C = (sqrt(1-model.L_E_norm_bound.^2)+1) * 0.5;
482  Coeff = model.dt /(4*alpha*C*(1-model.energy_norm_gamma * C));
483  Delta = sqrt(Delta * Coeff);
484  end;
485 end;
486 
487 % return simulation result
488 simulation_data = [];
489 simulation_data.a = a;
490 simulation_data.Delta = Delta;
491 simulation_data.LL_I = LL_I;
492 simulation_data.LL_E = LL_E;
493 simulation_data.bb = bb;
494 simulation_data.nRB = nRB;
495 
496 %debug
497 simulation_data.res_u = res_u;
498 simulation_data.res_u_der = res_u_der;
499 %end debug
500 
501 if model.compute_derivative_info
502  simulation_data.Delta_der = Delta_der;
503  simulation_data.c = c;
504 end
505 
506 
507 %output calculation
508 if isfield(model,'name_output_functional')
509  if isequal(model.error_norm,'l2')
510  simulation_data = model.get_output(model, simulation_data,reduced_data);
511 % s = reduced_data.s_RB'*a;
512 % if isfield(model,'s_l2norm')
513 % Delta_s = model.s_l2norm * Delta; %war ursprünglich in reduced_data.s_l2norm
514 % simulation_data.Delta_s = Delta_s;
515 % else
516 % if (model.verbose >=10)
517 % disp('warning: no L2_norm for output defined in lin_evol_rb_simulation...')
518 % end
519 % end
520 % simulation_data.s = s;
521 %
522 % if model.compute_derivative_info
523 % %derivative output and error estimation of gradient
524 % %sum=0;%for l2-norm
525 % for i=1:size(c,3)
526 % s_der{i} = reduced_data.s_RB'*c(:,:,i);
527 % %sum = sum + max(Delta_der(i,:))^2;
528 % end
529 % simulation_data.s_der = s_der;
530 % simulation_data.Delta_s_grad = model.s_l2norm .*max(Delta_der,[],2); %Gradient error bound
531 % %simulation_data.Delta_s_der = model.s_l2norm * Delta_der;
532 % end
533 
534  else
535  error(['output estimation not implemented concerning energy-norm.' ...
536  ' choose l2 as error_norm!']);
537  end;
538 end;
539 
540 %| \docupdate
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
Definition: verbose.m:17
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