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):

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)


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)


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)
Maxwell Magnet


<pyaedt.generic.plot.ModelPlotter object at 0x00000185FF7B14C0>

Solve Setup#



pyaedt info: Solving design setup MySetupAuto
pyaedt info: Design setup MySetupAuto solved correctly


Compute Mass Center#

Field Calculator is used to compute mass center."X")"Mean")"CM_X", "Fields")"Y")"Mean")"CM_Y", "Fields")"Z")"Mean")"CM_Z", "Fields")"clear")

Get Mass Center#

Field Calculator is used to get mass center.

xval ="CM_X", None)
yval ="CM_Y", None)
zval ="CM_Z", None)


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.

m3d[ + "x"] = str(xval * 1e3) + "mm"
m3d[ + "y"] = str(yval * 1e3) + "mm"
m3d[ + "z"] = str(zval * 1e3) + "mm"

Create Coordinate System#

Parametric Coordinate System is created

cs1 = m3d.modeler.create_coordinate_system(
    [ + "x", + "y", + "z"], reference_cs="Global", + "CS"

Save and Close#

m3d.save_project(os.path.join(tmpfold, "magnet.aedt"))
m3d.release_desktop(close_projects=True, close_desktop=True)


pyaedt info: Project magnet Saved correctly


Total running time of the script: ( 0 minutes 33.879 seconds)

Gallery generated by Sphinx-Gallery