-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_horn_antenna.m
More file actions
257 lines (205 loc) · 7.9 KB
/
test_horn_antenna.m
File metadata and controls
257 lines (205 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
% test_horn_antenna.m
clc
clear
close all
modelerPath = './Modeler_2D';
mesherPath = '../mesh2d';
meshWrapperPath = './Mesh_2D';
solver2DPath = './Solver_2D';
solver1DPath = './Solver_1D';
miscPath = './misc';
warning('off')
pkg('load','geometry');
pkg('load','miscellaneous');
addpath(modelerPath);
addpath(genpath(mesherPath));
addpath(meshWrapperPath);
addpath(solver2DPath);
addpath(solver1DPath);
addpath(miscPath);
% Simulation properties
simProps = cem2D_createSimPropsStruct(...
'fMin',25,...
'fMax',35,...
'polarizationType','TE');
f_sim = 30;
% Global mesh properties
meshProps = mesh2D_createMeshPropsStruct(...
'relWLmeshMax',0.33, ...
'boundingBoxAddSpace',1, ...
'algorithmType','delfront',...
'maxRadiusEdgeRatio',1.25);
% Horn antenna properties
horn_WG_L = 10;
horn_WG_H = 5;
horn_taper_ang_deg = 30;
horn_taper_L = 6;
horn_metal_thick = 0.8;
%%%%%%%%%%%%%%%%%%%%%%%
% Build horn geometry %
%%%%%%%%%%%%%%%%%%%%%%%
% Draw top and bottom panels
topPanel = mod2D_createRectangleStruct([-0.5*horn_WG_L 0.5*horn_WG_H],[0.5*horn_WG_L 0.5*horn_WG_H+horn_metal_thick]);
botPanel = mod2D_createRectangleStruct([-0.5*horn_WG_L -0.5*horn_WG_H-horn_metal_thick],[0.5*horn_WG_L -0.5*horn_WG_H]);
%
backPlate = mod2D_createRectangleStruct([0.5*horn_WG_L -0.5*horn_WG_H-horn_metal_thick],[0.5*horn_WG_L+horn_metal_thick 0.5*horn_WG_H+horn_metal_thick]);
portLine = mod2D_createLineStruct([0.5*horn_WG_L -0.5*horn_WG_H-horn_metal_thick],[0.5*horn_WG_L 0.5*horn_WG_H+horn_metal_thick]);
taper_ang = horn_taper_ang_deg*pi/180;
topTaper = mod2D_createPolygonStruct(...
[-0.5*horn_WG_L ; ...
-0.5*horn_WG_L-horn_taper_L ; ...
-0.5*horn_WG_L-horn_taper_L ; ...
-0.5*horn_WG_L], ...
[0.5*horn_WG_H ; ...
0.5*horn_WG_H+horn_taper_L*tan(taper_ang) ; ...
0.5*horn_WG_H+horn_taper_L*tan(taper_ang)+horn_metal_thick ; ...
0.5*horn_WG_H+horn_metal_thick]);
botTaper = mod2D_createPolygonStruct(...
[-0.5*horn_WG_L ; ...
-0.5*horn_WG_L-horn_taper_L ; ...
-0.5*horn_WG_L-horn_taper_L ; ...
-0.5*horn_WG_L], ...
[-0.5*horn_WG_H ; ...
-0.5*horn_WG_H-horn_taper_L*tan(taper_ang) ; ...
-0.5*horn_WG_H-horn_taper_L*tan(taper_ang)-horn_metal_thick ; ...
-0.5*horn_WG_H-horn_metal_thick]);
% Show geometry
topPanel = mod2D_booleanOperation(topPanel,topTaper,'add');
botPanel = mod2D_booleanOperation(botPanel,botTaper,'add');
%%%%%%%%%%%%%%%%%%%%
% Assign materials %
%%%%%%%%%%%%%%%%%%%%
% Create the materials for this simulation
material_default = cem2D_createMaterialDefs;
material_PEC = cem2D_createMaterialDefs('name','PEC','type','PEC');
% Create the material list with only the default material
materialList = cem2D_addMaterialToList(material_default);
materialList = cem2D_addMaterialToList(material_PEC,materialList);
% Create polygon list
polList = {topPanel,botPanel,backPlate};
% Assign materials per-shape
materialAssignment = {'PEC','PEC','PEC'};
% Create bounding box (background)
bBox = mod2D_createBoundingBox(...
polList,...
meshProps,...
simProps,...
material_default);
orig_bBox = bBox;
% Subtract all shapes from bounding box
for polIdx = 1:numel(polList)
bBox = mod2D_booleanOperation(bBox,polList{polIdx},'subtract');
end
polList = [{bBox} polList];
lineList = {portLine};
materialAssignment = [{'default'},materialAssignment];
%%%%%%%%%%%%%%%%%%%%%
% Plot the geometry %
%%%%%%%%%%%%%%%%%%%%%
figHdl = figure;
axHdl = axes;
mod2D_showPolygon(axHdl,bBox,[1 1 1],[0 0 0]);
mod2D_showPolygon(axHdl,topPanel,[0.3 0.3 0.3],[0 0 0]);
mod2D_showPolygon(axHdl,botPanel,[0.3 0.3 0.3],[0 0 0]);
mod2D_showPolygon(axHdl,backPlate,[0 0.1 0.7],[0 0 0]);
set(gca,'fontsize',14);
xlabel('x [mm]','fontsize',16);
ylabel('y [mm]','fontsize',16);
%%%%%%%%%%%%%%%%%%%%%
% Plot the geometry %
%%%%%%%%%%%%%%%%%%%%%
% Test mesh of bounding box
meshData = mesh2D_generateInitialMesh(...
polList,... % Entire polygon list. This is mainly to calculate the maximum\minimum edge length
lineList,... % List of lines. Used for porst, mainly.
materialAssignment,... % Material assignments for initial LFS assignment
materialList,... % Corresponding material properties
meshProps,... % Darrens Mesher properties
simProps); % Simulation properties. This is to assign spatial meshing rules, most
% Smooth the mesh
meshData = mesh2D_smoothMesh(meshData,meshProps);
hold(axHdl,'on');
patch('faces',meshData.tria(meshData.tnum == 1,1:3),'vertices',meshData.vert, ...
'facecolor','none', ...
'edgecolor',[0,0,0]) ;
% Plot lines
lineIdxs = unique(meshData.lnum);
for cLineIdx = lineIdxs(:).'
cLineVertPairs = meshData.ltri(meshData.lnum == cLineIdx,:);
cLineR1 = meshData.vert(cLineVertPairs(:,1),:);
cLineR2 = meshData.vert(cLineVertPairs(:,2),:);
plot([cLineR1(:,1) cLineR2(:,1)].',[cLineR1(:,2) cLineR2(:,2)].','-r','linewidth',3);
plot(cLineR1(:,1),cLineR1(:,2),'.b','markersize',20);
plot(cLineR2(:,1),cLineR2(:,2),'.g','markersize',10);
end
hold(axHdl,'off');
%mod2D_showPolyline(axHdl,portLine,[1 0 0]);
portStruct = cem2D_createWaveguidePortStruct('polyLineNumber',1);
% For this example , set the simulation frequency as the middle between
% minimum and maximum frequency
simProps.fSim = 0.5*(simProps.fMin + simProps.fMax);
% Generate port modes, store in port structure.
portStruct = cem1D_calcPortModes(...
portStruct,...
meshData,...
materialList,...
materialAssignment,...
meshProps,...
simProps);
% Switch propagation direction
portStruct.propDirection = -1;
% Show propagation direction
hold(axHdl,'on');
arrowHdl = quiver( portStruct.portCenter(1),...
portStruct.portCenter(2),...
4*portStruct.portDirection(1)*portStruct.propDirection,...
4*portStruct.portDirection(2)*portStruct.propDirection);
set(arrowHdl,'linewidth',3);
set(arrowHdl,'color',[1 0.2 0.2]);
hold(axHdl,'off');
% Create matrix for port propagation
[K_port,b_port] = cem2D_createKmatBvect_WG_Port(...
meshData,...
portStruct,...
materialList,...
simProps,...
meshProps,...
f_sim);
% Extract the edges
bbEdgeIdxs = mod2D_extractPolygonEdges(...
meshData,...
meshProps,...
orig_bBox);
% Assign to outline the 2nd order radiating boundary conditions
[K_rad,b_rad] = cem2D_createKmatBvect_2ndOrderRadCond(...
meshData,... % Mesh to use for final matrix
meshProps,... % Mesh properties
bbEdgeIdxs,...
materialList,... % List of all materials used
materialAssignment,... % Material assignements per-face
simProps,... % Simulation properties
f_sim);
[K_mat,b_mat] = cem2D_createKmatBvect_materials(...
meshData,...
meshProps,...
materialList,...
materialAssignment,...
simProps,...
f_sim);
K = K_rad + K_port + K_mat;
b = b_rad + b_port + b_mat;
u = K\b;
hold on;
colormap('jet');
meshHdl = trimesh(meshData.tria,meshData.vert(:,1),meshData.vert(:,2),zeros([size(meshData.vert,1) 1]),abs(u));
view([0 90]);
colorbar;
set(meshHdl,'facecolor','flat');
set(meshHdl,'edgealpha',0.5);
set(meshHdl,'facealpha',0.5);
rmpath(modelerPath);
rmpath(genpath(mesherPath));
rmpath(meshWrapperPath);
rmpath(solver2DPath);
rmpath(solver1DPath);
rmpath(miscPath);