1 function [ddescr, rdescr, dmodel, rmodel] =
nonlin_symmetry(steps, combined, M_by_N_ratio, noof_ei_extensions, random,
explicit, num_cpus, params)
2 %
function [descr, rdescr, dmodel, rmodel] =
nonlin_symmetry(steps, combined, M_by_N_ratio, noof_ei_extensions, random,
explicit, num_cpus, params)
3 % small script demonstrating the burgers equation with
explicit fv
4 % discretization and RB model reduction
5 % example is meant to demonstrate automatic symmetry detection by
7 % These results are presented at HYP2008
9 % Bernard Haasdonk 3.6.2008
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 %%%%%% Select here, what is to be performed with the burgers 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 colateral reduced basis of L_E operator
20 %step = 3 % compare single detailed simulation with and without
21 % interpolated space operator
22 %step = 4 % generate dummy reduced basis from single trajectory and check, if
23 % ei_interpolation with projection on this space maintains
24 % result. A simple reduced simulation can also be
25 % performed. All results should be visually identical.
26 %step = 5 % generate reduced basis
27 %step = 6 % time measurement of reduced simulation and demo rb gui
28 %step = 7 % generate error-landscape over varying N and M.
29 % This can take several hours!!!
30 %step = 8 % generate estimator-landscape over varying N and M and
31 % Mstrich. This can take several hours!!!
32 %step = 9 % generate different Figures for presentation and time measurement
34 %step = 11 % comparison of error estimator and error
40 %steps = [1,2,3,4,5,7,8];
45 noof_ei_extensions = 1;
56 for si=1:length(steps)
60 % output-filenames in rbmatlabresult
61 detailedfname = 'nonlin_symmetry_detailed.mat';
62 testdir = 'nonlin_symmetry_test_10';
63 results_fname_base = 'nonlin_symmetry_step7_result';
65 plot_params.axis_equal = 1;
66 plot_params.clim = [0,1];
69 params.explicit = explicit;
71 params.step7_outputfile = fullfile(rbmatlabresult, [params.model_type, '_step7_output']);
72 params.step8_outputfile = fullfile(rbmatlabresult, [params.model_type, '_step8_output']);
74 extrapar.Mstrich = 100;
79 if ~isempty(getenv('MACHINEFILE'))
80 machinefile = getenv('MACHINEFILE');
81 FakeMPI.MPI_Init(machinefile, fullfile(rbmatlabhome, 'fakeMPI', 'run_parCompErrs.sh'));
85 ddescr = nonlin_symmetry_descr(params);
86 rdescr.rb_problem_type = ddescr.rb_problem_type;
89 rdescr.Mmax_small = 0;
91 rdescr.Mmax_small = 20;
94 rdescr.extension_M_by_N_r = M_by_N_ratio; % 2.5;
95 rdescr.refinement_theta = 0.15;
96 rdescr.noof_ei_extensions = noof_ei_extensions;
97 rdescr.train_num_intervals = 25;
99 rdescr.stop_Mmax = 600;
100 rdescr.stop_Nmax = 300;
101 rdescr.stop_timeout = 12*60*60;
102 rdescr.stop_epsilon = 1e-9;
103 rdescr.epsilon_M_by_N_r = 1e-1;
104 rdescr.stop_max_val_train_ratio = 1.15;
107 rdescr.train_sample_mode = 'random';
108 rdescr.train_num_intervals = 400;
109 rdescr.stop_max_val_train_ratio = inf;
112 [rmodel, dmodel] =
gen_models(ddescr, rdescr);
114 params.mu_ranges = rmodel.mu_ranges;
115 params.mu_names = rmodel.mu_names;
117 dmodel.num_cpus = num_cpus;
119 model_data = gen_model_data(dmodel);
120 case 1 % single detailed simulation and plot
122 case 2 % empirical interpolation of space operator
124 case 3 % compare detailed simulation with and without interpolation
126 case 4 % construct dummy reduced basis by single trajectory and simulate
128 case 5 % reduced basis
129 detailed_data = gen_detailed_data(rmodel, model_data);
130 save(fullfile(rbmatlabresult, detailedfname), 'detailed_data', 'rmodel');
131 FakeMPI.MPI_Finalize;
135 load(fullfile(rbmatlabresult,detailedfname));
139 % maximum number of reduced basis functions
141 % maximum number of collateral reduced basis functions
142 model.Mmax = size(detailed_data.BM{1},2);
143 % fixed ratio between M and N in couples plots.
144 model.M_by_N_ratio = 1.5;
145 % number of reduced basis sizes to be tested.
147 % number of collateral reduced basis sizes to be tested.
149 % sample of values
for the coupling variable
'c' for which errors are
151 cmax = min(1,model.Mmax/(model.M_by_N_ratio*model.Nmax));
152 csample = cmax/20:cmax/20:cmax;
153 % axis description
for plots with coupling variable
'c'
154 cdescr =
'(N,M) = c * (Nmax, Mmax)';
155 % size of mu vector test
set.
160 load(params.step65_output);
161 for i = 1:length(output)
165 disp(
'warning: takes a few hours!');
166 load(fullfile(rbmatlabresult,detailedfname));
168 % maximum number of reduced basis vectors
169 model.Nmax = size( detailed_data.RB, 2 );
170 % maximum number of collateral reduced basis vectors used
for
171 model.Mmax = size( detailed_data.BM{1}, 2 ) - extrapar.Mstrich;
172 % fixed ratio between M and N in couples plots.
173 model.M_by_N_ratio = 1.5;
175 % number of reduced basis sizes to be tested.
177 % number of collateral reduced basis sizes to be tested.
179 % Mstrich values to be tested
180 Mstrich_samples = 1:2:extrapar.Mstrich;
181 % sample of values
for the coupling variable
'c' for which
182 % estimators are computed.
183 cmax = min(1,model.Mmax/(model.M_by_N_ratio*model.Nmax));
184 csample = cmax/20:cmax/20:cmax;
185 % size of mu vector test
set
187 % axis description
for plots with coupling variable
'c'
188 cdescr =
'(N,M) = c * (Nmax, Mmax)';
192 load(params.step75_output);
193 for i = 1:length(output)
196 case 9 % generate figures and runtime table
197 load(fullfile(rbmatlabresult,detailedfname));
199 % anfangsdaten, Enddaten p=1, Enddaten p=2
202 U1 = detailed_simulation(detailed_data.grid,model);
204 U2 = detailed_simulation(detailed_data.grid,model);
208 plot_element_data(detailed_data.grid,U1(:,1),model);
209 title(
'Initial Data');
210 set(gcf,
'Position',[420 663 565 285]);
211 saveas(gcf,
'smooth_init_data.eps',
'epsc');
214 plot_element_data(detailed_data.grid,U1(:,end),model);
215 title(
'End Data p=1');
216 set(gcf,
'Position',[420 663 565 285]);
217 saveas(gcf,
'smooth_end_data_p1.eps',
'epsc');
220 plot_element_data(detailed_data.grid,U2(:,end),model);
221 title(
'End Data p=2');
222 set(gcf,
'Position',[420 663 565 285]);
223 saveas(gcf,
'smooth_end_data_p2.eps',
'epsc');
226 model.M = length(detailed_data.TM{1});
227 rb_plot_interpolation_points(detailed_data,model);
228 set(gcf,
'Position',[420 663 565 285]);
230 cmap = cmap(1:150,:); % take dark shades
231 cmap(1,:) = [1.0,1.0,1.0]; % light yellow
236 saveas(gcf,
'smooth_interpolation_points.eps',
'epsc');
238 % nicely arranged error landscape figures:
240 % load(fullfile(rbmatlabresult,...
241 % [results_fname_base,
'_train.mat']));
242 load(fullfile(rbmatlabresult,...
243 [results_fname_base,
'_test.mat']));
247 % title(['test L^\infty([0,T],L^2) error
'],'Fontsize
',15);
248 title('test error
','Fontsize
',15); %L^\infty([0,T],L^2) error'],
'Fontsize',15);
249 set(gca,
'Zscale',
'log');
250 xlabel(
'M',
'Fontsize',15);
251 ylabel(
'N',
'Fontsize',15);
252 zlabel(
'error',
'Fontsize',15);
254 tmp = load('redgreencolmap.mat');
256 % cmap = cmap(end:-1:1,:);
258 % disp('adjust colorbar!');
259 set(gcf,'Color',[1.0,1.0,1.0]);
263 % generate runtime table
266 Ns = [10,20,30,40,50,60, 70, 80, 90, 100];
267 Ms = [15,30,45,60,75,90,105,120, 135,150];
268 t_detailed = zeros(nreps,1);
270 model.flux_pdeg = rand(1)+1;
271 % offline_data = rb_offline_prep(detailed_data,model);
273 u = detailed_simulation(model);
274 t_detailed(rep) = toc;
275 disp(['runtime for detailed: ',num2str(t_detailed(rep)),' sec.']);
278 t_reduced = zeros(nreps,length(Ns));
279 offline_data = rb_offline_prep(detailed_data,model);
280 for rn = 1:length(Ns)
283 reduced_data = rb_online_prep(offline_data,model);
285 model.flux_pdeg = rand(1)+1;
287 simulation_data = rb_simulation(reduced_data,model);
288 t_reduced(rep,rn) = toc;
289 disp(['N= ',num2str(model.N),', M= ',num2str(model.M)]);
290 disp(['runtime for reduced: ',num2str(t_reduced(rep,rn)),' sec.']);
295 disp(' t_mean t_std ');
296 disp([num2str(mean(t_detailed)),' ',num2str(std(t_detailed))]);
299 disp('N M t_mean t_std');
300 o = [Ns(:), Ms(:), mean(t_reduced,1)', std(t_reduced,1)'];
301 s = sprintf('%2.0f %2.0f %2.2f %2.2f \n ',o');
304 offline_data = rb_offline_prep(detailed_data,model);
305 plot(offline_data.grid_local_ext);
309 set(gcf,'Color',[1,1,1]);
312 load(fullfile(rbmatlabresult,detailedfname));
313 % Mmax = 150; Nmax = 100
317 model.enable_error_estimator = 1;
318 % model.RB_error_indicator = 'estimator';
321 case 11 % compare error and error estimator
322 load(fullfile(rbmatlabresult,detailedfname));
326 % model.Mstrich = 10; % set below in loop
327 model.enable_error_estimator = 1;
329 model_data = gen_model_data(model);
330 % detailed_data = gen_detailed_data(model,model_data);
331 reduced_data = gen_reduced_data(model, detailed_data);
333 model = model.set_mu(model,[1.5]);
334 % model = model.set_mu(model,2);
335 % model = model.set_mu(model,1);
336 sim_data = detailed_simulation(model,model_data);
337 % Mstrich = [1,10,150];
339 for Mi = 1:length(Mstrich);
340 model.Mstrich = Mstrich(Mi);
341 rb_sim_data = rb_simulation(model, reduced_data);
342 rb_sim_data = rb_reconstruction(model, detailed_data, rb_sim_data);
344 De{Mi} = rb_sim_data.Delta;
347 err_data.U = sim_data.U - rb_sim_data.U;
348 err = sqrt(max(0,sum(err_data.U
' * detailed_data.W * err_data.U)))';
351 % somehow replace by matrix version!!!
352 for i = 2:length(max_t_err)
353 if max_t_err(i) < max_t_err(i-1)
354 max_t_err(i) = max_t_err(i-1);
358 plot([De{1}(:),De{2}(:),De{3}(:),max_t_err(:),err(:)]);
359 Ylim =
get(gca,
'Ylim');
360 set(gca,
'Ylim',[0,max(Ylim)]);
361 title(
'rb state error and estimator');
362 legend({
'M''= 1, estimator \Delta(t)',...
363 'M''= 5, estimator \Delta(t)',...
364 'M''= 10, estimator \Delta(t)',...
365 '||e||_{L\infty([0,t],L2)}',...
366 '||e(t)||_{L2}'},
'Location',
'NorthWest');
369 error(
'step-number is unknown!');