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

Set non-graphical mode#

Set non-graphical mode. "PYAEDT_NON_GRAPHICAL" is needed to generate documentation only. You can set non_graphical either to True or False.

non_graphical = os.getenv("PYAEDT_NON_GRAPHICAL", "False").lower() in ("true", "1", "t")

Launch AEDT#

Launch AEDT 2022 R2 in graphical mode.

m3d = Maxwell3d(projectname=generate_unique_project_name(),

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(m3d.working_directory, "Image.jpg"), plot_air_objects=True)
Maxwell Magnet
<pyaedt.generic.plot.ModelPlotter object at 0x0000028B82240D90>

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", None)
yval ="CM_Y", None)
zval ="CM_Z", None)

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: ( 0 minutes 35.534 seconds)

Gallery generated by Sphinx-Gallery