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)
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)