diff --git a/_unittest/test_03_Materials.py b/_unittest/test_03_Materials.py index ae16883465e..6cece448949 100644 --- a/_unittest/test_03_Materials.py +++ b/_unittest/test_03_Materials.py @@ -290,29 +290,29 @@ def test_14_get_coreloss_coefficients(self): mat = self.aedtapp.materials.add_material("mat_test") # Test points_list_at_freq coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients( - points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]} + points_at_frequency={60: [[0, 0], [1, 3.5], [2, 7.4]]} ) assert isinstance(coeff, list) assert len(coeff) == 3 assert all(isinstance(c, float) for c in coeff) coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients( - points_list_at_freq={"60Hz": [[0, 0], [1, 3.5], [2, 7.4]]} + points_at_frequency={"60Hz": [[0, 0], [1, 3.5], [2, 7.4]]} ) assert isinstance(coeff, list) assert len(coeff) == 3 assert all(isinstance(c, float) for c in coeff) coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients( - points_list_at_freq={"0.06kHz": [[0, 0], [1, 3.5], [2, 7.4]]} + points_at_frequency={"0.06kHz": [[0, 0], [1, 3.5], [2, 7.4]]} ) assert isinstance(coeff, list) assert len(coeff) == 3 assert all(isinstance(c, float) for c in coeff) with pytest.raises(TypeError): self.aedtapp.materials["mat_test"].get_core_loss_coefficients( - points_list_at_freq=[[0, 0], [1, 3.5], [2, 7.4]] + points_at_frequency=[[0, 0], [1, 3.5], [2, 7.4]] ) coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients( - points_list_at_freq={ + points_at_frequency={ 60: [[0, 0], [1, 3.5], [2, 7.4]], 100: [[0, 0], [1, 8], [2, 9]], 150: [[0, 0], [1, 10], [2, 19]], @@ -323,45 +323,45 @@ def test_14_get_coreloss_coefficients(self): assert all(isinstance(c, float) for c in coeff) # Test thickness coeff = self.aedtapp.materials["mat_test"].get_core_loss_coefficients( - points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="0.6mm" + points_at_frequency={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="0.6mm" ) assert isinstance(coeff, list) assert len(coeff) == 3 assert all(isinstance(c, float) for c in coeff) with pytest.raises(TypeError): self.aedtapp.materials["mat_test"].get_core_loss_coefficients( - points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="invalid" + points_at_frequency={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="invalid" ) with pytest.raises(TypeError): self.aedtapp.materials["mat_test"].get_core_loss_coefficients( - points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness=50 + points_at_frequency={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness=50 ) def test_14_set_core_loss(self): mat = self.aedtapp.materials["mat_test"] # Test points_list_at_freq assert self.aedtapp.materials["mat_test"].set_coreloss_at_frequency( - points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]} + points_at_frequency={60: [[0, 0], [1, 3.5], [2, 7.4]]} ) assert self.aedtapp.materials["mat_test"].set_coreloss_at_frequency( - points_list_at_freq={"60Hz": [[0, 0], [1, 3.5], [2, 7.4]]} + points_at_frequency={"60Hz": [[0, 0], [1, 3.5], [2, 7.4]]} ) assert self.aedtapp.materials["mat_test"].set_coreloss_at_frequency( - points_list_at_freq={"0.06kHz": [[0, 0], [1, 3.5], [2, 7.4]]} + points_at_frequency={"0.06kHz": [[0, 0], [1, 3.5], [2, 7.4]]} ) with pytest.raises(TypeError): self.aedtapp.materials["mat_test"].set_coreloss_at_frequency( - points_list_at_freq=[[0, 0], [1, 3.5], [2, 7.4]] + points_at_frequency=[[0, 0], [1, 3.5], [2, 7.4]] ) assert self.aedtapp.materials["mat_test"].set_coreloss_at_frequency( - points_list_at_freq={ + points_at_frequency={ 60: [[0, 0], [1, 3.5], [2, 7.4]], 100: [[0, 0], [1, 8], [2, 9]], 150: [[0, 0], [1, 10], [2, 19]], } ) assert self.aedtapp.materials["mat_test"].set_coreloss_at_frequency( - points_list_at_freq={ + points_at_frequency={ 60: [[0, 0], [1, 3.5], [2, 7.4]], 100: [[0, 0], [1, 8], [2, 9]], 150: [[0, 0], [1, 10], [2, 19]], @@ -370,17 +370,17 @@ def test_14_set_core_loss(self): ) with pytest.raises(ValueError): self.aedtapp.materials["mat_test"].set_coreloss_at_frequency( - points_list_at_freq={80: [[0, 0], [1, 3.5], [2, 7.4]]}, core_loss_model_type="Power Ferrite" + points_at_frequency={80: [[0, 0], [1, 3.5], [2, 7.4]]}, core_loss_model_type="Power Ferrite" ) # Test thickness assert self.aedtapp.materials["mat_test"].set_coreloss_at_frequency( - points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="0.6mm" + points_at_frequency={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="0.6mm" ) with pytest.raises(TypeError): self.aedtapp.materials["mat_test"].set_coreloss_at_frequency( - points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="invalid" + points_at_frequency={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness="invalid" ) with pytest.raises(TypeError): self.aedtapp.materials["mat_test"].set_coreloss_at_frequency( - points_list_at_freq={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness=50 + points_at_frequency={60: [[0, 0], [1, 3.5], [2, 7.4]]}, thickness=50 ) diff --git a/_unittest/test_13_LoadAEDTFile.py b/_unittest/test_13_LoadAEDTFile.py index 792b6d17dfc..32dae828262 100644 --- a/_unittest/test_13_LoadAEDTFile.py +++ b/_unittest/test_13_LoadAEDTFile.py @@ -163,7 +163,7 @@ def test_07_load_material_file(self): def test_08_add_material_from_amat(self, mat1): mat_file = os.path.join(local_path, "example_models", test_subfolder, "material_sample.amat") dd = load_entire_aedt_file(mat_file) - newmat = mat1.materials.add_material("foe_mat", props=dd["mat_example_1"]) + newmat = mat1.materials.add_material("foe_mat", properties=dd["mat_example_1"]) assert newmat.conductivity.value == "1100000" assert newmat.thermal_conductivity.value == "13.8" assert newmat.mass_density.value == "8055" diff --git a/_unittest/test_28_Maxwell3D.py b/_unittest/test_28_Maxwell3D.py index a877e656bf1..67bd8a0fde8 100644 --- a/_unittest/test_28_Maxwell3D.py +++ b/_unittest/test_28_Maxwell3D.py @@ -561,7 +561,7 @@ def test_36_set_bp_curve_loss(self): [[0, 0], [0.6, 1.57], [1.0, 4.44], [1.5, 20.562], [2.1, 44.23]], kdc=0.002, cut_depth=0.0009, - punit="w/kg", + units="w/kg", bunit="tesla", frequency=50, thickness="0.5mm", diff --git a/examples/03-Maxwell/Maxwell_Transformer_Coreloss.py b/examples/03-Maxwell/Maxwell_Transformer_Coreloss.py index 64255feba78..e4bb24e1459 100644 --- a/examples/03-Maxwell/Maxwell_Transformer_Coreloss.py +++ b/examples/03-Maxwell/Maxwell_Transformer_Coreloss.py @@ -86,7 +86,7 @@ m3d.materials[mat.name].set_coreloss_at_frequency(points_list_at_freq=pv, coefficient_setup="kw_per_cubic_meter", core_loss_model_type="Power Ferrite") -coefficients = m3d.materials[mat.name].get_core_loss_coefficients(points_list_at_freq=pv, +coefficients = m3d.materials[mat.name].get_core_loss_coefficients(points_at_frequency=pv, coefficient_setup="kw_per_cubic_meter") ################################################################################### diff --git a/pyaedt/modeler/advanced_cad/stackup_3d.py b/pyaedt/modeler/advanced_cad/stackup_3d.py index c4b18125f11..b9e9f37ac8e 100644 --- a/pyaedt/modeler/advanced_cad/stackup_3d.py +++ b/pyaedt/modeler/advanced_cad/stackup_3d.py @@ -597,7 +597,7 @@ def duplicate_parametrize_material( if duplicated_material.name == cloned_material_name: # return that material. return duplicated_material duplicated_material = self._app.materials.duplicate_material( - material_name, cloned_material_name, props=list_of_properties + material_name, cloned_material_name, properties=list_of_properties ) # duplicated_material = DuplicatedParametrizedMaterial( # application, material_name, cloned_material_name, list_of_properties diff --git a/pyaedt/modules/Material.py b/pyaedt/modules/Material.py index 0c262427297..ccbc1d25bd5 100644 --- a/pyaedt/modules/Material.py +++ b/pyaedt/modules/Material.py @@ -610,13 +610,13 @@ def add_thermal_modifier_free_form(self, formula, index=0): self._property_value[index].thermalmodifier = formula return self._add_thermal_modifier(formula, index) - @pyaedt_function_handler() - def add_thermal_modifier_dataset(self, dataset_name, index=0): + @pyaedt_function_handler(dataset_name="dataset") + def add_thermal_modifier_dataset(self, dataset, index=0): """Add a thermal modifier to a material property using an existing dataset. Parameters ---------- - dataset_name : str + dataset : str Name of the project dataset. index : int, optional Value for the index. The default is ``0``. @@ -641,7 +641,7 @@ def add_thermal_modifier_dataset(self, dataset_name, index=0): >>> mat1.add_thermal_modifier_dataset("$ds1") """ - formula = "pwl({}, Temp)".format(dataset_name) + formula = "pwl({}, Temp)".format(dataset) self._property_value[index].thermalmodifier = formula return self._add_thermal_modifier(formula, index) @@ -1057,13 +1057,13 @@ def add_spatial_modifier_free_form(self, formula, index=0): self._property_value[index].spatialmodifier = formula return self._add_spatial_modifier(formula, index) - @pyaedt_function_handler() - def add_spatial_modifier_dataset(self, dataset_name, index=0): + @pyaedt_function_handler(dataset_name="dataset") + def add_spatial_modifier_dataset(self, dataset, index=0): """Add a spatial modifier to a material property using an existing dataset. Parameters ---------- - dataset_name : str + dataset : str Name of the project dataset. index : int, optional Value for the index. The default is ``0``. @@ -1088,7 +1088,7 @@ def add_spatial_modifier_dataset(self, dataset_name, index=0): >>> mat1.add_spatial_modifier_dataset("$ds1") """ - formula = "clp({}, X,Y,Z)".format(dataset_name) + formula = "clp({}, X,Y,Z)".format(dataset) self._property_value[index].spatialmodifier = formula return self._add_spatial_modifier(formula, index) @@ -2026,10 +2026,10 @@ def set_magnetic_coercivity(self, value=0, x=1, y=0, z=0): ) return self.update() - @pyaedt_function_handler() + @pyaedt_function_handler(points_list_at_freq="points_at_frequency") def get_core_loss_coefficients( self, - points_list_at_freq, + points_at_frequency, core_loss_model_type="Electrical Steel", thickness="0.5mm", conductivity=0, @@ -2039,7 +2039,7 @@ def get_core_loss_coefficients( Parameters ---------- - points_list_at_freq : dict + points_at_frequency : dict Dictionary where keys are the frequencies (in Hz) and values are lists of points (BP curve). If the core loss model is calculated at one frequency, this parameter must be provided as a dictionary with one key (single frequency in Hz) and values are lists of points at @@ -2075,13 +2075,12 @@ def get_core_loss_coefficients( >>> box = m3d.modeler.create_box([-10, -10, 0],[20, 20, 20],"box_to_split") >>> box.material = "magnesium" >>> coefficients = m3d.materials["magnesium"].get_core_loss_coefficients( - ... points_list_at_freq={60 : [[0, 0], [1, 3], [2, 7]]}, - ... thickness="0.5mm", - ... conductivity=0) + ... points_at_frequency={60 : [[0, 0], [1, 3], [2, 7]]}, + ... thickness="0.5mm",conductivity=0) >>> print(coefficients) >>> m3d.release_desktop(True, True) """ - if not isinstance(points_list_at_freq, dict): + if not isinstance(points_at_frequency, dict): raise TypeError("Points list at frequency must be provided as a dictionary.") if not isinstance(thickness, str): raise TypeError("Thickness must be provided as a string with value and unit.") @@ -2089,37 +2088,37 @@ def get_core_loss_coefficients( value, unit = decompose_variable_value(thickness) if not is_number(value) and not unit: raise TypeError("Thickness must be provided as a string with value and unit.") - if len(points_list_at_freq) <= 1 and core_loss_model_type == "Power Ferrite": + if len(points_at_frequency) <= 1 and core_loss_model_type == "Power Ferrite": raise ValueError("At least 2 frequencies must be included.") props = OrderedDict({}) - freq_keys = list(points_list_at_freq.keys()) + freq_keys = list(points_at_frequency.keys()) for i in range(0, len(freq_keys)): if isinstance(freq_keys[i], str): value, unit = decompose_variable_value(freq_keys[i]) if unit != "Hz": value = unit_converter(values=value, unit_system="Freq", input_units=unit, output_units="Hz") - points_list_at_freq[value] = points_list_at_freq[freq_keys[i]] - del points_list_at_freq[freq_keys[i]] + points_at_frequency[value] = points_at_frequency[freq_keys[i]] + del points_at_frequency[freq_keys[i]] - if len(points_list_at_freq) == 1: + if len(points_at_frequency) == 1: props["CoefficientSetupData"] = OrderedDict({}) props["CoefficientSetupData"]["property_data"] = "coreloss_data" props["CoefficientSetupData"]["coefficient_setup"] = coefficient_setup - frequency = list(points_list_at_freq.keys())[0] + frequency = list(points_at_frequency.keys())[0] props["CoefficientSetupData"]["Frequency"] = "{}Hz".format(frequency) props["CoefficientSetupData"]["Thickness"] = thickness props["CoefficientSetupData"]["Conductivity"] = str(conductivity) - points = [i for p in points_list_at_freq[frequency] for i in p] + points = [i for p in points_at_frequency[frequency] for i in p] props["CoefficientSetupData"]["Coordinates"] = OrderedDict({"DimUnits": ["", ""], "Points": points}) - elif len(points_list_at_freq) > 1: + elif len(points_at_frequency) > 1: props["CoreLossMultiCurveData"] = OrderedDict({}) props["CoreLossMultiCurveData"]["property_data"] = "coreloss_multi_curve_data" props["CoreLossMultiCurveData"]["coreloss_unit"] = coefficient_setup props["CoreLossMultiCurveData"]["AllCurves"] = OrderedDict({}) props["CoreLossMultiCurveData"]["AllCurves"]["OneCurve"] = [] - for freq in points_list_at_freq.keys(): - points = [i for p in points_list_at_freq[freq] for i in p] + for freq in points_at_frequency.keys(): + points = [i for p in points_at_frequency[freq] for i in p] one_curve = OrderedDict( { "Frequency": "{}Hz".format(freq), @@ -2130,7 +2129,7 @@ def get_core_loss_coefficients( props = self._get_args(props) props.pop(0) - if len(points_list_at_freq) == 1: + if len(points_at_frequency) == 1: props[0][-1][2] = "NAME:Points" points = props[0][-1].pop(2) props[0][-1][2].insert(0, points) @@ -2144,10 +2143,10 @@ def get_core_loss_coefficients( ) return list(coefficients) - @pyaedt_function_handler() + @pyaedt_function_handler(points_list_at_freq="points_at_frequency") def set_coreloss_at_frequency( self, - points_list_at_freq, + points_at_frequency, kdc=0, cut_depth="1mm", thickness="0.5mm", @@ -2159,7 +2158,7 @@ def set_coreloss_at_frequency( Parameters ---------- - points_list_at_freq : dict + points_at_frequency : dict Dictionary where keys are the frequencies (in Hz) and values are lists of points (BP curve). If the core loss model is calculated at one frequency, this parameter must be provided as a dictionary with one key (single frequency in Hz) and values are lists of points at @@ -2205,7 +2204,7 @@ def set_coreloss_at_frequency( >>> box = m3d.modeler.create_box([-10, -10, 0],[20, 20, 20],"box_to_split") >>> box.material = "magnesium" >>> m3d.materials["magnesium"].set_coreloss_at_frequency( - ... points_list_at_freq={60 : [[0,0], [1,3.5], [2,7.4]]} + ... points_at_frequency={60 : [[0,0], [1,3.5], [2,7.4]]} ... ) >>> m3d.release_desktop(True, True) @@ -2216,25 +2215,25 @@ def set_coreloss_at_frequency( >>> box = m3d.modeler.create_box([-10, -10, 0],[20, 20, 20],"box_to_split") >>> box.material = "magnesium" >>> m3d.materials["magnesium"].set_coreloss_at_frequency( - ... points_list_at_freq={60 : [[0,0], [1,3.5], [2,7.4]], + ... points_at_frequency={60 : [[0,0], [1,3.5], [2,7.4]], ... 100 : [[0,0], [1,8], [2,9]], ... 150 : [[0,0], [1,10], [2,19]]} ... ) >>> m3d.release_desktop(True, True) """ - if not isinstance(points_list_at_freq, dict): + if not isinstance(points_at_frequency, dict): raise TypeError("Points list at frequency must be provided as a dictionary.") - if len(points_list_at_freq) <= 1 and core_loss_model_type == "Power Ferrite": + if len(points_at_frequency) <= 1 and core_loss_model_type == "Power Ferrite": raise ValueError("At least 2 frequencies must be included.") - freq_keys = list(points_list_at_freq.keys()) + freq_keys = list(points_at_frequency.keys()) for i in range(0, len(freq_keys)): if isinstance(freq_keys[i], str): value, unit = decompose_variable_value(freq_keys[i]) if unit != "Hz": value = unit_converter(values=value, unit_system="Freq", input_units=unit, output_units="Hz") - points_list_at_freq[value] = points_list_at_freq[freq_keys[i]] - del points_list_at_freq[freq_keys[i]] + points_at_frequency[value] = points_at_frequency[freq_keys[i]] + del points_at_frequency[freq_keys[i]] if "core_loss_type" not in self._props: choice = "Electrical Steel" if core_loss_model_type == "Electrical Steel" else "Power Ferrite" self._props["core_loss_type"] = OrderedDict({"property_type": "ChoiceProperty", "Choice": choice}) @@ -2247,27 +2246,27 @@ def set_coreloss_at_frequency( self._props.pop("core_loss_hkc", None) self._props.pop("core_loss_curves", None) self._props["core_loss_type"]["Choice"] = core_loss_model_type - if len(points_list_at_freq) == 1: + if len(points_at_frequency) == 1: self._props["AttachedData"]["CoefficientSetupData"] = OrderedDict({}) self._props["AttachedData"]["CoefficientSetupData"]["property_data"] = "coreloss_data" self._props["AttachedData"]["CoefficientSetupData"]["coefficient_setup"] = coefficient_setup - frequency = list(points_list_at_freq.keys())[0] + frequency = list(points_at_frequency.keys())[0] self._props["AttachedData"]["CoefficientSetupData"]["Frequency"] = "{}Hz".format(frequency) self._props["AttachedData"]["CoefficientSetupData"]["Thickness"] = thickness self._props["AttachedData"]["CoefficientSetupData"]["Conductivity"] = str(conductivity) - points = [i for p in points_list_at_freq[frequency] for i in p] + points = [i for p in points_at_frequency[frequency] for i in p] self._props["AttachedData"]["CoefficientSetupData"]["Coordinates"] = OrderedDict( {"DimUnits": ["", ""], "Points": points} ) - elif len(points_list_at_freq) > 1: + elif len(points_at_frequency) > 1: self._props["AttachedData"]["CoreLossMultiCurveData"] = OrderedDict({}) self._props["AttachedData"]["CoreLossMultiCurveData"]["property_data"] = "coreloss_multi_curve_data" self._props["AttachedData"]["CoreLossMultiCurveData"]["coreloss_unit"] = coefficient_setup self._props["AttachedData"]["CoreLossMultiCurveData"]["AllCurves"] = OrderedDict({}) self._props["AttachedData"]["CoreLossMultiCurveData"]["AllCurves"]["OneCurve"] = [] - for freq in points_list_at_freq.keys(): - points = [i for p in points_list_at_freq[freq] for i in p] + for freq in points_at_frequency.keys(): + points = [i for p in points_at_frequency[freq] for i in p] one_curve = OrderedDict( { "Frequency": "{}Hz".format(freq), @@ -2277,7 +2276,7 @@ def set_coreloss_at_frequency( self._props["AttachedData"]["CoreLossMultiCurveData"]["AllCurves"]["OneCurve"].append(one_curve) coefficients = self.get_core_loss_coefficients( - points_list_at_freq, thickness=thickness, conductivity=conductivity + points_at_frequency, thickness=thickness, conductivity=conductivity ) if core_loss_model_type == "Electrical Steel": self._props["core_loss_kh"] = str(coefficients[0]) @@ -2413,19 +2412,19 @@ def set_power_ferrite_coreloss(self, cm=0, x=0, y=0, kdc=0, cut_depth=0.0001): self._props["core_loss_equiv_cut_depth"] = "{}meter".format(cut_depth) return self.update() - @pyaedt_function_handler() + @pyaedt_function_handler(point_list="points", punit="units") def set_bp_curve_coreloss( - self, point_list, kdc=0, cut_depth=0.0001, punit="kw/m^3", bunit="tesla", frequency=60, thickness="0.5mm" + self, points, kdc=0, cut_depth=0.0001, units="kw/m^3", bunit="tesla", frequency=60, thickness="0.5mm" ): """Set B-P Type Core Loss. Parameters ---------- - point_list : list of list + points : list of list List of [x,y] points. kdc : float cut_depth : float - punit : str + units : str Core loss unit. The default is ``"kw/m^3"``. bunit : str Magnetic field unit. The default is ``"tesla"``. @@ -2455,7 +2454,7 @@ def set_bp_curve_coreloss( self._props["core_loss_equiv_cut_depth"] = "{}meter".format(cut_depth) self._props["core_loss_curves"] = OrderedDict({}) self._props["core_loss_curves"]["property_type"] = "nonlinear" - self._props["core_loss_curves"]["PUnit"] = punit + self._props["core_loss_curves"]["PUnit"] = units self._props["core_loss_curves"]["BUnit"] = bunit self._props["core_loss_curves"]["Frequency"] = "{}Hz".format(frequency) self._props["core_loss_curves"]["Thickness"] = thickness @@ -2463,7 +2462,7 @@ def set_bp_curve_coreloss( self._props["core_loss_curves"]["BPCoordinates"] = OrderedDict({}) self._props["core_loss_curves"]["BPCoordinates"]["Point"] = [] - for points in point_list: + for points in points: self._props["core_loss_curves"]["BPCoordinates"]["Point"].append(points) return self.update() @@ -2596,12 +2595,12 @@ def is_dielectric(self, threshold=100000): """ return not self.is_conductor(threshold) - @pyaedt_function_handler + @pyaedt_function_handler(i_freq="frequency") def set_djordjevic_sarkar_model( self, dk=4, df=0.02, - i_freq=1e9, + frequency=1e9, sigma_dc=1e-12, freq_hi=159.15494e9, ): @@ -2613,7 +2612,7 @@ def set_djordjevic_sarkar_model( Dielectric constant at input frequency. df : int, float, str, optional Loss tangent at input frequency. - i_freq : int, float, optional. + frequency : int, float, optional. Input frequency in Hz. sigma_dc : int, float, optional Conductivity at DC. The default is ``1e-12``. @@ -2627,8 +2626,10 @@ def set_djordjevic_sarkar_model( """ # K = f"({dk} * {df} - {sigma_dc} / (2 * pi * {i_freq} * e0)) / atan({freq_hi} / {i_freq})" - K = "({} * {} - {} / (2 * pi * {} * e0)) / atan({} / {})".format(dk, df, sigma_dc, i_freq, freq_hi, i_freq) - epsilon_inf = "({} - {} / 2 * ln({}**2 / {}**2 + 1))".format(dk, K, freq_hi, i_freq) + K = "({} * {} - {} / (2 * pi * {} * e0)) / atan({} / {})".format( + dk, df, sigma_dc, frequency, freq_hi, frequency + ) + epsilon_inf = "({} - {} / 2 * ln({}**2 / {}**2 + 1))".format(dk, K, freq_hi, frequency) freq_low = "({} / exp(10 * {} * {} / ({})))".format(freq_hi, df, epsilon_inf, K) ds_er = "{} + {} / 2 * ln(({}**2 + Freq**2) / ({}**2 + Freq**2))".format(epsilon_inf, K, freq_hi, freq_low) cond = "{} + 2 * pi * Freq * e0 * ({}) * (atan(Freq / ({})) - atan(Freq / {}))".format( diff --git a/pyaedt/modules/MaterialLib.py b/pyaedt/modules/MaterialLib.py index 9dd029cc04b..58438bb8b2d 100644 --- a/pyaedt/modules/MaterialLib.py +++ b/pyaedt/modules/MaterialLib.py @@ -213,13 +213,13 @@ def _get_surface_materials(self): pass return mats - @pyaedt_function_handler() - def checkifmaterialexists(self, mat): + @pyaedt_function_handler(mat="material") + def checkifmaterialexists(self, material): """Check if a material exists in AEDT or PyAEDT Definitions. Parameters ---------- - mat : str + material : str Name of the material. If the material exists and is not in the materials database, it is added to this database. @@ -234,30 +234,30 @@ def checkifmaterialexists(self, mat): >>> oDefinitionManager.GetProjectMaterialNames >>> oMaterialManager.GetData """ - if isinstance(mat, Material): - if mat.name.lower() in self.material_keys: - return mat + if isinstance(material, Material): + if material.name.lower() in self.material_keys: + return material else: return False - if mat.lower() in self.material_keys: - if mat.lower() in self.mat_names_aedt_lower: - return self.material_keys[mat.lower()] - if mat.lower() not in list(self.odefinition_manager.GetProjectMaterialNames()): - self.material_keys[mat.lower()].update() - return self.material_keys[mat.lower()] - elif mat.lower() in self.mat_names_aedt_lower: - return self._aedmattolibrary(mat) + if material.lower() in self.material_keys: + if material.lower() in self.mat_names_aedt_lower: + return self.material_keys[material.lower()] + if material.lower() not in list(self.odefinition_manager.GetProjectMaterialNames()): + self.material_keys[material.lower()].update() + return self.material_keys[material.lower()] + elif material.lower() in self.mat_names_aedt_lower: + return self._aedmattolibrary(material) elif settings.remote_api or settings.remote_rpc_session: - return self._aedmattolibrary(mat) + return self._aedmattolibrary(material) return False - @pyaedt_function_handler() - def check_thermal_modifier(self, mat): + @pyaedt_function_handler(mat="material") + def check_thermal_modifier(self, material): """Check a material to see if it has any thermal modifiers. Parameters ---------- - mat : str + material : str Name of the material. All properties for this material are checked for thermal modifiers. @@ -267,15 +267,15 @@ def check_thermal_modifier(self, mat): ``True`` when successful, ``False`` when failed. """ - omat = self.checkifmaterialexists(mat) + omat = self.checkifmaterialexists(material) if omat: for el in MatProperties.aedtname: if omat.__dict__["_" + el].thermalmodifier: return True return False - @pyaedt_function_handler() - def add_material(self, materialname, props=None): + @pyaedt_function_handler(materialname="name", props="properties") + def add_material(self, name, properties=None): """Add a material with default values. When the added material object is returned, you can customize @@ -283,9 +283,9 @@ def add_material(self, materialname, props=None): Parameters ---------- - materialname : str + name : str Name of the material. - props : dict, optional + properties : dict, optional Material property dictionary. The default is ``None``. Returns @@ -309,25 +309,25 @@ def add_material(self, materialname, props=None): >>> oMaterialManager.GetData """ - materialname = materialname - self.logger.info("Adding new material to the Project Library: " + materialname) - if materialname.lower() in self.material_keys: + name = name + self.logger.info("Adding new material to the Project Library: " + name) + if name.lower() in self.material_keys: self.logger.warning("Warning. The material is already in the database. Change or edit the name.") - return self.material_keys[materialname.lower()] - elif self._get_aedt_case_name(materialname): - return self._aedmattolibrary(self._get_aedt_case_name(materialname)) + return self.material_keys[name.lower()] + elif self._get_aedt_case_name(name): + return self._aedmattolibrary(self._get_aedt_case_name(name)) else: - material = Material(self, materialname, props, material_update=True) + material = Material(self, name, properties, material_update=True) material._update_material() if material: self.logger.info("Material has been added. Edit it to update in Desktop.") - self.material_keys[materialname.lower()] = material - self._mats.append(materialname) - return self.material_keys[materialname.lower()] + self.material_keys[name.lower()] = material + self._mats.append(name) + return self.material_keys[name.lower()] return False - @pyaedt_function_handler() - def add_surface_material(self, material_name, emissivity=None): + @pyaedt_function_handler(material_name="name") + def add_surface_material(self, name, emissivity=None): """Add a surface material. In AEDT, base properties are loaded from the XML database file ``amat.xml`` @@ -335,7 +335,7 @@ def add_surface_material(self, material_name, emissivity=None): Parameters ---------- - material_name : str + name : str Name of the surface material. emissivity : float, optional Emissivity value. @@ -354,23 +354,23 @@ def add_surface_material(self, material_name, emissivity=None): >>> from pyaedt import Hfss >>> hfss = Hfss() - >>> mat = hfss.materials.add_surface_material("Steel", 0.85) + >>> mat = hfss.materials.add_surface_material("Steel",0.85) >>> print(mat.emissivity.value) """ - self.logger.info("Adding a surface material to the project library: " + material_name) - if material_name.lower() in self.surface_material_keys: + self.logger.info("Adding a surface material to the project library: " + name) + if name.lower() in self.surface_material_keys: self.logger.warning("Warning. The material is already in the database. Change the name or edit it.") - return self.surface_material_keys[material_name.lower()] + return self.surface_material_keys[name.lower()] else: - material = SurfaceMaterial(self._app, material_name, material_update=False) + material = SurfaceMaterial(self._app, name, material_update=False) if emissivity: material.emissivity = emissivity material.update() material._material_update = True self.logger.info("Material has been added. Edit it to update in Desktop.") - self.surface_material_keys[material_name.lower()] = material - return self.surface_material_keys[material_name.lower()] + self.surface_material_keys[name.lower()] = material + return self.surface_material_keys[name.lower()] @pyaedt_function_handler() def _create_mat_project_vars(self, matlist): @@ -392,15 +392,15 @@ def _create_mat_project_vars(self, matlist): pass return matprop - @pyaedt_function_handler() - def add_material_sweep(self, materials_list, material_name): + @pyaedt_function_handler(materials_list="assignment", material_name="name") + def add_material_sweep(self, assignment, name): """Create a sweep material made of an array of materials. Parameters ---------- - materials_list : list + assignment : list List of materials to merge into a single sweep material. - material_name : str + name : str Name of the sweep material. Returns @@ -420,44 +420,44 @@ def add_material_sweep(self, materials_list, material_name): >>> hfss = Hfss() >>> hfss.materials.add_material("MyMaterial") >>> hfss.materials.add_material("MyMaterial2") - >>> hfss.materials.add_material_sweep(["MyMaterial", "MyMaterial2"], "Sweep_copper") + >>> hfss.materials.add_material_sweep(["MyMaterial", "MyMaterial2"],"Sweep_copper") """ matsweep = [] - for mat in materials_list: + for mat in assignment: matobj = self.checkifmaterialexists(mat) if matobj: matsweep.append(matobj) mat_dict = self._create_mat_project_vars(matsweep) - newmat = Material(self, material_name, material_update=False) + newmat = Material(self, name, material_update=False) newmat._update_material() - index = "$ID" + material_name + index = "$ID" + name newmat.is_sweep_material = True self._app[index] = 0 for el in mat_dict: if el in list(mat_dict.keys()): - array_var_name = "$" + material_name + "_" + el + array_var_name = "$" + 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) newmat.update() - self.material_keys[material_name.lower()] = newmat + self.material_keys[name.lower()] = newmat return index - @pyaedt_function_handler() - def duplicate_material(self, material_name, new_name=None, props=None): + @pyaedt_function_handler(material_name="material", new_name="name", props="properties") + def duplicate_material(self, material, name=None, properties=None): """Duplicate a material. Parameters ---------- - material_name : str + material : str Name of the material. - new_name : str + name : str Name for the copy of the material. If a new name is not specified, the new material name is ``material_name`` plusa "_clone"`` suffix. - props : list + properties : list List of properties to parameterize when the material is duplicated. Parameterized properties have project scope. Options are: @@ -483,7 +483,7 @@ def duplicate_material(self, material_name, new_name=None, props=None): >>> from pyaedt import Hfss >>> hfss = Hfss() >>> hfss.materials.add_material("MyMaterial") - >>> hfss.materials.duplicate_material("MyMaterial", "MyMaterial2") + >>> hfss.materials.duplicate_material("MyMaterial","MyMaterial2") """ # Special characters must be removed from material names to make @@ -498,26 +498,26 @@ def duplicate_material(self, material_name, new_name=None, props=None): ) # Get the material definition. - material_in_aedt = material_name.lower() in list(self.mat_names_aedt_lower) - material_in_project = material_name.lower() in list(self.material_keys.keys()) + material_in_aedt = material.lower() in list(self.mat_names_aedt_lower) + material_in_project = material.lower() in list(self.material_keys.keys()) if not (material_in_aedt or material_in_project): # Check for material definition - self.logger.error("Material {} is not present".format(material_name)) + self.logger.error("Material {} is not present".format(material)) return False if not material_in_project: - material = self._aedmattolibrary(material_name) + material = self._aedmattolibrary(material) else: - material = self.material_keys[material_name.lower()] + material = self.material_keys[material.lower()] - if not new_name: - new_name = material_name + "_clone" - new_material = Material(self, new_name, material._props, material_update=False) + if not name: + name = material + "_clone" + new_material = Material(self, name, material._props, material_update=False) new_material._update_material() # Parameterize material properties if these were passed. - if props: - for p in props: + if properties: + for p in properties: if p in valid_prop_names: - var_name = "$" + new_name + "_" + p + var_name = "$" + name + "_" + p for r in replace_characters: var_name = var_name.replace(r[0], r[1]) self._app[var_name] = getattr( @@ -529,19 +529,19 @@ def duplicate_material(self, material_name, new_name=None, props=None): print("p = {}".format(p)) new_material.update() new_material._material_update = True - self._mats.append(new_name) - self.material_keys[new_name.lower()] = new_material + self._mats.append(name) + self.material_keys[name.lower()] = new_material return new_material - @pyaedt_function_handler() - def duplicate_surface_material(self, material, new_name): + @pyaedt_function_handler(new_name="name") + def duplicate_surface_material(self, material, name): """Duplicate a surface material. Parameters ---------- material : str Name of the surface material. - new_name : str + name : str Name for the copy of the surface material. Returns @@ -559,15 +559,15 @@ def duplicate_surface_material(self, material, new_name): >>> from pyaedt import Hfss >>> hfss = Hfss() >>> hfss.materials.add_surface_material("MyMaterial") - >>> hfss.materials.duplicate_surface_material("MyMaterial", "MyMaterial2") + >>> hfss.materials.duplicate_surface_material("MyMaterial","MyMaterial2") """ if not material.lower() in list(self.surface_material_keys.keys()): self.logger.error("Material {} is not present".format(material)) return False newmat = SurfaceMaterial( - self, new_name.lower(), self.surface_material_keys[material.lower()]._props, material_update=True + self, name.lower(), self.surface_material_keys[material.lower()]._props, material_update=True ) - self.surface_material_keys[new_name.lower()] = newmat + self.surface_material_keys[name.lower()] = newmat return newmat @pyaedt_function_handler() @@ -680,13 +680,13 @@ def _aedmattolibrary(self, matname): self.material_keys[matname.lower()] = newmat return self.material_keys[matname.lower()] - @pyaedt_function_handler() - def export_materials_to_file(self, full_json_path): + @pyaedt_function_handler(full_json_path="output_file") + def export_materials_to_file(self, output_file): """Export all materials to a JSON or TOML file. Parameters ---------- - full_json_path : str + output_file : str Full path and name of the JSON file to export to. Returns @@ -750,15 +750,15 @@ def find_datasets(d, out_list): json_dict["materials"] = output_dict if datasets: json_dict["datasets"] = datasets - return write_configuration_file(json_dict, full_json_path) + return write_configuration_file(json_dict, output_file) - @pyaedt_function_handler() - def import_materials_from_file(self, full_path=None, **kwargs): + @pyaedt_function_handler(full_path="input_file") + def import_materials_from_file(self, input_file=None, **kwargs): """Import and create materials from a JSON or AMAT file. Parameters ---------- - full_path : str + input_file : str Full path and name for the JSON or AMAT file. Returns @@ -772,21 +772,21 @@ def import_materials_from_file(self, full_path=None, **kwargs): "``full_json_path`` was deprecated in 0.8.1. Use ``full_path`` instead.", DeprecationWarning, ) - full_path = kwargs["full_json_path"] + input_file = kwargs["full_json_path"] - if full_path is None or not os.path.exists(full_path): + if input_file is None or not os.path.exists(input_file): self.logger.error("Incorrect path provided.") return False - _, file_extension = os.path.splitext(full_path) + _, file_extension = os.path.splitext(input_file) json_flag = True datasets = {} if file_extension.lower() == ".json": - data = read_json(full_path) + data = read_json(input_file) if "datasets" in list(data.keys()): datasets = data["datasets"] elif file_extension.lower() == ".amat": - data = load_entire_aedt_file(full_path) + data = load_entire_aedt_file(input_file) json_flag = False new_data = {} @@ -855,19 +855,19 @@ def import_materials_from_file(self, full_path=None, **kwargs): else: newname = mat_name - newmat = self.add_material(newname, props=data[mat_name]) + newmat = self.add_material(newname, properties=data[mat_name]) newmat._props = data[mat_name] newmat._update_material() materials_added.append(newmat) return materials_added - @pyaedt_function_handler() - def import_materials_from_excel(self, material_file): + @pyaedt_function_handler(material_file="input_file") + def import_materials_from_excel(self, input_file): """Import and create materials from a csv or excel file. Parameters ---------- - material_file : str + input_file : str Full path and name for the csv or xlsx file. Returns @@ -885,10 +885,10 @@ def import_materials_from_excel(self, material_file): if is_ironpython: self.logger.error("This method only works with CPython.") return False - if os.path.splitext(material_file)[1] == ".csv": - df = pd.read_csv(material_file, index_col=0) - elif os.path.splitext(material_file)[1] == ".xlsx": - df = pd.read_excel(material_file, index_col=0) + if os.path.splitext(input_file)[1] == ".csv": + df = pd.read_csv(input_file, index_col=0) + elif os.path.splitext(input_file)[1] == ".xlsx": + df = pd.read_excel(input_file, index_col=0) else: self.logger.error("Only csv and xlsx are supported.") return False