1 % script performing different experiments
for linear dynamical
4 step = 1; % initialize model, compute some trajectories
5 %step = 2; % generate reduced basis by POD
6 %step = 3; % comparison detailed and reduced simulation
10 %params.coarse_factor = 2; % fact 2 => ndofs = 16384, nt = 1024, 15s detailed
11 %params.coarse_factor = 1; % fact 1 => ndofs = 32768, nt = 2048, 60s detailed
12 params.coarse_factor = 1;
15 % some filenames
for storing data
16 trajectory_fnbase =
'advection_fv_output_vconst_trajectory';
17 detailed_data_fname =
'advection_fv_output_vconst_detailed_data';
18 rb_fname =
'advection_fv_output_vconst_rb';
23 model = lin_ds_advection_vconst_fast_model(params);
25 model_data = gen_model_data(model);
27 mus = {[0,0,0],[1,1,1],[1,1,0.5],[0,0.5,1]};
30 disp(['computing trajectory number ',num2str(m)]);
32 model = model.set_mu(model,mu);
33 ds_sim_data = detailed_simulation(model,model_data);
34 save(fullfile(rbmatlabtemp,[trajectory_fnbase,num2str(m)]),...
35 'model',
'model_data',
'ds_sim_data');
40 disp(
'PCA of snapshots takes a while...');
41 load(fullfile(rbmatlabtemp,[trajectory_fnbase,
'1']),...
42 'model',
'model_data',
'ds_sim_data');
43 % smaller epsilon does result in more than 1 vector
for mu=0,0,0
45 RB = PCA_fixspace(ds_sim_data.X,[],model_data.G,[],[],epsilon);
46 %RB = orthonormalize_qr(ds_sim_data.X,model_data.G);
47 % select correct orthogonal
set
48 K = RB
' * model_data.G * RB;
49 i = find(abs(diag(K)-1)>1e-2);
51 disp(['found
',num2str(size(RB,2)),' basis vectors after traj. 1
']);
57 disp(['reduced to
',num2str(size(RB,2)),' basis vectors.
']);
60 load(fullfile(rbmatlabtemp,[trajectory_fnbase,'2
']),...
61 'model
','model_data
','ds_sim_data
');
62 RB2 = PCA_fixspace(ds_sim_data.X,RB,model_data.G,[],[],epsilon);
63 %RB = orthonormalize_qr(ds_sim_data.X,model_data.G);
64 % select correct orthogonal set
65 K = RB2' * model_data.G * RB2;
66 i = find(abs(diag(K)-1)>1e-2);
71 disp(['found ',num2str(size(RB2,2)),' basis vectors after traj. 2']);
74 disp(['reduced to ',num2str(size(RB2,2)),' basis vectors after traj. 2']);
76 % RB = orthonormalize(RB);
80 save(fullfile(rbmatlabtemp,rb_fname),'RB');
82 model.RB_basis_filename = fullfile(rbmatlabtemp,rb_fname);
83 model.RB_generation_mode = 'file_load';
85 detailed_data = gen_detailed_data(model,model_data);
88 save(fullfile(rbmatlabtemp,detailed_data_fname),...
89 'model','detailed_data')
91 case 3 % compare detailed and reduced simulation
93 load(fullfile(rbmatlabtemp,detailed_data_fname),...
94 'model','detailed_data')
95 load(fullfile(rbmatlabtemp,[trajectory_fnbase,'2']),...
100 %perform single reduced simulation for given parameter
101 reduced_data = gen_reduced_data(model,detailed_data);
102 model.N = reduced_data.N;
104 % model.nt = model.nt/4;
105 % disp('set nt to quarter!!');
106 rb_sim_data = rb_simulation(model,reduced_data);
108 rb_sim_data = rb_reconstruction(model,detailed_data,rb_sim_data)
109 disp(['time for reduced simulation: ',num2str(t_red)]);
111 % plot of reduced trajectory
112 lin_evol_model = model.base_model;
113 lin_evol_model_data = gen_model_data(lin_evol_model);
116 params.show_colorbar = 1;
117 params.axis_equal = 1;
118 params.plot = lin_evol_model.plot;
119 % plot single snapshot
120 %lin_evol_model.plot(rb_sim_data.X(:,1),lin_evol_model_data.grid, ...
124 params.title = 'reduced solution';
128 params.title = 'error';
130 lin_evol_model_data.grid,params)
132 % plot of reduced output
133 figure,plot(rb_sim_data.time,[rb_sim_data.Y;ds_sim_data.Y]);
134 legend('reduced output','detailed output');
136 case 4 % einfache Basis durch balanciertes Abschneiden erzeugen
141 %[V,W] = balanced_truncation(A,B,C,D,k)
143 case 5 % test der Basis anahand von balancierten System
146 error('step unknown');