def test_Lam_Hole_51_0N2(self): """Test machine plot hole 51 with no magnet_1 """ self.test_obj.rotor.hole[0].magnet_0 = Magnet() self.test_obj.rotor.hole[0].magnet_1 = None self.test_obj.rotor.hole[0].magnet_2 = Magnet() self.test_obj.rotor.plot() fig = plt.gcf() fig.savefig(join(save_path, "test_Lam_Hole_51_s51_3-Rotor_0N2.png")) # 2 for lam + 5*8 for holes self.assertEqual(len(fig.axes[0].patches), 42)
def test_Lam_Hole_53_N01(self): """Test machine plot hole 53 with W1 = 0 and both magnets """ self.test_obj.rotor.hole[0].W1 = 0 self.test_obj.rotor.hole[0].magnet_0 = Magnet() self.test_obj.rotor.hole[0].magnet_1 = Magnet() self.test_obj.rotor.plot() fig = plt.gcf() fig.savefig(join(save_path, "test_Lam_Hole_s53_RotorN01.png")) # 2 lam + 5*8 for the holes self.assertEqual(len(fig.axes[0].patches), 42)
def test_Lam_Hole_51_012(self): """Test machine plot hole 51 with all magnets """ self.test_obj.rotor.hole[0].magnet_0 = Magnet() self.test_obj.rotor.hole[0].magnet_1 = Magnet() self.test_obj.rotor.hole[0].magnet_2 = Magnet() self.test_obj.plot() fig = plt.gcf() fig.savefig(join(save_path, "test_Lam_Hole_51_s51_1-Machine_012.png")) # Rotor + 2 for stator + 0 for frame + 1 for shaft self.assertEqual(len(fig.axes[0].patches), 61) self.test_obj.rotor.plot() fig = plt.gcf() fig.savefig(join(save_path, "test_Lam_Hole_51_s51_1-Rotor_012.png")) # 2 for lam + 7*8 for holes self.assertEqual(len(fig.axes[0].patches), 58)
def test_Lam_Hole_53_W0N(self): """Test machine plot hole 53 with W1 > 0 and no magnet_1 """ self.test_obj.rotor.hole[0].W1 = 2e-3 self.test_obj.rotor.hole[0].magnet_0 = Magnet() self.test_obj.rotor.hole[0].magnet_1 = None self.test_obj.rotor.plot() fig = plt.gcf() fig.savefig(join(save_path, "test_Lam_Hole_s53_RotorW0N.png")) # 2 for lam + (3+1)*8 self.assertEqual(len(fig.axes[0].patches), 34)
def test_Lam_Hole_53_NN1(self): """Test machine plot hole 53 with W1 = 0 and no magnet_0 """ self.test_obj.rotor.hole[0].W1 = 0 self.test_obj.rotor.hole[0].magnet_0 = None self.test_obj.rotor.hole[0].magnet_1 = Magnet() self.test_obj.rotor.plot() fig = plt.gcf() fig.savefig(join(save_path, "test_Lam_Hole_s53_RotorNN1.png")) # 2 for lam + 3*8 for holes self.assertEqual(len(fig.axes[0].patches), 26)
def test_Lam_Hole_51_N1N(self): """Test machine plot hole 51 with no magnet_0 and no magnet_2 """ self.test_obj.rotor.hole[0].magnet_0 = None self.test_obj.rotor.hole[0].magnet_1 = Magnet() self.test_obj.rotor.hole[0].magnet_2 = None self.test_obj.rotor.plot() fig = plt.gcf() fig.savefig(join(save_path, "test_Lam_Hole_s51_6-Rotor_N1N.png")) # 2 for lam + 3*8 for holes self.assertEqual(len(fig.axes[0].patches), 26)
def test_Lam_Hole_50_N0N(self): """Test machine plot hole 50 with W1 =0 and no magnet_1 """ self.test_obj.rotor.hole[0].W1 = 0 self.test_obj.rotor.hole[0].magnet_0 = Magnet() self.test_obj.rotor.hole[0].magnet_1 = None self.test_obj.rotor.plot() fig = plt.gcf() fig.savefig(join(save_path, "test_Lam_Hole_50_s50_RotorN0N.png")) # 2 for lam + (1+2)*8 for holes + 16 vents self.assertEqual(len(fig.axes[0].patches), 42)
def test_Lam_Hole_50_WN1(self): """Test machine plot hole 50 with W1 > 0 and only magnet_1 """ self.test_obj.rotor.hole[0].W1 = 2e-3 self.test_obj.rotor.hole[0].magnet_0 = None self.test_obj.rotor.hole[0].magnet_1 = Magnet() self.test_obj.rotor.plot() fig = plt.gcf() fig.savefig(join(save_path, "test_Lam_Hole_50_s50_RotorWN1.png")) # 2 for lam + (1+3)*8 for holes + 16 vents self.assertEqual(len(fig.axes[0].patches), 50)
def __init__( self, H0=0.003, W0=0.003, H1=0, W3=0.013, H2=0.02, magnet_0=-1, Zh=36, mat_void=-1, init_dict=None, ): """Constructor of the class. Can be use in two ways : - __init__ (arg1 = 1, arg3 = 5) every parameters have name and default values for Matrix, None will initialise the property with an empty Matrix for pyleecan type, None will call the default constructor - __init__ (init_dict = d) d must be a dictionnary wiht every properties as keys ndarray or list can be given for Vector and Matrix object or dict can be given for pyleecan Object""" if magnet_0 == -1: magnet_0 = Magnet() if mat_void == -1: mat_void = Material() if init_dict is not None: # Initialisation by dict check_init_dict( init_dict, ["H0", "W0", "H1", "W3", "H2", "magnet_0", "Zh", "mat_void"]) # Overwrite default value with init_dict content if "H0" in list(init_dict.keys()): H0 = init_dict["H0"] if "W0" in list(init_dict.keys()): W0 = init_dict["W0"] if "H1" in list(init_dict.keys()): H1 = init_dict["H1"] if "W3" in list(init_dict.keys()): W3 = init_dict["W3"] if "H2" in list(init_dict.keys()): H2 = init_dict["H2"] if "magnet_0" in list(init_dict.keys()): magnet_0 = init_dict["magnet_0"] if "Zh" in list(init_dict.keys()): Zh = init_dict["Zh"] if "mat_void" in list(init_dict.keys()): mat_void = init_dict["mat_void"] # Initialisation by argument self.H0 = H0 self.W0 = W0 self.H1 = H1 self.W3 = W3 self.H2 = H2 # magnet_0 can be None, a Magnet object or a dict if isinstance(magnet_0, dict): # Call the correct constructor according to the dict load_dict = { "MagnetFlat": MagnetFlat, "MagnetPolar": MagnetPolar, "MagnetType10": MagnetType10, "MagnetType11": MagnetType11, "MagnetType12": MagnetType12, "MagnetType13": MagnetType13, "MagnetType14": MagnetType14, "Magnet": Magnet, } obj_class = magnet_0.get("__class__") if obj_class is None: self.magnet_0 = Magnet(init_dict=magnet_0) elif obj_class in list(load_dict.keys()): self.magnet_0 = load_dict[obj_class](init_dict=magnet_0) else: # Avoid generation error or wrong modification in json raise InitUnKnowClassError( "Unknow class name in init_dict for magnet_0") else: self.magnet_0 = magnet_0 # Call HoleMag init super(HoleM52, self).__init__(Zh=Zh, mat_void=mat_void)
class HoleM52(HoleMag): """V shape slot for buried magnet""" VERSION = 1 IS_SYMMETRICAL = 1 # cf Methods.Slot.HoleM52.build_geometry build_geometry = build_geometry # cf Methods.Slot.HoleM52.check check = check # cf Methods.Slot.HoleM52.comp_alpha comp_alpha = comp_alpha # cf Methods.Slot.HoleM52.comp_mass_magnets comp_mass_magnets = comp_mass_magnets # cf Methods.Slot.HoleM52.comp_radius comp_radius = comp_radius # cf Methods.Slot.HoleM52.comp_surface comp_surface = comp_surface # cf Methods.Slot.HoleM52.comp_surface_magnets comp_surface_magnets = comp_surface_magnets # cf Methods.Slot.HoleM52.comp_volume_magnets comp_volume_magnets = comp_volume_magnets # cf Methods.Slot.HoleM52.comp_W1 comp_W1 = comp_W1 # cf Methods.Slot.HoleM52.get_height_magnet get_height_magnet = get_height_magnet # cf Methods.Slot.HoleM52.remove_magnet remove_magnet = remove_magnet # save method is available in all object save = save def __init__( self, H0=0.003, W0=0.003, H1=0, W3=0.013, H2=0.02, magnet_0=-1, Zh=36, mat_void=-1, init_dict=None, ): """Constructor of the class. Can be use in two ways : - __init__ (arg1 = 1, arg3 = 5) every parameters have name and default values for Matrix, None will initialise the property with an empty Matrix for pyleecan type, None will call the default constructor - __init__ (init_dict = d) d must be a dictionnary wiht every properties as keys ndarray or list can be given for Vector and Matrix object or dict can be given for pyleecan Object""" if magnet_0 == -1: magnet_0 = Magnet() if mat_void == -1: mat_void = Material() if init_dict is not None: # Initialisation by dict check_init_dict( init_dict, ["H0", "W0", "H1", "W3", "H2", "magnet_0", "Zh", "mat_void"]) # Overwrite default value with init_dict content if "H0" in list(init_dict.keys()): H0 = init_dict["H0"] if "W0" in list(init_dict.keys()): W0 = init_dict["W0"] if "H1" in list(init_dict.keys()): H1 = init_dict["H1"] if "W3" in list(init_dict.keys()): W3 = init_dict["W3"] if "H2" in list(init_dict.keys()): H2 = init_dict["H2"] if "magnet_0" in list(init_dict.keys()): magnet_0 = init_dict["magnet_0"] if "Zh" in list(init_dict.keys()): Zh = init_dict["Zh"] if "mat_void" in list(init_dict.keys()): mat_void = init_dict["mat_void"] # Initialisation by argument self.H0 = H0 self.W0 = W0 self.H1 = H1 self.W3 = W3 self.H2 = H2 # magnet_0 can be None, a Magnet object or a dict if isinstance(magnet_0, dict): # Call the correct constructor according to the dict load_dict = { "MagnetFlat": MagnetFlat, "MagnetPolar": MagnetPolar, "MagnetType10": MagnetType10, "MagnetType11": MagnetType11, "MagnetType12": MagnetType12, "MagnetType13": MagnetType13, "MagnetType14": MagnetType14, "Magnet": Magnet, } obj_class = magnet_0.get("__class__") if obj_class is None: self.magnet_0 = Magnet(init_dict=magnet_0) elif obj_class in list(load_dict.keys()): self.magnet_0 = load_dict[obj_class](init_dict=magnet_0) else: # Avoid generation error or wrong modification in json raise InitUnKnowClassError( "Unknow class name in init_dict for magnet_0") else: self.magnet_0 = magnet_0 # Call HoleMag init super(HoleM52, self).__init__(Zh=Zh, mat_void=mat_void) # The class is frozen (in HoleMag init), for now it's impossible to # add new properties def __str__(self): """Convert this objet in a readeable string (for print)""" HoleM52_str = "" # Get the properties inherited from HoleMag HoleM52_str += super(HoleM52, self).__str__() + linesep HoleM52_str += "H0 = " + str(self.H0) + linesep HoleM52_str += "W0 = " + str(self.W0) + linesep HoleM52_str += "H1 = " + str(self.H1) + linesep HoleM52_str += "W3 = " + str(self.W3) + linesep HoleM52_str += "H2 = " + str(self.H2) + linesep HoleM52_str += "magnet_0 = " + str(self.magnet_0.as_dict()) return HoleM52_str def __eq__(self, other): """Compare two objects (skip parent)""" if type(other) != type(self): return False # Check the properties inherited from HoleMag if not super(HoleM52, self).__eq__(other): return False if other.H0 != self.H0: return False if other.W0 != self.W0: return False if other.H1 != self.H1: return False if other.W3 != self.W3: return False if other.H2 != self.H2: return False if other.magnet_0 != self.magnet_0: return False return True def as_dict(self): """Convert this objet in a json seriable dict (can be use in __init__) """ # Get the properties inherited from HoleMag HoleM52_dict = super(HoleM52, self).as_dict() HoleM52_dict["H0"] = self.H0 HoleM52_dict["W0"] = self.W0 HoleM52_dict["H1"] = self.H1 HoleM52_dict["W3"] = self.W3 HoleM52_dict["H2"] = self.H2 if self.magnet_0 is None: HoleM52_dict["magnet_0"] = None else: HoleM52_dict["magnet_0"] = self.magnet_0.as_dict() # The class name is added to the dict fordeserialisation purpose # Overwrite the mother class name HoleM52_dict["__class__"] = "HoleM52" return HoleM52_dict def _set_None(self): """Set all the properties to None (except pyleecan object)""" self.H0 = None self.W0 = None self.H1 = None self.W3 = None self.H2 = None if self.magnet_0 is not None: self.magnet_0._set_None() # Set to None the properties inherited from HoleMag super(HoleM52, self)._set_None() def _get_H0(self): """getter of H0""" return self._H0 def _set_H0(self, value): """setter of H0""" check_var("H0", value, "float", Vmin=0) self._H0 = value # Slot depth # Type : float, min = 0 H0 = property(fget=_get_H0, fset=_set_H0, doc=u"""Slot depth""") def _get_W0(self): """getter of W0""" return self._W0 def _set_W0(self, value): """setter of W0""" check_var("W0", value, "float", Vmin=0) self._W0 = value # Magnet width # Type : float, min = 0 W0 = property(fget=_get_W0, fset=_set_W0, doc=u"""Magnet width""") def _get_H1(self): """getter of H1""" return self._H1 def _set_H1(self, value): """setter of H1""" check_var("H1", value, "float", Vmin=0) self._H1 = value # Magnet height # Type : float, min = 0 H1 = property(fget=_get_H1, fset=_set_H1, doc=u"""Magnet height""") def _get_W3(self): """getter of W3""" return self._W3 def _set_W3(self, value): """setter of W3""" check_var("W3", value, "float", Vmin=0) self._W3 = value # Tooth width # Type : float, min = 0 W3 = property(fget=_get_W3, fset=_set_W3, doc=u"""Tooth width""") def _get_H2(self): """getter of H2""" return self._H2 def _set_H2(self, value): """setter of H2""" check_var("H2", value, "float", Vmin=0) self._H2 = value # Additional depth for the magnet # Type : float, min = 0 H2 = property(fget=_get_H2, fset=_set_H2, doc=u"""Additional depth for the magnet""") def _get_magnet_0(self): """getter of magnet_0""" return self._magnet_0 def _set_magnet_0(self, value): """setter of magnet_0""" check_var("magnet_0", value, "Magnet") self._magnet_0 = value if self._magnet_0 is not None: self._magnet_0.parent = self # Magnet of the hole # Type : Magnet magnet_0 = property(fget=_get_magnet_0, fset=_set_magnet_0, doc=u"""Magnet of the hole""")
def __init__( self, H0=0.003, W0=0.003, H1=0, W3=0.013, H2=0.02, magnet_0=-1, Zh=36, mat_void=-1, init_dict=None, ): """Constructor of the class. Can be use in two ways : - __init__ (arg1 = 1, arg3 = 5) every parameters have name and default values for Matrix, None will initialise the property with an empty Matrix for pyleecan type, None will call the default constructor - __init__ (init_dict = d) d must be a dictionnary wiht every properties as keys ndarray or list can be given for Vector and Matrix object or dict can be given for pyleecan Object""" if magnet_0 == -1: magnet_0 = Magnet() if mat_void == -1: mat_void = Material() if init_dict is not None: # Initialisation by dict check_init_dict( init_dict, ["H0", "W0", "H1", "W3", "H2", "magnet_0", "Zh", "mat_void"]) # Overwrite default value with init_dict content if "H0" in list(init_dict.keys()): H0 = init_dict["H0"] if "W0" in list(init_dict.keys()): W0 = init_dict["W0"] if "H1" in list(init_dict.keys()): H1 = init_dict["H1"] if "W3" in list(init_dict.keys()): W3 = init_dict["W3"] if "H2" in list(init_dict.keys()): H2 = init_dict["H2"] if "magnet_0" in list(init_dict.keys()): magnet_0 = init_dict["magnet_0"] if "Zh" in list(init_dict.keys()): Zh = init_dict["Zh"] if "mat_void" in list(init_dict.keys()): mat_void = init_dict["mat_void"] # Initialisation by argument self.H0 = H0 self.W0 = W0 self.H1 = H1 self.W3 = W3 self.H2 = H2 # magnet_0 can be None, a Magnet object or a dict if isinstance(magnet_0, dict): # Check that the type is correct (including daughter) class_name = magnet_0.get("__class__") if class_name not in [ "Magnet", "MagnetFlat", "MagnetPolar", "MagnetType10", "MagnetType11", "MagnetType12", "MagnetType13", "MagnetType14", ]: raise InitUnKnowClassError("Unknow class name " + class_name + " in init_dict for magnet_0") # Dynamic import to call the correct constructor module = __import__("pyleecan.Classes." + class_name, fromlist=[class_name]) class_obj = getattr(module, class_name) self.magnet_0 = class_obj(init_dict=magnet_0) else: self.magnet_0 = magnet_0 # Call HoleMag init super(HoleM52, self).__init__(Zh=Zh, mat_void=mat_void)
class HoleM51(HoleMag): """3 magnets V hole""" VERSION = 1 IS_SYMMETRICAL = 1 # cf Methods.Slot.HoleM51.build_geometry build_geometry = build_geometry # cf Methods.Slot.HoleM51.check check = check # cf Methods.Slot.HoleM51.comp_alpha comp_alpha = comp_alpha # cf Methods.Slot.HoleM51.comp_mass_magnets comp_mass_magnets = comp_mass_magnets # cf Methods.Slot.HoleM51.comp_radius comp_radius = comp_radius # cf Methods.Slot.HoleM51.comp_surface_magnets comp_surface_magnets = comp_surface_magnets # cf Methods.Slot.HoleM51.comp_volume_magnets comp_volume_magnets = comp_volume_magnets # cf Methods.Slot.HoleM51.comp_width comp_width = comp_width # cf Methods.Slot.HoleM51.get_height_magnet get_height_magnet = get_height_magnet # cf Methods.Slot.HoleM51.remove_magnet remove_magnet = remove_magnet # save method is available in all object save = save def __init__( self, H0=0.003, H1=0, H2=0.02, W0=0.01, W1=0, W2=0.01, W3=0, W4=0.01, W5=0.01, W6=0, W7=0, magnet_0=-1, magnet_1=-1, magnet_2=-1, Zh=36, mat_void=-1, init_dict=None, ): """Constructor of the class. Can be use in two ways : - __init__ (arg1 = 1, arg3 = 5) every parameters have name and default values for Matrix, None will initialise the property with an empty Matrix for pyleecan type, None will call the default constructor - __init__ (init_dict = d) d must be a dictionnary wiht every properties as keys ndarray or list can be given for Vector and Matrix object or dict can be given for pyleecan Object""" if magnet_0 == -1: magnet_0 = Magnet() if magnet_1 == -1: magnet_1 = Magnet() if magnet_2 == -1: magnet_2 = Magnet() if mat_void == -1: mat_void = Material() if init_dict is not None: # Initialisation by dict check_init_dict( init_dict, [ "H0", "H1", "H2", "W0", "W1", "W2", "W3", "W4", "W5", "W6", "W7", "magnet_0", "magnet_1", "magnet_2", "Zh", "mat_void", ], ) # Overwrite default value with init_dict content if "H0" in list(init_dict.keys()): H0 = init_dict["H0"] if "H1" in list(init_dict.keys()): H1 = init_dict["H1"] if "H2" in list(init_dict.keys()): H2 = init_dict["H2"] if "W0" in list(init_dict.keys()): W0 = init_dict["W0"] if "W1" in list(init_dict.keys()): W1 = init_dict["W1"] if "W2" in list(init_dict.keys()): W2 = init_dict["W2"] if "W3" in list(init_dict.keys()): W3 = init_dict["W3"] if "W4" in list(init_dict.keys()): W4 = init_dict["W4"] if "W5" in list(init_dict.keys()): W5 = init_dict["W5"] if "W6" in list(init_dict.keys()): W6 = init_dict["W6"] if "W7" in list(init_dict.keys()): W7 = init_dict["W7"] if "magnet_0" in list(init_dict.keys()): magnet_0 = init_dict["magnet_0"] if "magnet_1" in list(init_dict.keys()): magnet_1 = init_dict["magnet_1"] if "magnet_2" in list(init_dict.keys()): magnet_2 = init_dict["magnet_2"] if "Zh" in list(init_dict.keys()): Zh = init_dict["Zh"] if "mat_void" in list(init_dict.keys()): mat_void = init_dict["mat_void"] # Initialisation by argument self.H0 = H0 self.H1 = H1 self.H2 = H2 self.W0 = W0 self.W1 = W1 self.W2 = W2 self.W3 = W3 self.W4 = W4 self.W5 = W5 self.W6 = W6 self.W7 = W7 # magnet_0 can be None, a Magnet object or a dict if isinstance(magnet_0, dict): # Call the correct constructor according to the dict load_dict = { "MagnetFlat": MagnetFlat, "MagnetPolar": MagnetPolar, "MagnetType10": MagnetType10, "MagnetType11": MagnetType11, "MagnetType12": MagnetType12, "MagnetType13": MagnetType13, "MagnetType14": MagnetType14, "Magnet": Magnet, } obj_class = magnet_0.get("__class__") if obj_class is None: self.magnet_0 = Magnet(init_dict=magnet_0) elif obj_class in list(load_dict.keys()): self.magnet_0 = load_dict[obj_class](init_dict=magnet_0) else: # Avoid generation error or wrong modification in json raise InitUnKnowClassError( "Unknow class name in init_dict for magnet_0") else: self.magnet_0 = magnet_0 # magnet_1 can be None, a Magnet object or a dict if isinstance(magnet_1, dict): # Call the correct constructor according to the dict load_dict = { "MagnetFlat": MagnetFlat, "MagnetPolar": MagnetPolar, "MagnetType10": MagnetType10, "MagnetType11": MagnetType11, "MagnetType12": MagnetType12, "MagnetType13": MagnetType13, "MagnetType14": MagnetType14, "Magnet": Magnet, } obj_class = magnet_1.get("__class__") if obj_class is None: self.magnet_1 = Magnet(init_dict=magnet_1) elif obj_class in list(load_dict.keys()): self.magnet_1 = load_dict[obj_class](init_dict=magnet_1) else: # Avoid generation error or wrong modification in json raise InitUnKnowClassError( "Unknow class name in init_dict for magnet_1") else: self.magnet_1 = magnet_1 # magnet_2 can be None, a Magnet object or a dict if isinstance(magnet_2, dict): # Call the correct constructor according to the dict load_dict = { "MagnetFlat": MagnetFlat, "MagnetPolar": MagnetPolar, "MagnetType10": MagnetType10, "MagnetType11": MagnetType11, "MagnetType12": MagnetType12, "MagnetType13": MagnetType13, "MagnetType14": MagnetType14, "Magnet": Magnet, } obj_class = magnet_2.get("__class__") if obj_class is None: self.magnet_2 = Magnet(init_dict=magnet_2) elif obj_class in list(load_dict.keys()): self.magnet_2 = load_dict[obj_class](init_dict=magnet_2) else: # Avoid generation error or wrong modification in json raise InitUnKnowClassError( "Unknow class name in init_dict for magnet_2") else: self.magnet_2 = magnet_2 # Call HoleMag init super(HoleM51, self).__init__(Zh=Zh, mat_void=mat_void) # The class is frozen (in HoleMag init), for now it's impossible to # add new properties def __str__(self): """Convert this objet in a readeable string (for print)""" HoleM51_str = "" # Get the properties inherited from HoleMag HoleM51_str += super(HoleM51, self).__str__() + linesep HoleM51_str += "H0 = " + str(self.H0) + linesep HoleM51_str += "H1 = " + str(self.H1) + linesep HoleM51_str += "H2 = " + str(self.H2) + linesep HoleM51_str += "W0 = " + str(self.W0) + linesep HoleM51_str += "W1 = " + str(self.W1) + linesep HoleM51_str += "W2 = " + str(self.W2) + linesep HoleM51_str += "W3 = " + str(self.W3) + linesep HoleM51_str += "W4 = " + str(self.W4) + linesep HoleM51_str += "W5 = " + str(self.W5) + linesep HoleM51_str += "W6 = " + str(self.W6) + linesep HoleM51_str += "W7 = " + str(self.W7) + linesep HoleM51_str += "magnet_0 = " + str( self.magnet_0.as_dict()) + linesep + linesep HoleM51_str += "magnet_1 = " + str( self.magnet_1.as_dict()) + linesep + linesep HoleM51_str += "magnet_2 = " + str(self.magnet_2.as_dict()) return HoleM51_str def __eq__(self, other): """Compare two objects (skip parent)""" if type(other) != type(self): return False # Check the properties inherited from HoleMag if not super(HoleM51, self).__eq__(other): return False if other.H0 != self.H0: return False if other.H1 != self.H1: return False if other.H2 != self.H2: return False if other.W0 != self.W0: return False if other.W1 != self.W1: return False if other.W2 != self.W2: return False if other.W3 != self.W3: return False if other.W4 != self.W4: return False if other.W5 != self.W5: return False if other.W6 != self.W6: return False if other.W7 != self.W7: return False if other.magnet_0 != self.magnet_0: return False if other.magnet_1 != self.magnet_1: return False if other.magnet_2 != self.magnet_2: return False return True def as_dict(self): """Convert this objet in a json seriable dict (can be use in __init__) """ # Get the properties inherited from HoleMag HoleM51_dict = super(HoleM51, self).as_dict() HoleM51_dict["H0"] = self.H0 HoleM51_dict["H1"] = self.H1 HoleM51_dict["H2"] = self.H2 HoleM51_dict["W0"] = self.W0 HoleM51_dict["W1"] = self.W1 HoleM51_dict["W2"] = self.W2 HoleM51_dict["W3"] = self.W3 HoleM51_dict["W4"] = self.W4 HoleM51_dict["W5"] = self.W5 HoleM51_dict["W6"] = self.W6 HoleM51_dict["W7"] = self.W7 if self.magnet_0 is None: HoleM51_dict["magnet_0"] = None else: HoleM51_dict["magnet_0"] = self.magnet_0.as_dict() if self.magnet_1 is None: HoleM51_dict["magnet_1"] = None else: HoleM51_dict["magnet_1"] = self.magnet_1.as_dict() if self.magnet_2 is None: HoleM51_dict["magnet_2"] = None else: HoleM51_dict["magnet_2"] = self.magnet_2.as_dict() # The class name is added to the dict fordeserialisation purpose # Overwrite the mother class name HoleM51_dict["__class__"] = "HoleM51" return HoleM51_dict def _set_None(self): """Set all the properties to None (except pyleecan object)""" self.H0 = None self.H1 = None self.H2 = None self.W0 = None self.W1 = None self.W2 = None self.W3 = None self.W4 = None self.W5 = None self.W6 = None self.W7 = None if self.magnet_0 is not None: self.magnet_0._set_None() if self.magnet_1 is not None: self.magnet_1._set_None() if self.magnet_2 is not None: self.magnet_2._set_None() # Set to None the properties inherited from HoleMag super(HoleM51, self)._set_None() def _get_H0(self): """getter of H0""" return self._H0 def _set_H0(self, value): """setter of H0""" check_var("H0", value, "float", Vmin=0) self._H0 = value # Hole depth # Type : float, min = 0 H0 = property(fget=_get_H0, fset=_set_H0, doc=u"""Hole depth""") def _get_H1(self): """getter of H1""" return self._H1 def _set_H1(self, value): """setter of H1""" check_var("H1", value, "float", Vmin=0) self._H1 = value # Distance from the lamination Bore # Type : float, min = 0 H1 = property(fget=_get_H1, fset=_set_H1, doc=u"""Distance from the lamination Bore""") def _get_H2(self): """getter of H2""" return self._H2 def _set_H2(self, value): """setter of H2""" check_var("H2", value, "float", Vmin=0) self._H2 = value # Hole width # Type : float, min = 0 H2 = property(fget=_get_H2, fset=_set_H2, doc=u"""Hole width""") def _get_W0(self): """getter of W0""" return self._W0 def _set_W0(self, value): """setter of W0""" check_var("W0", value, "float", Vmin=0) self._W0 = value # Hole bottom width # Type : float, min = 0 W0 = property(fget=_get_W0, fset=_set_W0, doc=u"""Hole bottom width""") def _get_W1(self): """getter of W1""" return self._W1 def _set_W1(self, value): """setter of W1""" check_var("W1", value, "float", Vmin=0) self._W1 = value # Hole angular width # Type : float, min = 0 W1 = property(fget=_get_W1, fset=_set_W1, doc=u"""Hole angular width""") def _get_W2(self): """getter of W2""" return self._W2 def _set_W2(self, value): """setter of W2""" check_var("W2", value, "float", Vmin=0) self._W2 = value # magnet_1 position # Type : float, min = 0 W2 = property(fget=_get_W2, fset=_set_W2, doc=u"""magnet_1 position""") def _get_W3(self): """getter of W3""" return self._W3 def _set_W3(self, value): """setter of W3""" check_var("W3", value, "float", Vmin=0) self._W3 = value # magnet_1 width # Type : float, min = 0 W3 = property(fget=_get_W3, fset=_set_W3, doc=u"""magnet_1 width""") def _get_W4(self): """getter of W4""" return self._W4 def _set_W4(self, value): """setter of W4""" check_var("W4", value, "float", Vmin=0) self._W4 = value # magnet_2 position # Type : float, min = 0 W4 = property(fget=_get_W4, fset=_set_W4, doc=u"""magnet_2 position""") def _get_W5(self): """getter of W5""" return self._W5 def _set_W5(self, value): """setter of W5""" check_var("W5", value, "float", Vmin=0) self._W5 = value # magnet_2 width # Type : float, min = 0 W5 = property(fget=_get_W5, fset=_set_W5, doc=u"""magnet_2 width""") def _get_W6(self): """getter of W6""" return self._W6 def _set_W6(self, value): """setter of W6""" check_var("W6", value, "float", Vmin=0) self._W6 = value # magnet_0 position # Type : float, min = 0 W6 = property(fget=_get_W6, fset=_set_W6, doc=u"""magnet_0 position""") def _get_W7(self): """getter of W7""" return self._W7 def _set_W7(self, value): """setter of W7""" check_var("W7", value, "float", Vmin=0) self._W7 = value # magnet_0 width # Type : float, min = 0 W7 = property(fget=_get_W7, fset=_set_W7, doc=u"""magnet_0 width""") def _get_magnet_0(self): """getter of magnet_0""" return self._magnet_0 def _set_magnet_0(self, value): """setter of magnet_0""" check_var("magnet_0", value, "Magnet") self._magnet_0 = value if self._magnet_0 is not None: self._magnet_0.parent = self # First Magnet # Type : Magnet magnet_0 = property(fget=_get_magnet_0, fset=_set_magnet_0, doc=u"""First Magnet""") def _get_magnet_1(self): """getter of magnet_1""" return self._magnet_1 def _set_magnet_1(self, value): """setter of magnet_1""" check_var("magnet_1", value, "Magnet") self._magnet_1 = value if self._magnet_1 is not None: self._magnet_1.parent = self # Second Magnet # Type : Magnet magnet_1 = property(fget=_get_magnet_1, fset=_set_magnet_1, doc=u"""Second Magnet""") def _get_magnet_2(self): """getter of magnet_2""" return self._magnet_2 def _set_magnet_2(self, value): """setter of magnet_2""" check_var("magnet_2", value, "Magnet") self._magnet_2 = value if self._magnet_2 is not None: self._magnet_2.parent = self # Third Magnet # Type : Magnet magnet_2 = property(fget=_get_magnet_2, fset=_set_magnet_2, doc=u"""Third Magnet""")