rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
porsche_model.m
1 function model = porsche_model(params)
2 %function model = porsche_model(params)
3 %
4 % model of a Porsche Turbo
5 % (the geometry information is described as polygonial of k points)
6 %
7 %
8 % Oliver Zeeb, 28.01.11
9 
10 
11 %% ===================================
12 % general information
13 % ====================================
14 if nargin == 0
15  params = [];
16 end;
17 
18 if ~isfield(params,'pdeg')
19  params.pdeg = 1; % polynomial degree
20 end;
21 
22 if ~isfield(params,'qdeg')
23  params.qdeg = 2; % quadrature degree
24 end;
25 
26 model = [];
27 model.verbose = 1;
28 model.debug = 0;
29 model.rb_problem_type = 'lin_stat';
30 model.compute_output_functional = 1; % turn on computation of output
31 model.plot_sim_data=@porsche_plot;
32 
33 %% ================================
34 % Settings for the PDE
35 % --> Needed for FEM
36 % =================================
37 % if any of the following flags is set, the corresponding function
38 % pointers must be provided below.
39 model.has_source = 0; % f=0
40 model.has_reaction = 0;
41 model.has_advection = 0;
42 model.has_diffusivity = 1;
43 model.has_output_functional = 1;
44 model.has_dirichlet_values = 1;
45 model.has_neumann_values = 1;
46 model.has_robin_values = 0;
47 
48 model.diffusivity_tensor_coefficients=@porsche_diffusivity_tensor_coefficients;
49 model.diffusivity_tensor_components=@porsche_diffusivity_tensor_components;
50 model.diffusivity_tensor = @(glob,params) ...
51  eval_affine_decomp_general(model.diffusivity_tensor_components, ...
52  model.diffusivity_tensor_coefficients, glob,params);
53 %model.diffusivity_gradient = @(glob,params) zeros(size(glob,1),2);
54 model.dirichlet_coefficients = @(glob,params) 1;
55 model.dirichlet_components = @(glob,params) {zeros(size(glob,1),1)};
56 model.dirichlet_values = @(glob, params) ...
57  eval_affine_decomp_general(model.dirichlet_components, ...
58  model.dirichlet_coefficients,glob,params);
59 model.neumann_coefficients = @(glob,params) 1;
60 model.neumann_components = @porsche_neumann_components;
61 model.neumann_values = @(glob,params) ...
62  eval_affine_decomp_general(model.neumann_components,...
63  model.neumann_coefficients, glob,params);
64 
65 model.pdeg = params.pdeg; % degree of polynomial functions
66 model.qdeg = params.qdeg; % quadrature degree
67 model.dimrange = 1; % scalar solution
68 model.operators = @fem_operators;
69 
70 %% ==================================================================
71 %================== Information about the car =======================
72 %====================================================================
73 model.speed = -100; % speed of the car
74 model.xrange = [0, 750];
75 model.yrange = [0, 300];
76 xmin = model.xrange(1);
77 xmax = model.xrange(2);
78 ymin = model.yrange(1);
79 ymax = model.yrange(2);
80 
81 spline_data = load('porsche_turbo_300pts.mat');
82 cp = spline_data.car_spline_pts;
83 model.cp = cp; % cp=Car_Points
84 clear('spline_data');
85 
86 macro_cp_indx = [1,116,138,172,199,247,276]; %indices for the macro model
87 macro_cp=model.cp(macro_cp_indx,:); %points of the macro model
88 model.nr_macro_car_points=length(macro_cp_indx);
89 
90 % macro-triangulation points on the boundary
91 pmacro_boundary = ... % points on the boundary of the macro triangulation
92  [xmax, ymin; ... % punkt 8
93  macro_cp(1,1), ymin; ... % punkt 9; cp(index of macro_car_point, x=1 or y=2)
94  macro_cp(2,1), ymin; ... % punkt 10
95  xmin, ymin; ... % punkt 11
96  xmin, macro_cp(2,2); ... % punkt 12
97  xmin, macro_cp(3,2); ... % punkt 13
98  xmin, ymax; ... % punkt 14
99  macro_cp(3,1), ymax; ... % punkt 15
100  macro_cp(4,1), ymax; ... % punkt 16
101  macro_cp(5,1), ymax; ... % punkt 17
102  macro_cp(6,1), ymax; ... % punkt 18
103  xmax, ymax; ... % punkt 19
104  xmax, macro_cp(6,2); ... % punkt 20
105  xmax, macro_cp(7,2); ... % punkt 21
106  xmax, macro_cp(1,2)]; % punkt 22
107 
108 % all points of the macro-grid: (7 car points + 15 boundary points)
109 pmacro = [macro_cp; pmacro_boundary];
110 
111 % Triangles of the macro-triangulation
112 tmacro = [9,8,1; ... % triangle 1
113  10,9,1; ... % triangle 2
114  10,1,2; ... % triangle 3
115  11,10,2; ... % triangle 4
116  11,2,12; ... % triangle 5
117  12,2,13; ... % triangle 6
118  2,3,13; ... % triangle 7
119  13,3,14; ... % triangle 8
120  3,15,14; ... % triangle 9
121  3,4,15; ... % triangle 10
122  4,16,15; ... % triangle 11
123  4,5,16; ... % triangle 12
124  5,17,16; ... % triangle 13
125  5,18,17; ... % triangle 14
126  6,18,5; ... % triangle 15
127  6,19,18; ... % triangle 16
128  6,20,19; ... % triangle 17
129  7,20,6; ... % triangle 18
130  7,21,20; ... % triangle 19
131  22,21,7; ... % triangle 20
132  1,22,7; ... % triangle 21
133  8,22,1]; % triangle 22
134 
135 model.pmacro = pmacro;
136 model.tmacro = tmacro;
137 model.gridtype = 'triagrid';
138 
139 %set rectangulars for defininiton of the boundary conditions:
140 model.bnd_rect_corner1 = [xmax-0.1, xmin-0.1, xmin-0.1, xmin-0.1, xmin+0.1; ...
141  ymin-0.1, ymin+0.1, ymin-0.1, ymax-0.1, ymin+0.1];
142 model.bnd_rect_corner2 = [xmax+0.1, xmin+0.1, xmax+0.1, xmax+0.1, xmax-0.1; ...
143  ymax+0.1, ymax-0.1, ymin+0.1, xmax+0.1, ymax-0.1];
144 model.bnd_rect_index = [-1,-2,-2,-2,-2];
145 % Gamma_out, Gamma_in, Gamma_bot, Gamma_up, Gamma_int
146 % Dirichlet (right part), Neumann (left part), 0-Neumann (lower part), 0-Neumann (upper part), 0-Neumann (inner part)
147 
148 model.use_saved_pet_for_model_data = 1; % 1 if grid data shall be loaded
149  % from porsche_turbo_p_e_t_microgrid
150 model.gen_model_data = @porsche_gen_model_data;
151 model.gen_detailed_data = @porsche_gen_detailed_data;
152 model.gen_reduced_data = @porsche_gen_reduced_data;
153 model.detailed_simulation = @porsche_detailed_simulation;
154 
155 model.output_functional = @porsche_output_functional; % detailed output-functional
156 model.get_dofs_from_sim_data = @(sim_data) sim_data.uh.dofs;
157 model.get_inner_product_matrix = @(detailed_data) ...
158  detailed_data.df_info.regularized_h10_inner_product_matrix;
159 model.get_estimators_from_sim_data= @(sim_data) sim_data.Delta;
160 
161 
162 %% ==================================================================
163 %================== Reduced Basis Settings ==========================
164 %====================================================================
165 model.RB_generation_mode = 'lagrangian';
166 model.set_rb_in_detailed_data=@lin_stat_set_rb_in_detailed_data;
167 model.get_rb_size= @(model,detailed_data) size(detailed_data.RB,2);
168 
169 model.decomp_mode = 0;
170 model.rb_simulation=@porsche_rb_simulation;
171 model.rb_reconstruction=@lin_stat_rb_reconstruction;
172 
173 model.x1 = macro_cp(1,1);
174 model.x2 = macro_cp(2,1);
175 model.x3 = macro_cp(3,1);
176 model.x4 = macro_cp(4,1);
177 model.x5 = macro_cp(5,1);
178 model.x6 = macro_cp(6,1);
179 model.x7 = macro_cp(7,1);
180 model.y1 = macro_cp(1,2);
181 model.y2 = macro_cp(2,2);
182 model.y3 = macro_cp(3,2);
183 model.y4 = macro_cp(4,2);
184 model.y5 = macro_cp(5,2);
185 model.y6 = macro_cp(6,2);
186 model.y7 = macro_cp(7,2);
187 
188 model.mu_names = {'x3', 'y3'};
189 %model.mu_names = {'x3', 'y3', 'x4', 'y4', 'x5', 'y5'};
190 
191 model.mu_ranges = my_mu_ranges(macro_cp, model.mu_names);
192 model.RB_mu_list = my_RB_mu_list(model.mu_names, model.mu_ranges);
193 
194 model.set_mu = @set_mu_default;
195 model.get_mu = @get_mu_default;
196 model.use_scm = 0;
197 
198 model.coercivity_alpha = @porsche_coercivity_alpha;
199 model.operators_output = @porsche_operators_output; % reduced output calculation
200 
201 %% ==================================================================
202 %================== Optimization Settings ===========================
203 %====================================================================
204 model.optimization.opt_mode = 'reduced'; % or 'detailed'
205 model.optimization.derivatives_available = 0; % 1 if the derivatives are available after a simulation, this ist not the case for porsche_model!
206 model.compute_derivative_info = 1;
207 model.optimization.nr_constraints = 1; %= length(model.mu_names)/2;
208 model.optimization.init_param=set_optimization_init_param(model);
209 model.optimization.params_to_optimize = ones(1,length(model.mu_names));
210 model.optimization.objective_function = @porsche_objective_function;
211 model.optimization.get_Jacobian = @porsche_get_Jacobian;
212 model.optimization.get_Hessian = @porsche_get_Hessian_J;
213 % model.optimization.get_Hes_Lag = @porsche_get_Hes_Lag;
214 % model.optimization.get_Hessian_eq_constr = @porsche_get_Hessian_eq_constr;
215 % model.optimization.get_eq_constr = @porsche_get_eq_constr;
216 % model.optimization.get_grad_eq_constr = @porsche_get_grad_eq_constr;
217 model.optimization.get_Hes_Lag = @porsche_circle_x3_y3_get_Hes_Lag;
218 model.optimization.get_Hessian_eq_constr = @porsche_circle_x3_y3_get_Hessian_eq_constr;
219 model.optimization.get_eq_constr = @porsche_circle_x3_y3_get_eq_constr;
220 model.optimization.get_grad_eq_constr = @porsche_circle_x3_y3_get_grad_eq_constr;
221 model.optimization.constraint_circle_radius = 10;
222 model.optimization.constraint_circle_midpoint = [176.1103 ; 161.1864]; % sehr gute werte um auf mu_opt = mu_ref zu kommen
223 
224 % =============================================
225 % resetting global functions to local functions
226 % needed for FEM simulation
227 % see elliptic_discrete_model for details
228 model=elliptic_discrete_model(model);
229 % =============================================
230 end
231 
232 
233 %% ==================================================================
234 %================== auxiliary funxtions ============================
235 %====================================================================
236 function init_param=set_optimization_init_param(model)
237  init_param=zeros(1,length(model.mu_names));
238  for k=1:length(model.mu_names)
239  init_param(k) = model.(model.mu_names{k});
240  end
241 end
242 
243 
244 function mu_ranges = my_mu_ranges(macro_cp, mu_names)
245  mu_range_all.x1 = macro_cp(1,1) + [0 0]; % x1
246  mu_range_all.x2 = macro_cp(2,1) + [0 0]; % x2
247  mu_range_all.x3 = macro_cp(3,1) + [-20 20]; % x3
248  mu_range_all.x4 = macro_cp(4,1) + [-20 20]; % x4
249  mu_range_all.x5 = macro_cp(5,1) + [-30 30]; % x5
250  mu_range_all.x6 = macro_cp(6,1) + [0 0]; % x6
251  mu_range_all.x7 = macro_cp(7,1) + [0 0]; % x7
252  mu_range_all.y1 = macro_cp(1,2) + [0 0]; % y1
253  mu_range_all.y2 = macro_cp(2,2) + [0 0]; % y2
254  mu_range_all.y3 = macro_cp(3,2) + [-20 20]; % y3
255  mu_range_all.y4 = macro_cp(4,2) + [-20 20]; % y4
256  mu_range_all.y5 = macro_cp(5,2) + [-30 20]; % y5
257  mu_range_all.y6 = macro_cp(6,2) + [0 0]; % y6
258  mu_range_all.y7 = macro_cp(7,2) + [0 0]; % y7
259  for k=1:length(mu_names)
260  mu_ranges{k} = getfield(mu_range_all, mu_names{k});
261  end
262 end
263 
264 function RB_mu_list = my_RB_mu_list(mu_names, mu_ranges)
265 % old: 06.09.11
266 % for k=1:length(mu_names)
267 % lower_points(k) = mu_ranges{k}(1);
268 % upper_points(k) = mu_ranges{k}(2);
269 % middle_points(k) = (mu_ranges{k}(2) + mu_ranges{k}(1))/2;
270 % end
271 % RB_mu_list={lower_points, upper_points, middle_points};
272 
273  for k=1:length(mu_names)
274  model_mus{k}=[mu_ranges{k}(1), (mu_ranges{k}(1)+mu_ranges{k}(2))/2, mu_ranges{k}(2)];
275  end
276 
277  %create all combinations of this vector
278  combination_mus=createCombinations(model_mus);
279 
280  %setting RB_mu_list
281  RB_mu_list=[];
282  for k=1:size(combination_mus,2)
283  RB_mu_list{k} = combination_mus(:,k)';
284  end
285 
286 end
287 
288 
289 
290 
function comb = createCombinations(ranges, varargin)
Creates the cartesian product of the vectors passed as a matrix containing elements of each vector pe...
function local_model = elliptic_discrete_model(model)
function creating a model with local functions out of a model with global functions. See detailed description for explanation.
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