1 % small script demonstrating the richards equation with
explicit fv
2 % discretization and RB model reduction
3 % Bernard Haasdonk 14.8.2007
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 %%%%%% Select here, what is to be performed with the richards data %%%%%%%%
7 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 %step = 1 % single detailed simulation with given data and plot. Run
9 %
this with varying parameters mu until sure that scheme
10 % is stable. Modify dt or the data-functions accordingly,
11 % until a nice parameter-domain with uniformly stable
12 % detailed scheme is obtained.
13 %step = 2 % generate colateral reduced basis of L_E
operator
14 %step = 3 % compare single detailed simulation with and without
15 % interpolated space
operator
16 %step = 4 % generate dummy reduced basis from single trajectory and check,
if
17 % ei_interpolation with projection on
this space maintains
18 % result. A simple reduced simulation can also be
19 % performed. All results should be visually identical
20 %step = 5 % generate reduced basis
21 %step = 6 % time measurement of reduced simulation and
22 % use reduced basis in rb_demo_gui
23 %step = 7 % generate error-landscape over varying N and M
24 % can take several hours!!!
25 %step = 8 %
do runtime comparisons between detailed and reduced simulations
26 %step = 10 % write out some nice pictures
31 imsavepath =
'/data/dune_work/private/m_droh01/images';
33 for si=1:length(steps)
37 % params.model_type =
'implicit_nonaffine_linear';
38 params.model_type =
'linear_heat_trapezoidal';
39 %params.model_size =
'big';
40 params.model_size =
'small';
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.clim = [0, 0.5];
65 % plot_params.clim_tight =
true;
67 plot_params.bind_to_model =
true;
68 plot_params.yscale_uicontrols = 0.6;
70 % output-filenames in rbmatlabresult
71 CRBfname = [
'richards_fv_', params.model_type,
'_CRB_interpol.mat'];
72 detailedfname = [
'richards_fv_', params.model_type,
'_detailed_interpol.mat'];
75 case 0 % initialize model data
76 model = richards_fv_model(params);
77 params.mu_ranges = model.mu_ranges;
78 params.mu_names = model.mu_names;
79 mu_default = cellfun(@mean, model.mu_ranges);
81 model_data = gen_model_data(model);
82 case 1 % single detailed simulation and plot
85 case 2 % empirical interpolation of space
operator
87 case 3 % compare detailed simulation with and without interpolation
88 load(fullfile(rbmatlabresult,CRBfname));
90 case 4 % construct dummy reduced basis by single trajectory and simulate
91 tmp=load(fullfile(rbmatlabresult,CRBfname));
92 detailed_data=tmp.detailed_data;
94 case 5 % reduced basis
95 load(fullfile(rbmatlabresult,CRBfname));
98 load(fullfile(rbmatlabresult,detailedfname));
100 case 7 % training-error landscape & time comparisons
101 load(fullfile(rbmatlabresult,detailedfname));
104 % maximum number of reduced basis functions
105 model.Nmax = size(detailed_data.RB,2);
106 % maximum number of collateral reduced basis functions
107 model.Mmax = size(detailed_data.BM{1},2);
108 % number of reduced basis sizes to be tested.
110 % number of collateral reduced basis sizes to be tested.
112 % sample of values
for the coupling variable
'c' for which errors are
115 % axis description
for plots with coupling variable
'c'
116 cdescr =
'(N,M) = c * (Nmax, Mmax)';
117 % size of mu vector test set.
123 load(params.step7_outputfile);
124 for i = 1:length(output)
128 disp(
'warning: takes a few hours!');
129 load(fullfile(rbmatlabresult,detailedfname));
131 % maximum number of reduced basis vectors
132 model.Nmax = model.RB_stop_Nmax;
133 % maximum number of collateral reduced basis vectors used
for
134 model.Mmax = size( detailed_data.BM{1}, 2 ) - extrapar.Mstrich;
136 % number of reduced basis sizes to be tested.
138 % number of collateral reduced basis sizes to be tested.
140 % Mstrich values to be tested
141 Mstrich_samples = 1:extrapar.Mstrich;
142 % sample of values
for the coupling variable
'c' for which
143 % estimators are computed.
144 csamples = 0.1:0.1:1;
145 % size of mu vector test set
147 % axis description
for plots with coupling variable
'c'
148 cdescr =
'(N,M) = c * (Nmax, Mmax)';
152 load(params.step8_outputfile);
153 for i = 1:length(output)
154 output{i}.bound = 1500;
155 output{i}.stab_limit = 10000;
159 load(fullfile(rbmatlabresult,detailedfname));
160 model_data = detailed_data;
161 testdir =
'richards_test_10';
163 model.Nmax = size(detailed_data.RB,2);
165 % generate test data
if not existent
166 rand(
'state',123456);
167 M = rand_uniform(10,params.mu_ranges);
170 % load demo_nonlin_evol_detailed_data_LE_on_RB;
171 reduced_data = gen_reduced_data(model,detailed_data);
173 settings = load(fullfile(rbmatlabtemp,...
174 testdir,
'settings.mat'));
178 % storage
for maximum l2-errors (i.e. linfty([0,T],l2)-norm)
179 errs = zeros(Msamples,Nsamples);
180 model.RB_error_indicator='ei_estimator_test';
182 Mstrich_set = 1:10:100;%[1,2,3,4,5,10,15,20];
184 deltas = zeros(size(M,2),length(Mstrich_set));
185 for mu_ind = 1:size(M,2);
186 disp(['processing parameter vector ',num2str(mu_ind),...
187 '/',num2str(size(M,2))]);
188 for msi = 1:length(Mstrich_set)
190 model = model.set_mu(model,settings.M(:,mu_ind));
196 mtemp.M = extrapar.M;
197 mtemp.Mstrich = Mstrich_set(msi);
198 mtemp.N = extrapar.N;
199 simulation_data = rb_simulation(mtemp,reduced_data);
202 deltas(mu_ind,msi) = simulation_data.Delta(end);
203 simulation_data = rb_reconstruction(mtemp,detailed_data,simulation_data);
204 error = model.error_algorithm(simulation_data.U, sim_data.U, ...
205 detailed_data.W, mtemp);
206 disp(['true error: ', num2str(max(error))]);
208 %
plot_sim_data(model,detailed_data,simulation_data,plot_params);
211 plot(Mstrich_set,deltas(mu_ind,:));
215 load('datafiles/strange.mat');
217 tmp = load(fullfile(rbmatlabtemp,detailedfname));
218 detailed_data = tmp.detailed_data;
219 plot_params.no_lines = 1;
221 plot_params.no_axes = 1;
222 plot_params.transparent_background = 1;
223 plot_params.show_colorbar = 0;
224 %plot_params.shrink_factor = 1.13;
225 plot_params.colormap = Cmap;
226 plot_params.clim = [0.0,0.35];
228 reduced_data = gen_reduced_data(model, detailed_data);
229 params.N = 14;%size(detailed_data.RB,2);
230 params.M = 100;%size(detailed_data.QM,2);
231 reduced_data = extract_reduced_data_subset(model, reduced_data, params);
233 model.hill_height = 0;
235 cparams.range = cell(length(model.mu_ranges)+1,1);
236 cparams.range{1} = [1, model.nt];
237 cparams.range(2:end) = model.mu_ranges(:);
238 cparams.numintervals = 2*ones(length(model.mu_ranges)+1,1);
241 parammat = cgrid.vertex;
242 parammat(:,1) = round(parammat(:,1));
244 for i=1:length(parammat)
245 tstep = parammat(i,1);
246 newmodel = newmodel.set_mu(model, parammat(i,2:end));
247 rb_sim_data = rb_simulation(newmodel, reduced_data, params);
248 rb_sim_data = rb_reconstruction(model, detailed_data, rb_sim_data);
250 % transformed version
251 plot_element_data(newmodel, model_data.grid, rb_sim_data.U(:,tstep), plot_params);
253 mustring = strrep(strrep(strrep(strrep(mat2str(parammat(i,2:end)),' ', '_'),'[',''),']',''),'.','p');
254 fp = fullfile(imsavepath, params.model_type);
258 fp = fullfile(fp, ['t_', num2str(tstep)]);
262 fn = ['sample_mu_', mustring];
263 disp(['Processing ', fn, ' ...']);
265 set(gcf,'Color','none');
266 set(gca,'Color','none');
267 set(gcf,'InvertHardCopy','off');
270 ranges{1} =
get(gca,
'XLim');
271 ranges{2} =
get(gca,
'YLim');
273 export_fig(fullfile(fp, fn),
'-pdf',
'-eps',
'-png');
276 colorbarfn = fullfile(imsavepath, params.model_type,
'colorbar');
277 if ~exist([colorbarfn,
'.pdf'],
'file')
279 yticks = get(colorh, 'YTick');
280 set(colorh, 'YTick',[]);
281 set(colorh, 'YTickLabel',[]);
283 export_fig(colorbarfn, '-pdf', '-eps', '-png', colorh);
284 cbim = export_fig(colorh);
288 tikzfile(newmodel, fp, fn, ranges, size(im), 5);
291 % untransformed version
292 fpu = fullfile(imsavepath, params.model_type, 'untransformed');
296 fpu = fullfile(fpu, ['t_', num2str(tstep)]);
301 plot_element_data(model, model_data.grid, rb_sim_data.U(:,tstep), plot_params);
303 set(gcf,'Color','none');
304 set(gca,'Color','none');
305 set(gcf,'InvertHardCopy','off');
307 ranges{1} =
get(gca,
'XLim');
308 ranges{2} =
get(gca,
'YLim');
310 export_fig(fullfile(fpu, fn),
'-pdf',
'-eps',
'-png');
312 tikzfile(newmodel, fpu, fn, ranges, size(im), 5);
317 load(
'richards_affine_detailed_interpol');
319 rdata = gen_reduced_data(model, detailed_data);
321 model.N = size(detailed_data,2);
324 rdata2 = extract_reduced_data_subset(model, rdata);
326 rdata1 = extract_reduced_data_subset(model, rdata);
328 TM1 = rdata1.TM_local{1}(1:10);
329 TM2 = rdata2.TM_local{1}(1:10);
331 gl1 = rdata1.grid_local_ext{1};
332 gl2 = rdata2.grid_local_ext{1};
334 if(any(gl1.CX(TM1) ~= gl2.CX(TM2)))
337 if(any(gl1.CY(TM1) ~= gl2.CY(TM2)))
340 if(any(any(gl1.X(gl1.VI(TM1,:)) ~= gl2.X(gl2.VI(TM2,:)))))
343 if(any(any(gl1.Y(gl1.VI(TM1,:)) ~= gl2.Y(gl2.VI(TM2,:)))))
346 if(any(any(gl1.SX(TM1,:) ~= gl2.SX(TM2,:))))
349 if(any(any(gl1.SY(TM1,:) ~= gl2.SY(TM2,:))))
352 if(any(gl1.EL(TM1,:) ~= gl2.EL(TM2,:)))
355 if(any(gl1.DC(TM1,:) ~= gl2.DC(TM2,:)))
358 if(any(gl1.NX(TM1,:) ~= gl2.NX(TM2,:)))
361 if(any(gl1.NY(TM1,:) ~= gl2.NY(TM2,:)))
364 if(any(gl1.ECX(TM1,:) ~= gl2.ECX(TM2,:)))
367 if(any(gl1.ECY(TM1,:) ~= gl2.ECY(TM2,:)))
371 NBI1 = gl1.NBI(TM1,:);
372 NBI2 = gl2.NBI(TM2,:);
373 if(any(gl1.CX(NBI1) ~= gl2.CX(NBI2)))
376 if(any(gl1.CY(NBI1) ~= gl2.CY(NBI2)))
379 if(any(any(gl1.X(gl1.VI(NBI1,:)) ~= gl2.X(gl2.VI(NBI2,:)))))
382 if(any(any(gl1.Y(gl1.VI(NBI1,:)) ~= gl2.Y(gl2.VI(NBI2,:)))))
385 if(any(any(gl1.SX(NBI1,:) ~= gl2.SX(NBI2,:))))
388 if(any(any(gl1.SY(NBI1,:) ~= gl2.SY(NBI2,:))))
391 for i = 1:length(TM1)
395 error('step-number is unknown!');
function [ sim_data , tictoc ] = load_detailed_simulation(m, savepath, params)
load single trajectory of previously saved results.
function step1_detailed_simulation()
script performing a single detailed simulation and plotting it.
function plot_error_landscape(output)
plots an output structure generated by stochastic_error_estimation()
A hierarchical cubegrid of arbitrary dimension.
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 save_detailed_simulations(model, model_data, M, savepath)
perform loop over detailed simulations and save results or check consistency with existing saved resu...
function step8_estimator_landscape()
script generating landscapes plot data by computing the error estimator of reduced simulations for gi...
function step6_demo_rb_gui()
script comparing time for a reduced and a detailed simulation and starting the demonstration GUI ...
function step3_detailed_ei_simulation()
script performing a detailed simulation with empirical interpolated operators comparing the result wi...
function p = plot_sim_data(model, model_data, sim_data, plot_params)
function performing the plot of the simulation results as specified in model.
function step5_rb_generation()
script constructing a reduced basis space