Skip to content

Commit c749569

Browse files
FIX: Output variable with differential pairs (#6132)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent e7a1acd commit c749569

File tree

4 files changed

+120
-11
lines changed

4 files changed

+120
-11
lines changed

doc/changelog.d/6132.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Output variable with differential pairs

src/ansys/aedt/core/application/analysis.py

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def active_setup(self, name):
352352
raise ValueError(f"Setup name {name} is invalid.")
353353
self._setup = name
354354
else:
355-
raise AttributeError("No setup is defined.")
355+
raise AttributeError("No setups defined.")
356356

357357
@property
358358
def setup_sweeps_names(self):
@@ -1470,7 +1470,7 @@ def get_setup(self, name):
14701470
return self.design_setups[name]
14711471

14721472
@pyaedt_function_handler()
1473-
def create_output_variable(self, variable, expression, solution=None, context=None):
1473+
def create_output_variable(self, variable, expression, solution=None, context=None, is_differential=False):
14741474
"""Create or modify an output variable.
14751475
14761476
Parameters
@@ -1484,6 +1484,9 @@ def create_output_variable(self, variable, expression, solution=None, context=No
14841484
If `None`, the first available solution is used. Default is `None`.
14851485
context : list, str, optional
14861486
Context under which the output variable will produce results.
1487+
is_differential : bool, optional
1488+
Whether the expression corresponds to a differential pair.
1489+
This parameter is only valid for HFSS 3D Layout and Circuit design types. The default value is `False`.
14871490
14881491
Returns
14891492
-------
@@ -1493,21 +1496,87 @@ def create_output_variable(self, variable, expression, solution=None, context=No
14931496
References
14941497
----------
14951498
>>> oModule.CreateOutputVariable
1499+
1500+
Examples
1501+
--------
1502+
>>> from ansys.aedt.core import Circuit
1503+
>>> aedtapp = Circuit()
1504+
>>> aedtapp.create_output_variable(variable="output_diff", expression="S(Comm,Diff)", is_differential=True)
1505+
>>> aedtapp.create_output_variable(variable="output_terminal", expression="S(1,1)", is_differential=False)
14961506
"""
14971507
if context is None:
14981508
context = []
1499-
if not context and self.solution_type == "Q3D Extractor":
1500-
context = ["Context:=", "Original"]
1501-
1509+
if not context:
1510+
if self.solution_type == "Q3D Extractor":
1511+
context = ["Context:=", "Original"]
1512+
elif self.design_type == "HFSS 3D Layout Design" and is_differential:
1513+
context = [
1514+
"NAME:Context",
1515+
"SimValueContext:=",
1516+
[
1517+
3,
1518+
0,
1519+
2,
1520+
0,
1521+
False,
1522+
False,
1523+
-1,
1524+
1,
1525+
0,
1526+
1,
1527+
1,
1528+
"",
1529+
0,
1530+
0,
1531+
"EnsDiffPairKey",
1532+
False,
1533+
"1",
1534+
"IDIID",
1535+
False,
1536+
"3",
1537+
],
1538+
]
1539+
elif self.design_type == "Circuit Design" and is_differential:
1540+
context = [
1541+
"NAME:Context",
1542+
"SimValueContext:=",
1543+
[
1544+
3,
1545+
0,
1546+
2,
1547+
0,
1548+
False,
1549+
False,
1550+
-1,
1551+
1,
1552+
0,
1553+
1,
1554+
1,
1555+
"",
1556+
0,
1557+
0,
1558+
"NUMLEVELS",
1559+
False,
1560+
"1",
1561+
"USE_DIFF_PAIRS",
1562+
False,
1563+
"1",
1564+
],
1565+
]
15021566
oModule = self.ooutput_variable
15031567
if solution is None:
1568+
if not self.existing_analysis_sweeps:
1569+
raise AEDTRuntimeError("No setups defined.")
15041570
solution = self.existing_analysis_sweeps[0]
15051571
if variable in self.output_variables:
15061572
oModule.EditOutputVariable(
15071573
variable, expression, variable, solution, self.design_solutions.report_type, context
15081574
)
15091575
else:
1510-
oModule.CreateOutputVariable(variable, expression, solution, self.design_solutions.report_type, context)
1576+
try:
1577+
oModule.CreateOutputVariable(variable, expression, solution, self.design_solutions.report_type, context)
1578+
except Exception:
1579+
raise AEDTRuntimeError(f"Invalid commands.")
15111580
return True
15121581

15131582
@pyaedt_function_handler()

tests/system/general/test_21_Circuit.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from ansys.aedt.core import Circuit
2929
from ansys.aedt.core import generate_unique_name
3030
from ansys.aedt.core.generic.settings import is_linux
31+
from ansys.aedt.core.internal.errors import AEDTRuntimeError
3132
import pytest
3233

3334
from tests import TESTS_GENERAL_PATH
@@ -514,8 +515,8 @@ def test_34_activate_variables(self, aedtapp):
514515
def test_35_netlist_data_block(self, aedtapp, local_scratch):
515516
with open(Path(local_scratch.path) / "lc.net", "w") as f:
516517
for i in range(10):
517-
f.write(f"L{i} net_{i} net_{i+1} 1e-9\n")
518-
f.write(f"C{i} net_{i+1} 0 5e-12\n")
518+
f.write(f"L{i} net_{i} net_{i + 1} 1e-9\n")
519+
f.write(f"C{i} net_{i + 1} 0 5e-12\n")
519520
assert aedtapp.add_netlist_datablock(Path(local_scratch.path) / "lc.net")
520521
aedtapp.modeler.components.create_interface_port("net_0", (0, 0))
521522
aedtapp.modeler.components.create_interface_port("net_10", (0.01, 0))
@@ -535,8 +536,8 @@ def test_37_draw_graphical_primitives(self, aedtapp):
535536
def test_38_browse_log_file(self, aedtapp, local_scratch):
536537
with open(Path(local_scratch.path) / "lc.net", "w") as f:
537538
for i in range(10):
538-
f.write(f"L{i} net_{i} net_{i+1} 1e-9\n")
539-
f.write(f"C{i} net_{i+1} 0 5e-12\n")
539+
f.write(f"L{i} net_{i} net_{i + 1} 1e-9\n")
540+
f.write(f"C{i} net_{i + 1} 0 5e-12\n")
540541
aedtapp.modeler.components.create_interface_port("net_0", (0, 0), angle=90)
541542
aedtapp.modeler.components.create_interface_port("net_10", (0.01, 0))
542543
lna = aedtapp.create_setup("mylna", aedtapp.SETUPS.NexximLNA)
@@ -1032,3 +1033,28 @@ def test_55_get_component_path_and_import_sss_files(self, aedtapp):
10321033
buffer = ibis_model.buffers["RDQS#"].insert(0.1016, 0.05334, 0.0)
10331034
assert len(aedtapp.modeler.schematic.components) == 5
10341035
assert buffer.component_path
1036+
1037+
def test_output_variables(self, circuitprj):
1038+
with pytest.raises(AEDTRuntimeError):
1039+
circuitprj.create_output_variable(
1040+
variable="outputvar_diff2", expression="S(Comm2,Diff2)", is_differential=False
1041+
)
1042+
circuitprj.create_setup()
1043+
assert circuitprj.create_output_variable(variable="outputvar_terminal", expression="S(1, 1)")
1044+
assert len(circuitprj.output_variables) == 1
1045+
assert circuitprj.set_differential_pair(
1046+
assignment="Port3",
1047+
reference="Port4",
1048+
common_mode="Comm2",
1049+
differential_mode="Diff2",
1050+
common_reference=34,
1051+
differential_reference=123,
1052+
)
1053+
assert circuitprj.create_output_variable(
1054+
variable="outputvar_diff", expression="S(Comm2,Diff2)", is_differential=True
1055+
)
1056+
assert len(circuitprj.output_variables) == 2
1057+
with pytest.raises(AEDTRuntimeError):
1058+
circuitprj.create_output_variable(
1059+
variable="outputvar_diff2", expression="S(Comm2,Diff2)", is_differential=False
1060+
)

tests/system/solvers/test_00_analyze.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

5353
component = "Circ_Patch_5GHz_232.a3dcomp"
5454

55-
5655
test_subfolder = "T00"
5756
erl_project_name = "erl_unit_test"
5857
com_project_name = "com_unit_test_23r2"
@@ -642,3 +641,17 @@ def test_10_export_to_maxwell(self, add_app):
642641
app2 = add_app("assm_test2", application=Rmxprt, solution_type="ASSM")
643642
app2.import_configuration(config)
644643
assert app2.circuit
644+
645+
def test_output_variables_3dlayout(self, hfss3dl_solved):
646+
hfss3dl_solved.set_differential_pair(
647+
assignment="Port1", reference="Port2", differential_mode="Diff", common_mode="Comm"
648+
)
649+
assert hfss3dl_solved.create_output_variable(
650+
variable="outputvar_diff", expression="S(Comm,Diff)", is_differential=True
651+
)
652+
assert hfss3dl_solved.create_output_variable(variable="outputvar_terminal", expression="dB(S(Port1,Port1))")
653+
assert len(hfss3dl_solved.output_variables) == 2
654+
with pytest.raises(AEDTRuntimeError):
655+
hfss3dl_solved.create_output_variable(
656+
variable="outputvar_diff2", expression="S(Comm,Diff)", is_differential=False
657+
)

0 commit comments

Comments
 (0)