rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
ei_error_convergence.m
1 function l = ei_error_convergence(detailed_data,detailed_path, ...
2  ei_operator_path, params)
3 %function l = ei_error_convergence(detailed_data,detailed_path, ...
4 % ei_operator_path, params)
5 %
6 % function generating a error-convergence graph over the set
7 % of parameters given in the paths. The handle to the plot is returned.
8 % The function performs the detailed_ei_interpolated simulation for
9 % increasing number of basis vectors M until the value given in params.M.
10 % (1) the maximum approximation error is plotted, i.e. projection of all
11 % ei-snapshots on the increasing ei-spaces, and computation of the
12 % maximum L^infty(L2)-error, (2) the interpolation error,
13 % i.e. interpolation of all snapshots, error computation and maximum
14 % search and (3) the error between detailed-ei-simulation and the real
15 % detailed simulations is computed.
16 % the detailed_path must contain detailed simulations, e.g. generated by
17 % save_detailed_simulations, the ei_operator_path must contain the
18 % corresponding space-discretization operator results, e.g. generated by
19 % save_ei_operator_trajectories
20 
21 % Bernard Haasdonk 7.9.2007
22 
23  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24  %%%%% general settings to be used
25  Msamples = params.Msamples;
26  % Mmax = size(detailed_data.BM,2);
27  Mmax = params.Mmax; % size(detailed_data.BM,2);
28  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 
30 % detailed_path = params.RB_detailed_train_savepath;
31 % ei_operator_path = params.ei_operator_savepath;
32 
33  errnames = {'approximation','interpolation','ei-simulation'}
34 
35  Ms = round((0:(Msamples-1)) * ...
36  (Mmax-1)/(Msamples-1)+1);
37 
38  settings = load(fullfile(rbmatlabtemp,...
39  detailed_path,'settings.mat'));
40 
41  % storage for maximum l2-errors (i.e. linfty([0,T],l2)-norm)
42  approx_errs = zeros(Msamples,1);
43  interpol_errs = zeros(Msamples,1);
44  ei_simulation_errs = zeros(Msamples,1);
45 
46  for mu_ind = 1:size(settings.M,2);
47 % for mu_ind = 1:1;
48  disp(['processing parameter vector ',num2str(mu_ind),...
49  '/',num2str(size(settings.M,2))]);
50  params = set_mu(settings.M(:,mu_ind),params);
51  if ismember('ei-simulation',errnames)
52  sim_data = load_detailed_simulation(mu_ind,settings.savepath,params);
53  U_H = sim_data.U;
54  end;
55  for Mind = 1:Msamples
56  fprintf('.');
57  M = Ms(Mind)
58  params.M = M;
59 
60  % detailed simulation with ei of the operator
61  if ismember('ei-simulation',errnames)
62  U_ei_H = detailed_ei_nonlin_evol_simulation(detailed_data, ...
63  params);
64 
65  l2err = fv_l2_error(U_H,U_ei_H,detailed_data.W);
66  max_l2err = max(l2err);
67  if max_l2err > ei_simulation_errs(Mind)
68  ei_simulation_errs(Mind) = max_l2err;
69  end;
70  clear('U_ei_H');
71  end;
72 
73  fname = ['LU',num2str(mu_ind)];
74  tmp = load(fullfile(rbmatlabtemp,ei_operator_path,fname));
75  L_E_U = tmp.LU;
76  clear('tmp');
77  % approximation error
78  if ismember('approximation',errnames)
79  % for each discrete function in LU
80  % compute best-l2-approximation in current space spanned by Q
81  %
82  % if <u_H,v_H> = u' * W * v (u,v coefficient vectors)
83  % then min_p (u_H - sum p(i) q_i) is minimized by
84  %
85  % p = (Q' W Q)^(-1) Q^T W u
86  %
87  % So compute whole array of p-vectors and resulting approximation Q*p
88  W = feval(params.get_inner_product_matrix(detailed_data),...
89  detailed_data.grid,...
90  params);
91  A = (detailed_data.QM(:,1:M)' * W * ...
92  detailed_data.QM(:,1:M))^(-1) * ...
93  detailed_data.QM(:,1:M)' * W;
94 
95  L_E_U_appr = detailed_data.QM(:,1:M) * A * L_E_U;
96 
97  l2err = fv_l2_error(L_E_U_appr,L_E_U,detailed_data.W);
98  max_l2err = max(l2err);
99  if max_l2err > approx_errs(Mind)
100  approx_errs(Mind) = max_l2err;
101  end;
102  clear('L_E_U_appr');
103  end;
104 
105  % interpolation error
106  if ismember('interpolation',errnames)
107  % for each discrete function in LU
108  % compute interpolation in current space spanned by Q
109  W = params.get_inner_product_matrix(detailed_data);
110 
111  QM = detailed_data.QM(:,1:M);
112 
113  % get interpolation coefficients
114  coeff = detailed_data.BM(1:M,1:M) \ L_E_U(detailed_data.TM(1:M),:);
115  L_E_U_interpol = QM * coeff;
116 
117  l2err = fv_l2_error(L_E_U_interpol,L_E_U,detailed_data.W);
118  max_l2err = max(l2err);
119  if max_l2err > interpol_errs(Mind)
120  interpol_errs(Mind) = max_l2err;
121  end;
122  clear('L_E_U_interpol');
123  end;
124  end;
125  fprintf('.');
126  % save workspace
127  disp('workspace is saved in ws.mat in case of break....');
128  save('ws');
129  end;
130  disp('finished!!!');
131  l = plot(Ms,[approx_errs,interpol_errs,ei_simulation_errs]);
132  set(l,'Linewidth',2);
133  set(l(1),'LineStyle','-');
134  set(l(2),'LineStyle','-.');
135  set(l(3),'LineStyle',':');
136  set(gca,'Yscale','log');
137  legend({'max approx-error','max interpol-error','max-ei-simulation-error'});
138  title('empirical interpolation error');
139  xlabel('M');
140  ylabel('L2-error');
141  % save workspace
142  disp('workspace is saved in ws.mat for modification of plots.');
143  save('ws');
144 % TO BE ADJUSTED TO NEW SYNTAX
145 %| \docupdate