rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules 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 = 1 % 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,2,3,4,7};
32 %steps = {4};
33 
34 for si=1:length(steps)
35 
36  step = steps{si};
37 
38  % output-filenames in rbmatlabresult
39  detailedfname = 'convdiff_detailed_interpol.mat';
40 
41  %% parameters for visualization
42  plot_params.show_colorbar = 1;
43  plot_params.colorbar_mode = 'EastOutside';
44  plot_params.plot = @fv_plot;
45 
46  switch step
47  case 0 % initialize model data
48  model = convdiff_model;
49 
50  model_data = gen_model_data(model);
51  case 1 % single detailed simulation and plot
52  disp('performing single detailed simulation')
53  tic
54  mu_test = cellfun(@mean, model.mu_ranges);
55  sim_data = detailed_simulation(model, model_data);
56  toc
57  plot_sim_data(model, model_data, sim_data, plot_params);
58 
59  case 2 % construct dummy reduced basis by single trajectory and simulate
60  disp('detailed interpolated simulation for basis construction:')
61  mu_test = cellfun(@mean, model.mu_ranges);
62  % mu_test2 = cellfun(@min, params.mu_ranges);
63  model = model.set_mu(model, mu_test);
64  sim_data = detailed_simulation(model, model_data);
65  UON = model.orthonormalize(model, model_data, sim_data.U);
66  detailed_data.grid = model_data.grid;
67  detailed_data.W = model_data.W;
68  detailed_data.RB = UON;
69  disp('reduced simulation:')
70  reduced_data = gen_reduced_data(model, detailed_data);
71  model.N = size(detailed_data.RB,2);
72  reduced_data = extract_reduced_data_subset(model, reduced_data);
73  model = model.set_mu(model, mu_test);
74  rb_sim_data = rb_simulation(model, reduced_data);
75  rb_sim_data = rb_reconstruction(model, detailed_data, rb_sim_data);
76 
77  plot_params.title = 'reduced simulation result';
78  plot_sim_data(model, model_data, rb_sim_data, plot_params);
79  plot_params.title = 'detailed simulation result';
80  plot_sim_data(model, model_data, sim_data, plot_params);
81 
82  case 3 % reduced basis
83  mu_test = cellfun(@mean, model.mu_ranges);
84  disp('constructing reduced basis')
85  detailed_data = gen_detailed_data(model, model_data);
86  tic;
87  % detailed_data = rb_basis_generation(detailed_data, ...
88  % params);
89  t = toc;
90  detailed_data.RB_info.elapsed_time = t;
91  save(fullfile(rbmatlabresult,detailedfname),...
92  'detailed_data','params');
93  plot(detailed_data.RB_info.max_err_sequence);
94  set(gca,'Yscale','log');
95  title('RB-generation error convergence');
96  case 4
97  mu_test = cellfun(@mean, model.mu_ranges);
98  load(fullfile(rbmatlabresult,detailedfname));
99  disp('reduced simulation:')
100  reduced_data = gen_reduced_data(model, detailed_data);
101  model.N = size(detailed_data.RB,2);
102 
103  reduced_data = extract_reduced_data_subset(model, reduced_data);
104  tic;
105 
106  model = model.set_mu(model, mu_test);
107  rb_sim_data = rb_simulation(model,reduced_data);
108  t = toc;
109  disp(['time for online phase: t = ',num2str(t)]);
110 
111  disp('full simulation:')
112  tic;
113  sim_data = detailed_simulation(model,model_data);
114  t = toc;
115  disp(['time for detailed simulation: t = ',num2str(t)]);
116  plot_params.axis_tight = 1;
117  demo_rb_gui(model,detailed_data,[],plot_params);
118 
119  case 7 % training-error landscape
120  disp('warning: takes a few hours!');
121  load(fullfile(rbmatlabresult,detailedfname));
122 
123  model.N = params.RB_stop_Nmax;
124 
125  offline_data = gen_reduced_data(model,detailed_data);
126  range_params.plot_fields = { 'N', 'M' };
127  range_params.max = [size(detailed_data.RB,2), ...
128  size(detailed_data.BM{1},2) ];
129  range_params.sample_size = [ 7, 12 ];
130  range_params.mu_set_size = 100;
131 
132  testdir = ['convdiff_test_', range_params.mu_set_size ];
133 
134  params.run_name = [testdir, '_step7'];
135  params.tictoctable = true;
136 
137  output = stochastic_error_estimation(model, detailed_data, offline_data,...
138  testdir, range_params, params);
139 
140  otherwise
141  error('step-number is unknown!');
142 
143  end; % switch
144 
145 
146 end; % for si
147 %| \docupdate
function model = convdiff_model(dummy)
function creating a simple model for a linear convection diffusion problem
function convdiff()
small script demonstrating the convdiff example from the M2AN Paper, that is also implemented in Dune...
Definition: convdiff.m:17
function p = fv_plot(gridbase grid, dofs, params)
routine plotting a single fv function of fv_functions.
Definition: fv_plot.m:17
function demo_rb_gui(varargin)
reduced basis demo with sliders
Definition: demo_rb_gui.m:17
function p = plot_sim_data(model, model_data, sim_data, plot_params)
function performing the plot of the simulation results as specified in model.
Definition: plot_sim_data.m:17
function detailed_data = rb_basis_generation(model, detailed_data)
reduced basis construction with different methods