Skip to content

Commit ac4b244

Browse files
amichel0205pre-commit-ci[bot]gmalinveMaxJPReyPipKat
authored
Create new function to import GDS file in HFSS (#4142)
* Create new function to import GDS file in HFSS * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix import_method typo in documentation * Fix issue for parameter import_method in documentation * Remove color list parameter * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Make parameters elevation_list and thickness_list optional * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove unnecessary comments * add unit test test_68_import_gds_3d * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add more test in test test_68_import_gds_3d * fix close project in test test_68_import_gds_3d * rework test test_68_import_gds_3d * rework test test_68_import_gds_3d * Removed unnecessary variable in test_20_HFSS Fixed typo and improve clarity of commenst * improve code format line 1372 * improve doc string format * improve code format * Add # pragma: no cover * modify for loop Improve doc string format * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix typo in doc string * pragma no cover * fix typo in doc string * fixed References * Update _unittest/test_20_HFSS.py Co-authored-by: Maxime Rey <[email protected]> * Update pyaedt/application/Analysis3D.py Co-authored-by: Kathy Pippert <[email protected]> * Update pyaedt/application/Analysis3D.py Co-authored-by: Kathy Pippert <[email protected]> * Update pyaedt/application/Analysis3D.py Co-authored-by: Kathy Pippert <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update pyaedt/application/Analysis3D.py Co-authored-by: Kathy Pippert <[email protected]> * Update pyaedt/application/Analysis3D.py Co-authored-by: Kathy Pippert <[email protected]> * Refactor import_gds_3d replace 3 list with a dictionary Update test_20_HFSS.py/test_68_import_gds_3d Add example section in documentation section * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update Analysis3D.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add # pragma: no cover as this function does not work in non graphical mode * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Giulia Malinverno <[email protected]> Co-authored-by: Maxime Rey <[email protected]> Co-authored-by: Kathy Pippert <[email protected]> Co-authored-by: Samuel Lopez <[email protected]>
1 parent 81e8810 commit ac4b244

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

_unittest/test_20_HFSS.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,3 +1624,14 @@ def test_67_transient_composite(self, add_app):
16241624
aedtapp.solution_type = "Transient Composite"
16251625
assert aedtapp.solution_type == "Transient Composite"
16261626
aedtapp.close_project(save_project=False)
1627+
1628+
@pytest.mark.skipif(config["NonGraphical"], reason="Test fails on build machine")
1629+
def test_68_import_gds_3d(self):
1630+
self.aedtapp.insert_design("gds_import_H3D")
1631+
gds_file = os.path.join(local_path, "example_models", "cad", "GDS", "gds1.gds")
1632+
assert self.aedtapp.import_gds_3d(gds_file, {7: (100, 10), 9: (110, 5)})
1633+
assert self.aedtapp.import_gds_3d(gds_file, {7: (0, 0), 9: (0, 0)})
1634+
assert self.aedtapp.import_gds_3d(gds_file, {7: (100e-3, 10e-3), 9: (110e-3, 5e-3)}, "mm", 0)
1635+
assert not self.aedtapp.import_gds_3d(gds_file, {})
1636+
gds_file = os.path.join(local_path, "example_models", "cad", "GDS", "gds1not.gds")
1637+
assert not self.aedtapp.import_gds_3d(gds_file, {7: (100, 10), 9: (110, 5)})

pyaedt/application/Analysis3D.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from pyaedt.application.Analysis import Analysis
77
from pyaedt.generic.configurations import Configurations
8+
from pyaedt.generic.constants import unit_converter
89
from pyaedt.generic.general_methods import generate_unique_name
910
from pyaedt.generic.general_methods import is_ironpython
1011
from pyaedt.generic.general_methods import open_file
@@ -1277,6 +1278,106 @@ def import_dxf(
12771278
self.oeditor.ImportDXF(vArg1)
12781279
return True
12791280

1281+
@pyaedt_function_handler
1282+
def import_gds_3d(self, gds_file, gds_number, unit="um", import_method=1): # pragma: no cover
1283+
"""Import a GDSII file.
1284+
1285+
Parameters
1286+
----------
1287+
gds_file : str
1288+
Path to the GDS file.
1289+
gds_number : dict
1290+
Dictionary keys are GDS layer numbers, and the value is a tuple with the thickness and elevation.
1291+
unit : string, optional
1292+
Length unit values. The default is ``"um"``.
1293+
import_method : integer, optional
1294+
GDSII import method. The default is ``1``. Options are:
1295+
1296+
- ``0`` for script.
1297+
- ``1`` for Parasolid.
1298+
1299+
Returns
1300+
-------
1301+
bool
1302+
``True`` when successful, ``False`` when failed.
1303+
1304+
References
1305+
----------
1306+
>>> oEditor.ImportGDSII
1307+
1308+
Examples
1309+
--------
1310+
Import a GDS file in an HFSS 3D project.
1311+
1312+
>>> gds_path = r"C:\temp\gds1.gds"
1313+
>>> from pyaedt import Hfss
1314+
>>> hfss = Hfss()
1315+
>>> gds_number = {7: (100, 10), 9: (110, 5)}
1316+
>>> hfss.import_gds_3d(gds_path, gds_number, unit="um", import_method=1)
1317+
1318+
"""
1319+
1320+
if self.desktop_class.non_graphical:
1321+
self.logger.error("Method is supported only in graphical mode.")
1322+
return False
1323+
if not os.path.exists(gds_file):
1324+
self.logger.error("GDSII file does not exist. No layer is imported.")
1325+
return False
1326+
if len(gds_number) == 0:
1327+
self.logger.error("Dictionary for GDSII layer numbers is empty. No layer is imported.")
1328+
return False
1329+
1330+
layermap = ["NAME:LayerMap"]
1331+
ordermap = []
1332+
for i, k in enumerate(gds_number):
1333+
layername = "signal" + str(k)
1334+
layermap.append(
1335+
[
1336+
"NAME:LayerMapInfo",
1337+
"LayerNum:=",
1338+
k,
1339+
"DestLayer:=",
1340+
layername,
1341+
"layer_type:=",
1342+
"signal",
1343+
]
1344+
)
1345+
ordermap1 = [
1346+
"entry:=",
1347+
[
1348+
"order:=",
1349+
i,
1350+
"layer:=",
1351+
layername,
1352+
"LayerNumber:=",
1353+
k,
1354+
"Thickness:=",
1355+
unit_converter(gds_number[k][1], unit_system="Length", input_units=unit, output_units="meter"),
1356+
"Elevation:=",
1357+
unit_converter(gds_number[k][0], unit_system="Length", input_units=unit, output_units="meter"),
1358+
"Color:=",
1359+
"color",
1360+
],
1361+
]
1362+
ordermap.extend(ordermap1)
1363+
1364+
self.oeditor.ImportGDSII(
1365+
[
1366+
"NAME:options",
1367+
"FileName:=",
1368+
gds_file,
1369+
"FlattenHierarchy:=",
1370+
True,
1371+
"ImportMethod:=",
1372+
import_method,
1373+
layermap,
1374+
"OrderMap:=",
1375+
ordermap,
1376+
]
1377+
)
1378+
self.logger.info("GDS layer imported with elevations and thickness.")
1379+
return True
1380+
12801381
@pyaedt_function_handler()
12811382
def _find_indices(self, list_to_check, item_to_find):
12821383
# type: (list, str|int) -> list

0 commit comments

Comments
 (0)