rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
advection_fv_output_mcmds.m
Go to the documentation of this file.
1 function advection_fv_output_mcmds(step)
2 % small script implementing a simple advection example
3 % for producing matrices to be used in the RB-DS framework
4 % Discretization with FV Functions. Used for the mcmds lin-ds paper.
5 %
6 % mu_names = {'cone_weight','vx_weight','vy_weight'};
7 % mu_ranges = [0,1]^3
8 %
9 % possible steps:
10 %
11 % step = 1; % initialization of model and plot of model data
12 % step = 2; % detailed simulation of lin_evol
13 % step = 2.5; % conversion to DS primal model, lin_ds detailed simulation
14 % step = 3; % conversion to DS primal model, DS detailed simulation
15 % and comparison with lin_evol
16 % step = 4 % compute several trajectories.
17 % step = 4.5 % compute reduced basis based on 2 trajecories.
18 % step = 4.75 % comparison of detailed and reduced simulation
19 % step = 5 % figures of detailed simulations based on step 4
20 % step = 6 % figures of reduced simulations based on step 4
21 % step = 7 % time measurements based on step 4
22 % step = 8; % compare original and accelerated ds_model
23 % step = 9; % generate greedy basis on subset of parameter domain
24 % step = 10; % reduced simulations and error plots
25 % step = 11; % test of matlab ode solver for resulting sparse system
26 % step = 12; % further plots for MCMDS paper
27 
28 % Bernard Haasdonk 25.8.2009
29 
30 % cartesian grid
31 
32 if nargin < 1
33  step = 1;
34 end;
35 
36 params = [];
37 model = [];
38 %params.coarse_factor = 2; % fact 2 => ndofs = 16384, nt = 1024, 15s detailed
39 %params.coarse_factor = 1; % fact 1 => ndofs = 32768, nt = 2048, 60s detailed
40 params.coarse_factor = 1;
41 %verbose(1);
42 
43 switch step
44 
45  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46  %step = 1; % initialization of model and plot of model data
47  case 1
48  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 
50 % verbose(1,'initializaton of lin_evol_model and plot model_data');
51  disp('initializaton of lin_evol_model and plot model_data');
52  model = advection_fv_output_model(params);
53  model_data = gen_model_data(model);
54  params.axis_equal = 1;
55  params.axis_tight = 1;
56  plot(model_data.grid,params);
57  % inspect(model_data.grid)
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59  %step = 2; % detailed simulation of lin_evol
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61  case 2
62 % verbose(1,'detailed simulation of lin_evol_model and plot');
63  disp('detailed simulation of lin_evol_model and plot');
64  model = advection_fv_output_model(params);
65  model_data = gen_model_data(model);
66  % model.debug = 1;
67  % disp('model debugging turned on.')
68  model.cone_weight = 0.0;
69  model.vx_weight = 0.0;
70  model.vy_weight = 0.0;
71  model.vx_weight = 1;
72  model.vy_weight = 1;
73  model.cone_weight = 1.0;
74 % model.vx_weight = 1;
75 % model.vy_weight = 0;
76  sim_data = detailed_simulation(model,model_data);
77  plot_sim_data(model,model_data,sim_data,[]);
78 
79 
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 %step = 2.5; % conversion to DS primal model, DS detailed simulation
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83  case 2.5
84  disp('initialization of lin_ds model from lin_evol model');
85  % verbose(1,'initialization of lin_ds model from lin_evol model and ...
86  % plot');
87 
88  lin_evol_model = advection_fv_output_model(params);
89  %lin_evol_model.debug = 1;
90  lin_evol_model_data = gen_model_data(lin_evol_model);
91 
92  % set some additional fields in model which will be copied into
93  % ds model depending on whether constants are known or not:
94  estimate_constants = 0;
95  if estimate_constants
96  %%% if constant estimaton has to be performed:
97  lin_evol_model.estimate_lin_ds_nmu = 4;
98  lin_evol_model.estimate_lin_ds_nX = 10;
99  lin_evol_model.estimate_lin_ds_nt = 4;
100  else
101  %%% otherwise:
102  % the following values are rough bounds, so could be
103  % non-rigorous, then larger search must be performed.
104  lin_evol_model.state_bound_constant_C1 = 1;
105  lin_evol_model.output_bound_constant_C2 = 1.2916;
106  end;
107 
108  ds_model = lin_ds_from_lin_evol_model(lin_evol_model);
109  %ds_model.u_function_ptr = @(params) 0.1; % define new
110 % ds_model.theta = 1;
111  ds_model.theta = 0;
112  ds_model_data = gen_model_data(ds_model);
113  mu = [0.5,1,1];
114  % set mu in model and base_model!!!
115  ds_model = ds_model.set_mu(ds_model,mu);
116 
117  ds_sim_data = detailed_simulation(ds_model,ds_model_data);
118 
119  params.no_lines = 1;
120  params.clim = [0,1];
121  params.plot_title='detailed implicit lin_ds';
122  lin_evol_from_ds_sim_data.U = ds_sim_data.X;
123  lin_evol_from_ds_sim_data.y = ds_sim_data.Y;
124  plot_sim_data(lin_evol_model,lin_evol_model_data,lin_evol_from_ds_sim_data,params);
125 
126  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 %step = 3; % conversion to DS primal model, DS detailed simulation
128  % and comparison with lin_evol
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 
131  case 3 % initialization of DS model and lin_ds detailed simulation
132  disp('initialization of lin_ds model from lin_evol model and plot');
133 % verbose(1,'initialization of lin_ds model from lin_evol model and ...
134 % plot');
135 
136  lin_evol_model = advection_fv_output_model(params);
137  %lin_evol_model.debug = 1;
138  lin_evol_model_data = gen_model_data(lin_evol_model);
139 
140  % set some additional fields in model which will be copied into
141  % ds model depending on whether constants are known or not:
142  estimate_constants = 0;
143  if estimate_constants
144  %%% if constant estimaton has to be performed:
145  lin_evol_model.estimate_lin_ds_nmu = 4;
146  lin_evol_model.estimate_lin_ds_nX = 10;
147  lin_evol_model.estimate_lin_ds_nt = 4;
148  else
149  %%% otherwise:
150  % the following values are rough bounds, so could be
151  % non-rigorous, then larger search must be performed.
152  lin_evol_model.state_bound_constant_C1 = 1;
153  lin_evol_model.output_bound_constant_C2 = 1.2916;
154  end;
155 
156  ds_model = lin_ds_from_lin_evol_model(lin_evol_model);
157 % ds_model.theta = 0.0;
158  %ds_model.u_function_ptr = @(params) 0.1; % define new
159 
160  ds_model_data = gen_model_data(ds_model);
161  mu = [0.5,1,1];
162  % set mu in model and base_model!!!
163  ds_model = ds_model.set_mu(ds_model,mu);
164 
165  ds_sim_data = detailed_simulation(ds_model,ds_model_data);
166  lin_evol_model = lin_evol_model.set_mu(lin_evol_model,mu);
167  lin_evol_sim_data = detailed_simulation(lin_evol_model,...
168  lin_evol_model_data);
169  err = lin_evol_sim_data.U - ds_sim_data.X;
170  disp(['max error in DOFs of lin_evol and ds simulation: ',...
171  num2str(max(abs(err(:))))]);
172 
173  params.plot_title='detailed lin_evol';
174  params.no_lines = 1;
175  plot_sim_data(lin_evol_model,lin_evol_model_data,lin_evol_sim_data,params);
176  params.plot_title='detailed lin_ds';
177  lin_evol_from_ds_sim_data.U = ds_sim_data.X;
178  lin_evol_from_ds_sim_data.y = ds_sim_data.Y;
179  plot_sim_data(lin_evol_model,lin_evol_model_data,lin_evol_from_ds_sim_data,params);
180  params.plot_title='error explicit lin_ds and lin_evol';
181  error_sim_data = lin_evol_sim_data;
182  error_sim_data.U = error_sim_data.U-ds_sim_data.X;
183  plot_sim_data(lin_evol_model,lin_evol_model_data,error_sim_data,params);
184  keyboard;
185 
186  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187  %step = 4 % reduced Basis generation by single trajectories and
188  %comparison of detailed and reduced simulation
189  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 
191  case 4 % generate some trajectories
192 
193  ds_model = fast_model(params);
194 % lin_evol_model = advection_fv_output_model(params);
195  %lin_evol_model.debug = 1;
196 % lin_evol_model_data = gen_model_data(lin_evol_model);
197 
198  % set some additional fields in model which will be copied into
199  % ds model depending on whether constants are known or not:
200 % estimate_constants = 0;
201 % if estimate_constants
202 % %%% if constant estimaton has to be performed:
203 % lin_evol_model.estimate_lin_ds_nmu = 4;
204 % lin_evol_model.estimate_lin_ds_nX = 10;
205 % lin_evol_model.estimate_lin_ds_nt = 4;
206 % else
207 % %%% otherwise:
208 % % the following values are rough bounds, so could be
209 % % non-rigorous, then larger search must be performed.
210 % lin_evol_model.state_bound_constant_C1 = 1;
211 % lin_evol_model.output_bound_constant_C2 = 1.2916;
212 % end;
213 %
214 % ds_model = lin_ds_from_lin_evol_model(lin_evol_model);
215  %ds_model.u_function_ptr = @(params) 0.1; % define new
216  ds_model_data = gen_model_data(ds_model);
217 % mu = [1,1,0.5];
218 % mu = [0.5,0.5,0.5];
219 
220  mus = {[0,0,0],[1,1,1],[1,1,0.5],[0,0.5,1]};
221  for m = 1:length(mus)
222  disp(['computing trajectory number ',num2str(m)]);
223  mu = mus{m};
224  ds_model = ds_model.set_mu(ds_model,mu);
225  %ds_model.theta = 0;
226  %ds_model.theta = 1;
227  %disp('set theta to 1!!!');
228  tic;
229  ds_sim_data = detailed_simulation(ds_model,ds_model_data);
230  t_det = toc;
231  disp(['time for full simulation: ',num2str(t_det)]);
232  save(fullfile(rbmatlabresult,['trajectory',num2str(m)]),...
233  'ds_model','ds_model_data','ds_sim_data');
234  end;
235 
236  case 4.5 % compute reduced basis.
237  % make sure that the previous trajectories are computed!!
238 
239  disp('PCA of snapshots takes a while...');
240  load(fullfile(rbmatlabresult,'trajectory1'),...
241  'ds_model','ds_model_data','ds_sim_data');
242  epsilon = 1e-4;
243  RB1 = PCA_fixspace(ds_sim_data.X,[],ds_model_data.G,1,[], ...
244  epsilon);
245  %RB = orthonormalize_qr(ds_sim_data.X,ds_model_data.G);
246  % select correct orthogonal set
247 % K = RB' * ds_model_data.G * RB;
248 % i = find(abs(diag(K)-1)>1e-2);
249 % i = min(i);
250 % disp(['found ',num2str(size(RB,2)),' basis vectors after traj. 1']);
251 % if isempty(i)
252 % i = size(RB,2)+1;
253 % end;
254 % keyboard;
255  % select first vector only (stationary solution)
256  RB = RB1(:,1);
257  disp(['reduced to ',num2str(size(RB,2)),' basis vectors.']);
258 % keyboard;
259 
260  load(fullfile(rbmatlabresult,'trajectory2'),...
261  'ds_model','ds_model_data','ds_sim_data');
262 
263  epsilon = 1e-12;
264 % ds_sim_data.X = ds_sim_data.X-...
265 % RB*(RB'*(ds_model_data.G*ds_sim_data.X));
266  RB2 = PCA_fixspace(ds_sim_data.X,RB,ds_model_data.G,[],'gram-schmidt',epsilon);
267  %RB = orthonormalize_qr(ds_sim_data.X,ds_model_data.G);
268  % select correct orthogonal set
269  K = RB2' * ds_model_data.G * RB2;
270  i = find(abs(diag(K)-1)>1e-2);
271  i = min(i);
272  if isempty(i)
273  i = size(RB2,2)+1;
274  end;
275  disp(['found ',num2str(size(RB2,2)),' basis vectors after traj. 2']);
276  RB2 = RB2(:,1:(i-1));
277  disp(['reduced to ',num2str(size(RB2,2)),' basis vectors after traj. 2']);
278  RB = [RB, RB2];
279 % RB = orthonormalize(RB);
280  keyboard;
281 
282 % check orthonormality
283  K = RB' * ds_model_data.G * RB;
284  i = find(abs(diag(K)-1)>1e-2);
285  i = min(i);
286  if isempty(i)
287  i = size(RB,2)+1;
288  end;
289  % make consistent with preprint: 127 vectors overall
290  if i>128
291  i = 128;
292  end;
293 
294  RB = RB(:,1:(i-1));
295  disp(['reduced to ',num2str(size(RB,2)),' basis vectors overall']);
296  keyboard;
297 
298  V = RB;
299  W = ds_model_data.G * V;
300  rbfname = fullfile(rbmatlabresult,'advection_fv_output_basis');
301  save(rbfname,'RB');
302 
303  ds_model.RB_basis_filename = rbfname;
304  ds_model.RB_generation_mode = 'file_load';
305 
306  detailed_data = gen_detailed_data(ds_model,ds_model_data);
307 
308  model = ds_model;
309  save(fullfile(rbmatlabresult,'advection_fv_output_detailed_data_2traj'),...
310  'model','detailed_data')
311 
312  case 4.75 % compare reduced and detailed simulation
313 
314  load(fullfile(rbmatlabresult,'advection_fv_output_detailed_data_2traj'),...
315  'model','detailed_data')
316  load(fullfile(rbmatlabresult,'trajectory2'),...
317  'ds_sim_data');
318 
319  ds_model = model;
320 
321  %perform single reduced simulation for given parameter
322  reduced_data = gen_reduced_data(ds_model,detailed_data);
323  ds_model.N = reduced_data.N;
324  tic,
325 % ds_model.nt = ds_model.nt/4;
326 % disp('set nt to quarter!!');
327  rb_sim_data = rb_simulation(ds_model,reduced_data);
328  t_red = toc;
329  rb_sim_data = rb_reconstruction(ds_model,detailed_data,rb_sim_data)
330  disp(['time for reduced simulation: ',num2str(t_red)]);
331 
332  % plot of reduced trajectory
333  lin_evol_model = ds_model.base_model;
334  lin_evol_model_data = gen_model_data(lin_evol_model);
335 
336  params.no_lines = 1;
337  params.show_colorbar = 1;
338  params.axis_equal = 1;
339  params.plot = lin_evol_model.plot;
340  % plot single snapshot
341  %lin_evol_model.plot(rb_sim_data.X(:,1),lin_evol_model_data.grid, ...
342  % params);
343 
344  % plot sequence:
345  params.title = 'reduced solution';
346  plot_sequence(rb_sim_data.X,lin_evol_model_data.grid,params)
347 
348  % plot sequence:
349  params.title = 'error';
350  plot_sequence((rb_sim_data.X-ds_sim_data.X),...
351  lin_evol_model_data.grid,params)
352 
353  % plot of reduced output
354  figure,plot(rb_sim_data.time,[rb_sim_data.Y;ds_sim_data.Y]);
355  legend('reduced output','detailed output');
356 
357  keyboard;
358 
359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
360  case 5 % generate plots of detailed data for paper:
361  % step = 5 % figures of detailed simuations based on step 4
362 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 
364  disp('generate plots of detailed_data for morepas poster');
365 
366  load(fullfile(rbmatlabresult,'advection_fv_output_detailed_data_2traj'),...
367  'model','detailed_data')
368 
369 % model = fast_model(params);
370 % rbfname = 'advection_fv_output_basis';
371 % load(fullfile(rbmatlabresult,rbfname),'ds_model','ds_model_data');
372 
373  % make sure, that these trajectories exist.
374  trajectories = [3,4];
375 
376  for tr = 1:length(trajectories);
377  trname = ['trajectory',num2str(trajectories(tr))];
378  % plots of trajectory
379  load(fullfile(rbmatlabresult,trname));
380  lin_evol_model = ds_model.base_model;
381  lin_evol_model_data = gen_model_data(lin_evol_model);
382 
383  params.no_lines = 1;
384  params.show_colorbar = 0;
385  params.axis_equal = 1;
386  params.plot = lin_evol_model.plot;
387  lin_evol_model.plot(ds_sim_data.X(:,1),lin_evol_model_data.grid, ...
388  params);
389  set(gca,'Xtick',[])
390  set(gca,'Ytick',[])
391  saveas(gcf,fullfile(rbmatlabresult,[trname,'_t1.eps']),'epsc');
392  close(gcf);
393 
394  lin_evol_model.plot(ds_sim_data.X(:,64),lin_evol_model_data.grid, ...
395  params);
396  set(gca,'Xtick',[])
397  set(gca,'Ytick',[])
398  saveas(gcf,fullfile(rbmatlabresult,[trname,'_tmiddle.eps']),'epsc');
399  close(gcf);
400 
401  lin_evol_model.plot(ds_sim_data.X(:,end),lin_evol_model_data.grid, ...
402  params);
403  set(gca,'Xtick',[])
404  set(gca,'Ytick',[])
405  saveas(gcf,fullfile(rbmatlabresult,[trname,'_tend.eps']),'epsc');
406  close(gcf);
407 
408  p = ds_model.plot_sim_data(ds_model, ds_model_data, ds_sim_data,params);
409  % Ylim = get(gca,'Ylim');
410  % Ylim = [Ylim(1),Ylim(2)*1.1];
411  set(gca,'Ylim',[0,0.09]);
412  set(p(2),'Color',[0,0.8,0]);
413  saveas(gcf,fullfile(rbmatlabresult,[trname,'_output.eps']),'epsc');
414  close(gcf);
415  close(gcf);
416  end;
417 
418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419 % step = 6 % figures of reduced simuations based on step 4
420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421  case 6 % generate plots of reduced model for poster/paper
422 
423  disp('generate plots of reduced simulations output estimation');
424 
425  load(fullfile(rbmatlabresult,'advection_fv_output_detailed_data_2traj'),...
426  'model','detailed_data')
427  % ds_model = model;
428 
429  % as reference
430  % load(fullfile(rbmatlabresult,'trajectory1'));
431  load(fullfile(rbmatlabresult,'trajectory2'));
432  ds_model.enable_error_estimator = 1;
433 
434 % ds_model.error_estimation = 1;
435 % ds_model.RB_generation_mode = 'file_load'
436 % ds_model.RB_basis_filename = fullfile(...
437 % rbmatlabresult,'advection_fv_output_basis');
438 % detailed_data = gen_detailed_data(ds_model,ds_model_data);
439  reduced_data = gen_reduced_data(ds_model,detailed_data);
440 
441  Ns = [150:-10:10];
442 
443  Ns = Ns(find(reduced_data.N>=Ns));
444 
445  for nind = 1:length(Ns)
446  % perform reduced simulation
447  ds_model.N = Ns(nind);
448  rb_sim_data = rb_simulation(ds_model,reduced_data);
449  rb_sim_data = rb_reconstruction(ds_model,detailed_data,rb_sim_data)
450 
451  params.no_lines = 1;
452  params.show_colorbar = 1;
453  params.axis_equal = 1;
454 
455  % plot of reduced output
456  figure;
457  p = plot(rb_sim_data.time,...
458  [rb_sim_data.Y;...
459  rb_sim_data.Y+rb_sim_data.DeltaY; ...
460  rb_sim_data.Y-rb_sim_data.DeltaY; ...
461  ds_sim_data.Y]);
462  colors = {[1,0,0],[1,0,0],[1,0,0],[0,1,0]};
463  linestyles = {'-','-.','-.','-'};
464  widths = [2,2,2,2];
465  for i = 1:length(p)
466  set(p(i),'Color',colors{i},'Linestyle',linestyles{i},...
467  'Linewidth',widths(i));
468  end;
469  % set marker on rb_sim_data:
470  Xdata = get(p(1),'XData');
471  Ydata = get(p(1),'YData');
472  Zdata = get(p(1),'ZData');
473  set(p(1),'XData',Xdata(1:4:end));
474  set(p(1),'YData',Ydata(1:4:end));
475  set(p(1),'ZData',Zdata(1:4:end));
476  set(p(1),'Marker','o');
477 
478  l = legend(['y\^(t): reduced output'],...
479  'y\^(t)+\Delta_y(t)',...
480  'y\^(t)-\Delta_y(t)',...
481  ['y(t): detailed output'],'Location','SouthEast');
482  set(l,'Fontsize',15);
483  title(['k = ',num2str(ds_model.N)],'Fontsize',15);
484  saveas(gcf,...
485  fullfile(rbmatlabresult,...
486  ['output_estimation',num2str(ds_model.N),'.eps']),'epsc');
487  close(gcf);
488  end;
489 
490 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
491 % step = 7 % time measurements
492 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
493  case 7
494  disp('time measurements for morepas poster');
495 
496 % clear all;
497  nreps = 10;
498  t_detailed = zeros(1,nreps);
499 
500  % initialize detailed model and simulate
501 
502  load(fullfile(rbmatlabresult,'advection_fv_output_detailed_data_2traj'),...
503  'model','detailed_data')
504  ds_model = model;
505 
506 % lin_evol_model = advection_fv_output_model(params);
507  %lin_evol_model.debug = 1;
508  %lin_evol_model_data = gen_model_data(lin_evol_model);
509 
510  % set some additional fields in model which will be copied into
511  % ds model depending on whether constants are known or not:
512 % estimate_constants = 0;
513 % if estimate_constants
514 % %%% if constant estimaton has to be performed:
515 % lin_evol_model.estimate_lin_ds_nmu = 4;
516 % lin_evol_model.estimate_lin_ds_nX = 10;
517 % lin_evol_model.estimate_lin_ds_nt = 4;
518 % else
519 % %%% otherwise:
520 % % the following values are rough bounds, so could be
521 % % non-rigorous, then larger search must be performed.
522 % lin_evol_model.state_bound_constant_C1 = 1;
523 % lin_evol_model.output_bound_constant_C2 = 1.2916;
524 % end;
525 %
526 % ds_model = lin_ds_from_lin_evol_model(lin_evol_model);
527 % % set accelerated data functions from below
528 % ds_model.A_function_ptr = @(model,model_data) ...
529 % eval_affine_decomp(@A_components,...
530 % @A_coefficients,...
531 % model,model_data);
532 %
533 % ds_model.B_function_ptr = @(model,model_data) ...
534 % eval_affine_decomp(@B_components,...
535 % @B_coefficients,...
536 % model,model_data);
537 % %ds_model.u_function_ptr = @(params) 0.1; % define new
538  ds_model_data = gen_model_data(ds_model);
539 
540  disp('skipping detailed simulations...')
541 % if 0
542 
543  for r = 1:nreps
544  disp(['repetition = ',num2str(r)])
545  mu = [1,1,0.5]-rand(1,3)*0.01;
546  ds_model = ds_model.set_mu(ds_model,mu);
547  tic,
548  ds_sim_data = detailed_simulation(ds_model,ds_model_data);
549  t_detailed(1,r) = toc;
550  end;
551 
552 % end;
553 
554  disp('--------------------------------------------------')
555  disp('detailed simulation')
556  disp(t_detailed);
557  disp(['mean t_detailed=',num2str(mean(t_detailed))]);
558  disp('--------------------------------------------------')
559 
560  % reduced simulation with and without error estimation
561 
562  clear('ds_sim_data');
563  ds_model.RB_generation_mode = 'file_load';
564  ds_model.RB_basis_filename = ...
565  fullfile(rbmatlabresult,'advection_fv_output_basis');
566  detailed_data = gen_detailed_data(ds_model,ds_model_data);
567  ds_model.enable_error_estimator = 1;
568  reduced_data = gen_reduced_data(ds_model,detailed_data);
569 
570  Ns = [150:-10:10]; %,30,20,10];
571  Ns = Ns(find(reduced_data.N>=Ns));
572 
573  t_reduced_with_err_est = zeros(length(Ns),nreps);
574  t_reduced_without_err_est = zeros(length(Ns),nreps);
575 
576  % reduced simulation with and without error estimation
577 
578  for err_est = 0:1;
579 % ds_model.error_estimation = err_est;
580  ds_model.enable_error_estimator = err_est;
581  disp(['err_est= ',num2str(err_est)]);
582  for n_ind = 1:length(Ns)
583  disp(['M = ',num2str(Ns(n_ind))]);
584  ds_model.N = Ns(n_ind);
585  for r = 1:nreps
586  disp(['repetition = ',num2str(r)])
587  mu = [1,1,1]-rand(1,3)*0.01;
588  ds_model = ds_model.set_mu(ds_model,mu);
589  tic;
590  rb_sim_data = rb_simulation(ds_model,reduced_data);
591  if size(rb_sim_data.Xr,1)~=Ns(n_ind)
592  disp('N dimension not set correctly!');
593  keyboard;
594  end;
595  if err_est == 1
596  t_reduced_with_err_est(n_ind,r) = toc;
597  else
598  t_reduced_without_err_est(n_ind,r) = toc;
599  end;
600  end;
601  end;
602  end;
603 
604  % output measurements
605 
606  disp('--------------------------------------------------')
607  disp('detailed simulation')
608  disp(t_detailed);
609  disp(['mean t_detailed=',num2str(mean(t_detailed))]);
610 
611  disp('--------------------------------------------------')
612  disp('reduced simulation with error estimation')
613  disp(t_reduced_with_err_est);
614  disp(['mean t_reduced_with_err_est=',...
615  num2str(mean(t_reduced_with_err_est,2)')]);
616  disp(['Ns =',num2str(Ns)]);
617 
618  disp('--------------------------------------------------')
619  disp('reduced simulation without error estimation')
620  disp(t_reduced_without_err_est);
621  disp(['mean t_reduced_without_err_est=',...
622  num2str(mean(t_reduced_without_err_est,2)')]);
623  disp(['Ns =',num2str(Ns)]);
624  disp('--------------------------------------------------')
625 
626  save(fullfile(rbmatlabresult,'time_measurements'));
627 
628 % dim_x = 65536, nt = 2048
629 %
630 %mean t_detailed=64.3806
631 %--------------------------------------------------
632 %reduced simulation with error estimation
633 % 3.4542 3.5969 3.5659 3.4216 3.6170
634 % 3.3648 3.3816 3.4218 3.4391 3.4552
635 % 3.1643 3.1312 3.1244 3.1433 3.1720
636 % 3.0594 3.0496 3.0628 3.0486 3.0387
637 % 2.9993 2.9953 3.0078 2.9413 2.9603
638 % 2.9555 2.9093 2.9091 2.9510 2.9256%%%
639 %
640 %mean t_reduced_with_err_est=3.5311 3.4125 3.147 3.0518 2.9808 2.9301
641 %Ns =60 50 40 30 20 10
642 %--------------------------------------------------
643 %reduced simulation without error estimation
644 % 2.3975 2.4220 2.2924 2.4490 2.3302
645 % 2.3322 2.3198 2.3425 2.3056 2.3512
646 % 2.2227 2.2734 2.2210 2.2582 2.2504
647 % 2.2531 2.2180 2.2429 2.2212 2.2612
648 % 2.2283 2.1979 2.2581 2.2241 2.1957
649 % 2.2274 2.2014 2.2577 2.1856 2.2268
650 %
651 %mean t_reduced_without_err_est=2.3782 2.3303 2.2451 2.2393 2.2208 2.2198
652 %Ns =60 50 40 30 20 10
653 %--------------------------------------------------
654 
655  case 8 % compare original and accelerated detailed model
656 
657  disp('compare original and accelerated lin_ds models');
658 
659  % clear all;
660  % initialize detailed model and simulate
661  lin_evol_model = advection_fv_output_model(params);
662  estimate_constants = 0;
663  if estimate_constants
664  %%% if constant estimaton has to be performed:
665  lin_evol_model.estimate_lin_ds_nmu = 4;
666  lin_evol_model.estimate_lin_ds_nX = 10;
667  lin_evol_model.estimate_lin_ds_nt = 4;
668  else
669  %%% otherwise:
670  % the following values are rough bounds, so could be
671  % non-rigorous, then larger search must be performed.
672  lin_evol_model.state_bound_constant_C1 = 1;
673  lin_evol_model.output_bound_constant_C2 = 1.2916;
674  end;
675 
676  ds_model = lin_ds_from_lin_evol_model(lin_evol_model);
677  %ds_model.u_function_ptr = @(params) 0.1; % define new
678  ds_model_data = gen_model_data(ds_model);
679 
680  % set accelerated data functions
681  ds_model_fast = lin_ds_from_lin_evol_model(lin_evol_model);
682  ds_model_fast.A_function_ptr = @(model,model_data) ...
683  eval_affine_decomp(@A_components,...
684  @A_coefficients,...
685  model,model_data);
686 
687  ds_model_fast.B_function_ptr = @(model,model_data) ...
688  eval_affine_decomp(@B_components,...
689  @B_coefficients,...
690  model,model_data);
691 
692  % ds_model_fast.C_function_ptr = @(model,model_data) ...
693  % eval_affine_decomp(@C_components,...
694  % @C_coefficients,...
695  % model,model_data);
696 
697  % disp('skipping detailed simulations...')
698  % if 0
699 
700  mu = [1,1,0.5]-rand(1,3)*0.01;
701  ds_model = ds_model.set_mu(ds_model,mu);
702  ds_model_fast = ds_model_fast.set_mu(ds_model_fast,mu);
703  tic,
704  ds_sim_data = detailed_simulation(ds_model,ds_model_data);
705  t_detailed = toc;
706  tic,
707  ds_sim_data_fast = detailed_simulation(ds_model_fast,ds_model_data);
708  t_detailed_fast = toc;
709 
710  disp(['original t = ',num2str(t_detailed),...
711  ', accelerated t = ',num2str(t_detailed_fast)]);
712  if ~isequal(ds_sim_data,ds_sim_data_fast)
713  disp('simulation results of original and accelerated model differ!')
714  else
715  disp('simulation results of original and accelerated model equal!')
716  end;
717 
718  keyboard;
719 
720  case 9 % generate basis from POD-Greedy
721 
722  filecache_clear;
723  ds_model = fast_model(params);
724  ds_model.cone_range = [0.4,0.6];
725  ds_model.base_model.cone_range = ds_model.cone_range;
726  % ds_model.
727  % shrink range to 'single point'
728 % r = [0.4,0.6]; % => 2 -> 0.8 error nach 10 basisvektoren
729 % r = [0.0,1.0]; % => 4.6 -> 1.9 error nach 10 basisvektoren
730 % r = [0.45,0.55]; % => 2.38 -> 0.51 error nach 10 basisvektoren
731  ds_model.mu_ranges = {[0,1],[0.4,0.6],[0.4,0.6]};
732  % ds_model.rb_basis_generation_ptr = ...
733  % @basisgen_POD_greedy_uniform_fixed;
734 
735  % ds_model.RB_generation_mode = 'uniform_fixed';
736  % ds_model.RB_num_intervals = [2,2,2];
737 
738  ds_model_data = gen_model_data(ds_model);
739 
740  disp('generating basis from POD-Greedy');
741 
742  % for basis generation, set further fields:
743 
744  ds_model.verbose = 5; % => only dots in greedy loop
745  ds_model.RB_generation_mode = 'greedy_uniform_fixed';
746  ds_model.RB_numintervals = [2,1,1]; % => 0.5 in cone_pos obtained
747 % ds_model.RB_numintervals = [4,4,4];
748  ds_model.RB_stop_epsilon = 1e-5;
749 % ds_model.RB_stop_timeout = 3600*6;
750 % ds_model.RB_stop_Nmax =150;
751  ds_model.RB_stop_timeout = 600;
752  ds_model.RB_stop_Nmax =10;
753  ds_model.RB_extension_algorithm = @RB_extension_PCA_fixspace;
754  ds_model.RB_error_indicator = 'estimator';
755  % default:
756  % ds_model.get_estimator_from_sim_data = @(sim_data) sim_data.DeltaX(end);
757 
758  detailed_data = gen_detailed_data(ds_model,ds_model_data);
759 
760  model = ds_model;
761  dfname = fullfile(rbmatlabresult,'advection_fv_output_lin_ds_detailed');
762  save(dfname,'model','detailed_data');
763 
764  disp('successfully generated and saved detailed_data');
765 
766  params.plot_title = 'reduced basis';
767  params.plot = model.base_model.plot;
768  lin_evol_model_data = gen_model_data(model.base_model);
769  plot_sequence(detailed_data.V,lin_evol_model_data.grid,params)
770 
771  keyboard;
772 
773  case 10 % reduced simulations and error plots
774 
775  %basis_from_step = 9; % step 9
776  basis_from_step = 4; % step 4
777 
778  if basis_from_step == 9
779  dfname = fullfile(rbmatlabresult,'advection_fv_output_lin_ds_detailed');
780  load(dfname);
781  disp('loaded basis from step 9')
782  else
783  load(fullfile(rbmatlabresult,'advection_fv_output_detailed_data_2traj'),...
784  'model','detailed_data')
785 
786 % model = fast_model(params);
787  model_data = gen_model_data(model);
788  % dfname = fullfile(rbmatlabresult,'advection_fv_output_detailed_data_146');
789 % model.RB_basis_filename = ...
790 % fullfile(rbmatlabresult,'advection_fv_output_basis');
791 % model.RB_generation_mode = 'file_load';
792 % detailed_data = gen_detailed_data(model,model_data);
793  % dfname = fullfile(rbmatlabresult,'advection_fv_output_detailed');
794  % load(dfname);
795  tmp = load(fullfile(rbmatlabresult,'trajectory2'));
796  ds_sim_data = tmp.ds_sim_data;
797  mu_from_file = get_mu(tmp.ds_model);
798  disp('loaded basis from step 4')
799  model = model.set_mu(model,mu_from_file);
800  end;
801  % trajectory2 above is made with this
802  % model = model.set_mu(model,[1,1,1]);
803  % model = model.set_mu(model,[1,1,1]);
804  % trajectory3 above is made with this:
805  %model = model.set_mu(model,[1,1,0.5]);
806  %model = model.set_mu(model,[0.5,0.6,0.6]);
807  %model = model.set_mu(model,[0.5,0.4,0.4]);
808  %model = model.set_mu(model,[0.5,0.5,0.5]);
809  model.N = size(detailed_data.V,2);
810  %model.N = 150;
811  reduced_data = gen_reduced_data(model,detailed_data);
812  rb_sim_data = rb_simulation(model,reduced_data);
813 
814  params.no_lines = 1;
815  params.show_colorbar = 1;
816  params.axis_equal = 1;
817 
818  % plot of reduced output
819  figure;
820  p = plot(rb_sim_data.time,...
821  [rb_sim_data.Y;...
822  rb_sim_data.Y+rb_sim_data.DeltaY; ...
823  rb_sim_data.Y-rb_sim_data.DeltaY]);
824  colors = {[1,0,0],[1,0,0],[1,0,0],[0,1,0]};
825  linestyles = {'-','-.','-.','-'};
826  widths = [2,2,2,2];
827  for i = 1:length(p)
828  set(p(i),'Color',colors{i},'Linestyle',linestyles{i},...
829  'Linewidth',widths(i));
830  end;
831  % set marker on rb_sim_data:
832  Xdata = get(p(1),'XData');
833  Ydata = get(p(1),'YData');
834  Zdata = get(p(1),'ZData');
835  set(p(1),'XData',Xdata(1:4:end));
836  set(p(1),'YData',Ydata(1:4:end));
837  set(p(1),'ZData',Zdata(1:4:end));
838  set(p(1),'Marker','o');
839 
840  l = legend(['y\^(t): reduced output'],...
841  'y\^(t)+\Delta_y(t)',...
842  'y\^(t)-\Delta_y(t)','Location','NorthWest');
843  set(l,'Fontsize',15);
844  title(['k = ',num2str(model.N)],'Fontsize',15);
845 
846  % table of error, error estimator and effectivity
847 
848  reduced_data = gen_reduced_data(model,detailed_data);
849 
850  Ns = 150:-10:10;
851  Ns = Ns(find(reduced_data.N>=Ns));
852 
853  err = zeros(1,length(Ns));
854  err_estim = zeros(1,length(Ns));
855  effectivity = zeros(1,length(Ns));
856 
857  for ni = 1:length(Ns)
858  model.N = Ns(ni);
859  rb_sim_data = rb_simulation(model, reduced_data);
860  err(ni) = abs(ds_sim_data.Y(end) - rb_sim_data.Y(end));
861  err_estim(ni) = rb_sim_data.DeltaY(end);
862  effectivity(ni) = err_estim(ni)/err(ni);
863  end;
864  Ns
865  err
866  err_estim
867  effectivity
868  disp('finished computing effectivities')
869  keyboard;
870 
871  case 11 % test of matlab ode solver for resulting sparse system
872 
873  params.coarse_factor = 8; % make model smaller
874  model = fast_model(params);
875  model.RB_generation_mode = 'from_detailed_data';
876 
877  % detailed simulation:
878  model_data = gen_model_data(model);
879  model_data.RB = zeros(size(model_data.G,1),0);
880  detailed_data = gen_detailed_data(model,model_data);
881 
882  model.decomp_mode = 0; % complete
883  model = model.set_time(model,0)
884  model = model.set_mu(model,[0.5,1,1]);
885 
886  A = @(model,model_data,t) ...
887  model.A_function_ptr(model.set_time(model,t),model_data);
888 
889  B = @(model,model_data,t) ...
890  model.B_function_ptr(model.set_time(model,t),model_data);
891 
892  x0 = model.x0_function_ptr(model,model_data);
893  tic;
894  [t,x] = ode15s(@(t,x) A(model,model_data,t)*x + B(model,model_data,t), ...
895  [0 1], x0);
896  time_ode15 = toc;
897  disp(['ode15 takes ',num2str(time_ode15),' sec']);
898 
899  params.plot_title = 'ode15 solution';
900  params.plot = model.base_model.plot;
901  params.axis_equal = 1;
902  lin_evol_model_data = gen_model_data(model.base_model);
903  plot_sequence((x'),lin_evol_model_data.grid,params)
904 
905  tic;
906  sim_data = detailed_simulation(model,model_data);
907  time_rbmatlab = toc;
908  disp(['rbmatlab takes ',num2str(time_rbmatlab),' sec']);
909  params.plot_title = 'rbmatlab solution';
910  params.plot = model.base_model.plot;
911  params.axis_equal = 1;
912  lin_evol_model_data = gen_model_data(model.base_model);
913  plot_sequence(sim_data.X,lin_evol_model_data.grid,params)
914 
915  % further plots for MCMCS paper
916  case 12
917 
918  load(fullfile(rbmatlabresult,'advection_fv_output_detailed_data_2traj'),...
919  'model','detailed_data')
920  model.enable_error_estimator = 1;
921  % plot of error estimator over parameter variation
922 % model = fast_model(params);
923 % model_data = gen_model_data(model);
924  % dfname = fullfile(rbmatlabresult,'advection_fv_output_detailed_data_146');
925 % model.RB_basis_filename = ...
926 % fullfile(rbmatlabresult,'advection_fv_output_basis');
927 % model.RB_generation_mode = 'file_load';
928 % detailed_data = gen_detailed_data(model,model_data);
929 % save(fullfile(rbmatlabresult,...
930 % 'advection_fv_output_detailed_2trajectories.mat'),...
931 % 'model','detailed_data')
932 % keyboard;
933  % dfname = fullfile(rbmatlabresult,'advection_fv_output_detailed');
934  % load(dfname);
935  tmp = load(fullfile(rbmatlabresult,'trajectory2'));
936  ds_sim_data = tmp.ds_sim_data;
937  disp('loaded basis from step 4')
938 
939  % factors = 0:0.05:1;
940  reduced_data = gen_reduced_data(model,detailed_data);
941  Ns = [1,4,8,16];
942  Ns = Ns(find(reduced_data.N>=Ns));
943  factors = 0:0.05:1;
944  err_estim = zeros(length(factors),length(Ns));
945 
946 % if 0
947  for ni = 1:length(Ns)
948  model.N = Ns(ni);
949  for i =1:length(factors)
950  model = model.set_mu(model, factors(i)*[1,1,1]);
951  rb_sim_data = rb_simulation(model, reduced_data);
952  % err(ni) = abs(ds_sim_data.Y(end) - rb_sim_data.Y(end));
953  err_estim(i,ni) = rb_sim_data.DeltaY(end);
954  % effectivity(ni) = err_estim(ni)/err(ni);
955  end;
956  end;
957 
958 % end; % if 0
959 
960 
961 % keyboard;
962  p = plot(factors,err_estim');
963  colors = {[1,0,0],[0,0.6,0],[0,0,1],[0,0,0]};
964  linestyles = {'-','-.','-','-.'};
965  for i = 1:4;
966  set(p(i),'Linewidth',2,'Color',colors{i},'Linestyle',linestyles{i});
967  end;
968 
969  xlabel('parameter \mu_1=\mu_2=\mu_3','Fontsize',15);
970  ylabel('\Delta_y(\mu)','Fontsize',15);
971  title('error estimator from parameter sweep','Fontsize',15)
972  l = legend({'k=1','k=4','k=8','k=16'},'Location','NorthWest');
973  set(l,'Fontsize',15);
974  saveas(gcf,fullfile(rbmatlabresult,'parameter_sweep.eps'),'epsc');
975  % plot of true errors
976 
977  model_data = gen_model_data(model);
978 
979  figure;
980 % factors = [0,0.5,1];
981  errs = zeros(length(factors),length(Ns));
982  for i =1:length(factors)
983  model = model.set_mu(model, factors(i)*[1,1,1]);
984  ds_sim_data = filecache_function(@detailed_simulation,model,model_data);
985  for ni = 1:length(Ns)
986  model.N = Ns(ni);
987  rb_sim_data = rb_simulation(model, reduced_data);
988  % err(ni) = abs(ds_sim_data.Y(end) - rb_sim_data.Y(end));
989  e = rb_sim_data.Y-ds_sim_data.Y;
990  e = max(sqrt(max(sum(e.*e),0)));
991  errs(i,ni) = e;
992  % effectivity(ni) = err_estim(ni)/err(ni);
993  end;
994  end;
995  % keyboard;
996  p = plot(factors,errs');
997  colors = {[1,0,0],[0,0.6,0],[0,0,1],[0,0,0]};
998  linestyles = {'-','-.','-','-.'};
999  for i = 1:4;
1000  set(p(i),'Linewidth',2,'Color',colors{i},'Linestyle',linestyles{i});
1001  end;
1002  % same range as first plot
1003  set(gca,'Ylim',[0,10]);
1004 
1005  xlabel('parameter \mu_1=\mu_2=\mu_3','Fontsize',15);
1006  ylabel('|y(\mu)-y\^(\mu)|','Fontsize',15);
1007  title('output errors from parameter sweep','Fontsize',15)
1008  l = legend({'k=1','k=4','k=8','k=16'},'Location','NorthWest');
1009  set(l,'Fontsize',15);
1010  saveas(gcf,fullfile(rbmatlabresult,'parameter_sweep_errs.eps'),'epsc');
1011  keyboard;
1012  % plot of true errors
1013 
1014  otherwise
1015  disp('step number unknown');
1016 end;
1017 
1018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1019 % generation of ds_model from lin_evol_model and replace
1020 % by fast vectors
1021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1022 
1023 function ds_model = fast_model(params);
1024  % fast_model
1025 lin_evol_model = advection_fv_output_model(params);
1026 %lin_evol_model.debug = 1;
1027 %lin_evol_model_data = gen_model_data(lin_evol_model);
1028 
1029 % set some additional fields in model which will be copied into
1030 % ds model depending on whether constants are known or not:
1031 estimate_constants = 0;
1032 if estimate_constants
1033  %%% if constant estimaton has to be performed:
1034  lin_evol_model.estimate_lin_ds_nmu = 4;
1035  lin_evol_model.estimate_lin_ds_nX = 10;
1036  lin_evol_model.estimate_lin_ds_nt = 4;
1037 else
1038  %%% otherwise:
1039  % the following values are rough bounds, so could be
1040  % non-rigorous, then larger search must be performed.
1041  lin_evol_model.state_bound_constant_C1 = 1;
1042  lin_evol_model.output_bound_constant_C2 = 1.2916;
1043 end;
1044 
1045 ds_model = lin_ds_from_lin_evol_model(lin_evol_model);
1046 % set accelerated data functions from below
1047 ds_model.A_function_ptr = @(model,model_data) ...
1048  eval_affine_decomp(@A_components,...
1049  @A_coefficients,...
1050  model,model_data);
1051 
1052 ds_model.B_function_ptr = @(model,model_data) ...
1053  eval_affine_decomp(@B_components,...
1054  @B_coefficients,...
1055  model,model_data);
1056 %ds_model.u_function_ptr = @(params) 0.1; % define new
1057 
1058 %ds_model.theta = 1;
1059 %disp('set theta to 1!!!');
1060 %keyboard;
1061 
1062 
1063 
1064 
1065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1066 % auxialiary coefficient functions for acceleration of
1067 % advection model: explicit implementation of coefficients
1068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1069 
1070 function Acomp = A_components(model,model_data)
1071  % A_components
1072 Acomp = model_data.A_components;
1073 
1074 function Acoeff = A_coefficients(model);
1075  % A_coefficients
1076 
1077 %model.base_model.decomp_mode = 2;
1078 %model.base_model.t = model.t;
1079 %mu = get_mu(model);
1080 %model.base_model = model.set_mu(model.base_model,mu);
1081 %[L_I_coeff, L_E_coeff, b_coeff] = ...
1082 % model.base_model.operators_ptr(model.base_model, );
1083 %% L_E = Id + Delta t * A
1084 %Acoeff = L_E_coeff(2:end)/model.base_model.dt;
1085 %keyboard;
1086 %Acoeff = -model.base_model.dt * ...
1087 % model.base_model.velocity_coefficients_ptr(model.base_model);
1088 %if model.t>0
1089  Acoeff = - [model.vx_weight, model.vy_weight]*(1-model.t);
1090 % keyboard;
1091 %end;
1092 
1093 function Bcomp = B_components(model,model_data)
1094  % B_components
1095 Bcomp = model_data.B_components;
1096 
1097 function Bcoeff = B_coefficients(model);
1098  % B_coefficients
1099 
1100 % hmmm the coefficients are now called twice in A and B
1101 % should somehow be cached later...
1102 %model.base_model.decomp_mode = 2;
1103 %model.base_model.t = model.t;
1104 %mu = get_mu(model);
1105 %model.base_model = model.set_mu(model.base_model,mu);
1106 %[L_I_coeff, L_E_coeff, b_coeff] = ...
1107 % model.base_model.operators_ptr(model.base_model, );
1108 %% L_E = Id + Delta t * A
1109 %Bcoeff2 = b_coeff/model.base_model.dt;
1110 vcoeff = - [model.vx_weight, model.vy_weight]*(1-model.t);
1111 Q_0 = model.base_model.cone_number;
1112 dcoeff = zeros(1,Q_0);
1113 max_pos = model.cone_weight * (Q_0-1)+1;
1114 t = model.t;
1115 for q = 1:Q_0
1116  dcoeff(q) = (1-(max_pos-q))*(1-t) * ((max_pos>=q) && (max_pos < q+1)) ...
1117  + (1+(max_pos-q))*(1-t) * ((max_pos>=q-1) && (max_pos < q));
1118 end;
1119 v = -(vcoeff(:)*(dcoeff(:)'));
1120 Bcoeff = v(:);
1121 %if model.t>0
1122 %keyboard;
1123 %end;
1124 
1125 %function Ccomp = C_components(model,model_data)
1126 %Ccomp = model_data.C_components;
1127 %
1128 %function Ccoeff = C_coefficients(model);
1129 %model.base_model.decomp_mode = 2;
1130 %model.base_model.t = model.t;
1131 %mu = get_mu(model);
1132 %model.base_model = model.set_mu(model.base_model,mu);
1133 %Ccoeff = ...
1134 % model.base_model.operators_output(model.base_model);
1135 
1136