Enabling Control Program in a Maxwell 2D Project#

This example shows how you can use PyAEDT to enable control program in a Maxwell 2D project. It shows how to create the geometry, load material properties from an Excel file and set up the mesh settings. Moreover, it focuses on post-processing operations, in particular how to plot field line traces, relevant for an electrostatic analysis.

Perform required imports#

Perform required imports.

from pyaedt import downloads
from pyaedt import generate_unique_folder_name
from pyaedt import Maxwell2d

Set AEDT version#

Set AEDT version.

aedt_version = "2024.1"

Set non-graphical mode#

Set non-graphical mode. You can set non_graphical either to True or False.

non_graphical = False

Download .aedt file example#

Set local temporary folder to export the .aedt file to.

temp_folder = generate_unique_folder_name()
aedt_file = downloads.download_file("maxwell_ctrl_prg", "ControlProgramDemo.aedt", temp_folder)
ctrl_prg_file = downloads.download_file("maxwell_ctrl_prg", "timestep_only.py", temp_folder)

Launch Maxwell 2D#

Launch Maxwell 2D.

m2d = Maxwell2d(projectname=aedt_file,
                specified_version=aedt_version,
                new_desktop_session=True,
                non_graphical=non_graphical)
C:\actions-runner\_work\_tool\Python\3.10.9\x64\lib\subprocess.py:1072: ResourceWarning: subprocess 3084 is still running
  _warn("subprocess %s is still running" % self.pid,
C:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\generic\settings.py:383: ResourceWarning: unclosed file <_io.TextIOWrapper name='D:\\Temp\\pyaedt_ansys.log' mode='a' encoding='cp1252'>
  self._logger = val

Set active design#

Set active design.

m2d.set_active_design("1 time step control")
True

Get design setup#

Get design setup to enable the control program to.

setup = m2d.setups[0]

Enable control program#

Enable control program by giving the path to the file.

setup.enable_control_program(control_program_path=ctrl_prg_file)
True

Analyze setup#

Analyze setup.

setup.analyze()

Plot results#

Plot Solved Results.

sols = m2d.post.get_solution_data("FluxLinkage(Winding1)", variations={"Time":["All"]}, primary_sweep_variable="Time")
sols.plot()
Simulation Results Plot
No artists with labels found to put in legend.  Note that artists whose label start with an underscore are ignored when legend() is called with no argument.

<Figure size 2000x1000 with 1 Axes>

Save project and close AEDT#

Save the project and close AEDT.

m2d.save_project()
m2d.release_desktop()
True

Total running time of the script: (1 minutes 9.461 seconds)

Gallery generated by Sphinx-Gallery