-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMaxwell3D_Team3_bath_plate.py
293 lines (242 loc) · 7.56 KB
/
Maxwell3D_Team3_bath_plate.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# # Bath plate analysis
#
# This example uses PyAEDT to set up the TEAM 3 bath plate problem and
# solve it using the Maxwell 3D Eddy Current solver.
# https://www.compumag.org/wp/wp-content/uploads/2018/06/problem3.pdf
#
# Keywords: **Maxwell 3D**, **TEAM 3 bath plate**
# ## Perform required imports
#
# Perform required imports.
import os
import tempfile
import time
import ansys.aedt.core
# ## Define constants
AEDT_VERSION = "2024.2"
NUM_CORES = 4
NG_MODE = False # Open Electronics UI when the application is launched.
# ## Create temporary directory
#
# Create temporary directory.
# 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 and Maxwell 3D
#
# Create an instance of the ``Maxwell3d`` class named ``m3d`` by providing
# the project and design names, the solver, and the version.
# +
m3d = ansys.aedt.core.Maxwell3d(
project=os.path.join(temp_folder.name, "COMPUMAG.aedt"),
design="TEAM_3_Bath_Plate",
solution_type="EddyCurrent",
version=AEDT_VERSION,
non_graphical=NG_MODE,
new_desktop=True,
)
uom = m3d.modeler.model_units = "mm"
# -
# ## Add variable
#
# Add a design variable named ``Coil_Position`` that you use later to adjust the
# position of the coil.
Coil_Position = -20
m3d["Coil_Position"] = str(Coil_Position) + m3d.modeler.model_units
# ## Add material
#
# Add a material named ``team3_aluminium`` for the ladder plate.
mat = m3d.materials.add_material(name="team3_aluminium")
mat.conductivity = 32780000
# ## Draw background region
#
# Draw a background region that uses the default properties for an air region.
m3d.modeler.create_air_region(
x_pos=100, y_pos=100, z_pos=100, x_neg=100, y_neg=100, z_neg=100
)
# ## Draw ladder plate and assign material
#
# Draw a ladder plate and assign it the newly created material ``team3_aluminium``.
m3d.modeler.create_box(
origin=[-30, -55, 0],
sizes=[60, 110, -6.35],
name="LadderPlate",
material="team3_aluminium",
)
m3d.modeler.create_box(origin=[-20, -35, 0], sizes=[40, 30, -6.35], name="CutoutTool1")
m3d.modeler.create_box(origin=[-20, 5, 0], sizes=[40, 30, -6.35], name="CutoutTool2")
m3d.modeler.subtract(
blank_list="LadderPlate",
tool_list=["CutoutTool1", "CutoutTool2"],
keep_originals=False,
)
# ## Add mesh refinement to ladder plate
#
# Add a mesh refinement to the ladder plate.
m3d.mesh.assign_length_mesh(
assignment="LadderPlate",
maximum_length=3,
maximum_elements=None,
name="Ladder_Mesh",
)
# ## Draw search coil and assign excitation
#
# Draw a search coil and assign it a ``stranded`` current excitation.
# The stranded type forces the current density to be constant in the coil.
m3d.modeler.create_cylinder(
orientation="Z",
origin=[0, "Coil_Position", 15],
radius=40,
height=20,
name="SearchCoil",
material="copper",
)
m3d.modeler.create_cylinder(
orientation="Z",
origin=[0, "Coil_Position", 15],
radius=20,
height=20,
name="Bore",
material="copper",
)
m3d.modeler.subtract(blank_list="SearchCoil", tool_list="Bore", keep_originals=False)
m3d.modeler.section(assignment="SearchCoil", plane="YZ")
m3d.modeler.separate_bodies(assignment="SearchCoil_Section1")
m3d.modeler.delete(assignment="SearchCoil_Section1_Separate1")
m3d.assign_current(
assignment=["SearchCoil_Section1"],
amplitude=1260,
solid=False,
name="SearchCoil_Excitation",
)
# ## Draw a line for plotting Bz
#
# Draw a line for plotting Bz later. Bz is the Z component of the flux
# density. The following code also adds a small diameter cylinder to refine the
# mesh locally around the line.
line_points = [["0mm", "-55mm", "0.5mm"], ["0mm", "55mm", "0.5mm"]]
m3d.modeler.create_polyline(points=line_points, name="Line_AB")
poly = m3d.modeler.create_polyline(points=line_points, name="Line_AB_MeshRefinement")
poly.set_crosssection_properties(type="Circle", width="0.5mm")
# ## Plot model
model = m3d.plot(show=False)
model.plot(os.path.join(temp_folder.name, "Image.jpg"))
# ## Add Maxwell 3D setup
#
# Add a Maxwell 3D setup with frequency points at 50 Hz and 200 Hz.
setup = m3d.create_setup(name="Setup1")
setup.props["Frequency"] = "200Hz"
setup.props["HasSweepSetup"] = True
setup.props["MaximumPasses"] = 1
setup.add_eddy_current_sweep(
range_type="LinearStep", start=50, end=200, count=150, clear=True
)
# ## Adjust eddy effects
#
# Adjust eddy effects for the ladder plate and the search coil. The setting for
# eddy effect is ignored for the stranded conductor type used in the search coil.
m3d.eddy_effects_on(
assignment=["LadderPlate"],
enable_eddy_effects=True,
enable_displacement_current=True,
)
m3d.eddy_effects_on(
assignment=["SearchCoil"],
enable_eddy_effects=False,
enable_displacement_current=True,
)
# ## Add linear parametric sweep
#
# Add a linear parametric sweep for the two coil positions.
sweep_name = "CoilSweep"
param = m3d.parametrics.add(
variable="Coil_Position",
start_point=-20,
end_point=0,
step=20,
variation_type="LinearStep",
name=sweep_name,
)
param["SaveFields"] = True
param["CopyMesh"] = False
param["SolveWithCopiedMeshOnly"] = True
# ## Solve parametric sweep
#
# Solve the parametric sweep directly so that results of all variations are available.
m3d.save_project()
param.analyze(cores=NUM_CORES)
# ## Create expression for Bz
#
# Create an expression for Bz using the fields calculator.
Fields = m3d.ofieldsreporter
Fields.EnterQty("B")
Fields.CalcOp("ScalarZ")
Fields.EnterScalar(1000)
Fields.CalcOp("*")
Fields.CalcOp("Smooth")
Fields.AddNamedExpression("Bz", "Fields")
# ## Plot mag(Bz) as a function of frequency
#
# Plot mag(Bz) as a function of frequency for both coil positions.
# +
variations = {
"Distance": ["All"],
"Freq": ["All"],
"Phase": ["0deg"],
"Coil_Position": ["All"],
}
m3d.post.create_report(
expressions="mag(Bz)",
variations=variations,
primary_sweep_variable="Distance",
report_category="Fields",
context="Line_AB",
plot_name="mag(Bz) Along 'Line_AB' Coil",
)
# -
# ## Get simulation results from a solved setup
#
# Get simulation results from a solved setup as a ``SolutionData`` object.
# +
solutions = m3d.post.get_solution_data(
expressions="mag(Bz)",
report_category="Fields",
context="Line_AB",
variations=variations,
primary_sweep_variable="Distance",
)
# -
# ## Set up sweep value and plot solution
#
# Set up a sweep value and plot the solution.
solutions.active_variation["Coil_Position"] = -0.02
solutions.plot()
# ## Change sweep value and plot solution
#
# Change the sweep value and plot the solution again.
# Uncomment to show plots.
solutions.active_variation["Coil_Position"] = 0
# solutions.plot()
# ## Plot induced current density on surface of ladder plate
#
# Plot the induced current density, ``"Mag_J"``, on the surface of the ladder plate.
ladder_plate = m3d.modeler.objects_by_name["LadderPlate"]
intrinsics = {"Freq": "50Hz", "Phase": "0deg"}
m3d.post.create_fieldplot_surface(
assignment=ladder_plate.faces,
quantity="Mag_J",
intrinsics=intrinsics,
plot_name="Mag_J",
)
# ## Release AEDT
m3d.save_project()
m3d.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_folder.cleanup()