Skip to content

Commit 274766d

Browse files
authored
Add export_w_elements to Q2d (#995)
* Add export_w_elements to Q2d Add a method to export all available variation W-elements from a 2D Extractor design. * Feedback from review and a new test Incorporate feedback from review and add a test for when export_folder is not supplied.
1 parent f88ddfb commit 274766d

File tree

5 files changed

+188
-1
lines changed

5 files changed

+188
-1
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os
2+
3+
from _unittest.conftest import BasisTest
4+
from _unittest.conftest import local_path
5+
from _unittest.conftest import new_thread
6+
from pyaedt import Q2d
7+
from pyaedt import settings
8+
9+
10+
class TestClass(BasisTest, object):
11+
def setup_class(self):
12+
BasisTest.my_setup(self)
13+
14+
def teardown_class(self):
15+
BasisTest.my_teardown(self)
16+
17+
def test_01_export_w_elements_from_sweep(self):
18+
test_project = self.local_scratch.copyfile(os.path.join(local_path, "example_models", "q2d_solved_sweep.aedtz"))
19+
with Q2d(test_project, non_graphical=settings.non_graphical, new_desktop_session=new_thread) as q2d:
20+
try:
21+
export_folder = os.path.join(self.local_scratch.path, "export_folder")
22+
files = q2d.export_w_elements(False, export_folder)
23+
assert len(files) == 3
24+
for file in files:
25+
_, ext = os.path.splitext(file)
26+
assert ext == ".sp"
27+
assert os.path.isfile(file)
28+
finally:
29+
q2d.close_project(saveproject=False)
30+
31+
def test_02_export_w_elements_from_nominal(self):
32+
test_project = self.local_scratch.copyfile(
33+
os.path.join(local_path, "example_models", "q2d_solved_nominal.aedtz")
34+
)
35+
with Q2d(test_project, non_graphical=settings.non_graphical, new_desktop_session=new_thread) as q2d:
36+
try:
37+
export_folder = os.path.join(self.local_scratch.path, "export_folder")
38+
files = q2d.export_w_elements(False, export_folder)
39+
assert len(files) == 1
40+
for file in files:
41+
_, ext = os.path.splitext(file)
42+
assert ext == ".sp"
43+
assert os.path.isfile(file)
44+
finally:
45+
q2d.close_project(saveproject=False)
46+
47+
def test_03_export_w_elements_to_working_directory(self):
48+
test_project = self.local_scratch.copyfile(
49+
os.path.join(local_path, "example_models", "q2d_solved_nominal.aedtz")
50+
)
51+
with Q2d(test_project, non_graphical=settings.non_graphical, new_desktop_session=new_thread) as q2d:
52+
try:
53+
files = q2d.export_w_elements(False)
54+
assert len(files) == 1
55+
for file in files:
56+
_, ext = os.path.splitext(file)
57+
assert ext == ".sp"
58+
assert os.path.isfile(file)
59+
file_dir = os.path.abspath(os.path.dirname(file))
60+
assert file_dir == os.path.abspath(q2d.working_directory)
61+
finally:
62+
q2d.close_project(saveproject=False)

pyaedt/application/Analysis.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,11 @@ def list_of_variations(self, setup_name=None, sweep_name=None):
625625
elif not sweep_name:
626626
self.logger.warning("No Sweep defined.")
627627
return False
628-
if self.solution_type == "HFSS3DLayout" or self.solution_type == "HFSS 3D Layout Design":
628+
if (
629+
self.solution_type == "HFSS3DLayout"
630+
or self.solution_type == "HFSS 3D Layout Design"
631+
or self.design_type == "2D Extractor"
632+
):
629633
try:
630634
return list(self.osolution.ListVariations("{0} : {1}".format(setup_name, sweep_name)))
631635
except:

pyaedt/q3d.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,127 @@ def auto_assign_conductors(self):
10171017
self.logger.info("No new nets identified")
10181018
return True
10191019

1020+
@pyaedt_function_handler()
1021+
def export_w_elements(self, analyze=False, export_folder=None):
1022+
"""Export all available W-elements to files.
1023+
1024+
Parameters
1025+
----------
1026+
analyze : bool, optional
1027+
Whether to analyze before export. Solutions must be present for the design.
1028+
The default is ``False``.
1029+
export_folder : str, optional
1030+
Full path to the folder to export files into. The default is ``None``, in
1031+
which case the working directory is used.
1032+
1033+
Returns
1034+
-------
1035+
list
1036+
List of all exported files.
1037+
"""
1038+
exported_files = []
1039+
if not export_folder:
1040+
export_folder = self.working_directory
1041+
if not os.path.exists(export_folder):
1042+
os.makedirs(export_folder)
1043+
if analyze:
1044+
self.analyze_all()
1045+
setups = self.oanalysis.GetSetups()
1046+
1047+
for s in setups:
1048+
sweeps = self.oanalysis.GetSweeps(s)
1049+
if not sweeps:
1050+
sweeps = ["LastAdaptive"]
1051+
for sweep in sweeps:
1052+
variation_array = self.list_of_variations(s, sweep)
1053+
solution_name = "{} : {}".format(s, sweep)
1054+
if len(variation_array) == 1:
1055+
try:
1056+
export_file = "{}_{}_{}.sp".format(self.project_name, s, sweep)
1057+
export_path = os.path.join(export_folder, export_file)
1058+
subckt_name = "w_{}".format(self.project_name)
1059+
self.oanalysis.ExportCircuit(
1060+
solution_name,
1061+
variation_array[0],
1062+
export_path,
1063+
[
1064+
"NAME:CircuitData",
1065+
"MatrixName:=",
1066+
"Original",
1067+
"NumberOfCells:=",
1068+
"1",
1069+
"UserHasChangedSettings:=",
1070+
True,
1071+
"IncludeCap:=",
1072+
False,
1073+
"IncludeCond:=",
1074+
False,
1075+
["NAME:CouplingLimits", "CouplingLimitType:=", "None"],
1076+
"IncludeR:=",
1077+
False,
1078+
"IncludeL:=",
1079+
False,
1080+
"ExportDistributed:=",
1081+
True,
1082+
"LumpedLength:=",
1083+
"1meter",
1084+
"RiseTime:=",
1085+
"1e-09s",
1086+
],
1087+
subckt_name,
1088+
"WElement",
1089+
0,
1090+
)
1091+
exported_files.append(export_path)
1092+
self.logger.info("Exported W-element: %s", export_path)
1093+
except: # pragma: no cover
1094+
self.logger.warning("Export W-element failed")
1095+
else:
1096+
varCount = 0
1097+
for variation in variation_array:
1098+
varCount += 1
1099+
try:
1100+
export_file = "{}_{}_{}_{}.sp".format(self.project_name, s, sweep, varCount)
1101+
export_path = os.path.join(export_folder, export_file)
1102+
subckt_name = "w_{}_{}".format(self.project_name, varCount)
1103+
self.oanalysis.ExportCircuit(
1104+
solution_name,
1105+
variation,
1106+
export_path,
1107+
[
1108+
"NAME:CircuitData",
1109+
"MatrixName:=",
1110+
"Original",
1111+
"NumberOfCells:=",
1112+
"1",
1113+
"UserHasChangedSettings:=",
1114+
True,
1115+
"IncludeCap:=",
1116+
False,
1117+
"IncludeCond:=",
1118+
False,
1119+
["NAME:CouplingLimits", "CouplingLimitType:=", "None"],
1120+
"IncludeR:=",
1121+
False,
1122+
"IncludeL:=",
1123+
False,
1124+
"ExportDistributed:=",
1125+
True,
1126+
"LumpedLength:=",
1127+
"1meter",
1128+
"RiseTime:=",
1129+
"1e-09s",
1130+
],
1131+
subckt_name,
1132+
"WElement",
1133+
0,
1134+
)
1135+
exported_files.append(export_path)
1136+
self.logger.info("Exported W-element: %s", export_path)
1137+
except: # pragma: no cover
1138+
self.logger.warning("Export W-element failed")
1139+
return exported_files
1140+
10201141
@pyaedt_function_handler()
10211142
def toggle_conductor_type(self, conductor_name, new_type):
10221143
"""Change the conductor type.

0 commit comments

Comments
 (0)