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 % Martin Drohmann 06.05.2009
5 % based on burgers_fv.m by
6 % Bernard Haasdonk 14.8.2007
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9 %%%%%% Select here, what is to be performed %%%%%%%%
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11 %step = 0 % initialize the model_data structure. This step needs to be executed
12 % once per Matlab session only
13 %step = 1 % single detailed simulation with given data and plot. Run
14 %
this with varying parameters mu until sure that scheme
15 % is stable. Modify dt or the data-functions accordingly,
16 % until a nice parameter-domain with uniformly stable
17 % detailed scheme is obtained.
18 %step = 2 % generate reduced basis
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21 %step = 6 % time measurement of reduced simulation and
22 % use reduced basis in rb_demo_gui
23 %step = 7 % generate error-landscape over varying N and M
24 % can take several hours!!!
25 %step = 9 % test one simulation
26 %step = 10 % generate dummy reduced basis from single trajectory.
27 % A simple reduced simulation can also be
28 % performed. All results should be visually identical
33 for si=1:length(steps)
37 params.model_type = 'default';
39 detailedfname = ['duneconvdiff_', params.model_type, '_detailed_interpol.mat'];
42 % $$$ %% parameters for visualization
43 % $$$ plot_params.show_colorbar = 1;
44 % $$$ plot_params.colorbar_mode = 'EastOutside';
47 case 0 % initialize model data
49 descr.detailedfname = fullfile(rbmatlabtemp, detailedfname);
50 params.mu_ranges = descr.mu_ranges;
51 params.mu_names = descr.mu_names;
55 model_data = gen_model_data(dmodel);
56 % $$$ grid = model_data.grid;
57 case 1 % single detailed simulation and plot
58 disp('performing single detailed simulation')
60 % mu_test = cellfun(@mean, model.mu_ranges);
62 % model = model.set_mu(model, mu_test);
63 sim_data = detailed_simulation(dmodel, model_data);
66 % Uname = [getenv('RBMATLABTEMP'),'/U',num2str(temp)];
68 % disp(['save solution U in ', Uname]);
72 case 2 % reduced basis
73 disp('constructing reduced basis')
74 % $$$ mu_test = cellfun(@mean, params.mu_ranges);
75 % $$$ params.mu = mu_test;
76 % $$$ sim_data = detailed_simulation(model, model_data, params);
79 detailed_data = gen_detailed_data(rmodel, model_data);
84 reduced_data = gen_reduced_data(rmodel, detailed_data);
86 rmodel.N = get_rb_size(detailed_data, rmodel);
87 reduced_data = extract_reduced_data_subset(rmodel, reduced_data);
89 %dunerbconvdiff('dune_keyboard');
90 params.mu = [0.001, 0.5, 0.5];
91 set_mu(rmodel, params.mu);
92 rb_sim_data = rb_simulation(rmodel, reduced_data);
93 % reconstruct_and_compare(model, rb_sim_data);
94 set_mu(dmodel, params.mu);
95 dmodel.descr.mexptr('reconstruct_and_compare', rb_sim_data.a);
97 save(fullfile(rbmatlabresult, detailedfname),...
98 'detailed_data','params');
99 plot(detailed_data.datatree.get_field_on_active_child('max_err_sequence', rmodel));
100 set(gca,'Yscale','log');
101 title('RB-generation error convergence');
104 load(fullfile(rbmatlabresult,detailedfname));
105 disp('reduced simulation:')
106 reduced_data = gen_reduced_data(model, detailed_data);
107 params.N = size(detailed_data.RB,2);
109 reduced_data = extract_reduced_data_subset(model, reduced_data);
112 rb_sim_data = rb_simulation(model,reduced_data,params);
114 disp(['time for online phase: t = ',num2str(t)]);
116 disp('full simulation:')
118 sim_data = detailed_simulation(model,model_data,params);
120 disp(['time for detailed simulation: t = ',num2str(t)]);
124 case 7 % training-error landscape
125 disp('warning: takes a few hours!');
126 load(fullfile(rbmatlabresult,detailedfname));
128 model.N = model.RB_stop_Nmax;
130 offline_data = gen_reduced_data(model,detailed_data);
131 range_params.plot_fields = {
'N',
'M' };
132 range_params.max = [ size(detailed_data.RB,2), ...
133 size(detailed_data.BM{1},2) ];
134 range_params.sample_size = [ 10, 12 ];
135 range_params.Msamples = 12;
136 range_params.mu_set_size = 100;
138 testdir = [
'duneconvdiff_test_', range_params.mu_set_size ];
140 params.run_name = [
'_', testdir,
'_step7'];
141 params.tictoctable =
true;
143 output=stochastic_error_estimation(model, detailed_data, offline_data,...
144 testdir, range_params, params);
147 tmp=load(fullfile(rbmatlabresult,detailedfname));
148 detailed_data = tmp.detailed_data;
150 reduced_data = gen_reduced_data(model, detailed_data, params);
152 params.N = get_rb_size(model, detailed_data);
153 reduced_data = extract_reduced_data_subset(model, reduced_data, ...
156 params.mu = [0.5, 0.5, 0.5];
157 rb_sim_data = rb_simulation(model, reduced_data, params);
161 case 10 % construct dummy reduced basis by single trajectory and simulate
162 disp(
'old, to be adjusted:')
163 disp('detailed interpolated simulation for basis construction:')
164 mu_test = cellfun(@mean, params.mu_ranges);
165 % mu_test2 = cellfun(@min, params.mu_ranges);
167 sim_data = detailed_simulation(model, model_data);
168 UON = model.orthonormalize(model, model_data, sim_data.U);
169 detailed_data.grid = model_data.grid;
170 detailed_data.W = model_data.W;
171 detailed_data.RB = UON;
172 disp('reduced simulation:')
173 reduced_data = gen_reduced_data(model, detailed_data);
174 params.N = size(detailed_data.RB,2);
175 reduced_data = extract_reduced_data_subset(reduced_data);
177 rb_sim_data = rb_simulation(model, reduced_data);
178 rb_sim_data = rb_reconstruction(model, detailed_data, rb_sim_data);
180 plot_params.title = 'reduced simulation result';
182 plot_params.title = 'detailed simulation result';
187 error('step-number is unknown!');
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
function [ dmodel , rmodel ] = gen_models(ModelDescr descr,BasisGenDescr bg_descr)
generates an IDetailedModel and an IReducedModel instance from description structures.
function convdiff()
small script demonstrating the convdiff example from the M2AN Paper, that is also implemented in Dune...
function dune_demo_rb_gui(varargin)
reduced basis demo with sliders for a remotely running DUNE-rb server application ...
function descr = convdiff_dune_descr(params)
convection diffusion example using dune-rb for high dimensional computations and data structures ...
function p = plot_sim_data(model, model_data, sim_data, plot_params)
function performing the plot of the simulation results as specified in model.
function detailed_data = rb_basis_generation(model, detailed_data)
reduced basis construction with different methods