rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
convdiff_new.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  plot_params.plot_type = 'patch';
45 
46  switch step
47  case 0 % initialize model data
48  descr = convdiff_descr;
49  [dmodel, rmodel] = gen_models(descr);
50 
51  model_data = gen_model_data(dmodel);
52  case 1 % single detailed simulation and plot
53  disp('performing single detailed simulation')
54  tic
55  sim_data = detailed_simulation(dmodel, model_data);
56  toc
57  plot_sim_data(dmodel, 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, dmodel.mu_ranges);
62  % mu_test2 = cellfun(@min, params.mu_ranges);
63  simple_bg_descr.rb_problem_type = 'LinEvol';
64  simple_bg_descr.detailed_data_constructor = @SimpleDetailedData;
65  simple_bg_descr.do_orthonormalize = true;
66  simple_bg_descr.mu_list = {sim_data.mu};
67  rsimple_model = gen_reduced_model(dmodel, simple_bg_descr);
68  detailed_data = gen_detailed_data(rsimple_model, model_data);
69 
70  disp('reduced simulation:')
71 
72  tic;
73  reduced_data = gen_reduced_data(rsimple_model, detailed_data);
74  disp(['gen_reduced_data timining: ', num2str(toc)]);
75  rsimple_model.N = get_rb_size(detailed_data);
76 
77  reduced_data = extract_reduced_data_subset(rsimple_model, reduced_data);
78  set_mu(rsimple_model, sim_data.mu);
79 
80  tic;
81  rb_sim_data = rb_simulation(rsimple_model, reduced_data);
82  disp(['rb_simulation timing: ', num2str(toc)]);
83  tic;
84  rb_sim_data = rb_reconstruction(rsimple_model, detailed_data, rb_sim_data);
85  disp(['rb_reconstruction timing: ', num2str(toc)]);
86 
87  plot_params.plot_title = 'reduced simulation result';
88  plot_sim_data(dmodel, model_data, rb_sim_data, plot_params);
89  plot_params.plot_title = 'detailed simulation result';
90  plot_sim_data(dmodel, model_data, sim_data, plot_params);
91 
92  case 3 % reduced basis
93  disp('constructing reduced basis')
94  detailed_data = gen_detailed_data(rmodel, model_data);
95  % detailed_data = rb_basis_generation(detailed_data, ...
96  % params);
97  save(fullfile(rbmatlabresult,detailedfname),...
98  'detailed_data','rmodel');
99  leaf_dd = get_leaf(detailed_data, rmodel);
100  max_err_sequence = get_field_on_active_child(detailed_data.datatree, 'max_err_sequence', rmodel);
101  plot(max_err_sequence);
102  set(gca,'Yscale','log');
103  title('RB-generation error convergence');
104  case 4
105  mu_test = cellfun(@mean, rmodel.mu_ranges);
106  load(fullfile(rbmatlabresult,detailedfname));
107  disp('reduced simulation:')
108  rmodel.N = get_rb_size(detailed_data, rmodel);
109  reduced_data = gen_reduced_data(rmodel, detailed_data);
110 
111  reduced_data = extract_reduced_data_subset(rmodel, reduced_data);
112  tic;
113 
114  set_mu(rmodel, mu_test);
115  rb_sim_data = rb_simulation(rmodel,reduced_data);
116  t = toc;
117  disp(['time for online phase: t = ',num2str(t)]);
118 
119  disp('full simulation:')
120  set_mu(dmodel, get_mu(rmodel));
121  tic;
122  sim_data = detailed_simulation(dmodel,model_data);
123  t = toc;
124  disp(['time for detailed simulation: t = ',num2str(t)]);
125 
126  demo_rb_gui(rmodel,detailed_data,[],plot_params);
127 
128  case 7 % training-error landscape
129  disp('warning: takes a few hours!');
130  load(fullfile(rbmatlabresult,detailedfname));
131 
132  model.N = params.RB_stop_Nmax;
133 
134  offline_data = gen_reduced_data(model,detailed_data);
135  range_params.plot_fields = { 'N', 'M' };
136  range_params.max = [size(detailed_data.RB,2), ...
137  size(detailed_data.BM{1},2) ];
138  range_params.sample_size = [ 7, 12 ];
139  range_params.mu_set_size = 100;
140 
141  testdir = ['convdiff_test_', range_params.mu_set_size ];
142 
143  params.run_name = [testdir, '_step7'];
144  params.tictoctable = true;
145 
146  output = stochastic_error_estimation(model, detailed_data, offline_data,...
147  testdir, range_params, params);
148 
149  otherwise
150  error('step-number is unknown!');
151 
152  end; % switch
153 
154 
155 end; % for si
156 %| \docupdate
function [ dmodel , rmodel ] = gen_models(ModelDescr descr,BasisGenDescr bg_descr)
generates an IDetailedModel and an IReducedModel instance from description structures.
Definition: gen_models.m:17
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
a very simple detailed data implementation gathering several detailed snapshots spanning the reduced ...
Reduced basis implementation for linear evolution equations.
function rmodel = gen_reduced_model(dmodel,BasisGenDescr bg_descr)
generates an IReducedModel instance from a description structure.
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