rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
step4_dummy_reduced_basis.m
Go to the documentation of this file.
1 % script constructing a reduced basis from a single trajectory and
2 % performing a detailed simulation where the data is projected on the
3 % dummy reduced basis space after each time step.
4 %
5 % required variables that need to be set:
6 % - 'CRBfname'
7 % - 'plot_params'
8 %
9 % generated variables:
10 % - 'ei_rb_proj_data': output of detailed_ei_rb_proj_simulation() with
11 % dummy reduced basis space.
12 
13 tmp=load(fullfile(rbmatlabresult,CRBfname));
14 detailed_data=tmp.detailed_data;
15 disp('detailed interpolated simulation for basis construction:')
16 if ~isfield(model,'Mstrich')
17  model.Mstrich = 0;
18  model.enable_error_estimator = 0;
19 end;
20 
21 model.M = cellfun(@(x)(size(x,2) - model.Mstrich), detailed_data.BM, 'UniformOutput', true);
22 
23 tic
24 ei_sim_data = model.detailed_ei_simulation(model,detailed_data);
25 dtime = toc
26 
27 % in case of newton scheme add temporary results of newton steps to dummy
28 % reduced basis
29 if model.newton_solver
30  U = ei_sim_data.Unewton;
31 else
32  U = ei_sim_data.U;
33 end
34 
35 UON = orth(U);
36 UON = UON / (full(sqrt(detailed_data.W(1))));
37 
38 %UON = model.orthonormalize(model, detailed_data, ei_sim_data.U,1e-7);
39 %
40 detailed_data.RB = UON;
41 
42 disp('reduced simulation:')
43 reduced_data = gen_reduced_data(model, detailed_data);
44 model.N = size(detailed_data.RB,2);
45 smodel = model;
46 smodel.enable_error_estimator = 0;
47 
48 tic
49 rb_sim_data = rb_simulation(smodel, reduced_data);
50 rbtime = toc
51 tic
52 rb_sim_data = rb_reconstruction(smodel, detailed_data, rb_sim_data);
53 rectime = toc
54 
55 if ~isfield(rb_sim_data, 'Delta')
56  smodel.enable_error_estimator = 0;
57 else
58  Delta = rb_sim_data.Delta(end);
59 
60  disp(['Error estimator returned: ', num2str(Delta)]);
61 end
62 
63 disp('detailed interpolated and rb-projected simulation:')
64 model.M = cellfun(@(x)(size(x,2) - model.Mstrich), detailed_data.BM, 'UniformOutput', true);
65 model.N = size(detailed_data.RB,2);
66 %ei_rb_proj_data = detailed_ei_rb_proj_simulation(smodel, detailed_data);
67 
68 plot_params.title = 'reduced simulation result';
69 plot_sim_data(model, detailed_data, rb_sim_data, plot_params);
70 plot_params.title = 'detailed ei_interpol simulation result';
71 plot_sim_data(model, detailed_data, ei_sim_data, plot_params);
72 %plot_params.title = 'detailed ei_interpol and rb_projected simulation result';
73 %plot_sim_data(model, detailed_data, ei_rb_proj_data, plot_params);
74 
75 epp = plot_params;
76 epp.title = 'error';
77 diff_data = rb_sim_data;
78 %diff_data.U = abs(diff_data.U - ei_rb_proj_data.U);
79 diff_data.U = abs(diff_data.U - ei_sim_data.U);
80 epp.clim = [0,max(max(diff_data.U))];
81 plot_sim_data(model, detailed_data, diff_data, epp);
82 disp(['maximum l-infty error:',num2str(max(max(diff_data.U)))]);
83 
84 if model.debug && smodel.enable_error_estimator
85  ei_res = rb_sim_data.eilog(end);
86  max_ei_error = max(cellfun(@(X) X.max_err_sequence(model.M), ...
87  detailed_data.ei_info));
88  ei_rel_diff = abs(ei_res - max_ei_error) / abs(ei_res);
89 
90  if ei_rel_diff < 0.1 || ei_rel_diff > 10
91  disp(['Oh no! The EI residuum has a different order of magnitude ', ...
92  'than the empirical interpolation error.']);
93  else
94  disp(['EI residuum has same order of magnitude as empirical ', ...
95  'interpolation error.']);
96  end;
97  disp(['EI residuum returned: ', num2str(ei_res)]);
98  disp(['maximum EI error: ', num2str(max_ei_error)]);
99 
100  proj_res = rb_sim_data.reslog(end);
101 % proj_res_exa = ei_rb_proj_data.reslog(end);
102 % proj_res_diff = abs(proj_res_exa - proj_res) / abs(proj_res);
103 
104 % if proj_res_diff < 0.1 || proj_res_diff > 10
105 % disp(['Oh no! The exact projection residuum has a different order of ', ...
106 % 'magnitude than the estimated.']);
107 % else
108 % disp(['Exact projection residuum has same order of magnitude as ', ...
109 % 'estimated projection residuum.']);
110 % end;
111  disp(['estimated projection residuum: ', num2str(proj_res)]);
112  disp(['exact projection residuum: ', num2str(proj_res_exa)]);
113 end
114 
115 disp(['runtime detailed : ', num2str(dtime)]);
116 disp(['runtime rb_sim : ', num2str(rbtime), ' factor: ', num2str(dtime/rbtime)]);
117 disp(['runtime reconstruction : ', num2str(rectime), ' factor: ', num2str(dtime/(rbtime+rectime))]);
118 
function [ descr , rdescr , dmodel , rmodel ] = newton(steps, combined, M_by_N_ratio, noof_ei_extensions, use_laplacian, model_size, random, num_cpus, Mstrich)
small script demonstrating a buckley leverett problem discretization and RB model reduction ...
Definition: newton.m:17
function p = plot_sim_data(model, model_data, sim_data, plot_params)
function performing the plot of the simulation results as specified in model.
Definition: plot_sim_data.m:17