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

.. only:: html

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

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

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

.. _sphx_glr_examples_02-HFSS_Flex_CPWG.py:


HFSS: flex cable CPWG
---------------------
This example shows how you can use PyAEDT to create a flex cable CPWG (coplanar waveguide with ground).

.. GENERATED FROM PYTHON SOURCE LINES 8-11

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

.. GENERATED FROM PYTHON SOURCE LINES 11-16

.. code-block:: Python


    import os
    from math import radians, sin, cos, sqrt
    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-28

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

.. GENERATED FROM PYTHON SOURCE LINES 28-31

.. code-block:: Python


    non_graphical = False








.. GENERATED FROM PYTHON SOURCE LINES 32-35

Launch AEDT
~~~~~~~~~~~
Launch AEDT 2023 R2 in graphical mode.

.. GENERATED FROM PYTHON SOURCE LINES 35-46

.. code-block:: Python


    hfss = pyaedt.Hfss(specified_version=aedt_version,
                       solution_type="DrivenTerminal",
                       new_desktop_session=True,
                       non_graphical=non_graphical)
    hfss.change_material_override(True)
    hfss.change_automatically_use_causal_materials(True)
    hfss.create_open_region("100GHz")
    hfss.modeler.model_units = "mil"
    hfss.mesh.assign_initial_mesh_from_slider(applycurvilinear=True)





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 47-50

Create variables
~~~~~~~~~~~~~~~~
Create input variables for creating the flex cable CPWG.

.. GENERATED FROM PYTHON SOURCE LINES 50-63

.. code-block:: Python


    total_length = 300
    theta = 120
    r = 100
    width = 3
    height = 0.1
    spacing = 1.53
    gnd_width = 10
    gnd_thickness = 2

    xt = (total_length - r * radians(theta)) / 2









.. GENERATED FROM PYTHON SOURCE LINES 64-68

Create bend
~~~~~~~~~~~
Create the bend. The ``create_bending`` method creates a list of points for
the bend based on the curvature radius and extension.

.. GENERATED FROM PYTHON SOURCE LINES 68-85

.. code-block:: Python


    def create_bending(radius, extension=0):
        position_list = [(-xt, 0, -radius), (0, 0, -radius)]

        for i in [radians(i) for i in range(theta)] + [radians(theta + 0.000000001)]:
            position_list.append((radius * sin(i), 0, -radius * cos(i)))

        x1, y1, z1 = position_list[-1]
        x0, y0, z0 = position_list[-2]

        scale = (xt + extension) / sqrt((x1 - x0) ** 2 + (z1 - z0) ** 2)
        x, y, z = (x1 - x0) * scale + x0, 0, (z1 - z0) * scale + z0

        position_list[-1] = (x, y, z)
        return position_list









.. GENERATED FROM PYTHON SOURCE LINES 86-89

Draw signal line
~~~~~~~~~~~~~~~~
Draw a signal line to create a bent signal wire.

.. GENERATED FROM PYTHON SOURCE LINES 89-94

.. code-block:: Python


    position_list = create_bending(r, 1)
    line = hfss.modeler.create_polyline(points=position_list, material="copper", xsection_type="Rectangle",
                                        xsection_width=height, xsection_height=width)








.. GENERATED FROM PYTHON SOURCE LINES 95-98

Draw ground line
~~~~~~~~~~~~~~~~
Draw a ground line to create two bent ground wires.

.. GENERATED FROM PYTHON SOURCE LINES 98-109

.. code-block:: Python


    gnd_r = [(x, spacing + width / 2 + gnd_width / 2, z) for x, y, z in position_list]
    gnd_l = [(x, -y, z) for x, y, z in gnd_r]

    gnd_objs = []
    for gnd in [gnd_r, gnd_l]:
        x = hfss.modeler.create_polyline(points=gnd, material="copper", xsection_type="Rectangle", xsection_width=height,
                                         xsection_height=gnd_width)
        x.color = (255, 0, 0)
        gnd_objs.append(x)








.. GENERATED FROM PYTHON SOURCE LINES 110-113

Draw dielectric
~~~~~~~~~~~~~~~
Draw a dielectric to create a dielectric cable.

.. GENERATED FROM PYTHON SOURCE LINES 113-119

.. code-block:: Python


    position_list = create_bending(r + (height + gnd_thickness) / 2)

    fr4 = hfss.modeler.create_polyline(points=position_list, material="FR4_epoxy", xsection_type="Rectangle",
                                       xsection_width=gnd_thickness, xsection_height=width + 2 * spacing + 2 * gnd_width)








.. GENERATED FROM PYTHON SOURCE LINES 120-123

Create bottom metals
~~~~~~~~~~~~~~~~~~~~
Create the bottom metals.

.. GENERATED FROM PYTHON SOURCE LINES 123-129

.. code-block:: Python


    position_list = create_bending(r + height + gnd_thickness, 1)

    bot = hfss.modeler.create_polyline(points=position_list, material="copper", xsection_type="Rectangle",
                                       xsection_width=height, xsection_height=width + 2 * spacing + 2 * gnd_width)








.. GENERATED FROM PYTHON SOURCE LINES 130-133

Create port interfaces
~~~~~~~~~~~~~~~~~~~~~~
Create port interfaces (PEC enclosures).

.. GENERATED FROM PYTHON SOURCE LINES 133-157

.. code-block:: Python


    port_faces = []
    for face, blockname in zip([fr4.top_face_z, fr4.bottom_face_x], ["b1", "b2"]):
        xc, yc, zc = face.center
        positions = [i.position for i in face.vertices]

        port_sheet_list = [((x - xc) * 10 + xc, (y - yc) + yc, (z - zc) * 10 + zc) for x, y, z in positions]
        s = hfss.modeler.create_polyline(port_sheet_list, cover_surface=True, close_surface=True)
        center = [round(i, 6) for i in s.faces[0].center]

        port_block = hfss.modeler.thicken_sheet(s.name, -5)
        port_block.name = blockname
        for f in port_block.faces:

            if [round(i, 6) for i in f.center] == center:
                port_faces.append(f)

        port_block.material_name = "PEC"

        for i in [line, bot] + gnd_objs:
            i.subtract([port_block], True)

        print(port_faces)





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

 .. code-block:: none

    [7391]
    [7391, 7586]




.. GENERATED FROM PYTHON SOURCE LINES 158-161

Create boundary condition
~~~~~~~~~~~~~~~~~~~~~~~~~
Creates a Perfect E boundary condition.

.. GENERATED FROM PYTHON SOURCE LINES 161-168

.. code-block:: Python


    boundary = []
    for face in [fr4.top_face_y, fr4.bottom_face_y]:
        s = hfss.modeler.create_object_from_face(face)
        boundary.append(s)
        hfss.assign_perfecte_to_sheets(s)








.. GENERATED FROM PYTHON SOURCE LINES 169-172

Create ports
~~~~~~~~~~~~
Creates ports.

.. GENERATED FROM PYTHON SOURCE LINES 172-178

.. code-block:: Python


    for s, port_name in zip(port_faces, ["1", "2"]):
        reference = [i.name for i in gnd_objs + boundary + [bot]] + ["b1", "b2"]

        hfss.wave_port(s.id, reference=reference, name=port_name)








.. GENERATED FROM PYTHON SOURCE LINES 179-182

Create setup and sweep
~~~~~~~~~~~~~~~~~~~~~~
Create the setup and sweep.

.. GENERATED FROM PYTHON SOURCE LINES 182-190

.. code-block:: Python


    setup = hfss.create_setup("setup1")
    setup["Frequency"] = "2GHz"
    setup.props["MaximumPasses"] = 10
    setup.props["MinimumConvergedPasses"] = 2
    hfss.create_linear_count_sweep(setup="setup1", units="GHz", start_frequency=1e-1, stop_frequency=4,
                                   num_of_freq_points=101, name="sweep1", save_fields=False, sweep_type="Interpolating")





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

 .. code-block:: none


    <pyaedt.modules.SolveSweeps.SweepHFSS object at 0x000002264A844E50>



.. GENERATED FROM PYTHON SOURCE LINES 191-194

Plot model
~~~~~~~~~~
Plot the model.

.. GENERATED FROM PYTHON SOURCE LINES 194-202

.. code-block:: Python


    my_plot = hfss.plot(show=False, plot_air_objects=False)
    my_plot.show_axes = False
    my_plot.show_grid = False
    my_plot.plot(
        os.path.join(hfss.working_directory, "Image.jpg"),
    )




.. image-sg:: /examples/02-HFSS/images/sphx_glr_Flex_CPWG_001.png
   :alt: Flex CPWG
   :srcset: /examples/02-HFSS/images/sphx_glr_Flex_CPWG_001.png
   :class: sphx-glr-single-img


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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 203-207

Analyze and release
~~~~~~~~~~~~~~~~~~~~
Uncomment the ``hfss.analyze`` command if you want to analyze the
model and release AEDT.

.. GENERATED FROM PYTHON SOURCE LINES 207-209

.. code-block:: Python


    hfss.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 3.203 seconds)


.. _sphx_glr_download_examples_02-HFSS_Flex_CPWG.py:

.. only:: html

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

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

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

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

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


.. only:: html

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

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