.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\03-Maxwell\Maxwell2D_Transient.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_Maxwell2D_Transient.py: Maxwell 2D: 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: - `Matplotlib `_ - `Numpty `_ - `PyVista `_ Install these libraries with: .. code:: pip install numpy pyvista matplotlib .. GENERATED FROM PYTHON SOURCE LINES 22-25 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports. .. GENERATED FROM PYTHON SOURCE LINES 25-29 .. code-block:: default import os import pyaedt .. GENERATED FROM PYTHON SOURCE LINES 30-34 Set non-graphical mode ~~~~~~~~~~~~~~~~~~~~~~ Set non-graphical mode. You can set ``non_graphical`` either to ``True`` or ``False``. .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: default non_graphical = False .. GENERATED FROM PYTHON SOURCE LINES 38-41 Insert Maxwell 2D design and save project ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Insert a Maxwell 2D design and save the project. .. GENERATED FROM PYTHON SOURCE LINES 41-45 .. code-block:: default maxwell_2d = pyaedt.Maxwell2d(solution_type="TransientXY", specified_version="2023.2", non_graphical=non_graphical, new_desktop_session=True, projectname=pyaedt.generate_unique_project_name()) .. rst-class:: sphx-glr-script-out .. code-block:: none Initializing new desktop! .. GENERATED FROM PYTHON SOURCE LINES 46-49 Create rectangle and duplicate it ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a rectangle and duplicate it. .. GENERATED FROM PYTHON SOURCE LINES 49-54 .. code-block:: default rect1 = maxwell_2d.modeler.create_rectangle([0, 0, 0], [10, 20], name="winding", matname="copper") added = rect1.duplicate_along_line([14, 0, 0]) rect2 = maxwell_2d.modeler[added[0]] .. GENERATED FROM PYTHON SOURCE LINES 55-58 Create air region ~~~~~~~~~~~~~~~~~ Create an air region. .. GENERATED FROM PYTHON SOURCE LINES 58-61 .. code-block:: default region = maxwell_2d.modeler.create_region([100, 100, 100, 100, 100, 100]) .. GENERATED FROM PYTHON SOURCE LINES 62-65 Assign windings and balloon ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Assigns windings to the sheets and a balloon to the air region. .. GENERATED FROM PYTHON SOURCE LINES 65-69 .. code-block:: default maxwell_2d.assign_winding([rect1.name, rect2.name], name="PHA") maxwell_2d.assign_balloon(region.edges) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 70-73 Plot model ~~~~~~~~~~ Plot the model. .. GENERATED FROM PYTHON SOURCE LINES 73-76 .. code-block:: default maxwell_2d.plot(show=False, export_path=os.path.join(maxwell_2d.working_directory, "Image.jpg"), plot_air_objects=True) .. image-sg:: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_Transient_001.png :alt: Maxwell2D Transient :srcset: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_Transient_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 77-80 Create setup ~~~~~~~~~~~~ Create the transient setup. .. GENERATED FROM PYTHON SOURCE LINES 80-89 .. code-block:: default 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" .. GENERATED FROM PYTHON SOURCE LINES 90-93 Create rectangular plot ~~~~~~~~~~~~~~~~~~~~~~~ Create a rectangular plot. .. GENERATED FROM PYTHON SOURCE LINES 93-98 .. code-block:: default maxwell_2d.post.create_report( "InputCurrent(PHA)", domain="Time", primary_sweep_variable="Time", plotname="Winding Plot 1" ) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 99-102 Solve model ~~~~~~~~~~~ Solve the model. .. GENERATED FROM PYTHON SOURCE LINES 102-105 .. code-block:: default maxwell_2d.analyze(use_auto_settings=False) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 106-109 Create output and plot using PyVista ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create the output and plot it using PyVista. .. GENERATED FROM PYTHON SOURCE LINES 109-136 .. code-block:: default cutlist = ["Global:XY"] face_lists = rect1.faces face_lists += rect2.faces timesteps = [str(i * 2e-4) + "s" for i in range(11)] id_list = [f.id for f in face_lists] animatedGif = maxwell_2d.post.plot_animated_field( "Mag_B", id_list, "Surface", intrinsics={"Time": "0s"}, variation_variable="Time", variation_list=timesteps, show=False, export_gif=False, ) animatedGif.isometric_view = False animatedGif.camera_position = [15, 15, 80] animatedGif.focal_point = [15, 15, 0] animatedGif.roll_angle = 0 animatedGif.elevation_angle = 0 animatedGif.azimuth_angle = 0 # Set off_screen to False to visualize the animation. # animatedGif.off_screen = False animatedGif.animate() .. image-sg:: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_Transient_002.png :alt: Maxwell2D Transient :srcset: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_Transient_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 137-140 Generate plot outside of AEDT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Generate the same plot outside AEDT. .. GENERATED FROM PYTHON SOURCE LINES 140-144 .. code-block:: default solutions = maxwell_2d.post.get_solution_data("InputCurrent(PHA)", primary_sweep_variable="Time") solutions.plot() .. image-sg:: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_Transient_003.png :alt: Simulation Results Plot :srcset: /examples/03-Maxwell/images/sphx_glr_Maxwell2D_Transient_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 145-148 Close AEDT ~~~~~~~~~~ Close AEDT. .. GENERATED FROM PYTHON SOURCE LINES 148-150 .. code-block:: default maxwell_2d.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 16.065 seconds) .. _sphx_glr_download_examples_03-Maxwell_Maxwell2D_Transient.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: Maxwell2D_Transient.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: Maxwell2D_Transient.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_