Download this example

Download this example as a Jupyter Notebook or as a Python script.


2D Axi-symmetric Actuator#

This example demonstrates how to leverage both: axi-symmetry and the magnetostatic solver to calculate the forces experienced by the anchor of an actuator due to change in current and anchor location

Keywords: Maxwell2D, axi-symmetry magnetostatic, translational motion, parametric sweep, installation example

Prerequisites#

Perform imports#

[1]:
import os
import tempfile
import time

import ansys.aedt.core  # Interface to Ansys Electronics Desktop

Define constants#

Constants help ensure consistency and avoid repetition throughout the example.

[2]:
AEDT_VERSION = "2025.1"
NUM_CORES = 4
NG_MODE = False  # Open AEDT UI when it is launched.

Create temporary directory#

Create a temporary working directory. The name of the working folder is stored in temp_folder.name.

Note: The final cell in the notebook cleans up the temporary folder. If you want to retrieve the AEDT project and data, do so before executing the final cell in the notebook.

[3]:
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

Launch Maxwell 2d#

Create an instance of the Maxwell2d class. The Ansys Electronics Desktop will be launched with an active Maxwell2D design. The m2d object is subsequently used to create and simulate the actuator model.

[4]:
project_name = os.path.join(temp_folder.name, "2d_axi_magsta_actuator.aedt")
m2d = ansys.aedt.core.Maxwell2d(
    project=project_name,
    solution_type="MagnetostaticZ",
    version=AEDT_VERSION,
    non_graphical=NG_MODE,
    new_desktop=True,
)
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)].
PyAEDT INFO: PyAEDT version 0.17.dev0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_4af5d215-243c-473d-af6b-cc3b13b3a967.log is enabled.
PyAEDT INFO: Log on AEDT is disabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: New AEDT session is starting on gRPC port 55186.
PyAEDT INFO: Electronics Desktop started on gRPC port: 55186 after 6.82410454750061 seconds.
PyAEDT INFO: AEDT installation Path C:\Program Files\ANSYS Inc\v251\AnsysEM
PyAEDT INFO: Ansoft.ElectronicsDesktop.2025.1 version started with process ID 10232.
PyAEDT INFO: Project 2d_axi_magsta_actuator has been created.
PyAEDT INFO: No design is present. Inserting a new design.
PyAEDT INFO: Added design 'Maxwell 2D_9Z5' of type Maxwell 2D.
PyAEDT INFO: Aedt Objects correctly read

Model Preparation#

Define actuator’s housing point location#

The actuator’s housing is built using line segments for readability and reusability we define the points as a python’s list of lists, where each sublist defines an x-, y-, z-coordinate. (e.g., [[x1,y1,z1],…,[xn,yn,zn]].

[5]:
points_housing = [
    [0, 0, 0],
    [0, 0, -10],
    [12, 0, -10],
    [12, 0, 10],
    [2.5, 0, 10],
    [2.5, 0, 8],
    [10, 0, 8],
    [10, 0, -8],
    [2, 0, -8],
    [2, 0, 0],
]

Declare and initialize design parameters#

[6]:
m2d.modeler.model_units = "mm"  # Global units used in geometry creation
m2d["Amp_1"] = "1000A"  # Net current applied to coil
m2d["move"] = "0mm"  # Displacement applied to anchor
PyAEDT INFO: Modeler2D class has been initialized!
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 1sec

Create 2D model#

Build coil, anchor and housing geometries

[7]:
coil_m = m2d.modeler.create_rectangle(
    origin=["3mm", "0mm", "7mm"], sizes=[-14, 6], name="Coil", material="Copper"
)
anchor_m = m2d.modeler.create_rectangle(
    origin=["0mm", "0mm", "13mm - move"],
    sizes=[-8, 2],
    name="Anchor",
    material="steel_1008",
)
housing_m = m2d.modeler.create_polyline(
    points_housing, close_surface=True, name="Housing", material="steel_1008"
)
m2d.modeler.cover_lines(housing_m)
PyAEDT INFO: Materials class has been initialized! Elapsed time: 0m 0sec
[7]:
True

Create surrounding vacuum domain

[8]:
region_m = m2d.modeler.create_region(pad_percent=100)
region_m.material_name = "vacuum"

Fit all geometrical entities into the modeler’s window

[9]:
m2d.modeler.fit_all()

Assign boundary conditions#

Apply zero magnetic vector potential on the region edges that the field only has a tangential component at the edge of the surrounding domain/region

[10]:
m2d.assign_vector_potential(assignment=region_m.edges, boundary="VectorPotential1")
PyAEDT INFO: Boundary Vector Potential VectorPotential1 has been created.
[10]:
<ansys.aedt.core.modules.boundary.common.BoundaryObject at 0x1763d6f34f0>

Assign Excitation#

Create a current driven coil by applying a current excitation in the coil domain

[11]:
m2d.assign_current(assignment=coil_m.name, amplitude="Amp_1", name="Current1")
PyAEDT INFO: Boundary Current Current1 has been created.
[11]:
<ansys.aedt.core.modules.boundary.common.BoundaryObject at 0x1764ec76c20>

Enable force calculation on the anchor#

[12]:
m2d.assign_force(
    assignment=anchor_m,
    force_name="Force",
)
PyAEDT INFO: Boundary Force Force has been created.
[12]:
<ansys.aedt.core.modules.boundary.maxwell_boundary.MaxwellParameters at 0x1763d6f3610>

Define solution setup#

[13]:
setup = m2d.create_setup("MySetup")
print(setup.props)
setup.props["MaximumPasses"] = 15
setup.props["PercentRefinement"] = 30
setup.props["PercentError"] = 0.1
setup.props["MinimumPasses"] = 2
setup.props["RelativeResidual"] = 1e-6
{'Enabled': True, 'MeshLink': {'ImportMesh': False}, 'MaximumPasses': 10, 'MinimumPasses': 2, 'MinimumConvergedPasses': 1, 'PercentRefinement': 30, 'SolveFieldOnly': False, 'PercentError': 1, 'SolveMatrixAtLast': True, 'UseIterativeSolver': False, 'RelativeResidual': 1e-06, 'NonLinearResidual': 0.001, 'SmoothBHCurve': False, 'MuOption': {'MuNonLinearBH': True}, 'Name': 'MySetup'}

Create variable/parameter sweeps#

Enable sweeps over coil net current and anchor displacement

[14]:
value_sweep = m2d.parametrics.add(
    "Amp_1", 500, 2000, 500, name="ParametricSetup1", variation_type="LinearStep"
)
value_sweep.add_variation("move", 0, 4, 1, variation_type="LinearStep")
#
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmpdq8fiaw1.ansys/2d_axi_magsta_actuator.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmpdq8fiaw1.ansys/2d_axi_magsta_actuator.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.015618562698364258
[14]:
True

Run analysis#

[15]:
value_sweep.analyze(cores=NUM_CORES)
PyAEDT INFO: Key Desktop/ActiveDSOConfigurations/Maxwell 2D correctly changed.
PyAEDT INFO: Solving Optimetrics
PyAEDT INFO: Key Desktop/ActiveDSOConfigurations/Maxwell 2D correctly changed.
PyAEDT INFO: Design setup ParametricSetup1 solved correctly in 0.0h 2.0m 49.0s
[15]:
True

Postprocess#

Create a Force vs. move (displacement) Report/Plot for every current value

[16]:
m2d.post.create_report(
    expressions=["Force.Force_z"],
    variations={"Amp_1": "All", "move": "All"},
    plot_name="Force Plot 1",
    primary_sweep_variable="move",
    plot_type="Rectangular Plot",
)
PyAEDT INFO: PostProcessor class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: PostProcessor class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Post class has been initialized! Elapsed time: 0m 0sec
[16]:
<ansys.aedt.core.visualization.report.standard.Standard at 0x1764f991cc0>

Finish#

Save the project#

[17]:
m2d.save_project()
m2d.release_desktop()
# Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory.
time.sleep(3)
PyAEDT INFO: Project 2d_axi_magsta_actuator Saved correctly
PyAEDT INFO: Desktop has been released and closed.

Clean up#

All project files are saved in the folder temp_folder.name. If you’ve run this example as a Jupyter notebook, you can retrieve those project files. The following cell removes all temporary files, including the project folder.

[18]:
temp_folder.cleanup()

Download this example

Download this example as a Jupyter Notebook or as a Python script.