1 function [ddescr, rdescr, dmodel, rmodel] =
nonlin_symmetry_oop(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
8 % This algorithm is
using oop model,
while original
11 % Martin Drohmann, Bernard Haasdonk 3.6.2008
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 %%%%%% Select here, what is to be performed with the burgers data %%%%%%%%%%
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16 %step = 1 % single detailed simulation with given data and plot. Run
17 %
this with varying parameters mu until sure that scheme
18 % is stable. Modify dt or the data-functions accordingly,
19 % until a nice parameter-domain with uniformly stable
20 % detailed scheme is obtained.
21 %step = 2 % generate colateral reduced basis of L_E
operator
22 %step = 3 % compare single detailed simulation with and without
23 % interpolated space
operator
24 %step = 4 % generate dummy reduced basis from single trajectory and check,
if
25 % ei_interpolation with projection on
this space maintains
26 % result. A simple reduced simulation can also be
27 % performed. All results should be visually identical.
28 %step = 5 % generate reduced basis
29 %step = 6 % time measurement of reduced simulation and demo rb gui
30 %step = 7 % generate error-landscape over varying N and M.
31 % This can take several hours!!!
32 %step = 8 % generate estimator-landscape over varying N and M and
33 % Mstrich. This can take several hours!!!
34 %step = 9 % generate different Figures
for presentation and time measurement
36 %step = 11 % comparison of error estimator and error
42 %steps = [1,2,3,4,5,7,8];
47 noof_ei_extensions = 1;
58 for si=1:length(steps)
62 % output-filenames in rbmatlabresult
63 detailedfname = 'nonlin_symmetry_detailed.mat';
64 testdir = 'nonlin_symmetry_test_10';
65 results_fname_base = 'nonlin_symmetry_step7_result';
67 plot_params.axis_equal = 1;
68 plot_params.clim = [0,1];
71 params.explicit = explicit;
73 params.step7_outputfile = fullfile(rbmatlabresult, [params.model_type, '_step7_output']);
74 params.step8_outputfile = fullfile(rbmatlabresult, [params.model_type, '_step8_output']);
76 extrapar.Mstrich = 100;
81 if ~isempty(getenv('MACHINEFILE'))
82 machinefile = getenv('MACHINEFILE');
83 FakeMPI.MPI_Init(machinefile, fullfile(rbmatlabhome, 'fakeMPI', 'run_parCompErrs.sh'));
87 ddescr = nonlin_symmetry_descr(params);
88 rdescr.rb_problem_type = ddescr.rb_problem_type;
91 rdescr.Mmax_small = 0;
93 rdescr.Mmax_small = 20;
96 rdescr.extension_M_by_N_r = M_by_N_ratio; % 2.5;
97 rdescr.refinement_theta = 0.15;
98 rdescr.noof_ei_extensions = noof_ei_extensions;
99 rdescr.train_num_intervals = 25;
101 rdescr.stop_Mmax = 600;
102 rdescr.stop_Nmax = 300;
103 rdescr.stop_timeout = 12*60*60;
104 rdescr.stop_epsilon = 1e-9;
105 rdescr.epsilon_M_by_N_r = 1e-1;
106 rdescr.stop_max_val_train_ratio = 1.15;
109 rdescr.train_sample_mode = 'random';
110 rdescr.train_num_intervals = 400;
111 rdescr.stop_max_val_train_ratio = inf;
114 [rmodel, dmodel] =
gen_models(ddescr, rdescr);
116 params.mu_ranges = rmodel.mu_ranges;
117 params.mu_names = rmodel.mu_names;
119 dmodel.num_cpus = num_cpus;
121 model_data = gen_model_data(dmodel);
122 case 1 % single detailed simulation and plot
124 case 2 % empirical interpolation of space operator
126 case 3 % compare detailed simulation with and without interpolation
128 case 4 % construct dummy reduced basis by single trajectory and simulate
130 case 5 % reduced basis
131 detailed_data = gen_detailed_data(rmodel, model_data);
132 save(fullfile(rbmatlabresult, detailedfname), 'detailed_data', 'rmodel');
133 FakeMPI.MPI_Finalize;
137 load(fullfile(rbmatlabresult,detailedfname));
141 % maximum number of reduced basis functions
143 % maximum number of collateral reduced basis functions
144 model.Mmax = size(detailed_data.BM{1},2);
145 % fixed ratio between M and N in couples plots.
146 model.M_by_N_ratio = 1.5;
147 % number of reduced basis sizes to be tested.
149 % number of collateral reduced basis sizes to be tested.
151 % sample of values
for the coupling variable
'c' for which errors are
153 cmax = min(1,model.Mmax/(model.M_by_N_ratio*model.Nmax));
154 csample = cmax/20:cmax/20:cmax;
155 % axis description
for plots with coupling variable
'c'
156 cdescr =
'(N,M) = c * (Nmax, Mmax)';
157 % size of mu vector test set.
162 load(params.step65_output);
163 for i = 1:length(output)
167 disp(
'warning: takes a few hours!');
168 load(fullfile(rbmatlabresult,detailedfname));
170 % maximum number of reduced basis vectors
171 model.Nmax = size( detailed_data.RB, 2 );
172 % maximum number of collateral reduced basis vectors used
for
173 model.Mmax = size( detailed_data.BM{1}, 2 ) - extrapar.Mstrich;
174 % fixed ratio between M and N in couples plots.
175 model.M_by_N_ratio = 1.5;
177 % number of reduced basis sizes to be tested.
179 % number of collateral reduced basis sizes to be tested.
181 % Mstrich values to be tested
182 Mstrich_samples = 1:2:extrapar.Mstrich;
183 % sample of values
for the coupling variable
'c' for which
184 % estimators are computed.
185 cmax = min(1,model.Mmax/(model.M_by_N_ratio*model.Nmax));
186 csample = cmax/20:cmax/20:cmax;
187 % size of mu vector test set
189 % axis description
for plots with coupling variable
'c'
190 cdescr =
'(N,M) = c * (Nmax, Mmax)';
194 load(params.step75_output);
195 for i = 1:length(output)
198 case 9 % generate figures and runtime table
199 load(fullfile(rbmatlabresult,detailedfname));
201 % anfangsdaten, Enddaten p=1, Enddaten p=2
204 U1 = detailed_simulation(detailed_data.grid,model);
206 U2 = detailed_simulation(detailed_data.grid,model);
210 plot_element_data(detailed_data.grid,U1(:,1),model);
211 title(
'Initial Data');
212 set(gcf,
'Position',[420 663 565 285]);
213 saveas(gcf,
'smooth_init_data.eps',
'epsc');
216 plot_element_data(detailed_data.grid,U1(:,end),model);
217 title(
'End Data p=1');
218 set(gcf,
'Position',[420 663 565 285]);
219 saveas(gcf,
'smooth_end_data_p1.eps',
'epsc');
222 plot_element_data(detailed_data.grid,U2(:,end),model);
223 title(
'End Data p=2');
224 set(gcf,
'Position',[420 663 565 285]);
225 saveas(gcf,
'smooth_end_data_p2.eps',
'epsc');
228 model.M = length(detailed_data.TM{1});
229 rb_plot_interpolation_points(detailed_data,model);
230 set(gcf,
'Position',[420 663 565 285]);
232 cmap = cmap(1:150,:); % take dark shades
233 cmap(1,:) = [1.0,1.0,1.0]; % light yellow
238 saveas(gcf,
'smooth_interpolation_points.eps',
'epsc');
240 % nicely arranged error landscape figures:
242 % load(fullfile(rbmatlabresult,...
243 % [results_fname_base,
'_train.mat']));
244 load(fullfile(rbmatlabresult,...
245 [results_fname_base,
'_test.mat']));
249 % title(['test L^\infty([0,T],L^2) error
'],'Fontsize
',15);
250 title('test error
','Fontsize
',15); %L^\infty([0,T],L^2) error'],
'Fontsize',15);
251 set(gca,
'Zscale',
'log');
252 xlabel(
'M',
'Fontsize',15);
253 ylabel(
'N',
'Fontsize',15);
254 zlabel(
'error',
'Fontsize',15);
256 tmp = load('redgreencolmap.mat');
258 % cmap = cmap(end:-1:1,:);
260 % disp('adjust colorbar!');
261 set(gcf,'Color',[1.0,1.0,1.0]);
265 % generate runtime table
268 Ns = [10,20,30,40,50,60, 70, 80, 90, 100];
269 Ms = [15,30,45,60,75,90,105,120, 135,150];
270 t_detailed = zeros(nreps,1);
272 model.flux_pdeg = rand(1)+1;
273 % offline_data = rb_offline_prep(detailed_data,model);
275 u = detailed_simulation(model);
276 t_detailed(rep) = toc;
277 disp(['runtime for detailed: ',num2str(t_detailed(rep)),' sec.']);
280 t_reduced = zeros(nreps,length(Ns));
281 offline_data = rb_offline_prep(detailed_data,model);
282 for rn = 1:length(Ns)
285 reduced_data = rb_online_prep(offline_data,model);
287 model.flux_pdeg = rand(1)+1;
289 simulation_data = rb_simulation(reduced_data,model);
290 t_reduced(rep,rn) = toc;
291 disp(['N= ',num2str(model.N),', M= ',num2str(model.M)]);
292 disp(['runtime for reduced: ',num2str(t_reduced(rep,rn)),' sec.']);
297 disp(' t_mean t_std ');
298 disp([num2str(mean(t_detailed)),' ',num2str(std(t_detailed))]);
301 disp('N M t_mean t_std');
302 o = [Ns(:), Ms(:), mean(t_reduced,1)', std(t_reduced,1)'];
303 s = sprintf('%2.0f %2.0f %2.2f %2.2f \n ',o');
306 offline_data = rb_offline_prep(detailed_data,model);
307 plot(offline_data.grid_local_ext);
311 set(gcf,'Color',[1,1,1]);
314 load(fullfile(rbmatlabresult,detailedfname));
315 % Mmax = 150; Nmax = 100
319 model.enable_error_estimator = 1;
320 % model.RB_error_indicator = 'estimator';
323 case 11 % compare error and error estimator
324 load(fullfile(rbmatlabresult,detailedfname));
328 % model.Mstrich = 10; % set below in loop
329 model.enable_error_estimator = 1;
331 model_data = gen_model_data(model);
332 % detailed_data = gen_detailed_data(model,model_data);
333 reduced_data = gen_reduced_data(model, detailed_data);
335 model = model.set_mu(model,[1.5]);
336 % model = model.set_mu(model,2);
337 % model = model.set_mu(model,1);
338 sim_data = detailed_simulation(model,model_data);
339 % Mstrich = [1,10,150];
341 for Mi = 1:length(Mstrich);
342 model.Mstrich = Mstrich(Mi);
343 rb_sim_data = rb_simulation(model, reduced_data);
344 rb_sim_data = rb_reconstruction(model, detailed_data, rb_sim_data);
346 De{Mi} = rb_sim_data.Delta;
349 err_data.U = sim_data.U - rb_sim_data.U;
350 err = sqrt(max(0,sum(err_data.U
' * detailed_data.W * err_data.U)))';
353 % somehow replace by matrix version!!!
354 for i = 2:length(max_t_err)
355 if max_t_err(i) < max_t_err(i-1)
356 max_t_err(i) = max_t_err(i-1);
360 plot([De{1}(:),De{2}(:),De{3}(:),max_t_err(:),err(:)]);
361 Ylim =
get(gca,
'Ylim');
362 set(gca,
'Ylim',[0,max(Ylim)]);
363 title(
'rb state error and estimator');
364 legend({
'M''= 1, estimator \Delta(t)',...
365 'M''= 5, estimator \Delta(t)',...
366 'M''= 10, estimator \Delta(t)',...
367 '||e||_{L\infty([0,t],L2)}',...
368 '||e(t)||_{L2}'},
'Location',
'NorthWest');
371 error(
'step-number is unknown!');
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
function step1_detailed_simulation()
script performing a single detailed simulation and plotting it.
function nonlin_symmetry(step)
file performing RB steps for nonlin_symmetry model
function [ dmodel , rmodel ] = gen_models(ModelDescr descr,BasisGenDescr bg_descr)
generates an IDetailedModel and an IReducedModel instance from description structures.
function plot_error_landscape(output)
plots an output structure generated by stochastic_error_estimation()
function p = fv_plot(gridbase grid, dofs, params)
routine plotting a single fv function of fv_functions.
function demo_rb_gui(varargin)
reduced basis demo with sliders
function step2_empirical_interpolation()
script constructing a collateral reduced basis space for localized space operators.
function step4_dummy_reduced_basis()
script constructing a reduced basis from a single trajectory and performing a detailed simulation whe...
function [ ddescr , rdescr , dmodel , rmodel ] = nonlin_symmetry_oop(steps, combined, M_by_N_ratio, noof_ei_extensions, random, explicit, num_cpus, params)
small script demonstrating the burgers equation with explicit fv discretization and RB model reductio...
function step7_error_landscape()
script generating error landscapes by computing the true error of reduced simulations vs...
function step8_estimator_landscape()
script generating landscapes plot data by computing the error estimator of reduced simulations for gi...
function step6_demo_rb_gui()
script comparing time for a reduced and a detailed simulation and starting the demonstration GUI ...
function step3_detailed_ei_simulation()
script performing a detailed simulation with empirical interpolated operators comparing the result wi...