rbmatlab 0.10.01
scripts/richards_fv.m
Go to the documentation of this file.
00001 % small script demonstrating the richards equation with explicit fv
00002 % discretization and RB model reduction
00003 % Bernard Haasdonk 14.8.2007
00004 
00005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00006 %%%%%% Select here, what is to be performed with the richards data %%%%%%%%
00007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00008 %step = 1 % single detailed simulation with given data and plot. Run
00009           % this with varying parameters mu until sure that scheme
00010           % is stable. Modify dt or the data-functions accordingly,
00011           % until a nice parameter-domain with uniformly stable
00012           % detailed scheme is obtained.
00013 %step = 2 % generate colateral reduced basis of L_E operator
00014 %step = 3 % compare single detailed simulation with and without
00015           % interpolated space operator
00016 %step = 4 % generate dummy reduced basis from single trajectory and check, if
00017           % ei_interpolation with projection on this space maintains
00018           % result. A simple reduced simulation can also be
00019           % performed. All results should be visually identical
00020 %step = 5 % generate reduced basis
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 = 8 % do runtime comparisons between detailed and reduced simulations
00026 %step = 10 % write out some nice pictures
00027 
00028 steps = [0,5]
00029 
00030 imsavepath = '/data/dune_work/private/m_droh01/images';
00031 
00032 for si=1:length(steps)
00033 
00034 step = steps(si);
00035 
00036 %params.model_type    = 'implicit_nonaffine_linear';
00037 %params.model_type    = 'linear_heat_trapezoidal';
00038 %params.model_type    = 'nonlinear_richards_trapezoidal';
00039 params.model_type = 'linear_heat_polynomial';
00040 %params.model_size    = 'big';
00041 params.model_size    = 'small';
00042 % params.model_size    = 'small';
00043 %  params.model_type    = 'nonlinear';
00044 params.separate_CRBs = false;
00045 
00046 % test parameters
00047 params.RB_detailed_test_savepath = 'test_data_100';
00048 params.RB_test_size              = 100;
00049 
00050 params.verbose = 5;
00051 params.debug   = 0;
00052 params.step7_outputfile = fullfile(rbmatlabresult, [params.model_type, '_step7_output']);
00053 params.step8_outputfile = fullfile(rbmatlabresult, [params.model_type, '_step8_output']);
00054 extrapar.Mstrich = 20;
00055 extrapar.N       = 25;
00056 extrapar.M       = 50;
00057 
00058 % email to which status messages about processing mu vectors is sent
00059 % params.email   = 'mdrohmann@uni-muenster.de';
00060 
00061 %% parameters for visualization
00062 plot_params.show_colorbar = 1;
00063 plot_params.colorbar_mode = 'EastOutside';
00064 plot_params.no_lines      = true;
00065 % plot_params.clim          = [0, 0.5];
00066 % plot_params.clim_tight    = true;
00067 plot_params.plot          = @fv_plot;
00068 plot_params.bind_to_model = true;
00069 plot_params.yscale_uicontrols = 0.6;
00070 
00071 % output-filenames in rbmatlabresult
00072 CRBfname      = ['richards_fv_', params.model_type, '_CRB_interpol.mat'];
00073 detailedfname = ['richards_fv_', params.model_type, '_detailed_interpol.mat'];
00074 
00075 switch step
00076  case 0 % initialize model data
00077    descr            = richards_fv_descr(params);
00078    bg_descr         = richards_fv_bg_descr(params);
00079    [dmodel, rmodel] = gen_models(descr, bg_descr);
00080    params.mu_ranges = dmodel.mu_ranges;
00081    params.mu_names  = dmodel.mu_names;
00082    mu_default = cellfun(@mean, dmodel.mu_ranges);
00083 
00084    model_data = gen_model_data(dmodel);
00085  case 1 % single detailed simulation and plot
00086    step1_detailed_simulation;
00087  case 5 % reduced basis
00088    detailed_data = gen_detailed_data(rmodel, model_data);
00089    save(fullfile(rbmatlabresult, detailedfname), 'detailed_data', 'rmodel');
00090  case 6
00091    load(fullfile(rbmatlabresult,detailedfname));
00092    step6_demo_rb_gui;
00093 case 10
00094   load('datafiles/strange.mat');
00095 
00096   tmp                  = load(fullfile(rbmatlabtemp,detailedfname));
00097   detailed_data        = tmp.detailed_data;
00098   plot_params.no_lines = 1;
00099 
00100   plot_params.no_axes                = 1;
00101   plot_params.transparent_background = 1;
00102   plot_params.show_colorbar          = 0;
00103   %plot_params.shrink_factor         = 1.13;
00104   plot_params.colormap               = Cmap;
00105   plot_params.clim                   = [0.0,0.35];
00106 
00107   reduced_data     = gen_reduced_data(model, detailed_data);
00108   params.N = 14;%size(detailed_data.RB,2);
00109   params.M = 100;%size(detailed_data.QM,2);
00110   reduced_data = extract_reduced_data_subset(model, reduced_data, params);
00111 
00112   model.hill_height = 0;
00113 
00114   cparams.range = cell(length(model.mu_ranges)+1,1);
00115   cparams.range{1}  = [1, model.nt];
00116   cparams.range(2:end) = model.mu_ranges(:);
00117   cparams.numintervals = 2*ones(length(model.mu_ranges)+1,1);
00118   cgrid = cubegrid(cparams);
00119 
00120   parammat = cgrid.vertex;
00121   parammat(:,1) = round(parammat(:,1));
00122 
00123   for i=1:length(parammat)
00124     tstep = parammat(i,1);
00125     newmodel = newmodel.set_mu(model, parammat(i,2:end));
00126     rb_sim_data = rb_simulation(newmodel, reduced_data, params);
00127     rb_sim_data = rb_reconstruction(model, detailed_data, rb_sim_data);
00128 
00129     % transformed version
00130     plot_element_data(newmodel, model_data.grid, rb_sim_data.U(:,tstep), plot_params);
00131 
00132     mustring = strrep(strrep(strrep(strrep(mat2str(parammat(i,2:end)),' ', '_'),'[',''),']',''),'.','p');
00133     fp = fullfile(imsavepath, params.model_type);
00134     if ~exist(fp,'dir')
00135       mkdir(fp);
00136     end
00137     fp = fullfile(fp, ['t_', num2str(tstep)]);
00138     if ~exist(fp,'dir')
00139       mkdir(fp);
00140     end
00141     fn = ['sample_mu_', mustring];
00142     disp(['Processing ', fn, ' ...']);
00143 
00144     set(gcf,'Color','none');
00145     set(gca,'Color','none');
00146     set(gcf,'InvertHardCopy','off');
00147     showaxes('hide');
00148     ranges=cell(2,1);
00149     ranges{1} = get(gca,'XLim');
00150     ranges{2} = get(gca,'YLim');
00151 
00152     export_fig(fullfile(fp, fn), '-pdf','-eps','-png');
00153     im = export_fig;
00154 
00155     colorbarfn = fullfile(imsavepath, params.model_type, 'colorbar');
00156     if ~exist([colorbarfn, '.pdf'], 'file')
00157       colorh = colorbar;
00158       yticks = get(colorh, 'YTick');
00159       set(colorh, 'YTick',[]);
00160       set(colorh, 'YTickLabel',[]);
00161 
00162       export_fig(colorbarfn, '-pdf', '-eps', '-png', colorh);
00163       cbim = export_fig(colorh);
00164       size(cbim)
00165     end
00166 
00167     tikzfile(newmodel, fp, fn, ranges, size(im), 5);
00168     close(gcf);
00169 
00170     % untransformed version
00171     fpu = fullfile(imsavepath, params.model_type, 'untransformed');
00172     if ~exist(fpu,'dir')
00173       mkdir(fpu);
00174     end
00175     fpu = fullfile(fpu, ['t_', num2str(tstep)]);
00176     if ~exist(fpu,'dir')
00177       mkdir(fpu);
00178     end
00179 
00180     plot_element_data(model, model_data.grid, rb_sim_data.U(:,tstep), plot_params);
00181 
00182     set(gcf,'Color','none');
00183     set(gca,'Color','none');
00184     set(gcf,'InvertHardCopy','off');
00185     showaxes('hide');
00186     ranges{1} = get(gca,'XLim');
00187     ranges{2} = get(gca,'YLim');
00188 
00189     export_fig(fullfile(fpu, fn), '-pdf', '-eps', '-png');
00190     im = export_fig;
00191     tikzfile(newmodel, fpu, fn, ranges, size(im), 5);
00192     close(gcf);
00193   end
00194 
00195 case 11
00196   load('richards_affine_detailed_interpol');
00197 
00198   rdata = gen_reduced_data(model, detailed_data);
00199 
00200   model.N = size(detailed_data,2);
00201   model.M = 10;
00202   model.Mstrich = 1;
00203   rdata2 = extract_reduced_data_subset(model, rdata);
00204   model.Mstrich = 10;
00205   rdata1 = extract_reduced_data_subset(model, rdata);
00206 
00207   TM1 = rdata1.TM_local{1}(1:10);
00208   TM2 = rdata2.TM_local{1}(1:10);
00209 
00210   gl1 = rdata1.grid_local_ext{1};
00211   gl2 = rdata2.grid_local_ext{1};
00212 
00213   if(any(gl1.CX(TM1) ~= gl2.CX(TM2)))
00214     disp('CX differs');
00215   end
00216   if(any(gl1.CY(TM1) ~= gl2.CY(TM2)))
00217     disp('CY differs');
00218   end
00219   if(any(any(gl1.X(gl1.VI(TM1,:)) ~= gl2.X(gl2.VI(TM2,:)))))
00220     disp('X differs');
00221   end
00222   if(any(any(gl1.Y(gl1.VI(TM1,:)) ~= gl2.Y(gl2.VI(TM2,:)))))
00223     disp('Y differs');
00224   end
00225   if(any(any(gl1.SX(TM1,:) ~= gl2.SX(TM2,:))))
00226     disp('SX differs');
00227   end
00228   if(any(any(gl1.SY(TM1,:) ~= gl2.SY(TM2,:))))
00229     disp('SY differs');
00230   end
00231     if(any(gl1.EL(TM1,:) ~= gl2.EL(TM2,:)))
00232       disp('EL differs');
00233     end
00234     if(any(gl1.DC(TM1,:) ~= gl2.DC(TM2,:)))
00235       disp('DC differs');
00236     end
00237     if(any(gl1.NX(TM1,:) ~= gl2.NX(TM2,:)))
00238       disp('NX differs');
00239     end
00240     if(any(gl1.NY(TM1,:) ~= gl2.NY(TM2,:)))
00241       disp('NY differs');
00242     end
00243     if(any(gl1.ECX(TM1,:) ~= gl2.ECX(TM2,:)))
00244       disp('ECX differs');
00245     end
00246     if(any(gl1.ECY(TM1,:) ~= gl2.ECY(TM2,:)))
00247       disp('ECY differs');
00248     end
00249   %% neighbours
00250   NBI1 = gl1.NBI(TM1,:);
00251   NBI2 = gl2.NBI(TM2,:);
00252   if(any(gl1.CX(NBI1) ~= gl2.CX(NBI2)))
00253     disp('CX differs');
00254   end
00255   if(any(gl1.CY(NBI1) ~= gl2.CY(NBI2)))
00256     disp('CY differs');
00257   end
00258   if(any(any(gl1.X(gl1.VI(NBI1,:)) ~= gl2.X(gl2.VI(NBI2,:)))))
00259     disp('X differs');
00260   end
00261   if(any(any(gl1.Y(gl1.VI(NBI1,:)) ~= gl2.Y(gl2.VI(NBI2,:)))))
00262     disp('Y differs');
00263   end
00264   if(any(any(gl1.SX(NBI1,:) ~= gl2.SX(NBI2,:))))
00265     disp('SX differs');
00266   end
00267   if(any(any(gl1.SY(NBI1,:) ~= gl2.SY(NBI2,:))))
00268     disp('SY differs');
00269   end
00270   for i = 1:length(TM1)
00271   end
00272 
00273 otherwise
00274   error('step-number is unknown!');
00275 end
00276 
00277 end
00278 
00279 %| \docupdate
00280 
All Classes Namespaces Files Functions Variables