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

.. only:: html

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

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

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

.. _sphx_glr_examples_05-Q3D_Q3D_from_EDB.py:


Q3D Extractor: PCB analysis
---------------------------
This example shows how you can use PyAEDT to create a design in
Q3D Extractor and run a simulation starting from an EDB Project.

.. GENERATED FROM PYTHON SOURCE LINES 9-12

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

.. GENERATED FROM PYTHON SOURCE LINES 12-16

.. code-block:: Python


    import os
    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-27

Setup project files and path
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Download of needed project file and setup of temporary project directory.

.. GENERATED FROM PYTHON SOURCE LINES 27-35

.. code-block:: Python


    project_dir = pyaedt.generate_unique_folder_name()
    aedb_project = pyaedt.downloads.download_file('edb/ANSYS-HSD_V1.aedb',destination=project_dir)

    project_name = pyaedt.generate_unique_name("HSD")
    output_edb = os.path.join(project_dir, project_name + '.aedb')
    output_q3d = os.path.join(project_dir, project_name + '_q3d.aedt')








.. GENERATED FROM PYTHON SOURCE LINES 36-40

Open EDB
~~~~~~~~
Open the edb project and created a cutout on the selected nets
before exporting to Q3D.

.. GENERATED FROM PYTHON SOURCE LINES 40-45

.. code-block:: Python


    edb = pyaedt.Edb(aedb_project, edbversion=aedt_version)
    edb.cutout(["CLOCK_I2C_SCL", "CLOCK_I2C_SDA"], ["GND"], output_aedb_path=output_edb,
                                  use_pyaedt_extent_computing=True, )





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

 .. code-block:: none

    C:\actions-runner\_work\pyaedt\pyaedt\.venv\lib\site-packages\pyedb\dotnet\edb_core\components.py:185: DeprecationWarning: Use new property :func:`instances` instead.
      warnings.warn("Use new property :func:`instances` instead.", DeprecationWarning)

    [[0.05144426092331123, 0.02870618555822053], [0.051507567732030704, 0.028387920738624846], [0.05165833184521132, 0.028023943971865067], [0.05183861438361972, 0.027754132085975027], [0.051963277357883246, 0.02760222981232462], [0.053777229532324555, 0.025788277637883304], [0.05392913180597483, 0.025663614663619865], [0.05415580049377229, 0.025512159488548385], [0.05441782786354536, 0.02538745261280736], [0.06473069662795325, 0.022204467947163603], [0.06483058727470829, 0.02217918947920218], [0.06500618407822036, 0.022144261103311254], [0.06520174524046095, 0.02212500001], [0.07179825761953895, 0.02212500001], [0.07199381878177934, 0.022144261103311212], [0.0723120836013751, 0.02220756791203067], [0.07267606036813512, 0.022358332025211397], [0.07294587225402517, 0.02253861456361987], [0.07309777452767545, 0.02266327753788331], [0.0740599412389342, 0.023625444249142077], [0.07421954256727642, 0.023833440749776783], [0.07443614991723896, 0.02420861568520458], [0.0745724466120828, 0.02471728187526527], [0.0745724466120828, 0.026282715184734545], [0.07443614991723915, 0.02679138137479491], [0.07415343353250461, 0.02728106051728747], [0.07378106403728785, 0.02765343001250433], [0.07347367549883911, 0.027830900867923555], [0.07337953919844722, 0.027878813335211135], [0.05488997543599179, 0.0360913298157531], [0.054678487766160536, 0.03615841638650295], [0.05444461588177951, 0.03620493639668876], [0.054249054719539, 0.03622419749], [0.05351810219436954, 0.03622419749], [0.05325817127675032, 0.03618997693549525], [0.05283971800976488, 0.03607785272053635], [0.052383660380235446, 0.03581454772536155], [0.05198383903463851, 0.03541472637976482], [0.05172053403946369, 0.03495866875023531], [0.05161337712231406, 0.034558753691050305], [0.05157992975286406, 0.03433747779237247], [0.05142573106834311, 0.030307359602748676], [0.05142499983, 0.0302691225047116], [0.05142499983, 0.028901746720461016]]



.. GENERATED FROM PYTHON SOURCE LINES 46-50

Identify pins position
~~~~~~~~~~~~~~~~~~~~~~
Identify [x,y] pin locations on the components to define where to assign sources
and sinks for Q3D and append Z elevation.

.. GENERATED FROM PYTHON SOURCE LINES 50-56

.. code-block:: Python


    pin_u13_scl = [i for i in edb.components["U13"].pins.values() if i.net_name == "CLOCK_I2C_SCL"]
    pin_u1_scl = [i for i in edb.components["U1"].pins.values() if i.net_name == "CLOCK_I2C_SCL"]
    pin_u13_sda = [i for i in edb.components["U13"].pins.values() if i.net_name == "CLOCK_I2C_SDA"]
    pin_u1_sda = [i for i in edb.components["U1"].pins.values() if i.net_name == "CLOCK_I2C_SDA"]








.. GENERATED FROM PYTHON SOURCE LINES 57-60

Append Z Positions
~~~~~~~~~~~~~~~~~~
Note: The factor 100 converts from "meters" to "mm"

.. GENERATED FROM PYTHON SOURCE LINES 60-73

.. code-block:: Python


    location_u13_scl = [i * 1000 for i in pin_u13_scl[0].position]
    location_u13_scl.append(edb.components["U13"].upper_elevation * 1000)

    location_u1_scl = [i * 1000 for i in pin_u1_scl[0].position]
    location_u1_scl.append(edb.components["U1"].upper_elevation * 1000)

    location_u13_sda = [i * 1000 for i in pin_u13_sda[0].position]
    location_u13_sda.append(edb.components["U13"].upper_elevation * 1000)

    location_u1_sda = [i * 1000 for i in pin_u1_sda[0].position]
    location_u1_sda.append(edb.components["U1"].upper_elevation * 1000)








.. GENERATED FROM PYTHON SOURCE LINES 74-77

Save and close Edb
~~~~~~~~~~~~~~~~~~
Save, close Edb and open it in Hfss 3D Layout to generate the 3D model.

.. GENERATED FROM PYTHON SOURCE LINES 77-83

.. code-block:: Python


    edb.save_edb()
    edb.close_edb()

    h3d = pyaedt.Hfss3dLayout(output_edb, specified_version=aedt_version, non_graphical=True, new_desktop_session=True)





.. 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 11764 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 84-88

Export to Q3D
~~~~~~~~~~~~~
Create a dummy setup and export the layout in Q3D.
keep_net_name will reassign Q3D nets names from Hfss 3D Layout.

.. GENERATED FROM PYTHON SOURCE LINES 88-93

.. code-block:: Python


    setup = h3d.create_setup()
    setup.export_to_q3d(output_q3d, keep_net_name=True)
    h3d.close_project()





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 94-97

Open Q3D
~~~~~~~~
Launch the newly created q3d project and plot it.

.. GENERATED FROM PYTHON SOURCE LINES 97-102

.. code-block:: Python


    q3d = pyaedt.Q3d(output_q3d)
    q3d.plot(show=False, objects=["CLOCK_I2C_SCL", "CLOCK_I2C_SDA"],
             export_path=os.path.join(q3d.working_directory, "Q3D.jpg"), plot_air_objects=False)




.. image-sg:: /examples/05-Q3D/images/sphx_glr_Q3D_from_EDB_001.png
   :alt: Q3D from EDB
   :srcset: /examples/05-Q3D/images/sphx_glr_Q3D_from_EDB_001.png
   :class: sphx-glr-single-img


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

 .. code-block:: none


    <pyaedt.generic.plot.ModelPlotter object at 0x000002265F710310>



.. GENERATED FROM PYTHON SOURCE LINES 103-107

Assign Source and Sink
~~~~~~~~~~~~~~~~~~~~~~
Use previously calculated position to identify faces and
assign sources and sinks on nets.

.. GENERATED FROM PYTHON SOURCE LINES 107-117

.. code-block:: Python


    f1 = q3d.modeler.get_faceid_from_position(location_u13_scl, assignment="CLOCK_I2C_SCL")
    q3d.source(f1, net_name="CLOCK_I2C_SCL")
    f1 = q3d.modeler.get_faceid_from_position(location_u13_sda, assignment="CLOCK_I2C_SDA")
    q3d.source(f1, net_name="CLOCK_I2C_SDA")
    f1 = q3d.modeler.get_faceid_from_position(location_u1_scl, assignment="CLOCK_I2C_SCL")
    q3d.sink(f1, net_name="CLOCK_I2C_SCL")
    f1 = q3d.modeler.get_faceid_from_position(location_u1_sda, assignment="CLOCK_I2C_SDA")
    q3d.sink(f1, net_name="CLOCK_I2C_SDA")





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

 .. code-block:: none


    <pyaedt.modules.Boundary.BoundaryObject object at 0x000002265F713430>



.. GENERATED FROM PYTHON SOURCE LINES 118-122

Create Setup
~~~~~~~~~~~~
Create a setup and a frequency sweep from DC to 2GHz.
Analyze project.

.. GENERATED FROM PYTHON SOURCE LINES 122-130

.. code-block:: Python


    setup = q3d.create_setup()
    setup.dc_enabled = True
    setup.capacitance_enabled = False
    sweep = setup.add_sweep()
    sweep.add_subrange("LinearStep", 0, end=2, count=0.05, unit="GHz", save_single_fields=False, clear=True)
    setup.analyze()








.. GENERATED FROM PYTHON SOURCE LINES 131-134

ACL Report
~~~~~~~~~~
Compute ACL solutions and plot them.

.. GENERATED FROM PYTHON SOURCE LINES 134-139

.. code-block:: Python


    traces_acl = q3d.post.available_report_quantities(quantities_category="ACL Matrix")
    solution = q3d.post.get_solution_data(traces_acl)
    solution.plot()




.. image-sg:: /examples/05-Q3D/images/sphx_glr_Q3D_from_EDB_002.png
   :alt: Simulation Results Plot
   :srcset: /examples/05-Q3D/images/sphx_glr_Q3D_from_EDB_002.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.

    <Figure size 2000x1000 with 1 Axes>



.. GENERATED FROM PYTHON SOURCE LINES 140-143

ACR Report
~~~~~~~~~~
Compute ACR solutions and plot them.

.. GENERATED FROM PYTHON SOURCE LINES 143-148

.. code-block:: Python


    traces_acr = q3d.post.available_report_quantities(quantities_category="ACR Matrix")
    solution2 = q3d.post.get_solution_data(traces_acr)
    solution2.plot()




.. image-sg:: /examples/05-Q3D/images/sphx_glr_Q3D_from_EDB_003.png
   :alt: Simulation Results Plot
   :srcset: /examples/05-Q3D/images/sphx_glr_Q3D_from_EDB_003.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.

    <Figure size 2000x1000 with 1 Axes>



.. GENERATED FROM PYTHON SOURCE LINES 149-153

Close AEDT
~~~~~~~~~~
After the simulation completes, you can close AEDT or release it using the
``release_desktop`` method. All methods provide for saving projects before closing.

.. GENERATED FROM PYTHON SOURCE LINES 153-155

.. code-block:: Python


    q3d.release_desktop()




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

 .. code-block:: none


    True




.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (9 minutes 17.502 seconds)


.. _sphx_glr_download_examples_05-Q3D_Q3D_from_EDB.py:

.. only:: html

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

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

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

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

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


.. only:: html

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

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