-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOptimetrics.py
164 lines (130 loc) · 4.49 KB
/
Optimetrics.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
# # Optimetrics setup
#
# This example shows how you can use PyAEDT to create a project in HFSS and create all optimetrics
# setups.
#
# Keywords: **General**, **Optimetrics**.
# ## Preparation
# Import the required packages
import os
import tempfile
import time
import ansys.aedt.core
# Define constants
AEDT_VERSION = "2024.2"
NG_MODE = False # Open Electronics UI when the application is launched.
# ## 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")
# ## Initialize HFSS and create variables
#
# Initialize the ``Hfss`` object and create two needed design variables,
# ``w1`` and ``w2``.
# +
project_name = os.path.join(temp_folder.name, "optimetrics.aedt")
hfss = ansys.aedt.core.Hfss(
project=project_name,
version=AEDT_VERSION,
new_desktop=True,
non_graphical=NG_MODE,
)
hfss["w1"] = "1mm"
hfss["w2"] = "100mm"
# -
# ## Create waveguide with sheets on it
#
# Create one of the standard waveguide structures and parametrize it.
# You can also create rectangles of waveguide openings and assign ports later.
# +
wg1, p1, p2 = hfss.modeler.create_waveguide(
[0, 0, 0],
hfss.AXIS.Y,
"WG17",
wg_thickness="w1",
wg_length="w2",
create_sheets_on_openings=True,
)
model = hfss.plot(show=False)
model.show_grid = False
model.plot(os.path.join(hfss.working_directory, "Image.jpg"))
# -
# ## Create two wave ports on the sheets.
hfss.wave_port(p1, integration_line=hfss.AxisDir.ZPos, name="1")
hfss.wave_port(p2, integration_line=hfss.AxisDir.ZPos, name="2")
# ## Create setup and frequency sweep
#
# Create a setup and a frequency sweep to use as the base for optimetrics
# setups.
setup = hfss.create_setup()
hfss.create_linear_step_sweep(
setupname=setup.name,
unit="GHz",
freqstart=1,
freqstop=5,
step_size=0.1,
sweepname="Sweep1",
save_fields=True,
)
# ## Optimetrics analysis
#
# ### Parametric Analysis
#
# Create a simple optimetrics parametrics analysis with output calculations.
sweep = hfss.parametrics.add("w2", 90, 200, 5)
sweep.add_variation("w1", 0.1, 2, 10)
sweep.add_calculation(calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"})
sweep.add_calculation(calculation="dB(S(1,1))", ranges={"Freq": "2.6GHz"})
# ## Create an optimetrics sensitivity analysis with output calculations.
sweep2 = hfss.optimizations.add(
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, optim_type="Sensitivity"
)
sweep2.add_variation("w1", 0.1, 3, 0.5)
sweep2.add_calculation(calculation="dB(S(1,1))", ranges={"Freq": "2.6GHz"})
# ## Create an optimization analysis based on goals and calculations.
sweep3 = hfss.optimizations.add(calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"})
sweep3.add_variation("w1", 0.1, 3, 0.5)
sweep3.add_goal(calculation="dB(S(1,1))", ranges={"Freq": "2.6GHz"})
sweep3.add_goal(calculation="dB(S(1,1))", ranges={"Freq": ("2.6GHz", "5GHz")})
sweep3.add_goal(
calculation="dB(S(1,1))",
ranges={"Freq": ("2.6GHz", "5GHz")},
condition="Maximize",
)
# ## Create a DX (DesignXplorer) optimization based on a goal and a calculation.
sweep4 = hfss.optimizations.add(
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, optim_type="DesignExplorer"
)
sweep4.add_goal(calculation="dB(S(1,1))", ranges={"Freq": "2.6GHz"})
# ## Create DOE based on a goal and calculation
#
# Create a DOE (Design of Experiments) based on a goal and a calculation.
sweep5 = hfss.optimizations.add(
calculation="dB(S(1,1))", ranges={"Freq": "2.5GHz"}, optim_type="DXDOE"
)
# ## Create DOE based on a goal and calculation
region = hfss.modeler.create_region()
hfss.assign_radiation_boundary_to_objects(region)
hfss.insert_infinite_sphere(name="Infinite_1")
sweep6 = hfss.optimizations.add(
calculation="RealizedGainTotal",
solution=hfss.nominal_adaptive,
ranges={"Freq": "5GHz", "Theta": ["0deg", "10deg", "20deg"], "Phi": "0deg"},
context="Infinite_1",
)
# ## Release AEDT
hfss.save_project()
hfss.release_desktop()
time.sleep(
3
) # Allow Electronics Desktop to shut down before cleaning the temporary project folder.
# ## Cleanup
#
# All project files are saved in the folder ``temp_folder.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_folder.cleanup()