1 function res=porsche_script(step,varargin)
2 %
function res=porsche_script(step,varargin)
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
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
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
27 % Oliver Zeeb, 01.09.11
41 qdeg = 2 * pdeg; % quadrature_degree
44 params.no_plot = 0; %plotting active
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%% GRID FUNCTIONS %%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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);
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);
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 case 3 % plot microgrid elementwise
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 disp('==============================')
83 disp('plot the microgrid elementwise')
84 disp('==============================')
86 model = porsche_model;
87 model_data = gen_model_data(model);
89 microgrid = model_data.grid;
90 macrogrid = model_data.macrogrid;
91 mic2mac=micro2macro_map(microgrid,macrogrid);
93 for k=1:macrogrid.nelements
94 elids=find(mic2mac==k);
98 gridp=gridpart(model_data.grid,elids);
100 axis([0 750 -50 350])
102 disp(['Macrotriangle Nr', num2str(k)])
104 disp('press enter to continue')
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);
122 model = change_mu(model, mu_mod);
125 grid_reshaped = grid_reshape(model, model_data.grid);
128 disp('plotting the original grid')
132 title('original grid')
135 disp('plotting the reference grid')
137 plot(model_data.grid)
139 title('reference grid')
142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 %%%%%%%%%%%%% DETAILED SIMULATIONS %%%%%%%%%%%%%%%
144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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('==============================================')
154 %%%%%%%%%%%%%%% initialize model %%%%%%%%%%%%%%%%%%%
155 model = porsche_model(params);
156 model_data = gen_model_data(model);
158 % do an FEM-simulation
159 disp('calculating detailed simulation...')
160 sim_data = detailed_simulation(model,model_data);
163 %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
164 disp('plotting the PDE solution...')
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...')
174 disp('porsche_script step 10 complete! Inspect workspace...')
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 case 11 %do a FEM Simulation with the reshaped grid
180 %and plot the solution on the reshaped grid
181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 disp('=============================================')
184 disp(' FEM solution and plot of the original car ')
185 disp('=============================================')
187 %%%%%%%%%%%%%%% initialize model %%%%%%%%%%%%%%%%%%%
188 model = porsche_model;
189 model_data = gen_model_data(model);
193 model=change_mu(model, mu_mod);
195 disp('calculating detailed simulation...')
196 sim_data = detailed_simulation(model,model_data);
198 %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
199 disp('plotting the PDE solution...')
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...')
209 disp('porsche_script step 11 complete! Inspect workspace...')
214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 %%%%%%%%%%%%%%%%% RB SIMULATIONS %%%%%%%%%%%%%%%%%
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 case 20 % RB-Simulation of the reference car
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 disp('=============================================')
223 disp(' RB-Simulation of the reference car ')
224 disp('=============================================')
226 %%%%%%%%%%%%%%% initialize model %%%%%%%%%%%%%%%%%%%
227 disp('Setting the model...');
229 disp('generating model_data');
230 model_data=gen_model_data(model);
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);
244 %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
245 disp('plotting the PDE solution...')
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);
252 rb_sim_data.pressure=compute_pressure(model,rb_sim_data.gradx, rb_sim_data.grady);
253 disp('plotting the velocity and pressure...')
258 disp('porsche_script step 20 complete! Inspect workspace...')
262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 case 21 %do a RB-Simulation with the original grid
264 %and plot the solution on the original grid
265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
267 disp('=============================================')
268 disp(' RB-Simulation of the original car ')
269 disp('=============================================')
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);
282 model=change_mu(model, mu_mod);
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);
290 %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
291 disp('plotting the PDE solution...')
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...')
303 disp('porsche_script step 21 complete! Inspect workspace...')
308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 %%%% COMPARISON OF DETAILED AND RB SIMULATION %%%%
310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 case 30 % Comparison with the reference car
314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 disp('=====================================================================')
317 disp(' Comparison between detailed an RB-simulation with the reference car ')
318 disp('=====================================================================')
320 %%%%%%%%%%%%%%% initialize model %%%%%%%%%%%%%%%%%%%
321 disp('Setting the model...');
323 disp('generating model_data');
324 model_data=gen_model_data(model);
326 %%%%%%%%% Detailed Simulation %%%%%%%%%%%
327 disp('doing a detailed_simulation...');
328 sim_data = detailed_simulation(model,model_data);
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);
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;
345 %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
347 disp('plotting the detailed solution...')
349 title('FEM-Solution on reference domain');
352 disp('plotting the reduced solution...')
355 title('RB-Solution on reference domain');
358 disp('plotting comparison...')
360 title('RB-Comparison (FEM-RB)');
362 res = {rb_sim_data, sim_data};
363 disp(
'porsche_script step 30 complete! Inspect workspace...')
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('====================================================================')
373 %%%%%%%%%%%%%%% initialize model %%%%%%%%%%%%%%%%%%%
374 disp('Setting the model...');
376 disp('generating model_data');
377 model_data=gen_model_data(model);
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);
388 model=change_mu(model, mu_mod);
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);
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;
404 %%%%%%%%%%%%%%% plotting %%%%%%%%%%%%%%%%%%%
406 disp('plotting the detailed solution...')
408 title('FEM-Solution on original domain');
411 disp('plotting the reduced solution...')
413 title('RB-Solution on original domain');
416 disp('plotting comparison...')
418 title('RB-Comparison (FEM-RB)');
420 res = {rb_sim_data, sim_data};
421 disp(
'porsche_script step 31 complete! Inspect workspace...')
425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426 %%%% OPTIMIZATION %%%%
427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 case 40 % Detailed Optimization
431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
432 disp('==================================')
433 disp(' Detailed Optimization ')
434 disp('==================================')
437 disp('setting the model... (hit RETURN to continue)');
442 disp('generating model_data...(hit RETURN to continue)');
444 model_data=gen_model_data(model);
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);
453 disp('optimization with SQP... (CAREFUL: This can take a while!!! Hit RETURN to continue)')
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);
461 disp('plotting the iterates... (hit RETURN to continue)')
464 plot(opt_data.mu_k(1,:),opt_data.mu_k(2,:),'--bs','LineWidth',2,...
465 'MarkerEdgeColor','r',...
466 'MarkerFaceColor','w',...
468 title('Detailed Optimization, N=9 mu_0=[178.06;151.38]')
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('-----------------------------------------')
484 disp('-----------------------------------------')
485 disp('porsche_script step 40 complete! Inspect workspace...')
491 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
492 case 41 % RB Optimization N=9
493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
494 disp('====================================')
495 disp(' Reduced Optimization N=9 ')
496 disp('====================================')
499 disp('setting the model... (hit RETURN to continue)');
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];
513 for k=1:size(snapshot_combination,2)
514 RB_mu_list{k} = snapshot_combination(:,k)
';
517 model.RB_mu_list=RB_mu_list;
520 disp('generating model_data...(hit RETURN to
continue)
');
522 model_data=gen_model_data(model);
525 disp('generation of offline_data (hit RETURN to
continue)
')
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);
536 disp('optimization with SQP... (hit RETURN to
continue)
')
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);
544 disp('plotting the iterates... (hit RETURN to
continue)
')
547 plot(opt_data.mu_k(1,:),opt_data.mu_k(2,:),'--bs
','LineWidth
',2,...
548 'MarkerEdgeColor
','r
',...
549 'MarkerFaceColor
','w
',...
551 title('RB-Optimization, N=9 mu_0=[178.06;151.38]
')
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('-----------------------------------------
')
569 disp('-----------------------------------------
')
570 disp('porsche_script step 41 complete! Inspect workspace...
')
574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
575 case 42 % RB Optimization N=16
576 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
577 disp('====================================
')
578 disp(' Reduced Optimization N=16
')
579 disp('====================================
')
582 disp('setting the model... (hit RETURN to
continue)
');
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)';
602 model.RB_mu_list=RB_mu_list;
605 disp('generating model_data...(hit RETURN to continue)');
607 model_data=gen_model_data(model);
610 disp('generation of offline_data (hit RETURN to continue)')
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);
621 disp('optimization with SQP... (hit RETURN to continue)')
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);
629 disp('plotting the iterates... (hit RETURN to continue)')
632 plot(opt_data.mu_k(1,:),opt_data.mu_k(2,:),'--bs','LineWidth',2,...
633 'MarkerEdgeColor','r',...
634 'MarkerFaceColor','w',...
636 title('RB-Optimization, N=16 mu_0=[178.06;151.38]')
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('-----------------------------------------')
654 disp('-----------------------------------------')
655 disp('porsche_script step 42 complete! Inspect workspace...')
659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660 case 43 % RB Optimization N=25
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
662 disp('=====================================')
663 disp(' Reduced Optimization N=25 ')
664 disp('=====================================')
667 disp('setting the model... (hit RETURN to continue)');
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];
681 for k=1:size(snapshot_combination,2)
682 RB_mu_list{k} = snapshot_combination(:,k)
';
684 model.RB_mu_list=RB_mu_list;
688 disp('generating model_data...(hit RETURN to
continue)
');
690 model_data=gen_model_data(model);
693 disp('generation of offline_data (hit RETURN to
continue)
')
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);
704 disp('optimization with SQP... (hit RETURN to
continue)
')
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);
712 disp('plotting the iterates... (hit RETURN to
continue)
')
715 plot(opt_data.mu_k(1,:),opt_data.mu_k(2,:),'--bs
','LineWidth
',2,...
716 'MarkerEdgeColor
','r
',...
717 'MarkerFaceColor
','w
',...
719 title('RB-Optimization, N=25 mu_0=[178.06;151.38]
')
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('-----------------------------------------
')
737 disp('-----------------------------------------
')
738 disp('porsche_script step 43 complete! Inspect workspace...
')
743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
744 case 44 % Comparison of detailed and RB Optimization
745 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
746 disp('==============================================
')
747 disp(' Comparison of detailed and RB optimization
')
748 disp('==============================================
')
751 disp('setting the model... (hit RETURN to
continue)
');
756 disp('generating model_data...(hit RETURN to
continue)
');
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];
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);
772 %---------------------
773 %------ detailed -----
774 %---------------------
775 disp('detailed optimization with SQP... (CAREFUL! This can take a
while!!! Hit RETURN to
continue)
')
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);
783 %----------------------
784 %------- N9 -----------
785 %----------------------
786 disp('N=9: generation of offline_data (hit RETURN to
continue)
')
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)';
795 model.RB_mu_list=RB_mu_list_N9;
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;
804 disp('N=9: RB optimization with SQP... (hit RETURN to continue)')
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);
813 %----------------------
814 %------- N16 ----------
815 %----------------------
816 disp('N=16: generation of offline_data (hit RETURN to continue)')
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);
825 for k=1:size(snapshot_combination_N16,2)
826 RB_mu_list_N16{k} = snapshot_combination_N16(:,k)
';
828 model.RB_mu_list=RB_mu_list_N16;
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;
837 disp('N=16: RB optimization with SQP... (hit RETURN to
continue)
')
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);
844 %----------------------
845 %------- N25 ----------
846 %----------------------
847 disp('N=25: generation of offline_data (hit RETURN to
continue)
')
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)';
856 model.RB_mu_list=RB_mu_list_N25;
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;
867 disp('N=25: RB optimization with SQP... (hit RETURN to continue)')
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);
875 %-------------------------
877 res={opt_data_detailed,opt_data_red_N9,opt_data_red_N16,opt_data_red_N25}; %setting the returning variable
879 %plotting the iterates
880 disp(
'plotting the iterates... (hit RETURN to continue)')
883 plot(opt_data_detailed.mu_k(1,:),opt_data_detailed.mu_k(2,:),'-rs','LineWidth',2,...
884 'MarkerEdgeColor','r',...
885 'MarkerFaceColor','w',...
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',...
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',...
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',...
900 legend('detailed', 'reduced, N=9', 'reduced, N=16','reduced, N=25','Location','NorthWest')
904 %calculating and plotting the error
905 disp('plotting the error... (hit RETURN to continue)')
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);
917 norm_diff_N9(k)=norm(differenz_mu_N9(:,k));
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);
922 norm_diff_N16(k)=norm(differenz_mu_N16(:,k));
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);
927 norm_diff_N25(k)=norm(differenz_mu_N25(:,k));
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;
936 plot(plot_achse_N9,norm_diff_N9,'c')
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')
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)),')'])
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('-----------------------------------------')
984 disp('porsche_script step 44 complete! Inspect workspace...')
988 error('unknown step number');
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.