1 function outfile = twophase_flow(steps, params)
9 if ~isfield(params, '
id')
13 if ~isfield(params, 'size')
16 if ~isfield(params, 'mode')
17 params.mode = 'normal';
20 mkdir(fullfile(rbmatlabresult, 'TwoPhaseFlow'));
21 outfile_prefix = fullfile(rbmatlabresult, 'TwoPhaseFlow', params.
id, 'Script');
22 imsavepath = fullfile(getenv('BASEDIR'), 'images', 'TwoPhaseFlow');
23 [dummy, sha] = system('git log --no-color --format=''%H'' HEAD | head -1');
24 outfile_elems = {
'params',
'sha'};
26 for si = 1:length(steps)
32 descr = twophase_descr(params);
36 model_data = gen_model_data(dmodel);
38 bg_descr.rb_problem_type = 'TwoPhaseFlow';
39 bg_descr.train_sample_mode = 'single';
44 outfile_elems = [ outfile_elems, {
'descr',
'dmodel',
'model_data',
'rmodel'}];
45 outfile = [outfile_prefix, 'Step0'];
46 save(outfile, outfile_elems{:});
48 oldoutfile = [outfile_prefix, 'Step0'];
50 outfile_elems = unique([outfile_elems, matfile_fields(oldoutfile)]);
53 sim_data = detailed_simulation(dmodel, model_data);
57 outfile_elems = [ outfile_elems, {'sim_data'}];
58 outfile = [outfile_prefix, 'Step1'];
59 save(outfile, outfile_elems{:});
62 if exist([outfile_prefix,
'Step1.mat'],
'file')
63 oldoutfile = [outfile_prefix, 'Step1'];
65 oldoutfile = [outfile_prefix, 'Step0'];
68 outfile_elems = unique([outfile_elems, matfile_fields(oldoutfile)]);
69 if exist([outfile_prefix, 'Step1'], 'file')
70 load([outfile_prefix, 'Step1']);
73 detailed_data = gen_detailed_data(rmodel, model_data);
75 outfile_elems = [ outfile_elems, {
'detailed_data'}];
76 outfile = [outfile_prefix, 'Step2'];
77 save(outfile, outfile_elems{:});
79 oldoutfile = [outfile_prefix, 'Step2'];
81 outfile_elems = unique([outfile_elems, matfile_fields(oldoutfile)]);
82 reduced_data = gen_reduced_data(rmodel, detailed_data);
84 rb_sim_data = rb_simulation(rmodel, reduced_data);
86 rb_sim_data.tictoc = t;
89 rb_sim_data = rb_reconstruction(rmodel, detailed_data, rb_sim_data);
91 rb_sim_data.rtictoc = t;
95 if exist(
'sim_data',
'var')
96 l2_errs = dmodel.l2_error_sequence_complete(rb_sim_data, sim_data, detailed_data.model_data);
97 linfty_errs = dmodel.linfty_error_sequence_complete(rb_sim_data, sim_data, detailed_data.model_data);
100 subplot(1,2,1); plot_error_sequence(dmodel, l2_errs); title('L^2-error');
101 subplot(1,2,2); plot_error_sequence(dmodel, linfty_errs); title('L^{\infty}-error');
103 data = [0:rmodel.descr.dt:rmodel.descr.T; ...
104 l2_errs.S; linfty_errs.S; ...
105 l2_errs.U; linfty_errs.U; ...
106 l2_errs.P; linfty_errs.P];
107 datafile = fullfile(imsavepath,
'errors_over_time.dat');
109 print_datatable(datafile, {
't',
'sat_l2',
'sat_linfty',
'vel_l2',
'vel_linfty',
'prs_l2',
'prs_linfty'}, data);
111 tmpcell = cellfun(@(X) rb_sim_data.(X) - sim_data.(X), {
'S',
'U',
'P'},
'UniformOutput',
false);
112 diff_data_rb=cell2struct(tmpcell, {
'S',
'U',
'P'}, 2);
115 datafile = fullfile(imsavepath,
'basis_gen.dat');
117 Ns = get_by_description(N,
'saturation');
118 Nu = get_by_description(N,
'velocity');
119 Np = get_by_description(N,
'pressure');
121 Ms = get_by_description(M,
'L_saturation');
122 Mu = get_by_description(M,
'L_velocity');
123 l2_errs.tot = l2_errs.S + l2_errs.U + l2_errs.P;
124 linfty_errs.tot = linfty_errs.S + linfty_errs.U + linfty_errs.P;
125 data = [ Ns, Nu, Np, Ms, Mu, ...
126 model_data.grid.nelements, ...
127 max(l2_errs.S), max(linfty_errs.S), ...
128 max(l2_errs.U), max(linfty_errs.U), ...
129 max(l2_errs.P), max(linfty_errs.P), ...
130 max(l2_errs.tot), max(linfty_errs.tot), ...
131 sim_data.tictoc, rb_sim_data.rtictoc]
';
133 print_datatable(datafile, {'Ns
', 'Nu
', 'Np
', 'Ms
', 'Mu
', 'H
', 'sat_l2
', 'sat_linfty
', 'vel_l2
', 'vel_linfty
', 'prs_l2
', 'prs_linfty
', 'l2
', 'linfty
', 'time
', 'rtime
'}, data);
136 outfile_elems = [ outfile_elems, {'reduced_data
', 'rb_sim_data
'}];
137 outfile = [outfile_prefix, 'Step3
'];
138 save(outfile, outfile_elems{:});
145 function fnames = matfile_fields(matfile)
146 temp = whos('-file', matfile);
147 fnames = arrayfun(@(X) X.name, temp,
'UniformOutput',
false)
';