rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
advection_Nadapt.m
Go to the documentation of this file.
1 % small script demonstrating RB-approach with adaptive N choice
2 % for a simple advection problem. Only dirichlet-data
3 % parametrization, should be made more complex later.
4 % Demonstrates the unequal error estimator increase
5 % is a motivation for model adaptivity.
6 %
7 % The results of the MATHMOD-Paper on Nadaptivity are generated
8 % with this script.
9 
10 % Bernard Haasdonk 28.10.2008
11 
12 %step = 0; % check continuity of dirichlet data
13 %step = 1; % single simulation
14 %step = 2; % generate reduced basis, detailed_data is stored
15 %step = 3 % load detailed_data and run reduced simulation with error plot
16 step = 4 % run n-adaptive reduced simulation with errot plot
17 %step = 5 % generate figures of error estimator and N evolution for paper
18 %step = 6 % perform time measurement for paper and generate error
19 % % estimator figure
20 
21 % default: load 'better' basis of step 3:
22 % Basis with large error 1e-2:
23 detailedfname = 'advection_Nadapt_detailed.mat';
24 %detailedfname = 'advection_adaptivity_detailed_new.mat';
25 
26 params = [];
27 % load demo_lin_evol_params;
28 % ===>
29 % xrange: [0 1.0000e-003]
30 % yrange: [0 2.0000e-004]
31 % T: 0.5000
32 % nt: 200
33 % bnd_rect_corner1: [2x5 double]
34 % bnd_rect_corner2: [2x5 double]
35 % bnd_rect_index: [-1 -2 -2 -1 -2]
36 % name_dirichlet_values: 'weighted_boxes'
37 % dir_box_xrange: {[-2.2204e-016 5.0000e-004] [5.0000e-004 1.0000e-003]}
38 % dir_box_yrange: {[2.0000e-004 2.0000e-004] [2.0000e-004 2.0000e-004]}
39 % c_dir: 1
40 % beta: 1
41 % name_neuman_values: 'rightflow'
42 % name_diffusivity: 'homogeneous'
43 % name_diffusive_num_flux: 'gradient'
44 % k: 0
45 % name_flux: 'gdl2'
46 % use_velocity_matrixfile: 1
47 % divclean_mode: 'none'
48 % lambda: 2.0000e-007
49 % velocity_matrixfile: 'vel_gdl2_200x40_l2e-07.mat'
50 % name_convective_num_flux: 'lax-friedrichs'
51 % name_init_values: 'wave'
52 % freq_x: 3.1416e+004
53 % freq_y: 0
54 % c_init: 1
55 % verbose: 9
56 % show_colorbar: 1
57 % colorbar_mode: 'EastOutside'
58 % mu_names: {'c_init' 'beta' 'k'}
59 % mu_ranges: {[0 1] [0 1] [0 5.0000e-008]}
60 % L_I_inv_norm_bound: 1
61 % L_E_norm_bound: 1
62 % detailed_simulation_algorithm: 'detailed_lin_evol_simulation'
63 % operators_algorithm: 'fv_operators_implicit_explicit'
64 % init_values_algorithm: 'fv_init_values'
65 % lxf_lambda: 1.0194e+003
66 % data_const_in_time: 1
67 % xnumintervals: 200
68 % ynumintervals: 40
69 % gridtype: 'rectgrid'
70 % error_norm: 'l2'
71 % coercivity_bound_name: 'fv_coercivity_bound'
72 % alpha_over_k: 1.9915e+007
73 % energy_norm_gamma: 0.5000
74 % axis_equal: 1
75 % rb_problem_type: 'lin_evol'
76 % inner_product_matrix_algorithm: 'fv_inner_product_matrix'
77 % error_algorithm: 'fv_error'
78 % RB_extension_algorithm: 'RB_extension_PCA_fixspace'
79 % RB_stop_timeout: 3600
80 % RB_stop_epsilon: 1.0000e-008
81 % RB_stop_Nmax: 150
82 % RB_error_indicator: 'estimator'
83 % RB_generation_mode: 'uniform_fixed'
84 % RB_numintervals: [4 4 4]
85 % flux_linear: 1
86 
87 
88 % the following is required for step 0 and 1:
89 
90 params.T = 2;
91 
92 params.gridtype = 'triagrid'; % required for gui!
93 params.grid_initfile = '2dsquaretriang';
94 eps = 1e-6;
95 params.bnd_rect_corner1= [-eps, -eps ; -eps,-eps; 1-eps, -eps; -eps ,1-eps]';
96 params.bnd_rect_corner2= [1+eps, +eps; 1+eps,+eps; 1+eps,1+eps; 1+eps, 1+eps]';
97 %bnd_rect_corner1= [-1, -1; eps,eps];
98 %bnd_rect_corner2= [2, 2; 2,2]';
99 params.bnd_rect_index= [-1; -1; -2; -2];
100 params.nt = 500;
101 grid = triagrid(params);
102 
103 %plot_element_data_sequence(grid,grid.NBI.*(grid.NBI<0),params);
104 %keyboard;
105 
106 %params.grid_initfile = 'circle_grid';
107 %grid = triagrid(params);
108 %plot(grid);
109 %params.nt = 300;
110 
111 params.name_dirichlet_values = 'decomp_function_ptr';
112 params.dirichlet_values_components_ptr = @advection_Nadapt.my_udir_components;
113 params.dirichlet_values_coefficients_ptr = @advection_Nadapt.my_udir_coefficients;
114 params.name_init_values = 'decomp_function_ptr';
115 params.init_values_components_ptr = @advection_Nadapt.my_u0_components;
116 params.init_values_coefficients_ptr = @advection_Nadapt.my_u0_coefficients;
117 params.c_dir_1 = 1;
118 params.c_dir_2 = 1;
119 %params.c_dir_3 = 1;
120 params.name_neuman_values = 'outflow';
121 
122 params.transport_x = 1;
123 params.transport_y = 1;
124 params.name_flux = 'transport';
125 params.flux_linear = 1;
126 params.name_convective_num_flux = 'engquist-osher';
127 
128 params.name_diffusivity = 'homogeneous';
129 params.name_diffusive_num_flux = 'gradient';
130 params.k = 0.00;
131 
132 params.detailed_simulation_algorithm = 'detailed_lin_evol_simulation';
133 params.operators_algorithm = 'fv_operators_implicit_explicit';
134 params.init_values_algorithm = 'fv_init_values';
135 params.data_const_in_time = 0;
136 params.rb_problem_type= 'lin_evol';
137 params.verbose = 9;
138 %params.verbose = 10;
139 
140 % the following is required for step 2
141 
142 %params.mu_names= {'c_dir_1' 'c_dir_2' 'c_dir_3'};
143 params.mu_names= {'c_dir_1' 'c_dir_2' 'k'};
144 params.mu_ranges= {[0 1] [0 1] [0 1]};
145 params.inner_product_matrix_algorithm= 'fv_inner_product_matrix';
146 params.L_I_inv_norm_bound = 1;
147 params.L_E_norm_bound =1;
148 params.error_norm = 'l2';
149 
150 params.show_colorbar = 1;
151 params.colorbar_mode = 'EastOutside';
152 
153 % the following is required for incremental basis generation
154 
155 % coercivity_bound_name: 'fv_coercivity_bound'
156 % alpha_over_k: 1.9915e+007
157 % energy_norm_gamma: 0.5000
158 % axis_equal: 1
159 % error_algorithm: 'fv_error'
160 
161 params.RB_extension_algorithm= 'RB_extension_PCA_fixspace';
162 params.RB_stop_timeout= 4*3600;
163 params.RB_stop_epsilon= 1.0000e-008;
164 params.RB_stop_Nmax= 150;
165 params.RB_error_indicator= 'estimator';
166 params.RB_generation_mode= 'uniform_fixed';
167 params.RB_numintervals= [2 2 6];
168 
169 detailed_data.grid = grid;
170 
171 switch step
172  case 0 % check continuity of dirichlet data
173  x = 0.0;
174  y = 0;
175  params.decomp_mode = 0; % complete
176 % params.affine_decomp_mode = 'complete';
177 % params.affine_decomp_mode = 'coefficients';
178  udir = zeros(params.nt+1,1);
179  dt = params.T/params.nt;
180  for ti = 0:params.nt
181  params.t = ti*dt;
182  udir(ti+1) = dirichlet_values(x,y,params);
183 % coeff = dirichlet_values(x,y,params);
184 % udir(ti+1) = coeff(3);
185  end;
186  plot(udir);
187  case 1
188  disp('performing single detailed simulation')
189  U = detailed_simulation(detailed_data.grid, params);
190  plot_element_data_sequence(detailed_data.grid,U,params);
191  case 2 % dummy reduced basis by single trajectory and simulate
192  % turn on matrix inversion for faster basis generation:
193  params.skip_matrix_inversion = 0;
194  % single trajectory:
195 
196 % disp('detailed simulations');
197 % params = params.set_mu([1,1,1],params);
198 % U1 = filecache_function(@detailed_simulation,detailed_data.grid,params);
199 % params = params.set_mu([0,1,0],params);
200 % U2 = filecache_function(@detailed_simulation,detailed_data.grid,params);
201 % params = params.set_mu([0,0,1],params);
202 % U3 = filecache_function(@detailed_simulation, ...
203 % detailed_data.grid,params);
204 
205 %A = feval(params.inner_product_matrix_algorithm,detailed_data.grid,params);
206 % disp('generating basis');
207 % disp('orthonormalization 1:');
208 % UON1 = orthonormalize_qr(U1,A);
209 % detailed_data.RB= UON1;
210 
211  % disp(['found ',num2str(size(UON1,2)),' basis vectors, only taking ', ...
212 % '25']);
213 % UON1 = UON1(:,1:25); % only take 30 for each trajectory
214 % disp('orthonormalization 2:');
215 % % orthonormalize UON2 with respect to UON1:
216 % U2P = U2 - UON1 * (UON1' * A * U2);
217 % UON2 = orthonormalize_qr(U2P,A);
218 % disp(['found ',num2str(size(UON2,2)),' basis vectors, only taking ', ...
219 % '25']);
220 % UON2 = UON2(:,1:25); % only take 20 for each trajectory
221 % disp('orthonormalization 3:');
222 % % orthonormalize UON3 with respect to [UON1, UON2]
223 % U3P = U3 - [UON1 UON2] * ([UON1'; UON2'] * A * U3);
224 % UON3 = orthonormalize_qr(U3P,A);
225 % disp(['found ',num2str(size(UON3,2)),' basis vectors, only taking ', ...
226 % ' 25']);
227 % UON3 = UON3(:,1:25); % only take 20 for each trajectory
228 % detailed_data.RB = [UON1,UON2,UON3];
229 % disp(['found total ',num2str(size(detailed_data.RB,2)),' basis vectors.']);
230 
231 % Gram Schmidt is much too sensitive for large trajectories
232 % UON = orthonormalize_gram_schmidt(U,A);
233 
234  detailed_data.grid = grid;
235 % detailed_data = rb_basis_generation(detailed_data,params);
236 % A = feval(params.inner_product_matrix_algorithm,detailed_data.grid,params);
237 
238 % params.set_mu([1,1,1],params);
239 % U = detailed_simulation(detailed_data.grid,params);
240 % UON = orthonormalize_qr(U,A);
241 
242 % detailed_data.RB = UON;
243  % adaptive basis generation:
244  detailed_data = rb_basis_generation(detailed_data,params);
245  disp('saving detailed_data')
246  save(detailedfname,'detailed_data','params');
247 % params.title = 'detailed simulation result';
248 % plot_element_data_sequence(detailed_data.grid,U,params);
249  case 3
250  disp('loading detailed data and parameters from file')
251  load(detailedfname);
252  disp('reduced simulation:')
253  offline_data = rb_offline_prep(detailed_data,params);
254 % params.N = size(detailed_data.RB,2)/2;
255  params.N = round(size(detailed_data.RB,2));
256  reduced_data = rb_online_prep(offline_data, params);
257  simulation_data = rb_simulation(reduced_data,params);
258  Uappr = rb_reconstruction(detailed_data,simulation_data);
259  params.title = 'reduced simulation result';
260  plot_element_data_sequence(detailed_data.grid,Uappr,params);
261  figure, plot(simulation_data.Delta);
262  title('error estimator');
263  case 4
264  disp('loading detailed data and parameters from file')
265  load(detailedfname);
266  disp('reduced simulation:')
267  offline_data = rb_offline_prep(detailed_data,params);
268  params.N_mode = 'adapt';
269  params.N_adapt_look_ahead_nt = 40;
270 % params.N_adapt_slope = 0.5;
271  params.N_adapt_slope = 10;
272  params.N = size(detailed_data.RB,2); % set max!
273 % params.N_adapt_epsilon = 7e-2;
274 % params.N_adapt_epsilon = 5e-2;
275 % params.N_adapt_epsilon = 3e-2;
276 % params.N_adapt_epsilon = 1e-1;
277 % params.N_adapt_epsilon = 7e-1;
278 % params.N_adapt_epsilon = 1e-3; => everything over 50% N
279 
280 % schoen niedriges N:
281  params.N_mode = 'adapt';
282  params = params.set_mu([1 0 0],params);
283  params.N_adapt_epsilon = 5e-2;
284 % schoen adaptives N:
285  params.N_mode = 'adapt';
286  params = params.set_mu([1 1 0],params);
287  params.N_adapt_epsilon = 5e-2;
288 % schoen adaptives N mit Diffusion:
289  params.N_mode = 'adapt';
290  params = params.set_mu([1 1 0.25],params);
291  params.N_adapt_epsilon = 7e-2;
292 % N-"switch" zu bestimmten Zeiten: verringerung des Knicks:
293  params.N_mode = 'switch';
294  params.N_switch_times = [0,1];
295  params.N_switch_values = [40,64];
296 % schoen adaptives N mit grosser Diffusion:
297  params.N_mode = 'adapt';
298  params = params.set_mu([1 1 1],params);
299  params.N_adapt_epsilon = 5e-2;
300 
301  reduced_data = rb_online_prep(offline_data, params);
302  simulation_data = rb_simulation(reduced_data,params);
303 % Uappr = rb_reconstruction(detailed_data,simulation_data);
304 % params.title = 'reduced simulation result';
305 % plot_element_data_sequence(detailed_data.grid,Uappr,params);
306 
307 
308  Nscaled = simulation_data.N /max(simulation_data.N)*...
309  params.N_adapt_epsilon;
310  figure, plot([simulation_data.Delta;...
311  0:(params.N_adapt_epsilon)/params.nt:params.N_adapt_epsilon;...
312  Nscaled]');
313  title('error estimator, N scaled, target line');
314 % figure, plot(simulation_data.N);
315 % title('reduced dimension N');
316 
317 % disp('time measurement: epsilon = 1e-2:')
318 % params.N_adapt_epsilon = 1e-2;
319 % tic, simulation_data = rb_simulation(reduced_data,params), toc
320 % disp(['average N: ', num2str(mean(simulation_data.N))]);
321 % disp('time measurement: epsilon = 1e-5:')
322 % params.N_adapt_epsilon = 1e-5;
323 % tic, simulation_data = rb_simulation(reduced_data,params), toc
324 % disp(['average N: ', num2str(mean(simulation_data.N))]);
325 
326  case 5
327  disp('loading detailed data and parameters from file')
328  load(detailedfname);
329  offline_data = rb_offline_prep(detailed_data,params);
330 
331  params = params.set_mu([1 1 1],params); % => non-monotonic error curve for Nfixed!
332 
333  linestyles = {'-.','-','-',':'};
334  linecolors = {[0,0,1],[0,0.5,0],[1,0,0],[0,0,0]};
335  linewidths = [1,1,2,2];
336 
337  params = params.set_mu([1,1,1],params); % convection
338  params.N_mode = 'adapt';
339 % params.N_adapt_epsilon = 7e-1;
340  params.N_adapt_epsilon = 7e-2;
341  params.N_adapt_look_ahead_nt = 40;
342  params.N_adapt_slope = 10;
343  disp('reduced_simulation:');
344  params.N = 64;
345  reduced_data = rb_online_prep(offline_data, params);
346  simulation_data = rb_simulation(reduced_data,params);
347 
348  N1 = 30;
349  N2 = 50;
350  params.N_mode = 'fixed';
351 
352  params.N = N1;
353  reduced_data = rb_online_prep(offline_data, params);
354  disp('reduced_simulation:');
355  simulation_data_N1 = rb_simulation(reduced_data,params);
356  params.N = N2;
357  reduced_data = rb_online_prep(offline_data, params);
358  disp('reduced_simulation:');
359  simulation_data_N2 = rb_simulation(reduced_data,params);
360  %Uappr = rb_reconstruction(detailed_data,simulation_data);
361  if isfield(simulation_data,'N');
362  Ns = simulation_data.N;
363  else
364  Ns = params.N * ones(1,params.nt+1);
365  end;
366  figure; % subplot(2,1,2);
367  p = plot([0:params.nt],[ones(size(Ns))*N1;ones(size(Ns))*N2;Ns]');
368  for i=1:length(p)
369  set(p(i),'Color',linecolors{i},...
370  'LineWidth',linewidths(i),...
371  'LineStyle',linestyles{i})
372  end;
373  %set(p(3),'LineWidth',2);
374  %set(p(1),'LineStyle','-.');
375  title('model dimension N');
376  legend(['N-fixed N=',num2str(N1)],...
377  ['N-fixed N=',num2str(N2)],'N-adaptive')
378  set(gca,'XLim',[0,params.nt]);
379  set(gca,'YLim',[0,100]);
380  xlabel('time index k');
381  saveas(gcf,'Nadaptive_error2_large','epsc');
382  set(gcf,'Position',[472 404 564 238]);
383  %subplot(2,1,1),
384  figure, p = plot([0:params.nt],[simulation_data_N1.Delta; ...
385  simulation_data_N2.Delta;...
386  simulation_data.Delta;...
387  0:(params.N_adapt_epsilon)/params.nt:params.N_adapt_epsilon
388  ]');
389  %keyboard;
390  for i=1:length(p)
391  set(p(i),'Color',linecolors{i},...
392  'LineWidth',linewidths(i),...
393  'LineStyle',linestyles{i})
394  end;
395  %keyboard;
396  %set(p(1),'LineStyle','-.');
397  %set(p(4),'LineStyle',':');
398  %set(p(3),'LineWidth',2);
399  title('error estimator evolution');
400  l = legend({['N-fixed, N=',num2str(N1)],...
401  ['N-fixed, N=',num2str(N2)], ...
402  'N-adaptive', ...
403  'N-adaptive-target'},'location','northwest');
404  set(gca,'XLim',[0,params.nt]);
405  xlabel('time index k');
406  saveas(gcf,'Nadaptive_Ns2_large','epsc');
407  set(gcf,'Position',[472 404 564 238]);
408  po = get(l,'Position');
409  set(l,'Position',po);
410  disp('please save figures as eps (automatic saving does not get aspectratio)')
411 
412  case 6
413  % time measurement:
414 
415  disp('loading detailed data and parameters from file')
416  load(detailedfname);
417  offline_data = rb_offline_prep(detailed_data,params);
418 
419  params = params.set_mu([1 1 1],params); % => non-monotonic error curve for Nfixed!
420 % params = params.set_mu([1 1 0.666666],params); % => non-monotonic error curve for Nfixed!
421 % params = params.set_mu([1 1 0.2],params); => fixed fastest
422 % params = params.set_mu([1 1 0.5],params); % => fixed fastest
423 % params = params.set_mu([1 1 0],params); % => almost no time difference!
424  % diffusivity required!
425  params.N = size(detailed_data.RB,2); % set max!
426 
427  nrep = 10;
428  t_exact = zeros(1,nrep);
429  disp('detailed_simulation:');
430  disp('(skipping detailed computation loop)')
431  % for r = 1:nrep
432  for r = 1:1
433  tic, U = detailed_simulation(detailed_data.grid,params);
434  t_exact(r) = toc;
435  end;
436  disp(' time av(N) Delta err ');
437  disp(['Exact simulation: ', ...
438  num2str(mean(t_exact)), '+-',num2str(std(t_exact)),...
439  ' ', num2str(detailed_data.grid.nelements),' 0 0 ']);
440 
441  disp('reduced_simulations, fixed Ns:');
442 % Ns = [100,85,70,55,40,25,10];
443 % Ns = [64,56,48,40,32,24,16,8];
444  Ns = [32,28,24,20,16,12,8];
445  t_Nfix = zeros(length(Ns),nrep);
446  Delta_Nfix = zeros(size(Ns));
447  % prevent matrix inversion for fair comparison
448  params.skip_matrix_inversion = 1;
449  params.N_mode = 'fixed';
450 
451  %dummy simulation
452  dummy_reduced_data = rb_online_prep(offline_data, params);
453  dummy = rb_simulation(dummy_reduced_data,params);
454 
455  for r = 1:nrep
456  for n = 1:length(Ns)
457  simulation_data = [];
458  params.N = Ns(n);
459  reduced_data = rb_online_prep(offline_data, params);
460  tic;
461  simulation_data = rb_simulation(reduced_data,params);
462  t_Nfix(n,r)= toc;
463  Uappr = rb_reconstruction(detailed_data,simulation_data);
464  err = fv_error(Uappr,U,detailed_data.grid,params);
465  err_Nfix(n) = max(err);
466  Delta_Nfix(n) = simulation_data.Delta(end);
467  % disp(['N = ',num2str(Ns(n)),' ',num2str(t_Nfix(n,r)),' ',...
468  % num2str(Ns(n)),' ',...
469  % num2str(Delta_Nfix(n)),' ',num2str(err_Nfix(n))]);
470  end;
471  end;
472  disp('overall:')
473  for n = 1:length(Ns)
474  disp(['N = ',num2str(Ns(n)),' ',num2str(mean(t_Nfix(n,:))),...
475  '+-',num2str(std(t_Nfix(n,:))),' ',...
476  num2str(Ns(n)),' ',...
477  num2str(Delta_Nfix(n)),' ',num2str(err_Nfix(n))]);
478  end;
479 
480  disp('reduced_simulations, adaptive Ns:');
481 % epsilons = [5e-6,1e-5,5e-5,1e-4,5e-4,1e-3];
482 % epsilons = [1e-2,2e-2,5e-2,1e-1,2e-1,5e-1,1,5];
483  epsilons = [1e-1,2e-1,5e-1,7e-1,1,2,5];
484  Delta_Nadaptive = zeros(size(epsilons));
485  t_Nadaptive = zeros(length(epsilons),nrep);
486  Nav_Nadaptive = zeros(size(epsilons));
487  params.N = size(detailed_data.RB,2);
488  reduced_data = rb_online_prep(offline_data, params);
489  params.N_mode = 'adapt';
490 % params.N_adapt_look_ahead_nt = 20;
491  params.N_adapt_look_ahead_nt = 40;
492  % params.N_adapt_slope = 0.5;
493 % params.N_adapt_slope = 5;
494  params.N_adapt_slope = 10;
495 
496  for r = 1:nrep
497  for e = 1:length(epsilons)
498  simulation_data =[];
499  params.N_adapt_epsilon = epsilons(e);
500  tic;
501  simulation_data = rb_simulation(reduced_data,params);
502  t_Nadaptive(e,r)= toc;
503  Uappr = rb_reconstruction(detailed_data,simulation_data);
504  err = fv_error(Uappr,U,detailed_data.grid,params);
505 % err_Nadaptive(e) = err(end);
506  err_Nadaptive(e) = max(err);
507  Delta_Nadaptive(e) = simulation_data.Delta(end);
508  Nav_Nadaptive(e) = mean(simulation_data.N);
509  % disp(['epsilon = ',num2str(epsilons(e)),...
510  % ' ',num2str(t_Nadaptive(e,r)),' ',num2str(Nav_Nadaptive(e)),...
511  % ' ',...
512  % num2str(Delta_Nadaptive(e)),' ',num2str(err_Nadaptive(e))]);
513  end;
514  end;
515  disp('overall:')
516  for e = 1:length(epsilons)
517  disp(['epsilon = ',num2str(epsilons(e)),...
518  ' ',num2str(mean(t_Nadaptive(e,:))),'+-',...
519  num2str(std(t_Nadaptive(e,:))),' ',num2str(Nav_Nadaptive(e)),...
520  ' ',...
521  num2str(Delta_Nadaptive(e)),' ',num2str(err_Nadaptive(e))]);
522  end;
523  disp(['above results averaged over ',num2str(nrep),' runs']);
524 
525 
526 % disp('reduced_simulations, switching Ns:');
527 %% epsilons = [5e-6,1e-5,5e-5,1e-4,5e-4,1e-3];
528 % switch_times = 0:0.25:2;
529 % Delta_Nswitch = zeros(size(switch_times));
530 % t_Nswitch = zeros(length(switch_times),nrep);
531 % Nav_Nswitch = zeros(size(switch_times));
532 % params.N = size(detailed_data.RB,2);
533 % reduced_data = rb_online_prep(offline_data, params);
534 % params.N_mode = 'switch';
535 % params.N_switch_values = [40,64];
536 % params.N_switch_times = [0,1];
537 %
538 % for r = 1:nrep
539 % for e = 1:length(switch_times)
540 % simulation_data =[];
541 % params.N_switch_times(2) = switch_times(e);
542 % tic;
543 % simulation_data = rb_simulation(reduced_data,params);
544 % t_Nswitch(e,r)= toc;
545 % Uappr = rb_reconstruction(detailed_data,simulation_data);
546 % err = fv_error(Uappr,U,detailed_data.grid,params);
547 %% err_Nadaptive(e) = err(end);
548 % err_Nswitch(e) = max(err);
549 % Delta_Nswitch(e) = simulation_data.Delta(end);
550 % Nav_Nswitch(e) = mean(simulation_data.N);
551 % % disp(['epsilon = ',num2str(epsilons(e)),...
552 % % ' ',num2str(t_Nadaptive(e,r)),' ',num2str(Nav_Nadaptive(e)),...
553 % % ' ',...
554 % % num2str(Delta_Nadaptive(e)),' ',num2str(err_Nadaptive(e))]);
555 % end;
556 % end;
557 % disp('overall:')
558 % for e = 1:length(switch_times)
559 % disp(['switch_time = ',num2str(switch_times(e)),...
560 % ' ',num2str(mean(t_Nswitch(e,:))),'+-',...
561 % num2str(std(t_Nswitch(e,:))),' ',num2str(Nav_Nswitch(e)),...
562 % ' ',...
563 % num2str(Delta_Nswitch(e)),' ',num2str(err_Nswitch(e))]);
564 % end;
565 % disp(['above results averaged over ',num2str(nrep),' runs']);
566 
567  linestyles = {'-.','-','-',':'};
568  linecolors = {[0,0,1],[0,0.5,0],[1,0,0],[0,0,0]};
569  linewidths = [1,1,2,2];
570  markers = {'','x','d',''};
571 
572  figure
573  plot(mean(t_Nadaptive,2),Delta_Nadaptive',...
574  'Color',linecolors{3},...
575  'LineStyle',linestyles{3},'Marker',markers{3},'LineWidth',linewidths(3));
576  hold on;
577  plot(mean(t_Nfix,2),Delta_Nfix',...
578  'Color',linecolors{2},...
579  'LineStyle',linestyles{2},'Marker',markers{2},'LineWidth',linewidths(2));
580  hold on;
581 % plot(mean(t_Nswitch,2),Delta_Nswitch','r-');
582 % hold on;
583  xlabel('runtime')
584  ylabel('error estimator')
585  set(gca,'Yscale','log')
586  title('error estimator over runtime')
587 % legend('N-adaptive','N-fixed','N-switch')
588  legend('N-adaptive','N-fixed')
589 
590  figure
591  plot(mean(t_Nadaptive,2),err_Nadaptive',...
592  'Color',linecolors{3},...
593  'LineStyle',linestyles{3},'Marker',markers{3},'LineWidth',linewidths(3));
594  hold on;
595  plot(mean(t_Nfix,2),err_Nfix',....
596  'Color',linecolors{2},...
597  'LineStyle',linestyles{2},'Marker',markers{2},'LineWidth',linewidths(2));
598 % hold on;
599 % plot(mean(t_Nswitch,2),err_Nswitch','r-');
600  xlabel('runtime')
601  ylabel('error')
602  set(gca,'Yscale','log')
603  title('error over runtime')
604 % legend('N-adaptive','N-fixed','N-switch')
605  legend('N-adaptive','N-fixed')
606 
607 % figure
608 % plot(Nav_Nadaptive,err_Nadaptive',...
609 % 'Color',linecolors{3},...
610 % 'LineStyle',linestyles{3},'Marker',markers{3});
611 % hold on;
612 % plot(Ns,err_Nfix',...
613 % 'Color',linecolors{2},...
614 % 'LineStyle',linestyles{2},'Marker',markers{2});
615 %% hold on;
616 %% plot(Nav_Nswitch,err_Nswitch','r-');
617 % xlabel('average N')
618 % ylabel('error')
619 % set(gca,'Yscale','log')
620 % title('error over average N')
621 %% legend('N-adaptive','N-fixed','N-switch')
622 % legend('N-adaptive','N-fixed')
623 
624  keyboard;
625 
626  disp('please save figures as eps and fig by hand.')
627 
628  otherwise
629  error('step number unknown!');
630 end;
631 
632 return;
633 
634 %| \docupdate