rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
rb_nonlin_error_convergence.m
Go to the documentation of this file.
1 % small script performing a reduced basis simulation with the
2 % linear and nonlinear scheme and plotting the results
3 %
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
7 
8 % Bernard Haasdonk 24.6.2007
9 
10 % prepare and run nonlin_evol simulation
11 
13 % params.Mmax = 100;
14 % detailed_data = rb_detailed_prep(params);
15  clear;
16 % load demo_nonlin_evol_detailed_data_LE_on_RB_wo_offset;
17 
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;
21 
22 % load demo_nonlin_evol_detailed_data_LE_on_RB;
23  offline_data = rb_offline_prep(detailed_data,params);
24 
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});
28 
29  % M usually less than N !!
30 
31  % set parameter vector mu for which loop has to be performed
32  params.k = 0;
33  params.c_init = 1;
34  params.beta = 1;
35  %params.k = 0;
36  %params.c_init = 0;
37  %params.beta = 0;
38  % => M >= 3N ist stabil
39 
40  % prepare linear parameters (plus some additional missing fields)
41  params_lin = params;
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);
51 
52  Nsamples = 12;
53  Ns = round((0:(Nsamples-1)) * ...
54  (size(detailed_data.RB,2)-1)/(Nsamples-1)+1);
55 
56  Msamples = 14;
57  Ms = round((0:(Msamples-1)) * ...
58  (size(detailed_data.BM,2)-1)/(Msamples-1)+1);
59 
60  % storage for maximum l2-errors (i.e. linfty([0,T],l2)-norm)
61  errs = zeros(Msamples,Nsamples);
62  inds = zeros(Msamples,Nsamples);
63 
64  for Nind = 1:Nsamples
65  N = Ns(Nind);
66  for Mind = 1:Msamples
67  M = Ms(Mind);
68 
69  % nonlinear simulation
70  params.M = M;
71  params.N = N;
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);
75 
76  l2_errors = fv_l2_error(U_lin,U,detailed_data.W);
77  [err,ind] = max(l2_errors);
78  errs(Mind,Nind) = err(1);
79  inds(Mind,Nind) = ind(1);
80 
81  end;
82  end;
83 
84  % define stability-region as error being smaller than
85  % sqrt(diffmax * area), e.g. diffmax = 4, area = 2e-7
86 
87  stab_limit = 1e-3;
88  C = ones(size(errs));
89  i = find(errs<stab_limit);
90  C(i) = 2;
91 
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');
96  shading interp;
97  end;
98 % figure, pcolor(Ms, Ns,C);
99  title('L-infty([0,T],L2) error of nonlinear-evolution');
100  set(gca,'Zscale','log');
101  xlabel('M');
102  ylabel('N');
103  zlabel('error');
104 
105  figure, surf(Ms, Ns,inds');
106  title('time index of maximum l2-error');
107  %set(gca,'Zscale','log');
108  xlabel('M');
109  ylabel('N');
110  zlabel('time index');
111 
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);
116 
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);
121 
122  % plot difference
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);
126 
127 % figure,plot(l2_errors);
128 % title('l2-difference');
129 
130 
131 % TO BE ADJUSTED TO NEW SYNTAX
132 %| \docupdate