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.

Perform required imports#

Perform required imports.

from pyaedt import Maxwell3d
from pyaedt import generate_unique_project_name
import os
import tempfile

Create temporary directory#

Create temporary directory.

Set non-graphical mode#

Set non-graphical mode. You can set non_graphical either to True or False.

non_graphical = False

Launch AEDT#

Launch AEDT in graphical mode.

m3d = Maxwell3d(projectname=generate_unique_project_name(),
Initializing new desktop!
C:\actions-runner\_work\_tool\Python\3.10.5\x64\lib\ ResourceWarning: subprocess 10760 is still running
  _warn("subprocess %s is still running" %,

Set up Maxwell solution#

Set up the Maxwell solution to DC.

m3d.solution_type = m3d.SOLUTIONS.Maxwell3d.ElectroDCConduction

Create magnet#

Create a magnet.

magnet = m3d.modeler.create_box(position=[7, 4, 22], dimensions_list=[10, 5, 30], name="Magnet", matname="copper")

Create setup and assign voltage#

Create the setup and assign a voltage.

m3d.assign_voltage(magnet.faces, 0)
SetupName MySetupAuto with 0 Sweeps

Plot model#

Plot the model.

m3d.plot(show=False, export_path=os.path.join(, "Image.jpg"), plot_air_objects=True)
Maxwell Magnet
<pyaedt.generic.plot.ModelPlotter object at 0x0000026980EF1E40>

Solve setup#

Solve the setup.


Compute mass center#

Compute mass center using the fields calculator."X")"Mean")"CM_X", "Fields")"Y")"Mean")"CM_Y", "Fields")"Z")"Mean")"CM_Z", "Fields")"clear")

Get mass center#

Get mass center using the fields calculator.

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

Create variables#

Create variables 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#

Create a parametric coordinate system.

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

Save and close#

Save the project and close AEDT.

m3d.release_desktop(close_projects=True, close_desktop=True)

Total running time of the script: (1 minutes 15.327 seconds)

Gallery generated by Sphinx-Gallery