rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
buckley_leverett.m
Go to the documentation of this file.
1 % small script demonstrating a buckley leverett problem
2 % discretization and RB model reduction
3 
4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 %%%%%% Select here, what is to be performed with the richards data %%%%%%%%
6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 %step = 1 % single detailed simulation with given data and plot. Run
8  % this with varying parameters mu until sure that scheme
9  % is stable. Modify dt or the data-functions accordingly,
10  % until a nice parameter-domain with uniformly stable
11  % detailed scheme is obtained.
12 %step = 2 % generate colateral reduced basis of L_E operator
13 %step = 3 % compare single detailed simulation with and without
14  % interpolated space operator
15 %step = 4 % generate dummy reduced basis from single trajectory and check, if
16  % ei_interpolation with projection on this space maintains
17  % result. A simple reduced simulation can also be
18  % performed. All results should be visually identical
19 %step = 5 % generate reduced basis
20 %step = 6 % time measurement of reduced simulation and
21  % use reduced basis in rb_demo_gui
22 %step = 7 % plot trajectories for some parameters mu at few time-instants
23 %step = 8 % do a coupled error plot
24 
25 steps = [0,2,5,7,9]
26 %steps = [0,1]
27 %steps = [0,7.5]
28 
29 warning('off', 'RBMatlab:rb_simulation:runtime');
30 
31 imsavepath = fullfile(rbmatlabresult, 'images');
32 
33 for si=1:length(steps)
34 
35 step = steps(si);
36 
37 params.model_type = 'buckley_leverett';
38 %params.model_type = 'eoc_nonlinear';
39 %params.model_size = 'big';
40 %params.model_size = 'medium';
41 params.model_size = 'small';
42 % params.model_type = 'nonlinear';
43 params.separate_CRBs = false;
44 
45 % test parameters
46 params.RB_detailed_test_savepath = 'test_data_100';
47 params.RB_test_size = 100;
48 
49 params.verbose = 1;
50 params.debug = 1;
51 params.step7_outputfile = fullfile(rbmatlabresult, [params.model_type, '_step7_output']);
52 params.step8_outputfile = fullfile(rbmatlabresult, [params.model_type, '_step8_output']);
53 extrapar.Mstrich = 20;
54 extrapar.N = 25;
55 extrapar.M = 50;
56 
57 % email to which status messages about processing mu vectors is sent
58 % params.email = 'mdrohmann@uni-muenster.de';
59 
60 %% parameters for visualization
61 plot_params.show_colorbar = 1;
62 plot_params.colorbar_mode = 'EastOutside';
63 plot_params.no_lines = true;
64 plot_params.plot_type = 'mesh';
65 % plot_params.clim = [0, 0.5];
66 % plot_params.clim_tight = true;
67 plot_params.plot = @fv_plot;
68 plot_params.bind_to_model = true;
69 plot_params.yscale_uicontrols = 0.6;
70 
71 % output-filenames in rbmatlabresult
72 CRBfname = ['bl_', params.model_type, '_CRB_interpol.mat'];
73 detailedfname = ['bl_', params.model_type, '_detailed_interpol.mat'];
74 
75 switch step
76  case 0 % initialize model data
77  model = buckley_leverett_model(params);
78  model.force_delete = true;
79  model.debug = false;
80  params.mu_ranges = model.mu_ranges;
81  params.mu_names = model.mu_names;
82 
83  model_data = gen_model_data(model);
84  case 1 % single detailed simulation and plot
86  case 1.5
87  tmppar.model_type = 'eoc';
88 
89  model = newton_model(tmppar);
90  model.debug = 1;
91  model.newton_solver = 0;
92  model.T = 1;
93  model.dt = model.T/model.nt;
94  model.verbose = 21;
95  err = zeros(model.nt+1,7);
96  eoc = zeros(4, 1);
97  for i = 1:7
98  model_data = gen_model_data(model);
99 
100  sim_data = detailed_simulation(model, model_data);
101 
102  ffe = @exact_function_heat_equation;
103 
104  exact_data.U = zeros(model_data.grid.nelements, model.nt+1);
105 
106  for tt = 1:model.nt+1
107  model.t = (tt-1) * model.dt;
108  exact_data.U(:,tt) = ffe([model_data.grid.CX(:), model_data.grid.CY(:)], model);
109  end
110  model.t = 0;
111 
112  err(:,i) = fv_l2_error(sim_data.U, exact_data.U, model_data.W);
113  if(i>1)
114  eoc(i-1) = log(max(err(:,i-1))/max(err(:,i)))/log(2);
115  disp(['Error: ', num2str(err(end,i)), 'EOC: ', num2str(eoc(i-1))]);
116  pause;
117  end
118 
119  model.xnumintervals = round(model.xnumintervals.*2);
120  model.ynumintervals = round(model.ynumintervals.*2);
121  end
122  case 1.75
123  tmppar.model_type = 'eoc_nonlinear';
124  tmppar.local_mass_matrix = @fv_local_mass_matrix_rect;
125  tmppar.element_quadrature = @cubequadrature;
126  tmppar.evaluate_basis = @fv_evaluate_basis;
127  tmppar.pdeg = 0;
128 
129  model = newton_model(tmppar);
130  %model.debug = 1;
131  % model.newton_regularisation = 0;
132  %model.verbose = 21;
133  model.dt = model.T/model.nt;
134  model.ynumintervals = 1;
135  err = zeros(model.nt+1,5);
136  eoc = zeros(4, 1);
137  for i = 1:6
138  disp(['Computing EOC step no. ', num2str(i)]);
139  model_data = gen_model_data(model);
140 
141  sim_data = detailed_simulation(model, model_data);
142 
144 
145  width = model_data.grid.X(2) - model_data.grid.X(1);
146 
147  Fe = @(einds, loc, grid, params) ffe([grid.X(einds) + loc(:,1)*width,...
148  grid.Y(einds) + loc(:,2)*width], ...
149  params);
150  tmppar.diff_k0 = model.diff_k0;
151  exact_data.U = zeros(model_data.grid.nelements, model.nt+1);
152  for tt = 1:model.nt+1
153  model.t = (tt-1) * model.dt;
154  exact_data.U(:,tt) = ffe([model_data.grid.CX(:), ...
155  model_data.grid.CY(:)], model);
156 % exact_data.U(:,tt) = l2project(Fe, 2, model_data.grid, tmppar);
157  end
158  model.t = 0;
159 
160  err(:,i) = fv_l2_error(sim_data.U, exact_data.U, model_data.W);
161  if(i>1)
162  eoc(i-1) = log(max(err(:,i-1))/max(err(:,i)))/log(2);
163  disp(['Error: ', num2str(err(end,i)), ' EOC: ', num2str(eoc(i-1))]);
164  end
165 
166  model.xnumintervals = model.xnumintervals.*2;
167  model.nt = model.nt;
168  model.dt = model.T / model.nt;
169  %model.ynumintervals = model.ynumintervals.*2;
170  end
171 
172  case 2 % empirical interpolation of space operator
174  case 3 % compare detailed simulation with and without interpolation
175  model.detailed_ei_simulation = @nonlin_evol_detailed_simulation;
177  case 4 % construct dummy reduced basis by single trajectory and simulate
178  model.detailed_ei_simulation = @nonlin_evol_detailed_simulation;
179 % model = model.set_mu(model, [0.1,0.01, 0.4]);
180  model = model.set_mu(model, [0.11,0.00, 0.12]);
182  case 5 % reduced basis
183 % load(fullfile(rbmatlabresult,CRBfname));
185  case 6
186 % load(fullfile(rbmatlabresult,detailedfname));
188 
189  case 7
190  tmp = load(fullfile(rbmatlabresult, detailedfname));
191  detailed_data = tmp.detailed_data;
192  mu_set = {[2,0.1,0.4]};
193  clim = [0.0, 1.0];
194  plot_params.plot_type = 'mesh';
195  plot_params.line_width = 1;
196  timeinstants = [0,0.3,1.0]*model.T;
197  boxed_snapshots = true;
199 case 8
200  tmp=load(fullfile(rbmatlabresult, detailedfname));
201  detailed_data = tmp.detailed_data;
202 
203  model.Mstrich = 0;
204  % maximum number of reduced basis functions
205  model.Nmax = size(detailed_data.RB,2);
206  % maximum number of collateral reduced basis functions
207  model.Mmax = cellfun(@(x)size(x,2), detailed_data.BM);
208  % number of reduced basis sizes to be tested.
209  Nsize = 7;
210  % number of collateral reduced basis sizes to be tested.
211  Msize = 10;
212  % sample of values for the coupling variable 'c' for which errors are
213  % computed.
214  csample = [1];
215  % axis description for plots with coupling variable 'c'
216  cdescr = '(N,M) = c * (Nmax, Mmax)';
217  % size of mu vector test set.
218  mu_set_size = 20;
219 
220  error_plots = { 'error_coupled' };
221 
222  model.M_by_N_ratio = 3;
223 
225 case 9
226  columntitles = {'minslicesize', 'noofslices', 'averageM', 'minM' ,'maxM', 'averagedtime'};
227  values = zeros(6,1);
228  values(1) = model.minimum_time_slice;
229  values(2) = max(detailed_data.time_split_map(:,2));
230  Msizes = cellfun(@(X) size(X,2), detailed_data.BM);
231  values(3) = sum(Msizes) / values(2);
232  values(4) = min(Msizes);
233  values(5) = max(Msizes);
234  values(6) = mean(output{1}.rtimes);
235  print_datatable(fullfile(rbmatlabresult,'tableline'),columntitles,values)
236 otherwise
237  error('step-number is unknown!');
238 end
239 
240 end
241 
242 %| \docupdate
243 
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
Definition: verbose.m:17
function step1_detailed_simulation()
script performing a single detailed simulation and plotting it.
function p = fv_plot(gridbase grid, dofs, params)
routine plotting a single fv function of fv_functions.
Definition: fv_plot.m:17
function step2_empirical_interpolation()
script constructing a collateral reduced basis space for localized space operators.
function step4_dummy_reduced_basis()
script constructing a reduced basis from a single trajectory and performing a detailed simulation whe...
function step7_error_landscape()
script generating error landscapes by computing the true error of reduced simulations vs...
function res = cubequadrature(poldeg, func, varargin)
integration of function func over reference cube == unit cube. by Gaussian quadrature exactly integra...
function step6_demo_rb_gui()
script comparing time for a reduced and a detailed simulation and starting the demonstration GUI ...
function buckley_leverett()
small script demonstrating a buckley leverett problem discretization and RB model reduction ...
function l2_error = fv_l2_error(U1, U2, W)
function computing the l2-error between the two fv-functions or function sequences in U1...
Definition: fv_l2_error.m:17
function res = exact_function_plaplace(glob, params)
This is the first function from http://eqworld.ipmnet.ru/en/solutions/npde/npde1201.pdf.
function step3_detailed_ei_simulation()
script performing a detailed simulation with empirical interpolated operators comparing the result wi...
function step10_plot_trajectories()
script generating a tikz graphic showing trajectories for certain selected parameters ...
function step5_rb_generation()
script constructing a reduced basis space