rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
script_detailled_simulation.m
Go to the documentation of this file.
1 % detailed_simulation_refined
2 
3 dbstop if error
4 
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 %%%% RESUME SIMULATION ?!?!?! %%%%%%%%%%%%%%%%%%%%%
7 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 %%%% Falls Simulation mit vorher gespeicherten Daten fortgesetzt wird:
9 %%%% Variable resume_simulation = 1 setzen und
10 %%%% hier den Name der zu ladenden Datei eingeben:
11 if exist('resume_simulation', 'var') && resume_simulation == 1
12 
13  %falls automatisch gespeicherte daten vorhanden und geladen werden
14  %sollen: tue dies hier und verwerfe die bisher geladenen daten:
15  if exist('loaded_automatically', 'var') && loaded_automatically == 1
16  %Daten müssen hier nicht mehr geladen werden, wurde schon in
17  %"DAS_UEBERSKRIPT" gemacht
18  cone_stop = c; %nur diesen einen cone_wert_berechnen
19  else %falls von hand geldane werden soll: gehe hier rein
20  load_saved_results = 'sicher_bernard_c8_216simsdone';
21  %load_saved_results = 'sicher_oli_c1_2done';
22  load_string = ['load ', load_saved_results];
23  eval(load_string)
24  end
25 
26  resume_simulation = 1; %wird durch das laden der daten auf 0 gesetzt --> muss ich heir von hand wieder auf 1 setzen
27  cone_start = c;
28 end
29 
30 
31 
32 if (~exist('resume_simulation', 'var')) || (resume_simulation == 0)
33  % If a calculation is resumed (that means if there exists a variable resume_simulation=1),
34  % use the loaded data instead of creating new data, i.e. this part is
35  % leapfroged and a new simulation is started
36 
37  clear
38  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39  %%%% NEW SIMULATION !!! %%%%%%%%%%
40  %%%% Change here the details of the calculation
41  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42  %used_basis_load = ['Greedy_basis_coarse1_100_adapt'];
43 
44  params.coarse_factor=4;
45  model = advection_fv_output_opt_model(params);
46  model_data = gen_model_data(model);
47 
48 
49  refinement_stop = 5; % Refinement_stop sets the meximal refinement_level,
50  % that means the level of subdivision of vx_weight and vy_weight
51  % 1 means 3 points per direction, 2 means 5
52  % points, 9 means 9 points...
53  cone_weight_nbrs = 33;
54 
55  % IN JEWEILGER VERSION (MARKUS; DANIEL; BERNARD; OLI)ANPASSEN!!!
56  % CONE WEIGHT LÄUFT VON 1 bis 17!!!
57  %Oli:
58  cone_start = 1;
59  cone_stop = 33;
60 
61  % Markus:
62  %cone_start = 3;
63  %cone_stop = 4;
64  %
65  % Bernard:
66  %cone_start = 5;
67  %cone_stop = 10;
68  %
69  % Daniel:
70  % cone_start = 11;
71  % cone_stop = 17;
72  % END: IN JEWEILGER VERSION (MARKUS; DANIEL; BERNARD; OLI) ANPASSEN!!!
73 
74 
75  % load the basis from *.mat file
76  %used_basis=[used_basis_load,'.mat'];
77  %load(used_basis);
78 
79  %change some fields in the model
80  model.compute_derivative_info=1;
81  model.optimization.params_to_optimize = [1 1 1];
82  model.L_I_inv_norm_bound = 1;
83  model.L_E_norm_bound = 1;
84  model.L_E_der_norm_bound = [0,1.25, 1];
85  model.L_I_der_norm_bound = [0,0,0];
86 
87  %reduced_data = gen_reduced_data(model, detailed_data);
88 
89  nr_params = length(model.mu_names);
90 
91  cone_weight = linspace(model.mu_ranges{1}(1),model.mu_ranges{1}(2),cone_weight_nbrs);
92  resume_simulation=0;
93  time=0;
94 end
95 
96 backup_nr = 30; % do a backup after (save workspace) after "backup_nr" simulations
97 
98 %Start Simulation
99 for c = cone_start:cone_stop % OBEN IN JEWEILIGER VERSION ANPASSEN: Laufindex für cone_weight
100  model.cone_weight = cone_weight(c);
101 
102  if resume_simulation ~= 1
103  clear value_calculated sim_data_J sim_data_s
104  end
105 
106  %if saved data are loaded to resume a calculation where the
107  %refinement_level has already been higher than 1, this refinement_level
108  %must be set here again...
109  if resume_simulation == 1
110  refinement_start = refinement_level;
111  else
112  refinement_start = 1;
113  end
114 
115 
116  for refinement_level = refinement_start:refinement_stop;
117 
118  dots_vx_vy = 2^refinement_level+1;
119 
120 
121  %create matrices in first loop
122  if ~exist('value_calculated','var')
123  value_calculated = zeros(dots_vx_vy);
124  end
125  if ~exist('sim_data_J','var')
126  sim_data_J = cell(dots_vx_vy, dots_vx_vy);
127  end
128  if ~exist('sim_data_s','var')
129  sim_data_s = cell(dots_vx_vy, dots_vx_vy);
130  end
131 
132  vx_weight = linspace(model.mu_ranges{2}(1),model.mu_ranges{2}(2),dots_vx_vy);
133  vy_weight = linspace(model.mu_ranges{3}(1),model.mu_ranges{3}(2),dots_vx_vy);
134 
135  %%%%%%%%%%%%
136  % simulation
137  %%%%%%%%%%%%
138  for x=1:dots_vx_vy
139  model.vx_weight=vx_weight(x);
140  for y=1:dots_vx_vy
141  model.vy_weight=vy_weight(y);
142 
143  if value_calculated(x,y) ~= 1
144 
145  %perform detailed_simulation
146  tic;
147  model.detailed_simulation = @lin_evol_opt_detailed_der_simulation;
148  %model.detailed_simulation = @test_det_der_sim_dummy; %IN CASE OF TESTING OF SOME CHANGES
149  sim_data = detailed_simulation(model, model_data);
150  sim_data_J{x,y} = sim_data.y;
151  sim_data_s{x,y} = sim_data.y_der;
152 
153  value_calculated(x,y) = 1;
154 
155  % Calculate the needed time for display
156  sim_time=toc/60; %Zeit für die letzte Simulation
157  time = time + sim_time; %bisher vergangene Zeit in Minuten
158  nr_sims_per_cone = (2^refinement_stop +1)^2;
159  nr_sims_done = length(find(value_calculated)) + ...
160  + (c - cone_start) * nr_sims_per_cone; %Anzahl der schon berechneten Simulationen
161  nr_sims_total = (2^refinement_stop + 1)^2 * (cone_stop - cone_start +1); %Gesamtanzahl der Simulationen (abh. vom Refinement Stop)
162  nr_sims_left_cone = nr_sims_per_cone - length(find(value_calculated));
163  nr_sims_left_refinement = mod(dots_vx_vy^2 - mod(nr_sims_per_cone - nr_sims_left_cone,dots_vx_vy^2),dots_vx_vy^2);
164  nr_sims_left_total = nr_sims_total - nr_sims_done; %insgesamt noch benötigte Simulationen
165  average_time = time/nr_sims_done; %Durchschnittszeit pro Simulation in Minuten
166  expected_time_left_cone = average_time * nr_sims_left_cone; %Vorr. verbleibende Zeit in Minuten auf diesem Refinement-Level
167  expected_time_left_total = average_time * nr_sims_left_total; %Vorr. verbleibende Zeit in Minuten auf diesem Refinement-Level
168 
169  %Display some status results
170  disp(['Insgesamt Durchgeführte Simulationen: ' num2str(nr_sims_done) ' (von ' num2str(nr_sims_total) ' gesamt)']);
171  disp('---');
172  disp(['Aktueller cone_weight Wert = ' num2str(model.cone_weight) ...
173  ' (zu berechnender Cone Wert Nr.' num2str(c - cone_start + 1) ' von ' num2str(cone_stop-cone_start+1) ')']);
174  disp(['Anzahl der durchgeführten Simulationen für diesen Cone Wert: ' num2str(length(find(value_calculated))) ...
175  ' von ' num2str(nr_sims_per_cone) ' (' num2str(nr_sims_left_cone) ' noch zu berechnen)']);
176  disp(['+ aktuelles Refinement Level für diesen Cone-Wert = ' num2str(refinement_level) ' (entspricht ' ...
177  num2str(dots_vx_vy^2) ' Punkten)']);
178  disp(['+ maximales Refinement Level = ' num2str(refinement_stop) ' (entspricht '...
179  num2str(nr_sims_per_cone) ' Punkten)']);
180  disp(['+ Anzahl der noch zu berechnenden Punkte für dieses Refinement-Level: ' num2str(nr_sims_left_refinement)]);
181  disp('---');
182  disp(['Gesamtzeit nach diesem Durchlauf: ' num2str(time) ' Minuten / ' num2str(time/60) ' Stunden']);
183  disp(['durchschnittliche Zeit pro Durchlauf: ' num2str(average_time) ' Minuten']);
184  disp(['Vorraussichtlich verbleibende Zeit für diesen Cone-Wert: ' num2str(expected_time_left_cone) ...
185  ' Minuten / ' num2str(expected_time_left_cone/60) ' Stunden']);
186  disp(['Vorraussichtlich verbleibende Gesamtzeit: ' num2str(expected_time_left_total) ' Minuten / '...
187  num2str(expected_time_left_total/60) ' Stunden']);
188  disp('--------------------------------------------------------------------------');
189  disp('--------------------------------------------------------------------------');
190 
191  resume_simulation = 0;
192 
193  % Backup from time to time...
194  if mod(nr_sims_done,backup_nr) == 0;
195  backup_string=['save backup_cone', num2str(c), '_', num2str(cone_weight_nbrs), ...
196  '_simsdonecone', num2str(length(find(value_calculated))), ...
197  '_reflvl', num2str(refinement_level), '_simsleftreflvl', num2str(nr_sims_left_refinement)];
198  eval(backup_string)
199  end
200  end
201  end
202  end
203 
204  used_cone_weight = cone_weight(c);
205  save_string=['save new_det_sim_cone', num2str(c), '_', num2str(cone_weight_nbrs), '_vx',...
206  num2str(dots_vx_vy),'_vy',num2str(dots_vx_vy), '_', ...
207  ' sim_data_J', ' sim_data_s', ' used_cone_weight', ' value_calculated', ' vx_weight', ' vy_weight'...
208  ' cone_weight', ' refinement_level'];
209  eval(save_string)
210 
211  %falls letzte simulation vorbei: speichere kompletten workspace
212  %bevors ans neue cone geht! auch wichtig für automatisches laden in
213  % DAS_UEBERSCRIPT
214  if length(find(value_calculated)) == nr_sims_per_cone
215  save_string_cone = ['save finished_det_sim_cone', num2str(c), '_refstop', num2str(refinement_stop),'coarse4'];
216  eval(save_string_cone)
217  end
218 
219 
220  % Blowup the result-matrices and cells
221  value_calculated = blowup_matrix(value_calculated);
222  sim_data_J = blowup_cell(sim_data_J);
223  sim_data_s = blowup_cell(sim_data_s);
224 
225 
226  end
227 
228 end