Skip to content

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

Merged
2 commits merged into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
45 changes: 45 additions & 0 deletions _unittest/test_36_Q2D_PostProcessing.py
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"))
Copy link
Author

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.

Copy link
Collaborator

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

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)
6 changes: 5 additions & 1 deletion pyaedt/application/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,11 @@ def list_of_variations(self, setup_name=None, sweep_name=None):
elif not sweep_name:
self.logger.warning("No Sweep defined.")
return False
if self.solution_type == "HFSS3DLayout" or self.solution_type == "HFSS 3D Layout Design":
if (
self.solution_type == "HFSS3DLayout"
or self.solution_type == "HFSS 3D Layout Design"
or self.design_type == "2D Extractor"
):
try:
return list(self.osolution.ListVariations("{0} : {1}".format(setup_name, sweep_name)))
except:
Expand Down
123 changes: 123 additions & 0 deletions pyaedt/q3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
analyze : bool
analyze : bool, optional

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if len(sweeps) == 0:
if not sweeps:

sweeps = ["LastAdaptive"]
else:
pass
Copy link
Contributor

Choose a reason for hiding this comment

The 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:
Copy link
Contributor

Choose a reason for hiding this comment

The 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
except:
except: # pragma: no cover

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Suggested change
except:
except: # pragma: no cover

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.
Expand Down