Maxwell 2D Analysis

This example shows how you can use PyAEDT to create a project in Maxwell 2D and run a transient simulation. It runs only on Windows using CPython.

The following libraries are required for the advanced postprocessing features used in this example:

Install these with:

pip install numpy pyvista matplotlib
import os
from pyaedt import Maxwell2d

Launch AEDT in Graphical Mode

You change the Boolean parameter non_graphical to False to launch AEDT in graphical mode.

Insert a Maxwell 2D Design and Save the Project

This example inserts a Maxwell 2D design and then saves the project.

maxwell_2d = Maxwell2d(solution_type="TransientXY", specified_version="2021.1", non_graphical=non_graphical)
project_dir = maxwell_2d.generate_temp_project_directory("Example")
maxwell_2d.save_project(os.path.join(project_dir, "M2d.aedt"))

Out:

Launching PyAEDT outside Electronics Desktop with CPython and Pythonnet
Launching AEDT installation C:\Program Files\AnsysEM\AnsysEM21.1\Win64
===================================================================================
pyaedt info: Launching AEDT with module Pythonnet.
pyaedt info:: Ansoft.ElectronicsDesktop.2021.1 Started with process ID 7900.
pyaedt info: Logger Started on C:\Users\ansys\Documents\Ansoft\pyaedt20211026_151540.log
pyaedt info: pyaedt v0.4.0
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 Project6077 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
pyaedt info: Saving Project6077 Project

True

Create a Rectangle and Duplicate It

This example creates a rectangle and then duplicates it.

rect1 = maxwell_2d.modeler.primitives.create_rectangle([0, 0, 0], [20, 10], "Rectangle1", "copper")
added = rect1.duplicate_along_line([14, 0, 0])
rect2 = maxwell_2d.modeler.primitives[added[0]]

Out:

pyaedt.generic.LoadAEDTFile._read_aedt_file: 0.0s
pyaedt info: AEDT Load time 0.0

Create an Air Region

This command creates an air region.

region = maxwell_2d.modeler.primitives.create_region([100, 100, 100, 100, 100, 100])

Assign Windings to Sheets and a Balloon to the Air Region

This example assigns windings to shhets and a balloon too the air region.

maxwell_2d.assign_winding([rect1.name, rect2.name], name="PHA")
maxwell_2d.assign_balloon(region.edges)

Out:

<pyaedt.modules.Boundary.BoundaryObject object at 0x000001CD71F0B790>

Add a Transient Setup

This example adds a transient setup.

setup = maxwell_2d.create_setup()
setup.props["StopTime"] = "0.02s"
setup.props["TimeStep"] = "0.0002s"
setup.props["SaveFieldsType"] = "Every N Steps"
setup.props["N Steps"] = "1"
setup.props["Steps From"] = "0s"
setup.props["Steps To"] = "0.002s"
setup.update()

Out:

True

Create a Rectangular Plot

This command creates a rectangular plot.

maxwell_2d.post.create_rectangular_plot(
    "InputCurrent(PHA)", primary_sweep_variable="Time", families_dict={"Time": ["All"]}, plotname="Winding Plot 1"
)

Out:

pyaedt info: Report Winding Plot 1 correctly created.

True

Solve the Model

This command solves the model.

maxwell_2d.analyze_nominal()

Out:

pyaedt info: Solving design setup MySetupAuto
pyaedt info: Key Desktop/ActiveDSOConfigurations/Maxwell 2D correctly changed.
pyaedt error: Error in Solving Setup MySetupAuto
Error in Solving Setup MySetupAuto

False

Create the Output and Plot It Using PyVista

This example creates the output and then plots it using PyVista.

import time

start = time.time()
cutlist = ["Global:XY"]
face_lists = rect1.faces
face_lists += rect2.faces
timesteps = [str(i * 1e-3) + "s" for i in range(21)]
id_list = [f.id for f in face_lists]
# animatedGif=maxwell_2d.post.animate_fields_from_aedtplt_2(
#   "Mag_B",
#   id_list,
#   "Surface",
#   intrinsic_dict={'Time': '0s'},
#   variation_variable="Time",
#   variation_list=timesteps,
#   off_screen=True,
#   export_gif=True
# )

Close AEDT

This command closes AEDT.

maxwell_2d.close_desktop()

Out:

True

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

Gallery generated by Sphinx-Gallery