Skip to content

Commit

Permalink
Merge branch 'main' into release/0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcapodi78 authored and maxcapodi78 committed Mar 25, 2024
2 parents 997a0fb + 244d74a commit 82030aa
Show file tree
Hide file tree
Showing 18 changed files with 1,338 additions and 559 deletions.
2 changes: 1 addition & 1 deletion _unittest/test_02_3D_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_27_create_region(self):
assert self.aedtapp.modeler.create_air_region(20, 20, 30, 50, 50, 100, False)
self.aedtapp.modeler["Region"].delete()
self.aedtapp["region_param"] = "20mm"
assert self.aedtapp.modeler.create_air_region("region_param", 20, "30mm", "50", 50, 100, False)
assert self.aedtapp.modeler.create_air_region("region_param", 20, "30", "50", 50, 100, False)
assert self.aedtapp.modeler.edit_region_dimensions(["40mm", "30mm", 30, 50, 50, 100])
self.aedtapp.modeler["Region"].delete()
assert self.aedtapp.modeler.create_air_region("20", 20, 30, 50, 50, 100)
Expand Down
70 changes: 48 additions & 22 deletions _unittest/test_98_Icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pyaedt.generic.settings import settings
from pyaedt.modules.Boundary import NativeComponentObject
from pyaedt.modules.Boundary import NetworkObject
from pyaedt.modules.MeshIcepak import MeshRegion
from pyaedt.modules.SetupTemplates import SetupKeys

test_subfolder = "T98"
Expand Down Expand Up @@ -74,9 +75,17 @@ def test_02A_find_top(self):

def test_03_AssignPCBRegion(self):
self.aedtapp.globalMeshSettings(2)
self.aedtapp.create_meshregion_component()
pcb_mesh_region = self.aedtapp.mesh.MeshRegion(self.aedtapp.mesh.omeshmodule, [1, 1, 1], "mm", self.aedtapp)
assert self.aedtapp.create_meshregion_component()
self.aedtapp.modeler.create_box([0, 0, 0], [50, 50, 2], "PCB")
old_pcb_mesh_region = MeshRegion(
meshmodule=self.aedtapp.mesh.omeshmodule, dimension=[1, 1, 1], unit="mm", app=self.aedtapp
)
assert old_pcb_mesh_region.MaxElementSizeX == 1 / 20
assert old_pcb_mesh_region.MaxElementSizeY == 1 / 20
assert old_pcb_mesh_region.MaxElementSizeZ == 1 / 20
pcb_mesh_region = MeshRegion(self.aedtapp, "PCB")
pcb_mesh_region.name = "PCB_Region"
# backward compatibility check
pcb_mesh_region.UserSpecifiedSettings = True
pcb_mesh_region.MaxElementSizeX = 2
pcb_mesh_region.MaxElementSizeY = 2
Expand All @@ -90,9 +99,43 @@ def test_03_AssignPCBRegion(self):
pcb_mesh_region.MinGapX = 1
pcb_mesh_region.MinGapY = 1
pcb_mesh_region.MinGapZ = 1
pcb_mesh_region.Objects = ["Component_Region"]
assert pcb_mesh_region.create()
assert pcb_mesh_region.update()
if settings.aedt_version > "2023.2":
assert pcb_mesh_region.assignment.padding_values == ["0"] * 6
assert pcb_mesh_region.assignment.padding_types == ["Percentage Offset"] * 6
pcb_mesh_region.assignment.negative_x_padding = 1
pcb_mesh_region.assignment.positive_x_padding = 1
pcb_mesh_region.assignment.negative_y_padding = 1
pcb_mesh_region.assignment.positive_y_padding = 1
pcb_mesh_region.assignment.negative_z_padding = 1
pcb_mesh_region.assignment.positive_z_padding = 1
pcb_mesh_region.assignment.negative_x_padding_type = "Absolute Offset"
pcb_mesh_region.assignment.positive_x_padding_type = "Absolute Position"
pcb_mesh_region.assignment.negative_y_padding_type = "Transverse Percentage Offset"
pcb_mesh_region.assignment.positive_y_padding_type = "Absolute Position"
pcb_mesh_region.assignment.negative_z_padding_type = "Absolute Offset"
pcb_mesh_region.assignment.positive_z_padding_type = "Transverse Percentage Offset"
assert pcb_mesh_region.assignment.negative_x_padding == "1mm"
assert pcb_mesh_region.assignment.positive_x_padding == "1mm"
assert pcb_mesh_region.assignment.negative_y_padding == "1"
assert pcb_mesh_region.assignment.positive_y_padding == "1mm"
assert pcb_mesh_region.assignment.negative_z_padding == "1mm"
assert pcb_mesh_region.assignment.positive_z_padding == "1"
assert pcb_mesh_region.assignment.negative_x_padding_type == "Absolute Offset"
assert pcb_mesh_region.assignment.positive_x_padding_type == "Absolute Position"
assert pcb_mesh_region.assignment.negative_y_padding_type == "Transverse Percentage Offset"
assert pcb_mesh_region.assignment.positive_y_padding_type == "Absolute Position"
assert pcb_mesh_region.assignment.negative_z_padding_type == "Absolute Offset"
assert pcb_mesh_region.assignment.positive_z_padding_type == "Transverse Percentage Offset"
pcb_mesh_region.assignment.padding_values = 2
pcb_mesh_region.assignment.padding_types = "Absolute Offset"
assert pcb_mesh_region.assignment.padding_values == ["2mm"] * 6
assert pcb_mesh_region.assignment.padding_types == ["Absolute Offset"] * 6
subregion = self.aedtapp.modeler.create_subregion([50, 50, 50, 50, 100, 100], "Percentage Offset", "PCB")
else:
box = self.aedtapp.modeler.create_box([0, 0, 0], [1, 2, 3])
pcb_mesh_region.Objects = box.name
assert pcb_mesh_region.update()
assert self.aedtapp.mesh.meshregions_dict
assert pcb_mesh_region.delete()

Expand Down Expand Up @@ -219,24 +262,6 @@ def test_12b_failing_AssignMeshOperation(self):
assert not test.update()
assert test.delete()

def test_12c_AssignVirtualMeshOperation(self):
self.aedtapp.oproject = test_project_name
self.aedtapp.odesign = "IcepakDesign1"
group_name = "Group1"
mesh_level_Filter = "2"
component_name = ["RadioBoard1_1"]
mesh_level_RadioPCB = "1"
test = self.aedtapp.mesh.assign_mesh_level_to_group(mesh_level_Filter, group_name)
assert test
# assert self.aedtapp.mesh.assignMeshLevel2Component(mesh_level_RadioPCB, component_name)
test = self.aedtapp.mesh.assign_mesh_region(
component_name, mesh_level_RadioPCB, is_submodel=True, virtual_region=True
)
assert test
assert test.delete()
test = self.aedtapp.mesh.assign_mesh_region(["USB_ID"], mesh_level_RadioPCB, virtual_region=True)
assert test

def test_13a_assign_openings(self):
airfaces = [self.aedtapp.modeler["Region"].top_face_x.id]
openings = self.aedtapp.assign_openings(airfaces)
Expand Down Expand Up @@ -1305,6 +1330,7 @@ def test_66_update_3d_component(self):
component_filepath = self.aedtapp.modeler.user_defined_components["test"].get_component_filepath()
assert component_filepath
comp = self.aedtapp.modeler.user_defined_components["test"].edit_definition()
comp.modeler.refresh_all_ids()
comp.modeler.objects_by_name["surf1"].move([1, 1, 1])
comp.modeler.create_3dcomponent(component_filepath)
comp.close_project()
Expand Down
8 changes: 8 additions & 0 deletions pyaedt/application/Analysis3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,12 @@ def export_3d_model(
if removed_objects is None:
removed_objects = []

sub_regions = []
if self.settings.aedt_version > "2023.2":
sub_regions = [
o for o in self.modeler.non_model_objects if self.modeler[o].history().command == "CreateSubRegion"
]

if not object_list:
allObjects = self.modeler.object_names
if removed_objects:
Expand All @@ -585,6 +591,8 @@ def export_3d_model(
else:
if "Region" in allObjects:
allObjects.remove("Region")
for o in sub_regions:
allObjects.remove(o)
else:
allObjects = object_list[:]

Expand Down
6 changes: 3 additions & 3 deletions pyaedt/application/Analysis3DLayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def get_next_xtalk_list(self, trlist=[], tx_prefix=""):
return next

@pyaedt_function_handler()
def get_fext_xtalk_list(self, trlist=[], reclist=[], tx_prefix="", rx_prefix="", skip_same_index_couples=True):
def get_fext_xtalk_list(self, trlist=None, reclist=None, tx_prefix="", rx_prefix="", skip_same_index_couples=True):
"""Retrieve a list of all the far end XTalks from two lists of exctitations (driver and receiver).
Parameters
Expand Down Expand Up @@ -371,9 +371,9 @@ def get_fext_xtalk_list(self, trlist=[], reclist=[], tx_prefix="", rx_prefix="",
>>> oModule.GetAllPorts
"""
fext = []
if not trlist:
if trlist is None:
trlist = [i for i in self.excitations if tx_prefix in i]
if not reclist:
if reclist is None:
reclist = [i for i in self.excitations if rx_prefix in i]
for i in trlist:
for k in reclist:
Expand Down
9 changes: 2 additions & 7 deletions pyaedt/application/AnalysisNexxim.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,15 +526,10 @@ def get_fext_xtalk_list(self, trlist=None, reclist=None, tx_prefix="", rx_prefix
>>> oEditor.GetAllPorts
"""
if trlist == None:
trlist = []
if reclist == None:
reclist = []

fext = []
if not trlist:
if trlist is None:
trlist = [i for i in list(self.excitations.keys()) if tx_prefix in i]
if not reclist:
if reclist is None:
reclist = [i for i in list(self.excitations.keys()) if rx_prefix in i]
for i in trlist:
for k in reclist:
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ def set_differential_pair(
self.odesign.SaveDiffPairsToFile(tmpfile1)
with open_file(tmpfile1, "r") as fh:
lines = fh.read().splitlines()
num_diffs_before = len(lines)

old_arg = []
for line in lines:
data = line.split(",")
Expand Down
6 changes: 3 additions & 3 deletions pyaedt/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,9 +925,9 @@ def _initialize(
StandalonePyScriptWrapper = AnsoftCOMUtil.Ansoft.CoreCOMScripting.COM.StandalonePyScriptWrapper
if non_graphical or new_session:
self.launched_by_pyaedt = True
oapp = StandalonePyScriptWrapper.CreateObjectNew(non_graphical)
return StandalonePyScriptWrapper.CreateObjectNew(non_graphical)
else:
oapp = StandalonePyScriptWrapper.CreateObject(version)
return StandalonePyScriptWrapper.CreateObject(version)
else:
base_path = settings.aedt_install_dir
sys.path.insert(0, base_path)
Expand Down Expand Up @@ -2089,7 +2089,7 @@ def get_ansyscloud_job_info(self, job_id=None, job_name=None): # pragma: no cov
>>> d.release_desktop(False,False)
"""
command = os.path.join(self.install_path, "common", "AnsysCloudCLI", "AnsysCloudCli.exe")
ver = self.aedt_version_id.replace(".", "R")

if job_name:
command = [command, "jobinfo", "-j", job_name]
elif job_id:
Expand Down
73 changes: 43 additions & 30 deletions pyaedt/generic/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pkgutil
import tempfile

import pyaedt
from pyaedt import Icepak
from pyaedt import __version__
from pyaedt import generate_unique_folder_name
Expand All @@ -14,6 +15,7 @@
from pyaedt.application.Variables import decompose_variable_value
from pyaedt.generic.DataHandlers import _arg2dict
from pyaedt.generic.LoadAEDTFile import load_keyword_in_aedt_file
from pyaedt.generic.general_methods import GrpcApiError
from pyaedt.generic.general_methods import generate_unique_name
from pyaedt.generic.general_methods import pyaedt_function_handler
from pyaedt.generic.general_methods import read_configuration_file
Expand All @@ -28,6 +30,8 @@
from pyaedt.modules.DesignXPloration import SetupParam
from pyaedt.modules.MaterialLib import Material
from pyaedt.modules.Mesh import MeshOperation
from pyaedt.modules.MeshIcepak import MeshRegion
from pyaedt.modules.MeshIcepak import SubRegion

if not is_ironpython:
from jsonschema import exceptions
Expand Down Expand Up @@ -689,7 +693,9 @@ def __init__(self, app):
self.results = ImportResults()

# Read the default configuration schema from pyaedt
schema_bytes = pkgutil.get_data(__name__, "../misc/config.schema.json")
schema_bytes = pkgutil.get_data(
__name__, os.path.join(os.path.dirname(pyaedt.__file__), "misc", "config.schema.json")
)
schema_string = schema_bytes.decode("utf-8")
self._schema = json.loads(schema_string)

Expand Down Expand Up @@ -917,7 +923,7 @@ def _update_mesh_operations(self, name, props):
bound = MeshOperation(self._app.mesh, name, props, props["Type"])
if bound.create():
self._app.mesh.meshoperations.append(bound)
self._app.logger.info("mesh Operation {} added.".format(name))
self._app.logger.info("Mesh Operation {} added.".format(name))
return True
else:
self._app.logger.warning("Failed to add Mesh {} ".format(name))
Expand Down Expand Up @@ -1142,6 +1148,14 @@ def import_config(self, config_file, *args):
"Circuit Design",
]:
self._app.modeler.set_working_coordinate_system("Global")

if self.options.import_mesh_operations and dict_in.get("mesh", None):
self.results.import_mesh_operations = True
for name, props in dict_in["mesh"].items():
self._convert_objects(props, dict_in["general"]["object_mapping"])
if not self._update_mesh_operations(name, props):
self.results.import_mesh_operations = False

if self.options.import_object_properties and dict_in.get("objects", None):
self.results.import_object_properties = True
for obj, val in dict_in["objects"].items():
Expand All @@ -1168,13 +1182,6 @@ def import_config(self, config_file, *args):
if not self._update_boundaries(name, dict_in["boundaries"][name]):
self.results.import_boundaries = False

if self.options.import_mesh_operations and dict_in.get("mesh", None):
self.results.import_mesh_operations = True
for name, props in dict_in["mesh"].items():
self._convert_objects(props, dict_in["general"]["object_mapping"])
if not self._update_mesh_operations(name, props):
self.results.import_mesh_operations = False

if self.options.import_setups and dict_in.get("setups", None):
self.results.import_setup = True
for setup, props in dict_in["setups"].items():
Expand Down Expand Up @@ -1612,19 +1619,23 @@ def _update_mesh_operations(self, name, props):
if el in mesh_el.__dict__:
mesh_el.__dict__[el] = props[el]
return mesh_el.update()

bound = self._app.mesh.MeshRegion(
self._app.mesh.omeshmodule, self._app.mesh.boundingdimension, self._app.mesh._model_units, self._app
)
bound.name = name
for el in props:
if el in bound.__dict__:
bound.__dict__[el] = props[el]
if bound.create():
try:
if self._app.settings.aedt_version < "2024.1":
objs = props.get("Objects", []) + props.get("Submodels", [])
else:
subregion = SubRegion(self._app, props["_subregion_information"]["parts"])
subregion.padding_values = props["_subregion_information"]["pad_vals"]
subregion.padding_types = props["_subregion_information"]["pad_types"]
objs = subregion.name
bound = MeshRegion(app=self._app, name=name, objects=objs)
bound.manual_settings = props["UserSpecifiedSettings"]
for el in props:
if el in bound.settings:
bound.settings[el] = props[el]
self._app.mesh.meshregions.append(bound)
self._app.logger.info("mesh Operation {} added.".format(name))
else:
self._app.logger.warning("Failed to add Mesh {} ".format(name))
self._app.logger.info("Mesh Operation {} added.".format(name))
except GrpcApiError:
self._app.logger.warning("Failed to add mesh {} ".format(name))
return True

@pyaedt_function_handler()
Expand All @@ -1635,7 +1646,7 @@ def _export_objects_properties(self, dict_out):
self._app.modeler.refresh_all_ids()
udc_parts_id = [part for _, uc in self._app.modeler.user_defined_components.items() for part in uc.parts]
for val in self._app.modeler.objects.values():
if val.id in udc_parts_id:
if val.id in udc_parts_id or val.history().command == "CreateSubRegion":
continue
dict_out["objects"][val.name] = {}
dict_out["objects"][val.name]["SurfaceMaterial"] = val.surface_material_name
Expand All @@ -1651,10 +1662,7 @@ def _export_objects_properties(self, dict_out):
def _export_mesh_operations(self, dict_out):
dict_out["mesh"] = {}
args = ["NAME:Settings"]
if self._app.mesh.global_mesh_region.UserSpecifiedSettings:
args += self._app.mesh.global_mesh_region.manualsettings
else:
args += self._app.mesh.global_mesh_region.autosettings
args += self._app.mesh.global_mesh_region.settings.parse_settings()
mop = OrderedDict({})
_arg2dict(args, mop)
dict_out["mesh"]["Settings"] = mop["Settings"]
Expand All @@ -1664,12 +1672,17 @@ def _export_mesh_operations(self, dict_out):
args = ["NAME:Settings"]
else:
args = ["NAME:" + mesh.name, "Enable:=", mesh.Enable]
if mesh.UserSpecifiedSettings:
args += mesh.manualsettings
else:
args += mesh.autosettings
args += mesh.settings.parse_settings()
args += getattr(mesh, "_parse_assignment_value")()
args += ["UserSpecifiedSettings:=", not mesh.manual_settings]
mop = OrderedDict({})
_arg2dict(args, mop)
if self._app.modeler[args[-3][0]].history().command == "CreateSubRegion":
mop[mesh.name]["_subregion_information"] = {
"pad_vals": mesh.assignment.padding_values,
"pad_types": mesh.assignment.padding_types,
"parts": list(mesh.assignment.parts.keys()),
}
dict_out["mesh"][mesh.name] = mop[mesh.name]
self._map_object(mop, dict_out)
pass
Expand Down
9 changes: 9 additions & 0 deletions pyaedt/icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -2768,6 +2768,9 @@ def create_meshregion_component(
):
"""Create a bounding box to use as a mesh region in Icepak.
.. deprecated:: 0.8.3
Use ``create_subregion`` or ``create_region`` functions inside the modeler class.
Parameters
----------
scale_factor : float, optional
Expand All @@ -2787,6 +2790,12 @@ def create_meshregion_component(
>>> oeditor.ChangeProperty
"""
warnings.warn(
"``create_meshregion_component`` was deprecated in 0.8.3."
"Use ``create_subregion`` or ``create_region`` instead.",
DeprecationWarning,
)

self.modeler.edit_region_dimensions([0, 0, 0, 0, 0, 0])

vertex_ids = self.modeler.oeditor.GetVertexIDsFromObject("Region")
Expand Down
Loading

0 comments on commit 82030aa

Please sign in to comment.