3 % collects
operator evaluations on a sample of snapshots
5 % This
function collects
operator evaluations applied to sets of snapshots.
6 % Given a list of operators parameter dependent operators `L_q(\mu) \in {\cal
7 % W}_h, q=1,\ldots,Q` which are `H`-independent Dof dependent as described in
8 % [DOH10] and a set of parameters `M \subset {\cal M} \subset {\cal R}^p`,
this
9 %
function computes
operator evaluations `L_q(\mu)[u_h(\mu;t^k)]`
for all `\mu
10 % \in M` and `t^k=k\Delta t`, and stores the results in matlab files.
13 % Mtrain : a matrix specifying the parameter
set `M`
for which
14 % detailed simulations shall be computed. The column vectors of the
15 % matrix each contain a parameter vector.
16 % params : a structure controlling the behaviour of
this function
18 % required fields of model:
19 % collect_newton_steps :
boolean flag, indicating whether the intermediate
20 %
newton steps computed by a detailed simulaton with a Newton scheme
21 % shall also be considered when applying the operators
22 % ei_detailed_savepath : path, where the trajectories computed as results
23 % of detailed simulations are stored. This files must contain a
24 % structure named
'sim_data' with a field
'U' of dimesion
25 %
'\#DOFs x model.nt +1' or a field
'Unewton' of dimension
26 %
'\#DOFs x model.nt + 1 + \#intermediate Newton steps' in
case of a
27 % Newton scheme and
'model.collect_newton_steps==true'. The files are
30 % ei_operator_savepath : path, where the LU-files are stored. These files
31 % each contain an array named 'LU' of the same dimension as 'sim_data.U'
32 % respectively 'sim_data.Unewton' from the files stored in
33 % 'ei_detailed_savepath'.
34 % separate_CRBs :
boolean flag, indicating whether, the operator
35 % evaluations shall be stored in different directories for the later
36 % computation of separate collateral reduced basis spaces for each
37 % operator, or combined a single directory.
39 % optional fields of model:
40 % force_delete : if this option is set to true (the default), directories
41 % with data inconsistent with the current settings are
44 % required fields of params:
45 % ei_space_operators: cell array of function pointers to spacial operators
46 % `L_q, q=1,\ldots,Q` for which evaluations on snapshots shall be
47 % computed and stored.
49 % optional fields of params:
50 % num_cpus: number of cpu cores that can be used for parallel
51 % computations. This parameter has only an effect, when Matlab's
52 % parallel computation capabilities are started by initiating a
53 % matlabpool. (default == 4)
55 % paths are to be understood relative to $RBMATLABTEMP
57 % Bernard Haasdonk 15.8.2007
59 % for each mu in Mtrain compute exact detailed trajectory u_H^k(mu)
60 npar = size(Mtrain,2);
63 disp(['generating detailed data in ',...
64 fullfile(rbmatlabtemp,model.ei_detailed_savepath)]);
70 savepath = fullfile(getenv('RBMATLABTEMP'),...
71 model.ei_operator_savepath);
74 disp(['generating ei_operator snapshot data in ',...
75 fullfile(rbmatlabtemp,model.ei_operator_savepath)]);
78 if ~isfield(model, 'force_delete')
79 model.force_delete = 1;
82 if ~exist(savepath,'dir');
83 [s,m,
id] =mkdir(getenv('RBMATLABTEMP'), ...
84 model.ei_operator_savepath);
86 error('problem in creating directory!');
88 elseif exist(fullfile(savepath,'settings.mat'), 'file')
89 % checking consistency of existing
90 disp('directory exists, checking for correct data.');
91 tmp = load(fullfile(savepath,'settings.mat'));
93 if ~isequal(Mtrain, tmp.Mtrain)
94 if ~model.debug && model.force_delete
95 disp(['Mtrain in precomputed data and current are inconsistent!',...
96 ' I am deleting the old data now!']);
97 delete(fullfile(savepath,'*.mat'))
100 error(['Mtrain in precomputed data and current',...
101 ' simulation are inconsistent! Please delete and restart!']);
104 % fields to skip in comparison
105 ignorelist = {
'Mmax',
'ei_Mmax',
'RB_stop_epsilon',
'RB_stop_Nmax',...
106 'ei_target_error',
'velocity_coefficients_ptr',
'Mstrich',...
107 model.mu_names{:},
'force_delete',
'RB_error_indicator',...
108 'ei_time_splits',
'verbose',
'adaptive_time_split_mode', ...
110 'ei_stop_epsilon',
'ei_stop_epsilon_first', ...
111 'minimum_time_slice',
'time_split_Mmax'};
112 ignorelist = [ignorelist, tmp.model.filecache_ignore_fields_in_model];
113 [iseq, a,b,c] = structcmp(model,tmp.model,ignorelist);
115 disp(
'fields of params and stored params differs:')
116 disp('differing fields:');
118 disp('additional fields in params:');
120 disp('additional fields in stored params:');
122 if ~model.debug && model.force_delete
123 disp(['Mtrain in precomputed data and current are inconsistent!',...
124 ' I am deleting the old data now!']);
125 delete(fullfile(savepath,'*.mat'))
128 error(['parameters of precomputed data and current',...
129 ' simulation are inconsistent! Please delete files at path ', ...
130 savepath, ' and restart!']);
134 if exist(fullfile(savepath,'UNFINISHED.lock'),'file');
135 disp(['detected UNFINISHED.lock in target directory, ',...
136 'resuming previous computations...']);
138 disp('skipping ei_operator evaluations on snapshots, as results existing')
139 skip_computation = 1;
144 disp('stray directory found! I am cleaning this one, now!');
145 delete(fullfile(savepath,'*.mat'))
149 save(fullfile(savepath,'UNFINISHED.lock'),'savepath');
150 save(fullfile(savepath,'settings.mat'),'Mtrain','model');
152 LU_fnames = cell(length(params.ei_space_operators),npar);
153 %BU_fnames = cell(length(params.ei_space_operators),npar);
155 % for each of these trajectories,
156 % select time-instants and apply tobe-interpolated operator
158 model.dt = model.T / model.nt;
160 if ~iscell(params.ei_space_operators)
161 params.ei_space_operators = { params.ei_space_operators };
164 if ~isfield(params,
'num_cpus')
167 num_cpus = params.num_cpus;
169 %if ~isfield(params, 'separate_CRBs')
170 % params.separate_CRBs = false;
174 for oi = 1:length(params.ei_space_operators)
175 for mout = 0:floor((npar-1)/num_cpus)
177 parfor m = (mout*num_cpus+1):min(npar,(mout+1)*num_cpus)
178 % mm = m - mout*num_cpus;
180 opname = tmp_params.ei_space_operators{oi};
181 tmp_model_data = model_data;
183 oiIdent = num2str(oi);
184 disp([
'processing parameter vector ',num2str(m),
'/',num2str(npar)]);
185 LU_fnames{oi,m} = fullfile(tmp_model.ei_operator_savepath,...
186 [
'LU_',oiIdent,
'_',num2str(m),
'.mat']);
187 % BU_fnames{oi,m} = fullfile(tmp_model.ei_operator_savepath,...
188 % [
'BU_',oiIdent,
'_',num2str(m),
'.mat']);
189 skip_file = exist(LU_fnames{oi,m},
'file');% && exist(BU_fnames{oi,m},
'file')
190 if ~skip_computation && ~skip_file
191 % determine initial size of vectors:
193 if model.newton_solver && model.collect_newton_steps
194 U = sim_data.Unewton;
198 TLU = zeros(size(U,1),0);
199 %TBU = zeros(size(U,1),0);
200 newmodel = model.set_mu(model, Mtrain(:,m));
201 if isfield(model,
'model_type') && isequal(newmodel.model_type,
'implicit_nonaffine_linear')
203 [tmp_model_data.implicit_operator, tmp_model_data.implicit_constant] = ...
204 model.operators_diff_implicit(newmodel, tmp_model_data, []);
207 if newmodel.newton_solver
208 for tn = 1:size(U,2);
210 if newmodel.debug && ~newmodel.data_const_in_time
211 error('time dependent data is not yet implemented for
newton schemes');
213 [nu, bu] = opname(newmodel, tmp_model_data, U(:,tn), []);
214 if ~isempty(bu) && tn==1
220 for tn = 1:length(newmodel.ei_time_indices);
222 ti = newmodel.ei_time_indices(tn);
223 % note the time-shift by 1 in the following (ti=1 is initial data)
224 newmodel.t = (ti-1)*newmodel.dt;
226 [nu, bu] = opname(newmodel, tmp_model_data, U(:,ti), []);
227 if ~isempty(bu) && tn==1
231 % save(fullfile(rbmatlabtemp,BU_fnames{oi,m}),
'LU');
241 for m = (mout*num_cpus+1):min(npar,(mout+1)*num_cpus)
242 skip_file = exist(LU_fnames{oi,m},'file');% && exist(BU_fnames{oi,m},
'file')
244 % mm = m - mout*num_cpus;
246 save(fullfile(rbmatlabtemp,LU_fnames{oi,m}),
'LU');
253 if ~model.separate_CRBs
254 LU_fnames = reshape(LU_fnames, 1, size(LU_fnames,1)*size(LU_fnames,2));
257 if exist(fullfile(savepath,
'UNFINISHED.lock'),
'file');
258 delete(fullfile(savepath,
'UNFINISHED.lock'));