-
Notifications
You must be signed in to change notification settings - Fork 162
Add export_w_elements to Q2d #995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
|
||
from _unittest.conftest import BasisTest | ||
from _unittest.conftest import local_path | ||
from _unittest.conftest import new_thread | ||
from pyaedt import Q2d | ||
from pyaedt import settings | ||
|
||
|
||
class TestClass(BasisTest, object): | ||
def setup_class(self): | ||
BasisTest.my_setup(self) | ||
|
||
def teardown_class(self): | ||
BasisTest.my_teardown(self) | ||
|
||
def test_01_export_w_elements_from_sweep(self): | ||
test_project = self.local_scratch.copyfile(os.path.join(local_path, "example_models", "q2d_solved_sweep.aedtz")) | ||
with Q2d(test_project, non_graphical=settings.non_graphical, new_desktop_session=new_thread) as q2d: | ||
try: | ||
export_folder = os.path.join(self.local_scratch.path, "export_folder") | ||
files = q2d.export_w_elements(False, export_folder) | ||
assert len(files) == 3 | ||
for file in files: | ||
_, ext = os.path.splitext(file) | ||
assert ext == ".sp" | ||
assert os.path.isfile(file) | ||
finally: | ||
q2d.close_project(saveproject=False) | ||
|
||
def test_02_export_w_elements_from_nominal(self): | ||
test_project = self.local_scratch.copyfile( | ||
os.path.join(local_path, "example_models", "q2d_solved_nominal.aedtz") | ||
) | ||
with Q2d(test_project, non_graphical=settings.non_graphical, new_desktop_session=new_thread) as q2d: | ||
try: | ||
export_folder = os.path.join(self.local_scratch.path, "export_folder") | ||
files = q2d.export_w_elements(False, export_folder) | ||
assert len(files) == 1 | ||
for file in files: | ||
_, ext = os.path.splitext(file) | ||
assert ext == ".sp" | ||
assert os.path.isfile(file) | ||
finally: | ||
q2d.close_project(saveproject=False) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1017,6 +1017,129 @@ def auto_assign_conductors(self): | |||||
self.logger.info("No new nets identified") | ||||||
return True | ||||||
|
||||||
@pyaedt_function_handler() | ||||||
def export_w_elements(self, analyze=False, export_folder=None): | ||||||
"""Export all available W-elements to files. | ||||||
|
||||||
Parameters | ||||||
---------- | ||||||
analyze : bool | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Whether to analyze before export. Solutions must be present for the design. | ||||||
The default is ``False``. | ||||||
export_folder : str, optional | ||||||
Full path to the folder to export files into. The default is ``None``, in | ||||||
which case the working directory is used. | ||||||
|
||||||
Returns | ||||||
------- | ||||||
list | ||||||
List of all exported files. | ||||||
""" | ||||||
exported_files = [] | ||||||
if not export_folder: | ||||||
export_folder = self.working_directory | ||||||
if not os.path.exists(export_folder): | ||||||
os.makedirs(export_folder) | ||||||
if analyze: | ||||||
self.analyze_all() | ||||||
setups = self.oanalysis.GetSetups() | ||||||
|
||||||
for s in setups: | ||||||
sweeps = self.oanalysis.GetSweeps(s) | ||||||
if len(sweeps) == 0: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
sweeps = ["LastAdaptive"] | ||||||
else: | ||||||
pass | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This else doesn't seem necessary. |
||||||
for sweep in sweeps: | ||||||
variation_array = self.list_of_variations(s, sweep) | ||||||
solution_name = "{} : {}".format(s, sweep) | ||||||
if len(variation_array) == 1: | ||||||
try: | ||||||
export_file = "{}_{}_{}.sp".format(self.project_name, s, sweep) | ||||||
export_path = os.path.join(export_folder, export_file) | ||||||
subckt_name = "w_{}".format(self.project_name) | ||||||
self.oanalysis.ExportCircuit( | ||||||
solution_name, | ||||||
variation_array[0], | ||||||
export_path, | ||||||
[ | ||||||
"NAME:CircuitData", | ||||||
"MatrixName:=", | ||||||
"Original", | ||||||
"NumberOfCells:=", | ||||||
"1", | ||||||
"UserHasChangedSettings:=", | ||||||
True, | ||||||
"IncludeCap:=", | ||||||
False, | ||||||
"IncludeCond:=", | ||||||
False, | ||||||
["NAME:CouplingLimits", "CouplingLimitType:=", "None"], | ||||||
"IncludeR:=", | ||||||
False, | ||||||
"IncludeL:=", | ||||||
False, | ||||||
"ExportDistributed:=", | ||||||
True, | ||||||
"LumpedLength:=", | ||||||
"1meter", | ||||||
"RiseTime:=", | ||||||
"1e-09s", | ||||||
], | ||||||
subckt_name, | ||||||
"WElement", | ||||||
0, | ||||||
) | ||||||
exported_files.append(export_path) | ||||||
self.logger.info("Exported W-element: %s", export_path) | ||||||
except: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't look like we'll be able to hit this with unit testing.
Suggested change
|
||||||
self.logger.warning("Export W-element failed") | ||||||
else: | ||||||
varCount = 0 | ||||||
for variation in variation_array: | ||||||
varCount += 1 | ||||||
try: | ||||||
export_file = "{}_{}_{}_{}.sp".format(self.project_name, s, sweep, varCount) | ||||||
export_path = os.path.join(export_folder, export_file) | ||||||
subckt_name = "w_{}_{}".format(self.project_name, varCount) | ||||||
self.oanalysis.ExportCircuit( | ||||||
solution_name, | ||||||
variation, | ||||||
export_path, | ||||||
[ | ||||||
"NAME:CircuitData", | ||||||
"MatrixName:=", | ||||||
"Original", | ||||||
"NumberOfCells:=", | ||||||
"1", | ||||||
"UserHasChangedSettings:=", | ||||||
True, | ||||||
"IncludeCap:=", | ||||||
False, | ||||||
"IncludeCond:=", | ||||||
False, | ||||||
["NAME:CouplingLimits", "CouplingLimitType:=", "None"], | ||||||
"IncludeR:=", | ||||||
False, | ||||||
"IncludeL:=", | ||||||
False, | ||||||
"ExportDistributed:=", | ||||||
True, | ||||||
"LumpedLength:=", | ||||||
"1meter", | ||||||
"RiseTime:=", | ||||||
"1e-09s", | ||||||
], | ||||||
subckt_name, | ||||||
"WElement", | ||||||
0, | ||||||
) | ||||||
exported_files.append(export_path) | ||||||
self.logger.info("Exported W-element: %s", export_path) | ||||||
except: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here.
Suggested change
|
||||||
self.logger.warning("Export W-element failed") | ||||||
return exported_files | ||||||
|
||||||
@pyaedt_function_handler() | ||||||
def toggle_conductor_type(self, conductor_name, new_type): | ||||||
"""Change the conductor type. | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure the best way to work with multiple projects in a single test class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented a method to do it in setup_class after you initialize BasisTest you can add your project
`
self.aedtapp1 = BasisTest.add_app(self, project_name="q2d_solved_sweep", application=Q2d)
self.aedtapp2 = BasisTest.add_app(self, project_name="q2d_solved_nominal", application=Q2d)
`
this method will take care of copying the file and opening the project and storing the app data in the variable that can be used in 1 or multiple tests and, at the end of the test, closing them