3 % script performing the experiments
for the N-adaptivity with the
4 % extended error estimator
6 % Bernard Haasdonk 7.11.2008
8 %step = 1 % generate figures
9 %step = 2 % perform time measurements and plot time over error/estimator/Nav
10 %step = 3 % profiling non-adaptive
11 %step = 4 % profiling adaptive
12 %step = 5 % simulation with longer time
13 step = 6 % new figures ignoring error
15 disp('preparing simulations:');
16 load demo_lin_evol_detailed_data;
17 offline_data = rb_offline_prep(detailed_data,params);
19 %params.N_adaptivity =
'off';
20 %params.N = 10 %
set max!
21 %params.error_norm =
'l1l2';
23 params.N_mode =
'adapt';
24 params.N = 100; %
set max!
25 %params.N = size(detailed_data.RB,2); %
set max!
26 %params.error_norm =
'l1l2';
27 params.error_norm =
'l2';
29 % the following illustrates non-rigorous error-estimator for adaptivity!!!!
30 params.N_adapt_epsilon = 1e-4;
31 %params.N_adapt_epsilon = 2e-5;
32 %params.N_adapt_epsilon = 1e-8;
33 params.N_adapt_look_ahead_nt = 20;
34 params.N_adapt_slope = 10;
35 % params.N_adapt_epsilon = 1e-3; => everything over 50% N
36 %params = set_mu([1,1,0],params); % convection
37 params = set_mu([1,0,1e-9],params); % convection
38 %params = set_mu([1,0,0],params); % convection => super
"prediction"
39 %params = set_mu([1,1,5e-8],params); % diffusion
40 %params = set_mu([0,1,5e-8],params); % diffusion
41 reduced_data = rb_online_prep(offline_data, params);
46 disp(
'detailed_simulation:');
47 %params = set_mu([1,0,1e-9],params); % convection
48 params = set_mu([1,0,0],params); % convection
49 params.N_adapt_epsilon = 5e-5;
50 params.N_adapt_look_ahead_nt = 10;
51 params.N_adapt_slope = 5;
52 U = detailed_simulation(detailed_data.grid,params);
53 disp(
'reduced_simulation:');
54 simulation_data = rb_simulation(reduced_data,params);
55 Uappr = rb_reconstruction(detailed_data,simulation_data);
56 err = fv_error(Uappr,U,detailed_data.W,params);
57 % params.title =
'reduced simulation result';
58 % plot_element_data_sequence(detailed_data.grid,Uappr,params);
59 if isfield(simulation_data,
'N');
60 Ns = simulation_data.N;
62 Ns = params.N * ones(1,params.nt+1);
64 figure; % subplot(2,1,2);
65 plot([0:params.nt],Ns);
66 title(
'model dimension N');
67 set(gca,
'XLim',[0,params.nt]);
68 set(gca,
'YLim',[0,100]);
69 xlabel(
'time index k');
70 set(gcf,
'Position',[472 404 564 238]);
71 saveas(gcf,
'Nadaptive_error',
'epsc');
73 figure, plot([0:params.nt],[simulation_data.Delta;...
74 0:(params.N_adapt_epsilon)/params.nt:params.N_adapt_epsilon;err]
');
75 legend({'estimator
','target
','error
'},'location
','west
');
76 title('error estimator evolution
');
77 set(gca,'XLim
',[0,params.nt]);
78 xlabel('time index k
');
79 set(gcf,'Position
',[472 404 564 238]);
80 disp('please save figure as eps (automatic saving does not
get aspectratio)
')
81 %saveas(gcf,'Nadaptive_Ns
','epsc
');
83 %plot_element_data_sequence(detailed_data.grid,Uappr,params);
84 %plot_element_data_sequence(detailed_data.grid,Uappr-U,params);
86 params.N_mode = 'fixed
';
88 reduced_data = rb_online_prep(offline_data, params);
89 disp('reduced_simulation:
');
90 simulation_data = rb_simulation(reduced_data,params);
91 Uappr = rb_reconstruction(detailed_data,simulation_data);
92 err = fv_error(Uappr,U,detailed_data.W,params);
93 % params.title = 'reduced simulation result
';
94 % plot_element_data_sequence(detailed_data.grid,Uappr,params);
95 if isfield(simulation_data,'N
');
96 Ns = simulation_data.N;
98 Ns = params.N * ones(1,params.nt+1);
100 figure, subplot(2,1,2); plot([0:params.nt],Ns);
101 title('model dimension N
');
102 set(gca,'XLim
',[0,params.nt]);
103 set(gca,'YLim
',[0,100]);
104 xlabel('time index k
');
105 subplot(2,1,1), plot([0:params.nt],[simulation_data.Delta;...
106 0:(params.N_adapt_epsilon)/params.nt:params.N_adapt_epsilon;err]');
107 legend({
'estimator',
'target',
'error'},
'location',
'northwest');
108 title(
'error estimator evolution');
109 set(gca,
'XLim',[0,params.nt]);
110 xlabel(
'time index k');
111 disp(
'please save figure as eps (automatic saving does not get aspectratio)')
120 t_exact = zeros(1,nrep);
121 disp('detailed_simulation:');
123 tic, U = detailed_simulation(detailed_data.grid,params);
126 disp(' time av(N) Delta err ');
127 disp(['Exact simulation: ', ...
128 num2str(mean(t_exact)), '+-',num2str(std(t_exact)),...
129 ' ', num2str(detailed_data.grid.nelements),' 0 0 ']);
131 disp('reduced_simulations, fixed Ns:');
132 Ns = [100,85,70,55,40,25,10];
133 t_Nfix = zeros(length(Ns),nrep);
134 Delta_Nfix = zeros(size(Ns));
135 % prevent matrix inversion for fair comparison
136 params.skip_matrix_inversion = 1;
137 params.N_mode = 'fixed';
140 dummy_reduced_data = rb_online_prep(offline_data, params);
141 dummy = rb_simulation(dummy_reduced_data,params);
145 simulation_data = [];
147 reduced_data = rb_online_prep(offline_data, params);
149 simulation_data = rb_simulation(reduced_data,params);
151 Uappr = rb_reconstruction(detailed_data,simulation_data);
152 err = fv_error(Uappr,U,detailed_data.W,params);
153 err_Nfix(n) = max(err);
154 Delta_Nfix(n) = simulation_data.Delta(end);
155 % disp(['N = ',num2str(Ns(n)),' ',num2str(t_Nfix(n,r)),' ',...
156 % num2str(Ns(n)),' ',...
157 % num2str(Delta_Nfix(n)),' ',num2str(err_Nfix(n))]);
162 disp(['N = ',num2str(Ns(n)),' ',num2str(mean(t_Nfix(n,:))),...
163 '+-',num2str(std(t_Nfix(n,:))),' ',...
164 num2str(Ns(n)),' ',...
165 num2str(Delta_Nfix(n)),' ',num2str(err_Nfix(n))]);
168 disp('reduced_simulations, adaptive Ns:');
169 epsilons = [5e-6,1e-5,5e-5,1e-4,5e-4,1e-3];
170 Delta_Nadaptive = zeros(size(epsilons));
171 t_Nadaptive = zeros(length(epsilons),nrep);
172 Nav_Nadaptive = zeros(size(epsilons));
173 params.N = 100; %size(detailed_data.RB,2);
174 reduced_data = rb_online_prep(offline_data, params);
175 params.N_mode = 'adapt';
178 for e = 1:length(epsilons)
180 params.N_adapt_epsilon = epsilons(e);
182 simulation_data = rb_simulation(reduced_data,params);
183 t_Nadaptive(e,r)= toc;
184 Uappr = rb_reconstruction(detailed_data,simulation_data);
185 err = fv_error(Uappr,U,detailed_data.W,params);
186 err_Nadaptive(e) = max(err);
187 Delta_Nadaptive(e) = simulation_data.Delta(end);
188 Nav_Nadaptive(e) = mean(simulation_data.N);
189 % disp(['epsilon = ',num2str(epsilons(e)),...
190 % ' ',num2str(t_Nadaptive(e,r)),' ',num2str(Nav_Nadaptive(e)),...
192 % num2str(Delta_Nadaptive(e)),' ',num2str(err_Nadaptive(e))]);
196 for e = 1:length(epsilons)
197 disp(['epsilon = ',num2str(epsilons(e)),...
198 ' ',num2str(mean(t_Nadaptive(e,:))),'+-',...
199 num2str(std(t_Nadaptive(e,:))),' ',num2str(Nav_Nadaptive(e)),...
201 num2str(Delta_Nadaptive(e)),' ',num2str(err_Nadaptive(e))]);
205 plot(mean(t_Nadaptive,2),Delta_Nadaptive','b-');
207 plot(mean(t_Nfix,2),Delta_Nfix','g-');
209 % plot(mean(t_Nswitch,2),Delta_Nswitch','r-');
212 ylabel('error estimator')
213 set(gca,'Yscale','log')
214 title('error estimator over runtime')
215 % legend('N-adaptive','N-fixed','N-switch')
216 legend('N-adaptive','N-fixed')
219 plot(mean(t_Nadaptive,2),err_Nadaptive','b-');
221 plot(mean(t_Nfix,2),err_Nfix','g-');
223 % plot(mean(t_Nswitch,2),err_Nswitch','r-');
226 set(gca,'Yscale','log')
227 title('error over runtime')
228 % legend('N-adaptive','N-fixed','N-switch')
229 legend('N-adaptive','N-fixed')
232 plot(Nav_Nadaptive,err_Nadaptive','b-');
234 plot(Ns,err_Nfix','g-');
236 % plot(Nav_Nswitch,err_Nswitch','r-');
239 set(gca,'Yscale','log')
240 title('error over average N')
241 % legend('N-adaptive','N-fixed','N-switch')
242 legend('N-adaptive','N-fixed')
244 case 3 % profiling non-adaptivity
245 % => 56.80 fuer bicgstab, 4.17 fuer res_norm_sqr
249 disp('without adaptivity:');
250 params.N_mode = 'fixed';
251 params.skip_matrix_inversion = 1;
255 simulation_data = rb_simulation(reduced_data,params);
259 profsave(profile('info'),'profile_results_non_adaptive')
262 case 4 % profiling non-adaptivity
263 % => 39.19 sec fuer bicgstab, 3.57 fuer res_norm_sqr
266 disp('with adaptivity:');
267 params.N_mode = 'adapt';
271 simulation_data = rb_simulation(reduced_data,params);
275 profsave(profile('info'),'profile_results_adaptive')
277 case 5 % test: adaptive and fixed N should give identical result!
280 disp('detailed_simulation:');
281 U = detailed_simulation(detailed_data.grid,params);
282 % prevent matrix inversion for fair comparison
283 params.N_mode = 'fixed';
284 params.skip_matrix_inversion = 1;
286 simulation_data_fix = [];
287 reduced_data = rb_online_prep(offline_data, params);
288 simulation_data_fix = rb_simulation(reduced_data,params);
289 Uappr_fix = rb_reconstruction(detailed_data,simulation_data_fix);
290 err_fix = fv_error(Uappr_fix,U,detailed_data.W,params);
291 disp(['error fixed N=100: ',num2str(err_fix(end))]);
293 disp('reduced_simulations, adaptive Ns:');
294 params.N = 100; %size(detailed_data.RB,2);
295 params.N_mode = 'adapt';
296 reduced_data = rb_online_prep(offline_data, params);
297 simulation_data_adapt =[];
298 params.N_adapt_epsilon = 1e-6;
299 simulation_data_adapt = rb_simulation(reduced_data,params);
300 Uappr_adapt = rb_reconstruction(detailed_data,simulation_data_adapt);
301 err_adapt = fv_error(Uappr_adapt,U,detailed_data.W,params);
302 disp(['error adapt N=100: ',num2str(err_adapt(end))]);
304 case 6 % new figures: no error....
306 linestyles = {
'-.',
'-',
'-',
':'};
307 linecolors = {[0,0,1],[0,0.5,0],[1,0,0],[0,0,0]};
308 linewidths = [1,1,2,2];
310 params = set_mu([1,0,0],params); % convection
311 params.N_adapt_epsilon = 5e-5;
312 params.N_adapt_look_ahead_nt = 20;
313 params.N_adapt_slope = 10;
314 disp(
'reduced_simulation:');
315 simulation_data = rb_simulation(reduced_data,params);
317 params.N_mode =
'fixed';
319 reduced_data = rb_online_prep(offline_data, params);
320 disp(
'reduced_simulation:');
321 simulation_data_N1 = rb_simulation(reduced_data,params);
323 reduced_data = rb_online_prep(offline_data, params);
324 disp(
'reduced_simulation:');
325 simulation_data_N2 = rb_simulation(reduced_data,params);
326 %Uappr = rb_reconstruction(detailed_data,simulation_data);
327 if isfield(simulation_data,
'N');
328 Ns = simulation_data.N;
330 Ns = params.N * ones(1,params.nt+1);
332 figure; % subplot(2,1,2);
333 p = plot([0:params.nt],[ones(size(Ns))*20;ones(size(Ns))*60;Ns]
');
335 set(p(i),'Color
',linecolors{i},...
336 'LineWidth
',linewidths(i),...
337 'LineStyle
',linestyles{i})
339 %set(p(3),'LineWidth
',2);
340 %set(p(1),'LineStyle
','-.');
341 title(
'model dimension N');
342 legend(
'N-fixed N=20',
'N-fixed N=60',
'N-adaptive')
343 set(gca,'XLim',[0,params.nt]);
344 set(gca,'YLim',[0,100]);
345 xlabel('time index k');
346 saveas(gcf,'Nadaptive_error_large','epsc');
347 set(gcf,'Position',[472 404 564 238]);
349 figure, p = plot([0:params.nt],[simulation_data_N1.Delta; ...
350 simulation_data_N2.Delta;...
351 simulation_data.Delta;...
352 0:(params.N_adapt_epsilon)/params.nt:params.N_adapt_epsilon
356 set(p(i),'Color',linecolors{i},...
357 'LineWidth',linewidths(i),...
358 'LineStyle',linestyles{i})
361 %
set(p(1),
'LineStyle',
'-.');
362 %
set(p(4),
'LineStyle',
':');
363 %
set(p(3),
'LineWidth',2);
364 title(
'error estimator evolution');
365 l = legend({
'N-fixed, N=20',
'N-fixed, N=60', ...
367 'N-adaptive-target'},
'location',
'northwest');
368 set(gca,
'XLim',[0,params.nt]);
369 xlabel(
'time index k');
370 saveas(gcf,
'Nadaptive_Ns_large',
'epsc');
371 set(gcf,
'Position',[472 404 564 238]);
372 po =
get(l,
'Position');
373 set(l,
'Position',po);
374 disp(
'please save figures as eps (automatic saving does not get aspectratio)')
377 error('step unknown');