1 % small script performing a reduced basis simulation with the
2 % linear and nonlinear scheme and plotting the results
4 %
for a single parameter a whole range of M and N is tried in the
5 % nonlinear simulation. The error is computed not to the detailed
6 % model, but to the large-N linear-evolution model as a substitute
8 % Bernard Haasdonk 24.6.2007
10 % prepare and run nonlin_evol simulation
14 % detailed_data = rb_detailed_prep(params);
16 % load demo_nonlin_evol_detailed_data_LE_on_RB_wo_offset;
18 %load demo_nonlin_evol_detailed_data3;
19 %load demo_nonlin_evol_detailed_data_LE_trajectory_1_1_0;
20 load demo_nonlin_evol_detailed_data_LE_2_beta_trajectories;
22 % load demo_nonlin_evol_detailed_data_LE_on_RB;
23 offline_data = rb_offline_prep(detailed_data,params);
25 %params.N = 25; params.M = length(detailed_data.TM{1});
26 %params.N = 123; params.M = length(detailed_data.TM{1});
27 %params.N = 20; params.M = length(detailed_data.TM{1});
29 % M usually less than N !!
31 %
set parameter vector mu
for which loop has to be performed
38 % => M >= 3N ist stabil
40 % prepare linear parameters (plus some additional missing fields)
42 params_lin.rb_problem_type =
'lin_evol';
43 params_lin.L_I_inv_norm_bound = 1;
44 params_lin.L_E_norm_bound = 1;
45 params_lin.N = size(detailed_data.RB,2);
46 offline_data_lin = rb_offline_prep(detailed_data,params_lin);
47 reduced_data_lin = rb_online_prep(offline_data_lin,params_lin);
48 % full linear simulation: only required once, as parameter is fixed
49 simulation_data_lin = rb_simulation(reduced_data_lin,params_lin);
50 U_lin = rb_reconstruction(detailed_data,simulation_data_lin);
53 Ns = round((0:(Nsamples-1)) * ...
54 (size(detailed_data.RB,2)-1)/(Nsamples-1)+1);
57 Ms = round((0:(Msamples-1)) * ...
58 (size(detailed_data.BM,2)-1)/(Msamples-1)+1);
60 % storage
for maximum l2-errors (i.e. linfty([0,T],l2)-norm)
61 errs = zeros(Msamples,Nsamples);
62 inds = zeros(Msamples,Nsamples);
69 % nonlinear simulation
72 reduced_data = rb_online_prep(offline_data,params);
73 simulation_data = rb_simulation(reduced_data,params);
74 U = rb_reconstruction(detailed_data,simulation_data);
77 [err,ind] = max(l2_errors);
78 errs(Mind,Nind) = err(1);
79 inds(Mind,Nind) = ind(1);
84 % define stability-region as error being smaller than
85 % sqrt(diffmax * area), e.g. diffmax = 4, area = 2e-7
89 i = find(errs<stab_limit);
92 if isempty(find(C==1,1)); % i.e. all stable
93 figure, surf(Ms, Ns,errs
');
94 else % some not stable
95 figure, surf(Ms, Ns,errs',C
');
98 % figure, pcolor(Ms, Ns,C);
99 title('L-infty([0,T],L2) error of nonlinear-evolution
');
100 set(gca,'Zscale
','log
');
105 figure, surf(Ms, Ns,inds');
106 title(
'time index of maximum l2-error');
107 %
set(gca,
'Zscale',
'log');
110 zlabel(
'time index');
112 % params.title =
'Solution from nonlinear rb-simulation';
113 % plot_element_data_sequence([],Unonlin,params);
114 % plot_element_data_sequence([],Unonlin(:,1:100),params);
115 %plot_rb_reconstruction(detailed_data,simulation_data,params);
117 %use same detailed-data, i.e. reduced basis
118 % lparams.title = 'Solution from linear rb-simulation';
119 % plot_element_data_sequence([],Ulin(:,1:100),lparams);
120 % plot_element_data_sequence([],Ulin,lparams);
123 % params.title =
'Difference of linear and nonlinear';
124 % plot_element_data_sequence([],Ulin(:,1:100)-Unonlin(:,1:100),params);
125 % plot_element_data_sequence([],Ulin-Unonlin,params);
127 % figure,plot(l2_errors);
128 % title(
'l2-difference');
131 % TO BE ADJUSTED TO NEW SYNTAX