Note
Click here to download the full example code
Maxwell 3d: Magnet DC Analysis#
This example shows how you can use PyAEDT to create a Maxwell DC Analysis, compute mass center and move Coordinate Systems.
from pyaedt import Maxwell3d
import os
import tempfile
tmpfold = tempfile.gettempdir()
if not os.path.exists(tmpfold):
os.mkdir(tmpfold)
Set Non Graphical Mode. Default is False
non_graphical = os.getenv("PYAEDT_NON_GRAPHICAL", "False").lower() in ("true", "1", "t")
Launch AEDT in Graphical Mode#
This examples launches AEDT 2022R2 in graphical mode.
m3d = Maxwell3d(specified_version="2022.2", new_desktop_session=True, non_graphical=non_graphical)
Out:
pyaedt info: Logger Started
pyaedt info: Launching PyAEDT outside Electronics Desktop with CPython and Pythonnet
pyaedt info: AEDT installation Path C:\Program Files\AnsysEM\v222\Win64.
pyaedt info: Launching AEDT with module Pythonnet.
pyaedt info: Ansoft.ElectronicsDesktop.2022.2 Started with process ID 10676.
pyaedt info: Logger file D:\Temp\pyaedt20220624_103520.log in use.
pyaedt info: pyaedt v0.4.87
pyaedt info: Python version 3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
pyaedt info: Project Project4 has been created.
pyaedt info: No design is present. Inserting a new design.
pyaedt info: Added design 'Maxwell 3D_U9B' of type Maxwell 3D.
pyaedt info: Design Loaded
pyaedt info: Successfully loaded project materials !
pyaedt info: Materials Loaded
Setup Maxwell Solution#
Setup Maxwell Solution to DC.
m3d.solution_type = m3d.SOLUTIONS.Maxwell3d.ElectroDCConduction
Create Magnet#
magnet = m3d.modeler.create_box([7, 4, 22], [10, 5, 30], name="Magnet", matname="copper")
Create Setup and Assign Voltage#
m3d.assign_voltage(magnet.faces, 0)
m3d.create_setup()
Out:
SetupName MySetupAuto with 0 Sweeps
Plot the model#
m3d.plot(show=False, export_path=os.path.join(m3d.working_directory, "Image.jpg"), plot_air_objects=True)

Out:
<pyaedt.generic.plot.ModelPlotter object at 0x00000185FF7B14C0>
Solve Setup#
m3d.analyze_nominal()
Out:
pyaedt info: Solving design setup MySetupAuto
pyaedt info: Design setup MySetupAuto solved correctly
True
Compute Mass Center#
Field Calculator is used to compute mass center.
m3d.post.ofieldsreporter.EnterScalarFunc("X")
m3d.post.ofieldsreporter.EnterVol(magnet.name)
m3d.post.ofieldsreporter.CalcOp("Mean")
m3d.post.ofieldsreporter.AddNamedExpression("CM_X", "Fields")
m3d.post.ofieldsreporter.EnterScalarFunc("Y")
m3d.post.ofieldsreporter.EnterVol(magnet.name)
m3d.post.ofieldsreporter.CalcOp("Mean")
m3d.post.ofieldsreporter.AddNamedExpression("CM_Y", "Fields")
m3d.post.ofieldsreporter.EnterScalarFunc("Z")
m3d.post.ofieldsreporter.EnterVol(magnet.name)
m3d.post.ofieldsreporter.CalcOp("Mean")
m3d.post.ofieldsreporter.AddNamedExpression("CM_Z", "Fields")
m3d.post.ofieldsreporter.CalcStack("clear")
Get Mass Center#
Field Calculator is used to get mass center.
Out:
pyaedt info: Exporting CM_X field. Be patient
pyaedt info: Quantity CM_X not present. Trying to get it from Stack
pyaedt info: Exporting CM_Y field. Be patient
pyaedt info: Quantity CM_Y not present. Trying to get it from Stack
pyaedt info: Exporting CM_Z field. Be patient
pyaedt info: Quantity CM_Z not present. Trying to get it from Stack
Create Variables#
Variables will be created with Mass Center values.
Create Coordinate System#
Parametric Coordinate System is created
cs1 = m3d.modeler.create_coordinate_system(
[magnet.name + "x", magnet.name + "y", magnet.name + "z"], reference_cs="Global", name=magnet.name + "CS"
)
Save and Close#
m3d.save_project(os.path.join(tmpfold, "magnet.aedt"))
m3d.release_desktop(close_projects=True, close_desktop=True)
Out:
pyaedt info: Project magnet Saved correctly
True
Total running time of the script: ( 0 minutes 33.879 seconds)