Dipole Antenna Example

This example shows how you can use PyAEDT to create an antenna setup in HFSS and postprocess results.

# sphinx_gallery_thumbnail_path = 'Resources/Dipole.png'

import os
import tempfile
from pyaedt import Hfss
from pyaedt import Desktop
from pyaedt import generate_unique_name

tmpfold = tempfile.gettempdir()

temp_folder = os.path.join(tmpfold, generate_unique_name("Example"))
if not os.path.exists(temp_folder):
    os.mkdir(temp_folder)

Launch AEDT in Graphical Mode

This examples launches AEDT 2021.1 in graphical mode.

nongraphical = False
d = Desktop("2021.1", non_graphical=nongraphical)

Out:

Launching PyAEDT outside Electronics Desktop with CPython and Pythonnet
Launching AEDT installation C:\Program Files\AnsysEM\AnsysEM21.1\Win64
===================================================================================
pyaedt info: Launching AEDT with module Pythonnet.
pyaedt info:: Ansoft.ElectronicsDesktop.2021.1 Started with process ID 252.
pyaedt info: Logger Started on C:\Users\ansys\Documents\Ansoft\pyaedt20211026_141848.log
pyaedt info: pyaedt v0.4.0
pyaedt info: Python version 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]

Launch HFSS in Graphical Mode

This examples launches HFSS 2021.1 in graphical mode.

hfss = Hfss()

Out:

pyaedt info: Project Project6077 has been created.
pyaedt info: No design is present. Inserting a new design.
pyaedt info: Design Loaded
pyaedt info: Successfully loaded project materials !
pyaedt info: Materials Loaded

Define a Dipole Length Variable

This command defines a dipole length variable.

hfss["l_dipole"] = "13.5cm"

Get a 3D Component from the syslib Directory

To run this example 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.

compfile = hfss.components3d["Dipole_Antenna_DM"]
geometryparams = hfss.get_components3d_vars("Dipole_Antenna_DM")
geometryparams["dipole_length"] = "l_dipole"
hfss.modeler.primitives.insert_3d_component(compfile, geometryparams)

Out:

'Dipole_Antenna1'

Create Boundaries

A region with openings is needed to run the analysis.

hfss.create_open_region(Frequency="1GHz")

Out:

pyaedt info: Open Region correctly created.

True

Create the Setup

A setup with a sweep will be used to run the simulation.

setup = hfss.create_setup("MySetup", hfss.SimulationSetupTypes.HFSSDrivenAuto)
setup.props["Type"] = "Interpolating"
setup.props["Sweeps"]["Sweep"]["RangeType"] = "LinearCount"
setup.props["Sweeps"]["Sweep"]["RangeStart"] = "0.5GHz"
setup.props["Sweeps"]["Sweep"]["RangeEnd"] = "1.5GHz"
setup.props["Sweeps"]["Sweep"]["RangeCount"] = 401
setup.props["Sweeps"]["Sweep"]["AutoSolverSetting"] = "Higher Speed"
setup.update()

Out:

True

Save and Run the Simulation

A setup with a sweep will be used to run the simulation.

hfss.save_project(os.path.join(temp_folder, "MyDipole.aedt"))
hfss.analyze_setup("MySetup")

Out:

pyaedt info: Saving Project6077 Project
pyaedt info: Solving design setup MySetup
pyaedt info: Key Desktop/ActiveDSOConfigurations/HFSS correctly changed.
pyaedt info: Design setup MySetup solved correctly

True

Postprocessing

Generate a scattering plot and a far fields plot.

hfss.create_scattering("MyScattering")
variations = hfss.available_variations.nominal_w_values_dict
variations["Freq"] = ["1GHz"]
variations["Theta"] = ["All"]
variations["Phi"] = ["All"]
hfss.post.create_rectangular_plot(
    "db(GainTotal)", hfss.nominal_adaptive, variations, "Theta", "3D", report_category="Far Fields"
)

Out:

pyaedt info: Report Plot_24X9S2 correctly created.

True

Close AEDT

After the simulaton is completed, you can close AEDT or release it using the pyaedt.Desktop.release_desktop() method. All methods provide for saving the project before exiting.

if os.name != "posix":
    d.force_close_desktop()

Total running time of the script: ( 1 minutes 55.196 seconds)

Gallery generated by Sphinx-Gallery