rbmatlab 0.10.01
|
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 % Martin Drohmann 06.05.2009 00005 % based on burgers_fv.m by 00006 % Bernard Haasdonk 14.8.2007 00007 00008 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00009 %%%%%% Select here, what is to be performed %%%%%%%% 00010 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00011 %step = 0 % initialize the model_data structure. This step needs to be executed 00012 % once per Matlab session only 00013 %step = 1 % single detailed simulation with given data and plot. Run 00014 % this with varying parameters mu until sure that scheme 00015 % is stable. Modify dt or the data-functions accordingly, 00016 % until a nice parameter-domain with uniformly stable 00017 % detailed scheme is obtained. 00018 %step = 2 % generate reduced basis 00019 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00020 %old steps: 00021 %step = 6 % time measurement of reduced simulation and 00022 % use reduced basis in rb_demo_gui 00023 %step = 7 % generate error-landscape over varying N and M 00024 % can take several hours!!! 00025 %step = 9 % test one simulation 00026 %step = 10 % generate dummy reduced basis from single trajectory. 00027 % A simple reduced simulation can also be 00028 % performed. All results should be visually identical 00029 00030 %steps = {2,5,7,8} 00031 steps = [0,1,2]; 00032 00033 for si=1:length(steps) 00034 00035 step = steps(si); 00036 00037 params.model_type = 'default'; 00038 00039 detailedfname = ['duneconvdiff_', params.model_type, '_detailed_interpol.mat']; 00040 % $$$ params.verbose = 5; 00041 % $$$ 00042 % $$$ %% parameters for visualization 00043 % $$$ plot_params.show_colorbar = 1; 00044 % $$$ plot_params.colorbar_mode = 'EastOutside'; 00045 00046 switch step 00047 case 0 % initialize model data 00048 descr = convdiff_dune_descr('init_model'); 00049 descr.detailedfname = fullfile(rbmatlabtemp, detailedfname); 00050 params.mu_ranges = descr.mu_ranges; 00051 params.mu_names = descr.mu_names; 00052 00053 [dmodel, rmodel] = gen_models(descr); 00054 00055 model_data = gen_model_data(dmodel); 00056 % $$$ grid = model_data.grid; 00057 case 1 % single detailed simulation and plot 00058 disp('performing single detailed simulation') 00059 tic 00060 % mu_test = cellfun(@mean, model.mu_ranges); 00061 % mu_test = [0,1,0.2] 00062 % model = model.set_mu(model, mu_test); 00063 sim_data = detailed_simulation(dmodel, model_data); 00064 toc 00065 % plot_sim_data(model, model_data, sim_data, plot_params); 00066 % Uname = [getenv('RBMATLABTEMP'),'/U',num2str(temp)]; 00067 % temp = temp + 1; 00068 % disp(['save solution U in ', Uname]); 00069 % save(Uname, 'U'); 00070 % end 00071 00072 case 2 % reduced basis 00073 disp('constructing reduced basis') 00074 % $$$ mu_test = cellfun(@mean, params.mu_ranges); 00075 % $$$ params.mu = mu_test; 00076 % $$$ sim_data = detailed_simulation(model, model_data, params); 00077 00078 tic; 00079 detailed_data = gen_detailed_data(rmodel, model_data); 00080 t = toc; 00081 % detailed_data = rb_basis_generation(detailed_data, ... 00082 % params); 00083 % reconstruct 00084 reduced_data = gen_reduced_data(rmodel, detailed_data); 00085 00086 rmodel.N = get_rb_size(detailed_data, rmodel); 00087 reduced_data = extract_reduced_data_subset(rmodel, reduced_data); 00088 00089 %dunerbconvdiff('dune_keyboard'); 00090 params.mu = [0.001, 0.5, 0.5]; 00091 set_mu(rmodel, params.mu); 00092 rb_sim_data = rb_simulation(rmodel, reduced_data); 00093 % reconstruct_and_compare(model, rb_sim_data); 00094 set_mu(dmodel, params.mu); 00095 dmodel.descr.mexptr('reconstruct_and_compare', rb_sim_data.a); 00096 00097 save(fullfile(rbmatlabresult, detailedfname),... 00098 'detailed_data','params'); 00099 plot(detailed_data.datatree.get_field_on_active_child('max_err_sequence', rmodel)); 00100 set(gca,'Yscale','log'); 00101 title('RB-generation error convergence'); 00102 00103 case 4 00104 load(fullfile(rbmatlabresult,detailedfname)); 00105 disp('reduced simulation:') 00106 reduced_data = gen_reduced_data(model, detailed_data); 00107 params.N = size(detailed_data.RB,2); 00108 params.M = params.N; 00109 reduced_data = extract_reduced_data_subset(model, reduced_data); 00110 tic; 00111 params.mu = mu_test; 00112 rb_sim_data = rb_simulation(model,reduced_data,params); 00113 t = toc; 00114 disp(['time for online phase: t = ',num2str(t)]); 00115 00116 disp('full simulation:') 00117 tic; 00118 sim_data = detailed_simulation(model,model_data,params); 00119 t = toc; 00120 disp(['time for detailed simulation: t = ',num2str(t)]); 00121 00122 dune_demo_rb_gui(model,detailed_data,[],params,plot_params); 00123 00124 case 7 % training-error landscape 00125 disp('warning: takes a few hours!'); 00126 load(fullfile(rbmatlabresult,detailedfname)); 00127 00128 model.N = model.RB_stop_Nmax; 00129 00130 offline_data = gen_reduced_data(model,detailed_data); 00131 range_params.plot_fields = { 'N', 'M' }; 00132 range_params.max = [ size(detailed_data.RB,2), ... 00133 size(detailed_data.BM{1},2) ]; 00134 range_params.sample_size = [ 10, 12 ]; 00135 range_params.Msamples = 12; 00136 range_params.mu_set_size = 100; 00137 00138 testdir = [ 'duneconvdiff_test_', range_params.mu_set_size ]; 00139 00140 params.run_name = ['_', testdir, '_step7']; 00141 params.tictoctable = true; 00142 00143 output=stochastic_error_estimation(model, detailed_data, offline_data,... 00144 testdir, range_params, params); 00145 00146 case 9 00147 tmp=load(fullfile(rbmatlabresult,detailedfname)); 00148 detailed_data = tmp.detailed_data; 00149 00150 reduced_data = gen_reduced_data(model, detailed_data, params); 00151 00152 params.N = get_rb_size(model, detailed_data); 00153 reduced_data = extract_reduced_data_subset(model, reduced_data, ... 00154 params); 00155 00156 params.mu = [0.5, 0.5, 0.5]; 00157 rb_sim_data = rb_simulation(model, reduced_data, params); 00158 00159 plot(rb_sim_data.a); 00160 00161 case 10 % construct dummy reduced basis by single trajectory and simulate 00162 disp('old, to be adjusted:') 00163 disp('detailed interpolated simulation for basis construction:') 00164 mu_test = cellfun(@mean, params.mu_ranges); 00165 % mu_test2 = cellfun(@min, params.mu_ranges); 00166 params.mu = mu_test; 00167 sim_data = detailed_simulation(model, model_data); 00168 UON = model.orthonormalize(model, model_data, sim_data.U); 00169 detailed_data.grid = model_data.grid; 00170 detailed_data.W = model_data.W; 00171 detailed_data.RB = UON; 00172 disp('reduced simulation:') 00173 reduced_data = gen_reduced_data(model, detailed_data); 00174 params.N = size(detailed_data.RB,2); 00175 reduced_data = extract_reduced_data_subset(reduced_data); 00176 params.mu = mu_test; 00177 rb_sim_data = rb_simulation(model, reduced_data); 00178 rb_sim_data = rb_reconstruction(model, detailed_data, rb_sim_data); 00179 00180 plot_params.title = 'reduced simulation result'; 00181 plot_sim_data(model, model_data, rb_sim_data, plot_params); 00182 plot_params.title = 'detailed simulation result'; 00183 plot_sim_data(model, model_data, sim_data, plot_params); 00184 00185 00186 otherwise 00187 error('step-number is unknown!'); 00188 end; 00189 00190 end; 00191 00192 %| \docupdate