Skip to content

Commit 0451aef

Browse files
Enhancement/q3d matrix (#834)
* Added Matrix to Q3d * Added First UT * Added methods to delete and add operations to Matrix * Added Unit Tests * black fix * Updated Q3D Example * added matrix to subcircuit * Added Filter to matrix search * Added Filter to matrix search * Update _unittest/test_30_Q2D.py Co-authored-by: Maxime Rey <[email protected]> * Close project after UT Co-authored-by: Maxime Rey <[email protected]>
1 parent 69cc793 commit 0451aef

File tree

9 files changed

+406
-39
lines changed

9 files changed

+406
-39
lines changed

_unittest/example_models/q2d_q3d.aedt

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ $begin 'AnsoftProject'
189189
$end 'Properties'
190190
CompExtID=6
191191
$begin 'Parameters'
192-
MenuProp('CoSimulator', 'D', '', 'DefaultNetlist', 0)
193192
ButtonProp('CosimDefinition', 'D', '', '', 'Edit', 40501, ButtonPropClientData())
193+
MenuProp('CoSimulator', 'D', '', 'DefaultNetlist', 0)
194194
$end 'Parameters'
195195
$begin 'CosimDefinitions'
196196
$begin 'CosimDefinition'
@@ -216,8 +216,8 @@ $begin 'AnsoftProject'
216216
$end 'Properties'
217217
CompExtID=6
218218
$begin 'Parameters'
219-
MenuProp('CoSimulator', 'D', '', 'DefaultNetlist', 0)
220219
ButtonProp('CosimDefinition', 'D', '', '', 'Edit', 40501, ButtonPropClientData())
220+
MenuProp('CoSimulator', 'D', '', 'DefaultNetlist', 0)
221221
$end 'Parameters'
222222
$begin 'CosimDefinitions'
223223
$begin 'CosimDefinition'
@@ -1061,7 +1061,7 @@ $begin 'AnsoftProject'
10611061
Notes=$begin_cdata$ $end_cdata$
10621062
$begin 'AnimationSetups'
10631063
$end 'AnimationSetups'
1064-
CacheHeaderFile='HDR550236600164422697169.tmp'
1064+
CacheHeaderFile='HDR3F8C6614816442353233.tmp'
10651065
$end '2DExtractorModel'
10661066
$begin 'Q3DModel'
10671067
RepRewriteV2=true
@@ -1532,27 +1532,13 @@ $begin 'AnsoftProject'
15321532
$end 'MeshOperations'
15331533
$end 'MeshSetup'
15341534
$begin 'ReduceMatrix'
1535-
NextUniqueID=2
1536-
MoveBackwards=false
15371535
$begin 'Original'
15381536
ID=0
15391537
$begin 'SortOrder'
15401538
net[1: -1]
15411539
terminal[1: -1]
15421540
$end 'SortOrder'
15431541
$end 'Original'
1544-
$begin 'JoinSeriesMatrix'
1545-
ID=1
1546-
$begin 'SortOrder'
1547-
net[1: -1]
1548-
terminal[1: -1]
1549-
$end 'SortOrder'
1550-
NextUniqueID=1
1551-
MoveBackwards=false
1552-
$begin 'Operations'
1553-
op('JoinSeries1', 0, JoinSeries('Box1', 3, 8))
1554-
$end 'Operations'
1555-
$end 'JoinSeriesMatrix'
15561542
$end 'ReduceMatrix'
15571543
$begin 'AnalysisSetup'
15581544
$begin 'CircuitData'
@@ -1728,7 +1714,7 @@ $begin 'AnsoftProject'
17281714
Notes=$begin_cdata$ $end_cdata$
17291715
$begin 'AnimationSetups'
17301716
$end 'AnimationSetups'
1731-
CacheHeaderFile='HDR550236600164422697168.tmp'
1717+
CacheHeaderFile='HDR3F8C6614816442353234.tmp'
17321718
$end 'Q3DModel'
17331719
$begin 'DataInstances'
17341720
DesignEditor='TopLevel'
@@ -1769,7 +1755,7 @@ $begin 'AnsoftProject'
17691755
DesignInstanceID=1
17701756
$begin 'WindowPosition'
17711757
$begin 'EditorWindow'
1772-
Circuit(Editor3d(View('View Orientation Gadget'=1, WindowPos(5, -1, -1, -9, -38, 0, 0, 1473, 335), OrientationMatrix(-0.187082901597023, -0.300000011920929, 0.474341750144958, 0, 0.561248660087585, -0.100000001490116, 0.158113896846771, 0, 4.62877292051189e-09, 0.499999970197678, 0.316227793693542, 0, -1.19209289550781e-07, 2.38418579101562e-07, -5.7486834526062, 1, 0, -3.58802819252014, 3.58802819252014, -1, 1, 1.3711838722229, 10.126184463501), Drawings[3: 'Box1', 'Box1_1', 'Box1_2'], 'View Data'('Render Mode'=1, 'Show Ruler'=1, 'Coordinate Systems View Mode'=1, 'CS Triad View Mode'=0, 'Render Facets'=1, GridVisible=1, GridAutoAdjust=1, GridAutoExtents=1, GridType='Rect', GridStyle='Line', NumPixels=30, dXForGrid=0.5, dYForGrid=0.5, dZForGrid=0.5, dRForGrid=0.5, dThetaForGrid=10), ClipPlanes(ClipPlaneOptions(DisableWhenDrawingNewPlane=true, ForceOpqaueForUnclipped=false, ShowClipped=false, Transparency=0, HandleColor=16776960)))))
1758+
Circuit(Editor3d(View('View Orientation Gadget'=1, WindowPos(3, -1, -1, -9, -38, 0, 0, 1473, 335), OrientationMatrix(-0.187082901597023, -0.300000011920929, 0.474341750144958, 0, 0.561248660087585, -0.100000001490116, 0.158113896846771, 0, 4.62877292051189e-09, 0.499999970197678, 0.316227793693542, 0, -1.19209289550781e-07, 2.38418579101562e-07, -5.7486834526062, 1, 0, -1.48734772205353, 1.48734772205353, -1, 1, 1.3711838722229, 10.126184463501), Drawings[3: 'Box1', 'Box1_1', 'Box1_2'], 'View Data'('Render Mode'=1, 'Show Ruler'=1, 'Coordinate Systems View Mode'=1, 'CS Triad View Mode'=0, 'Render Facets'=1, GridVisible=1, GridAutoAdjust=1, GridAutoExtents=1, GridType='Rect', GridStyle='Line', NumPixels=30, dXForGrid=0.1, dYForGrid=0.1, dZForGrid=0.1, dRForGrid=0.1, dThetaForGrid=10), ClipPlanes(ClipPlaneOptions(DisableWhenDrawingNewPlane=true, ForceOpqaueForUnclipped=false, ShowClipped=false, Transparency=0, HandleColor=16776960)))))
17731759
$end 'EditorWindow'
17741760
$end 'WindowPosition'
17751761
$begin 'ReportSetup'
@@ -1803,7 +1789,7 @@ $begin 'AnsoftProject'
18031789
DesignInstanceID=3
18041790
$begin 'WindowPosition'
18051791
$begin 'EditorWindow'
1806-
Circuit(Editor3d(View('View Orientation Gadget'=1, WindowPos(3, -1, -1, -9, -38, 32, 32, 1483, 371), OrientationMatrix(0.591607928276062, 1.77360472974897e-08, -7.6313835251085e-09, 0, 1.27724231191451e-08, 0.591607928276062, 0, 0, -1.15353318008715e-08, -5.96046447753906e-08, 0.591607928276062, 0, -1.19209289550781e-07, 2.38418579101562e-07, -5.7486834526062, 1, 0, -2.46868252754211, 2.46868252754211, -1, 1, 2.0897901058197, 9.4075756072998), Drawings[3: 'Circle1', 'Circle2', 'Circle3'], 'View Data'('Render Mode'=1, 'Show Ruler'=1, 'Coordinate Systems View Mode'=1, 'CS Triad View Mode'=0, 'Render Facets'=1, GridVisible=1, GridAutoAdjust=1, GridAutoExtents=1, GridType='Rect', GridStyle='Line', NumPixels=30, dXForGrid=0.2, dYForGrid=0.2, dZForGrid=0.2, dRForGrid=0.2, dThetaForGrid=10), ClipPlanes(ClipPlaneOptions(DisableWhenDrawingNewPlane=true, ForceOpqaueForUnclipped=false, ShowClipped=false, Transparency=0, HandleColor=16776960)))))
1792+
Circuit(Editor3d(View('View Orientation Gadget'=1, WindowPos(5, -1, -1, -9, -38, 32, 32, 1483, 371), OrientationMatrix(0.591607928276062, 1.77360472974897e-08, -7.6313835251085e-09, 0, 1.27724231191451e-08, 0.591607928276062, 0, 0, -1.15353318008715e-08, -5.96046447753906e-08, 0.591607928276062, 0, -1.19209289550781e-07, 2.38418579101562e-07, -5.7486834526062, 1, 0, -3.46180534362793, 3.46180534362793, -1, 1, 2.0897901058197, 9.4075756072998), Drawings[3: 'Circle1', 'Circle2', 'Circle3'], 'View Data'('Render Mode'=1, 'Show Ruler'=1, 'Coordinate Systems View Mode'=1, 'CS Triad View Mode'=0, 'Render Facets'=1, GridVisible=1, GridAutoAdjust=1, GridAutoExtents=1, GridType='Rect', GridStyle='Line', NumPixels=30, dXForGrid=0.5, dYForGrid=0.5, dZForGrid=0.5, dRForGrid=0.5, dThetaForGrid=10), ClipPlanes(ClipPlaneOptions(DisableWhenDrawingNewPlane=true, ForceOpqaueForUnclipped=false, ShowClipped=false, Transparency=0, HandleColor=16776960)))))
18071793
$end 'EditorWindow'
18081794
$end 'WindowPosition'
18091795
$begin 'ReportSetup'

_unittest/test_22_Circuit_DynamicLink.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ def setup_class(self):
2929
example_project = os.path.join(local_path, "example_models", test_project_name + ".aedt")
3030
source_project = os.path.join(local_path, "example_models", src_project_name + ".aedt")
3131
linked_project = os.path.join(local_path, "example_models", linked_project_name + ".aedt")
32-
32+
q3d = (os.path.join(local_path, "example_models", "q2d_q3d.aedt"),)
3333
self.test_project = self.local_scratch.copyfile(example_project)
3434
self.test_src_project = self.local_scratch.copyfile(source_project)
3535
self.test_lkd_project = self.local_scratch.copyfile(linked_project)
36+
self.q3d = self.local_scratch.copyfile(linked_project)
37+
3638
self.local_scratch.copyfolder(
3739
os.path.join(local_path, "example_models", test_project_name + ".aedb"),
3840
os.path.join(self.local_scratch.path, test_project_name + ".aedb"),
@@ -187,11 +189,8 @@ def test_09_setup(self):
187189
assert LNA_setup.update()
188190

189191
def test_10_q3d_link(self):
190-
q2d = Q2d(
191-
projectname=os.path.join(local_path, "example_models", "q2d_q3d.aedt"), specified_version=desktop_version
192-
)
192+
q2d = Q2d(projectname=self.q3d, specified_version=desktop_version)
193193
assert self.aedtapp.modeler.schematic.add_subcircuit_dynamic_link(q2d)
194-
q3d = Q3d(
195-
projectname=os.path.join(local_path, "example_models", "q2d_q3d.aedt"), specified_version=desktop_version
196-
)
194+
q3d = Q3d(specified_version=desktop_version)
197195
assert self.aedtapp.modeler.schematic.add_subcircuit_dynamic_link(q3d)
196+
self.aedtapp.close_project(q3d.project_name, False)

_unittest/test_30_Q2D.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33
# Setup paths for module imports
4-
from _unittest.conftest import scratch_path
4+
from _unittest.conftest import scratch_path, local_path, desktop_version
55
import gc
66

77
# Import required modules
@@ -15,7 +15,8 @@ class TestClass:
1515
def setup_class(self):
1616
# set a scratch directory and the environment / test data
1717
with Scratch(scratch_path) as self.local_scratch:
18-
self.aedtapp = Q2d()
18+
self.aedtapp = Q2d(specified_version=desktop_version)
19+
self.test_matrix = self.local_scratch.copyfile(os.path.join(local_path, "example_models", "q2d_q3d.aedt"))
1920

2021
def teardown_class(self):
2122
self.aedtapp._desktop.ClearMessages("", "", 3)
@@ -63,3 +64,20 @@ def test_10_toggle_condcutor(self):
6364
assert self.aedtapp.toggle_conductor_type("Rectangle1", "ReferenceGround")
6465
assert not self.aedtapp.toggle_conductor_type("Rectangle3", "ReferenceGround")
6566
assert not self.aedtapp.toggle_conductor_type("Rectangle2", "ReferenceggGround")
67+
68+
def test_11_matrix_reduction(self):
69+
q2d = Q2d(self.test_matrix, specified_version=desktop_version)
70+
assert q2d.matrices[0].name == "Original"
71+
assert len(q2d.matrices[0].sources()) > 0
72+
assert len(q2d.matrices[0].sources(False)) > 0
73+
assert q2d.insert_reduced_matrix(q2d.MATRIXOPERATIONS.Float, "Circle2", "Test1")
74+
assert q2d.matrices[1].name == "Test1"
75+
assert q2d.insert_reduced_matrix(q2d.MATRIXOPERATIONS.AddGround, "Circle2", "Test2")
76+
assert q2d.matrices[2].name == "Test2"
77+
assert q2d.insert_reduced_matrix(q2d.MATRIXOPERATIONS.SetReferenceGround, "Circle2", "Test3")
78+
assert q2d.matrices[3].name == "Test3"
79+
assert q2d.insert_reduced_matrix(q2d.MATRIXOPERATIONS.Parallel, ["Circle2", "Circle3"], "Test4")
80+
assert q2d.matrices[4].name == "Test4"
81+
assert q2d.insert_reduced_matrix(q2d.MATRIXOPERATIONS.DiffPair, ["Circle2", "Circle3"], "Test5")
82+
assert q2d.matrices[5].name == "Test5"
83+
self.aedtapp.close_project(q2d.project_name, False)

_unittest/test_31_Q3D.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33
# Setup paths for module imports
4-
from _unittest.conftest import scratch_path, local_path
4+
from _unittest.conftest import scratch_path, local_path, desktop_version
55
import gc
66

77
# Import required modules
@@ -16,9 +16,10 @@ class TestClass:
1616
def setup_class(self):
1717
# set a scratch directory and the environment / test data
1818
with Scratch(scratch_path) as self.local_scratch:
19-
self.aedtapp = Q3d()
19+
self.aedtapp = Q3d(specified_version=desktop_version)
2020
example_project = os.path.join(local_path, "example_models", bondwire_project_name + ".aedt")
2121
self.test_project = self.local_scratch.copyfile(example_project)
22+
self.test_matrix = self.local_scratch.copyfile(os.path.join(local_path, "example_models", "q2d_q3d.aedt"))
2223

2324
def teardown_class(self):
2425
self.aedtapp._desktop.ClearMessages("", "", 3)
@@ -106,7 +107,7 @@ def test_08_create_faceted_bondwire(self):
106107
pass
107108

108109
def test_10_q2d(self):
109-
q2d = Q2d()
110+
q2d = Q2d(specified_version=desktop_version)
110111
assert q2d
111112
assert q2d.dim == "2D"
112113
pass
@@ -130,3 +131,34 @@ def test_11_assign_net(self):
130131
def test_12_mesh_settings(self):
131132
assert self.aedtapp.mesh.initial_mesh_settings
132133
assert self.aedtapp.mesh.initial_mesh_settings.props
134+
135+
def test_13_matrix_reduction(self):
136+
q3d = Q3d(self.test_matrix, specified_version="2021.2")
137+
assert q3d.matrices[0].name == "Original"
138+
assert len(q3d.matrices[0].sources()) > 0
139+
assert len(q3d.matrices[0].sources(False)) > 0
140+
assert q3d.insert_reduced_matrix("JoinSeries", ["Source1", "Sink4"], "JointTest")
141+
assert q3d.matrices[1].name == "JointTest"
142+
assert q3d.insert_reduced_matrix("JoinParallel", ["Source1", "Source2"], "JointTest2")
143+
assert q3d.matrices[2].name == "JointTest2"
144+
assert q3d.insert_reduced_matrix("FloatInfinity", None, "JointTest3")
145+
assert q3d.matrices[3].name == "JointTest3"
146+
assert q3d.insert_reduced_matrix(q3d.MATRIXOPERATIONS.MoveSink, "Source2", "JointTest4")
147+
assert q3d.matrices[4].name == "JointTest4"
148+
assert q3d.insert_reduced_matrix(q3d.MATRIXOPERATIONS.ReturnPath, "Source2", "JointTest5")
149+
assert q3d.matrices[5].name == "JointTest5"
150+
assert q3d.insert_reduced_matrix(q3d.MATRIXOPERATIONS.GroundNet, "Box1", "JointTest6")
151+
assert q3d.matrices[6].name == "JointTest6"
152+
assert q3d.insert_reduced_matrix(q3d.MATRIXOPERATIONS.FloatTerminal, "Source2", "JointTest7")
153+
assert q3d.matrices[7].name == "JointTest7"
154+
assert q3d.matrices[7].delete()
155+
assert q3d.matrices[6].add_operation(q3d.MATRIXOPERATIONS.ReturnPath, "Source2")
156+
full_list = q3d.matrices[0].get_sources_for_plot()
157+
mutual_list = q3d.matrices[0].get_sources_for_plot(
158+
get_self_terms=False, category=q3d.matrices[0].CATEGORIES.Q3D.ACL
159+
)
160+
assert len(full_list) > len(mutual_list)
161+
assert q3d.matrices[0].get_sources_for_plot(first_element_filter="Box?", second_element_filter="B*2") == [
162+
"C(Box1,Box1_2)"
163+
]
164+
self.aedtapp.close_project(q3d.project_name, False)

examples/05-Q3D/Q3D_Example.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@
112112
# ~~~~~~~~~~~~~~~~~~~~~~~~~
113113
# This command creates a rectangular plot and a Data Table.
114114

115-
q.post.create_rectangular_plot(expression="C(Bar1,Bar1)", context="Original")
115+
data_plot_self = q.matrices[0].get_sources_for_plot(get_self_terms=True, get_mutual_terms=False)
116116

117-
q.post.create_rectangular_plot(expression="C(Bar1,Bar1)", context="Original", plot_type="Data Table")
117+
q.post.create_rectangular_plot(expression=data_plot_self, context="Original")
118+
119+
data_plot_mutual = q.matrices[0].get_sources_for_plot(get_self_terms=False, get_mutual_terms=True)
120+
121+
q.post.create_rectangular_plot(expression=data_plot_mutual, context="Original", plot_type="Data Table")
118122

119123
###############################################################################
120124
# Solve the Setup
@@ -128,7 +132,7 @@
128132
# ~~~~~~~~~~~~~~~
129133
# This command get the report data into a Data Structure that allows to manipulate them.
130134

131-
a = q.post.get_report_data(expression="C(Bar1,Bar1)", domain=["Context:=", "Original"])
135+
a = q.post.get_report_data(expression=data_plot_self, domain=["Context:=", "Original"])
132136
a.sweeps["Freq"]
133137
a.data_magnitude()
134138

pyaedt/generic/constants.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,57 @@ class GLOBALCS(object):
369369
(XY, YZ, ZX) = ("Global:XY", "Global:YZ", "Global:XZ")
370370

371371

372+
class MATRIXOPERATIONSQ3D(object):
373+
"""Matrix Reduction types."""
374+
375+
(JoinSeries, JoinParallel, FloatNet, GroundNet, FloatTerminal, FloatInfinity, ReturnPath, AddSink, MoveSink) = (
376+
"JoinSeries",
377+
"JoinParallel",
378+
"FloatNet",
379+
"GroundNet",
380+
"FloatTerminal",
381+
"FloatInfinity",
382+
"ReturnPath",
383+
"AddSink",
384+
"MoveSink",
385+
)
386+
387+
388+
class MATRIXOPERATIONSQ2D(object):
389+
"""Matrix Reduction types."""
390+
391+
(AddGround, SetReferenceGround, Float, Parallel, DiffPair) = (
392+
"AddGround",
393+
"SetReferenceGround",
394+
"Float",
395+
"Parallel",
396+
"DiffPair",
397+
)
398+
399+
400+
class CATEGORIESQ3D(object):
401+
"""Plot Categories for Q2d and Q3d."""
402+
403+
class Q2D(object):
404+
(
405+
CMatrix,
406+
GMatrix,
407+
RMatrix,
408+
LMatrix,
409+
LumpedC,
410+
LumpedG,
411+
LumpedR,
412+
LumpedL,
413+
CharacteristicImpedance,
414+
CrossTalkForward,
415+
LumpedCrossTalkForward,
416+
CrossTalkBackward,
417+
) = ("C", "G", "R", "L", "lumpC", "lumpG", "lumpR", "lumpL", "Z0", "Kf", "lumpKf", "Kb")
418+
419+
class Q3D(object):
420+
(C, G, DCL, DCR, ACL, ACR) = ("C", "G", "DCL", "DCR", "ACL", "ACR")
421+
422+
372423
class CSMODE(object):
373424
"""COORDINATE SYSTEM MODE Enumerator class."""
374425

pyaedt/modeler/PrimitivesNexxim.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ def add_subcircuit_dynamic_link(
12211221
sinks.append(excts[i])
12221222
i += 2
12231223
pin_names = sources + sinks
1224+
matrix = ["NAME:Reduce Matrix Choices"] + list(pyaedt_app.omatrix.ListReduceMatrixes())
12241225
elif pyaedt_app.design_type == "2D Extractor":
12251226
excts = list(pyaedt_app.oboundary.GetExcitations())
12261227
pins = []
@@ -1233,6 +1234,7 @@ def add_subcircuit_dynamic_link(
12331234
pin_names.append("Input_ref")
12341235
pin_names.extend([i + "_out" for i in pins])
12351236
pin_names.append("Output_ref")
1237+
matrix = ["NAME:Reduce Matrix Choices"] + list(pyaedt_app.omatrix.ListReduceMatrixes())
12361238
variables = {}
12371239
if map_source_variables:
12381240
for k, v in pyaedt_app.variable_manager.variables.items():

0 commit comments

Comments
 (0)