1 function adaptive_basisgen_mcmds(step)
2 %
function adaptive_basisgen_mcmds(step)
4 % small script performing the experiments
for the (second half) of
5 % the MCMDS paper. Experiments are based on a simple advection example
7 % mu_names = {
'cone_weight',
'vx_weight',
'vy_weight'};
12 % step 1: detailed simulation of single trajectory, plot
13 % POD and save reduced basis
14 % reduced simulation and error
16 % Bernard Haasdonk 4.2.2010
24 %params.coarse_factor = 2; % fact 2 => ndofs = 16384, nt = 1024, 15s detailed
25 %params.coarse_factor = 1; % fact 1 => ndofs = 32768, nt = 2048, 60s detailed
26 params.coarse_factor = 2;
28 trajectory_fnbase =
'advection_trajectory';
29 detailed_data_fname =
'advection_detailed_data';
30 rb_fname =
'advection_rb';
35 disp(
'initialization of lin_ds model from lin_evol model');
36 %
verbose(1,
'initialization of lin_ds model from lin_evol model and ...
39 ds_model = fast_model(params);
40 ds_model.save_time_indices = 0:ds_model.nt;
42 %ds_model.u_function_ptr = @(params) 0.1; % define
new
45 ds_model_data = gen_model_data(ds_model);
48 %
set mu in model and base_model!!!
49 ds_model = ds_model.set_mu(ds_model,mu);
50 ds_sim_data = detailed_simulation(ds_model,ds_model_data);
53 save(fullfile(rbmatlabresult,[trajectory_fnbase,num2str(1)]),...
54 'ds_model',
'ds_model_data',
'ds_sim_data');
59 params.plot_title=
'detailed implicit lin_ds';
62 disp(
'PCA of snapshots takes a while...');
63 disp(
'Loading of trajectory...');
64 load(fullfile(rbmatlabresult,[trajectory_fnbase,
'1']),...
65 'ds_model',
'ds_model_data',
'ds_sim_data');
67 % smaller epsilon does result in more than 1 vector
for mu=0,0,0
69 disp(
'Calling PCA_Fixspace...');
70 RB = PCA_fixspace(ds_sim_data.X,[],ds_model_data.G,150,[],epsilon);
72 %RB = orthonormalize_qr(ds_sim_data.X,ds_model_data.G);
73 % select correct orthogonal
set
74 K = RB
' * ds_model_data.G * RB;
75 i = find(abs(diag(K)-1)>1e-2);
77 disp(['found
',num2str(size(RB,2)),' basis vectors after traj. 1
']);
83 disp(['reduced to
',num2str(size(RB,2)),' basis vectors.
']);
87 W = ds_model_data.G * V;
88 save(fullfile(rbmatlabresult,rb_fname),'RB
');
90 ds_model.RB_basis_filename = fullfile(rbmatlabresult,rb_fname);
91 ds_model.RB_generation_mode = 'file_load
';
93 detailed_data = gen_detailed_data(ds_model,ds_model_data);
96 save(fullfile(rbmatlabresult,detailed_data_fname),...
97 'model
','detailed_data
')
99 % compare detailed and reduced simulation
100 load(fullfile(rbmatlabresult,detailed_data_fname),...
101 'model
','detailed_data
')
102 load(fullfile(rbmatlabresult,[trajectory_fnbase,'1
']),...
107 %perform single reduced simulation for given parameter
108 reduced_data = gen_reduced_data(ds_model,detailed_data);
109 ds_model.N = reduced_data.N;
111 % ds_model.nt = ds_model.nt/4;
112 % disp('set nt to quarter!!
');
113 rb_sim_data = rb_simulation(ds_model,reduced_data);
115 rb_sim_data = rb_reconstruction(ds_model,detailed_data,rb_sim_data)
116 disp(['time
for reduced simulation:
',num2str(t_red)]);
118 % plot of reduced trajectory
119 lin_evol_model = ds_model.base_model;
120 lin_evol_model_data = gen_model_data(lin_evol_model);
123 params.show_colorbar = 1;
124 params.axis_equal = 1;
125 params.plot = lin_evol_model.plot;
126 % plot single snapshot
127 %lin_evol_model.plot(rb_sim_data.X(:,1),lin_evol_model_data.grid, ...
131 params.title = 'reduced solution
';
132 plot_sequence(rb_sim_data.X,lin_evol_model_data.grid,params)
135 params.title = 'error
';
136 plot_sequence((rb_sim_data.X-ds_sim_data.X),...
137 lin_evol_model_data.grid,params)
139 % plot of reduced output
140 figure,plot(rb_sim_data.time,[rb_sim_data.Y;ds_sim_data.Y]);
141 legend('reduced output
','detailed output
');
145 % generate more intelligent basis
147 disp('initialization of lin_ds model from lin_evol model
');
148 % verbose(1,'initialization of lin_ds model from lin_evol model and ...
151 model = fast_model(params);
152 model.save_time_indices = 0:model.nt;
157 % set mu in model and base_model!!!
158 model = model.set_mu(model,mu);
159 model.RB_stop_Nmax = 150;
161 %%%% basis generation: POD of single trajectory:
162 model.RB_generation_mode = 'PCA_trajectory
';
164 %%% basis generation. POD of several trajectories
165 %model.RB_generation_mode = 'PCA_trajectories
';
166 %model.RB_mu_list = {[0,0,0],[1,1,1]};
168 %%% basis generation: greedy_random_fixed
169 %model.RB_generation_mode = 'greedy_random_fixed
';
170 %model.RB_train_rand_seed = 12356;
171 %model.RB_train_size = 5;
172 %model.RB_error_indicator = 'estimator
';
173 %model.RB_stop_epsilon = 1e-2;
174 %model.RB_stop_timeout = 1*60; % 1 minute
175 %model.RB_stop_Nmax = 5;
176 %model.RB_extension_algorithm = @RB_extension_PCA_fixspace;
178 %%% basis generation: greedy_uniform_fixed
179 %model.RB_generation_mode = 'greedy_uniform_fixed
';
180 %model.RB_numintervals = [1,1,1];
181 %model.RB_error_indicator = 'estimator
';
182 %model.RB_extension_algorithm = @RB_extension_PCA_fixspace;
183 %model.RB_stop_epsilon = 1e-2;
184 %model.RB_stop_timeout = 1*60; % 1 minute
185 %model.RB_stop_Nmax = 5;
187 %%% basis generation: greedy_refined with uniform refinement
188 %model.RB_generation_mode = 'greedy_refined
';
189 %model.RB_stop_max_val_train_ratio = 5;
190 %model.RB_refinement_mode = 'uniform
';
191 %model.RB_val_rand_seed = 543;
192 %model.RB_M_val_size = 10;
193 %model.RB_numintervals = [1,1,1];
194 %model.RB_max_refinement_level = 10;
195 %model.RB_error_indicator = 'estimator
';
196 %model.RB_extension_algorithm = @RB_extension_PCA_fixspace;
197 %model.RB_stop_epsilon = 1e-8;
198 %model.RB_stop_timeout = 60*60; % 1 hour
199 %model.RB_stop_max_val_train_ratio = 4;
200 %model.RB_stop_Nmax = 150;
201 %model.mu_ranges = {[0.4,0.6],[0.4,0.6],[0.4,0.6]};
203 %%% basis generation: greedy_refined with local refinement
204 %% RB_detailed_val_savepath
205 %model.RB_generation_mode = 'greedy_refined
';
206 %model.RB_refinement_mode = 'adaptive
';
207 %model.RB_stop_max_val_train_ratio = 5;
208 %model.RB_refinement_theta = 0.2;
209 %model.RB_val_rand_seed = 543;
210 %model.RB_M_val_size = 10;
211 %model.RB_numintervals = [1,1,1];
212 %model.RB_max_refinement_level = 10;
213 %model.RB_error_indicator = 'estimator
';
214 %model.RB_extension_algorithm = @RB_extension_PCA_fixspace;
215 %model.RB_stop_epsilon = 1e-2;
216 %model.RB_stop_timeout = 1*60; % 1 minute
217 %model.RB_stop_Nmax = 5;
219 % convert model into a p_part model
220 %params.p_part_generation_mode = 'uniform
';
221 %params.p_part_numintervals = [2,1,1];
222 %model = p_part_model(model,params);
224 % convert model into a p_part model
225 %params.p_part_generation_mode = 'adaptive
';
226 %params.p_part_numintervals = [2,1,1];
227 %model = p_part_model(model,params);
229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 model_data = gen_model_data(model);
232 detailed_data = gen_detailed_data(model,model_data);
236 save(fullfile(rbmatlabresult,detailed_data_fname),...
237 'model
','detailed_data
')
239 % compare detailed and reduced simulation
240 load(fullfile(rbmatlabresult,detailed_data_fname),...
241 'model
','detailed_data
')
242 load(fullfile(rbmatlabresult,[trajectory_fnbase,'1
']),...
247 %perform single reduced simulation for given parameter
248 reduced_data = gen_reduced_data(model,detailed_data);
249 model.N = reduced_data.N;
251 % model.nt = model.nt/4;
252 % disp('set nt to quarter!!
');
253 rb_sim_data = rb_simulation(model,reduced_data);
255 rb_sim_data = rb_reconstruction(model,detailed_data,rb_sim_data)
256 disp(['time
for reduced simulation:
',num2str(t_red)]);
258 % plot of reduced trajectory
259 lin_evol_model = model.base_model;
260 lin_evol_model_data = gen_model_data(lin_evol_model);
263 params.show_colorbar = 1;
264 params.axis_equal = 1;
265 params.plot = lin_evol_model.plot;
266 % plot single snapshot
267 %lin_evol_model.plot(rb_sim_data.X(:,1),lin_evol_model_data.grid, ...
271 params.title = 'reduced solution
';
272 plot_sequence(rb_sim_data.X,lin_evol_model_data.grid,params)
275 params.title = 'error
';
276 plot_sequence((rb_sim_data.X-ds_sim_data.X),...
277 lin_evol_model_data.grid,params)
279 % plot of reduced output
280 figure,plot(rb_sim_data.time,[rb_sim_data.Y;ds_sim_data.Y]);
281 legend('reduced output
','detailed output
');
283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284 % step = 7 % time measurements
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 t_detailed = zeros(1,nreps);
292 % initialize detailed model and simulate
294 load(fullfile(rbmatlabresult,detailed_data_fname),...
295 'model
','detailed_data
')
298 % lin_evol_model = advection_fv_output_vconst_model(params);
299 %lin_evol_model.debug = 1;
300 %lin_evol_model_data = gen_model_data(lin_evol_model);
302 % set some additional fields in model which will be copied into
303 % ds model depending on whether constants are known or not:
304 % estimate_constants = 0;
305 % if estimate_constants
306 % %%% if constant estimaton has to be performed:
307 % lin_evol_model.estimate_lin_ds_nmu = 4;
308 % lin_evol_model.estimate_lin_ds_nX = 10;
309 % lin_evol_model.estimate_lin_ds_nt = 4;
312 % % the following values are rough bounds, so could be
313 % % non-rigorous, then larger search must be performed.
314 % lin_evol_model.state_bound_constant_C1 = 1;
315 % lin_evol_model.output_bound_constant_C2 = 1.2916;
318 % model = lin_ds_from_lin_evol_model(lin_evol_model);
319 % % set accelerated data functions from below
320 % model.A_function_ptr = @(model,model_data) ...
321 % eval_affine_decomp(@A_components,...
322 % @A_coefficients,...
325 % model.B_function_ptr = @(model,model_data) ...
326 % eval_affine_decomp(@B_components,...
327 % @B_coefficients,...
329 % %model.u_function_ptr = @(params) 0.1; % define new
330 model_data = gen_model_data(model);
332 disp('skipping detailed simulations...
')
336 disp(['repetition =
',num2str(r)])
337 mu = [1,1,0.5]-rand(1,3)*0.01;
338 model = model.set_mu(model,mu);
340 ds_sim_data = detailed_simulation(model,model_data);
341 t_detailed(1,r) = toc;
346 disp('--------------------------------------------------')
347 disp('detailed simulation')
349 disp([
'mean t_detailed=',num2str(mean(t_detailed))]);
350 disp(
'--------------------------------------------------')
352 % reduced simulation with and without error estimation
354 clear(
'ds_sim_data');
355 model.RB_generation_mode =
'file_load';
356 model.RB_basis_filename = ...
357 fullfile(rbmatlabresult,rb_fname);
358 detailed_data = gen_detailed_data(model,model_data);
359 reduced_data = gen_reduced_data(model,detailed_data);
361 Ns = [150:-10:10]; %,30,20,10];
362 Ns = Ns(find(reduced_data.N>=Ns));
364 t_reduced_with_err_est = zeros(length(Ns),nreps);
365 t_reduced_without_err_est = zeros(length(Ns),nreps);
367 % reduced simulation with and without error estimation
370 model.error_estimation = err_est;
371 disp([
'err_est= ',num2str(err_est)]);
372 for n_ind = 1:length(Ns)
373 disp(['M = ',num2str(Ns(n_ind))]);
376 disp(['repetition = ',num2str(r)])
377 mu = [1,1,1]-rand(1,3)*0.01;
378 model = model.set_mu(model,mu);
380 rb_sim_data = rb_simulation(model,reduced_data);
381 if size(rb_sim_data.Xr,1)~=Ns(n_ind)
382 disp('N dimension not set correctly!');
386 t_reduced_with_err_est(n_ind,r) = toc;
388 t_reduced_without_err_est(n_ind,r) = toc;
394 % output measurements
396 disp('--------------------------------------------------')
397 disp('detailed simulation')
399 disp(['mean t_detailed=',num2str(mean(t_detailed))]);
401 disp('--------------------------------------------------')
402 disp('reduced simulation with error estimation')
403 disp(t_reduced_with_err_est);
404 disp(['mean t_reduced_with_err_est=',...
405 num2str(mean(t_reduced_with_err_est,2)')]);
406 disp(['Ns =',num2str(Ns)]);
408 disp('--------------------------------------------------')
409 disp('reduced simulation without error estimation')
410 disp(t_reduced_without_err_est);
411 disp(['mean t_reduced_without_err_est=',...
412 num2str(mean(t_reduced_without_err_est,2)')]);
413 disp(['Ns =',num2str(Ns)]);
414 disp('--------------------------------------------------')
416 save(fullfile(rbmatlabresult,'time_measurements'));
418 % dim_x = 65536, nt = 2048
420 %mean t_detailed=64.3806
421 %--------------------------------------------------
422 %reduced simulation with error estimation
423 % 3.4542 3.5969 3.5659 3.4216 3.6170
424 % 3.3648 3.3816 3.4218 3.4391 3.4552
425 % 3.1643 3.1312 3.1244 3.1433 3.1720
426 % 3.0594 3.0496 3.0628 3.0486 3.0387
427 % 2.9993 2.9953 3.0078 2.9413 2.9603
428 % 2.9555 2.9093 2.9091 2.9510 2.9256%%%
430 %mean t_reduced_with_err_est=3.5311 3.4125 3.147 3.0518 2.9808 2.9301
431 %Ns =60 50 40 30 20 10
432 %--------------------------------------------------
433 %reduced simulation without error estimation
434 % 2.3975 2.4220 2.2924 2.4490 2.3302
435 % 2.3322 2.3198 2.3425 2.3056 2.3512
436 % 2.2227 2.2734 2.2210 2.2582 2.2504
437 % 2.2531 2.2180 2.2429 2.2212 2.2612
438 % 2.2283 2.1979 2.2581 2.2241 2.1957
439 % 2.2274 2.2014 2.2577 2.1856 2.2268
441 %mean t_reduced_without_err_est=2.3782 2.3303 2.2451 2.2393 2.2208 2.2198
442 %Ns =60 50 40 30 20 10
443 %--------------------------------------------------
445 case 8 % compare original and accelerated detailed model
447 disp('compare original and accelerated lin_ds models');
450 % initialize detailed model and simulate
451 lin_evol_model = advection_fv_output_vconst_model(params);
452 estimate_constants = 0;
453 if estimate_constants
454 %%% if constant estimaton has to be performed:
455 lin_evol_model.estimate_lin_ds_nmu = 4;
456 lin_evol_model.estimate_lin_ds_nX = 10;
457 lin_evol_model.estimate_lin_ds_nt = 4;
460 % the following values are rough bounds, so could be
461 % non-rigorous, then larger search must be performed.
462 lin_evol_model.state_bound_constant_C1 = 1;
463 lin_evol_model.output_bound_constant_C2 = 1.2916;
466 model = lin_ds_from_lin_evol_model(lin_evol_model);
467 %model.u_function_ptr = @(params) 0.1; % define new
468 model_data = gen_model_data(model);
470 % set accelerated data functions
471 model_fast = lin_ds_from_lin_evol_model(lin_evol_model);
472 model_fast.A_function_ptr = @(model,model_data) ...
473 eval_affine_decomp(@A_components,...
477 model_fast.B_function_ptr = @(model,model_data) ...
478 eval_affine_decomp(@B_components,...
482 % model_fast.C_function_ptr = @(model,model_data) ...
483 % eval_affine_decomp(@C_components,...
484 % @C_coefficients,...
487 % disp('skipping detailed simulations...')
490 mu = [1,1,0.5]-rand(1,3)*0.01;
491 model = model.set_mu(model,mu);
492 model_fast = model_fast.set_mu(model_fast,mu);
494 ds_sim_data = detailed_simulation(model,model_data);
497 ds_sim_data_fast = detailed_simulation(model_fast,model_data);
498 t_detailed_fast = toc;
500 disp(['original t = ',num2str(t_detailed),...
501 ', accelerated t = ',num2str(t_detailed_fast)]);
502 if ~isequal(ds_sim_data,ds_sim_data_fast)
503 disp('simulation results of original and accelerated model differ!')
505 disp('simulation results of original and accelerated model equal!')
510 case 9 % generate basis from POD-Greedy
513 model = fast_model(params);
514 model.cone_range = [0.4,0.6];
515 model.base_model.cone_range = model.cone_range;
517 % shrink range to 'single point'
518 % r = [0.4,0.6]; % => 2 -> 0.8 error nach 10 basisvektoren
519 % r = [0.0,1.0]; % => 4.6 -> 1.9 error nach 10 basisvektoren
520 % r = [0.45,0.55]; % => 2.38 -> 0.51 error nach 10 basisvektoren
521 model.mu_ranges = {[0,1],[0.4,0.6],[0.4,0.6]};
522 % model.rb_basis_generation_ptr = ...
523 % @basisgen_POD_greedy_uniform_fixed;
525 % model.RB_generation_mode =
'uniform_fixed';
526 % model.RB_num_intervals = [2,2,2];
528 model_data = gen_model_data(model);
530 disp(
'generating basis from POD-Greedy');
532 %
for basis generation,
set further fields:
534 model.verbose = 5; % => only dots in greedy loop
535 model.RB_generation_mode =
'greedy_uniform_fixed';
536 model.RB_numintervals = [1,1,1]; % => 0.5 in cone_pos obtained
537 % model.RB_numintervals = [4,4,4];
538 model.RB_stop_epsilon = 1e-5;
539 model.RB_stop_timeout = 3600;
540 model.RB_stop_Nmax =150;
541 % model.RB_stop_timeout = 600;
542 % model.RB_stop_Nmax =10;
544 model.RB_error_indicator =
'estimator';
546 % model.get_estimator_from_sim_data = @(sim_data) sim_data.DeltaX(end);
548 detailed_data = gen_detailed_data(model,model_data);
551 dfname = fullfile(rbmatlabresult,[detailed_data_fname,
'_greedy']);
552 save(dfname,
'model',
'detailed_data');
554 disp(
'successfully generated and saved detailed_data');
556 params.plot_title =
'reduced basis';
557 params.plot = model.base_model.plot;
558 lin_evol_model_data = gen_model_data(model.base_model);
559 plot_sequence(detailed_data.V,lin_evol_model_data.grid,params)
563 case 10 % reduced simulations and error plots
565 %basis_from_step = 9; % step 9
566 basis_from_step = 4; % step 4
568 if basis_from_step == 9
569 dfname = fullfile(rbmatlabresult,[detailed_data_fname,'_greedy']);
571 disp('loaded basis from step 9')
573 load(fullfile(rbmatlabresult,detailed_data_fname),...
574 'model','detailed_data')
576 % model = fast_model(params);
577 model_data = gen_model_data(model);
578 % dfname = fullfile(rbmatlabresult,'advection_fv_output_detailed_data_146');
579 % model.RB_basis_filename = ...
580 % fullfile(rbmatlabresult,'advection_fv_output_basis');
581 % model.RB_generation_mode = 'file_load';
582 % detailed_data = gen_detailed_data(model,model_data);
583 % dfname = fullfile(rbmatlabresult,'advection_fv_output_detailed');
585 tmp = load(fullfile(rbmatlabresult,[trajectory_fnbase,'2']));
586 ds_sim_data = tmp.ds_sim_data;
587 mu_from_file = get_mu(tmp.model);
588 disp('loaded basis from step 4')
589 model = model.set_mu(model,mu_from_file);
591 % trajectory2 above is made with this
592 % model = model.set_mu(model,[1,1,1]);
593 % model = model.set_mu(model,[1,1,1]);
594 % trajectory3 above is made with this:
595 %model = model.set_mu(model,[1,1,0.5]);
596 %model = model.set_mu(model,[0.5,0.6,0.6]);
597 %model = model.set_mu(model,[0.5,0.4,0.4]);
598 %model = model.set_mu(model,[0.5,0.5,0.5]);
599 model.N = size(detailed_data.V,2);
601 reduced_data = gen_reduced_data(model,detailed_data);
602 rb_sim_data = rb_simulation(model,reduced_data);
605 params.show_colorbar = 1;
606 params.axis_equal = 1;
608 % plot of reduced output
610 p = plot(rb_sim_data.time,...
612 rb_sim_data.Y+rb_sim_data.DeltaY; ...
613 rb_sim_data.Y-rb_sim_data.DeltaY]);
614 colors = {[1,0,0],[1,0,0],[1,0,0],[0,1,0]};
615 linestyles = {
'-',
'-.',
'-.',
'-'};
618 set(p(i),'Color',colors{i},
'Linestyle',linestyles{i},...
619 'Linewidth',widths(i));
621 %
set marker on rb_sim_data:
622 Xdata =
get(p(1),
'XData');
623 Ydata =
get(p(1),
'YData');
624 Zdata =
get(p(1),
'ZData');
625 set(p(1),
'XData',Xdata(1:4:end));
626 set(p(1),
'YData',Ydata(1:4:end));
627 set(p(1),
'ZData',Zdata(1:4:end));
628 set(p(1),
'Marker',
'o');
630 legend([
'y\^(t): reduced output'],...
631 'y\^(t)+\Delta_y(t)',...
632 'y\^(t)-\Delta_y(t)',
'Location',
'NorthWest');
633 title([
'k = ',num2str(model.N)],
'Fontsize',15);
635 % table of error, error estimator and effectivity
637 reduced_data = gen_reduced_data(model,detailed_data);
640 Ns = Ns(find(reduced_data.N>=Ns));
642 err = zeros(1,length(Ns));
643 err_estim = zeros(1,length(Ns));
644 effectivity = zeros(1,length(Ns));
646 for ni = 1:length(Ns)
648 rb_sim_data = rb_simulation(model, reduced_data);
649 err(ni) = abs(ds_sim_data.Y(end) - rb_sim_data.Y(end));
650 err_estim(ni) = rb_sim_data.DeltaY(end);
651 effectivity(ni) = err_estim(ni)/err(ni);
657 disp('finished computing effectivities')
660 case 11 % test of matlab ode solver for resulting sparse system
662 params.coarse_factor = 8; % nake model smaller
663 model = fast_model(params);
664 model.RB_generation_mode = 'from_detailed_data';
666 % detailed simulation:
667 model_data = gen_model_data(model);
668 model_data.RB = zeros(size(model_data.G,1),0);
669 detailed_data = gen_detailed_data(model,model_data);
671 model.decomp_mode = 0; % complete
672 model = model.set_time(model,0)
673 model = model.set_mu(model,[0.5,1,1]);
675 A = @(model,model_data,t) ...
676 model.A_function_ptr(model.set_time(model,t),model_data);
678 B = @(model,model_data,t) ...
679 model.B_function_ptr(model.set_time(model,t),model_data);
681 x0 = model.x0_function_ptr(model,model_data);
683 [t,x] = ode15s(@(t,x) A(model,model_data,t)*x + B(model,model_data,t), ...
686 disp(['ode15 takes ',num2str(time_ode15),' sec']);
688 params.plot_title = 'ode15 solution';
689 params.plot = model.base_model.plot;
690 params.axis_equal = 1;
691 lin_evol_model_data = gen_model_data(model.base_model);
695 sim_data = detailed_simulation(model,model_data);
697 disp(['rbmatlab takes ',num2str(time_rbmatlab),' sec']);
698 params.plot_title = 'rbmatlab solution';
699 params.plot = model.base_model.plot;
700 params.axis_equal = 1;
701 lin_evol_model_data = gen_model_data(model.base_model);
704 % further plots for MCMCS paper
707 load(fullfile(rbmatlabresult,detailed_data_fname),...
708 'model','detailed_data')
710 % plot of error estimator over parameter variation
711 % model = fast_model(params);
712 % model_data = gen_model_data(model);
713 % dfname = fullfile(rbmatlabresult,'advection_fv_output_detailed_data_146');
714 % model.RB_basis_filename = ...
715 % fullfile(rbmatlabresult,'advection_fv_output_basis');
716 % model.RB_generation_mode = 'file_load';
717 % detailed_data = gen_detailed_data(model,model_data);
718 % save(fullfile(rbmatlabresult,...
719 % 'advection_fv_output_detailed_2trajectories.mat'),...
720 % 'model','detailed_data')
722 % dfname = fullfile(rbmatlabresult,'advection_fv_output_detailed');
724 tmp = load(fullfile(rbmatlabresult,[trajectory_fnbase,'2']));
725 ds_sim_data = tmp.ds_sim_data;
726 disp('loaded basis from step 4')
728 % factors = 0:0.05:1;
729 reduced_data = gen_reduced_data(model,detailed_data);
731 Ns = Ns(find(reduced_data.N>=Ns));
733 err_estim = zeros(length(factors),length(Ns));
734 for ni = 1:length(Ns)
736 for i =1:length(factors)
737 model = model.set_mu(model, factors(i)*[1,1,1]);
738 rb_sim_data = rb_simulation(model, reduced_data);
739 % err(ni) = abs(ds_sim_data.Y(end) - rb_sim_data.Y(end));
740 err_estim(i,ni) = rb_sim_data.DeltaY(end);
741 % effectivity(ni) = err_estim(ni)/err(ni);
745 p = plot(factors,err_estim');
746 colors = {[1,0,0],[0,0.6,0],[0,0,1],[0,0,0]};
747 linestyles = {
'-',
'-.',
'-',
'-.'};
749 set(p(i),
'Linewidth',2,
'Color',colors{i},
'Linestyle',linestyles{i});
752 xlabel(
'parameter \mu_1=\mu_2=\mu_3');
753 ylabel(
'\Delta_y(\mu)');
754 title(
'error estimator from parameter sweep')
755 legend({
'k=1',
'k=8',
'k=16',
'k=32',
'k=64'},
'Location',
'NorthWest');
756 saveas(gcf,fullfile(rbmatlabresult,
'parameter_sweep.eps'),
'epsc');
759 disp(
'step number unknown');
764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
767 % generation of model from lin_evol_model and replace
769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
771 function model = fast_model(params);
772 lin_evol_model = advection_fv_output_vconst_model(params);
773 lin_evol_model.vy_weight = 0.5;
774 lin_evol_model.mu_names = {
'cone_amplitude',
'vx_weight'};
775 lin_evol_model.mu_ranges = {[0,1],[0,1]};
776 %lin_evol_model.debug = 1;
777 %lin_evol_model_data = gen_model_data(lin_evol_model);
779 %
set some additional fields in model which will be copied into
780 % ds model depending on whether constants are known or not:
781 estimate_constants = 0;
782 if estimate_constants
783 %%%
if constant estimaton has to be performed:
784 lin_evol_model.estimate_lin_ds_nmu = 4;
785 lin_evol_model.estimate_lin_ds_nX = 10;
786 lin_evol_model.estimate_lin_ds_nt = 4;
789 % the following values are rough bounds, so could be
790 % non-rigorous, then larger search must be performed.
791 lin_evol_model.state_bound_constant_C1 = 1;
792 lin_evol_model.output_bound_constant_C2 = 1.2916;
795 model = lin_ds_from_lin_evol_model(lin_evol_model);
796 %
set accelerated data functions from below
797 model.A_function_ptr = @(model,model_data) ...
798 eval_affine_decomp(@A_components,...
802 model.B_function_ptr = @(model,model_data) ...
803 eval_affine_decomp(@B_components,...
806 %model.u_function_ptr = @(params) 0.1; % define
new
809 %disp(
'set theta to 1!!!');
815 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
816 % auxialiary coefficient functions
for acceleration of
817 % advection model:
explicit implementation of coefficients
818 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
820 function Acomp = A_components(model,model_data)
821 Acomp = model_data.A_components;
823 function Acoeff = A_coefficients(model);
824 %model.base_model.decomp_mode = 2;
825 %model.base_model.t = model.t;
827 %model.base_model = model.set_mu(model.base_model,mu);
828 %[L_I_coeff, L_E_coeff, b_coeff] = ...
829 % model.base_model.operators_ptr(model.base_model, );
830 %% L_E = Id + Delta t * A
831 %Acoeff = L_E_coeff(2:end)/model.base_model.dt;
833 %Acoeff = -model.base_model.dt * ...
834 % model.base_model.velocity_coefficients_ptr(model.base_model);
836 Acoeff = - [model.vx_weight, model.base_model.vy_weight]*0.5; %*(1-model.t);
840 function Bcomp = B_components(model,model_data)
841 Bcomp = model_data.B_components;
843 function Bcoeff = B_coefficients(model);
844 % hmmm the coefficients are now called twice in A and B
845 % should somehow be cached later...
846 %model.base_model.decomp_mode = 2;
847 %model.base_model.t = model.t;
849 %model.base_model = model.set_mu(model.base_model,mu);
850 %[L_I_coeff, L_E_coeff, b_coeff] = ...
851 % model.base_model.operators_ptr(model.base_model, );
852 %% L_E = Id + Delta t * A
853 %Bcoeff2 = b_coeff/model.base_model.dt;
854 vcoeff = - [model.vx_weight, model.base_model.vy_weight]*0.5;%*(1-model.t);
855 Q_0 = model.base_model.cone_number;
856 dcoeff = zeros(1,Q_0);
857 max_pos = model.base_model.cone_weight * (Q_0-1)+1;
860 dcoeff(q) = (1-(max_pos-q))*(1-t) * ((max_pos>=q) && (max_pos < q+1)) ...
861 + (1+(max_pos-q))*(1-t) * ((max_pos>=q-1) && (max_pos < q));
863 v = -(vcoeff(:)*(dcoeff(:)'));
864 Bcoeff = v(:)*model.cone_amplitude;
869 %function Ccomp = C_components(model,model_data)
870 %Ccomp = model_data.C_components;
872 %function Ccoeff = C_coefficients(model);
873 %model.base_model.decomp_mode = 2;
874 %model.base_model.t = model.t;
876 %model.base_model = model.set_mu(model.base_model,mu);
878 % model.base_model.operators_output(model.base_model);