3 % perform loop over detailed simulations and save results or check
4 % consistency with existing saved results.
6 % -# If the given path does not exist, it is generated and a set of
7 % detailed simulations
for all parameters mu (columns of M).
8 % is computed and the results are stored in the path specified in
10 % Files to be generated in the target path are:
11 % -
'settings.mat' :containing
'model',
'grid',
'M',
'path', ... such that
12 % the directory can be regenerated with
this file and
13 % the current
function
14 % -
'detail1.mat' :containing the simulation data
for first `mu`
16 % -
'detail1.mat' :containing the simulation data
for second `mu`
19 % -
'detail123.mat' : ...
21 % -# If the path exists, a check on consistency is performed by checking the
22 %
'model' and
'Mtrain' fields and checking whether the previous computation has
23 % been finished. If it is not, and the current settings are consistent with the
24 % old ones, the computations are resumed.
26 % optional fields of model:
27 % force_delete :
if this option is set to
true (the
default), directories
28 % with data inconsistent with the current settings are
32 % M : is a matrix of `mu` vectors (column vectors)
for which detailed
33 % simulations shall be computed and stored.
34 % savepath: is the directory name relative to
'RBMATLABTEMP' where the
35 % detailed simulations shall be stored.
38 % Bernard Haasdonk 29.3.2007
40 sp = fullfile(rbmatlabtemp,savepath);
42 if ~isfield(model,
'force_delete')
43 model.force_delete = 1;
46 % generate directory if not available
48 disp('data directory does not exist, creating .... ');
49 [p,s,e] = fileparts(sp);
53 error('error in generating savepath!');
55 elseif exist(fullfile(sp, 'settings.mat'), 'file')
56 % check consistency of file
57 tmp = load(fullfile(sp,'settings.mat'));
58 % fields to skip in comparison
59 ignorelist = {
'Mmax',
'MM',
'Mstrich',
'ei_Mmax',
'k',
'Mmax',
'M',
'N',
'Nmax',...
60 'RB_error_indicator',
'RB_stop_Nmax',...
61 'RB_stop_timeout',
'RB_detailed_test_savepath',...
62 'RB_generation_mode',
'RB_train_rand_seed',
'RB_train_size',...
63 'test_N_samples',
'RB_stop_epsilon',
'RB_M_val_size',...
64 'RB_numintervals',
'RB_refinement_mode',...
65 'RB_refinement_theta',
'RB_max_refinement_level',...
66 'RB_stop_max_val_train_ratio',
'RB_val_rand_seed',...
67 'ei_stop_on_Mmax',
'CRB_generation_mode',...
69 'CRB_basis_filename',
'ei_space_operators',...
70 'Msamples',
'ei_operator_savepath',
'ei_target_error',...
71 'ei_numintervals',
'ei_detailed_savepath',
'verbose',
'debug', ...
72 'velocity_coefficients_ptr',
'enable_error_estimator',...
73 'force_delete',
'ei_time_splits',
'adaptive_time_split_mode', ...
74 'ei_stop_epsilon',
'ei_stop_epsilon_first',
'minimum_time_slice', ...
76 ignorelist = [ignorelist, model.mu_names,...
77 model.filecache_ignore_fields_in_model];
79 [iseq, a,b,c] = structcmp(model,tmp.model,ignorelist);
81 disp(
'fields of model and stored model differs:')
82 disp('differing fields:');
84 disp('additional fields in model:');
86 disp('additional fields in stored model:');
88 if ~model.debug && model.force_delete
89 disp(['parameters in precomputed data and current are inconsistent!',...
90 ' I am deleting the old data now!']);
91 delete(fullfile(sp,'*.mat'))
94 error(['parameters of precomputed data and current',...
95 ' simulation are inconsistent! Please delete files in path ', ...
96 sp, ' and restart!']);
98 elseif ~isequal(M,tmp.M)
99 if ~model.debug && model.force_delete
100 disp(['M of precomputed and current data is inconsistent!',...
101 ' I am deleting the old data now!']);
102 delete(fullfile(sp,'*.mat'))
105 error(['M of precomputed data and current',...
106 ' simulation are inconsistent! Please delete and restart!']);
109 if exist(fullfile(sp,'UNFINISHED.lock'),'file')
111 disp(['detected UNFINISHED.lock in target directory, ',...
112 'resuming previous computations...']);
114 error(['Previous computation of detailed simulations seems not', ...
115 ' to be finished!!! please delete and restart!', ...
119 disp('skipping detailed computations and using stored results');
124 disp(['stray directory found! I am cleaning this one, now!']);
125 delete(fullfile(sp,'*.mat'))
129 save(fullfile(sp,'UNFINISHED.lock'),'model');
131 % save general settings
132 save(fullfile(sp,'settings.mat'),'M','model','savepath');
134 if ~isfield(model, 'num_cpus')
137 num_cpus = model.num_cpus;
139 % save simulation_data
141 for mout = 0:floor((npar-1)/num_cpus)
142 sim_data_c = cell(1, npar);
143 tictoc_c = cell(1, npar);
144 parfor mu = (mout*num_cpus+1):min(npar,(mout+1)*num_cpus)
146 filename = fullfile(sp,['detail',num2str(mu),'.mat']);
147 if ~exist(filename, 'file')
149 disp(['processing parameter vector ',num2str(mu),'/',num2str(npar)]);
150 %tmp_model = tmp_model.set_mu( model,M(:,mu) );
151 tmp_model = set_mu( tmp_model,M(:,mu) );
153 sim_data_c{mu} = detailed_simulation(tmp_model, model_data);
156 disp([
'file exists: skipping parameter vector ', ...
157 num2str(mu),
'/', num2str(npar)]);
160 for mu=(mout*num_cpus+1):min(npar,(mout+1)*num_cpus)
162 sim_data = sim_data_c{mu};
163 tictoc = tictoc_c{mu};
164 filename = fullfile(sp,[
'detail',num2str(mu),
'.mat']);
165 if ~exist(filename,
'file')
166 save(filename,'sim_data','tictoc');
171 delete(fullfile(sp,'UNFINISHED.lock'));
function save_detailed_simulations(model, model_data, M, savepath)
perform loop over detailed simulations and save results or check consistency with existing saved resu...