Skip to content

Commit 063e62d

Browse files
committed
S588850: Linked coupling pyaedt support
1 parent efd119b commit 063e62d

File tree

7 files changed

+213
-4
lines changed

7 files changed

+213
-4
lines changed

_setup_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def recursive_glob(startpath, filepattern):
5252
"pyaedt.modules",
5353
"pyaedt.generic",
5454
"pyaedt.edb_core",
55+
"pyaedt.emit_core",
5556
"pyaedt.examples",
5657
"pyaedt.rpc",
5758
"pyaedt.third_party",

_unittest/test_26_emit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_objects(self):
2727
assert self.aedtapp.modeler
2828
assert self.aedtapp.oanalysis is None
2929

30-
@pytest.mark.skipif(config["build_machine"], reason="Not functional in non-graphical mode")
30+
@pytest.mark.skipif(config["NonGraphical"], reason="Not functional in non-graphical mode")
3131
def test_create_components(self):
3232
radio = self.aedtapp.modeler.components.create_component("New Radio", "TestRadio")
3333
assert radio.name == "TestRadio"
@@ -36,7 +36,7 @@ def test_create_components(self):
3636
assert antenna.name == "TestAntenna"
3737
assert isinstance(antenna, EmitComponent)
3838

39-
@pytest.mark.skipif(config["build_machine"], reason="Not functional in non-graphical mode")
39+
@pytest.mark.skipif(config["NonGraphical"], reason="Not functional in non-graphical mode")
4040
@pytest.mark.skipif(config["desktopVersion"] < "2021.2", reason="Skipped on versions lower than 2021.2")
4141
def test_connect_components(self):
4242
radio = self.aedtapp.modeler.components.create_component("New Radio")
@@ -54,7 +54,7 @@ def test_connect_components(self):
5454
assert connected_comp is None
5555
assert connected_port is None
5656

57-
@pytest.mark.skipif(config["build_machine"], reason="Not functional in non-graphical mode")
57+
@pytest.mark.skipif(config["NonGraphical"], reason="Not functional in non-graphical mode")
5858
def test_radio_component(self):
5959
radio = self.aedtapp.modeler.components.create_component("New Radio")
6060
# default radio has 1 Tx channel and 1 Rx channel
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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)

pyaedt/application/AnalsyisEmit.py renamed to pyaedt/application/AnalysisEmit.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pyaedt.application.Design import Design
22
from pyaedt.modeler.Circuit import ModelerEmit
3+
from pyaedt.emit_core.Couplings import CouplingsEmit
34

45

56
class FieldAnalysisEmit(Design):
@@ -50,6 +51,7 @@ def __init__(
5051
self.solution_type = solution_type
5152
self.oanalysis = None
5253
self._modeler = ModelerEmit(self)
54+
self._couplings = CouplingsEmit(self)
5355

5456
@property
5557
def modeler(self):
@@ -61,3 +63,14 @@ def modeler(self):
6163
Design oModeler
6264
"""
6365
return self._modeler
66+
67+
@property
68+
def couplings(self):
69+
"""Emit Couplings.
70+
71+
Returns
72+
-------
73+
pyaedt.emit_core.Couplings.CouplingsEmit
74+
Couplings within the EMIT Design
75+
"""
76+
return self._couplings

pyaedt/emit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import absolute_import # noreorder
22

3-
from pyaedt.application.AnalsyisEmit import FieldAnalysisEmit
3+
from pyaedt.application.AnalysisEmit import FieldAnalysisEmit
44

55

66
class Emit(FieldAnalysisEmit, object):

pyaedt/emit_core/Couplings.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
This module contains these classes: `CouplingsEmit`.
3+
4+
This module provides the capability to interact with EMIT Analysis & Results windows.
5+
"""
6+
7+
import warnings
8+
9+
10+
class CouplingsEmit(object):
11+
"""Provides for interaction with the EMIT Coupling folder
12+
13+
This class is accessible through the EMIT application results variable
14+
object( eg. ``emit.couplings``).
15+
16+
Parameters
17+
----------
18+
app :
19+
Inherited parent object.
20+
21+
Examples
22+
--------
23+
>>> from pyaedt import Emit
24+
>>> app = Emit()
25+
>>> my_couplings = app.couplings
26+
"""
27+
28+
def __init__(self, app):
29+
self._app = app
30+
31+
# Properties derived from internal parent data
32+
@property
33+
def _desktop(self):
34+
"""Desktop."""
35+
return self._app._desktop
36+
37+
@property
38+
def logger(self):
39+
"""Logger."""
40+
return self._app.logger
41+
42+
@property
43+
def _odesign(self):
44+
"""Design."""
45+
return self._app._odesign
46+
47+
@property
48+
def projdir(self):
49+
"""Project directory."""
50+
return self._app.project_path
51+
52+
@property
53+
def coupling_names(self):
54+
"""List of existing link names."""
55+
return self._odesign.GetLinkNames()
56+
57+
def add_link(self, new_coupling_name):
58+
"""add a new link if it's not already there"""
59+
if new_coupling_name not in self._odesign.GetLinkNames():
60+
self._odesign.AddLink(new_coupling_name)
61+
62+
def update_link(self, coupling_name):
63+
"""update the link if it's a valid link"""
64+
if coupling_name in self._odesign.GetLinkNames():
65+
self._odesign.UpdateLink(coupling_name)
66+
67+
@property
68+
def linkable_design_names(self):
69+
"""list the available link names"""
70+
desktop_version = self._desktop.GetVersion()[0:6]
71+
if desktop_version >= "2022.2":
72+
return self._odesign.GetAvailableLinkNames()
73+
else:
74+
warnings.warn(
75+
"The function linkable_design_names() requires AEDT 2022 R2 or newer."
76+
)
77+
return []

pyaedt/emit_core/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)