-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFlex_CPWG.py
254 lines (198 loc) · 5.77 KB
/
Flex_CPWG.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
# # Flex cable CPWG
#
# This example shows how you can use PyAEDT to create a flex cable CPWG
# (coplanar waveguide with ground).
#
# Keywords: **HFSS**, **flex cable**, **CPWG**.
# ## Perform required imports
#
# Perform required imports.
import os
import tempfile
from math import cos, radians, sin, sqrt
import ansys.aedt.core
from ansys.aedt.core.generic.general_methods import generate_unique_name
# Set constant values
AEDT_VERSION = "2024.2"
# ## Set non-graphical mode
#
# Set non-graphical mode.
# You can set ``non_graphical`` either to ``True`` or ``False``.
non_graphical = False
# ## Create temporary directory and download files
#
# Create a temporary directory where we store downloaded data or
# dumped data.
# If you'd like to retrieve the project data for subsequent use,
# the temporary folder name is given by ``temp_folder.name``.
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
# ## Launch AEDT
#
# Launch AEDT, create an HFSS design, and save the project.
hfss = ansys.aedt.core.Hfss(
version=AEDT_VERSION,
solution_type="DrivenTerminal",
new_desktop=True,
non_graphical=non_graphical,
)
hfss.save_project(
os.path.join(temp_folder.name, generate_unique_name("example") + ".aedt")
)
# ## Design settings
#
# Modify some design settings.
hfss.change_material_override(True)
hfss.change_automatically_use_causal_materials(True)
hfss.create_open_region("100GHz")
hfss.modeler.model_units = "mil"
hfss.mesh.assign_initial_mesh_from_slider(applycurvilinear=True)
# ## Create variables
#
# Create input variables for creating the flex cable CPWG.
# +
total_length = 300
theta = 120
r = 100
width = 3
height = 0.1
spacing = 1.53
gnd_width = 10
gnd_thickness = 2
xt = (total_length - r * radians(theta)) / 2
# -
# ## Create bend
#
# The ``create_bending`` method creates a list of points for
# the bend based on the curvature radius and extension.
def create_bending(radius, extension=0):
points = [(-xt, 0, -radius), (0, 0, -radius)]
for i in [radians(i) for i in range(theta)] + [radians(theta + 0.000000001)]:
points.append((radius * sin(i), 0, -radius * cos(i)))
x1, y1, z1 = points[-1]
x0, y0, z0 = points[-2]
scale = (xt + extension) / sqrt((x1 - x0) ** 2 + (z1 - z0) ** 2)
x, y, z = (x1 - x0) * scale + x0, 0, (z1 - z0) * scale + z0
points[-1] = (x, y, z)
return points
# ## Draw signal line
#
# Draw a signal line to create a bent signal wire.
points = create_bending(r, 1)
line = hfss.modeler.create_polyline(
points=points,
xsection_type="Rectangle",
xsection_width=height,
xsection_height=width,
material="copper",
)
# ## Draw ground line
#
# Draw a ground line to create two bent ground wires.
# +
gnd_r = [(x, spacing + width / 2 + gnd_width / 2, z) for x, y, z in points]
gnd_l = [(x, -y, z) for x, y, z in gnd_r]
gnd_objs = []
for gnd in [gnd_r, gnd_l]:
x = hfss.modeler.create_polyline(
points=gnd,
xsection_type="Rectangle",
xsection_width=height,
xsection_height=gnd_width,
material="copper",
)
x.color = (255, 0, 0)
gnd_objs.append(x)
# -
# ## Draw dielectric
#
# Draw a dielectric to create a dielectric cable.
# +
points = create_bending(r + (height + gnd_thickness) / 2)
fr4 = hfss.modeler.create_polyline(
points=points,
xsection_type="Rectangle",
xsection_width=gnd_thickness,
xsection_height=width + 2 * spacing + 2 * gnd_width,
material="FR4_epoxy",
)
# -
# ## Create bottom metals
#
# Create the bottom metals.
# +
points = create_bending(r + height + gnd_thickness, 1)
bot = hfss.modeler.create_polyline(
points=points,
xsection_type="Rectangle",
xsection_width=height,
xsection_height=width + 2 * spacing + 2 * gnd_width,
material="copper",
)
# -
# ## Create port interfaces
#
# Create port interfaces (PEC enclosures).
port_faces = []
for face, blockname in zip([fr4.top_face_z, fr4.bottom_face_x], ["b1", "b2"]):
xc, yc, zc = face.center
positions = [i.position for i in face.vertices]
port_sheet_list = [
((x - xc) * 10 + xc, (y - yc) + yc, (z - zc) * 10 + zc) for x, y, z in positions
]
s = hfss.modeler.create_polyline(
port_sheet_list, close_surface=True, cover_surface=True
)
center = [round(i, 6) for i in s.faces[0].center]
port_block = hfss.modeler.thicken_sheet(s.name, -5)
port_block.name = blockname
for f in port_block.faces:
if [round(i, 6) for i in f.center] == center:
port_faces.append(f)
port_block.material_name = "PEC"
for i in [line, bot] + gnd_objs:
i.subtract([port_block], True)
print(port_faces)
# ## Create boundary condition
#
# Creates a Perfect E boundary condition.
boundary = []
for face in [fr4.top_face_y, fr4.bottom_face_y]:
s = hfss.modeler.create_object_from_face(face)
boundary.append(s)
hfss.assign_perfecte_to_sheets(s)
# ## Create ports
#
# Creates ports.
for s, port_name in zip(port_faces, ["1", "2"]):
reference = [i.name for i in gnd_objs + boundary + [bot]] + ["b1", "b2"]
hfss.wave_port(s.id, name=port_name, reference=reference)
# ## Create setup and sweep
#
# Create the setup and sweep.
setup = hfss.create_setup("setup1")
setup["Frequency"] = "2GHz"
setup.props["MaximumPasses"] = 10
setup.props["MinimumConvergedPasses"] = 2
hfss.create_linear_count_sweep(
setup="setup1",
units="GHz",
start_frequency=1e-1,
stop_frequency=4,
num_of_freq_points=101,
name="sweep1",
save_fields=False,
sweep_type="Interpolating",
)
# ## Plot model
#
# Plot the model.
my_plot = hfss.plot(show=False, plot_air_objects=False)
my_plot.show_axes = False
my_plot.show_grid = False
my_plot.plot(
os.path.join(hfss.working_directory, "Image.jpg"),
)
# ## Release AEDT
hfss.release_desktop()
# ## Clean temporary directory
temp_folder.cleanup()