Skip to content

Commit

Permalink
Fix/issue 4122 (#4307)
Browse files Browse the repository at this point in the history
Co-authored-by: maxcapodi78 <Shark78>
  • Loading branch information
Samuelopez-ansys authored Feb 29, 2024
1 parent 0fabb06 commit d8da512
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 38 deletions.
98 changes: 98 additions & 0 deletions _unittest/example_models/T03/iron_pyaedt.amat
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

$begin 'iron_pyaedt'
$begin 'MaterialDef'
$begin 'iron_pyaedt'
CoordinateSystemType='Cartesian'
BulkOrSurfaceType=1
$begin 'PhysicsTypes'
set('Electromagnetic', 'Thermal', 'Structural')
$end 'PhysicsTypes'
$begin 'AttachedData'
$begin 'MatAppearanceData'
property_data='appearance_data'
Red=74
Green=74
Blue=74
$end 'MatAppearanceData'
$begin 'MatNotesData'
property_data='notes_data'
Notes='Materials data\
Database: MaterialU\
Table: MaterialU\
Record name: iron_pyaedt\
Designation: iron_pyaedt, BS EN 1561:1997 (record based on BS 1542:1990 BS grade 250)\
GUID: 04b3107f-45c5-4e7c-bdd6-3bf3cffc2ef2'
$end 'MatNotesData'
$end 'AttachedData'
$begin 'ModifierData'
$begin 'ThermalModifierData'
modifier_data='thermal_modifier_data'
$begin 'all_thermal_modifiers'
$begin 'one_thermal_modifier'
'Property:'='thermal_conductivity'
'Index:'=0
prop_modifier='thermal_modifier'
use_free_form=true
free_form_value='pwl($Thermal_conductivity_with_temperature_1,Temp)'
$end 'one_thermal_modifier'
$begin 'one_thermal_modifier'
'Property:'='specific_heat'
'Index:'=0
prop_modifier='thermal_modifier'
use_free_form=true
free_form_value='pwl($Specific_heat_capacity_with_temperature_1,Temp)'
$end 'one_thermal_modifier'
$begin 'one_thermal_modifier'
'Property:'='thermal_expansion_coefficient'
'Index:'=0
prop_modifier='thermal_modifier'
use_free_form=true
free_form_value='pwl($Thermal_expansion_coefficient_with_temperature_1,Temp)'
$end 'one_thermal_modifier'
$end 'all_thermal_modifiers'
$end 'ThermalModifierData'
$end 'ModifierData'
$begin 'permeability'
property_type='nonlinear'
BTypeForSingleCurve='normal'
HUnit='A_per_meter'
BUnit='tesla'
IsTemperatureDependent=false
$begin 'BHCoordinates'
DimUnits[2: '', '']
Points[54: 0, 0, 16000, 1, 17281.6, 1.05, 18847.4, 1.1, 20865.9, 1.15, 23376, 1.2, 26469.5, 1.25, 30177.8, 1.3, 34493.5, 1.35, 39401.2, 1.4, 44861, 1.45, 50789.6, 1.5, 57260.3, 1.55, 64825.4, 1.6, 74271.5, 1.65, 86025.4, 1.7, 100233, 1.75, 117472, 1.8, 138235, 1.85, 162690, 1.9, 191556, 1.95, 224815, 2, 260282, 2.05, 295816, 2.1, 330843, 2.15, 367601, 2.2, 407000, 2.25]
$end 'BHCoordinates'
$begin 'Temperatures'
$end 'Temperatures'
$end 'permeability'
conductivity='1371180'
thermal_conductivity='43.0284'
mass_density='7199.83'
specific_heat='445.332'
youngs_modulus='1.23511e+11'
poissons_ratio='0.259952'
thermal_expansion_coefficient='8.97454e-6'
$begin 'thermal_material_type'
property_type='ChoiceProperty'
Choice='Solid'
$end 'thermal_material_type'
$end 'iron_pyaedt'
$end 'MaterialDef'
$begin 'RefDatasets'
$begin '$Thermal_conductivity_with_temperature_1'
DimUnits[2: 'cel', '']
X('19.85', '96.99', '174.1', '251.3', '328.4', '405.6', '482.7', '559.9', '637', '714.1', '791.3', '868.4', '945.6', '1023', '1100')
Y('0.999572', '1.01491', '1.00771', '0.985861', '0.95681', '0.932872', '0.914512', '0.889413', '0.853622', '0.81086', '0.773443', '0.79831', '0.833403', '0.864778', '0.885229')
$end '$Thermal_conductivity_with_temperature_1'
$begin '$Specific_heat_capacity_with_temperature_1'
DimUnits[2: 'cel', '']
X('19.85', '86.52', '153.2', '219.9', '286.5', '353.2', '419.9', '486.5', '553.2', '619.9')
Y('0.996785', '1.09649', '1.18024', '1.25345', '1.32171', '1.39132', '1.46789', '1.55704', '1.6646', '1.79664')
$end '$Specific_heat_capacity_with_temperature_1'
$begin '$Thermal_expansion_coefficient_with_temperature_1'
DimUnits[2: 'cel', '']
X('19.85', '88.94', '158', '227.1', '296.2', '365.3', '434.4', '503.5', '572.6', '641.7', '710.8', '779.9')
Y('0.996931', '1.09554', '1.17332', '1.23238', '1.27806', '1.31149', '1.33712', '1.3594', '1.37946', '1.40174', '1.43406', '1.53657')
$end '$Thermal_expansion_coefficient_with_temperature_1'
$end 'RefDatasets'
$end 'iron_pyaedt'
81 changes: 81 additions & 0 deletions _unittest/example_models/T03/material_sample.amat
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
$begin '$base_index$'
$begin 'properties'
all_levels=000000000000
time(year=000000002022, month=000000000004, day=000000000026, hour=000000000014, min=000000000052, sec=000000000029)
version=000000000000
$end 'properties'
$begin '$base_index$'
$index$(pos=000000002021, lin=000000000072, lvl=000000000000)
$end '$base_index$'
$end '$base_index$'
$begin 'vacuum'
$begin 'AttachedData'
$begin 'MatAppearanceData'
property_data='appearance_data'
Red=230
Green=230
Blue=230
Transparency=0.95
$end 'MatAppearanceData'
$end 'AttachedData'
simple('permittivity', 1)
ModTime=1499970477
$end 'vacuum'
$begin 'pec'
$begin 'AttachedData'
$begin 'MatAppearanceData'
property_data='appearance_data'
Red=247
Green=242
Blue=232
$end 'MatAppearanceData'
$end 'AttachedData'
simple('conductivity', 1.0E30)
ModTime=1499970477
$end 'pec'
$begin 'mat_example_1'
$begin 'AttachedData'
$begin 'MatAppearanceData'
property_data='appearance_data'
Red=176
Green=154
Blue=176
$end 'MatAppearanceData'
$end 'AttachedData'
simple('conductivity', 1100000)
simple('thermal_conductivity', 13.8)
simple('mass_density', 8055)
simple('specific_heat', 480)
simple('youngs_modulus', 195000000000)
simple('poissons_ratio', 0.3)
simple('thermal_expansion_coeffcient', 1.08e-005)
ModTime=1499970477
$end 'mat_example_1'
$begin 'mat_example_2'
$begin 'AttachedData'
$begin 'MatAppearanceData'
property_data='appearance_data'
Red=235
Green=235
Blue=123
$end 'MatAppearanceData'
$end 'AttachedData'
simple('conductivity', 16700000)
simple('thermal_conductivity', 115.5)
simple('mass_density', 7140)
simple('specific_heat', 389)
simple('youngs_modulus', 115000000000)
simple('poissons_ratio', 0.33)
simple('thermal_expansion_coeffcient', 6.35e-005)
ModTime=1499970477
$end 'mat_example_2'
$begin '$index$'
$begin '$index$'
vacuum(pos=370, lin=11, lvl=0)
pec(pos=675, lin=24, lvl=0)
mat_example_1(pos=954, lin=36, lvl=0)
mat_example_2(pos=1486, lin=54, lvl=0)
$base_index$(pos=0, lin=1, lvl=0)
$index$(pos=2021, lin=72, lvl=0)
$end '$index$'
$end '$index$'
14 changes: 14 additions & 0 deletions _unittest/test_03_Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ def test_08_import_materials(self):
assert "al-extruded1" in self.aedtapp.materials.material_keys.keys()
assert self.aedtapp.materials["al-extruded1"].thermal_conductivity.thermalmodifier

assert not self.aedtapp.materials.import_materials_from_file()
assert not self.aedtapp.materials.import_materials_from_file("mat.invented")
assert not self.aedtapp.materials.import_materials_from_file(
os.path.join(local_path, "example_models", test_subfolder, "mats.csv")
)

assert self.aedtapp.materials.import_materials_from_file(
os.path.join(local_path, "example_models", test_subfolder, "material_sample.amat")
)
assert self.aedtapp.materials.import_materials_from_file(
os.path.join(local_path, "example_models", test_subfolder, "iron_pyaedt.amat")
)
x = 1

def test_08B_import_materials_from_excel(self):
mats = self.aedtapp.materials.import_materials_from_excel(
os.path.join(local_path, "example_models", test_subfolder, "mats.xlsx")
Expand Down
1 change: 1 addition & 0 deletions pyaedt/generic/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,7 @@ def import_config(self, config_file, *args):
else:
newname = el
newmat = Material(self._app, el, val, material_update=True)
newmat._update_material()
if newmat:
self._app.materials.material_keys[newname] = newmat
else: # pragma: no cover
Expand Down
46 changes: 30 additions & 16 deletions pyaedt/modules/Material.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,12 @@ def __init__(self, material, name, val=None, thermalmodifier=None, spatialmodifi
elif e == "IsTemperatureDependent":
self.is_temperature_dependent = v
elif e in ["BHCoordinates", "DECoordinates", "JECoordinates"]:
self.value = v["Point"]
self._unit = v["DimUnits"]
if "Point" in v:
self.value = v["Point"]
elif "Points" in v:
pair_list = [v["Points"][i : i + 2] for i in range(0, len(v["Points"]), 2)]
self.value = pair_list
elif e == "Temperatures":
self.temperatures = v
elif val is not None and isinstance(val, OrderedDict) and "Magnitude" in val.keys():
Expand Down Expand Up @@ -1170,18 +1174,17 @@ def _get_args(self, props=None):
_dict2arg(props, arg)
return arg

def _update_props(self, propname, provpavlue, update_aedt=True):
def _update_props(self, propname, propvalue, update_aedt=True):
"""Update properties.
Parameters
----------
propname : str
Name of the property.
provpavlue :
propvalue :
Value of the property.
update_aedt : bool, optional
Whether to update the property in AEDT. The default is ``True``.
"""

try:
Expand All @@ -1190,9 +1193,9 @@ def _update_props(self, propname, provpavlue, update_aedt=True):
except:
material_props_type = None

if isinstance(provpavlue, list) and material_props_type and material_props_type in ["tensor", "anisotropic"]:
if isinstance(propvalue, list) and material_props_type and material_props_type in ["tensor", "anisotropic"]:
i = 1
for val in provpavlue:
for val in propvalue:
if not self._props.get(propname, None) or not isinstance(self._props[propname], dict):
if material_props_type == "tensor":
self._props[propname] = OrderedDict({"property_type": "TensorProperty"})
Expand All @@ -1204,18 +1207,18 @@ def _update_props(self, propname, provpavlue, update_aedt=True):
i += 1
if update_aedt:
return self.update()
elif isinstance(provpavlue, (str, float, int)):
self._props[propname] = str(provpavlue)
elif isinstance(propvalue, (str, float, int)):
self._props[propname] = str(propvalue)
if update_aedt:
return self.update()
elif isinstance(provpavlue, OrderedDict):
self._props[propname] = provpavlue
elif isinstance(propvalue, OrderedDict):
self._props[propname] = propvalue
if update_aedt:
return self.update()
elif isinstance(provpavlue, list) and material_props_type and material_props_type == "nonlinear":
elif isinstance(propvalue, list) and material_props_type and material_props_type == "nonlinear":
if propname == "permeability":
bh = OrderedDict({"DimUnits": ["", ""]})
for point in provpavlue:
for point in propvalue:
if "Point" in bh:
bh["Point"].append(point)
else:
Expand All @@ -1232,7 +1235,7 @@ def _update_props(self, propname, provpavlue, update_aedt=True):
self._props[propname]["BHCoordinates"]["Temperatures"] = OrderedDict({})
else:
bh = OrderedDict({"DimUnits": [self.__dict__["_" + propname]._unit]})
for point in provpavlue:
for point in propvalue:
if "Point" in bh:
bh["Point"].append(point)
else:
Expand All @@ -1244,9 +1247,9 @@ def _update_props(self, propname, provpavlue, update_aedt=True):
self._props[propname] = OrderedDict({"property_type": "nonlinear", pr_name: bh})
if update_aedt:
return self.update()
elif isinstance(provpavlue, list) and material_props_type and material_props_type == "vector":
elif isinstance(propvalue, list) and material_props_type and material_props_type == "vector":
if propname == "magnetic_coercivity":
return self.set_magnetic_coercivity(provpavlue[0], provpavlue[1], provpavlue[2], provpavlue[3])
return self.set_magnetic_coercivity(propvalue[0], propvalue[1], propvalue[2], propvalue[3])
return False


Expand Down Expand Up @@ -1275,6 +1278,17 @@ def __init__(self, materiallib, name, props=None, material_update=True):
CommonMaterial.__init__(self, materiallib, name, props)
self.thermal_material_type = "Solid"
self._material_update = material_update
self._wire_type = None
self._wire_width = None
self._wire_diameter = None
self._wire_width_direction = None
self._wire_thickness_direction = None
self._wire_thickness = None
self._stacking_type = None
self._stacking_direction = None
self._stacking_factor = None
self._strand_number = None

if "thermal_material_type" in self._props:
self.thermal_material_type = self._props["thermal_material_type"]["Choice"]
if "PhysicsTypes" in self._props:
Expand Down Expand Up @@ -1312,6 +1326,7 @@ def __init__(self, materiallib, name, props=None, material_update=True):
if "wire_type" in self._props:
self.wire_type = self._props["wire_type"]["Choice"]

def _update_material(self):
for property in MatProperties.aedtname:
tmods = None
smods = None
Expand Down Expand Up @@ -1344,7 +1359,6 @@ def __init__(self, materiallib, name, props=None, material_update=True):
else:
if modifiers[mod]["Property:"] == property:
smods = modifiers[mod]

property_value = (
self._props[property] if property in self._props else MatProperties.get_defaultvalue(aedtname=property)
)
Expand Down
Loading

0 comments on commit d8da512

Please sign in to comment.