|
3 | 3 | # This example shows how to use PyAEDT to find the best machine 2D geometry |
4 | 4 | # to achieve high torque and low losses. |
5 | 5 | # 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. |
7 | 7 | # The torque and losses results are then exported in a .csv file. |
8 | 8 | # |
9 | 9 | # Keywords: **Maxwell 2D**, **transient**, **motor**, **optimization**. |
|
20 | 20 |
|
21 | 21 | import ansys.aedt.core |
22 | 22 | from ansys.aedt.core.examples.downloads import download_file |
| 23 | + |
23 | 24 | # - |
24 | 25 |
|
25 | 26 | # Define constants. |
|
58 | 59 | non_graphical=NG_MODE, |
59 | 60 | ) |
60 | 61 |
|
| 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 | + |
61 | 79 | # ## Add parametric setup |
62 | 80 | # |
63 | 81 | # Add a parametric setup made up of geometry variable sweep definitions and single value for the stator current angle. |
|
71 | 89 | ) |
72 | 90 | param_sweep.add_variation( |
73 | 91 | sweep_variable="din", |
74 | | - start_point=70, |
| 92 | + start_point=78, |
75 | 93 | end_point=80, |
76 | 94 | step=10, |
77 | 95 | units="mm", |
|
87 | 105 | sweep_variable="Ipeak", start_point=200, units="A", variation_type="SingleValue" |
88 | 106 | ) |
89 | 107 |
|
| 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 | + |
90 | 130 | # ## Analyze parametric sweep |
91 | 131 |
|
| 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" |
92 | 138 | param_sweep.analyze(cores=NUM_CORES) |
93 | 139 |
|
94 | 140 | # ## Post-processing |
95 | 141 | # |
96 | 142 | # 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. |
97 | 146 |
|
98 | | -report_torque = m2d.post.create_report( |
| 147 | +report_torque_din_costant = m2d.post.create_report( |
99 | 148 | expressions="Moving1.Torque", |
100 | 149 | 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 | + }, |
102 | 157 | primary_sweep_variable="Time", |
103 | 158 | plot_type="Rectangular Plot", |
104 | | - plot_name="TorqueAllVariations", |
| 159 | + plot_name="torque_din_costant", |
105 | 160 | ) |
106 | 161 |
|
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( |
108 | 198 | expressions="SolidLoss", |
109 | 199 | 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 | + }, |
111 | 207 | primary_sweep_variable="Time", |
112 | 208 | plot_type="Rectangular Plot", |
113 | | - plot_name="SolidLossAllVariations", |
| 209 | + plot_name="solid_loss_mat_costant", |
114 | 210 | ) |
115 | 211 |
|
116 | | -report_core_loss = m2d.post.create_report( |
| 212 | +report_core_loss_din_costant = m2d.post.create_report( |
117 | 213 | expressions="CoreLoss", |
118 | 214 | 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 | + }, |
120 | 222 | primary_sweep_variable="Time", |
121 | 223 | plot_type="Rectangular Plot", |
122 | | - plot_name="CoreLossAllVariations", |
| 224 | + plot_name="core_loss_din_costant", |
123 | 225 | ) |
124 | 226 |
|
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. |
126 | 243 |
|
127 | 244 | torque_data = m2d.post.get_solution_data( |
128 | 245 | expressions=["Moving1.Torque"], |
129 | 246 | setup_sweep_name=m2d.nominal_sweep, |
130 | 247 | 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 | + }, |
132 | 255 | primary_sweep_variable="Time", |
133 | 256 | report_category="Standard", |
134 | 257 | ) |
135 | 258 |
|
136 | 259 | solid_loss_data = m2d.post.get_solution_data( |
137 | | - expressions=["CoreLoss"], |
| 260 | + expressions=["SolidLoss"], |
138 | 261 | setup_sweep_name=m2d.nominal_sweep, |
139 | 262 | 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 | + }, |
141 | 270 | primary_sweep_variable="Time", |
142 | 271 | report_category="Standard", |
143 | 272 | ) |
144 | 273 |
|
145 | 274 | core_loss_data = m2d.post.get_solution_data( |
146 | | - expressions=["SolidLoss"], |
| 275 | + expressions=["CoreLoss"], |
147 | 276 | setup_sweep_name=m2d.nominal_sweep, |
148 | 277 | 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 | + }, |
150 | 285 | primary_sweep_variable="Time", |
151 | 286 | report_category="Standard", |
152 | 287 | ) |
|
0 commit comments