From 837fdfc45451a08c8b308c5f8ac3cbff179fac9d Mon Sep 17 00:00:00 2001 From: Alberto Di Maria <84965833+Alberto-DM@users.noreply.github.com> Date: Thu, 11 Jul 2024 16:04:55 +0200 Subject: [PATCH] FEAT: set thermal modifier and spatial modifier to None (#4908) --- _unittest/test_03_Materials.py | 39 +++++++++++++ pyaedt/modules/Material.py | 100 +++++++++++++++++++++++++++++++-- 2 files changed, 133 insertions(+), 6 deletions(-) diff --git a/_unittest/test_03_Materials.py b/_unittest/test_03_Materials.py index 3779bdae18d..019c420193d 100644 --- a/_unittest/test_03_Materials.py +++ b/_unittest/test_03_Materials.py @@ -408,3 +408,42 @@ def test_14_set_core_loss(self): self.aedtapp.materials["mat_test"].set_coreloss_at_frequency( points_at_frequency={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness=50 ) + + def test_15_thermalmodifier_and_spatialmodifier(self): + assert self.aedtapp.materials["vacuum"].conductivity.thermalmodifier is None + assert self.aedtapp.materials["vacuum"].conductivity.spatialmodifier is None + + self.aedtapp.materials["vacuum"].conductivity.thermalmodifier = "1" + assert self.aedtapp.materials["vacuum"].conductivity.thermalmodifier == "1" + self.aedtapp.materials["vacuum"].conductivity.spatialmodifier = "1" + assert self.aedtapp.materials["vacuum"].conductivity.spatialmodifier == "1" + + self.aedtapp.materials["vacuum"].conductivity.thermalmodifier = None + assert self.aedtapp.materials["vacuum"].conductivity.thermalmodifier is None + self.aedtapp.materials["vacuum"].conductivity.thermalmodifier = "2" + assert self.aedtapp.materials["vacuum"].conductivity.thermalmodifier == "2" + + self.aedtapp.materials["vacuum"].conductivity.spatialmodifier = None + assert self.aedtapp.materials["vacuum"].conductivity.spatialmodifier is None + self.aedtapp.materials["vacuum"].conductivity.spatialmodifier = "2" + assert self.aedtapp.materials["vacuum"].conductivity.spatialmodifier == "2" + + self.aedtapp.materials["vacuum"].conductivity.thermalmodifier = None + assert self.aedtapp.materials["vacuum"].conductivity.thermalmodifier is None + self.aedtapp.materials["vacuum"].conductivity.spatialmodifier = None + assert self.aedtapp.materials["vacuum"].conductivity.spatialmodifier is None + + self.aedtapp.materials["vacuum"].conductivity.thermalmodifier = "3" + assert self.aedtapp.materials["vacuum"].conductivity.thermalmodifier == "3" + self.aedtapp.materials["vacuum"].conductivity.spatialmodifier = "3" + assert self.aedtapp.materials["vacuum"].conductivity.spatialmodifier == "3" + + self.aedtapp.materials["vacuum"].conductivity.thermalmodifier = None + self.aedtapp.materials["vacuum"].conductivity.spatialmodifier = None + self.aedtapp.materials["vacuum"].conductivity.thermalmodifier = "4" + assert self.aedtapp.materials["vacuum"].conductivity.thermalmodifier == "4" + self.aedtapp.materials["vacuum"].conductivity.spatialmodifier = "4" + assert self.aedtapp.materials["vacuum"].conductivity.spatialmodifier == "4" + + self.aedtapp.materials["vacuum"].conductivity.thermalmodifier = None + self.aedtapp.materials["vacuum"].conductivity.spatialmodifier = None diff --git a/pyaedt/modules/Material.py b/pyaedt/modules/Material.py index 7214ce71392..f656dca9c72 100644 --- a/pyaedt/modules/Material.py +++ b/pyaedt/modules/Material.py @@ -460,11 +460,20 @@ def thermalmodifier(self, thermal_value): >>> oDefinitionManager.EditMaterial """ - if isinstance(thermal_value, str): + if thermal_value is None: + self._property_value[0].thermalmodifier = None + self._reset_thermal_modifier() + elif isinstance(thermal_value, str): + self._property_value[0].thermalmodifier = thermal_value self._add_thermal_modifier(thermal_value, 0) else: - for i in thermal_value: - self._add_thermal_modifier(i, thermal_value.index(i)) + for i, value in enumerate(thermal_value): + self._add_thermal_modifier(value, i) + try: + self._property_value[i].thermalmodifier = value + except IndexError: + self._property_value.append(BasicValue()) + self._property_value[i].thermalmodifier = value def _add_thermal_modifier(self, formula, index): """Add a thermal modifier. @@ -484,6 +493,10 @@ def _add_thermal_modifier(self, formula, index): if ( "ModifierData" not in self._material._props or "ThermalModifierData" not in self._material._props["ModifierData"] + or ( + "all_thermal_modifiers" in self._material._props["ModifierData"]["ThermalModifierData"] + and bool(self._material._props["ModifierData"]["ThermalModifierData"]["all_thermal_modifiers"]) == False + ) ): tm = OrderedDict( { @@ -602,6 +615,35 @@ def _add_thermal_modifier(self, formula, index): ].append(tm) return self._material.update() + def _reset_thermal_modifier(self): + """Set the thermal modifier to None. + + Returns + ------- + type + + """ + if "ModifierData" in self._material._props and "ThermalModifierData" in self._material._props["ModifierData"]: + if ( + "ModifierData" in self._material._props + and "SpatialModifierData" in self._material._props["ModifierData"] + ): + self._material._props["ModifierData"] = { + "SpatialModifierData": self._material._props["ModifierData"]["SpatialModifierData"], + "ThermalModifierData": { + "modifier_data": "thermal_modifier_data", + "all_thermal_modifiers": None, + }, + } + else: + self._material._props["ModifierData"] = { + "ThermalModifierData": { + "modifier_data": "thermal_modifier_data", + "all_thermal_modifiers": None, + } + } + return self._material.update() + @pyaedt_function_handler() def add_thermal_modifier_free_form(self, formula, index=0): """Add a thermal modifier to a material property using a free-form formula. @@ -773,6 +815,10 @@ def add_thermal_modifier_closed_form( if ( "ModifierData" not in self._material._props or "ThermalModifierData" not in self._material._props["ModifierData"] + or ( + "all_thermal_modifiers" in self._material._props["ModifierData"]["ThermalModifierData"] + and bool(self._material._props["ModifierData"]["ThermalModifierData"]["all_thermal_modifiers"]) == False + ) ): if ( "ModifierData" in self._material._props @@ -934,11 +980,20 @@ def spatialmodifier(self, spatial_value): >>> oDefinitionManager.EditMaterial """ - if isinstance(spatial_value, str): + if spatial_value is None: + self._property_value[0].spatialmodifier = None + self._reset_spatial_modifier() + elif isinstance(spatial_value, str): + self._property_value[0].spatialmodifier = spatial_value self._add_spatial_modifier(spatial_value, 0) else: - for i in spatial_value: - self._add_spatial_modifier(i, spatial_value.index(i)) + for i, value in enumerate(spatial_value): + self._add_spatial_modifier(value, i) + try: + self._property_value[i].spatialmodifier = value + except IndexError: + self._property_value.append(BasicValue()) + self._property_value[i].spatialmodifier = value def _add_spatial_modifier(self, formula, index): """Add a spatial modifier. @@ -958,6 +1013,10 @@ def _add_spatial_modifier(self, formula, index): if ( "ModifierData" not in self._material._props or "SpatialModifierData" not in self._material._props["ModifierData"] + or ( + "all_spatial_modifiers" in self._material._props["ModifierData"]["SpatialModifierData"] + and bool(self._material._props["ModifierData"]["SpatialModifierData"]["all_spatial_modifiers"]) == False + ) ): sm = OrderedDict( { @@ -1049,6 +1108,35 @@ def _add_spatial_modifier(self, formula, index): ].append(sm) return self._material.update() + def _reset_spatial_modifier(self): + """Set the spatial modifier to None. + + Returns + ------- + type + + """ + if "ModifierData" in self._material._props and "SpatialModifierData" in self._material._props["ModifierData"]: + if ( + "ModifierData" in self._material._props + and "ThermalModifierData" in self._material._props["ModifierData"] + ): + self._material._props["ModifierData"] = { + "ThermalModifierData": self._material._props["ModifierData"]["ThermalModifierData"], + "SpatialModifierData": { + "modifier_data": "spatial_modifier_data", + "all_spatial_modifiers": None, + }, + } + else: + self._material._props["ModifierData"] = { + "SpatialModifierData": { + "modifier_data": "spatial_modifier_data", + "all_spatial_modifiers": None, + } + } + return self._material.update() + @pyaedt_function_handler() def add_spatial_modifier_free_form(self, formula, index=0): """Add a spatial modifier to a material property using a free-form formula.