Skip to content

Commit 284fa4a

Browse files
Material refactoring (#1168)
* Refactored MaterialLib to avoid case insensitive material creation in AEDT * Refactored MaterialLib to avoid case insensitive material creation in AEDT * Replaced method not working in Non Graphical Mode * Fixed UT * Improved Speedup * Improved Speedup * Fixed 2022R2 Desktop Release * Improved Coverage * Update pyaedt/modules/MaterialLib.py Co-authored-by: Maxime Rey <[email protected]> * Improved Coverage Co-authored-by: maxcapodi78 <Shark78> Co-authored-by: Maxime Rey <[email protected]>
1 parent ea02f0f commit 284fa4a

15 files changed

+211
-113
lines changed

_unittest/test_03_Materials.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,8 @@ def test_09_non_linear_materials(self):
172172
def test_10_add_material_sweep(self):
173173
assert self.aedtapp.materials.add_material_sweep(["copper", "aluminum"], "sweep_copper")
174174
assert "sweep_copper" in list(self.aedtapp.materials.material_keys.keys())
175+
176+
def test_11_material_case(self):
177+
assert self.aedtapp.materials["Aluminum"] == self.aedtapp.materials["aluminum"]
178+
assert self.aedtapp.materials["Aluminum"].name == "aluminum"
179+
assert self.aedtapp.materials.add_material("AluMinum") == self.aedtapp.materials["aluminum"]

_unittest/test_08_Primitives3D.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ def test_63_import_step(self):
859859
assert len(self.aedtapp.modeler.object_names) == 1
860860

861861
def test_64_create_3dcomponent(self):
862+
for i in list(self.aedtapp.modeler.objects.keys()):
863+
self.aedtapp.modeler.objects[i].material_name = "copper"
862864
assert self.aedtapp.modeler.create_3dcomponent(self.component3d_file)
863865
assert os.path.exists(self.component3d_file)
864866
new_obj = self.aedtapp.modeler.duplicate_along_line("Solid", [100, 0, 0])

_unittest/test_41_3dlayout_modeler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def test28_create_scattering(self):
414414
def test29_duplicate_material(self):
415415
material = self.aedtapp.materials.add_material("FirstMaterial")
416416
new_material = self.aedtapp.materials.duplicate_material("FirstMaterial", "SecondMaterial")
417-
assert new_material.name == "secondmaterial"
417+
assert new_material.name == "SecondMaterial"
418418

419419
def test30_expand(self):
420420
self.aedtapp.modeler.create_rectangle("Bottom", [20, 20], [50, 50], name="rect_1")

_unittest/test_98_Icepak.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ def test_28_assign_surface_material(self):
313313
self.aedtapp.materials.add_surface_material("my_surface", 0.5)
314314
obj = ["box2", "box3"]
315315
assert self.aedtapp.assign_surface_material(obj, "my_surface")
316+
assert self.aedtapp.assign_surface_material("box", "Fe-cast")
316317
mat = self.aedtapp.materials.add_material("test_mat1")
317318
mat.thermal_conductivity = 10
318319
mat.thermal_conductivity = [20, 20, 10]

pyaedt/application/Analysis3D.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -604,21 +604,19 @@ def assign_material(self, obj, mat):
604604
>>> obj_names_list = [box1.name, box2.name, cylinder1.name, cylinder2.name]
605605
>>> hfss.assign_material(obj_names_list, "aluminum")
606606
"""
607-
mat = mat.lower()
608607
selections = self.modeler.convert_to_selections(obj, True)
609608

610-
mat_exists = False
611-
if mat in self.materials.material_keys:
612-
mat_exists = True
613-
if mat_exists or self.materials.checkifmaterialexists(mat):
614-
Mat = self.materials.material_keys[mat]
615-
if mat_exists:
616-
Mat.update()
609+
if mat.lower() not in self.materials.material_keys:
610+
matobj = self.materials._aedmattolibrary(mat)
611+
else:
612+
matobj = self.materials.material_keys[mat.lower()]
613+
614+
if matobj:
617615
self.logger.info("Assign Material " + mat + " to object " + str(selections))
618616
for el in selections:
619-
self.modeler[el].material_name = mat
620-
self.modeler[el].color = self.materials.material_keys[mat].material_appearance
621-
if Mat.is_dielectric():
617+
self.modeler[el].material_name = matobj.name
618+
self.modeler[el].color = matobj.material_appearance
619+
if matobj.is_dielectric():
622620
self.modeler[el].solve_inside = True
623621
else:
624622
self.modeler[el].solve_inside = False
@@ -736,10 +734,9 @@ def assignmaterial_from_sherlock_files(self, csv_component, csv_material):
736734
list_mat_obj += [rd for rd, md in zip(component_data["Ref Des"], component_data["Material"]) if md == mat]
737735
list_mat_obj = [mo for mo in list_mat_obj if mo in all_objs]
738736
if list_mat_obj:
739-
if not self.materials.checkifmaterialexists(mat.lower()):
737+
newmat = self.materials.checkifmaterialexists(mat)
738+
if not newmat:
740739
newmat = self.materials.add_material(mat.lower())
741-
else:
742-
newmat = self.materials[mat.lower()]
743740
if "Material Density" in material_data:
744741
if "@" in material_data["Material Density"][i] and "," in material_data["Material Density"][i]:
745742
nominal_val, dataset_name = self._create_dataset_from_sherlock(

pyaedt/desktop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def release_desktop(close_projects=True, close_desktop=True):
170170
desktop.CloseProject(project)
171171
pid = _main.oDesktop.GetProcessID()
172172
if not is_ironpython:
173-
if settings.aedt_version >= "2022.2":
173+
if settings.aedt_version >= "2022.2" and settings.use_grpc_api:
174174
import ScriptEnv
175175

176176
ScriptEnv.Release()

pyaedt/generic/configurations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,12 +965,12 @@ def import_config(self, config_file):
965965
if self.options.import_materials and dict_in.get("materials", None):
966966
self.results.import_materials = True
967967
for el, val in dict_in["materials"].items():
968-
if el.lower() in list(self._app.materials.material_keys.keys()):
968+
if self._app.materials.checkifmaterialexists(el):
969969
newname = generate_unique_name(el)
970970
self._app.logger.warning("Material %s already exists. Renaming to %s", el, newname)
971971
else:
972972
newname = el
973-
newmat = Material(self._app, newname, val)
973+
newmat = Material(self._app, el, val)
974974
if newmat.update():
975975
self._app.materials.material_keys[newname] = newmat
976976
else:
@@ -1133,7 +1133,7 @@ def _export_mesh_operations(self, dict_out):
11331133
def _export_materials(self, dict_out):
11341134
output_dict = {}
11351135
for el, val in self._app.materials.material_keys.items():
1136-
output_dict[el] = copy.deepcopy(val._props)
1136+
output_dict[val.name] = copy.deepcopy(val._props)
11371137
out_list = []
11381138
_find_datasets(output_dict, out_list)
11391139
datasets = OrderedDict()

pyaedt/hfss.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -614,16 +614,9 @@ def assign_coating(
614614
listobjname = "_".join(listobj)
615615
props = {"Objects": listobj}
616616
if mat:
617-
mat = mat.lower()
618-
if mat in self.materials.material_keys:
619-
Mat = self.materials.material_keys[mat]
620-
Mat.update()
617+
if self.materials[mat]:
621618
props["UseMaterial"] = True
622-
props["Material"] = mat
623-
self.materials._aedmattolibrary(mat)
624-
elif self.materials.checkifmaterialexists(mat):
625-
props["UseMaterial"] = True
626-
props["Material"] = mat
619+
props["Material"] = self.materials[mat].name
627620
else:
628621
return False
629622
else:

pyaedt/icepak.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,21 +2759,39 @@ def assign_surface_material(self, obj, mat):
27592759
27602760
>>> oEditor.ChangeProperty
27612761
"""
2762-
mat = mat.lower()
2763-
if mat not in self.materials.surface_material_keys:
2762+
objs = ["NAME:PropServers"]
2763+
objs.extend(self.modeler.convert_to_selections(obj, True))
2764+
try:
2765+
self.modeler.oeditor.ChangeProperty(
2766+
[
2767+
"NAME:AllTabs",
2768+
[
2769+
"NAME:Geometry3DAttributeTab",
2770+
objs,
2771+
["NAME:ChangedProps", ["NAME:Surface Material", "Value:=", '"' + mat + '"']],
2772+
],
2773+
]
2774+
)
2775+
except:
27642776
self.logger.warning("Warning. The material is not the database. Use add_surface_material.")
27652777
return False
2766-
else:
2767-
for el in obj:
2768-
self.modeler.oeditor.ChangeProperty(
2769-
[
2770-
"NAME:AllTabs",
2771-
[
2772-
"NAME:Geometry3DAttributeTab",
2773-
["NAME:PropServers", el],
2774-
["NAME:ChangedProps", ["NAME:Surface Material", "Value:=", '"' + mat + '"']],
2775-
],
2776-
]
2777-
)
2778-
2779-
return True
2778+
if mat.lower() not in self.materials.surface_material_keys:
2779+
oo = self.get_oo_object(self.oproject, "Surface Materials/{}".format(mat))
2780+
if oo:
2781+
from pyaedt.modules.Material import SurfaceMaterial
2782+
2783+
sm = SurfaceMaterial(self.materials, mat)
2784+
sm.coordinate_system = oo.GetPropEvaluatedValue("Coordinate System Type")
2785+
props = oo.GetPropNames()
2786+
if "Surface Emissivity" in props:
2787+
sm.emissivity = oo.GetPropEvaluatedValue("Surface Emissivity")
2788+
if "Surface Roughness" in props:
2789+
sm.surface_roughness = oo.GetPropEvaluatedValue("Surface Roughness")
2790+
if "Solar Behavior" in props:
2791+
sm.surface_clarity_type = oo.GetPropEvaluatedValue("Solar Behavior")
2792+
if "Solar Diffuse Absorptance" in props:
2793+
sm.surface_diffuse_absorptance = oo.GetPropEvaluatedValue("Solar Diffuse Absorptance")
2794+
if "Solar Normal Absorptance" in props:
2795+
sm.surface_incident_absorptance = oo.GetPropEvaluatedValue("Solar Normal Absorptance")
2796+
self.materials.surface_material_keys[mat.lower()] = sm
2797+
return True

pyaedt/modeler/Circuit.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def __init__(self, app):
3333
self.o_def_manager = self._app.odefinition_manager
3434
self.o_component_manager = self.o_def_manager.GetManager("Component")
3535
self.o_model_manager = self.o_def_manager.GetManager("Model")
36-
3736
Modeler.__init__(self, app)
3837

3938
@property
@@ -148,13 +147,23 @@ def __init__(self, app):
148147
self._app = app
149148
ModelerCircuit.__init__(self, app)
150149
self._schematic = NexximComponents(self)
151-
self.layouteditor = None
152-
if self._app.design_type != "Twin Builder":
153-
self.layouteditor = self._odesign.SetActiveEditor("Layout")
154-
self._odesign.SetActiveEditor("SchematicEditor")
150+
self._layouteditor = None
155151
self.layers = Layers(self, roughnessunits="um")
156152
self._primitives = Primitives3DLayout(app)
157153

154+
@property
155+
def layouteditor(self):
156+
"""Return the Circuit Layout Editor.
157+
158+
References
159+
----------
160+
161+
>>> oDesign.SetActiveEditor("Layout")
162+
"""
163+
if not self._layouteditor and self._app.design_type != "Twin Builder":
164+
self._layouteditor = self._odesign.SetActiveEditor("Layout")
165+
return self._layouteditor
166+
158167
@property
159168
def schematic(self):
160169
"""Schematic Component.

0 commit comments

Comments
 (0)