Skip to content

Commit 2dcb141

Browse files
authored
FEAT: Improve ipm_optimazation (#432)
1 parent 3595f8a commit 2dcb141

File tree

2 files changed

+152
-17
lines changed

2 files changed

+152
-17
lines changed
28.3 KB
Loading

examples/low_frequency/motor/aedt_motor/ipm_optimization.py

Lines changed: 152 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This example shows how to use PyAEDT to find the best machine 2D geometry
44
# to achieve high torque and low losses.
55
# The example shows how to setup an optimetrics analysis to sweep geometries
6-
# for a single value of stator current angle.
6+
# for a single value of stator current angle and a varying material for the magnets.
77
# The torque and losses results are then exported in a .csv file.
88
#
99
# Keywords: **Maxwell 2D**, **transient**, **motor**, **optimization**.
@@ -20,6 +20,7 @@
2020

2121
import ansys.aedt.core
2222
from ansys.aedt.core.examples.downloads import download_file
23+
2324
# -
2425

2526
# Define constants.
@@ -58,6 +59,23 @@
5859
non_graphical=NG_MODE,
5960
)
6061

62+
# ## Design variables
63+
#
64+
# Define the materials array to be used in the parametric sweep.
65+
66+
m2d["mat_sweep"] = '["XG196/96_2DSF1.000_X", "NdFe30", "NdFe35"]'
67+
m2d["mat_index"] = 0
68+
69+
# ## Assign material array to magnets
70+
#
71+
# Get all magnets in the design that by default have the material ``"XG196/96_2DSF1.000_X"`` assigned.
72+
# Assign the material array defined above to all magnets.
73+
74+
magnets = m2d.modeler.get_objects_by_material("XG196/96_2DSF1.000_X")
75+
76+
for mag in magnets:
77+
mag.material_name = "mat_sweep[mat_index]"
78+
6179
# ## Add parametric setup
6280
#
6381
# Add a parametric setup made up of geometry variable sweep definitions and single value for the stator current angle.
@@ -71,7 +89,7 @@
7189
)
7290
param_sweep.add_variation(
7391
sweep_variable="din",
74-
start_point=70,
92+
start_point=78,
7593
end_point=80,
7694
step=10,
7795
units="mm",
@@ -87,66 +105,183 @@
87105
sweep_variable="Ipeak", start_point=200, units="A", variation_type="SingleValue"
88106
)
89107

108+
# Add material variation to the parametric setup and sweep the index of the material array defined above.
109+
110+
param_sweep.add_variation(
111+
sweep_variable="mat_index",
112+
start_point=0,
113+
end_point=2,
114+
step=1,
115+
variation_type="LinearStep",
116+
)
117+
118+
# ## Alternative way to add a parametric setup from file
119+
#
120+
# Suppose you have a .csv file with all the parameters to be swept defined in columns, such as:
121+
#
122+
# # <img src="_static/param_sweep.png" alt="" width="400">
123+
#
124+
# You can add a parametric setup from that file using the ``add_from_file`` method:
125+
126+
# +
127+
# param_sweep_from_file = m2d.parametrics.add_from_file(csv_file_path)
128+
# -
129+
90130
# ## Analyze parametric sweep
91131

132+
# To speed up the analysis, the time step is increased in the transient setup.
133+
# This can be done by modifying the ``TimeStep`` property of the transient setup.
134+
# Note: In a real case scenario, the time step should be: ``1/freq_e/360``.
135+
# To simulate a real case scenario, please comment out the following line.
136+
137+
m2d.setups[0].props["TimeStep"] = "1/freq_e/45"
92138
param_sweep.analyze(cores=NUM_CORES)
93139

94140
# ## Post-processing
95141
#
96142
# Create reports to get torque and loss results for all variations.
143+
# Create reports with all variations and with one variable at a time held constant.
144+
# This helps to visualize the influence of each variable on the torque and losses.
145+
# For the first torque report the ``din`` variable is held constant at 78mm.
97146

98-
report_torque = m2d.post.create_report(
147+
report_torque_din_costant = m2d.post.create_report(
99148
expressions="Moving1.Torque",
100149
domain="Sweep",
101-
variations={"bridge": "All", "din": "All", "Ipeak": "All", "phase_advance": "All"},
150+
variations={
151+
"bridge": "All",
152+
"din": "78mm",
153+
"Ipeak": "All",
154+
"phase_advance": "All",
155+
"mat_index": "All",
156+
},
102157
primary_sweep_variable="Time",
103158
plot_type="Rectangular Plot",
104-
plot_name="TorqueAllVariations",
159+
plot_name="torque_din_costant",
105160
)
106161

107-
report_solid_loss = m2d.post.create_report(
162+
# The second torque report has the ``mat_index`` variable held constant at 0.
163+
# In this case the material used for the magnets is ``"XG196/96_2DSF1.000_X"``.
164+
165+
report_torque_mat_costant = m2d.post.create_report(
166+
expressions="Moving1.Torque",
167+
domain="Sweep",
168+
variations={
169+
"bridge": "All",
170+
"din": "All",
171+
"Ipeak": "All",
172+
"phase_advance": "All",
173+
"mat_index": "0",
174+
},
175+
primary_sweep_variable="Time",
176+
plot_type="Rectangular Plot",
177+
plot_name="torque_mat_costant",
178+
)
179+
180+
# The same approach is used to create reports for solid and core losses.
181+
182+
report_solid_loss_din_costant = m2d.post.create_report(
183+
expressions="SolidLoss",
184+
domain="Sweep",
185+
variations={
186+
"bridge": "All",
187+
"din": "78mm",
188+
"Ipeak": "All",
189+
"phase_advance": "All",
190+
"mat_index": "All",
191+
},
192+
primary_sweep_variable="Time",
193+
plot_type="Rectangular Plot",
194+
plot_name="solid_loss_din_costant",
195+
)
196+
197+
report_solid_loss_mat_costant = m2d.post.create_report(
108198
expressions="SolidLoss",
109199
domain="Sweep",
110-
variations={"bridge": "All", "din": "All", "Ipeak": "All", "phase_advance": "All"},
200+
variations={
201+
"bridge": "All",
202+
"din": "All",
203+
"Ipeak": "All",
204+
"phase_advance": "All",
205+
"mat_index": "0",
206+
},
111207
primary_sweep_variable="Time",
112208
plot_type="Rectangular Plot",
113-
plot_name="SolidLossAllVariations",
209+
plot_name="solid_loss_mat_costant",
114210
)
115211

116-
report_core_loss = m2d.post.create_report(
212+
report_core_loss_din_costant = m2d.post.create_report(
117213
expressions="CoreLoss",
118214
domain="Sweep",
119-
variations={"bridge": "All", "din": "All", "Ipeak": "All", "phase_advance": "All"},
215+
variations={
216+
"bridge": "All",
217+
"din": "78mm",
218+
"Ipeak": "All",
219+
"phase_advance": "All",
220+
"mat_index": "All",
221+
},
120222
primary_sweep_variable="Time",
121223
plot_type="Rectangular Plot",
122-
plot_name="CoreLossAllVariations",
224+
plot_name="core_loss_din_costant",
123225
)
124226

125-
# Get torque and loss solution data for all available variations.
227+
report_core_loss_mat_costant = m2d.post.create_report(
228+
expressions="CoreLoss",
229+
domain="Sweep",
230+
variations={
231+
"bridge": "All",
232+
"din": "All",
233+
"Ipeak": "All",
234+
"phase_advance": "All",
235+
"mat_index": "0",
236+
},
237+
primary_sweep_variable="Time",
238+
plot_type="Rectangular Plot",
239+
plot_name="core_loss_mat_costant",
240+
)
241+
242+
# Get torque and loss solution data for all variations.
126243

127244
torque_data = m2d.post.get_solution_data(
128245
expressions=["Moving1.Torque"],
129246
setup_sweep_name=m2d.nominal_sweep,
130247
domain="Sweep",
131-
variations={"bridge": "All", "din": "All", "Ipeak": "All", "phase_advance": "All"},
248+
variations={
249+
"bridge": "All",
250+
"din": "All",
251+
"Ipeak": "All",
252+
"phase_advance": "All",
253+
"mat_index": "All",
254+
},
132255
primary_sweep_variable="Time",
133256
report_category="Standard",
134257
)
135258

136259
solid_loss_data = m2d.post.get_solution_data(
137-
expressions=["CoreLoss"],
260+
expressions=["SolidLoss"],
138261
setup_sweep_name=m2d.nominal_sweep,
139262
domain="Sweep",
140-
variations={"bridge": "All", "din": "All", "Ipeak": "All", "phase_advance": "All"},
263+
variations={
264+
"bridge": "All",
265+
"din": "All",
266+
"Ipeak": "All",
267+
"phase_advance": "All",
268+
"mat_index": "All",
269+
},
141270
primary_sweep_variable="Time",
142271
report_category="Standard",
143272
)
144273

145274
core_loss_data = m2d.post.get_solution_data(
146-
expressions=["SolidLoss"],
275+
expressions=["CoreLoss"],
147276
setup_sweep_name=m2d.nominal_sweep,
148277
domain="Sweep",
149-
variations={"bridge": "All", "din": "All", "Ipeak": "All", "phase_advance": "All"},
278+
variations={
279+
"bridge": "All",
280+
"din": "All",
281+
"Ipeak": "All",
282+
"phase_advance": "All",
283+
"mat_index": "All",
284+
},
150285
primary_sweep_variable="Time",
151286
report_category="Standard",
152287
)

0 commit comments

Comments
 (0)