rbmatlab 0.10.01
scripts/convdiff.m
Go to the documentation of this file.
00001 % small script demonstrating the convdiff example from the M2AN Paper, that is
00002 % also implemented in Dune. Later it will be possible to use the Dune
00003 % implementation through a mex interface.
00004 
00005 % Martin Drohmann 06.05.2009
00006 % based on burgers_fv.m by
00007 % Bernard Haasdonk 14.8.2007
00008 
00009 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00010 %%%%%% Select here, what is to be performed                        %%%%%%%%
00011 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00012 step = 0 % initialize the model_data structure. This step needs to be executed
00013           % once per Matlab session only
00014 %step = 1 % single detailed simulation with given data and plot. Run
00015           % this with varying parameters mu until sure that scheme
00016           % is stable. Modify dt or the data-functions accordingly,
00017           % until a nice parameter-domain with uniformly stable
00018           % detailed scheme is obtained.
00019 %step = 2 % generate dummy reduced basis from single trajectory and check, if
00020           % ei_interpolation with projection on this space maintains
00021           % result. A simple reduced simulation can also be
00022           % performed. All results should be visually identical
00023 %step = 3 % generate reduced basis
00024 %step = 6 % time measurement of reduced simulation and
00025           % use reduced basis in rb_demo_gui
00026 %step = 7 % generate error-landscape over varying N and M
00027           % can take several hours!!!
00028 %step = 8 % do runtime comparisons between detailed and reduced simulations
00029 
00030 %steps = {2,5,7,8}
00031 steps = {0,3,4};
00032 
00033 for si=1:length(steps)
00034 
00035   step = steps{si};
00036 
00037   % output-filenames in rbmatlabresult
00038   detailedfname = 'convdiff_detailed_interpol.mat';
00039 
00040   %% parameters for visualization
00041   plot_params.show_colorbar = 1;
00042   plot_params.colorbar_mode = 'EastOutside';
00043   plot_params.plot          = @fv_plot;
00044 
00045   switch step
00046    case 0 % initialize model data
00047     descr             = convdiff_descr;
00048     [dmodel, rmodel] = gen_models(descr);
00049 
00050     model_data = gen_model_data(dmodel);
00051    case 1 % single detailed simulation and plot
00052     disp('performing single detailed simulation')
00053     tic
00054     sim_data  = detailed_simulation(dmodel, model_data);
00055     toc
00056     plot_sim_data(dmodel, model_data, sim_data, plot_params);
00057 
00058    case 2 % construct dummy reduced basis by single trajectory and simulate
00059     disp('detailed interpolated simulation for basis construction:')
00060     % mu_test      = cellfun(@mean, dmodel.mu_ranges);
00061     %  mu_test2  = cellfun(@min, params.mu_ranges);
00062     simple_bg_descr.rb_problem_type           = 'LinEvol';
00063     simple_bg_descr.detailed_data_constructor = @SimpleDetailedData;
00064     simple_bg_descr.do_orthonormalize         = true;
00065     simple_bg_descr.mu_list                   = {sim_data.mu};
00066     rsimple_model = gen_reduced_model(dmodel, simple_bg_descr);
00067     detailed_data = gen_detailed_data(rsimple_model, model_data);
00068 
00069     disp('reduced simulation:')
00070 
00071     tic;
00072     reduced_data = gen_reduced_data(rsimple_model, detailed_data);
00073     disp(['gen_reduced_data timining: ', num2str(toc)]);
00074     rsimple_model.N = get_rb_size(detailed_data);
00075 
00076     reduced_data = extract_reduced_data_subset(rsimple_model, reduced_data);
00077     set_mu(rsimple_model, sim_data.mu);
00078 
00079     tic;
00080     rb_sim_data = rb_simulation(rsimple_model, reduced_data);
00081     disp(['rb_simulation timing:      ', num2str(toc)]);
00082     tic;
00083     rb_sim_data = rb_reconstruction(rsimple_model, detailed_data, rb_sim_data);
00084     disp(['rb_reconstruction timing:  ', num2str(toc)]);
00085 
00086     plot_params.plot_title = 'reduced simulation result';
00087     plot_sim_data(dmodel, model_data, rb_sim_data, plot_params);
00088     plot_params.plot_title = 'detailed simulation result';
00089     plot_sim_data(dmodel, model_data, sim_data, plot_params);
00090 
00091    case 3 % reduced basis
00092     disp('constructing reduced basis')
00093     detailed_data = gen_detailed_data(rmodel, model_data);
00094     %  detailed_data = rb_basis_generation(detailed_data, ...
00095     %                  params);
00096     save(fullfile(rbmatlabresult,detailedfname),...
00097          'detailed_data','rmodel');
00098     leaf_dd = get_leaf(detailed_data, rmodel);
00099     max_err_sequence = get_field_on_active_child(detailed_data.datatree, 'max_err_sequence', rmodel);
00100     plot(max_err_sequence);
00101     set(gca,'Yscale','log');
00102     title('RB-generation error convergence');
00103    case 4
00104     mu_test   = cellfun(@mean, rmodel.mu_ranges);
00105     load(fullfile(rbmatlabresult,detailedfname));
00106     disp('reduced simulation:')
00107     rmodel.N = get_rb_size(detailed_data, rmodel);
00108     reduced_data = gen_reduced_data(rmodel, detailed_data);
00109 
00110     reduced_data = extract_reduced_data_subset(rmodel, reduced_data);
00111     tic;
00112 
00113     set_mu(rmodel, mu_test);
00114     rb_sim_data = rb_simulation(rmodel,reduced_data);
00115     t = toc;
00116     disp(['time for online phase: t = ',num2str(t)]);
00117 
00118     disp('full simulation:')
00119     set_mu(dmodel, get_mu(rmodel));
00120     tic;
00121     sim_data = detailed_simulation(dmodel,model_data);
00122     t = toc;
00123     disp(['time for detailed simulation: t = ',num2str(t)]);
00124 
00125     demo_rb_gui(rmodel,detailed_data,[],plot_params);
00126 
00127    case 7 % training-error landscape
00128     disp('warning: takes a few hours!');
00129     load(fullfile(rbmatlabresult,detailedfname));
00130 
00131     model.N = params.RB_stop_Nmax;
00132 
00133     offline_data = gen_reduced_data(model,detailed_data);
00134     range_params.plot_fields = { 'N', 'M' };
00135     range_params.max         = [size(detailed_data.RB,2), ...
00136                                 size(detailed_data.BM{1},2) ];
00137     range_params.sample_size = [ 7, 12 ];
00138     range_params.mu_set_size = 100;
00139 
00140     testdir = ['convdiff_test_', range_params.mu_set_size ];
00141 
00142     params.run_name    = [testdir, '_step7'];
00143     params.tictoctable = true;
00144 
00145     output = stochastic_error_estimation(model, detailed_data, offline_data,...
00146                                          testdir, range_params, params);
00147 
00148   otherwise
00149     error('step-number is unknown!');
00150 
00151   end; % switch
00152 
00153 
00154 end; % for si
00155 %| \docupdate 
All Classes Namespaces Files Functions Variables