.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples\07-Circuit\Circuit_Example.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_07-Circuit_Circuit_Example.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_07-Circuit_Circuit_Example.py:


Circuit: schematic creation and analysis
----------------------------------------
This example shows how you can use PyAEDT to create a circuit design
and run a Nexxim time-domain simulation.

.. GENERATED FROM PYTHON SOURCE LINES 8-11

Perform required imports
~~~~~~~~~~~~~~~~~~~~~~~~
Perform required imports.

.. GENERATED FROM PYTHON SOURCE LINES 11-16

.. code-block:: Python


    # sphinx_gallery_thumbnail_path = 'Resources/circuit.png'

    import pyaedt








.. GENERATED FROM PYTHON SOURCE LINES 17-20

Set AEDT version
~~~~~~~~~~~~~~~~
Set AEDT version.

.. GENERATED FROM PYTHON SOURCE LINES 20-23

.. code-block:: Python


    aedt_version = "2024.1"








.. GENERATED FROM PYTHON SOURCE LINES 24-30

Set non-graphical mode
~~~~~~~~~~~~~~~~~~~~~~
Set non-graphical mode. 
You can set ``non_graphical`` either to ``True`` or ``False``.
The Boolean parameter ``new_thread`` defines whether to create a new instance
of AEDT or try to connect to an existing instance of it.

.. GENERATED FROM PYTHON SOURCE LINES 30-34

.. code-block:: Python


    non_graphical = False
    new_thread = True








.. GENERATED FROM PYTHON SOURCE LINES 35-39

Launch AEDT and Circuit
~~~~~~~~~~~~~~~~~~~~~~~
Launch AEDT and Circuit. The :class:`pyaedt.Desktop` class initializes AEDT and
starts the specified version in the specified mode.

.. GENERATED FROM PYTHON SOURCE LINES 39-43

.. code-block:: Python


    desktop = pyaedt.launch_desktop(aedt_version, non_graphical, new_thread)
    aedt_app = pyaedt.Circuit(projectname=pyaedt.generate_unique_project_name())
    aedt_app.modeler.schematic.schematic_units = "mil"




.. 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 1108 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:383: ResourceWarning: unclosed file <_io.TextIOWrapper name='D:\\Temp\\pyaedt_ansys.log' mode='a' encoding='cp1252'>
      self._logger = val




.. GENERATED FROM PYTHON SOURCE LINES 44-47

Create circuit setup
~~~~~~~~~~~~~~~~~~~~
Create and customize an LNA (linear network analysis) setup.

.. GENERATED FROM PYTHON SOURCE LINES 47-51

.. code-block:: Python


    setup1 = aedt_app.create_setup("MyLNA")
    setup1.props["SweepDefinition"]["Data"] = "LINC 0GHz 4GHz 10001"








.. GENERATED FROM PYTHON SOURCE LINES 52-55

Create components
~~~~~~~~~~~~~~~~~
Create components, such as an inductor, resistor, and capacitor.

.. GENERATED FROM PYTHON SOURCE LINES 55-60

.. code-block:: Python


    inductor = aedt_app.modeler.schematic.create_inductor(name="L1", value=1e-9, location=[0, 0])
    resistor = aedt_app.modeler.schematic.create_resistor(name="R1", value=50, location=[500, 0])
    capacitor = aedt_app.modeler.schematic.create_capacitor(name="C1", value=1e-12, location=[1000, 0])








.. GENERATED FROM PYTHON SOURCE LINES 61-64

Get all pins
~~~~~~~~~~~~
Get all pins of a specified component.

.. GENERATED FROM PYTHON SOURCE LINES 64-67

.. code-block:: Python


    pins_resistor = resistor.pins








.. GENERATED FROM PYTHON SOURCE LINES 68-71

Create port and ground
~~~~~~~~~~~~~~~~~~~~~~
Create a port and a ground, which are needed for the circuit analysis.

.. GENERATED FROM PYTHON SOURCE LINES 71-75

.. code-block:: Python


    port = aedt_app.modeler.components.create_interface_port(name="myport", location=[-200, 0] )
    gnd = aedt_app.modeler.components.create_gnd(location=[1200, -100])








.. GENERATED FROM PYTHON SOURCE LINES 76-79

Connect components
~~~~~~~~~~~~~~~~~~
Connect components with wires.

.. GENERATED FROM PYTHON SOURCE LINES 79-85

.. code-block:: Python


    port.pins[0].connect_to_component(assignment=inductor.pins[0], use_wire=True)
    inductor.pins[1].connect_to_component(assignment=resistor.pins[1], use_wire=True)
    resistor.pins[0].connect_to_component(assignment=capacitor.pins[0], use_wire=True)
    capacitor.pins[1].connect_to_component(assignment=gnd.pins[0], use_wire=True)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 86-89

Create transient setup
~~~~~~~~~~~~~~~~~~~~~~
Create a transient setup.

.. GENERATED FROM PYTHON SOURCE LINES 89-94

.. code-block:: Python


    setup2 = aedt_app.create_setup(name="MyTransient", setup_type=aedt_app.SETUPS.NexximTransient)
    setup2.props["TransientData"] = ["0.01ns", "200ns"]
    setup3 = aedt_app.create_setup(name="MyDC", setup_type=aedt_app.SETUPS.NexximDC)








.. GENERATED FROM PYTHON SOURCE LINES 95-98

Solve transient setup
~~~~~~~~~~~~~~~~~~~~~
Solve the transient setup.

.. GENERATED FROM PYTHON SOURCE LINES 98-102

.. code-block:: Python


    aedt_app.analyze_setup("MyLNA")
    aedt_app.export_fullwave_spice()





.. rst-class:: sphx-glr-script-out

 .. code-block:: none


    'D:/Temp/pyaedt_prj_TXW/Project_Q2D.pyaedt\\Circuit_Design_FHS\\Circuit Design_FHS.sp'



.. GENERATED FROM PYTHON SOURCE LINES 103-106

Create report
~~~~~~~~~~~~~
Create a report that plots solution data.

.. GENERATED FROM PYTHON SOURCE LINES 106-112

.. code-block:: Python


    solutions = aedt_app.post.get_solution_data(expressions=aedt_app.get_traces_for_plot(category="S"))
    solutions.enable_pandas_output = True
    real, imag = solutions.full_matrix_real_imag
    print(real)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

            S(myport,myport)
    0.0000          1.000000
    0.0004          1.000000
    0.0008          1.000000
    0.0012          0.999999
    0.0016          0.999999
    ...                  ...
    3.9984          0.021101
    3.9988          0.021083
    3.9992          0.021065
    3.9996          0.021046
    4.0000          0.021028

    [10001 rows x 1 columns]




.. GENERATED FROM PYTHON SOURCE LINES 113-116

Plot data
~~~~~~~~~
Create a plot based on solution data.

.. GENERATED FROM PYTHON SOURCE LINES 116-119

.. code-block:: Python


    fig = solutions.plot()




.. image-sg:: /examples/07-Circuit/images/sphx_glr_Circuit_Example_001.png
   :alt: Simulation Results Plot
   :srcset: /examples/07-Circuit/images/sphx_glr_Circuit_Example_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    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.




.. GENERATED FROM PYTHON SOURCE LINES 120-125

Close AEDT
~~~~~~~~~~
After the simulation completes, you can close AEDT or release it using the
:func:`pyaedt.Desktop.force_close_desktop` method.
All methods provide for saving the project before closing.

.. GENERATED FROM PYTHON SOURCE LINES 125-127

.. code-block:: Python


    desktop.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 14.387 seconds)


.. _sphx_glr_download_examples_07-Circuit_Circuit_Example.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: Circuit_Example.ipynb <Circuit_Example.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: Circuit_Example.py <Circuit_Example.py>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_