|
| 1 | +""" |
| 2 | +EMIT Example |
| 3 | +------------ |
| 4 | +This tutorial shows how you can use PyAEDT to open an AEDT project with |
| 5 | +an HFSS design, create an EMIT design in the project, then link the HFSS design |
| 6 | +as a coupling link in the EMIT design. |
| 7 | +""" |
| 8 | +# sphinx_gallery_thumbnail_path = 'Resources/emit.png' |
| 9 | +import os |
| 10 | +import tempfile |
| 11 | + |
| 12 | +# Import required modules |
| 13 | +from pyaedt.generic.filesystem import Scratch |
| 14 | + |
| 15 | +# Setup paths for module imports |
| 16 | +from _unittest.conftest import scratch_path |
| 17 | + |
| 18 | +from pyaedt import Emit |
| 19 | +from pyaedt import Desktop |
| 20 | + |
| 21 | +############################################################################### |
| 22 | +# Initialization Settings |
| 23 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 24 | +# Change NonGraphical Boolean to False to open AEDT in graphical mode |
| 25 | +# With NewThread = False, an existing instance of AEDT will be used, if |
| 26 | +# available. This example will use AEDT 2022.2 |
| 27 | + |
| 28 | +NonGraphical = False |
| 29 | +NewThread = True |
| 30 | +desktop_version = "2022.2" |
| 31 | + |
| 32 | + |
| 33 | +############################################################################### |
| 34 | +# Launch AEDT and EMIT Design |
| 35 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 36 | +# Desktop class initializes AEDT and starts it on specified version and |
| 37 | +# specified graphical mode. NewThread Boolean variable defines if a user wants |
| 38 | +# to create a new instance of AEDT or try to connect to existing instance of |
| 39 | +# it. |
| 40 | +d = Desktop(desktop_version, NonGraphical, NewThread) |
| 41 | +tmpfold = tempfile.gettempdir() |
| 42 | + |
| 43 | +temp_folder = os.path.join(tmpfold, ("EmitHFSSExample")) |
| 44 | +if not os.path.exists(temp_folder): |
| 45 | + os.mkdir(temp_folder) |
| 46 | + |
| 47 | +example_name = "Cell Phone RFI Desense" |
| 48 | +example_aedt = example_name + ".aedt" |
| 49 | +example_lock = example_aedt + ".lock" |
| 50 | +example_pdf_file = example_name + " Example.pdf" |
| 51 | + |
| 52 | +example_dir = os.path.join(d.install_path, "Examples\\EMIT") |
| 53 | +example_project = os.path.join(example_dir, example_aedt) |
| 54 | +example_pdf = os.path.join(example_dir, example_pdf_file) |
| 55 | + |
| 56 | +# If the Cell phone example is not in the install dir, exit from this example. |
| 57 | +if not os.path.exists(example_project): |
| 58 | + msg = """ |
| 59 | + Cell phone RFT Desense example file is not in the |
| 60 | + Examples/EMIT directory under the EDT installation. You can not run this example. |
| 61 | + """ |
| 62 | + print(msg) |
| 63 | + d.force_close_desktop() |
| 64 | + exit() |
| 65 | + |
| 66 | +my_project = os.path.join(temp_folder, example_aedt) |
| 67 | +my_project_lock = os.path.join(temp_folder, example_lock) |
| 68 | +my_project_pdf = os.path.join(temp_folder, example_pdf_file) |
| 69 | + |
| 70 | +if os.path.exists(my_project): |
| 71 | + os.remove(my_project) |
| 72 | + |
| 73 | +if os.path.exists(my_project_lock): |
| 74 | + os.remove(my_project_lock) |
| 75 | + |
| 76 | +with Scratch(scratch_path) as local_scratch: |
| 77 | + local_scratch.copyfile(example_project, my_project) |
| 78 | + if os.path.exists(example_pdf): |
| 79 | + local_scratch.copyfile(example_pdf, my_project_pdf) |
| 80 | + |
| 81 | +aedtapp = Emit(my_project) |
| 82 | +############################################################################### |
| 83 | + |
| 84 | +# Create and Connect EMIT Components |
| 85 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 86 | +# Create 3 radios and connect an antenna to each. |
| 87 | +rad1 = aedtapp.modeler.components.create_component("UE - Handheld") |
| 88 | +ant1 = aedtapp.modeler.components.create_component("Antenna") |
| 89 | +if rad1 and ant1: |
| 90 | + ant1.move_and_connect_to(rad1) |
| 91 | + |
| 92 | +rad2 = aedtapp.modeler.components.create_component("GPS Receiver") |
| 93 | +ant2 = aedtapp.modeler.components.create_component("Antenna") |
| 94 | +if rad2 and ant2: |
| 95 | + ant2.move_and_connect_to(rad2) |
| 96 | + |
| 97 | +############################################################################### |
| 98 | +# Define Coupling Among the RF Systems |
| 99 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 100 | +for link in aedtapp.couplings.linkable_design_names: |
| 101 | + aedtapp.couplings.add_link(link) |
| 102 | + |
| 103 | +for link in aedtapp.couplings.coupling_names: |
| 104 | + aedtapp.couplings.update_link(link) |
| 105 | +############################################################################### |
| 106 | +# Run the EMIT Simulation |
| 107 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 108 | +# This portion of the EMIT API is not yet implemented. |
| 109 | + |
| 110 | + |
| 111 | +############################################################################### |
| 112 | +# Close Desktop |
| 113 | +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 114 | +# After the simulaton is completed user can close the desktop or release it |
| 115 | +# (using release_desktop method). All methods give possibility to save projects |
| 116 | +# before exit. |
| 117 | +aedtapp.save_project() |
| 118 | +aedtapp.release_desktop(close_projects=True, close_desktop=True) |
0 commit comments