1 function res = rb_tutorial(step)
2 %
function res = rb_tutorial(step)
4 % step : index of experiment to be performed
5 % 1 - 10: Thermal block, elliptic PDE
6 % 11 - 17: Advection-Diffusion, parabolic PDE
8 % This program allows to reproduce the
thermalblock and advection-diffusion
9 % experiments of the RB-Summerschool and the pictures are used in the
10 % RB-Tutorial book chapter.
12 % B. Haasdonk: Reduced Basis Methods
for Parametrized PDEs --
13 % A Tutorial Introduction
for Stationary and Instationary Problems.
14 % Chapter in P. Benner, A. Cohen, M. Ohlberger and K. Willcox (eds.):
15 %
"Model Reduction and Approximation: Theory and Algorithms", SIAM, Philadelphia, 2016
17 % A Preprint version of this chapter is available at:
21 % B. Haasdonk, 7.9.2013
26 disp(
'now running step 1');
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 %PART 1: Stationary Thermalblock example
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 disp(
'thermal block for different configurations and corresponding plots');
39 params.mu_range = [0.1;10];
40 params.numintervals_per_block = 5;
42 model_data = gen_model_data(model);
44 plot_params.axis_equal = 1;
45 plot_params.axis_tight = 1;
47 % plot 1: four identical values
49 model = set_mu(model,[1,1,1,1]);
50 sim_data = detailed_simulation(model,model_data);
53 % plot 2: lower and upper values identical
55 model = set_mu(model,[0.1,0.1,10,10]);
56 sim_data = detailed_simulation(model,model_data);
59 % plot 3: four different values
61 model = set_mu(model,[0.3,0.2,0.2,0.7]);
62 sim_data = detailed_simulation(model,model_data);
65 % plot 4: larger division
66 % mu = rand(params.B1*params.B2,1)+0.1;
68 mu = [ 0.8094 0.8547 0.3760 0.7797 0.7551 0.2626, ...
69 0.2190 0.5984 1.0597 0.4404 0.6853 0.3238, ...
70 0.8513 0.3551 0.6060 0.7991 0.9909 1.0593 ...
71 0.6472 0.2386 0.2493 0.3575 0.9407 0.3543 ...
72 0.9143 0.3435 1.0293 0.4500 0.2966 0.3511 ...
73 0.7160 0.5733 0.4517 0.9308 0.6853 0.6497]
';
77 params.mu_range = [0.1;10];
78 model = thermalblock_model_struct(params);
79 model_data = gen_model_data(model);
80 model = set_mu(model,mu);
81 sim_data = detailed_simulation(model,model_data);
82 plot_sim_data(model,model_data,sim_data,plot_params);
85 disp('thermal block detailed gui
');
89 params.numintervals_per_block = 50;
90 params.mu_range = [0.1;10];
91 params.numintervals_per_block = 5;
92 model = thermalblock_model_struct(params);
93 model_data = gen_model_data(model);
95 plot_params.axis_equal = 1;
96 plot_params.axis_tight = 1;
97 plot_params.yscale_uicontrols = 0.7;
98 demo_detailed_gui(model,model_data,[],plot_params);
99 set(gcf,'Position
',[584 245 553 691]);
102 disp('equidistant samples
for basis generation, offline versus online time
');
107 params.numintervals_per_block = 20;
108 params.mu_range = [0.1;10];
109 disp('initializing model
')
110 model = thermalblock_model_struct(params);
112 disp('-----------------------------------------------------
')
113 disp('OFFLINE PHASE:
');
114 disp('generating model data: grid, fem inner product matrix, etc.
');
116 model_data = gen_model_data(model);
117 model.RB_generation_mode = 'lagrangian
';
118 model.RB_mu_list = lin_equidist_samples(model,[4,2,2,2]);
119 disp('generating detailed data: A_q,f_q,l_q components, reduced basis.
');
120 detailed_data = gen_detailed_data(model,model_data);
121 disp('generating reduced data: A_Nq,f_Nq,l_Nq components
');
122 reduced_data = gen_reduced_data(model, detailed_data);
124 disp('Offline time:
')
126 save('thermalblock_2x2_data
');
128 disp('-----------------------------------------------------
')
129 disp('ONLINE PHASE:
');
130 % online phase for single simulation:
131 disp('reduced simulation: assembling system and solve
');
132 model = set_mu(model,[1,1,1,1]);
134 sim_data = rb_simulation(model,reduced_data);
137 disp('Online time:
')
140 disp('starting reduced basis gui:
')
142 plot_params.axis_equal = 1;
143 plot_params.axis_tight = 1;
144 plot_params.yscale_uicontrols = 0.7;
145 demo_rb_gui(model,detailed_data,reduced_data,plot_params);
148 disp('1-parameter example: error, estimator, effectivity bound plot.
');
150 % generate reduced model
151 disp('generating reduced model
')
155 params.numintervals_per_block = 20;
156 params.mu_range = [0.1;10];
157 model = thermalblock_model_struct(params);
158 model_data = gen_model_data(model);
159 model.RB_generation_mode = 'lagrangian
';
161 mu_list = {[0.1,c,c,c],...
166 model.RB_mu_list = mu_list;
167 detailed_data = gen_detailed_data(model,model_data);
168 reduced_data = gen_reduced_data(model,detailed_data);
170 disp('computing parameter sweep
')
171 mu1s = linspace(0.1,4,1000);
172 % rapidly computable error landscape:
173 Deltas = zeros(length(mu1s),1);
174 for n = 1:length(mu1s)
176 mu = [mu1s(n),c,c,c];
177 model = set_mu(model,mu);
178 sim_data = rb_simulation(model,reduced_data);
179 Deltas(n) = sim_data.Delta;
182 plot(mu1s,Deltas,'Linewidth
',2);
183 xlabel('mu1
','Fontsize
',15);
184 ylabel('error/estimator
','Fontsize
',15);
185 title('error estimator by parameter sweep
','Fontsize
',15);
186 set(gca,'Yscale
','log
');
187 legend('estimator \Delta_u(\mu)
');
189 % comparison with expensive true error
191 disp('computing
true error
for some parameters
')
192 mu1s = linspace(0.1,4,40);
193 errs = zeros(length(mu1s),1);
194 for n = 1:length(mu1s)
196 mu = [mu1s(n),c,c,c];
197 model = set_mu(model,mu);
198 sim_data = detailed_simulation(model,model_data);
199 rb_sim_data = rb_simulation(model,reduced_data);
200 % linear combination of reduced vector with basis:
201 rb_sim_data= rb_reconstruction(model,detailed_data,rb_sim_data);
203 err.dofs = err.dofs - rb_sim_data.uh.dofs;
204 errs(n) = fem_h10_norm(err);
208 plot(mu1s,errs,'r*
','Markersize
',10);
209 legend({'estimator \Delta_u(\mu)
','true error |u-u_N|
'},'Fontsize
',15);
211 %set(gcf,'Position
', [379 492 434 328]);
212 %saveas(gcf,'error_parameter_sweep.png
');
213 %saveas(gcf,'error_parameter_sweep.eps
','epsc
');
215 save('rb_tutorial_step4
');
218 disp('Effectivity plot
');
219 load('rb_tutorial_step4
');
221 disp('computing parameter sweep
')
222 mu1s = linspace(0.1,4,40);
223 % rapidly computable error landscape:
224 Deltas = zeros(length(mu1s),1);
225 for n = 1:length(mu1s)
227 mu = [mu1s(n),0.1,0.1,0.1];
228 model = set_mu(model,mu);
229 sim_data = rb_simulation(model,reduced_data);
230 Deltas(n) = sim_data.Delta;
234 etas = Deltas.*(errs.^(-1));
238 plot(mu1s,etas,'b*
','Markersize
',10);
239 xlabel('\mu1
','Fontsize
',15);
240 ylabel('effectivity
','Fontsize
',15);
241 title('effectivity over parameter
','Fontsize
',15);
242 % set(gca,'Yscale
','log
');
247 effectivities = gammas/alpha;
248 plot(mu1s,effectivities,'r-
','Linewidth
',2);
250 legend({'effectivity \Delta_u/|u-u_N|
',...
251 'upper bound \gamma(\mu)/\alpha(\mu)
'},...
253 'Location
','NorthWest
');
255 % set(gcf,'Position
', [379 492 434 328]);
256 % saveas(gcf,'effectivity_parameter_sweep.png
');
257 % saveas(gcf,'effectivity_parameter_sweep.eps
','epsc
');
260 disp('Convergence plot
for test error on equidistant samples
');
265 params.numintervals_per_block = 20;
266 params.mu_range = [0.5;2];
267 model = thermalblock_model_struct(params);
268 model_data = gen_model_data(model);
269 model.RB_generation_mode = 'model_RB_basisgen
';
270 model.RB_basisgen = @lagrangian_orth_basisgen;
271 Ns = 2:8; % linear dependent for higher values...
273 maxDeltas = zeros(length(Ns),1);
274 maxerrs = zeros(length(Ns),1);
276 disp('Precomputing test snapshots
');
278 [U,test_mus] = filecache_function(@precompute_test_snapshots,...
279 params,model,model_data,ntest);
281 disp('Generating basis and determining max error, estimators
');
283 for Ni = 1:length(Ns)
285 train_mu1s = linspace(params.mu_range(1),params.mu_range(2),N);
286 train_mus = [train_mu1s(:), ones(N,params.B1*params.B2-1)*1];
287 model.RB_mu_list = mat2cell(train_mus,ones(N,1),params.B1*params.B2);
288 detailed_data = gen_detailed_data(model,model_data);
289 reduced_data = gen_reduced_data(model,detailed_data);
291 model = set_mu(model,test_mus(i,:));
292 rb_sim_data = rb_simulation(model, reduced_data);
293 rb_sim_data = rb_reconstruction(model,detailed_data,rb_sim_data);
294 err = rb_sim_data.uh;
295 err.dofs = err.dofs - U(:,i);
296 errnorm = fem_h10_norm(err);
297 if maxerrs(Ni)<errnorm
300 if maxDeltas(Ni)<rb_sim_data.Delta
301 maxDeltas(Ni)=rb_sim_data.Delta;
307 save('rb_tutorial_step6
');
308 % case 6.1 % plot of error convergenc
309 % load('rb_tutorial_step6
');
310 plot(Ns,maxDeltas,'b-
','Linewidth
',2);
312 plot(Ns,maxerrs,'r:
','Linewidth
',2);
313 set(gca,'Yscale
','log
');
314 legend({'estimator \Delta_u(\mu)
','error |u(\mu)-u_N(\mu)|
'},'Fontsize
',15);
315 title('test error decay
for growing sample size
','Fontsize
',15);
316 xlabel('sample/basis Size N
','Fontsize
',15);
317 ylabel('error/estimator
','Fontsize
',15);
319 % set(gcf,'Position
', [379 492 434 328]);
320 % saveas(gcf,'lagrangian_error_convergence.png
');
321 % saveas(gcf,'lagrangian_error_convergence.eps
','epsc
');
325 load('rb_tutorial_step6
');
327 plot_params.axis_equal = 1;
328 plot_params.axis_tight = 1;
329 plot_params.plot = @plot_vertex_data;
330 plot_params.title='Orthonormal Reduced Basis \Phi_N
';
332 plot_sequence(detailed_data.RB,detailed_data.grid,plot_params);
335 plot_params.show_colorbar = 0;
336 plot_params.no_lines = 1;
340 plot_vertex_data(detailed_data.grid,detailed_data.RB(:,n), ...
342 title(['n=
',num2str(n)],'Fontsize
',10);
346 set(gcf,'Position
',[ 32 254 1554 701 ]);
347 saveasshown(gcf,'orthonormal_basis.png
');
348 saveasshown(gcf,'orthonormal_basis.eps
','epsc
');
351 disp('Greedy error convergence
');
356 params.numintervals_per_block = 20;
357 params.mu_range = [0.5;2];
358 model = thermalblock_model_struct(params);
359 model_data = gen_model_data(model);
360 model.RB_stop_epsilon = 1e-6;
361 model.RB_stop_Nmax = 50;
362 model.RB_train_size = 1000;
364 disp('Generating basis and determining max error, estimators
');
366 detailed_data = gen_detailed_data(model,model_data);
367 reduced_data = gen_reduced_data(model,detailed_data);
369 disp('Precomputing test snapshots
');
371 [U,test_mus] = filecache_function(@precompute_test_snapshots,...
372 params,model,model_data,ntest);
374 Ns = 1:size(detailed_data.RB,2);
375 maxDeltas = zeros(length(Ns),1);
376 maxerrs = zeros(length(Ns),1);
377 for Ni = 1:length(Ns)
380 reduced_data_subset = model.reduced_data_subset(model,reduced_data);
382 model = set_mu(model,test_mus(i,:));
383 rb_sim_data = rb_simulation(model, reduced_data_subset);
384 rb_sim_data = rb_reconstruction(model,detailed_data,rb_sim_data);
385 err = rb_sim_data.uh;
386 err.dofs = err.dofs - U(:,i);
387 errnorm = fem_h10_norm(err);
388 if maxerrs(Ni)<errnorm
391 if maxDeltas(Ni)<rb_sim_data.Delta
392 maxDeltas(Ni)=rb_sim_data.Delta;
397 save('rb_tutorial_step8
');
400 disp('plot of greedy errors
');
401 load('rb_tutorial_step8
');
403 plot(Ns,maxDeltas,'b-
','Linewidth
',2);
405 plot(Ns,maxerrs,'r:
','Linewidth
',2);
406 set(gca,'Yscale
','log
');
407 % if wanted, training error can be plotted
408 % plot(Ns(1:end-2),detailed_data.RB_info.max_err_est_sequence(2:end),...
409 % 'g-.
','Linewidth
',2);
410 set(gca,'Yscale
','log
');
411 legend({'test estimator \Delta_u(\mu)
','test error |u(\mu)-u_N(\mu)|
'},'Fontsize
',15);
412 title('Error decay
for Greedy basis
','Fontsize
',15);
413 xlabel('sample/basis Size N
','Fontsize
',15);
414 ylabel('error/estimator
','Fontsize
',15);
416 % set(gcf,'Position
', [379 492 434 328]);
417 % saveas(gcf,'greedy_test_error.png
');
418 % saveas(gcf,'greedy_test_error.eps
','epsc
');
420 % possible further cases:
421 % plot of sample points: not spectacular...
422 % load('rb_tutorial_step8
');
423 % mus = detailed_data.RB_info.max_mu_sequence;
424 % mumat = cell2mat(mus)
425 % plot(mumat(1,:),mumat(2,:),'*
');
428 disp('experiment with basis from 4
');
430 load('rb_tutorial_step4
');
432 mus= {[1,0.2,0.2,0.2],[1,0.1,1,0.1]};
433 for i = 1:length(mus)
434 disp('-------------------------------------------
')
435 disp(['Experiment
for mu = (
',num2str(mus{i}),')
']);
436 model = set_mu(model,mus{i});
437 sim_data = detailed_simulation(model,model_data);
438 rb_sim_data = rb_simulation(model,reduced_data);
439 rb_sim_data = rb_reconstruction(model,detailed_data,rb_sim_data);
440 disp(['output s(mu) =
', num2str(sim_data.s)]);
441 disp(['output s_N(mu) =
', num2str(rb_sim_data.s)]);
442 disp(['output error s(mu)-s_N(mu) =
', ...
443 num2str(sim_data.s-rb_sim_data.s)]);
444 disp(['output error bound Delta_s(\mu) =
', num2str(rb_sim_data.Delta_s)]);
446 err.dofs = err.dofs - rb_sim_data.uh.dofs;
447 disp(['field error |u-u_N| =
',num2str(fem_h10_norm(err))]);
448 disp(['field error bound Delta_u(\mu) =
', num2str(rb_sim_data.Delta)]);
452 disp('convergence curves, training error
for different block numbers
');
457 max_err_est_sequences = {};
459 for bi = 1:length(B1S)
463 disp('--------------------------------------------------
');
464 disp(['generating basis
for (B1,B2) = (
',...
465 num2str(params.B1),',
',num2str(params.B2),')
']);
466 params.numintervals_per_block = 20;
467 params.mu_range = [0.5;2];
468 model = thermalblock_model_struct(params);
469 model_data = gen_model_data(model);
470 model.RB_stop_epsilon = 1e-6;
471 model.RB_stop_Nmax = 50;
472 model.RB_train_size = 1000;
473 detailed_data = gen_detailed_data(model,model_data);
474 max_err_est_sequences = [max_err_est_sequences,...
475 {detailed_data.RB_info.max_err_est_sequence}]
478 % save('rb_tutorial_step10
');
479 % case 10.1 % plot training error curves
480 % load('rb_tutorial_step10
');
485 styles = {'b-
','r-
','g-
','k-
'}
486 for i=1:length(max_err_est_sequences)
487 seq = max_err_est_sequences{i};
488 plot(0:length(seq)-1,seq,styles{i});
489 legstr = [legstr,{['(B1,B2)= (
',...
490 num2str(B1S(i)),',
',num2str(B2S(i)),')
']}]
492 legend(legstr,'Fontsize
',15);
493 title('greedy training error decay
','Fontsize
',15);
494 xlabel('basis size N
','Fontsize
',15);
495 ylabel('training error
','Fontsize
',15);
496 set(gca,'Yscale
','log
');
498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
499 %PART 2: Instationary Advection-diffusion example
500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
503 disp('full simulation of advection-diffusion problem.
');
506 params.coarse_factor = 4;
507 model = advection_diffusion_fv_model(params);
508 model_data = gen_model_data(model);
510 plot_params.axis_equal = 1;
511 plot_params.axis_tight = 1;
512 plot_params.no_lines = 1;
514 model = set_mu(model,[1,0.1]);
515 tic; sim_data = detailed_simulation(model,model_data);
516 disp('time
for full simulation (seconds):
')
518 plot_sim_data(model,model_data,sim_data,plot_params);
521 disp('generate plots of varying mu and t:
');
524 params.coarse_factor = 4;
525 model = advection_diffusion_fv_model(params);
526 model_data = gen_model_data(model);
528 plot_params.axis_equal = 1;
529 plot_params.axis_tight = 1;
530 plot_params.no_lines = 1;
531 plot_params.show_colorbar = 0;
532 plot_params.clim = [0,1];
534 mus = {[0,0],[1,0],[1,1]};
536 snapshots = cell(3,3);
537 for mi = 1:length(mus)
538 model = set_mu(model,mus{mi});
539 sim_data = detailed_simulation(model,model_data);
540 for ti = 1:length(ts);
541 snapshots{mi,ti} = sim_data.U(:,ts(ti));
542 plot_element_data(model_data.grid,...
543 sim_data.U(:,ts(ti)),plot_params);
546 saveas(gcf,['advection_diffusion_snapshot-m
',num2str(mi),...
547 '-t
',num2str(ti),'.png
']);
548 saveas(gcf,['advection_diffusion_snapshot-m
',num2str(mi),...
549 '-t
',num2str(ti),'.eps
'],'epsc
');
555 for mi = 1:length(mus)
556 for ti = 1:length(ts);
557 subplot(3,3,(ti-1)*3 + mi);
558 plot_element_data(model_data.grid,...
559 snapshots{mi,ti} ,plot_params);
564 title(['\mu = (
',num2str(mu(1)),',
',num2str(mu(2)),')^T
'],...
569 pos = [354 335 1241 613]
570 set(gcf,'Position
',pos);
571 disp('please
do a manual => File => Export Setup => Export
');
572 disp('as files advection_diffusion_snapshots.png and *.eps
');
573 % saveas(gcf,'advection_diffusion_snapshots.png
');
574 % saveas(gcf,'advection_diffusion_snapshots.eps
','epsc
');
577 disp('POD-
Greedy basis generation, caution takes +- 1 hour!
');
580 params.coarse_factor = 4;
581 model = advection_diffusion_fv_model(params);
582 model_data = gen_model_data(model);
584 % POD-Greedy settings:
586 % choose initial data components as initial basis:
587 model.rb_init_data_basis = @RB_init_data_basis;
588 % or choose empty initial basis:
589 %model.rb_init_data_basis = @RB_init_basis_empty;
591 model.RB_generation_mode = 'greedy_uniform_fixed
';
592 model.RB_extension_algorithm = @RB_extension_PCA_fixspace;
593 model.RB_stop_epsilon = 1e-2;
594 model.RB_stop_timeout = 2*60*60; % 2 hours
595 model.RB_stop_Nmax = 100;
596 % decide, whether estimator or true error is error-indicator for greedy
597 % params.RB_error_indicator = 'error
'; % true error, i.e. strong POD-greedy
598 model.RB_error_indicator = 'estimator
'; % Delta from rb_simulation
600 % choose a 10x10 uniform grid
601 model.RB_numintervals = 9 * ones(size(model.mu_names));
603 detailed_data = gen_detailed_data(model,model_data);
605 save rb_tutorial_step_13.mat;
608 disp('plot first 16 snapshots and point distribution
');
610 load rb_tutorial_step_13.mat;
613 plot_params.axis_equal = 1;
614 plot_params.axis_tight = 1;
615 plot_params.no_lines = 1;
616 plot_params.show_colorbar = 0;
618 plot_detailed_data(model,detailed_data);
620 disp('inspect diagrams and press enter to
continue')
623 close(4); % runtime plot not too interesting
624 title('maximal POD-
Greedy training estimator
','Fontsize
',15);
625 xlabel('basis vector number N
','Fontsize
',15);
626 ylabel('estimator
','Fontsize
',15);
627 saveas(gcf,'PODgreedy_train_estimator_advection_diffusion.png
');
628 saveas(gcf,'PODgreedy_train_estimator_advection_diffusion.eps
','epsc
');
629 close(3); % training error decay only partially interesting
631 title('POD-
Greedy parameter selection
','Fontsize
',15);
632 xlabel('mu1
','Fontsize
',15);
633 ylabel('mu2
','Fontsize
',15);
634 set(gcf,'Color
',[1,1,1]);
635 % export_fig('PODgreedy_points_advection_diffusion.png
',gcf);
636 saveas(gcf,'PODgreedy_points_advection_diffusion.png
');
637 saveas(gcf,'PODgreedy_points_advection_diffusion.eps
','epsc
');
642 plot_element_data(detailed_data.grid,detailed_data.RB(:,n), ...
644 title(['n=
',num2str(n)],'Fontsize
',15);
648 set(gcf,'Position
',[32 49 1569 906]);
649 saveas(gcf,'basis_advection_diffusion.png
');
650 saveas(gcf,'basis_advection_diffusion.eps
','epsc
');
653 % plot_params.axis_equal = 1;
654 % plot_params.axis_tight = 1;
655 % plot_params.no_lines = 1;
658 disp('reduced simulation
');
660 load rb_tutorial_step_13.mat;
661 reduced_data = gen_reduced_data(model,detailed_data);
664 model = set_mu(model,[1,0.1]);
665 rb_sim_data = rb_simulation(model,reduced_data);
666 disp('time
for reduced simulation (in seconds):
')
668 rb_sim_data = rb_reconstruction(model,detailed_data,rb_sim_data);
671 plot_params.axis_equal = 1;
672 plot_params.axis_tight = 1;
673 plot_params.no_lines = 1;
674 plot_params.show_colorbar = 0;
676 plot_sim_data(model,model_data,rb_sim_data,plot_params);
677 disp('press enter
for rb simulation gui
')
680 demo_rb_gui(model,detailed_data,[],plot_params,'rb simulation
');
682 disp('press enter
for rb error simulation gui
')
685 plot_params.show_colorbar = 1;
686 demo_rb_error_gui(model,detailed_data,[],plot_params,'rb error simulation
');
689 disp('error, estimator by parameter sweep
');
691 % sweep along the diagonal of the parameter space, i.e.
692 % some training points, but ´mostly test-points
694 load rb_tutorial_step_13.mat;
695 reduced_data = gen_reduced_data(model,detailed_data);
697 ntest = 101; % higher later, take care that 10x10 training grid is contained
699 % RandStream.setDefaultStream(RandStream('mt19937ar
','seed
', ...
701 % mu_test = rand_uniform(ntest,model.mu_ranges);
703 mu_test = [1;1]*(0:(ntest-1))/(ntest-1)
705 errs_max_t = zeros(ntest,1);
706 errs_final_t = zeros(ntest,1);
707 Deltas_final_t = zeros(ntest,1);
709 W = model.get_inner_product_matrix(detailed_data);
711 disp(['processing parameter
',num2str(mi),'/
',num2str(ntest)]);
712 model = model.set_mu(model,mu_test(:,mi));
713 sim_data = detailed_simulation(model,model_data);
714 rb_sim_data = rb_simulation(model,reduced_data);
715 rb_sim_data = rb_reconstruction(model,detailed_data, ...
717 errs = rb_sim_data.U(:,model.save_time_indices+1) -sim_data.U;
718 err_norms = sqrt(sum(errs.* (W * errs)));
719 errs_final_t(mi) = err_norms(end);
720 errm = max(err_norms);
721 errs_max_t(mi) = errm(1);
722 Deltas_final_t(mi) = rb_sim_data.Delta(end);
724 p = plot(mu_test(2,:),[errs_max_t(:),Deltas_final_t(:)]);
725 set(p,'Linewidth
',2);
726 set(p(2),'Linestyle
','-.
');
727 title('error and error estimator at
final time t=T
','Fontsize
',15);
728 legend({'error
','estimator
'},'Fontsize
',15);
729 set(gca,'Yscale
','log
');
730 ylabel('error/estimator
','Fontsize
',15);
731 xlabel('parameter scaling factor s
','Fontsize
',15);
733 saveas(gcf,'advection-diffusion-error-parameter-sweep.png
');
734 saveas(gcf,'advection-diffusion-error-parameter-sweep.eps
','epsc
');
735 saveas(gcf,'advection-diffusion-error-parameter-sweep.fig
');
738 disp('Effectivity computation
for 200 random points
');
740 % plot: test effectivity over diffusivity parameter
742 load rb_tutorial_step_13.mat;
743 reduced_data = gen_reduced_data(model,detailed_data);
745 if matlab_version> 7.9
746 s = RandStream('mt19937ar
','Seed
',12345)
747 RandStream.setGlobalStream(s);
749 RandStream.setDefaultStream(RandStream('mt19937ar
','seed
', ...
753 ntest = 200; % higher later
754 mu_test = rand_uniform(ntest,model.mu_ranges);
755 errs_max_t = zeros(ntest,1);
756 errs_final_t = zeros(ntest,1);
757 Deltas_final_t = zeros(ntest,1);
760 disp(['processing parameter
',num2str(mi),'/
',num2str(ntest)]);
761 model = model.set_mu(model,mu_test(:,mi));
762 sim_data = detailed_simulation(model,model_data);
763 rb_sim_data = rb_simulation(model,reduced_data);
764 rb_sim_data = rb_reconstruction(model,detailed_data, ...
766 errs = rb_sim_data.U(:,model.save_time_indices+1) -sim_data.U;
767 err_norms = sqrt(sum(errs.* (model.get_inner_product_matrix(detailed_data) * errs)));
768 errs_final_t(mi) = err_norms(end);
769 errm = max(err_norms);
770 errs_max_t(mi) = errm(1);
771 Deltas_final_t(mi) = rb_sim_data.Delta(end);
774 % [mu_sort,ind ] = sort(mu_test(2,:));
775 % plot(mu_test(2,ind),[Deltas_final_t(ind)./errs_max_t(ind)]);
777 [mu_sort,ind ] = sort(mu_test(1,:));
778 plot(mu_test(1,ind),[Deltas_final_t(ind)./errs_max_t(ind)],'b*
');
779 ylim = get(gca,'Ylim
');
781 set(gca,'Ylim
',ylim);
783 % plot: maximum test error over Basis size
784 title('effectivities at
final time t=T over test set
','Fontsize
',15);
785 ylabel('effectivity
','Fontsize
',15);
786 xlabel('velocity weight mu1
','Fontsize
',15);
788 saveas(gcf,'advection-diffusion-effectivity.png
');
789 saveas(gcf,'advection-diffusion-effectivity.eps
','epsc
');
790 saveas(gcf,'advection-diffusion-effectivity.fig
');
793 disp('step number unknown
');
797 function mu_list = lin_equidist_samples(model,numintervals)
798 % generate cell array of parameter vectors
799 % numintervals a vector of number of equal sized intervals per
800 % parameter direction
802 p.range = model.mu_ranges;
803 p.numintervals = numintervals;
805 mu_list = mat2cell(c.vertex,ones(size(c.vertex,1),1),...
808 function [U,test_mus] = precompute_test_snapshots(params,model,model_data,ntest)
809 % function precomputing test snapshots for step 6
810 test_mu1s = rand_uniform(ntest,{params.mu_range});
811 test_mus = [test_mu1s(:), ones(ntest,params.B1*params.B2-1)*1];
812 U = zeros(model_data.df_info.ndofs,0);
815 model = set_mu(model,test_mus(i,:));
816 sim_data = detailed_simulation(model, model_data);
817 U = [U,sim_data.uh.dofs(:)];
821 function RB = lagrangian_orth_basisgen(model, ...
824 for m = 1:length(model.RB_mu_list)
825 model = set_mu(model,model.RB_mu_list{m});
826 sim_data = detailed_simulation(model,detailed_data);
828 Utot = model.get_dofs_from_sim_data(sim_data);
830 U = model.get_dofs_from_sim_data(sim_data);
834 % Gram-Schmidt orthonormalization
835 %KN = Utot'*model.get_inner_product_matrix(detailed_data)*Utot;
836 %KN = 0.5*(KN + KN
');
837 % This does no longer work with recent matlab:
839 %RB = Utot / Ltransp;
840 RB = orthonormalize_qr(Utot,model.get_inner_product_matrix(detailed_data),1e-12);
function model = thermalblock_model_struct(params)
Thermal Block example similar as described in the book of A.T. patera and G. Rozza (just one paramete...
function p = plot_sim_data(model, model_data, sim_data, plot_params)
function performing the plot of the simulation results as specified in model.
Customizable implementation of an abstract greedy algorithm.
function res = thermalblock(step, params)
thermalblock example