-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy path03_5G_antenna_example_parametrics.py
341 lines (268 loc) · 10.2 KB
/
03_5G_antenna_example_parametrics.py
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# # EDB: Layout Components
#
# This example shows how you can use EDB to create a parametric component using
# 3D Layout and use it in HFSS 3D.
# ## Perform required imports
#
# Perform required imports, which includes importing the ``Hfss3dlayout`` object
# and initializing it on version 2023 R2.
import tempfile
import pyaedt
import os
# Set non-graphical mode
non_graphical = False
# ## Create data classes
#
# Data classes are useful to do calculations and store variables.
# There are three data classes: ``Patch``, ``Line``, and ``Array``.
# +
class Patch:
def __init__(self, width=0.0, height=0.0, position=0.0):
self.width = width
self.height = height
self.position = position
@property
def points(self):
return [
[self.position, "-{}/2".format(self.height)],
["{} + {}".format(self.position, self.width), "-{}/2".format(self.height)],
["{} + {}".format(self.position, self.width), "{}/2".format(self.height)],
[self.position, "{}/2".format(self.height)],
]
class Line:
def __init__(self, length=0.0, width=0.0, position=0.0):
self.length = length
self.width = width
self.position = position
@property
def points(self):
return [
[self.position, "-{}/2".format(self.width)],
["{} + {}".format(self.position, self.length), "-{}/2".format(self.width)],
["{} + {}".format(self.position, self.length), "{}/2".format(self.width)],
[self.position, "{}/2".format(self.width)],
]
class LinearArray:
def __init__(self, nb_patch=1, array_length=10e-3, array_width=5e-3):
self.nbpatch = nb_patch
self.length = array_length
self.width = array_width
@property
def points(self):
return [
[-1e-3, "-{}/2-1e-3".format(self.width)],
["{}+1e-3".format(self.length), "-{}/2-1e-3".format(self.width)],
["{}+1e-3".format(self.length), "{}/2+1e-3".format(self.width)],
[-1e-3, "{}/2+1e-3".format(self.width)],
]
# -
# ## Launch EDB
#
# PyAEDT.Edb allows to open existing Edb project or create a new empty project.
temp_dir = tempfile.TemporaryDirectory(suffix=".ansys")
aedb_path = os.path.join(temp_dir.name, "linear_array.aedb")
edb = pyaedt.Edb(edbpath=aedb_path, edbversion="2023.2") # Create an instance of the Edb class.
# Add stackup layers
edb.stackup.add_layer("Virt_GND")
edb.stackup.add_layer("Gap", "Virt_GND", layer_type="dielectric", thickness="0.05mm", material="Air")
edb.stackup.add_layer("GND", "Gap")
edb.stackup.add_layer("Substrat", "GND", layer_type="dielectric", thickness="0.5mm", material="Duroid (tm)")
edb.stackup.add_layer("TOP", "Substrat")
# Create the the first patch and feed line using the ``Patch``, ``Line``classes defined above.
#
# Define parameters:
# +
edb["w1"] = 1.4e-3
edb["h1"] = 1.2e-3
edb["initial_position"] = 0.0
edb["l1"] = 2.4e-3
edb["trace_w"] = 0.3e-3
first_patch = Patch(width="w1", height="h1", position="initial_position")
edb.modeler.create_polygon(first_patch.points, "TOP", net_name="Array_antenna")
# -
# First line
first_line = Line(length="l1", width="trace_w", position=first_patch.width)
edb.modeler.create_polygon(first_line.points, "TOP", net_name="Array_antenna")
# Now use the ``LinearArray`` class to create the array.
# +
edb["w2"] = 2.29e-3
edb["h2"] = 3.3e-3
edb["l2"] = 1.9e-3
edb["trace_w2"] = 0.2e-3
patch = Patch(width="w2", height="h2")
line = Line(length="l2", width="trace_w2")
linear_array = LinearArray(nb_patch=8, array_width=patch.height)
current_patch = 1
current_position = "{} + {}".format(first_line.position, first_line.length)
while current_patch <= linear_array.nbpatch:
patch.position = current_position
edb.modeler.create_polygon(patch.points, "TOP", net_name="Array_antenna")
current_position = "{} + {}".format(current_position, patch.width)
if current_patch < linear_array.nbpatch:
line.position = current_position
edb.modeler.create_polygon(line.points, "TOP", net_name="Array_antenna")
current_position = "{} + {}".format(current_position, line.length)
current_patch += 1
linear_array.length = current_position
# -
# Add the ground conductor.
edb.modeler.create_polygon(linear_array.points, "GND", net_name="GND")
# Add the connector pin to use to assign the port.
edb.padstacks.create(padstackname="Connector_pin", holediam="100um", paddiam="0", antipaddiam="200um")
con_pin = edb.padstacks.place(
["{}/4.0".format(first_patch.width), 0],
"Connector_pin",
net_name="Array_antenna",
fromlayer="TOP",
tolayer="GND",
via_name="coax",
)
# Add a connector ground.
edb.modeler.create_polygon(first_patch.points, "Virt_GND", net_name="GND")
edb.padstacks.create("gnd_via", "100um", "0", "0")
edb["via_spacing"] = 0.2e-3
con_ref1 = edb.padstacks.place(
["{} + {}".format(first_patch.points[0][0], "via_spacing"), "{} + {}".format(first_patch.points[0][1], "via_spacing")],
"gnd_via",
fromlayer="GND",
tolayer="Virt_GND",
net_name="GND",
)
con_ref2 = edb.padstacks.place(
["{} + {}".format(first_patch.points[1][0], "-via_spacing"), "{} + {}".format(first_patch.points[1][1], "via_spacing")],
"gnd_via",
fromlayer="GND",
tolayer="Virt_GND",
net_name="GND",
)
con_ref3 = edb.padstacks.place(
["{} + {}".format(first_patch.points[2][0], "-via_spacing"), "{} + {}".format(first_patch.points[2][1], "-via_spacing")],
"gnd_via",
fromlayer="GND",
tolayer="Virt_GND",
net_name="GND",
)
con_ref4 = edb.padstacks.place(
["{} + {}".format(first_patch.points[3][0], "via_spacing"), "{} + {}".format(first_patch.points[3][1], "-via_spacing")],
"gnd_via",
fromlayer="GND",
tolayer="Virt_GND",
net_name="GND",
)
# Define the port.
edb.padstacks.set_solderball(con_pin, "Virt_GND", isTopPlaced=False, ballDiam=0.1e-3)
port_name = edb.padstacks.create_coax_port(con_pin)
# Display the model using the ``Edb.nets.plot()`` method.
edb.nets.plot()
# The EDB is complete. Now close the EDB and import it into HFSS as a "Layout Component".
edb.save_edb()
edb.close_edb()
print("EDB saved correctly to {}. You can import in AEDT.".format(aedb_path))
# ## 3D component in HFSS
#
# First create an instance of the ``pyaedt.Hfss`` class. If you set
# > ``non_graphical = False
#
# then AEDT user interface will be visible after the following cell is executed. It is now possible
# to monitor the progress in the UI as each of the following cells is executed. All commands can be run
# without the UI by chaning the value of ``non_graphical``.
h3d = pyaedt.Hfss(projectname="Demo_3DComp",
designname="Linear_Array",
specified_version="2023.2",
new_desktop_session=True,
non_graphical=non_graphical,
close_on_exit=True,
solution_type="Terminal")
# Set units to ``mm``.
h3d.modeler.model_units = "mm"
# ## Import the EDB as a 3D component
#
# One or more layout components can be imported into HFSS. The combination of layout data and 3D CAD data helps streamline
# model creation and setup.
component = h3d.modeler.insert_layout_component(aedb_path, parameter_mapping=True)
# ## Expose the component parameters
#
# If a layout component is parametric, you can expose and change parameters in HFSS
# +
component.parameters
w1_name = "{}_{}".format("w1", h3d.modeler.user_defined_component_names[0])
h3d[w1_name]= 0.0015
# -
# ### Radiation Boundary Assignment
#
# The 3D domain includes the air volume surrounding the antenna. This antenna will be simulted from 20 GHz - 50 GHz.
#
# A "radiation boundary" will be assigned to the outer boundaries of the domain.
# This boundary should be roughly one quarter wavelength away from the radiating strucure:
#
# $$ \lambda/4 = \frac{c_0}{4 f} \approx 2.8mm $$
# +
h3d.modeler.fit_all()
h3d.modeler.create_air_region(2.8, 2.8, 2.8, 2.8, 2.8, 2.8, is_percentage=False)
h3d.assign_radiation_boundary_to_objects("Region")
# -
# ### Set up analysis
#
# The finite element mesh is adapted iteratively. The maximum number of adaptive passes is set using the ``MaximumPasses`` property. This model converges such that the $S_{11}$ is independent of the mesh. The default accuracy setting is:
# $$ \max(|\Delta S|) < 0.02 $$
setup = h3d.create_setup()
setup.props['Frequency']="20GHz"
setup.props['MaximumPasses'] = 10
# Specify properties of the frequency sweep:
sweep1 = setup.add_sweep(sweepname="20GHz_to_50GHz")
sweep1.props["RangeStart"]="20GHz"
sweep1.props["RangeEnd"]="50GHz"
sweep1.update()
# Solve the project
h3d.analyze()
# ## Plot results outside AEDT
#
# Plot results using Matplotlib.
trace = h3d.get_traces_for_plot()
solution = h3d.post.get_solution_data(trace[0])
solution.plot()
# ## Plot far fields in AEDT
#
# Plot radiation patterns in AEDT.
# +
variations = {}
variations["Freq"] = ["20GHz"]
variations["Theta"] = ["All"]
variations["Phi"] = ["All"]
h3d.insert_infinite_sphere( name="3D")
new_report = h3d.post.reports_by_category.far_field("db(RealizedGainTotal)", h3d.nominal_adaptive, "3D")
new_report.variations = variations
new_report.primary_sweep = "Theta"
new_report.create("Realized2D")
# -
# ## Plot far fields in AEDT
#
# Plot radiation patterns in AEDT
new_report.report_type = "3D Polar Plot"
new_report.secondary_sweep = "Phi"
new_report.create("Realized3D")
# ## Plot far fields outside AEDT
#
# Plot radiation patterns outside AEDT
solutions_custom = new_report.get_solution_data()
solutions_custom.plot_3d()
# ## Plot E Field on nets and layers
#
# Plot E Field on nets and layers in AEDT
h3d.post.create_fieldplot_layers_nets(
[["TOP","Array_antenna"]],
"Mag_E",
intrinsics={"Freq":"20GHz", "Phase": "0deg"},
plot_name="E_Layers",
)
# ## Close AEDT
#
# After the simulation completes, the application can be released from the
# :func:`pyaedt.Desktop.release_desktop` method.
# All methods provide for saving the project before closing AEDT.
h3d.save_project(os.path.join(temp_dir, "test_layout.aedt"))
h3d.release_desktop()
# ### Clean up the temporary directory
#
# The following command removes the project and the temporary directory. If you'd like to save this project, save it to a folder of your choice prior to running the following cell.
temp_dir.cleanup()