.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples\02-SBR+\SBR_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_02-SBR+_SBR_Example.py>`
        to download the full example code.

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

.. _sphx_glr_examples_02-SBR+_SBR_Example.py:


SBR+: HFSS to SBR+ coupling
---------------------------
This example shows how you can use PyAEDT to create an HFSS SBR+ project from an
HFSS antenna and run a simulation.

.. GENERATED FROM PYTHON SOURCE LINES 8-12

Perform required imports
~~~~~~~~~~~~~~~~~~~~~~~~
Perform required imports and set up the local path to the path for the PyAEDT
directory.

.. GENERATED FROM PYTHON SOURCE LINES 12-18

.. code-block:: Python


    import os
    import pyaedt

    project_full_name = pyaedt.downloads.download_sbr(pyaedt.generate_unique_project_name(project_name="sbr_freq"))








.. GENERATED FROM PYTHON SOURCE LINES 19-22

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

.. GENERATED FROM PYTHON SOURCE LINES 22-25

.. code-block:: Python


    aedt_version = "2024.1"








.. GENERATED FROM PYTHON SOURCE LINES 26-30

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

.. GENERATED FROM PYTHON SOURCE LINES 30-33

.. code-block:: Python


    non_graphical = False








.. GENERATED FROM PYTHON SOURCE LINES 34-38

Define designs
~~~~~~~~~~~~~~
Define two designs, one source and one target, with each design connected to
a different object.

.. GENERATED FROM PYTHON SOURCE LINES 38-53

.. code-block:: Python


    target = pyaedt.Hfss(
        projectname=project_full_name,
        designname="Cassegrain_",
        solution_type="SBR+",
        specified_version=aedt_version,
        new_desktop_session=True,
        non_graphical=non_graphical
    )

    source = pyaedt.Hfss(projectname=target.project_name,
                         designname="feeder",
                         specified_version=aedt_version,
                         )





.. 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 1936 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 54-57

Define linked antenna
~~~~~~~~~~~~~~~~~~~~~~~
Define a linked antenna. This is HFSS far field applied to HFSS SBR+.

.. GENERATED FROM PYTHON SOURCE LINES 57-60

.. code-block:: Python


    target.create_sbr_linked_antenna(source, target_cs="feederPosition", field_type="farfield")





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

 .. code-block:: none


    <pyaedt.modules.Boundary.NativeComponentObject object at 0x000002264A6A6E90>



.. GENERATED FROM PYTHON SOURCE LINES 61-64

Assign boundaries
~~~~~~~~~~~~~~~~~
Assign boundaries.

.. GENERATED FROM PYTHON SOURCE LINES 64-68

.. code-block:: Python


    target.assign_perfecte_to_sheets(["Reflector", "Subreflector"])
    target.mesh.assign_curvilinear_elements(["Reflector", "Subreflector"])





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

 .. code-block:: none


    <pyaedt.modules.Mesh.MeshOperation object at 0x000002264A6A61A0>



.. GENERATED FROM PYTHON SOURCE LINES 69-72

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

.. GENERATED FROM PYTHON SOURCE LINES 72-76

.. code-block:: Python


    source.plot(show=False, export_path=os.path.join(target.working_directory, "Source.jpg"), plot_air_objects=True)
    target.plot(show=False, export_path=os.path.join(target.working_directory, "Target.jpg"), plot_air_objects=False)




.. rst-class:: sphx-glr-horizontal


    *

      .. image-sg:: /examples/02-SBR+/images/sphx_glr_SBR_Example_001.png
          :alt: SBR Example
          :srcset: /examples/02-SBR+/images/sphx_glr_SBR_Example_001.png
          :class: sphx-glr-multi-img

    *

      .. image-sg:: /examples/02-SBR+/images/sphx_glr_SBR_Example_002.png
          :alt: SBR Example
          :srcset: /examples/02-SBR+/images/sphx_glr_SBR_Example_002.png
          :class: sphx-glr-multi-img


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

 .. code-block:: none


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



.. GENERATED FROM PYTHON SOURCE LINES 77-80

Create setup and solve
~~~~~~~~~~~~~~~~~~~~~~~~
Create a setup and solve it.

.. GENERATED FROM PYTHON SOURCE LINES 80-90

.. code-block:: Python


    setup1 = target.create_setup()
    setup1.props["RadiationSetup"] = "ATK_3D"
    setup1.props["ComputeFarFields"] = True
    setup1.props["RayDensityPerWavelength"] = 2
    setup1.props["MaxNumberOfBounces"] = 3
    setup1["RangeType"] = "SinglePoints"
    setup1["RangeStart"] = "10GHz"
    target.analyze()





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

 .. code-block:: none


    True



.. GENERATED FROM PYTHON SOURCE LINES 91-94

Plot results
~~~~~~~~~~~~
Plot results.

.. GENERATED FROM PYTHON SOURCE LINES 94-102

.. code-block:: Python


    variations = target.available_variations.nominal_w_values_dict
    variations["Freq"] = ["10GHz"]
    variations["Theta"] = ["All"]
    variations["Phi"] = ["All"]
    target.post.create_report("db(GainTotal)", target.nominal_adaptive, variations=variations,
                              primary_sweep_variable="Theta", report_category="Far Fields", context="ATK_3D")





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

 .. code-block:: none


    <pyaedt.modules.report_templates.FarField object at 0x000002264A6DC1F0>



.. GENERATED FROM PYTHON SOURCE LINES 103-106

Plot results outside AEDT
~~~~~~~~~~~~~~~~~~~~~~~~~
Plot results using Matplotlib.

.. GENERATED FROM PYTHON SOURCE LINES 106-117

.. code-block:: Python


    solution = target.post.get_solution_data(
        "GainTotal",
        target.nominal_adaptive,
        variations=variations,
        primary_sweep_variable="Theta",
        context="ATK_3D",
        report_category="Far Fields",
    )
    solution.plot()




.. image-sg:: /examples/02-SBR+/images/sphx_glr_SBR_Example_003.png
   :alt: Simulation Results Plot
   :srcset: /examples/02-SBR+/images/sphx_glr_SBR_Example_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 118-121

Release AEDT
~~~~~~~~~~~~
Release AEDT and close the example.

.. GENERATED FROM PYTHON SOURCE LINES 121-123

.. code-block:: Python


    target.release_desktop()




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

 .. code-block:: none


    True




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

   **Total running time of the script:** (2 minutes 6.246 seconds)


.. _sphx_glr_download_examples_02-SBR+_SBR_Example.py:

.. only:: html

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

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

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

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

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


.. only:: html

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

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