rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
porsche_script.m
1 function res=porsche_script(step,varargin)
2 %function res=porsche_script(step,varargin)
3 %
4 %
5 % GRID FUNCTIONS
6 % step 1: plot of the macrogrid
7 % step 2: plot of the microgrid
8 % step 3: plot microgrid elementwise
9 % step 4: reshape a grid and plot it
10 % DETAILED SIMULATIONS
11 % step 10: FEM simulation of the model with the reference grid
12 % step 11: FEM simulation with the reshaped grid, plot of the original grid
13 % RB SIMULATIONS
14 % step 20: RB simulation of the model with the reference grid
15 % step 21: RB simulation with the reshaped grid, plot of the original grid
16 % COMPARISON OF DETAILED AND RB SIMULATION
17 % step 30: compare detailed and RB solution of reference car
18 % step 31: compare detailed and RB solution of original car
19 % OPTIMIZATION
20 % step 40: Detailed Optimization
21 % step 41: RB Optimization N=9
22 % step 42: RB Optimization N=16
23 % step 43: RB Optimization N=25
24 % step 44: Comparison of detailed and RB Optimization
25 %
26 %
27 % Oliver Zeeb, 01.09.11
28 
29 if nargin == 0
30  step = 1;
31 end;
32 
33 if nargin < 2
34  params = [];
35 end;
36 
37 %set some parameters
38 params = [];
39 params.dimrange = 1;
40 pdeg = 1;
41 qdeg = 2 * pdeg; % quadrature_degree
42 params.pdeg = pdeg;
43 params.qdeg = qdeg;
44 params.no_plot = 0; %plotting active
45 
46 res = [];
47 
48 
49 switch step
50  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51  %%%%%%%%%%%%%%%%% GRID FUNCTIONS %%%%%%%%%%%%%%%%%
52  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 
54  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55  case 1 %plot of the macrogrid
56  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57  disp('=====================')
58  disp('plot of the macrogrid')
59  disp('=====================')
60  model = porsche_model;
61  model_data = gen_model_data(model);
62  plot_params.color=[1 0 0];
63  disp('plotting the macrogrid')
64  plot(model_data.macrogrid,plot_params);
65  axis equal;
66 
67  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68  case 2 %plot of the microgrid
69  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70  disp('=====================')
71  disp('plot of the microgrid')
72  disp('=====================')
73  model = porsche_model;
74  model_data = gen_model_data(model);
75  disp('plotting the microgrid')
76  plot(model_data.grid);
77  axis equal;
78 
79  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80  case 3 % plot microgrid elementwise
81  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82  disp('==============================')
83  disp('plot the microgrid elementwise')
84  disp('==============================')
85  clear
86  model = porsche_model;
87  model_data = gen_model_data(model);
88 
89  microgrid = model_data.grid;
90  macrogrid = model_data.macrogrid;
91  mic2mac=micro2macro_map(microgrid,macrogrid);
92 
93  for k=1:macrogrid.nelements
94  elids=find(mic2mac==k);
95 
96  figure(1)
97  axis equal
98  gridp=gridpart(model_data.grid,elids);
99  plot(gridp)
100  axis([0 750 -50 350])
101 
102  disp(['Macrotriangle Nr', num2str(k)])
103 
104  disp('press enter to continue')
105  pause;
106 
107  %close(1)
108  hold on
109  end
110 
111  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112  case 4 %reshape a grid and plot it
113  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114  disp('==============================')
115  disp(' reshape a grid and plot it ')
116  disp('==============================')
117  model = porsche_model;
118  model_data = gen_model_data(model);
119 
120  %reset the mus
121  mu_mod = [0,30];
122  model = change_mu(model, mu_mod);
123 
124  %reshape the grid
125  grid_reshaped = grid_reshape(model, model_data.grid);
126 
127  %plot reshaped grid
128  disp('plotting the original grid')
129  figure(1)
130  plot(grid_reshaped);
131  axis equal
132  title('original grid')
133 
134  %plot reference grid
135  disp('plotting the reference grid')
136  figure(2)
137  plot(model_data.grid)
138  axis equal
139  title('reference grid')
140 
141 
142  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143  %%%%%%%%%%%%% DETAILED SIMULATIONS %%%%%%%%%%%%%%%
144  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 
146  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147  case 10 % finite element assembly, solution and plot
148  % with the reference car
149  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150  disp('==============================================')
151  disp(' FEM solution and plot of the reference car ')
152  disp('==============================================')
153 
154  %%%%%%%%%%%%%%% initialize model %%%%%%%%%%%%%%%%%%%
155  model = porsche_model(params);
156  model_data = gen_model_data(model);
157 
158  % do an FEM-simulation
159  disp('calculating detailed simulation...')
160  sim_data = detailed_simulation(model,model_data);
161 
162 
163  %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
164  disp('plotting the PDE solution...')
165  plot_sim_data(model,model_data,sim_data,1)
166  % calculate and plot pressure and velocity
167  disp('calculating gradient (velocity) and pressure')
168  [sim_data.gradx, sim_data.grady]=disc_gradient([sim_data.uh.grid.X,sim_data.uh.grid.Y],sim_data.uh);
169  sim_data.pressure=compute_pressure(model,sim_data.gradx, sim_data.grady);
170  disp('plotting the velocity and pressure...')
171  plot_sim_data(model,model_data,sim_data,3)
172 
173  res = sim_data;
174  disp('porsche_script step 10 complete! Inspect workspace...')
175  keyboard
176 
177 
178  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179  case 11 %do a FEM Simulation with the reshaped grid
180  %and plot the solution on the reshaped grid
181  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 
183  disp('=============================================')
184  disp(' FEM solution and plot of the original car ')
185  disp('=============================================')
186 
187  %%%%%%%%%%%%%%% initialize model %%%%%%%%%%%%%%%%%%%
188  model = porsche_model;
189  model_data = gen_model_data(model);
190 
191  %reset the mus
192  mu_mod = [0,30];
193  model=change_mu(model, mu_mod);
194 
195  disp('calculating detailed simulation...')
196  sim_data = detailed_simulation(model,model_data);
197 
198  %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
199  disp('plotting the PDE solution...')
200  plot_sim_data(model,model_data,sim_data,2);
201 
202  disp('calculating gradient (velocity) and pressure')
203  [sim_data.gradx,sim_data.grady]=disc_gradient([sim_data.uh.grid.X, sim_data.uh.grid.Y],sim_data.uh); % OLI: 14.02.11 ONLY VALID FOR PDEG = 1 !
204  sim_data.pressure=compute_pressure(model, sim_data.gradx, sim_data.grady);
205  disp('plotting the velocity and pressure...')
206  plot_sim_data(model,model_data,sim_data,4)
207 
208  res=sim_data;
209  disp('porsche_script step 11 complete! Inspect workspace...')
210  keyboard
211 
212 
213 
214  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215  %%%%%%%%%%%%%%%%% RB SIMULATIONS %%%%%%%%%%%%%%%%%
216  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 
218  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219  case 20 % RB-Simulation of the reference car
220  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 
222  disp('=============================================')
223  disp(' RB-Simulation of the reference car ')
224  disp('=============================================')
225 
226  %%%%%%%%%%%%%%% initialize model %%%%%%%%%%%%%%%%%%%
227  disp('Setting the model...');
228  model=porsche_model;
229  disp('generating model_data');
230  model_data=gen_model_data(model);
231 
232  %%%%%%%%%%%% RB-Simulation %%%%%%%%%%%%%%
233  disp('generating detailed_data...');
234  detailed_data=gen_detailed_data(model,model_data);
235  disp('generating reduced_data...');
236  reduced_data=gen_reduced_data(model,detailed_data);
237  disp('doing a reduced simulation');
238  rb_sim_data=rb_simulation(model,reduced_data);
239  disp('rb_reconstruction...');
240  rb_sim_data=rb_reconstruction(model,detailed_data,rb_sim_data);
241 
242 
243 
244  %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
245  disp('plotting the PDE solution...')
246  plot_sim_data(model,model_data,rb_sim_data,1);
247 
248  % calculate and plot pressure and velocity
249  disp('calculating gradient (velocity) and pressure')
250  [rb_sim_data.gradx, rb_sim_data.grady]=disc_gradient([rb_sim_data.uh.grid.X, rb_sim_data.uh.grid.Y],rb_sim_data.uh);
251 
252  rb_sim_data.pressure=compute_pressure(model,rb_sim_data.gradx, rb_sim_data.grady);
253  disp('plotting the velocity and pressure...')
254  plot_sim_data(model, model_data, rb_sim_data,3)
255 
256  res = rb_sim_data;
257 
258  disp('porsche_script step 20 complete! Inspect workspace...')
259  keyboard
260 
261 
262  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263  case 21 %do a RB-Simulation with the original grid
264  %and plot the solution on the original grid
265  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266 
267  disp('=============================================')
268  disp(' RB-Simulation of the original car ')
269  disp('=============================================')
270 
271  disp('Setting the model...');
272  model = porsche_model;
273  disp('generating model_data');
274  model_data = gen_model_data(model);
275  disp('generating detailed_data...');
276  detailed_data=gen_detailed_data(model,model_data);
277  disp('generating reduced_data...');
278  reduced_data=gen_reduced_data(model,detailed_data);
279 
280  %reset the mus
281  mu_mod=[0,30];
282  model=change_mu(model, mu_mod);
283 
284  %RB-Simulation
285  disp('doing a reduced simulation');
286  rb_sim_data=rb_simulation(model,reduced_data);
287  disp('rb_reconstruction...');
288  rb_sim_data=rb_reconstruction(model,detailed_data,rb_sim_data);
289 
290  %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
291  disp('plotting the PDE solution...')
292  plot_sim_data(model,model_data,rb_sim_data,2);
293 
294 
295  disp('calculating gradient (velocity) and pressure')
296  [rb_sim_data.gradx,rb_sim_data.grady]=disc_gradient([rb_sim_data.uh.grid.X, rb_sim_data.uh.grid.Y],rb_sim_data.uh); % OLI: 14.02.11 ONLY VALID FOR PDEG = 1 !
297  rb_sim_data.pressure=compute_pressure(model, rb_sim_data.gradx, rb_sim_data.grady);
298  disp('plotting the velocity and pressure...')
299  plot_sim_data(model,model_data,rb_sim_data,4)
300 
301  res=rb_sim_data;
302 
303  disp('porsche_script step 21 complete! Inspect workspace...')
304  keyboard
305 
306 
307 
308  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309  %%%% COMPARISON OF DETAILED AND RB SIMULATION %%%%
310  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 
312  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313  case 30 % Comparison with the reference car
314  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 
316  disp('=====================================================================')
317  disp(' Comparison between detailed an RB-simulation with the reference car ')
318  disp('=====================================================================')
319 
320  %%%%%%%%%%%%%%% initialize model %%%%%%%%%%%%%%%%%%%
321  disp('Setting the model...');
322  model=porsche_model;
323  disp('generating model_data');
324  model_data=gen_model_data(model);
325 
326  %%%%%%%%% Detailed Simulation %%%%%%%%%%%
327  disp('doing a detailed_simulation...');
328  sim_data = detailed_simulation(model,model_data);
329 
330  %%%%%%%%%%%% RB-Simulation %%%%%%%%%%%%%%
331  disp('generating detailed_data...');
332  detailed_data=gen_detailed_data(model,model_data);
333  disp('generating reduced_data...');
334  reduced_data=gen_reduced_data(model,detailed_data);
335  disp('doing a reduced simulation');
336  rb_sim_data=rb_simulation(model,reduced_data);
337  disp('rb_reconstruction...');
338  rb_sim_data=rb_reconstruction(model,detailed_data,rb_sim_data);
339 
340  %comparison
341  comparison_sim_data = sim_data;
342  comparison_sim_data.uh=copy(sim_data.uh); %need to copy the fdf-class uh seperatly
343  comparison_sim_data.uh.dofs = sim_data.uh.dofs-rb_sim_data.uh.dofs;
344 
345  %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
346  figure(1);
347  disp('plotting the detailed solution...')
348  plot_sim_data(model,model_data,sim_data,1);
349  title('FEM-Solution on reference domain');
350 
351  figure(2);
352  disp('plotting the reduced solution...')
353 
354  plot_sim_data(model,model_data,rb_sim_data,1);
355  title('RB-Solution on reference domain');
356 
357  figure(3);
358  disp('plotting comparison...')
359  plot_sim_data(model,model_data,comparison_sim_data,1);
360  title('RB-Comparison (FEM-RB)');
361 
362  res = {rb_sim_data, sim_data};
363  disp('porsche_script step 30 complete! Inspect workspace...')
364  keyboard
365 
366  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
367  case 31 % Comparison of detailed and RB-solution of the original car
368  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369  disp('====================================================================')
370  disp(' Comparison between detailed an RB-simulation with the original car ')
371  disp('====================================================================')
372 
373  %%%%%%%%%%%%%%% initialize model %%%%%%%%%%%%%%%%%%%
374  disp('Setting the model...');
375  model=porsche_model;
376  disp('generating model_data');
377  model_data=gen_model_data(model);
378 
379 
380  %%%%%%%%%%%% calculate RB-data %%%%%%%%%%%%%%
381  disp('generating detailed_data...');
382  detailed_data=gen_detailed_data(model,model_data);
383  disp('generating reduced_data...');
384  reduced_data=gen_reduced_data(model,detailed_data);
385 
386  %reset the mus
387  mu_mod=[0,30];
388  model=change_mu(model, mu_mod);
389 
390  %%%%%%%%% Detailed Simulation %%%%%%%%%%%
391  disp('doing a detailed_simulation...');
392  sim_data = detailed_simulation(model,model_data);
393  %%%%%%%%%%%%% RB-Simulation %%%%%%%%%%%%%
394  disp('doing a reduced simulation');
395  rb_sim_data=rb_simulation(model,reduced_data);
396  disp('rb_reconstruction...');
397  rb_sim_data=rb_reconstruction(model,detailed_data,rb_sim_data);
398 
399  %comparison
400  comparison_sim_data = sim_data;
401  comparison_sim_data.uh=copy(sim_data.uh); %need to copy the fdf-class uh seperatly
402  comparison_sim_data.uh.dofs = sim_data.uh.dofs-rb_sim_data.uh.dofs;
403 
404  %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
405  figure(1);
406  disp('plotting the detailed solution...')
407  plot_sim_data(model,model_data,sim_data,2);
408  title('FEM-Solution on original domain');
409 
410  figure(2);
411  disp('plotting the reduced solution...')
412  plot_sim_data(model,model_data,rb_sim_data,2);
413  title('RB-Solution on original domain');
414 
415  figure(3);
416  disp('plotting comparison...')
417  plot_sim_data(model,model_data,comparison_sim_data,2);
418  title('RB-Comparison (FEM-RB)');
419 
420  res = {rb_sim_data, sim_data};
421  disp('porsche_script step 31 complete! Inspect workspace...')
422  keyboard
423 
424 
425  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426  %%%% OPTIMIZATION %%%%
427  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 
429  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430  case 40 % Detailed Optimization
431  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
432  disp('==================================')
433  disp(' Detailed Optimization ')
434  disp('==================================')
435 
436  disp('---')
437  disp('setting the model... (hit RETURN to continue)');
438  pause
439  model=porsche_model;
440  disp('...done');
441  disp('---')
442  disp('generating model_data...(hit RETURN to continue)');
443  pause
444  model_data=gen_model_data(model);
445  disp('...done');
446  disp('---')
447  % optimization parameters
448  model.optimization.constraint_circle_midpoint = [176.1103;161.1864];
449  model.optimization.constraint_circle_radius = 10;
450  mu_start=[178.06;151.38];
451  model=set_mu(model,mu_start);
452 
453  disp('optimization with SQP... (CAREFUL: This can take a while!!! Hit RETURN to continue)')
454  pause
455  model.optimization.opt_mode='detailed';
456  J_mu_0 = model.optimization.objective_function(model,model_data);
457  opt_data=SQP_algorithm(model,model_data);
458  res=opt_data;
459  disp('...done');
460  disp('---')
461  disp('plotting the iterates... (hit RETURN to continue)')
462  pause
463  figure(1)
464  plot(opt_data.mu_k(1,:),opt_data.mu_k(2,:),'--bs','LineWidth',2,...
465  'MarkerEdgeColor','r',...
466  'MarkerFaceColor','w',...
467  'MarkerSize',5)
468  title('Detailed Optimization, N=9 mu_0=[178.06;151.38]')
469  disp('...done');
470  disp('---')
471 
472 
473  disp('-----------------------------------------')
474  disp(' some information about the optimization ')
475  disp('-----------------------------------------')
476  disp(['mu_0 = (',num2str(mu_start(1)),', ', num2str(mu_start(2)),')'])
477  disp(['mu_opt = (', num2str(opt_data.mu_opt(1)), ', ', num2str(opt_data.mu_opt(2)),')'])
478  disp(['J(0) = ', num2str(J_mu_0, '%10.5e\n')])
479  disp(['J(mu_opt) = ', num2str(opt_data.obj_function, '%10.5e\n')])
480  disp(['nr_iterations : ', num2str(opt_data.nr_iterations)])
481  disp(['time online : ', num2str(opt_data.time_elapsed),' sec'])
482  disp('-----------------------------------------')
483 
484  disp('-----------------------------------------')
485  disp('porsche_script step 40 complete! Inspect workspace...')
486  keyboard
487 
488 
489 
490 
491  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
492  case 41 % RB Optimization N=9
493  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
494  disp('====================================')
495  disp(' Reduced Optimization N=9 ')
496  disp('====================================')
497 
498  disp('---')
499  disp('setting the model... (hit RETURN to continue)');
500  pause
501  model=porsche_model;
502  % optmization parameters
503  model.optimization.constraint_circle_midpoint = [176.1103;161.1864];
504  model.optimization.constraint_circle_radius = 10;
505  mu_start=[178.06;151.38];
506  model=set_mu(model,mu_start);
507  %setting 3 points in x- and y-direction for the basis --> N=9
508  midpoint_x=model.optimization.constraint_circle_midpoint(1);
509  midpoint_y=model.optimization.constraint_circle_midpoint(2);
510  snapshot_x=[midpoint_x-20, midpoint_x, midpoint_x+20];
511  snapshot_y=[midpoint_y-20, midpoint_y, midpoint_y+20];
512  snapshot_combination=createCombinations(snapshot_x, snapshot_y);
513  for k=1:size(snapshot_combination,2)
514  RB_mu_list{k} = snapshot_combination(:,k)';
515  end
516 
517  model.RB_mu_list=RB_mu_list;
518  disp('...done');
519  disp('---')
520  disp('generating model_data...(hit RETURN to continue)');
521  pause
522  model_data=gen_model_data(model);
523  disp('...done');
524  disp('---')
525  disp('generation of offline_data (hit RETURN to continue)')
526  pause
527  tic;
528  disp('...generating detailed_data...');
529  detailed_data=gen_detailed_data(model,model_data);
530  disp('...generating reduced_data...');
531  reduced_data=gen_reduced_data(model,detailed_data);
532  time_offline = toc;
533  disp('...done');
534  disp('---')
535 
536  disp('optimization with SQP... (hit RETURN to continue)')
537  pause
538  model.optimization.opt_mode='reduced';
539  J_mu_0 = model.optimization.objective_function(model,reduced_data);
540  opt_data=SQP_algorithm(model,reduced_data);
541  res=opt_data;
542  disp('...done');
543  disp('---')
544  disp('plotting the iterates... (hit RETURN to continue)')
545  pause
546  figure(2)
547  plot(opt_data.mu_k(1,:),opt_data.mu_k(2,:),'--bs','LineWidth',2,...
548  'MarkerEdgeColor','r',...
549  'MarkerFaceColor','w',...
550  'MarkerSize',5)
551  title('RB-Optimization, N=9 mu_0=[178.06;151.38]')
552  disp('...done');
553  disp('---')
554 
555 
556  disp('-----------------------------------------')
557  disp(' some information about the optimization ')
558  disp('-----------------------------------------')
559  disp(['mu_0 = (',num2str(mu_start(1)),', ', num2str(mu_start(2)),')'])
560  disp(['mu_opt = (', num2str(opt_data.mu_opt(1)), ', ', num2str(opt_data.mu_opt(2)),')'])
561  disp(['J(0) = ', num2str(J_mu_0, '%10.5e\n')])
562  disp(['J(mu_opt) = ', num2str(opt_data.obj_function, '%10.5e\n')])
563  disp(['nr_iterations : ', num2str(opt_data.nr_iterations)])
564  disp(['time online : ', num2str(opt_data.time_elapsed),' sec'])
565  disp(['time offline : ', num2str(time_offline),' sec'])
566  disp(['N : ', num2str(length(model.RB_mu_list))])
567  disp('-----------------------------------------')
568 
569  disp('-----------------------------------------')
570  disp('porsche_script step 41 complete! Inspect workspace...')
571  keyboard
572 
573 
574  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
575  case 42 % RB Optimization N=16
576  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577  disp('====================================')
578  disp(' Reduced Optimization N=16 ')
579  disp('====================================')
580 
581  disp('---')
582  disp('setting the model... (hit RETURN to continue)');
583  pause
584  model=porsche_model;
585  % optimization parameters
586  model.optimization.constraint_circle_midpoint = [176.1103;161.1864];
587  model.optimization.constraint_circle_radius = 10;
588  mu_start=[178.06;151.38];
589  model=set_mu(model,mu_start);
590  %setting 4 points in x- and y-direction for the basis --> N=16
591  x_min=model.optimization.constraint_circle_midpoint(1)-20;
592  x_max=model.optimization.constraint_circle_midpoint(1)+20;
593  y_min=model.optimization.constraint_circle_midpoint(2)-20;
594  y_max=model.optimization.constraint_circle_midpoint(2)+20;
595  snapshot_x=linspace(x_min,x_max,4);
596  snapshot_y=linspace(y_min,y_max,4);
597  snapshot_combination=createCombinations(snapshot_x, snapshot_y);
598  for k=1:size(snapshot_combination,2)
599  RB_mu_list{k} = snapshot_combination(:,k)';
600  end
601 
602  model.RB_mu_list=RB_mu_list;
603  disp('...done');
604  disp('---')
605  disp('generating model_data...(hit RETURN to continue)');
606  pause
607  model_data=gen_model_data(model);
608  disp('...done');
609  disp('---')
610  disp('generation of offline_data (hit RETURN to continue)')
611  pause
612  tic;
613  disp('...generating detailed_data...');
614  detailed_data=gen_detailed_data(model,model_data);
615  disp('...generating reduced_data...');
616  reduced_data=gen_reduced_data(model,detailed_data);
617  time_offline = toc;
618  disp('...done');
619  disp('---')
620 
621  disp('optimization with SQP... (hit RETURN to continue)')
622  pause
623  model.optimization.opt_mode='reduced';
624  J_mu_0 = model.optimization.objective_function(model,reduced_data);
625  opt_data=SQP_algorithm(model,reduced_data);
626  res=opt_data;
627  disp('...done');
628  disp('---')
629  disp('plotting the iterates... (hit RETURN to continue)')
630  pause
631  figure(2)
632  plot(opt_data.mu_k(1,:),opt_data.mu_k(2,:),'--bs','LineWidth',2,...
633  'MarkerEdgeColor','r',...
634  'MarkerFaceColor','w',...
635  'MarkerSize',5)
636  title('RB-Optimization, N=16 mu_0=[178.06;151.38]')
637  disp('...done');
638  disp('---')
639 
640 
641  disp('-----------------------------------------')
642  disp(' some information about the optimization ')
643  disp('-----------------------------------------')
644  disp(['mu_0 = (',num2str(mu_start(1)),', ', num2str(mu_start(2)),')'])
645  disp(['mu_opt = (', num2str(opt_data.mu_opt(1)), ', ', num2str(opt_data.mu_opt(2)),')'])
646  disp(['J(0) = ', num2str(J_mu_0, '%10.5e\n')])
647  disp(['J(mu_opt) = ', num2str(opt_data.obj_function, '%10.5e\n')])
648  disp(['nr_iterations : ', num2str(opt_data.nr_iterations)])
649  disp(['time online : ', num2str(opt_data.time_elapsed),' sec'])
650  disp(['time offline : ', num2str(time_offline),' sec'])
651  disp(['N : ', num2str(length(model.RB_mu_list))])
652  disp('-----------------------------------------')
653 
654  disp('-----------------------------------------')
655  disp('porsche_script step 42 complete! Inspect workspace...')
656  keyboard
657 
658 
659  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660  case 43 % RB Optimization N=25
661  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
662  disp('=====================================')
663  disp(' Reduced Optimization N=25 ')
664  disp('=====================================')
665 
666  disp('---')
667  disp('setting the model... (hit RETURN to continue)');
668  pause
669  model=porsche_model;
670  % optimization parameters
671  model.optimization.constraint_circle_midpoint = [176.1103;161.1864];
672  model.optimization.constraint_circle_radius = 10;
673  mu_start=[178.06;151.38];
674  model=set_mu(model,mu_start);
675  %setting 5 points in x- and y-direction for the basis --> N=25
676  midpoint_x=model.optimization.constraint_circle_midpoint(1);
677  midpoint_y=model.optimization.constraint_circle_midpoint(2);
678  snapshot_x=[midpoint_x-40, midpoint_x-20, midpoint_x, midpoint_x+20, midpoint_x+40];
679  snapshot_y=[midpoint_y-40, midpoint_y-20, midpoint_y, midpoint_y+20, midpoint_y+40];
680  snapshot_combination=createCombinations(snapshot_x, snapshot_y);
681  for k=1:size(snapshot_combination,2)
682  RB_mu_list{k} = snapshot_combination(:,k)';
683  end
684  model.RB_mu_list=RB_mu_list;
685  disp('...done');
686  disp('---')
687 
688  disp('generating model_data...(hit RETURN to continue)');
689  pause
690  model_data=gen_model_data(model);
691  disp('...done');
692  disp('---')
693  disp('generation of offline_data (hit RETURN to continue)')
694  pause
695  tic;
696  disp('...generating detailed_data...');
697  detailed_data=gen_detailed_data(model,model_data);
698  disp('...generating reduced_data...');
699  reduced_data=gen_reduced_data(model,detailed_data);
700  time_offline = toc;
701  disp('...done');
702  disp('---')
703 
704  disp('optimization with SQP... (hit RETURN to continue)')
705  pause
706  model.optimization.opt_mode='reduced';
707  J_mu_0 = model.optimization.objective_function(model,reduced_data);
708  opt_data=SQP_algorithm(model,reduced_data);
709  res=opt_data;
710  disp('...done');
711  disp('---')
712  disp('plotting the iterates... (hit RETURN to continue)')
713  pause
714  figure(2)
715  plot(opt_data.mu_k(1,:),opt_data.mu_k(2,:),'--bs','LineWidth',2,...
716  'MarkerEdgeColor','r',...
717  'MarkerFaceColor','w',...
718  'MarkerSize',5)
719  title('RB-Optimization, N=25 mu_0=[178.06;151.38]')
720  disp('...done');
721  disp('---')
722 
723 
724  disp('-----------------------------------------')
725  disp(' some information about the optimization ')
726  disp('-----------------------------------------')
727  disp(['mu_0 = (',num2str(mu_start(1)),', ', num2str(mu_start(2)),')'])
728  disp(['mu_opt = (', num2str(opt_data.mu_opt(1)), ', ', num2str(opt_data.mu_opt(2)),')'])
729  disp(['J(0) = ', num2str(J_mu_0, '%10.5e\n')])
730  disp(['J(mu_opt) = ', num2str(opt_data.obj_function, '%10.5e\n')])
731  disp(['nr_iterations : ', num2str(opt_data.nr_iterations)])
732  disp(['time online : ', num2str(opt_data.time_elapsed),' sec'])
733  disp(['time offline : ', num2str(time_offline),' sec'])
734  disp(['N : ', num2str(length(model.RB_mu_list))])
735  disp('-----------------------------------------')
736 
737  disp('-----------------------------------------')
738  disp('porsche_script step 43 complete! Inspect workspace...')
739  keyboard
740 
741 
742 
743  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
744  case 44 % Comparison of detailed and RB Optimization
745  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
746  disp('==============================================')
747  disp(' Comparison of detailed and RB optimization ')
748  disp('==============================================')
749 
750  disp('---')
751  disp('setting the model... (hit RETURN to continue)');
752  pause
753  model=porsche_model;
754  disp('...done');
755  disp('---')
756  disp('generating model_data...(hit RETURN to continue)');
757  pause
758  model_data=gen_model_data(model);
759  %%% optimization parameters %%%
760  model.optimization.constraint_circle_midpoint = [176.1103;161.1864];
761  model.optimization.constraint_circle_radius = 10;
762  mu_start=[178.06;151.38];
763 
764 
765  midpoint_x=model.optimization.constraint_circle_midpoint(1);
766  midpoint_y=model.optimization.constraint_circle_midpoint(2);
767  model=set_mu(model,mu_start);
768  disp('...done');
769  disp('---')
770 
771 
772  %---------------------
773  %------ detailed -----
774  %---------------------
775  disp('detailed optimization with SQP... (CAREFUL! This can take a while!!! Hit RETURN to continue)')
776  pause
777  model.optimization.opt_mode='detailed';
778  J_mu_0_det = model.optimization.objective_function(model,model_data);
779  opt_data_detailed=SQP_algorithm(model,model_data);
780  disp('...done');
781  disp('---')
782 
783  %----------------------
784  %------- N9 -----------
785  %----------------------
786  disp('N=9: generation of offline_data (hit RETURN to continue)')
787  pause
788 
789  snapshot_x_N9=[midpoint_x-20, midpoint_x, midpoint_x+20];
790  snapshot_y_N9=[midpoint_y-20, midpoint_y, midpoint_y+20];
791  snapshot_combination_N9=createCombinations(snapshot_x_N9, snapshot_y_N9);
792  for k=1:size(snapshot_combination_N9,2)
793  RB_mu_list_N9{k} = snapshot_combination_N9(:,k)';
794  end
795  model.RB_mu_list=RB_mu_list_N9;
796  tic;
797  disp('N=9: ...generating detailed_data...');
798  detailed_data_N9=gen_detailed_data(model,model_data);
799  disp('N=9: ...generating reduced_data...');
800  reduced_data_N9=gen_reduced_data(model,detailed_data_N9);
801  time_offline_N9 = toc;
802  disp('...done');
803  disp('---')
804  disp('N=9: RB optimization with SQP... (hit RETURN to continue)')
805  pause
806  model.optimization.opt_mode='reduced';
807  J_mu_0_red_N9 = model.optimization.objective_function(model,reduced_data_N9);
808  opt_data_red_N9 = SQP_algorithm(model,reduced_data_N9);
809  disp('...done');
810  disp('---')
811 
812 
813  %----------------------
814  %------- N16 ----------
815  %----------------------
816  disp('N=16: generation of offline_data (hit RETURN to continue)')
817  pause
818  x_min_N16=model.optimization.constraint_circle_midpoint(1)-20;
819  x_max_N16=model.optimization.constraint_circle_midpoint(1)+20;
820  y_min_N16=model.optimization.constraint_circle_midpoint(2)-20;
821  y_max_N16=model.optimization.constraint_circle_midpoint(2)+20;
822  snapshot_x_N16=linspace(x_min_N16,x_max_N16,4);
823  snapshot_y_N16=linspace(y_min_N16,y_max_N16,4);
824  snapshot_combination_N16=createCombinations(snapshot_x_N16, snapshot_y_N16);
825  for k=1:size(snapshot_combination_N16,2)
826  RB_mu_list_N16{k} = snapshot_combination_N16(:,k)';
827  end
828  model.RB_mu_list=RB_mu_list_N16;
829  tic;
830  disp('N=16: ...generating detailed_data...');
831  detailed_data_N16=gen_detailed_data(model,model_data);
832  disp('N=16: ...generating reduced_data...');
833  reduced_data_N16=gen_reduced_data(model,detailed_data_N16);
834  time_offline_N16 = toc;
835  disp('...done');
836  disp('---')
837  disp('N=16: RB optimization with SQP... (hit RETURN to continue)')
838  pause
839  model.optimization.opt_mode='reduced';
840  J_mu_0_red_N16 = model.optimization.objective_function(model,reduced_data_N16);
841  opt_data_red_N16 = SQP_algorithm(model,reduced_data_N16);
842  disp('...done');
843  disp('---')
844  %----------------------
845  %------- N25 ----------
846  %----------------------
847  disp('N=25: generation of offline_data (hit RETURN to continue)')
848  pause
849 
850  snapshot_x_N25=[midpoint_x-40, midpoint_x-20, midpoint_x, midpoint_x+20, midpoint_x+40];
851  snapshot_y_N25=[midpoint_y-40, midpoint_y-20, midpoint_y, midpoint_y+20, midpoint_y+40];
852  snapshot_combination_N25=createCombinations(snapshot_x_N25, snapshot_y_N25);
853  for k=1:size(snapshot_combination_N25,2)
854  RB_mu_list_N25{k} = snapshot_combination_N25(:,k)';
855  end
856  model.RB_mu_list=RB_mu_list_N25;
857 
858  tic;
859  disp('N=25: ...generating detailed_data...');
860  detailed_data_N25=gen_detailed_data(model,model_data);
861  disp('N=25: ...generating reduced_data...');
862  reduced_data_N25=gen_reduced_data(model,detailed_data_N25);
863  time_offline_N25 = toc;
864  disp('...done');
865  disp('---')
866 
867  disp('N=25: RB optimization with SQP... (hit RETURN to continue)')
868  pause
869  model.optimization.opt_mode='reduced';
870  J_mu_0_red_N25 = model.optimization.objective_function(model,reduced_data_N25);
871  opt_data_red_N25 = SQP_algorithm(model,reduced_data_N25);
872  disp('...done');
873  disp('---')
874 
875  %-------------------------
876 
877  res={opt_data_detailed,opt_data_red_N9,opt_data_red_N16,opt_data_red_N25}; %setting the returning variable
878 
879  %plotting the iterates
880  disp('plotting the iterates... (hit RETURN to continue)')
881  pause
882  figure(1)
883  plot(opt_data_detailed.mu_k(1,:),opt_data_detailed.mu_k(2,:),'-rs','LineWidth',2,...
884  'MarkerEdgeColor','r',...
885  'MarkerFaceColor','w',...
886  'MarkerSize',5)
887  hold on
888  plot(opt_data_red_N9.mu_k(1,:),opt_data_red_N9.mu_k(2,:),'--cs','LineWidth',2,...
889  'MarkerEdgeColor','c',...
890  'MarkerFaceColor','w',...
891  'MarkerSize',5)
892  plot(opt_data_red_N16.mu_k(1,:),opt_data_red_N16.mu_k(2,:),'-.gs','LineWidth',2,...
893  'MarkerEdgeColor','g',...
894  'MarkerFaceColor','w',...
895  'MarkerSize',5)
896  plot(opt_data_red_N25.mu_k(1,:),opt_data_red_N25.mu_k(2,:),'--bs','LineWidth',2,...
897  'MarkerEdgeColor','b',...
898  'MarkerFaceColor','w',...
899  'MarkerSize',5)
900  legend('detailed', 'reduced, N=9', 'reduced, N=16','reduced, N=25','Location','NorthWest')
901  disp('...done');
902  disp('---')
903 
904  %calculating and plotting the error
905  disp('plotting the error... (hit RETURN to continue)')
906  pause
907  k_det = opt_data_detailed.nr_iterations;
908  k_red_N9 = opt_data_red_N9.nr_iterations;
909  k_red_N16 = opt_data_red_N16.nr_iterations;
910  k_red_N25 = opt_data_red_N25.nr_iterations;
911  k_min_N9= min(k_det,k_red_N9);
912  k_min_N16= min(k_det,k_red_N16);
913  k_min_N25= min(k_det,k_red_N25);
914  % calculating error N9
915  differenz_mu_N9(:,1:k_min_N9) = opt_data_red_N9.mu_k(:,1:k_min_N9) - opt_data_detailed.mu_k(:,1:k_min_N9);
916  for k=1:k_min_N9
917  norm_diff_N9(k)=norm(differenz_mu_N9(:,k));
918  end
919  % calculating error N16
920  differenz_mu_N16(:,1:k_min_N16) = opt_data_red_N16.mu_k(:,1:k_min_N16) - opt_data_detailed.mu_k(:,1:k_min_N16);
921  for k=1:k_min_N16
922  norm_diff_N16(k)=norm(differenz_mu_N16(:,k));
923  end
924  % calculating error N25
925  differenz_mu_N25(:,1:k_min_N25) = opt_data_red_N25.mu_k(:,1:k_min_N25) - opt_data_detailed.mu_k(:,1:k_min_N25);
926  for k=1:k_min_N25
927  norm_diff_N25(k)=norm(differenz_mu_N25(:,k));
928  end
929 
930  % plot of the error
931  figure(2)
932  plot_achse_N9=0:1:k_min_N9-1;
933  plot_achse_N16=0:1:k_min_N16-1;
934  plot_achse_N25=0:1:k_min_N25-1;
935 
936  plot(plot_achse_N9,norm_diff_N9,'c')
937  hold on
938  plot(plot_achse_N16,norm_diff_N16,'g')
939  plot(plot_achse_N25,norm_diff_N25,'b')
940  legend('reduced, N=16', 'reduced, N=9','reduced, N=25')
941  title('Error');
942  xlabel('k');
943  disp('...done');
944  disp('---')
945 
946  % displaying information about the optimization
947  disp('-----------------------------------------')
948  disp(' some information about the optimization ')
949  disp('-----------------------------------------')
950  disp(['mu_0 = (',num2str(mu_start(1)),' , ', num2str(mu_start(2)),')'])
951 
952  disp(['mu_opt_detailed = (', num2str(opt_data_detailed.mu_opt(1)), ', ', num2str(opt_data_detailed.mu_opt(2)),')'])
953  disp(['mu_opt_red_N9 = (', num2str(opt_data_red_N9.mu_opt(1)), ', ', num2str(opt_data_red_N9.mu_opt(2)),')'])
954  disp(['mu_opt_red_N16 = (', num2str(opt_data_red_N16.mu_opt(1)), ', ', num2str(opt_data_red_N16.mu_opt(2)),')'])
955  disp(['mu_opt_red_N25 = (', num2str(opt_data_red_N25.mu_opt(1)), ', ', num2str(opt_data_red_N25.mu_opt(2)),')'])
956  disp('-----------------------------------------')
957  disp(['J_det(mu_0) = ', num2str(J_mu_0_det, '%10.5e\n')])
958  disp(['J_red_N9(mu_0) = ', num2str(J_mu_0_red_N9, '%10.5e\n')])
959  disp(['J_red_N16(mu_0) = ', num2str(J_mu_0_red_N16, '%10.5e\n')])
960  disp(['J_red_N25(mu_0) = ', num2str(J_mu_0_red_N25, '%10.5e\n')])
961  disp('-----------------------------------------')
962  disp(['J_det(mu_opt) = ', num2str(opt_data_detailed.obj_function, '%10.5e\n')])
963  disp(['J_red_N9(mu_opt) = ', num2str(opt_data_red_N9.obj_function, '%10.5e\n')])
964  disp(['J_red_N16(mu_opt) = ', num2str(opt_data_red_N16.obj_function, '%10.5e\n')])
965  disp(['J_red_N25(mu_opt) = ', num2str(opt_data_red_N25.obj_function, '%10.5e\n')])
966  disp('-----------------------------------------')
967  disp(['nr_iterations_det : ', num2str(opt_data_detailed.nr_iterations)])
968  disp(['nr_iterations_red_N9 : ', num2str(opt_data_red_N9.nr_iterations)])
969  disp(['nr_iterations_red_N16 : ', num2str(opt_data_red_N16.nr_iterations)])
970  disp(['nr_iterations_red_N25 : ', num2str(opt_data_red_N25.nr_iterations)])
971  disp('-----------------------------------------')
972  disp(['time_online_det : ', num2str(opt_data_detailed.time_elapsed),' sec'])
973  disp(['time_online_red_N9 : ', num2str(opt_data_red_N9.time_elapsed),' sec'])
974  disp(['time_online_red_N16 : ', num2str(opt_data_red_N16.time_elapsed),' sec'])
975  disp(['time_online_red_N25 : ', num2str(opt_data_red_N25.time_elapsed),' sec'])
976  disp('-----------------------------------------')
977  disp(['time offline N9 : ', num2str(time_offline_N9),' sec'])
978  disp(['time offline N16 : ', num2str(time_offline_N16),' sec'])
979  disp(['time offline N25 : ', num2str(time_offline_N25),' sec'])
980  disp('-----------------------------------------')
981  disp('-----------------------------------------')
982 
983 
984  disp('porsche_script step 44 complete! Inspect workspace...')
985  keyboard
986 
987  otherwise
988  error('unknown step number');
989 end;
function comb = createCombinations(ranges, varargin)
Creates the cartesian product of the vectors passed as a matrix containing elements of each vector pe...
function p = plot_sim_data(model, model_data, sim_data, plot_params)
function performing the plot of the simulation results as specified in model.
Definition: plot_sim_data.m:17