.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\02-HFSS\HFSS_Dipole.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_02-HFSS_HFSS_Dipole.py: HFSS: dipole antenna -------------------- This example shows how you can use PyAEDT to create a dipole antenna in HFSS and postprocess results. .. GENERATED FROM PYTHON SOURCE LINES 8-11 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports. .. GENERATED FROM PYTHON SOURCE LINES 11-17 .. code-block:: Python import os import ansys.aedt.core project_name = ansys.aedt.core.generate_unique_project_name(project_name="dipole") .. GENERATED FROM PYTHON SOURCE LINES 18-21 Set AEDT version ~~~~~~~~~~~~~~~~ Set AEDT version. .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python aedt_version = "2024.2" .. GENERATED FROM PYTHON SOURCE LINES 25-29 Set non-graphical mode ~~~~~~~~~~~~~~~~~~~~~~ Set non-graphical mode. ` You can set ``non_graphical`` either to ``True`` or ``False``. .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: Python non_graphical = False .. GENERATED FROM PYTHON SOURCE LINES 33-36 Launch AEDT ~~~~~~~~~~~ Launch AEDT 2023 R2 in graphical mode. .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: Python d = ansys.aedt.core.launch_desktop(aedt_version, non_graphical=non_graphical, new_desktop=True) .. GENERATED FROM PYTHON SOURCE LINES 40-43 Launch HFSS ~~~~~~~~~~~ Launch HFSS 2023 R2 in graphical mode. .. GENERATED FROM PYTHON SOURCE LINES 43-46 .. code-block:: Python hfss = ansys.aedt.core.Hfss(project=project_name, solution_type="Modal") .. GENERATED FROM PYTHON SOURCE LINES 47-50 Define variable ~~~~~~~~~~~~~~~ Define a variable for the dipole length. .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: Python hfss["l_dipole"] = "13.5cm" .. GENERATED FROM PYTHON SOURCE LINES 54-59 Get 3D component from system library ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get a 3D component from the ``syslib`` directory. For this example to run correctly, you must get all geometry parameters of the 3D component or, in case of an encrypted 3D component, create a dictionary of the parameters. .. GENERATED FROM PYTHON SOURCE LINES 59-65 .. code-block:: Python compfile = hfss.components3d["Dipole_Antenna_DM"] geometryparams = hfss.get_components3d_vars("Dipole_Antenna_DM") geometryparams["dipole_length"] = "l_dipole" hfss.modeler.insert_3d_component(compfile, geometryparams) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 66-69 Create boundaries ~~~~~~~~~~~~~~~~~ Create boundaries. A region with openings is needed to run the analysis. .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. code-block:: Python hfss.create_open_region(frequency="1GHz") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 73-76 Plot model ~~~~~~~~~~ Plot the model. .. GENERATED FROM PYTHON SOURCE LINES 76-85 .. 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.isometric_view = False my_plot.plot( os.path.join(hfss.working_directory, "Image.jpg"), ) .. image-sg:: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_001.png :alt: HFSS Dipole :srcset: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 86-89 Create setup ~~~~~~~~~~~~ Create a setup with a sweep to run the simulation. .. GENERATED FROM PYTHON SOURCE LINES 89-97 .. code-block:: Python setup = hfss.create_setup("MySetup") setup.props["Frequency"] = "1GHz" setup.props["MaximumPasses"] = 1 hfss.create_linear_count_sweep(setup=setup.name, units="GHz", start_frequency=0.5, stop_frequency=1.5, num_of_freq_points=251, name="sweep1", save_fields=False, sweep_type="Interpolating", interpolation_tol=3, interpolation_max_solutions=255) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 98-101 Save and run simulation ~~~~~~~~~~~~~~~~~~~~~~~ Save and run the simulation. .. GENERATED FROM PYTHON SOURCE LINES 101-104 .. code-block:: Python hfss.analyze_setup("MySetup") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 105-108 Create scattering plot and far fields report ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a scattering plot and a far fields report. .. GENERATED FROM PYTHON SOURCE LINES 108-117 .. code-block:: Python hfss.create_scattering("MyScattering") variations = hfss.available_variations.nominal_w_values_dict variations["Freq"] = ["1GHz"] variations["Theta"] = ["All"] variations["Phi"] = ["All"] hfss.post.create_report("db(GainTotal)", hfss.nominal_adaptive, variations, primary_sweep_variable="Theta", report_category="Far Fields", context="3D") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 118-122 Create far fields report using report objects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a far fields report using the ``report_by_category.far field`` method, which gives you more freedom. .. GENERATED FROM PYTHON SOURCE LINES 122-128 .. code-block:: Python new_report = hfss.post.reports_by_category.far_field("db(RealizedGainTotal)", hfss.nominal_adaptive, "3D") new_report.variations = variations new_report.primary_sweep = "Theta" new_report.create("Realized2D") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 129-133 Generate multiple plots ~~~~~~~~~~~~~~~~~~~~~~~ Generate multiple plots using the object ``new_report``. This code generates 2D and 3D polar plots. .. GENERATED FROM PYTHON SOURCE LINES 133-138 .. code-block:: Python new_report.report_type = "3D Polar Plot" new_report.secondary_sweep = "Phi" new_report.create("Realized3D") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 139-143 Get solution data ~~~~~~~~~~~~~~~~~ Get solution data using the object ``new_report``` and postprocess or plot the data outside AEDT. .. GENERATED FROM PYTHON SOURCE LINES 143-147 .. code-block:: Python solution_data = new_report.get_solution_data() solution_data.plot() .. image-sg:: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_002.png :alt: Simulation Results Plot :srcset: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 148-154 Generate far field plot ~~~~~~~~~~~~~~~~~~~~~~~ Generate a far field plot by creating a postprocessing variable and assigning it to a new coordinate system. You can use the ``post`` prefix to create a postprocessing variable directly from a setter, or you can use the ``set_variable`` method with an arbitrary name. .. GENERATED FROM PYTHON SOURCE LINES 154-160 .. code-block:: Python hfss["post_x"] = 2 hfss.variable_manager.set_variable(name="y_post", expression=1, is_post_processing=True) hfss.modeler.create_coordinate_system(origin=["post_x", "y_post", 0], name="CS_Post") hfss.insert_infinite_sphere(custom_coordinate_system="CS_Post", name="Sphere_Custom") .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 161-164 Get solution data ~~~~~~~~~~~~~~~~~ Get solution data. You can use this code to generate the same plot outside AEDT. .. GENERATED FROM PYTHON SOURCE LINES 164-170 .. code-block:: Python new_report = hfss.post.reports_by_category.far_field("GainTotal", hfss.nominal_adaptive, "3D") new_report.primary_sweep = "Theta" new_report.far_field_sphere = "3D" solutions = new_report.get_solution_data() .. GENERATED FROM PYTHON SOURCE LINES 171-174 Generate 3D plot using Matplotlib ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Generate a 3D plot using Matplotlib. .. GENERATED FROM PYTHON SOURCE LINES 174-177 .. code-block:: Python solutions.plot_3d() .. image-sg:: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_003.png :alt: Simulation Results Plot :srcset: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 178-181 Generate 3D far fields plot using Matplotlib ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Generate a far fields plot using Matplotlib. .. GENERATED FROM PYTHON SOURCE LINES 181-186 .. code-block:: Python new_report.far_field_sphere = "Sphere_Custom" solutions_custom = new_report.get_solution_data() solutions_custom.plot_3d() .. image-sg:: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_004.png :alt: Simulation Results Plot :srcset: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 187-191 Generate 2D plot using Matplotlib ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Generate a 2D plot using Matplotlib where you specify whether it is a polar plot or a rectangular plot. .. GENERATED FROM PYTHON SOURCE LINES 191-194 .. code-block:: Python solutions.plot() .. image-sg:: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_005.png :alt: Simulation Results Plot :srcset: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 195-200 Get far field data ~~~~~~~~~~~~~~~~~~ Get far field data. After the simulation completes, the far field data is generated port by port and stored in a data class, , user can use this data once AEDT is released. .. GENERATED FROM PYTHON SOURCE LINES 200-204 .. code-block:: Python ffdata = hfss.get_antenna_data(frequencies=["1000MHz"], setup=hfss.nominal_adaptive, sphere="Sphere_Custom") .. image-sg:: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_006.png :alt: HFSS Dipole :srcset: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 205-209 Generate 2D cutout plot ~~~~~~~~~~~~~~~~~~~~~~~ Generate 2D cutout plot. You can define the Theta scan and Phi scan. .. GENERATED FROM PYTHON SOURCE LINES 209-213 .. code-block:: Python ffdata.farfield_data.plot_cut(quantity='RealizedGain', primary_sweep="theta", secondary_sweep_value=0, title='FarField', quantity_format="dB20", is_polar=True) .. image-sg:: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_007.png :alt: FarField :srcset: /examples/02-HFSS/images/sphx_glr_HFSS_Dipole_007.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 214-219 Close AEDT ~~~~~~~~~~ After the simulation completes, you can close AEDT or release it using the :func:`ansys.aedt.core.Desktop.release_desktop` method. All methods provide for saving the project before closing. .. GENERATED FROM PYTHON SOURCE LINES 219-221 .. code-block:: Python d.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 25.332 seconds) .. _sphx_glr_download_examples_02-HFSS_HFSS_Dipole.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: HFSS_Dipole.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: HFSS_Dipole.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: HFSS_Dipole.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_