Download this example
Download this example as a Jupyter Notebook or as a Python script.
Antenna#
This example shows how to create a project in EMIT for the simulation of an antenna using HFSS.
Keywords: EMIT, Antenna.
Perform imports and define constants#
Perform required imports.
[1]:
import tempfile
import time
[2]:
import ansys.aedt.core
from ansys.aedt.core.emit_core.emit_constants import ResultType, TxRxMode
Define constants.
[3]:
AEDT_VERSION = "2024.2"
NG_MODE = False # Open AEDT UI when it is launched.
Create temporary directory#
Create a temporary directory where downloaded data or dumped data can be stored. If you’d like to retrieve the project data for subsequent use, the temporary folder name is given by temp_folder.name
.
[4]:
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")
Launch AEDT with EMIT#
Launch AEDT with EMIT. The launch_desktop()
method initializes AEDT using the specified version. The second argument can be set to True
to run AEDT in non-graphical mode.
[5]:
project_name = ansys.aedt.core.generate_unique_project_name(
root_name=temp_folder.name, project_name="antenna_cosite"
)
d = ansys.aedt.core.launch_desktop(AEDT_VERSION, NG_MODE, new_desktop=True)
aedtapp = ansys.aedt.core.Emit(project_name, version=AEDT_VERSION)
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_17378b20-5760-400b-8cda-69f2ee953f82.log is enabled.
PyAEDT INFO: Log on AEDT is enabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: New AEDT session is starting on gRPC port 58452
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
PyAEDT INFO: Ansoft.ElectronicsDesktop.2024.2 version started with process ID 3512.
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Returning found Desktop session with PID 3512!
PyAEDT INFO: Project antenna_cosite has been created.
PyAEDT INFO: No design is present. Inserting a new design.
PyAEDT INFO: Added design 'EMIT_6XR' of type EMIT.
PyAEDT INFO: Aedt Objects correctly read
PyAEDT INFO: ModelerCircuit class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: ModelerEmit class has been initialized!
PyAEDT INFO: Importing EmitApiPython from: C:\Program Files\AnsysEM\v242\Win64\Delcross\EmitApiPython
PyAEDT INFO: Loaded Ansys EMIT API (Beta) 2024.2.0
Create and connect EMIT components#
Create three radios and connect an antenna to each one.
[6]:
rad1 = aedtapp.modeler.components.create_component("New Radio")
ant1 = aedtapp.modeler.components.create_component("Antenna")
if rad1 and ant1:
ant1.move_and_connect_to(rad1)
Place radio/antenna pair#
Use the create_radio_antenna()
method to place the radio/antenna pair. The first argument is the type of radio. The second argument is the name to assign to the radio.
[7]:
rad2, ant2 = aedtapp.modeler.components.create_radio_antenna("GPS Receiver")
rad3, ant3 = aedtapp.modeler.components.create_radio_antenna(
"Bluetooth Low Energy (LE)", "Bluetooth"
)
Define the RF environment#
Specify the RF coupling among antennas. This functionality is not yet implemented in the API, but it can be entered from the UI.
Run EMIT simulation#
Run the EMIT simulation.
This part of the example requires Ansys AEDT 2023 R2.
Note: You can uncomment the following code.
if AEDT_VERSION > “2023.1”: rev = aedtapp.results.analyze() rx_bands = rev.get_band_names(rad2.name, TxRxMode.RX) tx_bands = rev.get_band_names(rad3.name, TxRxMode.TX) domain = aedtapp.results.interaction_domain() domain.set_receiver(rad2.name, rx_bands[0], -1) domain.set_interferer(rad3.name, tx_bands[0]) interaction = rev.run(domain) worst = interaction.get_worst_instance(ResultType.EMI) if worst.has_valid_values(): emi = worst.get_value(ResultType.EMI) print(“Worst case interference is: {} dB”.format(emi))
Release AEDT#
Release AEDT and close the example.
[8]:
aedtapp.save_project()
aedtapp.release_desktop()
# Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory.
time.sleep(3)
PyAEDT ERROR: **************************************************************
PyAEDT ERROR: File "C:\Users\ansys\AppData\Local\Programs\Python\Python310\Lib\runpy.py", line 196, in _run_module_as_main
PyAEDT ERROR: return _run_code(code, main_globals, None,
PyAEDT ERROR: File "C:\Users\ansys\AppData\Local\Programs\Python\Python310\Lib\runpy.py", line 86, in _run_code
PyAEDT ERROR: exec(code, run_globals)
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel_launcher.py", line 18, in <module>
PyAEDT ERROR: app.launch_new_instance()
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\traitlets\config\application.py", line 1075, in launch_instance
PyAEDT ERROR: app.start()
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\kernelapp.py", line 739, in start
PyAEDT ERROR: self.io_loop.start()
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\tornado\platform\asyncio.py", line 205, in start
PyAEDT ERROR: self.asyncio_loop.run_forever()
PyAEDT ERROR: File "C:\Users\ansys\AppData\Local\Programs\Python\Python310\Lib\asyncio\base_events.py", line 603, in run_forever
PyAEDT ERROR: self._run_once()
PyAEDT ERROR: File "C:\Users\ansys\AppData\Local\Programs\Python\Python310\Lib\asyncio\base_events.py", line 1909, in _run_once
PyAEDT ERROR: handle._run()
PyAEDT ERROR: File "C:\Users\ansys\AppData\Local\Programs\Python\Python310\Lib\asyncio\events.py", line 80, in _run
PyAEDT ERROR: self._context.run(self._callback, *self._args)
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\kernelbase.py", line 545, in dispatch_queue
PyAEDT ERROR: await self.process_one()
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\kernelbase.py", line 534, in process_one
PyAEDT ERROR: await dispatch(*args)
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\kernelbase.py", line 437, in dispatch_shell
PyAEDT ERROR: await result
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\ipkernel.py", line 362, in execute_request
PyAEDT ERROR: await super().execute_request(stream, ident, parent)
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\kernelbase.py", line 778, in execute_request
PyAEDT ERROR: reply_content = await reply_content
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\ipkernel.py", line 449, in do_execute
PyAEDT ERROR: res = shell.run_cell(
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ipykernel\zmqshell.py", line 549, in run_cell
PyAEDT ERROR: return super().run_cell(*args, **kwargs)
PyAEDT ERROR: File "C:\Users\ansys\AppData\Local\Temp\ipykernel_6556\1706598488.py", line 1, in <module>
PyAEDT ERROR: aedtapp.save_project()
PyAEDT ERROR: File "C:\actions-runner\_work\pyaedt-examples\pyaedt-examples\.venv\lib\site-packages\ansys\aedt\core\emit.py", line 351, in save_project
PyAEDT ERROR: self._emit_api.save_project()
PyAEDT ERROR: Error: a project directory name must be specified. on save_project
PyAEDT ERROR: **************************************************************
PyAEDT INFO: Desktop has been released and closed.
Clean up#
All project files are saved in the folder temp_folder.name
. If you’ve run this example as a Jupyter notebook, you can retrieve those project files. The following cell removes all temporary files, including the project folder.
[9]:
temp_folder.cleanup()
Download this example
Download this example as a Jupyter Notebook or as a Python script.