diff --git a/Tests/Functions/test_save_load.py b/Tests/Functions/test_save_load.py index 04824c345..b8200d65a 100644 --- a/Tests/Functions/test_save_load.py +++ b/Tests/Functions/test_save_load.py @@ -20,10 +20,11 @@ from pyleecan.Classes.Simu1 import Simu1 from pyleecan.Classes.SlotM11 import SlotM11 from pyleecan.Classes.SlotW10 import SlotW10 +from pyleecan.Classes.SlotUD import SlotUD +from pyleecan.Classes.HoleUD import HoleUD from pyleecan.Classes.Winding import Winding from pyleecan.Classes.OPdq import OPdq from pyleecan.Functions.load import ( - LoadSwitchError, LoadWrongDictClassError, LoadWrongTypeError, load, @@ -247,6 +248,31 @@ def test_save_load_just_name(): # remove(file_path) +def test_save_load_DXF_flat(): + """Check that you can save/load a machine with dxf slot/hole in flat mode""" + Prius_DXF = load(join(DATA_DIR, "Machine", "Toyota_Prius_DXF.json")) + save_dir = join(save_path, "Toyota_Prius_DXF") + # Check save + assert not isdir(save_dir) + Prius_DXF.save(save_path=save_dir, is_folder=True) + assert isdir(save_dir) + file_list = listdir(save_dir) + assert len(file_list) == 12 + assert "hole.json" in file_list + assert "slot.json" in file_list + # Check load + Prius_2 = load(save_dir) + assert isinstance(Prius_2.stator.slot, SlotUD) + assert isinstance(Prius_2.rotor.hole[0], HoleUD) + assert len(Prius_DXF.compare(Prius_2)) == 0 + # Remove file and check None + remove(join(save_dir, "hole.json")) + remove(join(save_dir, "slot.json")) + Prius_3 = load(save_dir) + assert Prius_3.stator.slot is None + assert Prius_3.rotor.hole[0] is None + + def test_load_error_missing(): """Test that the load function can detect missing file""" with pytest.raises(LoadMissingFileError): @@ -406,9 +432,8 @@ def test_save_load_simu(type_file): if __name__ == "__main__": - test_save_load_simu("json") - test_save_load_simu("h5") - test_save_load_simu("pkl") - # test_save_load_folder_path() - # test_save_load_json_compressed() + test_save_load_DXF_flat() print("Done") + # test_save_load_simu("json") + # test_save_load_simu("h5") + # test_save_load_simu("pkl") diff --git a/pyleecan/Classes/BoreUD.py b/pyleecan/Classes/BoreUD.py index 5760b358e..e87973920 100644 --- a/pyleecan/Classes/BoreUD.py +++ b/pyleecan/Classes/BoreUD.py @@ -200,6 +200,15 @@ def _set_line_list(self, value): """setter of line_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "line_list" diff --git a/pyleecan/Classes/HoleUD.py b/pyleecan/Classes/HoleUD.py index 8dc13541f..80ed497d1 100644 --- a/pyleecan/Classes/HoleUD.py +++ b/pyleecan/Classes/HoleUD.py @@ -345,6 +345,15 @@ def _set_surf_list(self, value): """setter of surf_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "surf_list" @@ -378,6 +387,15 @@ def _set_magnet_dict(self, value): """setter of magnet_dict""" if type(value) is dict: for key, obj in value.items(): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[key] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "magnet_dict" diff --git a/pyleecan/Classes/ImportData.py b/pyleecan/Classes/ImportData.py index 02541617f..554686849 100644 --- a/pyleecan/Classes/ImportData.py +++ b/pyleecan/Classes/ImportData.py @@ -281,6 +281,15 @@ def _set_axes(self, value): """setter of axes""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "axes" diff --git a/pyleecan/Classes/ImportGenMatrixSin.py b/pyleecan/Classes/ImportGenMatrixSin.py index 8ff1ac422..d6cd1c2ba 100644 --- a/pyleecan/Classes/ImportGenMatrixSin.py +++ b/pyleecan/Classes/ImportGenMatrixSin.py @@ -220,6 +220,15 @@ def _set_sin_list(self, value): """setter of sin_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "sin_list" diff --git a/pyleecan/Classes/ImportVectorField.py b/pyleecan/Classes/ImportVectorField.py index 8d450c7a5..0475438eb 100644 --- a/pyleecan/Classes/ImportVectorField.py +++ b/pyleecan/Classes/ImportVectorField.py @@ -211,6 +211,15 @@ def _set_components(self, value): """setter of components""" if type(value) is dict: for key, obj in value.items(): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[key] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "components" diff --git a/pyleecan/Classes/LUTdq.py b/pyleecan/Classes/LUTdq.py index 79a6b2f6c..2c0dd95fc 100644 --- a/pyleecan/Classes/LUTdq.py +++ b/pyleecan/Classes/LUTdq.py @@ -472,6 +472,15 @@ def _set_Phi_wind(self, value): """setter of Phi_wind""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "SciDataTool.Classes", obj.get("__class__"), "Phi_wind" @@ -499,6 +508,8 @@ def _get_Phi_dqh_interp(self): def _set_Phi_dqh_interp(self, value): """setter of Phi_dqh_interp""" + if value == -1: + value = RegularGridInterpolator() check_var("Phi_dqh_interp", value, "RegularGridInterpolator") self._Phi_dqh_interp = value diff --git a/pyleecan/Classes/LamHole.py b/pyleecan/Classes/LamHole.py index 2011b1b23..6eafcd04c 100644 --- a/pyleecan/Classes/LamHole.py +++ b/pyleecan/Classes/LamHole.py @@ -438,6 +438,15 @@ def _set_hole(self, value): """setter of hole""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "hole" diff --git a/pyleecan/Classes/LamSlotMulti.py b/pyleecan/Classes/LamSlotMulti.py index e8702fb41..e4a470623 100644 --- a/pyleecan/Classes/LamSlotMulti.py +++ b/pyleecan/Classes/LamSlotMulti.py @@ -447,6 +447,15 @@ def _set_slot_list(self, value): """setter of slot_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "slot_list" diff --git a/pyleecan/Classes/LamSquirrelCageMag.py b/pyleecan/Classes/LamSquirrelCageMag.py index b27170adc..90e8a0065 100644 --- a/pyleecan/Classes/LamSquirrelCageMag.py +++ b/pyleecan/Classes/LamSquirrelCageMag.py @@ -377,6 +377,15 @@ def _set_hole(self, value): """setter of hole""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "hole" diff --git a/pyleecan/Classes/Lamination.py b/pyleecan/Classes/Lamination.py index 31f0fbb8e..27e79682c 100644 --- a/pyleecan/Classes/Lamination.py +++ b/pyleecan/Classes/Lamination.py @@ -1093,6 +1093,15 @@ def _set_axial_vent(self, value): """setter of axial_vent""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "axial_vent" @@ -1126,6 +1135,15 @@ def _set_notch(self, value): """setter of notch""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "notch" @@ -1193,6 +1211,15 @@ def _set_yoke_notch(self, value): """setter of yoke_notch""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "yoke_notch" diff --git a/pyleecan/Classes/Loss.py b/pyleecan/Classes/Loss.py index 316fb9b61..9cf9d7184 100644 --- a/pyleecan/Classes/Loss.py +++ b/pyleecan/Classes/Loss.py @@ -262,6 +262,15 @@ def _set_model_list(self, value): """setter of model_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "model_list" diff --git a/pyleecan/Classes/MachineUD.py b/pyleecan/Classes/MachineUD.py index 770ec8ab6..33d615763 100644 --- a/pyleecan/Classes/MachineUD.py +++ b/pyleecan/Classes/MachineUD.py @@ -259,6 +259,15 @@ def _set_lam_list(self, value): """setter of lam_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "lam_list" diff --git a/pyleecan/Classes/MeshMat.py b/pyleecan/Classes/MeshMat.py index ad645734d..5c0b38ee5 100644 --- a/pyleecan/Classes/MeshMat.py +++ b/pyleecan/Classes/MeshMat.py @@ -443,6 +443,15 @@ def _set_cell(self, value): """setter of cell""" if type(value) is dict: for key, obj in value.items(): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[key] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "cell" diff --git a/pyleecan/Classes/MeshSolution.py b/pyleecan/Classes/MeshSolution.py index 7a04a98e7..7daf7c722 100644 --- a/pyleecan/Classes/MeshSolution.py +++ b/pyleecan/Classes/MeshSolution.py @@ -495,6 +495,15 @@ def _set_mesh(self, value): """setter of mesh""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "mesh" @@ -546,6 +555,15 @@ def _set_solution(self, value): """setter of solution""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "solution" diff --git a/pyleecan/Classes/MeshVTK.py b/pyleecan/Classes/MeshVTK.py index 4ee2ee83f..82f394261 100644 --- a/pyleecan/Classes/MeshVTK.py +++ b/pyleecan/Classes/MeshVTK.py @@ -401,6 +401,8 @@ def _get_mesh(self): def _set_mesh(self, value): """setter of mesh""" + if value == -1: + value = vtkPointSet() check_var("mesh", value, "vtkPointSet") self._mesh = value @@ -491,6 +493,8 @@ def _get_surf(self): def _set_surf(self, value): """setter of surf""" + if value == -1: + value = PolyData() check_var("surf", value, "PolyData") self._surf = value diff --git a/pyleecan/Classes/OptiGenAlgNsga2Deap.py b/pyleecan/Classes/OptiGenAlgNsga2Deap.py index d247fc555..d8fff8785 100644 --- a/pyleecan/Classes/OptiGenAlgNsga2Deap.py +++ b/pyleecan/Classes/OptiGenAlgNsga2Deap.py @@ -317,6 +317,8 @@ def _get_toolbox(self): def _set_toolbox(self, value): """setter of toolbox""" + if value == -1: + value = Toolbox() check_var("toolbox", value, "Toolbox") self._toolbox = value diff --git a/pyleecan/Classes/OptiProblem.py b/pyleecan/Classes/OptiProblem.py index 5079ceb0a..3d2304104 100644 --- a/pyleecan/Classes/OptiProblem.py +++ b/pyleecan/Classes/OptiProblem.py @@ -444,6 +444,15 @@ def _set_design_var(self, value): """setter of design_var""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "design_var" @@ -477,6 +486,15 @@ def _set_obj_func(self, value): """setter of obj_func""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "obj_func" @@ -545,6 +563,15 @@ def _set_constraint(self, value): """setter of constraint""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "constraint" @@ -613,6 +640,15 @@ def _set_datakeeper_list(self, value): """setter of datakeeper_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "datakeeper_list" diff --git a/pyleecan/Classes/OutElec.py b/pyleecan/Classes/OutElec.py index 644993447..03007da42 100644 --- a/pyleecan/Classes/OutElec.py +++ b/pyleecan/Classes/OutElec.py @@ -483,6 +483,15 @@ def _set_axes_dict(self, value): """setter of axes_dict""" if type(value) is dict: for key, obj in value.items(): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[key] = None if type(obj) is dict: class_obj = import_class( "SciDataTool.Classes", obj.get("__class__"), "axes_dict" diff --git a/pyleecan/Classes/OutForce.py b/pyleecan/Classes/OutForce.py index 30968e74c..ccbfb92fc 100644 --- a/pyleecan/Classes/OutForce.py +++ b/pyleecan/Classes/OutForce.py @@ -262,6 +262,15 @@ def _set_axes_dict(self, value): """setter of axes_dict""" if type(value) is dict: for key, obj in value.items(): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[key] = None if type(obj) is dict: class_obj = import_class( "SciDataTool.Classes", obj.get("__class__"), "axes_dict" diff --git a/pyleecan/Classes/OutGeo.py b/pyleecan/Classes/OutGeo.py index b38b4fb35..752c1a33b 100644 --- a/pyleecan/Classes/OutGeo.py +++ b/pyleecan/Classes/OutGeo.py @@ -646,6 +646,15 @@ def _set_axes_dict(self, value): """setter of axes_dict""" if type(value) is dict: for key, obj in value.items(): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[key] = None if type(obj) is dict: class_obj = import_class( "SciDataTool.Classes", obj.get("__class__"), "axes_dict" diff --git a/pyleecan/Classes/OutLoss.py b/pyleecan/Classes/OutLoss.py index 4c28c4e17..ea3031a40 100644 --- a/pyleecan/Classes/OutLoss.py +++ b/pyleecan/Classes/OutLoss.py @@ -275,6 +275,15 @@ def _set_loss_list(self, value): """setter of loss_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "SciDataTool.Classes", obj.get("__class__"), "loss_list" @@ -308,6 +317,15 @@ def _set_meshsol_list(self, value): """setter of meshsol_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "meshsol_list" diff --git a/pyleecan/Classes/OutMag.py b/pyleecan/Classes/OutMag.py index a747c503f..0ec5ced17 100644 --- a/pyleecan/Classes/OutMag.py +++ b/pyleecan/Classes/OutMag.py @@ -605,6 +605,15 @@ def _set_axes_dict(self, value): """setter of axes_dict""" if type(value) is dict: for key, obj in value.items(): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[key] = None if type(obj) is dict: class_obj = import_class( "SciDataTool.Classes", obj.get("__class__"), "axes_dict" @@ -787,6 +796,15 @@ def _set_Phi_wind(self, value): """setter of Phi_wind""" if type(value) is dict: for key, obj in value.items(): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[key] = None if type(obj) is dict: class_obj = import_class( "SciDataTool.Classes", obj.get("__class__"), "Phi_wind" @@ -1046,6 +1064,15 @@ def _set_Phi_wind_slice(self, value): """setter of Phi_wind_slice""" if type(value) is dict: for key, obj in value.items(): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[key] = None if type(obj) is dict: class_obj = import_class( "SciDataTool.Classes", obj.get("__class__"), "Phi_wind_slice" diff --git a/pyleecan/Classes/OutMagFEMM.py b/pyleecan/Classes/OutMagFEMM.py index 38018ef8d..471a29562 100644 --- a/pyleecan/Classes/OutMagFEMM.py +++ b/pyleecan/Classes/OutMagFEMM.py @@ -237,6 +237,15 @@ def _set_handler_list(self, value): """setter of handler_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "handler_list" diff --git a/pyleecan/Classes/OutStruct.py b/pyleecan/Classes/OutStruct.py index 60ad221ee..232bc2ba3 100644 --- a/pyleecan/Classes/OutStruct.py +++ b/pyleecan/Classes/OutStruct.py @@ -226,6 +226,15 @@ def _set_axes_dict(self, value): """setter of axes_dict""" if type(value) is dict: for key, obj in value.items(): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[key] = None if type(obj) is dict: class_obj = import_class( "SciDataTool.Classes", obj.get("__class__"), "axes_dict" diff --git a/pyleecan/Classes/Simulation.py b/pyleecan/Classes/Simulation.py index aebd68b8b..7f03e86aa 100644 --- a/pyleecan/Classes/Simulation.py +++ b/pyleecan/Classes/Simulation.py @@ -545,6 +545,15 @@ def _set_postproc_list(self, value): """setter of postproc_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "postproc_list" diff --git a/pyleecan/Classes/SlotUD.py b/pyleecan/Classes/SlotUD.py index cdafdf509..2edc64c79 100644 --- a/pyleecan/Classes/SlotUD.py +++ b/pyleecan/Classes/SlotUD.py @@ -305,6 +305,15 @@ def _set_line_list(self, value): """setter of line_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "line_list" diff --git a/pyleecan/Classes/SlotUD2.py b/pyleecan/Classes/SlotUD2.py index 5dccda57e..19427d16f 100644 --- a/pyleecan/Classes/SlotUD2.py +++ b/pyleecan/Classes/SlotUD2.py @@ -341,6 +341,15 @@ def _set_line_list(self, value): """setter of line_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "line_list" diff --git a/pyleecan/Classes/SurfLine.py b/pyleecan/Classes/SurfLine.py index 75ec0e556..37672bbf0 100644 --- a/pyleecan/Classes/SurfLine.py +++ b/pyleecan/Classes/SurfLine.py @@ -353,6 +353,15 @@ def _set_line_list(self, value): """setter of line_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "line_list" diff --git a/pyleecan/Classes/VarParam.py b/pyleecan/Classes/VarParam.py index 9e16ec8d3..d88b346db 100644 --- a/pyleecan/Classes/VarParam.py +++ b/pyleecan/Classes/VarParam.py @@ -294,6 +294,15 @@ def _set_paramexplorer_list(self, value): """setter of paramexplorer_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "paramexplorer_list" diff --git a/pyleecan/Classes/VarSimu.py b/pyleecan/Classes/VarSimu.py index c4268246c..c0194b906 100644 --- a/pyleecan/Classes/VarSimu.py +++ b/pyleecan/Classes/VarSimu.py @@ -630,6 +630,15 @@ def _set_datakeeper_list(self, value): """setter of datakeeper_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "datakeeper_list" @@ -771,6 +780,15 @@ def _set_postproc_list(self, value): """setter of postproc_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "postproc_list" @@ -804,6 +822,15 @@ def _set_pre_keeper_postproc_list(self, value): """setter of pre_keeper_postproc_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", @@ -839,6 +866,15 @@ def _set_post_keeper_postproc_list(self, value): """setter of post_keeper_postproc_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", diff --git a/pyleecan/Classes/XOutput.py b/pyleecan/Classes/XOutput.py index 54baadd92..a76df755f 100644 --- a/pyleecan/Classes/XOutput.py +++ b/pyleecan/Classes/XOutput.py @@ -764,6 +764,15 @@ def _set_paramexplorer_list(self, value): """setter of paramexplorer_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "paramexplorer_list" @@ -797,6 +806,15 @@ def _set_output_list(self, value): """setter of output_list""" if type(value) is list: for ii, obj in enumerate(value): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[ii] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "output_list" @@ -830,6 +848,15 @@ def _set_xoutput_dict(self, value): """setter of xoutput_dict""" if type(value) is dict: for key, obj in value.items(): + if isinstance(obj, str): # Load from file + try: + obj = load_init_dict(obj)[1] + except Exception as e: + self.get_logger().error( + "Error while loading " + obj + ", setting None instead" + ) + obj = None + value[key] = None if type(obj) is dict: class_obj = import_class( "pyleecan.Classes", obj.get("__class__"), "xoutput_dict" diff --git a/pyleecan/Data/Machine/Toyota_Prius_DXF.json b/pyleecan/Data/Machine/Toyota_Prius_DXF.json new file mode 100644 index 000000000..d569c81b0 --- /dev/null +++ b/pyleecan/Data/Machine/Toyota_Prius_DXF.json @@ -0,0 +1,1652 @@ +{ + "__class__": "MachineIPMSM", + "__save_date__": "2022_01_21 14h02min45s ", + "__version__": "pyleecan_2.1.12", + "desc": "TOYOTA Prius 2004 interior magnet (V shape) with distributed winding", + "frame": null, + "logger_name": "Pyleecan.Machine", + "name": "Toyota_Prius", + "rotor": { + "Kf1": 0.95, + "L1": 0.08382, + "Nrvd": 0, + "Rext": 0.0802, + "Rint": 0.05532, + "Wrvd": 0, + "__class__": "LamHole", + "axial_vent": [], + "bore": null, + "hole": [ + { + "Alpha0": 0, + "Zh": 8, + "__class__": "HoleUD", + "magnet_dict": { + "magnet_0": { + "Lmag": 0.08381999999999999, + "__class__": "Magnet", + "mat_type": { + "HT": { + "Cp": 450.0, + "__class__": "MatHT", + "alpha": null, + "lambda_x": 8.5, + "lambda_y": 8.5, + "lambda_z": 8.5 + }, + "__class__": "Material", + "desc": "MAGNET1 for SIPMSM", + "eco": { + "__class__": "MatEconomical", + "cost_unit": 252.0, + "unit_name": "$" + }, + "elec": { + "__class__": "MatElectrical", + "alpha": 1, + "epsr": null, + "rho": 1.6e-06 + }, + "is_isotropic": true, + "mag": { + "BH_curve": { + "__class__": "ImportMatrixXls", + "axes_colrows": null, + "file_path": null, + "is_allsheets": null, + "is_transpose": null, + "sheet": null, + "skiprows": null, + "usecols": null + }, + "Brm20": 1.24, + "Hc": 902181.163126629, + "LossData": { + "__class__": "ImportMatrix", + "is_transpose": false + }, + "ModelBH": { + "Bmax": 2.31, + "Hmax": null, + "__class__": "ModelBH", + "delta": 100 + }, + "Wlam": 0, + "__class__": "MatMagnetics", + "alpha_Br": -0.001, + "is_BH_extrapolate": false, + "mur_lin": 1.05 + }, + "name": "MagnetPrius", + "path": "D:/MWS5/Material/MagnetPrius.json", + "struct": { + "Ex": 15500000000, + "Ey": null, + "Ez": null, + "Gxy": null, + "Gxz": null, + "Gyz": null, + "__class__": "MatStructural", + "nu_xy": 0.3, + "nu_xz": null, + "nu_yz": null, + "rho": 7500.0 + } + }, + "type_magnetization": 1 + }, + "magnet_1": { + "Lmag": 0.08381999999999999, + "__class__": "Magnet", + "mat_type": { + "HT": { + "Cp": 450.0, + "__class__": "MatHT", + "alpha": null, + "lambda_x": 8.5, + "lambda_y": 8.5, + "lambda_z": 8.5 + }, + "__class__": "Material", + "desc": "MAGNET1 for SIPMSM", + "eco": { + "__class__": "MatEconomical", + "cost_unit": 252.0, + "unit_name": "$" + }, + "elec": { + "__class__": "MatElectrical", + "alpha": 1, + "epsr": null, + "rho": 1.6e-06 + }, + "is_isotropic": true, + "mag": { + "BH_curve": { + "__class__": "ImportMatrixXls", + "axes_colrows": null, + "file_path": null, + "is_allsheets": null, + "is_transpose": null, + "sheet": null, + "skiprows": null, + "usecols": null + }, + "Brm20": 1.24, + "Hc": 902181.163126629, + "LossData": { + "__class__": "ImportMatrix", + "is_transpose": false + }, + "ModelBH": { + "Bmax": 2.31, + "Hmax": null, + "__class__": "ModelBH", + "delta": 100 + }, + "Wlam": 0, + "__class__": "MatMagnetics", + "alpha_Br": -0.001, + "is_BH_extrapolate": false, + "mur_lin": 1.05 + }, + "name": "MagnetPrius", + "path": "D:/MWS5/Material/MagnetPrius.json", + "struct": { + "Ex": 15500000000, + "Ey": null, + "Ez": null, + "Gxy": null, + "Gxz": null, + "Gyz": null, + "__class__": "MatStructural", + "nu_xy": 0.3, + "nu_xz": null, + "nu_yz": null, + "rho": 7500.0 + } + }, + "type_magnetization": 1 + } + }, + "magnetization_dict_offset": { + "magnet_0": 0.3047921108660834, + "magnet_1": -0.30479211086608327 + }, + "mat_void": { + "HT": { + "Cp": 1007, + "__class__": "MatHT", + "alpha": 0.00343, + "lambda_x": 0.0257, + "lambda_y": 0.0257, + "lambda_z": 0.0257 + }, + "__class__": "Material", + "desc": "Air", + "eco": { + "__class__": "MatEconomical", + "cost_unit": 0.127, + "unit_name": "$" + }, + "elec": { + "__class__": "MatElectrical", + "alpha": 1, + "epsr": 1, + "rho": 1 + }, + "is_isotropic": true, + "mag": { + "BH_curve": { + "__class__": "ImportMatrix", + "is_transpose": false + }, + "Brm20": 0, + "Hc": 0, + "LossData": { + "__class__": "ImportMatrix", + "is_transpose": false + }, + "ModelBH": { + "Bmax": 2.31, + "Hmax": null, + "__class__": "ModelBH", + "delta": 100 + }, + "Wlam": 0, + "__class__": "MatMagnetics", + "alpha_Br": 0, + "is_BH_extrapolate": false, + "mur_lin": 1 + }, + "name": "Air", + "path": "D:/MWS5/Material/Air.json", + "struct": { + "Ex": 215000000000.0, + "Ey": 215000000000.0, + "Ez": 80000000000, + "Gxy": 0, + "Gxz": 2000000000, + "Gyz": 2000000000, + "__class__": "MatStructural", + "nu_xy": 0.3, + "nu_xz": 0.03, + "nu_yz": 0.03, + "rho": 1.2044 + } + }, + "name": "hole", + "surf_list": [ + { + "__class__": "SurfLine", + "label": "HoleVoid", + "line_list": [ + { + "__class__": "Arc1", + "begin": "(0.075099920331122-0.023530660132242913j)", + "end": "(0.07584648970123797-0.021j)", + "is_trigo_direction": true, + "prop_dict": null, + "radius": 0.0787000000000002 + }, + { + "__class__": "Segment", + "begin": "(0.07584648970123797-0.021j)", + "end": "(0.07491179312436094-0.018028886897267164j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.07491179312436094-0.018028886897267164j)", + "end": "(0.06966529164632024-0.019679408705943636j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06966529164632024-0.019679408705943636j)", + "end": "(0.07024411843077703-0.021519321128922977j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.07024411843077703-0.021519321128922977j)", + "end": "(0.075099920331122-0.023530660132242913j)", + "prop_dict": null + } + ], + "point_ref": "(0.07270351183411423-0.021797604835677796j)" + }, + { + "__class__": "SurfLine", + "label": "HoleVoid", + "line_list": [ + { + "__class__": "Segment", + "begin": "(0.06399349852195929+0.001650521808676468j)", + "end": "(0.06924+0j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06924+0j)", + "end": "(0.06399349852195929-0.001650521808676468j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06399349852195929-0.001650521808676468j)", + "end": "(0.06347425303002167+0j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06347425303002167+0j)", + "end": "(0.06399349852195929+0.001650521808676468j)", + "prop_dict": null + } + ], + "point_ref": "(0.06565579143264992-0.00027508696811274466j)" + }, + { + "__class__": "SurfLine", + "label": "HoleVoid", + "line_list": [ + { + "__class__": "Arc1", + "begin": "(0.07584648970123799+0.021000000000000005j)", + "end": "(0.07509992033112199+0.023530660132242903j)", + "is_trigo_direction": true, + "prop_dict": null, + "radius": 0.07869999999999973 + }, + { + "__class__": "Segment", + "begin": "(0.075099920331122+0.02353066013224291j)", + "end": "(0.07024411843077703+0.021519321128922974j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.07024411843077703+0.021519321128922974j)", + "end": "(0.06966529164632024+0.019679408705943636j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06966529164632024+0.019679408705943636j)", + "end": "(0.07491179312436094+0.01802888689726717j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.07491179312436094+0.01802888689726717j)", + "end": "(0.07584648970123799+0.021000000000000005j)", + "prop_dict": null + } + ], + "point_ref": "(0.07270351183411425+0.021797604835677796j)" + }, + { + "__class__": "SurfLine", + "label": "HoleMag", + "line_list": [ + { + "__class__": "Segment", + "begin": "(0.06924+0j)", + "end": "(0.07491179312436094-0.018028886897267164j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.07491179312436094-0.018028886897267164j)", + "end": "(0.06966529164632024-0.019679408705943636j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06966529164632024-0.019679408705943636j)", + "end": "(0.06871138228667648-0.01997950358024845j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06871138228667648-0.01997950358024845j)", + "end": "(0.06303958916231552-0.0019506166829812849j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06303958916231552-0.0019506166829812849j)", + "end": "(0.06399349852195929-0.001650521808676468j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06399349852195929-0.001650521808676468j)", + "end": "(0.06924+0j)", + "prop_dict": null + } + ], + "point_ref": "(0.0682602591236054-0.01021482294585283j)" + }, + { + "__class__": "SurfLine", + "label": "HoleMag", + "line_list": [ + { + "__class__": "Segment", + "begin": "(0.07491179312436094+0.01802888689726717j)", + "end": "(0.06966529164632024+0.019679408705943636j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06966529164632024+0.019679408705943636j)", + "end": "(0.06871138228667648+0.019979503580248446j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06871138228667648+0.019979503580248446j)", + "end": "(0.06303958916231552+0.001950616682981278j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06303958916231552+0.001950616682981278j)", + "end": "(0.06399349852195929+0.001650521808676468j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06399349852195929+0.001650521808676468j)", + "end": "(0.06924+0j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.06924+0j)", + "end": "(0.07491179312436094+0.01802888689726717j)", + "prop_dict": null + } + ], + "point_ref": "(0.06826025912360541+0.010214822945852835j)" + } + ] + } + ], + "is_internal": true, + "is_stator": false, + "mat_type": { + "HT": { + "Cp": 1, + "__class__": "MatHT", + "alpha": 0.00393, + "lambda_x": 1, + "lambda_y": 1, + "lambda_z": 1 + }, + "__class__": "Material", + "desc": "Lamination M400-50A", + "eco": { + "__class__": "MatEconomical", + "cost_unit": 0.127, + "unit_name": "$" + }, + "elec": { + "__class__": "MatElectrical", + "alpha": 1, + "epsr": 1, + "rho": 1 + }, + "is_isotropic": false, + "mag": { + "BH_curve": { + "__class__": "ImportMatrixVal", + "is_transpose": false, + "value": [ + [ + 0.0, + 0.0 + ], + [ + 100.0, + 0.5 + ], + [ + 150.0, + 0.7 + ], + [ + 180.0, + 0.8 + ], + [ + 200.0, + 0.9 + ], + [ + 250.0, + 1.0 + ], + [ + 300.0, + 1.05 + ], + [ + 350.0, + 1.1 + ], + [ + 450.0, + 1.15 + ], + [ + 550.0, + 1.2 + ], + [ + 650.0, + 1.225 + ], + [ + 750.0, + 1.25 + ], + [ + 850.0, + 1.275 + ], + [ + 950.0, + 1.3 + ], + [ + 1100.0, + 1.325 + ], + [ + 1250.0, + 1.35 + ], + [ + 1400.0, + 1.375 + ], + [ + 1550.0, + 1.4 + ], + [ + 1700.0, + 1.425 + ], + [ + 1900.0, + 1.45 + ], + [ + 2150.0, + 1.475 + ], + [ + 2450.0, + 1.5 + ], + [ + 2750.0, + 1.525 + ], + [ + 3150.0, + 1.55 + ], + [ + 3600.0, + 1.575 + ], + [ + 4100.0, + 1.6 + ], + [ + 4700.0, + 1.625 + ], + [ + 5250.0, + 1.65 + ], + [ + 6000.0, + 1.675 + ], + [ + 6700.0, + 1.7 + ], + [ + 7500.0, + 1.725 + ], + [ + 8650.0, + 1.75 + ], + [ + 9500.0, + 1.775 + ], + [ + 10750.0, + 1.8 + ], + [ + 14500.0, + 1.85 + ], + [ + 19500.0, + 1.9 + ], + [ + 25000.0, + 1.95 + ], + [ + 33000.0, + 2.0 + ], + [ + 44000.0, + 2.05 + ], + [ + 57000.0, + 2.1 + ], + [ + 74000.0, + 2.15 + ], + [ + 96000.0, + 2.2 + ], + [ + 130000.0, + 2.25 + ], + [ + 170000.0, + 2.3 + ] + ] + }, + "Brm20": 0, + "Hc": 0, + "LossData": { + "__class__": "ImportMatrix", + "is_transpose": false + }, + "ModelBH": { + "Bmax": 2.31, + "Hmax": null, + "__class__": "ModelBH", + "delta": 100 + }, + "Wlam": 0.0005, + "__class__": "MatMagnetics", + "alpha_Br": 0, + "is_BH_extrapolate": false, + "mur_lin": 2500.0 + }, + "name": "M400-50A", + "path": "M400-50A.json", + "struct": { + "Ex": 215000000000.0, + "Ey": 215000000000.0, + "Ez": 80000000000.0, + "Gxy": 82700000000.0, + "Gxz": 2000000000.0, + "Gyz": 2000000000.0, + "__class__": "MatStructural", + "nu_xy": 0.3, + "nu_xz": 0.03, + "nu_yz": 0.03, + "rho": 7650.0 + } + }, + "notch": [], + "skew": null, + "yoke_notch": [] + }, + "shaft": { + "Drsh": 0.11064, + "Lshaft": 0.1, + "__class__": "Shaft", + "mat_type": { + "HT": { + "Cp": 1, + "__class__": "MatHT", + "alpha": 0.00393, + "lambda_x": 1, + "lambda_y": 1, + "lambda_z": 1 + }, + "__class__": "Material", + "desc": "Lamination M400-50A", + "eco": { + "__class__": "MatEconomical", + "cost_unit": 0.127, + "unit_name": "$" + }, + "elec": { + "__class__": "MatElectrical", + "alpha": 1, + "epsr": 1, + "rho": 1 + }, + "is_isotropic": false, + "mag": { + "BH_curve": { + "__class__": "ImportMatrixVal", + "is_transpose": false, + "value": [ + [ + 0.0, + 0.0 + ], + [ + 100.0, + 0.5 + ], + [ + 150.0, + 0.7 + ], + [ + 180.0, + 0.8 + ], + [ + 200.0, + 0.9 + ], + [ + 250.0, + 1.0 + ], + [ + 300.0, + 1.05 + ], + [ + 350.0, + 1.1 + ], + [ + 450.0, + 1.15 + ], + [ + 550.0, + 1.2 + ], + [ + 650.0, + 1.225 + ], + [ + 750.0, + 1.25 + ], + [ + 850.0, + 1.275 + ], + [ + 950.0, + 1.3 + ], + [ + 1100.0, + 1.325 + ], + [ + 1250.0, + 1.35 + ], + [ + 1400.0, + 1.375 + ], + [ + 1550.0, + 1.4 + ], + [ + 1700.0, + 1.425 + ], + [ + 1900.0, + 1.45 + ], + [ + 2150.0, + 1.475 + ], + [ + 2450.0, + 1.5 + ], + [ + 2750.0, + 1.525 + ], + [ + 3150.0, + 1.55 + ], + [ + 3600.0, + 1.575 + ], + [ + 4100.0, + 1.6 + ], + [ + 4700.0, + 1.625 + ], + [ + 5250.0, + 1.65 + ], + [ + 6000.0, + 1.675 + ], + [ + 6700.0, + 1.7 + ], + [ + 7500.0, + 1.725 + ], + [ + 8650.0, + 1.75 + ], + [ + 9500.0, + 1.775 + ], + [ + 10750.0, + 1.8 + ], + [ + 14500.0, + 1.85 + ], + [ + 19500.0, + 1.9 + ], + [ + 25000.0, + 1.95 + ], + [ + 33000.0, + 2.0 + ], + [ + 44000.0, + 2.05 + ], + [ + 57000.0, + 2.1 + ], + [ + 74000.0, + 2.15 + ], + [ + 96000.0, + 2.2 + ], + [ + 130000.0, + 2.25 + ], + [ + 170000.0, + 2.3 + ] + ] + }, + "Brm20": 0, + "Hc": 0, + "LossData": { + "__class__": "ImportMatrix", + "is_transpose": false + }, + "ModelBH": { + "Bmax": 2.31, + "Hmax": null, + "__class__": "ModelBH", + "delta": 100 + }, + "Wlam": 0.0005, + "__class__": "MatMagnetics", + "alpha_Br": 0, + "is_BH_extrapolate": false, + "mur_lin": 2500.0 + }, + "name": "M400-50A", + "path": "M400-50A.json", + "struct": { + "Ex": 215000000000.0, + "Ey": 215000000000.0, + "Ez": 80000000000.0, + "Gxy": 82700000000.0, + "Gxz": 2000000000.0, + "Gyz": 2000000000.0, + "__class__": "MatStructural", + "nu_xy": 0.3, + "nu_xz": 0.03, + "nu_yz": 0.03, + "rho": 7650.0 + } + } + }, + "stator": { + "Kf1": 0.95, + "Ksfill": null, + "L1": 0.08382, + "Nrvd": 0, + "Rext": 0.13462, + "Rint": 0.08095, + "Wrvd": 0, + "__class__": "LamSlotWind", + "axial_vent": [], + "bore": null, + "is_internal": false, + "is_stator": true, + "mat_type": { + "HT": { + "Cp": 1, + "__class__": "MatHT", + "alpha": 0.00393, + "lambda_x": 1, + "lambda_y": 1, + "lambda_z": 1 + }, + "__class__": "Material", + "desc": "Lamination M400-50A", + "eco": { + "__class__": "MatEconomical", + "cost_unit": 0.127, + "unit_name": "$" + }, + "elec": { + "__class__": "MatElectrical", + "alpha": 1, + "epsr": 1, + "rho": 1 + }, + "is_isotropic": false, + "mag": { + "BH_curve": { + "__class__": "ImportMatrixVal", + "is_transpose": false, + "value": [ + [ + 0.0, + 0.0 + ], + [ + 100.0, + 0.5 + ], + [ + 150.0, + 0.7 + ], + [ + 180.0, + 0.8 + ], + [ + 200.0, + 0.9 + ], + [ + 250.0, + 1.0 + ], + [ + 300.0, + 1.05 + ], + [ + 350.0, + 1.1 + ], + [ + 450.0, + 1.15 + ], + [ + 550.0, + 1.2 + ], + [ + 650.0, + 1.225 + ], + [ + 750.0, + 1.25 + ], + [ + 850.0, + 1.275 + ], + [ + 950.0, + 1.3 + ], + [ + 1100.0, + 1.325 + ], + [ + 1250.0, + 1.35 + ], + [ + 1400.0, + 1.375 + ], + [ + 1550.0, + 1.4 + ], + [ + 1700.0, + 1.425 + ], + [ + 1900.0, + 1.45 + ], + [ + 2150.0, + 1.475 + ], + [ + 2450.0, + 1.5 + ], + [ + 2750.0, + 1.525 + ], + [ + 3150.0, + 1.55 + ], + [ + 3600.0, + 1.575 + ], + [ + 4100.0, + 1.6 + ], + [ + 4700.0, + 1.625 + ], + [ + 5250.0, + 1.65 + ], + [ + 6000.0, + 1.675 + ], + [ + 6700.0, + 1.7 + ], + [ + 7500.0, + 1.725 + ], + [ + 8650.0, + 1.75 + ], + [ + 9500.0, + 1.775 + ], + [ + 10750.0, + 1.8 + ], + [ + 14500.0, + 1.85 + ], + [ + 19500.0, + 1.9 + ], + [ + 25000.0, + 1.95 + ], + [ + 33000.0, + 2.0 + ], + [ + 44000.0, + 2.05 + ], + [ + 57000.0, + 2.1 + ], + [ + 74000.0, + 2.15 + ], + [ + 96000.0, + 2.2 + ], + [ + 130000.0, + 2.25 + ], + [ + 170000.0, + 2.3 + ] + ] + }, + "Brm20": 0, + "Hc": 0, + "LossData": { + "__class__": "ImportMatrix", + "is_transpose": false + }, + "ModelBH": { + "Bmax": 2.31, + "Hmax": null, + "__class__": "ModelBH", + "delta": 100 + }, + "Wlam": 0.0005, + "__class__": "MatMagnetics", + "alpha_Br": 0, + "is_BH_extrapolate": false, + "mur_lin": 2500.0 + }, + "name": "M400-50A", + "path": "M400-50A.json", + "struct": { + "Ex": 215000000000.0, + "Ey": 215000000000.0, + "Ez": 80000000000.0, + "Gxy": 82700000000.0, + "Gxz": 2000000000.0, + "Gyz": 2000000000.0, + "__class__": "MatStructural", + "nu_xy": 0.3, + "nu_xz": 0.03, + "nu_yz": 0.03, + "rho": 7650.0 + } + }, + "notch": [], + "skew": null, + "slot": { + "Zs": 48, + "__class__": "SlotUD", + "line_list": [ + { + "__class__": "Segment", + "begin": "(0.08094424794264259-0.0009650000000000006j)", + "end": "(0.08194424794264257-0.0009649999999999988j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.08194424794264257-0.0009649999999999988j)", + "end": "(0.08194424794264257-0.002499999999999999j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.08194424794264257-0.002499999999999999j)", + "end": "(0.1112442479426426-0.004000000000000001j)", + "prop_dict": null + }, + { + "__class__": "Arc1", + "begin": "(0.1112442479426426-0.004000000000000001j)", + "end": "(0.1112442479426426+0.004j)", + "is_trigo_direction": true, + "prop_dict": null, + "radius": 0.004 + }, + { + "__class__": "Segment", + "begin": "(0.1112442479426426+0.004j)", + "end": "(0.08194424794264257+0.0025000000000000005j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.08194424794264257+0.0025000000000000005j)", + "end": "(0.08194424794264257+0.0009649999999999997j)", + "prop_dict": null + }, + { + "__class__": "Segment", + "begin": "(0.08194424794264257+0.0009649999999999997j)", + "end": "(0.08094424794264257+0.0009649999999999988j)", + "prop_dict": null + } + ], + "name": "slot", + "type_line_wind": 0, + "wind_begin_index": 1, + "wind_end_index": 6 + }, + "winding": { + "Lewout": 0.019366, + "Nlayer": 1, + "Npcp": 1, + "Nslot_shift_wind": 0, + "Ntcoil": 9, + "__class__": "Winding", + "coil_pitch": 6, + "conductor": { + "Kwoh": 0.5, + "Nwppc": 13, + "Wins_cond": 0.015, + "Wins_wire": 1e-06, + "Wwire": 0.000912, + "__class__": "CondType12", + "cond_mat": { + "HT": { + "Cp": 381.0, + "__class__": "MatHT", + "alpha": 0.00393, + "lambda_x": 385.0, + "lambda_y": 385.0, + "lambda_z": 385.0 + }, + "__class__": "Material", + "desc": "COPPER WINDING", + "eco": { + "__class__": "MatEconomical", + "cost_unit": 60.0, + "unit_name": "$" + }, + "elec": { + "__class__": "MatElectrical", + "alpha": 1, + "epsr": null, + "rho": 1.73e-08 + }, + "is_isotropic": true, + "mag": { + "BH_curve": { + "__class__": "ImportMatrixXls", + "axes_colrows": null, + "file_path": null, + "is_allsheets": null, + "is_transpose": null, + "sheet": null, + "skiprows": null, + "usecols": null + }, + "Brm20": 0, + "Hc": 0, + "LossData": { + "__class__": "ImportMatrix", + "is_transpose": false + }, + "ModelBH": { + "Bmax": 2.31, + "Hmax": null, + "__class__": "ModelBH", + "delta": 100 + }, + "Wlam": 0, + "__class__": "MatMagnetics", + "alpha_Br": 0, + "is_BH_extrapolate": false, + "mur_lin": 1 + }, + "name": "Copper1", + "path": "Copper1.json", + "struct": { + "Ex": 115000000000.0, + "Ey": 115000000000.0, + "Ez": 115000000000.0, + "Gxy": null, + "Gxz": null, + "Gyz": null, + "__class__": "MatStructural", + "nu_xy": null, + "nu_xz": null, + "nu_yz": null, + "rho": 8900.0 + } + }, + "ins_mat": { + "HT": { + "Cp": 671.0, + "__class__": "MatHT", + "alpha": null, + "lambda_x": 0.2, + "lambda_y": 0.2, + "lambda_z": 0.2 + }, + "__class__": "Material", + "desc": "INSULATOR1", + "eco": { + "__class__": "MatEconomical", + "cost_unit": null, + "unit_name": "$" + }, + "elec": { + "__class__": "MatElectrical", + "alpha": 1, + "epsr": null, + "rho": null + }, + "is_isotropic": true, + "mag": { + "BH_curve": { + "__class__": "ImportMatrixXls", + "axes_colrows": null, + "file_path": null, + "is_allsheets": null, + "is_transpose": null, + "sheet": null, + "skiprows": null, + "usecols": null + }, + "Brm20": 0, + "Hc": 0, + "LossData": { + "__class__": "ImportMatrix", + "is_transpose": false + }, + "ModelBH": { + "Bmax": 2.31, + "Hmax": null, + "__class__": "ModelBH", + "delta": 100 + }, + "Wlam": 0, + "__class__": "MatMagnetics", + "alpha_Br": 0, + "is_BH_extrapolate": false, + "mur_lin": 1 + }, + "name": "Insulator1", + "path": "Insulator1.json", + "struct": { + "Ex": null, + "Ey": null, + "Ez": null, + "Gxy": null, + "Gxz": null, + "Gyz": null, + "__class__": "MatStructural", + "nu_xy": null, + "nu_xz": null, + "nu_yz": null, + "rho": 1200.0 + } + } + }, + "end_winding": { + "__class__": "EndWinding" + }, + "is_aper_a": true, + "is_change_layer": false, + "is_permute_B_C": false, + "is_reverse_layer": false, + "is_reverse_wind": false, + "p": 4, + "per_a": 8, + "qs": 3, + "type_connection": 0, + "wind_mat": [ + [ + [ + [ + 9.0, + 0.0, + 0.0 + ], + [ + 9.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + -9.0 + ], + [ + 0.0, + 0.0, + -9.0 + ], + [ + 0.0, + 9.0, + 0.0 + ], + [ + 0.0, + 9.0, + 0.0 + ], + [ + -9.0, + 0.0, + 0.0 + ], + [ + -9.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 9.0 + ], + [ + 0.0, + 0.0, + 9.0 + ], + [ + 0.0, + -9.0, + 0.0 + ], + [ + 0.0, + -9.0, + 0.0 + ], + [ + 9.0, + 0.0, + 0.0 + ], + [ + 9.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + -9.0 + ], + [ + 0.0, + 0.0, + -9.0 + ], + [ + 0.0, + 9.0, + 0.0 + ], + [ + 0.0, + 9.0, + 0.0 + ], + [ + -9.0, + 0.0, + 0.0 + ], + [ + -9.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 9.0 + ], + [ + 0.0, + 0.0, + 9.0 + ], + [ + 0.0, + -9.0, + 0.0 + ], + [ + 0.0, + -9.0, + 0.0 + ], + [ + 9.0, + 0.0, + 0.0 + ], + [ + 9.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + -9.0 + ], + [ + 0.0, + 0.0, + -9.0 + ], + [ + 0.0, + 9.0, + 0.0 + ], + [ + 0.0, + 9.0, + 0.0 + ], + [ + -9.0, + 0.0, + 0.0 + ], + [ + -9.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 9.0 + ], + [ + 0.0, + 0.0, + 9.0 + ], + [ + 0.0, + -9.0, + 0.0 + ], + [ + 0.0, + -9.0, + 0.0 + ], + [ + 9.0, + 0.0, + 0.0 + ], + [ + 9.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + -9.0 + ], + [ + 0.0, + 0.0, + -9.0 + ], + [ + 0.0, + 9.0, + 0.0 + ], + [ + 0.0, + 9.0, + 0.0 + ], + [ + -9.0, + 0.0, + 0.0 + ], + [ + -9.0, + 0.0, + 0.0 + ], + [ + 0.0, + 0.0, + 9.0 + ], + [ + 0.0, + 0.0, + 9.0 + ], + [ + 0.0, + -9.0, + 0.0 + ], + [ + 0.0, + -9.0, + 0.0 + ] + ] + ] + ] + }, + "yoke_notch": [] + }, + "type_machine": 1 +} \ No newline at end of file diff --git a/pyleecan/Functions/get_logger.py b/pyleecan/Functions/get_logger.py index f95ca9172..010beb055 100644 --- a/pyleecan/Functions/get_logger.py +++ b/pyleecan/Functions/get_logger.py @@ -18,7 +18,7 @@ def get_logger(obj): if hasattr(obj, "logger_name"): # Object logger return getLogger(obj.logger_name) - elif obj.parent != None: # Parent logger + elif hasattr(obj, "parent") and obj.parent != None: # Parent logger return obj.parent.get_logger() else: # Default logger return getLogger(DEFAULT_LOG_NAME) diff --git a/pyleecan/GUI/Dxf/DXF_Slot.py b/pyleecan/GUI/Dxf/DXF_Slot.py index 32e2059ba..0471bd14d 100644 --- a/pyleecan/GUI/Dxf/DXF_Slot.py +++ b/pyleecan/GUI/Dxf/DXF_Slot.py @@ -8,15 +8,17 @@ ) from ezdxf import readfile from numpy import angle as np_angle -from numpy import argmin, array -from PySide2.QtCore import QUrl -from PySide2.QtGui import QDesktopServices, QIcon -from PySide2.QtWidgets import QDialog, QFileDialog, QMessageBox +from numpy import argmin, array, exp, angle +from PySide2.QtCore import QSize, Qt, QUrl +from PySide2.QtGui import QIcon, QPixmap, QFont, QDesktopServices +from PySide2.QtWidgets import QComboBox, QDialog, QFileDialog, QMessageBox, QPushButton from ...Classes.LamSlot import LamSlot from ...Classes.SlotUD import SlotUD +from ...Classes.Segment import Segment from ...definitions import config_dict +from ...Functions.Plot.set_plot_gui_icon import set_plot_gui_icon from ...GUI.Dxf.dxf_to_pyleecan import dxf_to_pyleecan_list, convert_dxf_with_FEMM from ...GUI.Resources import pixmap_dict from ...GUI.Tools.MPLCanvas import MPLCanvas @@ -29,6 +31,8 @@ DEL_COL = 1 HL_COL = 2 WIND_COLOR = config_dict["PLOT"]["COLOR_DICT"]["BAR_COLOR"] +FONT_SIZE = 12 +FONT_NAME = config_dict["PLOT"]["FONT_NAME"] Z_TOL = 1e-4 # Point comparison tolerance @@ -91,6 +95,12 @@ def __init__(self, dxf_path=None, Zs=None, lam=None): if self.dxf_path is not None and isfile(self.dxf_path): self.open_document() + # Set font + font = QFont() + font.setFamily(FONT_NAME) + font.setPointSize(FONT_SIZE) + self.textBrowser.setFont(font) + # Connect signals to slot self.w_path_selector.pathChanged.connect(self.open_document) self.b_save.pressed.connect(self.save) @@ -404,6 +414,40 @@ def get_slot(self): break curve_list.append(line_list.pop(ii)) + # Translate + if self.Zcenter != 0: + for line in curve_list: + line.translate(-self.Zcenter * self.lf_scaling.value()) + + # Check the first and last point are matching Rint + Rbo = self.lam.get_Rbo() + Zbegin = curve_list[0].get_begin() + Zend = curve_list[-1].get_end() + if abs(abs(Zbegin) - Rbo) > Z_TOL: + QMessageBox().critical( + self, + self.tr("Error"), + self.tr( + "First point of the slot is not on the bore radius:\nBore radius=" + + str(Rbo) + + ", abs(First point)=" + + str(abs(Zbegin)) + ), + ) + return None + if abs(abs(Zend) - Rbo) > Z_TOL: + QMessageBox().critical( + self, + self.tr("Error"), + self.tr( + "Last point of the slot is not on the bore radius:\nBore radius=" + + str(Rbo) + + ", abs(Last point)=" + + str(abs(Zend)) + ), + ) + return None + # Create the Slot object slot = SlotUD(line_list=curve_list) slot.type_line_wind = self.c_type_line.currentIndex() @@ -420,11 +464,6 @@ def get_slot(self): slot.wind_begin_index = None slot.wind_end_index = None - # Translate - if self.Zcenter != 0: - for line in curve_list: - line.translate(-self.Zcenter * self.lf_scaling.value()) - # Rotation Z1 = curve_list[0].get_begin() Z2 = curve_list[-1].get_end() @@ -432,6 +471,17 @@ def get_slot(self): for line in curve_list: line.rotate(-1 * alpha) + # Enforce perfect match with Bore radius by adding Segments in needed + Zbegin = curve_list[0].get_begin() + Zb2 = Rbo * exp(1j * angle(Zbegin)) + if abs(Zb2 - Zbegin) > 1e-9: + curve_list.insert(0, Segment(begin=Zb2, end=Zbegin)) + + Zend = curve_list[-1].get_end() + Ze2 = Rbo * exp(1j * angle(Zend)) + if abs(Ze2 - Zend) > 1e-9: + curve_list.append(Segment(begin=Zend, end=Ze2)) + # Set metadata slot.Zs = self.si_Zs.value() @@ -447,6 +497,8 @@ def plot(self): """ if self.check_selection(): slot = self.get_slot() + if slot is None: + return # Uncorrect slot # Lamination definition if self.lam is None: lam = LamSlot(slot=slot) @@ -454,24 +506,32 @@ def plot(self): else: lam = self.lam.copy() lam.slot = slot - fig, (ax1, ax2) = plt.subplots(1, 2) - slot.plot(fig=fig, ax=ax1) - # Add the winding if defined - if slot.wind_begin_index is not None: - surf_wind = slot.get_surface_active() - surf_wind.plot(fig=fig, ax=ax1, color=WIND_COLOR, is_show_fig=False) - # Add point index - index = 0 - for line in slot.line_list: - Zb = line.get_begin() - ax1.plot(Zb.real, Zb.imag, "rx", zorder=0) - ax1.text(Zb.real, Zb.imag, str(index)) - index += 1 - Ze = slot.line_list[-1].get_end() - ax1.plot(Ze.real, Ze.imag, "rx", zorder=0) - ax1.text(Ze.real, Ze.imag, str(index)) - # Lamination point - lam.plot(fig=fig, ax=ax2) + try: + fig, (ax1, ax2) = plt.subplots(1, 2) + slot.plot(fig=fig, ax=ax1) + # Add the winding if defined + if slot.wind_begin_index is not None: + surf_wind = slot.get_surface_active() + surf_wind.plot(fig=fig, ax=ax1, color=WIND_COLOR, is_show_fig=False) + # Add point index + index = 0 + for line in slot.line_list: + Zb = line.get_begin() + ax1.plot(Zb.real, Zb.imag, "rx", zorder=0) + ax1.text(Zb.real, Zb.imag, str(index)) + index += 1 + Ze = slot.line_list[-1].get_end() + ax1.plot(Ze.real, Ze.imag, "rx", zorder=0) + ax1.text(Ze.real, Ze.imag, str(index)) + # Lamination point + lam.plot(fig=fig, ax=ax2) + set_plot_gui_icon() + except Exception as e: + QMessageBox().critical( + self, + self.tr("Error"), + self.tr("Error while plotting slot:\n" + str(e)), + ) def save(self): """Save the SlotUD object in a json file @@ -484,7 +544,8 @@ def save(self): if self.check_selection(): slot = self.get_slot() - + if slot is None: + return # Uncorrect slot save_file_path = QFileDialog.getSaveFileName( self, self.tr("Save file"), dirname(self.dxf_path), "Json (*.json)" )[0] diff --git a/pyleecan/Generator/ClassGenerator/properties_generator.py b/pyleecan/Generator/ClassGenerator/properties_generator.py index f20081792..c94ed4099 100644 --- a/pyleecan/Generator/ClassGenerator/properties_generator.py +++ b/pyleecan/Generator/ClassGenerator/properties_generator.py @@ -1,4 +1,4 @@ -from ...Generator import PYTHON_TYPE, TAB, TAB2, TAB3, TAB4, TAB5, TAB6, TAB7 +from ...Generator import PYTHON_TYPE, TAB, TAB2, TAB3, TAB4, TAB5, TAB6 from ...Generator.read_fct import is_list_pyleecan_type, is_dict_pyleecan_type @@ -159,6 +159,16 @@ def generate_prop_setter(gen_dict, class_dict, prop, soft_name="pyleecan"): elif is_dict_pyleecan_type(prop["type"]): set_str += TAB2 + "if type(value) is dict:\n" set_str += TAB3 + "for key, obj in value.items():\n" + set_str += TAB4 + "if isinstance(obj, str): # Load from file\n" + set_str += TAB5 + "try:\n" + set_str += TAB6 + "obj = load_init_dict(obj)[1]\n" + set_str += TAB5 + "except Exception as e:\n" + set_str += ( + TAB6 + + "self.get_logger().error('Error while loading '+obj+', setting None instead')\n" + ) + set_str += TAB6 + "obj = None\n" + set_str += TAB6 + "value[key] = None\n" set_str += TAB4 + "if type(obj) is dict:\n" if "SciDataTool" in prop["type"]: set_str += ( @@ -182,6 +192,16 @@ def generate_prop_setter(gen_dict, class_dict, prop, soft_name="pyleecan"): elif is_list_pyleecan_type(prop["type"]): set_str += TAB2 + "if type(value) is list:\n" set_str += TAB3 + "for ii, obj in enumerate(value):\n" + set_str += TAB4 + "if isinstance(obj, str): # Load from file\n" + set_str += TAB5 + "try:\n" + set_str += TAB6 + "obj = load_init_dict(obj)[1]\n" + set_str += TAB5 + "except Exception as e:\n" + set_str += ( + TAB6 + + "self.get_logger().error('Error while loading '+obj+', setting None instead')\n" + ) + set_str += TAB6 + "obj = None\n" + set_str += TAB6 + "value[ii] = None\n" set_str += TAB4 + "if type(obj) is dict:\n" if "SciDataTool" in prop["type"]: set_str += ( @@ -269,6 +289,9 @@ def generate_prop_setter(gen_dict, class_dict, prop, soft_name="pyleecan"): set_str += TAB3 + "value = " + prop["type"].split(".")[-1] + "()\n" else: set_str += TAB3 + "value = " + prop["type"] + "()\n" + elif "." in prop["type"]: + set_str += TAB2 + "if value == -1:\n" + set_str += TAB3 + "value = " + prop["type"].split(".")[-1] + "()\n" ## Add check_var("var_name",value, "var_type", min=var_min, max=var_max) if prop["type"] == "function":