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

.. only:: html

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

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

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

.. _sphx_glr_examples_01-HFSS3DLayout_Hfss3DComponent.py:


HFSS: 3D Components
-------------------
This example shows how you can use PyAEDT to place 3D Components in Hfss and in Hfss 3D Layout.

.. GENERATED FROM PYTHON SOURCE LINES 6-9

.. code-block:: Python

    import os
    import pyaedt








.. GENERATED FROM PYTHON SOURCE LINES 10-13

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

.. GENERATED FROM PYTHON SOURCE LINES 13-16

.. code-block:: Python


    aedt_version = "2024.1"








.. GENERATED FROM PYTHON SOURCE LINES 17-21

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

.. GENERATED FROM PYTHON SOURCE LINES 21-24

.. code-block:: Python


    non_graphical = False








.. GENERATED FROM PYTHON SOURCE LINES 25-28

Common Properties
~~~~~~~~~~~~~~~~~
Set common properties.

.. GENERATED FROM PYTHON SOURCE LINES 28-37

.. code-block:: Python


    trace_width = 0.6
    trace_length = 30
    diel_height = "121mil"
    sig_height = "5mil"
    max_steps = 3
    freq = "3GHz"
    new_session = True








.. GENERATED FROM PYTHON SOURCE LINES 38-41

3D Component Definition
~~~~~~~~~~~~~~~~~~~~~~~
File to be used in the example

.. GENERATED FROM PYTHON SOURCE LINES 41-44

.. code-block:: Python


    component3d = pyaedt.downloads.download_file("component_3d", "SMA_RF_Jack.a3dcomp",)








.. GENERATED FROM PYTHON SOURCE LINES 45-49

Hfss Example
------------
This example will create a stackup in Hfss place a 3d component, build a ground plane, a trace,
create excitation and solve it in Hfss.

.. GENERATED FROM PYTHON SOURCE LINES 51-54

Launch Hfss
~~~~~~~~~~~
Launch HFSS application

.. GENERATED FROM PYTHON SOURCE LINES 54-59

.. code-block:: Python


    hfss = pyaedt.Hfss(new_desktop_session=True, specified_version=aedt_version, non_graphical=non_graphical)

    hfss.solution_type = "Terminal"








.. GENERATED FROM PYTHON SOURCE LINES 60-63

Insert 3d Component
~~~~~~~~~~~~~~~~~~~
To insert a 3d component we need to read parameters and then import in Hfss.

.. GENERATED FROM PYTHON SOURCE LINES 63-67

.. code-block:: Python


    comp_param = hfss.get_components3d_vars(component3d)
    hfss.modeler.insert_3d_component(component3d, comp_param)





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

 .. code-block:: none


    <pyaedt.modeler.cad.components_3d.UserDefinedComponent object at 0x000002263F093970>



.. GENERATED FROM PYTHON SOURCE LINES 68-71

Add a new Stackup
~~~~~~~~~~~~~~~~~
Pyaedt has a Stackup class which allows to parametrize stacked structures.

.. GENERATED FROM PYTHON SOURCE LINES 71-77

.. code-block:: Python


    stackup = hfss.add_stackup_3d()
    s1 = stackup.add_signal_layer("L1", thickness=sig_height)
    d1 = stackup.add_dielectric_layer("D1", thickness=diel_height)
    g1 = stackup.add_ground_layer("G1", thickness=sig_height)








.. GENERATED FROM PYTHON SOURCE LINES 78-81

Define stackup extensions
~~~~~~~~~~~~~~~~~~~~~~~~~~
Define stackup elevation and size. Defines also the stackup origin.

.. GENERATED FROM PYTHON SOURCE LINES 81-88

.. code-block:: Python


    stackup.start_position = "-131mil"
    stackup.dielectric_width = "20mm"
    stackup.dielectric_length = "40mm"
    stackup.dielectric_y_position = "-dielectric_width/2"
    stackup.dielectric_x_position = "-dielectric_length/4"








.. GENERATED FROM PYTHON SOURCE LINES 89-93

Padstack Definition
~~~~~~~~~~~~~~~~~~~
Padstacks are needed to create a clearance around 3d component since
intersections are not allowed. There will be 1 padstack for Gnd and 1 for pin.

.. GENERATED FROM PYTHON SOURCE LINES 93-113

.. code-block:: Python


    p1 = stackup.add_padstack("gnd_via", material="cloned_copper")
    p1.set_start_layer("L1")
    p1.set_stop_layer("G1")
    p1.set_all_antipad_value(1.3)
    p1.set_all_pad_value(0)
    p1.num_sides = 8
    p1.add_via(-3.2, -3.2)
    p1.add_via(-3.2, 3.2)
    p1.add_via(3.2, -3.2)
    p1.add_via(3.2, 3.2)
    p2 = stackup.add_padstack("signal_via", material="cloned_copper")

    p2.set_start_layer("L1")
    p2.set_stop_layer("G1")
    p2.set_all_antipad_value(0.7)
    p2.set_all_pad_value(0)
    p2.padstacks_by_layer["L1"].pad_radius = 0.3048
    p2.add_via(0, 0)





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

 .. code-block:: none


    <pyaedt.modeler.cad.object3d.Object3d object at 0x0000022638C95270>



.. GENERATED FROM PYTHON SOURCE LINES 114-117

Trace Definition
~~~~~~~~~~~~~~~~
The trace will connect the pin to the port on layer L1.

.. GENERATED FROM PYTHON SOURCE LINES 117-124

.. code-block:: Python


    t1 = s1.add_trace(trace_width, trace_length)
    rect1 = hfss.modeler.create_rectangle(orientation=hfss.PLANE.YZ,
                                                     origin=["0.75*dielectric_length", "-5*" + t1.width.name, "0mm"],
                                                     sizes=["15*" + t1.width.name, "-3*" + stackup.thickness.name])
    p1 = hfss.wave_port(assignment=rect1, reference="G1", name="P1")








.. GENERATED FROM PYTHON SOURCE LINES 125-128

Set Simulation Boundaries
~~~~~~~~~~~~~~~~~~~~~~~~~
Define regione and simulation boundaries.

.. GENERATED FROM PYTHON SOURCE LINES 128-134

.. code-block:: Python


    hfss.change_material_override(True)
    region = hfss.modeler.create_region([0, 0, 0, 0, 0, 100])
    sheets = [i for i in region.faces]
    hfss.assign_radiation_boundary_to_faces(sheets)





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

 .. code-block:: none


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



.. GENERATED FROM PYTHON SOURCE LINES 135-138

Create Setup
~~~~~~~~~~~~
Iterations will be reduced to reduce simulation time.

.. GENERATED FROM PYTHON SOURCE LINES 138-144

.. code-block:: Python


    setup1 = hfss.create_setup()
    sweep1 = hfss.create_linear_count_sweep(setup1.name, "GHz", 0.01, 8, 1601, sweep_type="Interpolating")
    setup1.props["Frequency"] = freq
    setup1.props["MaximumPasses"] = max_steps








.. GENERATED FROM PYTHON SOURCE LINES 145-148

Solve Setup
~~~~~~~~~~~
Save the project first and then solve the setup.

.. GENERATED FROM PYTHON SOURCE LINES 148-152

.. code-block:: Python


    hfss.save_project()
    hfss.analyze()





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 153-156

Plot results
~~~~~~~~~~~~
Plot the results when analysis is completed.

.. GENERATED FROM PYTHON SOURCE LINES 156-161

.. code-block:: Python


    traces = hfss.get_traces_for_plot(category="S")
    solutions = hfss.post.get_solution_data(traces)
    solutions.plot(traces, formula="db20")




.. image-sg:: /examples/01-HFSS3DLayout/images/sphx_glr_Hfss3DComponent_001.png
   :alt: Simulation Results Plot
   :srcset: /examples/01-HFSS3DLayout/images/sphx_glr_Hfss3DComponent_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.

    <Figure size 2000x1000 with 1 Axes>



.. GENERATED FROM PYTHON SOURCE LINES 162-166

Hfss 3D Layout Example
----------------------
Previous example will be repeated this time in Hfss 3d Layout.
Small differences are expected in layout but results should be similar.

.. GENERATED FROM PYTHON SOURCE LINES 168-171

Launch Hfss3dLayout
~~~~~~~~~~~~~~~~~~~
Launch HFSS3dLayout application

.. GENERATED FROM PYTHON SOURCE LINES 171-174

.. code-block:: Python


    h3d = pyaedt.Hfss3dLayout()








.. GENERATED FROM PYTHON SOURCE LINES 175-178

Add stackup layers
~~~~~~~~~~~~~~~~~~
Add stackup layers.

.. GENERATED FROM PYTHON SOURCE LINES 178-184

.. code-block:: Python


    l1 = h3d.modeler.layers.add_layer("L1", "signal", thickness=sig_height)
    h3d.modeler.layers.add_layer("diel", "dielectric", thickness=diel_height, material="FR4_epoxy")
    h3d.modeler.layers.add_layer("G1", "signal", thickness=sig_height, isnegative=True)






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

 .. code-block:: none


    <pyaedt.modules.LayerStackup.Layer object at 0x000002263F30C8E0>



.. GENERATED FROM PYTHON SOURCE LINES 185-188

Place 3d Component
~~~~~~~~~~~~~~~~~~
Place a 3d component by specifying the .a3dcomp file path.

.. GENERATED FROM PYTHON SOURCE LINES 188-194

.. code-block:: Python


    comp = h3d.modeler.place_3d_component(
        component_path=component3d, number_of_terminals=1, placement_layer="G1", component_name="my_connector",
        pos_x=0.000, pos_y=0.000
    )








.. GENERATED FROM PYTHON SOURCE LINES 195-198

Create signal net and ground planes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a signal net and ground planes.

.. GENERATED FROM PYTHON SOURCE LINES 198-205

.. code-block:: Python


    h3d["len"] = str(trace_length) + "mm"
    h3d["w1"] = str(trace_width) + "mm"

    line = h3d.modeler.create_line("L1", [[0, 0], ["len", 0]], lw="w1", name="microstrip", net="microstrip")
    h3d.create_edge_port(line, h3d.modeler[line.name].top_edge_x, is_wave_port=True, wave_horizontal_extension=15)





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

 .. code-block:: none


    <pyaedt.modules.Boundary.BoundaryObject3dLayout object at 0x000002263F421FF0>



.. GENERATED FROM PYTHON SOURCE LINES 206-209

Create void on Ground plane for pin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a void.

.. GENERATED FROM PYTHON SOURCE LINES 209-212

.. code-block:: Python


    h3d.modeler.create_circle("G1", 0, 0, 0.5)





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

 .. code-block:: none


    <pyaedt.modeler.pcb.object3dlayout.Circle3dLayout object at 0x000002263F1F1060>



.. GENERATED FROM PYTHON SOURCE LINES 213-216

Create Setup
~~~~~~~~~~~~
Iterations will be reduced to reduce simulation time.

.. GENERATED FROM PYTHON SOURCE LINES 216-230

.. code-block:: Python


    h3d.set_meshing_settings(mesh_method="PhiPlus", enable_intersections_check=False)
    h3d.edit_hfss_extents(diel_extent_horizontal_padding="0.2", air_vertical_positive_padding="0",
                          air_vertical_negative_padding="2", airbox_values_as_dim=False)
    setup1 = h3d.create_setup()
    sweep1 = h3d.create_linear_count_sweep(setup1.name,
                                           "GHz",
                                           0.01,
                                           8,
                                           1601,
                                           sweep_type="Interpolating")
    setup1.props["AdaptiveSettings"]["SingleFrequencyDataList"]["AdaptiveFrequencyData"]["AdaptiveFrequency"] = freq
    setup1.props["AdaptiveSettings"]["SingleFrequencyDataList"]["AdaptiveFrequencyData"]["MaxPasses"] = max_steps








.. GENERATED FROM PYTHON SOURCE LINES 231-233

Solve Setup
~~~~~~~~~~~

.. GENERATED FROM PYTHON SOURCE LINES 233-236

.. code-block:: Python


    h3d.analyze()





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 237-239

Plot results
~~~~~~~~~~~~

.. GENERATED FROM PYTHON SOURCE LINES 239-246

.. code-block:: Python


    traces = h3d.get_traces_for_plot(category="S")
    solutions = h3d.post.get_solution_data(traces)
    solutions.plot(traces, formula="db20")

    h3d.save_project()
    h3d.release_desktop()



.. image-sg:: /examples/01-HFSS3DLayout/images/sphx_glr_Hfss3DComponent_002.png
   :alt: Simulation Results Plot
   :srcset: /examples/01-HFSS3DLayout/images/sphx_glr_Hfss3DComponent_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.

    True




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

   **Total running time of the script:** (3 minutes 31.721 seconds)


.. _sphx_glr_download_examples_01-HFSS3DLayout_Hfss3DComponent.py:

.. only:: html

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

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

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

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

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


.. only:: html

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

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