Transient Winding 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.2", 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.2\Win64
===================================================================================
pyaedt info: Launching AEDT with module Pythonnet.
pyaedt info: Ansoft.ElectronicsDesktop.2021.2 Started with process ID 3408.
pyaedt info: Logger Started on C:\Users\ansys\Documents\Ansoft\pyaedt20220120_154011.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
pyaedt info: Saving Project2596 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], [10, 20], name="winding", matname="copper")
added = rect1.duplicate_along_line([14, 0, 0])
rect2 = maxwell_2d.modeler.primitives[added[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 0x000001D051ED0E80>

Plot the model

maxwell_2d.plot(show=False, export_path=os.path.join(maxwell_2d.working_directory, "Image.jpg"), plot_air_objects=True)
Maxwell2D Transient

Out:

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

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: Design setup MySetupAuto solved correctly

True

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,
    show=False,
    export_gif=True,
)
Maxwell2D Transient

Out:

pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
pyaedt error: Method create Failed:  General or AEDT Error. Please Check again
Method create Failed:  General or AEDT Error. Please Check again
pyaedt error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
(-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024381), None)
pyaedt error: Arguments Provided:
Arguments Provided:
pyaedt error: Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
Error in :   File "C:\actions-runner\_work\PyAEDT\PyAEDT\pyaedt\modules\PostProcessor.py", line 772, in create
pyaedt error: Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create
Check Online documentation on: https://aedtdocs.pyansys.com/search.html?q=create

Close AEDT

This command closes AEDT.

maxwell_2d.release_desktop()

Out:

True

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

Gallery generated by Sphinx-Gallery