Skip to content
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

Fixed bug in SweepMaterial creation #3879

Merged
merged 8 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
27 changes: 25 additions & 2 deletions _unittest/test_03_Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,31 @@ def test_09_non_linear_materials(self, add_app):
assert app.materials.material_keys["mymat2"].is_used

def test_10_add_material_sweep(self):
assert self.aedtapp.materials.add_material_sweep(["copper", "aluminum"], "sweep_copper")
assert "sweep_copper" in list(self.aedtapp.materials.material_keys.keys())
material_name = "sweep_material"
assert self.aedtapp.materials.add_material_sweep(["copper", "aluminum", "FR4_epoxy"], material_name)
assert material_name in list(self.aedtapp.materials.material_keys.keys())
properties_to_check = [
"permittivity",
"permeability",
"conductivity",
"dielectric_loss_tangent",
"thermal_conductivity",
"mass_density",
"specific_heat",
"thermal_expansion_coefficient",
"youngs_modulus",
"poissons_ratio",
]
# check if the variables are correctly created
assert "$ID" + material_name in self.aedtapp.variable_manager.variable_names
for prop in properties_to_check:
var_name = "$" + material_name + "_" + prop
assert var_name in self.aedtapp.variable_manager.variable_names
# check if the material properties are correct
for prop in properties_to_check:
var_name = "$" + material_name + "_" + prop
mat_prop = getattr(self.aedtapp.materials[material_name], prop).value
assert mat_prop == var_name + "[$ID" + material_name + "]"

def test_11_material_case(self):
assert self.aedtapp.materials["Aluminum"] == self.aedtapp.materials["aluminum"]
Expand Down
30 changes: 12 additions & 18 deletions pyaedt/modules/MaterialLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,22 +404,15 @@
return matprop

@pyaedt_function_handler()
def add_material_sweep(self, swargs, matname):
def add_material_sweep(self, materials_list, material_name):
"""Create a sweep material made of an array of materials.

If a material needs to have a dataset (thermal modifier), then a
dataset is created. Material properties are loaded from the XML file
database ``amat.xml``.

Parameters
----------
swargs : list
materials_list : list
List of materials to merge into a single sweep material.
matname : str
material_name : str
Name of the sweep material.
enableTM : bool, optional
Unavailable currently. Whether to enable the thermal modifier.
The default is ``True``.

Returns
-------
Expand All @@ -441,25 +434,26 @@
>>> hfss.materials.add_material_sweep(["MyMaterial", "MyMaterial2"], "Sweep_copper")
"""
matsweep = []
for args in swargs:
matobj = self.checkifmaterialexists(args)
for mat in materials_list:
matobj = self.checkifmaterialexists(mat)

Check warning on line 438 in pyaedt/modules/MaterialLib.py

View check run for this annotation

Codecov / codecov/patch

pyaedt/modules/MaterialLib.py#L437-L438

Added lines #L437 - L438 were not covered by tests
if matobj:
matsweep.append(matobj)

mat_dict = self._create_mat_project_vars(matsweep)

newmat = Material(self, matname)
index = "$ID" + matname
newmat = Material(self, material_name, material_update=False)
index = "$ID" + material_name

Check warning on line 445 in pyaedt/modules/MaterialLib.py

View check run for this annotation

Codecov / codecov/patch

pyaedt/modules/MaterialLib.py#L444-L445

Added lines #L444 - L445 were not covered by tests
newmat.is_sweep_material = True
self._app[index] = 0
for el in mat_dict:
if el in list(mat_dict.keys()):
self._app["$" + matname + el] = mat_dict[el]
newmat.__dict__["_" + el].value = "$" + matname + el + "[" + index + "]"
newmat._update_props(el, "$" + matname + el + "[" + index + "]", False)
array_var_name = "$" + material_name + "_" + el
self._app[array_var_name] = mat_dict[el]
newmat.__dict__["_" + el].value = array_var_name + "[" + index + "]"
newmat._update_props(el, array_var_name + "[" + index + "]", False)

Check warning on line 453 in pyaedt/modules/MaterialLib.py

View check run for this annotation

Codecov / codecov/patch

pyaedt/modules/MaterialLib.py#L450-L453

Added lines #L450 - L453 were not covered by tests

newmat.update()
self.material_keys[matname.lower()] = newmat
self.material_keys[material_name.lower()] = newmat

Check warning on line 456 in pyaedt/modules/MaterialLib.py

View check run for this annotation

Codecov / codecov/patch

pyaedt/modules/MaterialLib.py#L456

Added line #L456 was not covered by tests
return index

@pyaedt_function_handler()
Expand Down
Loading