1 % script collecting the commands
for running the chemnitz-experiments
4 %B. Haasdonk, M. Ohlberger, M., G. Rozza: A Reduced Basis Method for Evolution
5 %Schemes with Parameter-Dependent Explicit Operators. Preprint 09/07 - N,
6 %FB 10 , University of Muenster, Preprint Nr. 17/2007,
7 %Institute of Mathematics, University of Freiburg, 2007, Accepted by ETNA.
9 % Bernard Haasdonk 3.9.2007
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 %%%%%% Select here, what is to be performed with the data %%%%%%%%%%%%%%%%%%
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 %step = 1 % single detailed simulation with given data and plot. Run
15 % this with varying parameters mu until sure that scheme
16 % is stable. Modify dt or the data-functions accordingly,
17 % until a nice parameter-domain with uniformly stable
18 % detailed scheme is obtained.
19 %step = 2 % generate collateral reduced basis of L_E operator
20 step = 3 % compare single detailed simulation with and without
21 % interpolated space operator vary the parameters to ensure that
22 % the empirical interpolation is stable
23 %step = 4 % generate dummy reduced basis from single trajectory and check, if
24 % ei_interpolation with projection on this space maintains
25 % result. A simple reduced simulation can also be
26 % performed. All results should be visually identical
27 %step = 5 % generate reduced basis
28 %step = 6 % time measurement of reduced simulation and
29 % use of reduced basis in rb_demo_gui
30 %step = 7 % generate train and/or test-error-landscape by doing
31 % reduced simulations for these
33 % load linear gdl example, but turn it into nonlinear in the following
34 load demo_lin_evol_params
36 %CRBfname = 'chemnitz_CRB_new_interpol';
37 %detailed_data_fname =
'chemnitz_detailed_data_new_interpol';
38 %CRBfname =
'chemnitz_CRB_new';
39 %detailed_data_fname =
'chemnitz_detailed_data_new';
40 CRBfname =
'chemnitz_CRB_new_interpol';
41 detailed_data_fname =
'chemnitz_detailed_data_new_interpol';
43 % finite volume settings
44 %params.operators_algorithm =
'fv_operators_implicit_explicit';
45 %params.init_values_algorithm =
'fv_init_values';
46 params.implicit_operators_algorithm =
'fv_operators_implicit';
47 params.inner_product_matrix_algorithm =
'fv_inner_product_matrix';
48 params.data_const_in_time = 1;
49 params.L_E_local_name =
'fv_conv_explicit_space';
50 params.dt = params.T/params.nt;
52 % change to nonlin problem type
53 params.mu_names = {
'beta',
'c_init'};
54 %params.mu_ranges = {[-1,1],[0, 0.4]};
55 params.mu_ranges = {[0,1],[0, 1]};
56 params.rb_problem_type =
'nonlin_evol';
61 % settings
for empirical interpolation
62 par.range = params.mu_ranges;
63 params.ei_numintervals = [4,4]; % 5x5 parameter grid
68 params.ei_detailed_savepath =
'chemnitz_5x5_detailed';
69 params.ei_operator_savepath =
'chemnitz_5x5_ei_operator_new';
70 params.ei_time_indices = 1:params.nt;
71 % spaeter einbauen: params.ei_stop_epsilon = 1e-12;
72 params.CRB_generation_mode =
'param-time-space-grid';
73 %params.ei_target_error =
'approx';
74 %params.ei_target_error =
'interpol';
75 %disp(
'taking interpolation error as target in empirical interpolation!!');
77 % settings
for reduced basis generation
78 params.detailed_simulation_algorithm =
'detailed_simulation';
79 params.error_algorithm =
'fv_error';
80 %params.lxf_lambda = 1.0194e+003;
81 %params.data_const_in_time = 1;
82 params.error_norm =
'l2';
83 params.RB_extension_algorithm =
'RB_extension_PCA_fixspace';
84 %
'RB_extension_max_error_snapshot'};
85 params.RB_stop_timeout = 3*60*60; % 3 hours
86 params.RB_stop_epsilon = 1e-9;
87 params.RB_error_indicator =
'error'; %
true error
88 %params.RB_error_indicator =
'estimator'; % Delta from rb_simulation
89 params.RB_stop_Nmax = 150;
90 params.RB_generation_mode =
'uniform_fixed';
91 params.RB_numintervals = params.ei_numintervals;
92 params.RB_detailed_train_savepath = params.ei_detailed_savepath;
94 % caching of velocity field
for acceleration of GDL-example
95 params.filecache_velocity_matrixfile_extract = 2;
98 case 1 % single detailed simulation and plot
99 disp(
'performing single detailed simulation')
100 grid = construct_grid(params);
101 U = detailed_simulation(grid, params);
102 plot_element_data_sequence(grid,U,params);
103 case 2 % empirical interpolation of space operator
104 disp('constructing colateral reduced basis')
105 params.RB_generation_mode = 'none';
106 detailed_data = rb_detailed_prep(params);
107 save(fullfile(rbmatlabresult,CRBfname),...
108 'detailed_data','params');
109 detailed_data.RB = zeros(detailed_data.grid.nelements,1);
110 rb_plot_detailed_data(detailed_data,params);
112 case 3 % compare detailed simulation with and without interpolation
113 disp(['comparison between detailed simulation with and without', ...
115 % tmp = load(fullfile(rbmatlabresult,'chemnitz_CRB.mat'));
116 tmp = load(fullfile(rbmatlabresult,CRBfname));
117 detailed_data = tmp.detailed_data;
122 U = detailed_simulation(detailed_data.grid, params);
123 params.title = 'detailed simulation without interpolation';
124 plot_element_data_sequence(detailed_data.grid,U,params);
126 %M = round(size(detailed_data.QM,2)/2)
127 % M = round(size(detailed_data.QM,2)/2)
130 Ui = detailed_ei_nonlin_evol_simulation(detailed_data,params);
131 params.title = 'detailed simulation with empirical interpolation';
132 plot_element_data_sequence(detailed_data.grid,Ui,params);
133 params.title = 'error';
134 plot_element_data_sequence(detailed_data.grid,abs(Ui-U),params);
135 disp(['maximum l-infty error:',num2str(max(max(abs(Ui-U))))]);
136 case 4 % construct dummy reduced basis by single trajectory and simulate
137 load(fullfile(rbmatlabresult,CRBfname));
138 disp('detailed interpolated simulation for basis construction:')
139 % params.M = round(size(detailed_data.QM{1},2)/2);
140 params.M = size(detailed_data.QM{1},2);
141 % params.nt = params.nt /2;
142 Ui = detailed_ei_nonlin_evol_simulation(detailed_data,params);
143 A = feval(params.inner_product_matrix_algorithm,detailed_data.grid,params);
144 UON = orthonormalize(Ui,A);
145 detailed_data.RB = UON;
146 disp(
'reduced simulation:')
147 offline_data = rb_offline_prep(detailed_data,params);
148 params.N = size(detailed_data.RB,2);
149 % params.M = size(detailed_data.QM{1},2);
150 reduced_data = rb_online_prep(offline_data, params);
151 simulation_data = rb_simulation(reduced_data,params);
152 Uappr = rb_reconstruction(detailed_data,simulation_data);
154 disp(
'detailed interpolated and rb-projected simulation:')
155 params.M = size(detailed_data.QM{1},2);
156 params.N = size(detailed_data.RB,2);
157 Uirb = detailed_ei_rb_proj_nonlin_evol_simulation(detailed_data,params);
159 params.title =
'reduced simulation result';
160 plot_element_data_sequence(detailed_data.grid,Uappr,params);
161 params.title =
'detailed ei_interpol simulation result';
162 plot_element_data_sequence(detailed_data.grid,Ui,params);
163 params.title =
'detailed ei_interpol and rb_projected simulation result';
164 plot_element_data_sequence(detailed_data.grid,Uirb,params);
166 case 5 % reduced basis
167 disp(
'constructing reduced basis')
168 tmp = load(fullfile(rbmatlabresult,CRBfname));
169 detailed_data = tmp.detailed_data;
170 % params = tmp.params;
173 save(fullfile(rbmatlabresult,detailed_data_fname),...
174 'detailed_data','params');
176 load(fullfile(rbmatlabresult,detailed_data_fname));
177 disp('reduced simulation:')
178 offline_data = rb_offline_prep(detailed_data,params);
179 params.N = size(detailed_data.RB,2);
180 params.M = size(detailed_data.QM{1},2);
181 reduced_data = rb_online_prep(offline_data, params);
183 simulation_data = rb_simulation(reduced_data,params);
185 disp([
'time for online phase: t = ',num2str(t)]);
187 disp(
'full simulation:')
189 U = detailed_simulation(detailed_data.grid, params);
191 disp(['time for detailed simulation: t = ',num2str(t)]);
195 case 7 % train-error landscape and test-error landscape
196 disp('warning: takes a few hours!');
197 load(fullfile(rbmatlabresult,detailed_data_fname));
199 % replace RB with dummy basis from linear case!!
200 %disp('replacing RB with linear basis!! remove this afterwards!!');
201 %tmp = load('demo_lin_evol_detailed_data');
202 %detailed_data.RB = tmp.detailed_data.RB;
204 % runs = {
'train_linRB',
'test_linRB'};
205 % dirnames = {testdir};
206 % testdir =
'chemnitz_test_100';
208 % runs = {
'train',
'test'};
209 % dirnames = {params.RB_detailed_train_savepath, testdir};
212 %dirnames = {params.RB_detailed_train_savepath};
215 dirnames = {testdir};
217 % generate test data
if not existent
218 if ismember(
'test',runs)
219 % generate test data
if not existent
220 rand(
'state',123456);
221 M = rand_uniform(100,params.mu_ranges);
225 % load demo_nonlin_evol_detailed_data_LE_on_RB;
226 offline_data = rb_offline_prep(detailed_data,params);
229 % Nmax = size(detailed_data.RB,2);
231 Ns = round((0:(Nsamples-1)) * ...
232 (Nmax-1)/(Nsamples-1)+1);
236 % Mmax = size(detailed_data.BM,2);
237 Mmax = 100; % size(detailed_data.BM,2);
238 Ms = round((0:(Msamples-1)) * ...
239 (Mmax-1)/(Msamples-1)+1);
241 for ru = 1:length(runs);
242 disp(['starting run ',runs{ru}]);
243 % storage
for maximum l2-errors (i.e. linfty([0,T],l2)-norm)
244 errs = zeros(Msamples,Nsamples);
245 inds = zeros(Msamples,Nsamples);
246 mu_inds = zeros(Msamples,Nsamples);
247 % assuming, that training data is in the following directory
248 settings = load(fullfile(rbmatlabtemp,...
249 dirnames{ru},
'settings.mat'));
251 for mu_ind = 1:size(settings.M,2);
252 disp([
'processing parameter vector ',num2str(mu_ind),...
253 '/',num2str(size(settings.M,2))]);
254 params = set_mu(settings.M(:,mu_ind),params);
257 for Nind = 1:Nsamples
259 for Mind = 1:Msamples
263 % nonlinear simulation
266 reduced_data = rb_online_prep(offline_data,params);
267 simulation_data = rb_simulation(reduced_data,params);
268 U = rb_reconstruction(detailed_data,simulation_data);
271 [err,ind] = max(l2_errors);
272 if err(1)>errs(Mind,Nind)
273 errs(Mind,Nind) = err(1);
274 inds(Mind,Nind) = ind(1);
275 mu_inds(Mind,Nind) = mu_ind;
281 % define stability-region as error being smaller than
282 % sqrt(diffmax * area), e.g. diffmax = 4, area = 2e-7
285 C = ones(size(errs));
286 i = find(errs<stab_limit);
289 if isempty(find(C==1)); % i.e. all stable
290 f1 = figure, surf(Ms, Ns,errs');
291 else % some not stable
292 f1 = figure, surf(Ms, Ns,errs',C');
295 % figure, pcolor(Ms, Ns,C);
296 title([runs{ru},
' L-infty([0,T],L2) error']);
297 set(gca,
'Zscale',
'log');
302 f2 = figure, surf(Ms, Ns,inds
');
303 title([runs{ru},' time index of maximum l2-error
']);
304 %set(gca,'Zscale
','log
');
307 zlabel('time index
');
309 save(fullfile(rbmatlabresult,...
310 ['chemnitz_gdl_experiment_step7_result_
',...
315 error('step-number is unknown!
');
318 % TO BE ADJUSTED TO NEW SYNTAX