.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\03-Maxwell\Maxwell_Control_Program.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_03-Maxwell_Maxwell_Control_Program.py: 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. .. GENERATED FROM PYTHON SOURCE LINES 11-14 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports. .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: Python from pyaedt import downloads from pyaedt.generic.general_methods import generate_unique_folder_name from pyaedt import Maxwell2d .. GENERATED FROM PYTHON SOURCE LINES 20-23 Set AEDT version ~~~~~~~~~~~~~~~~ Set AEDT version. .. GENERATED FROM PYTHON SOURCE LINES 23-26 .. code-block:: Python aedt_version = "2024.2" .. GENERATED FROM PYTHON SOURCE LINES 27-31 Set non-graphical mode ~~~~~~~~~~~~~~~~~~~~~~ Set non-graphical mode. You can set ``non_graphical`` either to ``True`` or ``False``. .. GENERATED FROM PYTHON SOURCE LINES 31-34 .. code-block:: Python non_graphical = False .. GENERATED FROM PYTHON SOURCE LINES 35-38 Download .aedt file example ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Set local temporary folder to export the .aedt file to. .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 43-46 Launch Maxwell 2D ~~~~~~~~~~~~~~~~~ Launch Maxwell 2D. .. GENERATED FROM PYTHON SOURCE LINES 46-52 .. code-block:: Python m2d = Maxwell2d(project=aedt_file, version=aedt_version, new_desktop=True, non_graphical=non_graphical) .. rst-class:: sphx-glr-script-out .. code-block:: none C:\actions-runner\_work\_tool\Python\3.10.9\x64\lib\subprocess.py:1072: ResourceWarning: subprocess 2160 is still running _warn("subprocess %s is still running" % self.pid, C:\actions-runner\_work\pyaedt\pyaedt\.venv\lib\site-packages\pyaedt\generic\settings.py:437: ResourceWarning: unclosed file <_io.TextIOWrapper name='D:\\Temp\\pyaedt_ansys_e6365f2f-3b8c-40bb-8a68-3f4e6e7c8dd5.log' mode='a' encoding='cp1252'> self._logger = val .. GENERATED FROM PYTHON SOURCE LINES 53-56 Set active design ~~~~~~~~~~~~~~~~~ Set active design. .. GENERATED FROM PYTHON SOURCE LINES 56-59 .. code-block:: Python m2d.set_active_design("1 time step control") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 60-63 Get design setup ~~~~~~~~~~~~~~~~ Get design setup to enable the control program to. .. GENERATED FROM PYTHON SOURCE LINES 63-66 .. code-block:: Python setup = m2d.setups[0] .. GENERATED FROM PYTHON SOURCE LINES 67-70 Enable control program ~~~~~~~~~~~~~~~~~~~~~~ Enable control program by giving the path to the file. .. GENERATED FROM PYTHON SOURCE LINES 70-73 .. code-block:: Python setup.enable_control_program(control_program_path=ctrl_prg_file) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 74-77 Analyze setup ~~~~~~~~~~~~~ Analyze setup. .. GENERATED FROM PYTHON SOURCE LINES 77-81 .. code-block:: Python setup.analyze() .. GENERATED FROM PYTHON SOURCE LINES 82-85 Plot results ~~~~~~~~~~~~ Plot Solved Results. .. GENERATED FROM PYTHON SOURCE LINES 85-89 .. code-block:: Python sols = m2d.post.get_solution_data("FluxLinkage(Winding1)", variations={"Time":["All"]}, primary_sweep_variable="Time") sols.plot() .. image-sg:: /examples/03-Maxwell/images/sphx_glr_Maxwell_Control_Program_001.png :alt: Simulation Results Plot :srcset: /examples/03-Maxwell/images/sphx_glr_Maxwell_Control_Program_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 90-93 Save project and close AEDT ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Save the project and close AEDT. .. GENERATED FROM PYTHON SOURCE LINES 93-96 .. code-block:: Python m2d.save_project() m2d.release_desktop() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 1.891 seconds) .. _sphx_glr_download_examples_03-Maxwell_Maxwell_Control_Program.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Maxwell_Control_Program.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Maxwell_Control_Program.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_