Download this example
Download this example as a Jupyter Notebook or as a Python script.
Maxwell 3D-Icepak electrothermal analysis#
This example uses PyAEDT to set up a simple Maxwell design consisting of a coil and a ferrite core. Coil current is set to 100A, and coil resistance and ohmic loss are analyzed. Ohmic loss is mapped to Icepak, and a thermal analysis is performed. Icepak calculates a temperature distribution, and it is mapped back to Maxwell (2-way coupling). Coil resistance and ohmic loss are analyzed again in Maxwell. Results are printed in AEDT Message Manager.
Keywords: Multiphysics, Maxwell, Icepak, Wireless Charging.
Perform imports and define constants#
Perform required imports.
[1]:
import os
import tempfile
import time
import ansys.aedt.core
from ansys.aedt.core.generic.constants import AXIS
Define constants.
[2]:
AEDT_VERSION = "2024.2"
NG_MODE = False # Open AEDT UI when it is launched.
Create temporary directory#
Create a temporary working directory. The name of the working folder is stored in temp_folder.name
.
Note: The final cell in the notebook cleans up the temporary folder. If you want to retrieve the AEDT project and data, do so before executing the final cell in the notebook.
[3]:
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
Launch application#
The syntax for different applications in AEDT differ only in the name of the class. This example demonstrates the use of the Maxwell3d
class.
Note: An AEDT Project is created when the
Maxwell3d
class is instantiated. An instance of theIcepak
class will be used to insert and simulate an Icepak design and demonstrate the coupled electrical-thermal workflow.
[4]:
project_name = os.path.join(temp_folder.name, "Maxwell-Icepak-2way-Coupling")
maxwell_design_name = "1 Maxwell"
icepak_design_name = "2 Icepak"
m3d = ansys.aedt.core.Maxwell3d(
project=project_name,
design=maxwell_design_name,
solution_type="EddyCurrent",
version=AEDT_VERSION,
non_graphical=NG_MODE,
)
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_44d90dbf-0a32-461f-b874-da6dd4fa3fd8.log is enabled.
PyAEDT INFO: Log on AEDT is enabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: New AEDT session is starting on gRPC port 56206
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
PyAEDT INFO: Ansoft.ElectronicsDesktop.2024.2 version started with process ID 4564.
PyAEDT INFO: Project Maxwell-Icepak-2way-Coupling has been created.
PyAEDT INFO: Added design '1 Maxwell' of type Maxwell 3D.
PyAEDT INFO: Aedt Objects correctly read
Units#
The default units are “mm”. Model units can be queried or changed using the property m3d.modeler.model_units
.
[5]:
print(f'Model units are "{m3d.modeler.model_units}"')
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 1sec
Model units are "mm"
Set up model#
Create the coil, coil terminal, core, and surrounding air region. The coil and core are created by drawing a rectangle and sweeping it about the z-axis.
[6]:
coil_origin = [70, 0, -11] # [x, y, z] position of the rectangle origin.
coil_xsection = [11, 110] # [z-size, x-size]
core_origin = [45, 0, -18]
core_xsection = [7, 160]
coil = m3d.modeler.create_rectangle(
orientation="XZ", origin=coil_origin, sizes=coil_xsection, name="Coil"
)
coil.sweep_around_axis(axis=AXIS.Z)
coil_terminal = m3d.modeler.create_rectangle(
orientation="XZ", origin=coil_origin, sizes=coil_xsection, name="Coil_terminal"
)
core = m3d.modeler.create_rectangle(
orientation="XZ", origin=core_origin, sizes=core_xsection, name="Core"
)
core.sweep_around_axis(axis=AXIS.Z)
# The air region should be sufficiently large to avoid interaction with the
# coil magnetic field.
region = m3d.modeler.create_region(pad_percent=[20, 20, 20, 20, 500, 100])
PyAEDT INFO: Materials class has been initialized! Elapsed time: 0m 0sec
Restore view#
If you are using PyAEDT with an interactive desktop, you may want to fit the visible view to fit the model. PyAEDT uses the direct access to the native API for this command using the property m3d.odesktop
.
Uncomment and run the following cell if you are running PyAEDT interactively and would like to automatically fit the window to the model.
[7]:
# desktop=m3d.odesktop.RestoreWindow() # Fit the active view
Create and assign material#
Define a new material for the AWG40 Litz wire copper strands:
Strand diameter = 0.08 mm
Number of parallel strands in the Litz wire = 24
The built-in material “ferrite” will be assigned to the core. The material “vacuum” will be assigned to the outer region.
You will also see the return value when True
printed when material is successfully assigned.
[8]:
no_strands = 24
strand_diameter = 0.08
cu_litz = m3d.materials.duplicate_material("copper", "copper_litz")
cu_litz.stacking_type = "Litz Wire"
cu_litz.wire_diameter = str(strand_diameter) + "mm"
cu_litz.wire_type = "Round"
cu_litz.strand_number = no_strands
m3d.assign_material(region.name, "vacuum")
m3d.assign_material(coil.name, "copper_litz")
m3d.assign_material(core.name, "ferrite")
[8]:
True
The coil carries 0.5 A and 20 turns.
[9]:
turns = 20
wire_current = 0.5
m3d.assign_coil(["Coil_terminal"], conductors_number=turns, name="Coil_terminal")
m3d.assign_winding(is_solid=False, current=wire_current * turns, name="Winding1")
m3d.add_winding_coils(assignment="Winding1", coils=["Coil_terminal"])
[9]:
True
Assign mesh operations#
Mesh “seeding” is used to retain solution accuracy and accelerate the auto-adaptive mesh refinement.
[10]:
m3d.mesh.assign_length_mesh(
["Core"], maximum_length=15, maximum_elements=None, name="Inside_Core"
)
m3d.mesh.assign_length_mesh(
["Coil"], maximum_length=30, maximum_elements=None, name="Inside_Coil"
)
PyAEDT INFO: Mesh class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Mesh class has been initialized! Elapsed time: 0m 0sec
[10]:
<ansys.aedt.core.modules.mesh.MeshOperation at 0x14a921acc40>
Set object temperature and enable feedback#
The impact of Joule heating on conductivity can be considered by adding a “thermal modifier” to the cu_litz
material definition. In this example, conductivity increases by 0.393% per \(\Delta\)K. The temperature of the objects is set to the default value (\(22^0\) C).
[11]:
cu_resistivity_temp_coefficient = 0.00393
cu_litz.conductivity.add_thermal_modifier_free_form(
"1.0/(1.0+{}*(Temp-20))".format(cu_resistivity_temp_coefficient)
)
m3d.modeler.set_objects_temperature(["Coil"], ambient_temperature=22)
PyAEDT INFO: Set model temperature and enabling Thermal Feedback
PyAEDT INFO: Assigned Objects Temperature
[11]:
True
Assign matrix#
The resistance and inductance calculations for the coil are enabled by adding the matrix assignment.
[12]:
m3d.assign_matrix(["Winding1"], matrix_name="Matrix1")
PyAEDT INFO: Infinite is the only return path option in EddyCurrent.
[12]:
<ansys.aedt.core.modules.boundary.MaxwellParameters at 0x14a921adb70>
Create the simulation setup#
The simulation frequency is 150 kHz. You can query and modify the properties of the simulation setup using setup.props
. The “PercentError” establishes the minimum allowed change in energy due to the change in mesh size and ensure a small global solution error.
[13]:
setup = m3d.create_setup(name="Setup1")
setup.props["Frequency"] = "150kHz"
setup.props["MaximumPasses"] = 4
setup.props["PercentError"] = 0.5
setup.props["MinimumConvergedPasses"] = 2
Run the Maxwell 3D analysis#
[14]:
m3d.analyze_setup("Setup1")
PyAEDT INFO: Key Desktop/ActiveDSOConfigurations/Maxwell 3D correctly changed.
PyAEDT INFO: Solving design setup Setup1
PyAEDT INFO: Key Desktop/ActiveDSOConfigurations/Maxwell 3D correctly changed.
PyAEDT INFO: Design setup Setup1 solved correctly in 0.0h 2.0m 10.0s
[14]:
True
Postprocessing#
The DC resistance of the coil can be calculated analyticially. The following cell compares the known DC resistance with the simulated coil resistance.
The values can be displayed in the AEDT “Message Manager”. The Ohmic loss in coil is calculated and displayed so we can see the change when Joule heating is considered.
[15]:
report = m3d.post.create_report(expressions="Matrix1.R(Winding1,Winding1)")
solution = report.get_solution_data()
resistance = solution.data_magnitude()[0] # Resistance is the first matrix element.
report_loss = m3d.post.create_report(expressions="StrandedLossAC")
solution_loss = report_loss.get_solution_data()
em_loss = solution_loss.data_magnitude()[0]
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmpx4s5dz2d.ansys/Maxwell-Icepak-2way-Coupling.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmpx4s5dz2d.ansys/Maxwell-Icepak-2way-Coupling.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.015631437301635742
PyAEDT INFO: PostProcessor class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Post class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Solution Data Correctly Loaded.
PyAEDT INFO: Solution Data Correctly Loaded.
[16]:
# Analytical calculation of the DC resistance of the coil
cu_cond = float(cu_litz.conductivity.value)
# Average radius of a coil turn = 125 mm
avg_coil_radius = (
coil_xsection[1] / 2 + coil_origin[0] / 2
) * 0.001 # Convert to meters
l_conductor = turns * 2 * avg_coil_radius * 3.1415
# R = resistivity * length / area / no_strand
r_analytic_DC = (
(1.0 / cu_cond)
* l_conductor
/ (3.1415 * (strand_diameter * 0.001 / 2) ** 2)
/ no_strands
)
# Print results in AEDT Message Manager
m3d.logger.info(f"*******Coil analytical DC resistance = {r_analytic_DC:.2f}Ohm")
m3d.logger.info(
f"*******Coil resistance at 150kHz BEFORE temperature feedback = {resistance:.2f}Ohm"
)
m3d.logger.info(
f"*******Ohmic loss in coil BEFORE temperature feedback = {em_loss / 1000:.2f}W"
)
PyAEDT INFO: *******Coil analytical DC resistance = 1.62Ohm
PyAEDT INFO: *******Coil resistance at 150kHz BEFORE temperature feedback = 2.26Ohm
PyAEDT INFO: *******Ohmic loss in coil BEFORE temperature feedback = 112.96W
Insert Icepak design#
The following commands insert an Icepak design into the AEDT project, copies the solid objects from Maxwell 3D, and modifies the region dimensions so they’re suitable for thermal convection analysis.
[17]:
ipk = ansys.aedt.core.Icepak(design=icepak_design_name, version=AEDT_VERSION)
ipk.copy_solid_bodies_from(m3d, no_pec=False)
# Set domain dimensions suitable for natural convection using the diameter of the coil
ipk.modeler["Region"].delete()
coil_dim = coil.bounding_dimension[0]
ipk.modeler.create_region(0, False)
ipk.modeler.edit_region_dimensions(
[coil_dim / 2, coil_dim / 2, coil_dim / 2, coil_dim / 2, coil_dim * 2, coil_dim]
)
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Returning found Desktop session with PID 4564!
PyAEDT INFO: No project is defined. Project Maxwell-Icepak-2way-Coupling exists and has been read.
PyAEDT INFO: Added design '2 Icepak' of type Icepak.
PyAEDT INFO: Aedt Objects correctly read
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Parsing design objects. This operation can take time
PyAEDT INFO: 3D Modeler objects parsed. Elapsed time: 0m 0sec
[17]:
True
Map coil losses#
Map ohmic losses from Maxwell 3D to the Icepak design.
[18]:
ipk.assign_em_losses(
design="1 Maxwell",
setup=m3d.setups[0].name,
sweep="LastAdaptive",
assignment=["Coil"],
)
PyAEDT INFO: Mapping EM losses.
PyAEDT INFO: EM losses mapped from design: 1 Maxwell.
[18]:
<ansys.aedt.core.modules.boundary.BoundaryObject at 0x14a921ae920>
Define boundary conditions#
Assign the opening in the Icepak model to allow free airflow.
[19]:
faces = ipk.modeler["Region"].faces
face_names = [face.id for face in faces]
ipk.assign_free_opening(face_names, boundary_name="Opening1")
[19]:
<ansys.aedt.core.modules.boundary.BoundaryObject at 0x14a921af7c0>
Assign monitor#
Assign a temperature monitor on the coil surface.
[20]:
temp_monitor = ipk.assign_point_monitor([70, 0, 0], monitor_name="PointMonitor1")
Set up Icepak solution
[21]:
solution_setup = ipk.create_setup()
solution_setup.props["Convergence Criteria - Max Iterations"] = 50
solution_setup.props["Flow Regime"] = "Turbulent"
solution_setup.props["Turbulent Model Eqn"] = "ZeroEquation"
solution_setup.props["Radiation Model"] = "Discrete Ordinates Model"
solution_setup.props["Include Flow"] = True
solution_setup.props["Include Gravity"] = True
solution_setup.props["Solution Initialization - Z Velocity"] = "0.0005m_per_sec"
solution_setup.props["Convergence Criteria - Flow"] = 0.0005
solution_setup.props["Flow Iteration Per Radiation Iteration"] = "5"
Add two-way coupling and solve the project#
The temperature update from Icepak to Maxwell 3D is activated using the method assign_2way_coupling()
. The Ohmic loss in Maxwell will change due to the temperature increase, which in turn will change the results from the Icepak simulation. By default, this iteration occurs twice. However, the named argument number_of_iterations
can be passed to the assign_2way_coupling
method to increase the number of iterations.
The full electro-thermal analysis is run by calling the analyze_setup()
method.
[22]:
ipk.assign_2way_coupling()
ipk.analyze_setup(name=solution_setup.name)
PyAEDT INFO: Key Desktop/ActiveDSOConfigurations/Icepak correctly changed.
PyAEDT INFO: Solving design setup Setup
PyAEDT INFO: Key Desktop/ActiveDSOConfigurations/Icepak correctly changed.
PyAEDT INFO: Design setup Setup solved correctly in 0.0h 3.0m 31.0s
[22]:
True
Postprocess#
Plot the temperature on object surfaces.
[23]:
surface_list = []
for name in ["Coil", "Core"]:
surface_list.extend(ipk.modeler.get_object_faces(name))
surf_temperature = ipk.post.create_fieldplot_surface(
surface_list, quantity="SurfTemperature", plot_name="Surface Temperature"
)
velocity_cutplane = ipk.post.create_fieldplot_cutplane(
assignment=["Global:XZ"], quantity="Velocity Vectors", plot_name="Velocity Vectors"
)
surf_temperature.export_image()
velocity_cutplane.export_image(orientation="right")
report_temp = ipk.post.create_report(
expressions="PointMonitor1.Temperature", primary_sweep_variable="X"
)
solution_temp = report_temp.get_solution_data()
temp = solution_temp.data_magnitude()[0]
m3d.logger.info("*******Coil temperature = {:.2f}deg C".format(temp))
PyAEDT INFO: PostProcessor class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Post class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Solution Data Correctly Loaded.
PyAEDT INFO: *******Coil temperature = 61.46deg C
Get new resistance from Maxwell 3D#
The temperature of the coil increases, and consequently the coil resistance increases.
[24]:
report_new = m3d.post.create_report(expressions="Matrix1.R(Winding1,Winding1)")
solution_new = report_new.get_solution_data()
resistance_new = solution_new.data_magnitude()[0]
resistance_increase = (resistance_new - resistance) / resistance * 100
report_loss_new = m3d.post.create_report(expressions="StrandedLossAC")
solution_loss_new = report_loss_new.get_solution_data()
em_loss_new = solution_loss_new.data_magnitude()[0]
m3d.logger.info(
"*******Coil resistance at 150kHz AFTER temperature feedback = {:.2f}Ohm".format(
resistance_new
)
)
m3d.logger.info(
"*******Coil resistance increased by {:.2f}%".format(resistance_increase)
)
m3d.logger.info(
"*******Ohmic loss in coil AFTER temperature feedback = {:.2f}W".format(
em_loss_new / 1000
)
)
PyAEDT INFO: Solution Data Correctly Loaded.
PyAEDT INFO: Solution Data Correctly Loaded.
PyAEDT INFO: *******Coil resistance at 150kHz AFTER temperature feedback = 2.56Ohm
PyAEDT INFO: *******Coil resistance increased by 13.31%
PyAEDT INFO: *******Ohmic loss in coil AFTER temperature feedback = 127.97W
Save project#
[25]:
ipk.save_project()
ipk.release_desktop()
time.sleep(3) # Allow AEDT to shut down before cleaning the temporary project folder.
PyAEDT INFO: Project Maxwell-Icepak-2way-Coupling Saved correctly
PyAEDT INFO: Desktop has been released and closed.
Clean up#
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.
[26]:
temp_folder.cleanup()
Download this example
Download this example as a Jupyter Notebook or as a Python script.