Skip to content

Commit 417fb70

Browse files
committed
Convert busbar_joule_heating.py to template format
- Changed cell markers from # %% to # + and # - - Updated tmpdir to temp_folder for consistency - Reorganized sections to match template structure - Added temp_folder.cleanup() at end - Preserved all functionality and analysis content
1 parent 59d57f3 commit 417fb70

File tree

1 file changed

+61
-49
lines changed

1 file changed

+61
-49
lines changed

examples/low_frequency/magnetic/busbar_joule_heating.py

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# %% [markdown]
21
# # Busbar Joule Heating Analysis with Maxwell 3D
32
#
43
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
@@ -28,24 +27,25 @@
2827
# - Skin depth effects on current distribution
2928
#
3029
# This example demonstrates the complete electromagnetic analysis workflow for conductor systems.
30+
#
31+
# Keywords: **Maxwell 3D**, **Eddy Current**, **Joule Heating**, **Skin Effect**
3132

32-
# %% [markdown]
33-
# ## 1. Perform Required Imports
34-
# Import all necessary modules for the Maxwell 3D busbar analysis.
33+
# ## Prerequisites
34+
#
35+
# ### Perform imports
3536

36-
# %%
37+
# +
3738
import math
3839
import os
3940
import tempfile
4041
import time
4142

4243
from ansys.aedt.core import Maxwell3d
44+
# -
4345

44-
# %% [markdown]
45-
# ## 2. Set Analysis Parameters
46+
# ### Define constants
4647
# Define geometric dimensions and electrical parameters for the busbar system.
4748

48-
# %%
4949
AEDT_VERSION = "2025.2"
5050
NG_MODE = False
5151
PROJECT_NAME = "Busbar_JouleHeating_Simple.aedt"
@@ -68,13 +68,20 @@
6868
print(f"Input currents: {I1}A + {I2}A = {I1+I2}A total")
6969
print(f"Frequency: {FREQ} Hz")
7070

71-
# %% [markdown]
72-
# ## 3. Initialize Maxwell 3D
73-
# Start Maxwell 3D with eddy current solution type and set model units.
71+
# ### Create temporary directory
72+
#
73+
# Create a temporary working directory.
74+
# The name of the working folder is stored in ``temp_folder.name``.
75+
#
76+
# > **Note:** The final cell in the notebook cleans up the temporary folder. If you want to
77+
# > retrieve the AEDT project and data, do so before executing the final cell in the notebook.
7478

75-
# %%
76-
tmpdir = tempfile.TemporaryDirectory(suffix=".ansys")
77-
project_path = os.path.join(tmpdir.name, PROJECT_NAME)
79+
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
80+
project_path = os.path.join(temp_folder.name, PROJECT_NAME)
81+
82+
# ### Launch application
83+
#
84+
# Start Maxwell 3D with eddy current solution type and set model units.
7885

7986
m3d = Maxwell3d(
8087
project=project_path,
@@ -87,11 +94,12 @@
8794
m3d.modeler.model_units = "mm"
8895
print("Maxwell 3D initialized")
8996

90-
# %% [markdown]
91-
# ## 4. Create Busbar Geometry
97+
# ## Model Preparation
98+
#
9299
# Create the main busbar conductor and terminal tabs, then unite them into a single object.
93100

94-
# %%
101+
# ### Create 3D model
102+
#
95103
print("\nCreating Geometry")
96104

97105
# Main busbar
@@ -123,11 +131,11 @@
123131
conductor.name = "CompleteBusbar"
124132
print(f"Created united conductor with {len(conductor.faces)} faces")
125133

126-
# %% [markdown]
127-
# ## 5. Define Current Excitations
134+
# ### Assign boundary conditions
135+
#
128136
# Select terminal faces and assign current excitations following Kirchhoff's current law.
129137

130-
# %%
138+
# +
131139
print("\nSelecting Terminal Faces")
132140

133141
# Sort faces by x-coordinate to identify input and output terminals
@@ -167,23 +175,19 @@
167175
print(f"Output Current: {-(I1 + I2)}A")
168176
print(f"Current balance: {I1 + I2 + (-(I1 + I2))} = 0A")
169177

170-
# %% [markdown]
171-
# ## 6. Create Air Region
172-
# Define the air region that provides boundary conditions for the electromagnetic field solution.
173-
174-
# %%
175178
print("\nCreating Air Region")
176179

177180
air = m3d.modeler.create_air_region(
178181
x_pos=0, y_pos=50, z_pos=100, x_neg=0, y_neg=50, z_neg=100
179182
)
180183
print("Air region created with 50% padding")
184+
# -
181185

182-
# %% [markdown]
183-
# ## 7. Configure Analysis Setup
186+
# ### Define solution setup
187+
#
184188
# Set up the eddy current analysis with frequency, convergence criteria, and mesh settings.
185189

186-
# %%
190+
# +
187191
print("\n Setting Up Analysis ")
188192

189193
setup = m3d.create_setup("EddyCurrentSetup")
@@ -201,12 +205,12 @@
201205
name="ConductorMesh",
202206
)
203207
print("Mesh operation assigned")
208+
# -
204209

205-
# %% [markdown]
206-
# ## 8. Run Analysis
210+
# ### Run analysis
211+
#
207212
# Execute the finite element solver with automatic adaptive mesh refinement.
208213

209-
# %%
210214
print("\n Running Analysis ")
211215
print("Starting solver... (this may take a few minutes)")
212216

@@ -217,11 +221,13 @@
217221
m3d.analyze_setup(setup.name)
218222
print("Analysis completed")
219223

220-
# %% [markdown]
221-
# ## 9. Extract Solution Data
224+
# ## Postprocess
225+
#
222226
# Get Ohmic loss (Joule heating) results from the electromagnetic field solution.
223227

224-
# %%
228+
# ### Evaluate loss
229+
#
230+
# +
225231
print("\n--- Extracting Results ---")
226232

227233
setup_sweep = f"{setup.name} : LastAdaptive"
@@ -237,12 +243,13 @@
237243

238244
total_loss = solution_data.data_magnitude()[0]
239245
print(f"\nOhmic Loss (Joule heating): {total_loss:.6f} W")
246+
# -
240247

241-
# %% [markdown]
242-
# ## 10. Create Field Visualizations
248+
# ### Visualize fields
249+
#
243250
# Generate 3D field plots showing current density, electric field, and power loss distributions.
244251

245-
# %%
252+
# +
246253
print("\n Creating Field Plots ")
247254

248255
j_plot = m3d.post.create_fieldplot_surface(
@@ -262,11 +269,9 @@
262269
)
263270
print("Joule heating distribution plot created")
264271

265-
# %% [markdown]
266-
# ## 11. Calculate Engineering Metrics
272+
# Calculate engineering metrics
267273
# Compute key parameters including resistance, loss density, skin depth, and current density.
268274

269-
# %%
270275
print("\nANALYSIS RESULTS")
271276

272277
# Basic electrical parameters
@@ -315,21 +320,30 @@
315320
print("Current density magnitude (|J|): Shows current distribution")
316321
print("Electric field magnitude (|E|): Shows electric field intensity")
317322
print("Joule heating distribution: Shows power loss density")
323+
# -
318324

319-
# %% [markdown]
320-
# ## 12. Save Project and Release Resources
321-
# Save the analysis project and clean up AEDT resources.
325+
# ## Finish
326+
#
327+
# ### Save the project
322328

323-
# %%
324329
print(f"\n--- Saving Project ---")
325330
m3d.save_project(project_path)
326331
print(f"Project saved to: {project_path}")
327332

328333
m3d.release_desktop(close_projects=True, close_desktop=True)
329-
time.sleep(2)
334+
# Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory.
335+
time.sleep(3)
336+
337+
# ### Clean up
338+
#
339+
# All project files are saved in the folder ``temp_folder.name``.
340+
# If you've run this example as a Jupyter notebook, you
341+
# can retrieve those project files. The following cell
342+
# removes all temporary files, including the project folder.
330343

331-
# %% [markdown]
332-
# ## 13. Conclusion
344+
temp_folder.cleanup()
345+
346+
# ## Conclusion
333347
# This example demonstrated the complete workflow for busbar Joule heating analysis using Maxwell 3D
334348
# and PyAEDT. The analysis captured frequency-dependent phenomena including skin effect, current
335349
# redistribution, and AC losses. Key outputs included power loss calculations, field visualizations,
@@ -339,5 +353,3 @@
339353
# Joule heating due to AC resistance and skin effect
340354
# Non-uniform current density due to skin effect
341355
# Relationship between frequency, skin depth, and power loss
342-
343-
# %%

0 commit comments

Comments
 (0)