rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
porsche_gen_model_data.m
1 function model_data=porsche_gen_model_data(model)
2 %function model_data=porsche_gen_model_data(model)
3 %
4 % function generating a macro-triangulation
5 %
6 % needed fields of model:
7 % pmacro: n-by-2-vector of all the macro-points
8 % tmacro: m-by-3-vector of the points belonging to one macro-triangle
9 % cp: k-by-2-vector of all the carpoints (the model is described as
10 % polygonial of k points)
11 %
12 % Oliver Zeeb, 31.01.11
13 
14 tmacro = model.tmacro;
15 pmacro = model.pmacro;
16 cp=model.cp;
17 
18 
19 % Create macro-grid
20 % =================
21 macrogrid = triagrid(pmacro', tmacro',[]);
22 disp('created macrogrid...')
23 
24 
25 % Create micro-grid: (either with pdetoolbox or with presaved data)
26 % ==================
27 if model.use_saved_pet_for_model_data % In case of pre-saved p, e, t - data:
28  % microgrid can be obtained with
29  % these data.
30  load porsche_turbo_p_e_t_microgrid;
31  model_data.pdetoolbox_mesh.p = p;
32  model_data.pdetoolbox_mesh.e = e;
33  model_data.pdetoolbox_mesh.t = t;
34  disp('p, e, t, data loaded from porsche_turbo_p_e_t_microgrid.mat')
35 else % p, e, t data generated by pdetoolbox:
36  % initialize pdetoolbox
37  [pde_fig,ax]=pdeinit;
38  pdetool('appl_cb',1);
39  set(ax,'DataAspectRatio',[1 1 1]);
40  set(ax,'PlotBoxAspectRatio',[1.5 1 1]);
41  set(ax,'XLim',[-50 750]);
42  set(ax,'YLim',[-50 350]);
43  set(ax,'XTickMode','auto');
44  set(ax,'YTickMode','auto');
45 
46  %create the macro-triangles as defined in the model
47  for k=1:size(tmacro,1)
48  tria_pts = pmacro(tmacro(k,:),:); % points of the triangle
49  pdepoly(tria_pts(:,1), tria_pts(:,2), ['T',num2str(k)])
50  end
51 
52  % whole car:
53  pdepoly(cp(:,1),cp(:,2),'PorscheTurbo')
54 
55  %set area to: sum(triangles) - PorscheTurbo
56  set(findobj(get(pde_fig,'Children'),'Tag','PDEEval'),'String',...
57  '(T1+T2+T3+T4+T5+T6+T7+T8+T9+T10+T11+T12+T13+T14+T15+T16+T17+T18+T19+T20+T21+T22)-PorscheTurbo')
58 
59  % Mesh generation:
60  setappdata(pde_fig,'Hgrad',1.3);
61  setappdata(pde_fig,'refinemethod','regular');
62  setappdata(pde_fig,'jiggle',char('on','mean',''));
63  pdetool('initmesh')
64 
65  % Export grid from PDE-Toolbox by hand
66  disp('====================================================================')
67  disp('Please export the grid information from the pdetoolbox.')
68  disp('In the PDE Toolbox choose "Mesh" --> "Export Mesh..." and press "OK"')
69  disp('then continue by typing "dbcont"')
70  disp('====================================================================')
71  keyboard
72 
73  %PDE Toolbox exports mesh to the workspace, so usage of 'evalin' is needed
74  p = evalin('base', 'p');
75  e = evalin('base', 'e');
76  t = evalin('base', 't');
77 
78  model_data.pdetoolbox_mesh.p = p;
79  model_data.pdetoolbox_mesh.e = e;
80  model_data.pdetoolbox_mesh.t = t;
81 
82  evalin('base', 'clear p e t');
83  disp('p, e, t, data created and exported from pdetoolbox')
84 end
85 
86 microgrid = triagrid(p,t,[]);
87 microgrid = set_boundary_types(microgrid, model);
88 disp('created microgrid...')
89 df_info = feminfo(model,microgrid);
90 
91 
92 % Setting grid and dfinfo in the model_data
93 % =========================================
94 model_data.grid=microgrid;
95 model_data.macrogrid=macrogrid;
96 model_data.df_info=df_info;
97 
98 
99 % Information about the front-part of the car
100 % ===========================================
101 %find the elements belonging to the boundary with corresponding
102 %element-index and edge-index
103 bnd_ind = find(model_data.grid.NBI(:)<0);
104 [el_ind_bnd,local_edge_ind_bnd] = ind2sub(size(model_data.grid.NBI),bnd_ind); %lokaler Edge-Index (Kante 1, 2 oder 3 vom Element)
105 
106 [x_car_min, x_car_min_ind] = min(model.cp(:,1));
107 [y_car_min, y_car_min_ind] = min(model.cp(:,2));
108 [y_car_max, y_car_max_ind] = max(model.cp(:,2));
109 x_car_max = model.cp(y_car_max_ind,1); % x-value of the car point with maximum y_value
110 
111 %find points on the front of the car
112 ind_front=find(model_data.grid.ECX(bnd_ind) > x_car_min-eps & ...
113  model_data.grid.ECY(bnd_ind) > y_car_min+eps & ... %damit werden punkte des unterbodens ausgeschlossen
114  model_data.grid.ECY(bnd_ind) < y_car_max+eps & ...
115  model_data.grid.ECX(bnd_ind) < x_car_max+eps);
116 
117 el_ind_front = el_ind_bnd(ind_front);
118 local_edge_ind_front = local_edge_ind_bnd(ind_front);
119 linear_ind_front=sub2ind(size(model_data.grid.VI), el_ind_front, local_edge_ind_front); %single indices are needed for getting the points in model_data.grid.VI
120 
121 %%%%%%%%%%%%%%%%%
122 edge_length=model_data.grid.EL(linear_ind_front); %length of the edges belonging to the front
123 
124 %get the tangent vectors: rotate normal-vector by 90 degree!
125 % rot_angle = pi/2;
126 % rot_matrix=[cos(rot_angle), -sin(rot_angle); sin(rot_angle), cos(rot_angle)];
127 nx_front=model_data.grid.NX(linear_ind_front); %normal vectors of the edges belonging to the front
128 ny_front=model_data.grid.NY(linear_ind_front);
129 rot_matrix=[0, -1 ; 1 0];
130 tangent_vectors=rot_matrix * [nx_front'; ny_front'];
131 tx_front = tangent_vectors(1,:)';
132 ty_front = tangent_vectors(2,:)';
133 edge_midpts_x=model_data.grid.ECX(linear_ind_front);
134 edge_midpts_y=model_data.grid.ECY(linear_ind_front);
135 %%%%%%%%%%%%%%%%%%%%%%%%
136 
137 %Adding the information to model_data
138 model_data.front_ref_domain.el_ind_front = el_ind_front;
139 model_data.front_ref_domain.local_edge_ind_front = local_edge_ind_front;
140 model_data.front_ref_domain.linear_ind_front = linear_ind_front;
141 model_data.front_ref_domain.edge_length_front=edge_length;
142 model_data.front_ref_domain.normal_front=[nx_front, ny_front];
143 model_data.front_ref_domain.tangent_front=[tx_front, ty_front];
144 model_data.front_ref_domain.edge_midpts_front=[edge_midpts_x, edge_midpts_y];
A triangular conforming grid in two dimensions.
Definition: triagrid.m:17
structure representing the fem-space information shared by all fem-functions. Implemented as handle c...
Definition: feminfo.m:17