1 % small script demonstrating a buckley leverett problem
2 % discretization and RB model reduction
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
29 warning(
'off',
'RBMatlab:rb_simulation:runtime');
31 imsavepath = fullfile(rbmatlabresult,
'images');
33 for si=1:length(steps)
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;
46 params.RB_detailed_test_savepath = 'test_data_100';
47 params.RB_test_size = 100;
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;
57 % email to which status messages about processing mu vectors is sent
58 % params.email = 'mdrohmann@uni-muenster.de';
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;
68 plot_params.bind_to_model = true;
69 plot_params.yscale_uicontrols = 0.6;
71 % output-filenames in rbmatlabresult
72 CRBfname = ['bl_', params.model_type, '_CRB_interpol.mat'];
73 detailedfname = ['bl_', params.model_type, '_detailed_interpol.mat'];
76 case 0 % initialize model data
77 model = buckley_leverett_model(params);
78 model.force_delete = true;
80 params.mu_ranges = model.mu_ranges;
81 params.mu_names = model.mu_names;
83 model_data = gen_model_data(model);
84 case 1 % single detailed simulation and plot
87 tmppar.model_type = 'eoc';
89 model = newton_model(tmppar);
91 model.newton_solver = 0;
93 model.dt = model.T/model.nt;
95 err = zeros(model.nt+1,7);
98 model_data = gen_model_data(model);
100 sim_data = detailed_simulation(model, model_data);
102 ffe = @exact_function_heat_equation;
104 exact_data.U = zeros(model_data.grid.nelements, model.nt+1);
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);
112 err(:,i) =
fv_l2_error(sim_data.U, exact_data.U, model_data.W);
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))]);
119 model.xnumintervals = round(model.xnumintervals.*2);
120 model.ynumintervals = round(model.ynumintervals.*2);
123 tmppar.model_type = 'eoc_nonlinear';
124 tmppar.local_mass_matrix = @fv_local_mass_matrix_rect;
126 tmppar.evaluate_basis = @fv_evaluate_basis;
129 model = newton_model(tmppar);
131 % model.newton_regularisation = 0;
133 model.dt = model.T/model.nt;
134 model.ynumintervals = 1;
135 err = zeros(model.nt+1,5);
138 disp(['Computing EOC step no. ', num2str(i)]);
139 model_data = gen_model_data(model);
141 sim_data = detailed_simulation(model, model_data);
145 width = model_data.grid.X(2) - model_data.grid.X(1);
147 Fe = @(einds, loc, grid, params) ffe([grid.X(einds) + loc(:,1)*width,...
148 grid.Y(einds) + loc(:,2)*width], ...
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);
160 err(:,i) =
fv_l2_error(sim_data.U, exact_data.U, model_data.W);
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))]);
166 model.xnumintervals = model.xnumintervals.*2;
168 model.dt = model.T / model.nt;
169 %model.ynumintervals = model.ynumintervals.*2;
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));
186 % load(fullfile(rbmatlabresult,detailedfname));
190 tmp = load(fullfile(rbmatlabresult, detailedfname));
191 detailed_data = tmp.detailed_data;
192 mu_set = {[2,0.1,0.4]};
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;
200 tmp=load(fullfile(rbmatlabresult, detailedfname));
201 detailed_data = tmp.detailed_data;
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.
210 % number of collateral reduced basis sizes to be tested.
212 % sample of values
for the coupling variable
'c' for which errors are
215 % axis description
for plots with coupling variable
'c'
216 cdescr =
'(N,M) = c * (Nmax, Mmax)';
217 % size of mu vector test set.
220 error_plots = {
'error_coupled' };
222 model.M_by_N_ratio = 3;
226 columntitles = {
'minslicesize',
'noofslices',
'averageM',
'minM' ,
'maxM',
'averagedtime'};
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)
237 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 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.
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...
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