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)

Launch AEDT in Graphical Mode

This examples launches AEDT 2021.2 in graphical mode.

m3d = Maxwell3d(specified_version="2021.2", new_desktop_session=True)

Out:

Launching PyAEDT outside Electronics Desktop with CPython and Pythonnet
Launching AEDT installation C:\Program Files\AnsysEM\AnsysEM21.2\Win64
===================================================================================
pyaedt info: Launching AEDT with module Pythonnet.
pyaedt info: Ansoft.ElectronicsDesktop.2021.2 Started with process ID 9392.
pyaedt info: Logger Started on C:\Users\ansys\Documents\Ansoft\pyaedt20220120_154240.log
pyaedt info: pyaedt v0.5.dev1
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 Project2596 has been created.
pyaedt info: No design is present. Inserting a new design.
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.primitives.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)
Maxwell Magnet

Out:

<pyaedt.modules.AdvancedPostProcessing.ModelPlotter object at 0x000001D06205FB80>

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.

xval = m3d.post.get_scalar_field_value("CM_X", None)
yval = m3d.post.get_scalar_field_value("CM_Y", None)
zval = m3d.post.get_scalar_field_value("CM_Z", None)

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.

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

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: Saving Project2596 Project

True

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

Gallery generated by Sphinx-Gallery