-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHFSS_Spiral.py
229 lines (181 loc) · 5.38 KB
/
HFSS_Spiral.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
# # Spiral inductor
#
# This example shows how you can use PyAEDT to create a spiral inductor, solve it, and plot results.
#
# Keywords: **HFSS**, **Spiral**, **Inductance**, **Output variable**.
# ## Perform required imports
#
# Perform required imports.
import os
import tempfile
import time
import ansys.aedt.core
# Set constant values
AEDT_VERSION = "2024.2"
NUM_CORES = 4
NG_MODE = False # Open Electronics UI when the application is launched.
# ## Create temporary directory
temp_dir = tempfile.TemporaryDirectory(suffix="_ansys")
# ## Launch HFSS
#
# Create a new HFSS design and change the units to microns.
project_name = os.path.join(temp_dir.name, "spiral.aedt")
hfss = ansys.aedt.core.Hfss(
project=project_name,
version=AEDT_VERSION,
non_graphical=NG_MODE,
design="A1",
new_desktop=True,
solution_type="Modal",
)
hfss.modeler.model_units = "um"
# ## Define variables
#
# Define input variables. You can use the values that follow or edit
# them.
rin = 10
width = 2
spacing = 1
thickness = 1
Np = 8
Nr = 10
gap = 3
hfss["Tsub"] = "6" + hfss.modeler.model_units
# ## Standardize polyline
#
# Define a function that creates a polyline using the ``create_line`` method. This
# function creates a polyline having fixed width, thickness, and material.
def create_line(pts):
hfss.modeler.create_polyline(
pts,
xsection_type="Rectangle",
xsection_width=width,
xsection_height=thickness,
material="copper",
)
# ## Create spiral inductor
#
# Create the spiral inductor. This spiral inductor is not
# parametric, but you could parametrize it later.
ind = hfss.modeler.create_spiral(
internal_radius=rin,
width=width,
spacing=spacing,
turns=Nr,
faces=Np,
thickness=thickness,
material="copper",
name="Inductor1",
)
# ## Center return path
#
# Center the return path.
x0, y0, z0 = ind.points[0]
x1, y1, z1 = ind.points[-1]
create_line([(x0 - width / 2, y0, -gap), (abs(x1) + 5, y0, -gap)])
hfss.modeler.create_box(
[x0 - width / 2, y0 - width / 2, -gap - thickness / 2],
[width, width, gap + thickness],
matname="copper",
)
# Create port 1.
hfss.modeler.create_rectangle(
orientation=ansys.aedt.core.constants.PLANE.YZ,
origin=[abs(x1) + 5, y0 - width / 2, -gap - thickness / 2],
sizes=[width, "-Tsub+{}{}".format(gap, hfss.modeler.model_units)],
name="port1",
)
hfss.lumped_port(assignment="port1", integration_line=ansys.aedt.core.constants.AXIS.Z)
# Create port 2.
create_line([(x1 + width / 2, y1, 0), (x1 - 5, y1, 0)])
hfss.modeler.create_rectangle(
ansys.aedt.core.constants.PLANE.YZ,
[x1 - 5, y1 - width / 2, -thickness / 2],
[width, "-Tsub"],
name="port2",
)
hfss.lumped_port(assignment="port2", integration_line=ansys.aedt.core.constants.AXIS.Z)
# Create the silicon substrate and the ground plane.
# +
hfss.modeler.create_box(
[x1 - 20, x1 - 20, "-Tsub-{}{}/2".format(thickness, hfss.modeler.model_units)],
[-2 * x1 + 40, -2 * x1 + 40, "Tsub"],
material="silicon",
)
hfss.modeler.create_box(
[x1 - 20, x1 - 20, "-Tsub-{}{}/2".format(thickness, hfss.modeler.model_units)],
[-2 * x1 + 40, -2 * x1 + 40, -0.1],
material="PEC",
)
# -
# ## Model Setup
#
# Create the air box and radiation boundary condition.
# +
box = hfss.modeler.create_box(
[
x1 - 20,
x1 - 20,
"-Tsub-{}{}/2 - 0.1{}".format(
thickness, hfss.modeler.model_units, hfss.modeler.model_units
),
],
[-2 * x1 + 40, -2 * x1 + 40, 100],
name="airbox",
material="air",
)
hfss.assign_radiation_boundary_to_objects("airbox")
# -
# Assign a material override which allows object intersections,
# assigning conductors higher priority than insulators.
hfss.change_material_override()
# View the model.
hfss.plot(
show=False,
output_file=os.path.join(hfss.working_directory, "Image.jpg"),
plot_air_objects=False,
)
# ## Generate the solution
#
# Create the setup including a frequency sweep, then solve the project.
setup1 = hfss.create_setup(name="setup1")
setup1.props["Frequency"] = "10GHz"
hfss.create_linear_count_sweep(
setup="setup1",
units="GHz",
start_frequency=1e-3,
stop_frequency=50,
num_of_freq_points=451,
sweep_type="Interpolating",
)
hfss.save_project()
hfss.analyze(cores=NUM_CORES)
# ## Post-processing
#
# Get report data and use the following formulas to calculate
# the inductance and quality factor.
L_formula = "1e9*im(1/Y(1,1))/(2*pi*freq)"
Q_formula = "im(Y(1,1))/re(Y(1,1))"
# Define the inductance as a post-processing variable.
hfss.create_output_variable("L", L_formula, solution="setup1 : LastAdaptive")
# Plot the results using Matplotlib.
data = hfss.post.get_solution_data([L_formula, Q_formula])
data.plot(
curves=[L_formula, Q_formula], formula="re", x_label="Freq", y_label="L and Q"
)
# Export results to csv file
data.export_data_to_csv(os.path.join(hfss.toolkit_directory, "output.csv"))
# ## Save project and close AEDT
#
# Save the project and close AEDT.
hfss.save_project()
hfss.release_desktop()
# Wait 3 seconds to allow Electronics Desktop to shut down before cleaning the temporary directory.
time.sleep(3)
# ## Cleanup
#
# All project files are saved in the folder ``temp_dir.name``.
# If you've run this example as a Jupyter notebook you
# can retrieve those project files. The following cell removes
# all temporary files, including the project folder.
temp_dir.cleanup()