rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
basisgen.m
Go to the documentation of this file.
1 % Script basisgen: demonstration of functionality for basis generation
2 % and generation of plots for comparing different methods
3 
4 % B. Haasdonk and S. Habiger 27.7.2009
5 
6 %step = 1 % single detailed simulation with given data and plot. Run
7  % this with varying parameters mu until sure that scheme
8  % is stable. Modify dt or the data-functions accordingly,
9  % until a nice parameter-domain with uniformly stable
10  % detailed scheme is obtained.
11 %step = 2 % generate dummy reduced basis from single trajectory.
12  % simple reduced simulation can also be
13  % performed. All results should be visually identical
14 step = 3 % generate more intelligent reduced basis
15 %step = 4 % generate and test reduced basis for paper experiments
16 %step = 5 % generate plots of adaptive parameter grids
17  % generate plots of time/N, max_err/min_err, etc.
18 
19 switch step
20  case 1 % initialize model and single detailed simulation
21 
22  model = init_model('convdiff_model');
23  model_data = gen_model_data(model);
24  params.mu = [1,0];
25  sim_data = detailed_simulation(model,model_data,params);
26  params.title = 'detailed simulation';
27  params.axis_equal = 1;
28  plot_sim_data(model,model_data,sim_data,params);
29 
30  case 2 % simple RB generation by orthonormalizing trajectory
31 
32  model = init_model('convdiff_model');
33  model_data = gen_model_data(model);
34  mu_test = cellfun(@mean, model.mu_ranges);
35  % mu_test2 = cellfun(@min, para 1. case 3: ms.mu_ranges);
36  params.mu = mu_test;
37 
38  % not: gen_detailed_data is not called here as the following lines do
39  % the job:
40  sim_data = detailed_simulation(model, model_data, params);
41  UON = model.orthonormalize(model, model_data, sim_data.U);
42  detailed_data.grid = model_data.grid;
43  detailed_data.W = model_data.W;
44  detailed_data.RB = UON;
45 
46  reduced_data = gen_reduced_data(model, detailed_data, params);
47 % params.N = size(detailed_data.RB,2);
48 % reduced_data = extract_reduced_data_subset(reduced_data, params);
49  params.mu = mu_test;
50  rb_sim_data = rb_simulation(model, reduced_data, params);
51 % keyboard;
52  rb_sim_data = rb_reconstruction(model, detailed_data, rb_sim_data);
53 
54  params.axis_equal = 1;
55  params.title = 'reduced simulation result';
56  plot_sim_data(model, model_data, rb_sim_data, params);
57  params.title = 'detailed simulation result';
58  plot_sim_data(model, model_data, sim_data, params);
59  RB = detailed_data.RB;
60  save(fullfile(rbmatlabresult,'tmp_detailed_data.mat'),'RB','model');
61 
62  case 3 % test different basis generation methods
63 
64  model = init_model('convdiff_model');
65  model_data = gen_model_data(model);
66 
67 % params.RB_generation_mode = 'file_load';
68 % params.RB_basis_filename = fullfile(rbmatlabtemp,'tmp_detailed_data.mat');
69 
70  params.RB_generation_mode = 'uniform_fixed';
71  params.RB_numintervals = [4,4];
72  params.mu_ranges = model.mu_ranges;
73  params.RB_stop_epsilon = 1e-5;
74 % params.RB_stop_max_val_train_ratio = ???
75  params.RB_stop_timeout = 3600;
76  params.RB_stop_Nmax = 10;
77  params.RB_extension_algorithm = @RB_extension_PCA_fixspace;
78  params.RB_error_indicator = 'estimator';
79 % params.RB_detailed_val_savepath
80 % params.RB_detailed_train_savepath =
81 
82  %%%%%%%%%%%%%%%%%%%
83 
84  detailed_data = gen_detailed_data(model,model_data,params);
85 
86  %%%%%%%%%%%%%%%%%%%
87 
88  params.title='Reduced Basis';
89  params.axis_equal = 1;
90  params.clim_tight = 1;
91  plot_element_data_sequence(model,model_data.grid,detailed_data.RB,params);
92 
93  % test different methods of rb_basis_generation
94  % X 'file_load' : simple loading o 1. case 3: f reduced basis from a file
95  %
96  % X 'uniform_fixed' : greedy algorithm based on a uniform
97  % cartesian parameter grid
98  % 'random_fixed' : greedy algorithm based on a uniformly
99  % distributed random parameter set
100  % 'PCA_trajectory' : simple detailed simulation and PCA of the
101  % trajectory
102  % 'PCA_trajectories' : simple detailed simulation and PCA of the
103  % trajectories with parameter vectors specified in
104  % params.RB_mu_list
105  % 'uniform_refined' : greedy algorithm based on a uniformly
106  % random parameter set with grid refinement
107  % 'adaptive_refined' : greedy algorithm based on an adaptively
108  % refined parameter grid
109 
110  case 4 % generate different reduced basis by gen_and_test_basis
111 
112  % the file basis/basisgen/gen_and_test_basis must be updated to
113  % new syntax... this is main work
114 
115  % ... correct call of gen_and_test_basis with correct arguments
116 
117  % for example:
118  % fns = {'RB_uniform_refined_p3_i2_r1_notimeout_tested',...
119  %'RB_uniform_refined_p3_i3_r1_notimeout_tested',...
120  %'RB_adaptive_refined_p3_i2_r1_smax1000_theta5e-2_tested',...
121  %'RB_adaptive_refined_p3_i3_r1_smax1000_theta5e-2_notimeout_tested',...
122  %'RB_uniform_fixed_p3_64_tested',...
123  %'RB_uniform_fixed_p3_125_tested'};
124  %%'RB_uniform_fixed_p3_216_notimeou
125 
126 
127  case 5 % plots of adaptive grids and error estimator
128 
129  % adapt the below code such that new plots are generated...
130 
131  % ...
132 
133  % the following code was used to generate the figures in the
134  % ADMOS Paper on adaptive parameter grids:
135  % figure;
136  %load(['C:\Dokumente und Einstellungen\Bernard\Eigene Dateien\',...
137  % 'TempMatlab\basisgen\RB_uniform_fixed_64.mat']);
138  %params.num_plot_intervals = [40,40];
139  %offline_data = rb_offline_prep(detailed_data,params);
140  %params.N = size(detailed_data.RB,2);
141  %reduced_data = rb_online_prep(offline_data,params);
142  %params.no_lines = 1;
143  %plot_error_estimator(reduced_data,params);
144  %c = get(gca,'Children');
145  %cdata = get(c(end),'Cdata');
146  %cdata = log10(cdata);
147  %set(c(end),'Cdata',cdata);
148  %set(gca,'Clim',[-8,-7]);
149  %title('log_{10}(\Delta(\mu))');
150  %colorbar;
151  %%colorbar;
152  %hold on;
153  %par.numintervals = params.RB_numintervals;
154  %par.range = params.mu_ranges; 1. case 3:
155  %par.color = [0,0,0];
156  %pgrid = cubegrid(par);
157  %plot(pgrid,par);
158  %%
159  %figure;
160  %load(['C:\Dokumente und Einstellungen\Bernard\Eigene Dateien\',...
161  % 'TempMatlab\basisgen\RB_uniform_refined_2_2_r1.mat']);
162  %params.num_plot_intervals = [40,40];
163  %offline_data = rb_offline_prep(detailed_data,params);
164  %params.N = size(detailed_data.RB,2);
165  %reduced_data = rb_online_prep(offline_data,params);
166  %params.no_lines = 1;
167  %plot_error_estimator(reduced_data,params);
168  %c = get(gca,'Children');
169  %cdata = get(c(end),'Cdata');
170  %cdata = log10(cdata);
171  %set(c(end),'Cdata',cdata);
172  %set(gca,'Clim',[-8,-7]);
173  %title('log_{10}(\Delta(\mu))');
174  %colorbar;
175  %hold on;
176  %params.no_lines = 0;
177  %params.color = [0,0,0];
178  %plot(detailed_data.RB_info.MMesh_list{end},params);
179  %%CLIM : 2.07876e-008 7.30869e-008
180  %%
181  %figure;
182  %load(['C:\Dokumente und Einstellungen\Bernard\Eigene Dateien\',...
183  % 'TempMatlab\basisgen\RB_adaptive_refined_2_2_r1_smax1000.mat']);
184  %params.num_plot_intervals = [40,40];
185  %offline_data = rb_offline_prep(detailed_data,params);
186  %params.N = size(detailed_data.RB,2);
187  %reduced_data = rb_online_prep(offline_data,params);
188  %params.no_lines = 1;
189  %plot_error_estimator(reduced_data,params);
190  %c = get(gca,'Children');
191  %cdata = get(c(end),'Cdata');
192  %cdata = log10(cdata);
193  %set(c(end),'Cdata',cdata);
194  %set(gca,'Clim',[-8,-7]);
195  %title('log_{10}(\Delta(\mu))');
196  %colorbar;
197  %hold on;
198  %params.no_lines = 0;
199  %params.color = [0,0,0];
200  %plot(detailed_data.RB_info.MMesh_list{end},params);
201  %%CLIM : 2.07876e-008 7.30869e-008
202 
203  case 6 % different plots of time/N, max_err/min_err, etc.
204 
205  % adapt the below code such that nice plots are generated
206 
207  % select different basis generation methods
208 
209  % the following code was used to generate the figures in the
210  % ADMOS Paper on adaptive parameter grids:
211 
212  %fns = {'RB_uniform_refined_p3_i2_r1_tested',...
213  %'RB_uniform_refined_p3_i3_r1_tested',...
214  %'RB_adaptive_refined_p3_i2_r1_smax1000_theta5e-2_tested',...
215  %'RB_adaptive_refined_p3_i3_r1_smax1000_theta5e-2_tested',...
216  %'RB_uniform_fixed_p3_64_tested',...
217  %'RB_uniform_fixed_p3_125_tested',...
218  %};
219  %
220  %params.plot_train_times = 1;
221  %params.plot_train_estimators = 0;
222  %params.plot_test_estimators = 0;
223  %params.plot_test_errors = 0;
224  %params.plot_linestyles = {'-','-.','-','-.','-','-.'};
225  %params.plot_linecolors = {'r','r',[0,0.6,0],[0,0.6,0],'b','b'};
226  %params.plot_linewidths = [2,2,2,2,2,2];
227  %params.plot_legends_location = 'Northwest';
228  %params.plot_legends = {'uniform-refined 2^3',...
229  % 'uniform-refined 3^3',...
230  % 'adaptive-refined 2^3',...
231  % 'adaptive-refined 3^3',...
232  % 'uniform-fixed 4^3',...
233  % 'uniform-fixed 5^3'};
234  %
235  % plot_basisgen_results(fns,params);
236 
237  % uniform-refined approaches jetzt ohne timeout:
238  %fns = {'RB_uniform_refined_p3_i2_r1_notimeout_tested',...
239  %'RB_uniform_refined_p3_i3_r1_notimeout_tested',...
240  %'RB_adaptive_refined_p3_i2_r1_smax1000_theta5e-2_tested',...
241  %'RB_adaptive_refined_p3_i3_r1_smax1000_theta5e-2_notimeout_tested',...
242  %'RB_uniform_fixed_p3_64_tested',...
243  %'RB_uniform_fixed_p3_125_tested'};
244  %'RB_uniform_fixed_p3_216_notimeout_tested',...
245 
246  %params.plot_train_times = 0;
247  %params.plot_train_estimators = 1;
248  %params.plot_test_estimators = 0;
249  %params.plot_test_errors = 0;
250  %params.plot_legends_location = 'NorthEast';
251  %plot_basisgen_results(fns,params);
252 
253  % => Manuelles Speichern der Bilder als
254  % computation_times.eps und
255  % train_errors.eps
256 
257 
258  %%%%%% run basisgen_main with the following settings in the header:
259  %%
260  %%test_RB_methods = {...
261  %% 'RB_uniform_refined_2_2_r1',...
262  %% 'RB_uniform_refined_2_2_r5',...
263  %% 'RB_uniform_fixed_64',...
264  %% 'RB_uniform_fixed_256',...
265  %% 'RB_uniform_refined_2_2_r1',...
266  %% 'RB_uniform_refined_2_2_r5',...
267  %% 'RB_adaptive_refined_2_2_r1_smax1000_theta5e-2',...
268  %% 'RB_adaptive_refined_2_2_r5_smax1000_theta5e-2',...
269  %% 'RB_adaptive_refined_2_2_r1_smax1000_theta1e-1',...
270  %% 'RB_adaptive_refined_2_2_r5_smax1000_theta1e-1',...
271  %% };
272  %% test_RB_indicators = {'estimator'}; % only estimators
273  %% compute_RB_methods = test_RB_methods;
274  %
275  %%%%%%% then perform the following on the generated files for getting
276  %%%%%%% the figures
277 
278  %%fns = {...
279  %% 'RB_uniform_refined_2_2_r1_tested',...
280  %% 'RB_uniform_fixed_256_tested',...
281  %% 'RB_adaptive_refined_2_2_r1_smax1000_theta5e-2_tested'};
282 
283  %% uniform-refined approaches jetzt ohne timeout:
284  %fns = {'RB_uniform_refined_p3_i2_r1_notimeout_tested',...
285  %'RB_uniform_refined_p3_i3_r1_notimeout_tested',...
286  %'RB_adaptive_refined_p3_i2_r1_smax1000_theta5e-2_tested',...
287  %'RB_adaptive_refined_p3_i3_r1_smax1000_theta5e-2_notimeout_tested',...
288  %'RB_uniform_fixed_p3_64_tested',...
289  %'RB_uniform_fixed_p3_125_tested'};
290  %%'RB_uniform_fixed_p3_216_notimeout_tested',...
291 
292  %params.plot_train_times = 0;
293  %params.plot_train_estimators = 0;
294  %params.plot_test_estimators = 1;
295  %params.plot_test_errors = 1;
296  %params.plot_linestyles = {'-','-.','-','-.','-','-.'};
297  %params.plot_linecolors = {'r','r',[0,0.6,0],[0,0.6,0],'b','b'};
298  %params.plot_linewidths = [2,2,2,2,2,2];
299  %params.plot_legends_location = 'North';
300  %params.plot_legends = {'uniform-refined 2^3',...
301  % 'uniform-refined 3^3',...
302  % 'adaptive-refined 2^3',...
303  % 'adaptive-refined 3^3',...
304  % 'uniform-fixed 4^3',...
305  % 'uniform-fixed 5^3'};
306  %
307  %plot_basisgen_results(fns,params);
308  %close(gcf-1);
309  %close(gcf);
310  %
311  %params.plot_legends_location = 'NorthWest';
312  %plot_basisgen_results(fns,params);
313  %close(gcf-2);
314  %close(gcf-1);
315  %
316  %% => Manuelles Speichern der Bilder als
317  %% test_errors.eps und
318  %% test_error_ratio.eps
319 
320 
321  % fns = {'RB_uniform_refined_p3_i2_r1_notimeout_tested',...
322  %'RB_uniform_refined_p3_i3_r1_notimeout_tested',...
323  %'RB_adaptive_refined_p3_i2_r1_smax1000_theta5e-2_tested',...
324  %'RB_adaptive_refined_p3_i3_r1_smax1000_theta5e-2_notimeout_tested',...
325  %'RB_uniform_fixed_p3_64_tested',...
326  %'RB_uniform_fixed_p3_125_tested'};
327  %%'RB_uniform_fixed_p3_216_notimeout_tested',...
328  %
329  %params.plot_train_times = 0;
330  %params.plot_train_estimators = 0;
331  %params.plot_test_estimators = 1;
332  %params.plot_test_errors = 0;
333  %params.plot_max_test_vs_time = 1;
334  %params.plot_linestyles = {'-','-.','-','-.','-','-.'};
335  %params.plot_linecolors = {'r','r',[0,0.6,0],[0,0.6,0],'b','b'};
336  %params.plot_linewidths = [2,2,2,2,2,2];
337  %params.plot_legends_location = 'NorthEast';
338  %params.plot_legends = {'uniform-refined 2^3',...
339  % 'uniform-refined 3^3',...
340  % 'adaptive-refined 2^3',...
341  % 'adaptive-refined 3^3',...
342  % 'uniform-fixed 4^3',...
343  % 'uniform-fixed 5^3'};
344  %
345  %plot_basisgen_results(fns,params);
346  %close(gcf-3);
347  %close(gcf-2);
348  %close(gcf-1);
349  %set(gca,'Xlim',[0,3600]);
350  %set(gca,'Ylim',[1e-7,2e-4]);
351 
352  otherwise
353  error('step number unknown')
354 end;
355 
356 
357 
358 %| \docupdate