rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
convdiff.m
Go to the documentation of this file.
1 % small script demonstrating the convdiff example from the M2AN Paper, that is
2 % also implemented in Dune. Later it will be possible to use the Dune
3 % implementation through a mex interface.
4 
5 % Martin Drohmann 06.05.2009
6 % based on burgers_fv.m by
7 % Bernard Haasdonk 14.8.2007
8 
9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 %%%%%% Select here, what is to be performed %%%%%%%%
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 step = 0 % initialize the model_data structure. This step needs to be executed
13  % once per Matlab session only
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 dummy reduced basis from single trajectory and check, if
20  % ei_interpolation with projection on this space maintains
21  % result. A simple reduced simulation can also be
22  % performed. All results should be visually identical
23 %step = 3 % generate reduced basis
24 %step = 6 % time measurement of reduced simulation and
25  % use reduced basis in rb_demo_gui
26 %step = 7 % generate error-landscape over varying N and M
27  % can take several hours!!!
28 %step = 8 % do runtime comparisons between detailed and reduced simulations
29 
30 %steps = {2,5,7,8}
31 steps = {0,1};
32 
33 for si=1:length(steps)
34 
35  step = steps{si};
36 
37  % output-filenames in rbmatlabresult
38  detailedfname = 'convdiff_detailed_interpol.mat';
39 
40  %% parameters for visualization
41  plot_params.show_colorbar = 1;
42  plot_params.colorbar_mode = 'EastOutside';
43  plot_params.plot = @fv_plot;
44 
45  switch step
46  case 0 % initialize model data
47  model = convdiff_model;
48 
49  model_data = gen_model_data(model);
50  case 1 % single detailed simulation and plot
51  disp('performing single detailed simulation')
52  tic
53  mu_test = cellfun(@mean, model.mu_ranges);
54  sim_data = detailed_simulation(model, model_data);
55  toc
56  plot_sim_data(model, model_data, sim_data, plot_params);
57 
58  case 2 % construct dummy reduced basis by single trajectory and simulate
59  disp('detailed interpolated simulation for basis construction:')
60  mu_test = cellfun(@mean, model.mu_ranges);
61  % mu_test2 = cellfun(@min, params.mu_ranges);
62  model = model.set_mu(model, mu_test);
63  sim_data = detailed_simulation(model, model_data);
64  UON = model.orthonormalize(model, model_data, sim_data.U);
65  detailed_data.grid = model_data.grid;
66  detailed_data.W = model_data.W;
67  detailed_data.RB = UON;
68  disp('reduced simulation:')
69  reduced_data = gen_reduced_data(model, detailed_data);
70  model.N = size(detailed_data.RB,2);
71  reduced_data = extract_reduced_data_subset(model, reduced_data);
72  model = model.set_mu(model, mu_test);
73  rb_sim_data = rb_simulation(model, reduced_data);
74  rb_sim_data = rb_reconstruction(model, detailed_data, rb_sim_data);
75 
76  plot_params.title = 'reduced simulation result';
77  plot_sim_data(model, model_data, rb_sim_data, plot_params);
78  plot_params.title = 'detailed simulation result';
79  plot_sim_data(model, model_data, sim_data, plot_params);
80 
81  case 3 % reduced basis
82  mu_test = cellfun(@mean, model.mu_ranges);
83  disp('constructing reduced basis')
84  detailed_data = gen_detailed_data(model, model_data);
85  tic;
86  % detailed_data = rb_basis_generation(detailed_data, ...
87  % params);
88  t = toc;
89  detailed_data.RB_info.elapsed_time = t;
90  save(fullfile(rbmatlabresult,detailedfname),...
91  'detailed_data','params');
92  plot(detailed_data.RB_info.max_err_sequence);
93  set(gca,'Yscale','log');
94  title('RB-generation error convergence');
95  case 4
96  mu_test = cellfun(@mean, model.mu_ranges);
97  load(fullfile(rbmatlabresult,detailedfname));
98  disp('reduced simulation:')
99  reduced_data = gen_reduced_data(model, detailed_data);
100  model.N = size(detailed_data.RB,2);
101 
102  reduced_data = extract_reduced_data_subset(model, reduced_data);
103  tic;
104 
105  model = model.set_mu(model, mu_test);
106  rb_sim_data = rb_simulation(model,reduced_data);
107  t = toc;
108  disp(['time for online phase: t = ',num2str(t)]);
109 
110  disp('full simulation:')
111  tic;
112  sim_data = detailed_simulation(model,model_data);
113  t = toc;
114  disp(['time for detailed simulation: t = ',num2str(t)]);
115 
116  demo_rb_gui(model,detailed_data,[],plot_params);
117 
118  case 7 % training-error landscape
119  disp('warning: takes a few hours!');
120  load(fullfile(rbmatlabresult,detailedfname));
121 
122  model.N = params.RB_stop_Nmax;
123 
124  offline_data = gen_reduced_data(model,detailed_data);
125  range_params.plot_fields = { 'N', 'M' };
126  range_params.max = [size(detailed_data.RB,2), ...
127  size(detailed_data.BM{1},2) ];
128  range_params.sample_size = [ 7, 12 ];
129  range_params.mu_set_size = 100;
130 
131  testdir = ['convdiff_test_', range_params.mu_set_size ];
132 
133  params.run_name = [testdir, '_step7'];
134  params.tictoctable = true;
135 
136  output = stochastic_error_estimation(model, detailed_data, offline_data,...
137  testdir, range_params, params);
138 
139  otherwise
140  error('step-number is unknown!');
141 
142  end; % switch
143 
144 
145 end; % for si
146 %| \docupdate