def test_Lam_Mag_11_surface(self): """Test machine plot with Magnet 11 surface""" plt.close("all") test_obj = Machine() test_obj.rotor = LamSlotMag( Rint=40e-3, Rext=90e-3, is_internal=True, is_stator=False, L1=0.45, Nrvd=1, Wrvd=0.05, ) magnet = [MagnetType11(Lmag=0.5, Hmag=0.01, Wmag=pi / 8)] test_obj.rotor.slot = SlotMPolar(Zs=8, W0=pi / 8, magnet=magnet) test_obj.rotor.mat_type.magnetics = MatLamination(Wlam=0.5e-3) test_obj.shaft = Shaft(Drsh=test_obj.rotor.Rint * 2, Lshaft=0.55) test_obj.stator = LamSlotMag( Rint=115e-3, Rext=200e-3, is_internal=False, is_stator=True, L1=0.45, Nrvd=1, Wrvd=0.05, ) magnet2 = [MagnetType11(Lmag=0.5, Hmag=0.01, Wmag=pi / 4)] test_obj.stator.slot = SlotMPolar(Zs=4, W0=pi / 4, magnet=magnet2) test_obj.stator.mat_type.magnetics = MatLamination(Wlam=0.5e-3) test_obj.frame = Frame(Rint=200e-3, Rext=200e-3, Lfra=0.5) test_obj.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 17) fig.savefig(join(save_path, "test_Lam_Mag_11s_1-Machine.png")) test_obj.rotor.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 10) fig.savefig(join(save_path, "test_Lam_Mag_11s_2-Rotor.png")) test_obj.stator.plot() fig = plt.gcf() patches = fig.axes[0].patches self.assertEqual(len(patches), 6) self.assertTrue(isinstance(patches[0], Circle)) self.assertEqual(patches[0].get_radius(), 200e-3) self.assertEqual(patches[0].get_facecolor(), (0.0, 0.0, 1.0, 1.0)) # Blue for i in range(1, 6): self.assertTrue(isinstance(patches[i], Polygon)) if i == 1: # Lamination inner self.assertEqual(patches[i].get_facecolor(), (1.0, 1.0, 1.0, 1.0)) # White else: # Magnet self.assertEqual(patches[i].get_facecolor(), (0.75, 0.75, 0.75, 1.0)) # Gray fig.savefig(join(save_path, "test_Lam_Mag_11s_3-Stator.png"))
def test_Lam_Mag_11_inset(self): """Test machine plot with Magnet 11 inset""" plt.close("all") test_obj = Machine() test_obj.rotor = LamSlotMag( Rint=40e-3, Rext=90e-3, is_internal=True, is_stator=False, L1=0.4, Nrvd=2, Wrvd=0.05, ) test_obj.rotor.mat_type.mag = MatLamination(Wlam=0.5e-3) magnet = [MagnetType11(Lmag=0.5, Hmag=0.01, Wmag=pi / 8)] test_obj.rotor.slot = SlotMPolar(Zs=8, W0=pi / 8, H0=0.01, W3=2 * pi / 64, magnet=magnet) test_obj.shaft = Shaft(Drsh=test_obj.rotor.Rint * 2, Lshaft=0.55) test_obj.stator = LamSlotMag( Rint=115e-3, Rext=200e-3, is_internal=False, is_stator=True, L1=0.4, Nrvd=2, Wrvd=0.05, ) magnet2 = [MagnetType11(Lmag=0.35, Hmag=0.03, Wmag=pi / 4)] test_obj.stator.slot = SlotMPolar(Zs=4, W0=pi / 4, H0=0.02, W3=2 * pi / 64, magnet=magnet2) test_obj.stator.mat_type.mag = MatLamination(Wlam=0.5e-3) test_obj.frame = Frame(Rint=200e-3, Rext=230e-3, Lfra=0.3) test_obj.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 19) fig.savefig(join(save_path, "test_Lam_Mag_11i_1-Machine.png")) test_obj.rotor.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 10) fig.savefig(join(save_path, "test_Lam_Mag_11i_2-Rotor.png")) test_obj.stator.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 6) fig.savefig(join(save_path, "test_Lam_Mag_11i_3-Stator.png"))
def test_Lam_Mag_11_inset_2_mag(self): """Test machine plot with Magnet 11 inset with two magnet in the slot""" plt.close("all") rotor = LamSlotMag( Rint=40e-3, Rext=90e-3, is_internal=True, is_stator=False, L1=0.4, Nrvd=2, Wrvd=0.05, ) rotor.mat_type.mag = MatMagnetics(Wlam=0.5e-3) rotor.slot = SlotMPolar( Zs=8, W0=pi / 12, H0=0.01, W3=pi / 18, magnet=[ MagnetType11(Lmag=0.5, Hmag=0.01, Wmag=pi / 12), MagnetType11(Lmag=0.5, Hmag=0.01, Wmag=pi / 12), ], ) stator = LamSlotMag( Rint=115e-3, Rext=200e-3, is_internal=False, is_stator=True, L1=0.4, Nrvd=2, Wrvd=0.05, ) stator.slot = SlotMPolar( Zs=4, W0=pi / 10, H0=0.02, W3=2 * pi / 50, magnet=[ MagnetType11(Lmag=0.35, Hmag=0.03, Wmag=pi / 10), MagnetType11(Lmag=0.35, Hmag=0.03, Wmag=pi / 10), ], ) stator.mat_type.mag = MatMagnetics(Wlam=0.5e-3) rotor.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 18) fig.savefig(join(save_path, "test_Lam_Mag_11i_2_Mag_2-Rotor.png")) stator.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 10) fig.savefig(join(save_path, "test_Lam_Mag_11i_3_Mag_2-Stator.png"))
def test_save_load_machine(self): """Check that you can save and load a machine object """ # SetUp test_obj = MachineSIPMSM(name="test", desc="test\non\nseveral lines") test_obj.stator = LamSlotWind(L1=0.45) test_obj.stator.slot = SlotW10(Zs=10, H0=0.21, W0=0.23) test_obj.stator.winding = WindingDW1L(qs=5) test_obj.rotor = LamSlotMag(L1=0.55) test_obj.rotor.slot = SlotMPolar(W0=pi / 4) test_obj.rotor.slot.magnet = [MagnetType11(Wmag=pi / 4, Hmag=3)] test_obj.shaft = Shaft(Lshaft=0.65) test_obj.frame = None # Save Test file_path = join(save_dir, "test_machine.json") if isfile(file_path): remove(file_path) self.assertFalse(isfile(file_path)) test_obj.save(file_path) self.assertTrue(isfile(file_path)) # Load Test result = load(file_path) self.assertTrue(type(result) is MachineSIPMSM) self.assertEqual(result.name, "test") self.assertEqual(result.desc, "test\non\nseveral lines") self.assertTrue(type(result.stator) is LamSlotWind) self.assertEqual(result.stator.L1, 0.45) self.assertTrue(type(result.stator.slot) is SlotW10) self.assertEqual(result.stator.slot.Zs, 10) self.assertEqual(result.stator.slot.H0, 0.21) self.assertEqual(result.stator.slot.W0, 0.23) self.assertTrue(type(result.stator.winding) is WindingDW1L) self.assertEqual(result.stator.winding.qs, 5) self.assertTrue(type(result.rotor) is LamSlotMag) self.assertEqual(result.rotor.L1, 0.55) self.assertTrue(type(result.rotor.slot) is SlotMPolar) self.assertEqual(result.rotor.slot.W0, pi / 4) self.assertTrue(type(result.rotor.slot.magnet) is list) self.assertTrue(type(result.rotor.slot.magnet[0]) is MagnetType11) self.assertEqual(len(result.rotor.slot.magnet), 1) self.assertEqual(result.rotor.slot.magnet[0].Wmag, pi / 4) self.assertEqual(result.rotor.slot.magnet[0].Hmag, 3) self.assertTrue(type(result.shaft) is Shaft) self.assertEqual(result.shaft.Lshaft, 0.65) self.assertEqual(result.frame, None)
def test_Lam_Mag_14_inset(self): """Test machine plot with Magnet 14 inset""" plt.close("all") test_obj = Machine() test_obj.rotor = LamSlotMag( Rint=40e-3, Rext=90e-3, is_internal=True, is_stator=False, L1=0.4, Nrvd=5, Wrvd=0.02, ) magnet = [MagnetType14(Lmag=0.5, Hmag=0.02, Wmag=0.628, Rtop=0.04)] test_obj.rotor.slot = SlotMPolar(Zs=4, W0=0.628, H0=0.02, magnet=magnet) test_obj.rotor.mat_type.mag = MatLamination(Wlam=0.5e-3) test_obj.shaft = Shaft(Drsh=test_obj.rotor.Rint * 2, Lshaft=0.55) test_obj.stator = Lamination( Rint=130e-3, Rext=0.2, is_internal=False, is_stator=True, L1=0.4, Nrvd=5, Wrvd=0.02, ) test_obj.stator.mat_type.mag = MatLamination(Wlam=0.5e-3) test_obj.frame = Frame(Rint=200e-3, Rext=250e-3, Lfra=0.5) test_obj.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 11) fig.savefig(join(save_path, "test_Lam_Mag_14i_1-Machine.png")) test_obj.rotor.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 6) fig.savefig(join(save_path, "test_Lam_Mag_14i_2-Rotor.png")) test_obj.stator.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 2) fig.savefig(join(save_path, "test_Lam_Mag_14i_3-Stator.png"))
def test_save_load_dict(self): """Test the save and load function of data structures """ # SetUp test_obj_1 = MachineSIPMSM(name="test", desc="test\non\nseveral lines") test_obj_1.stator = LamSlotWind(L1=0.45) test_obj_1.stator.slot = SlotW10(Zs=10, H0=0.21, W0=0.23) test_obj_1.stator.winding = WindingDW1L(qs=5) test_obj_1.rotor = LamSlotMag(L1=0.55) test_obj_1.rotor.slot = SlotMPolar(W0=pi / 4) test_obj_1.rotor.slot.magnet = [MagnetType11(Wmag=pi / 4, Hmag=3)] test_obj_1.shaft = Shaft(Lshaft=0.65) test_obj_1.frame = None test_obj_2 = LamSlotWind(L1=0.45) test_obj_3 = {"H0": 0.001, "Zs": 10, "__class__": "ClassDoesntExist"} test_obj_4 = tuple([1, 2, 3]) test_dict = { "tuple": test_obj_4, "list": [test_obj_1, None], "dict": {"test_obj_2": test_obj_2, "test_obj_list": [test_obj_3, None]}, } # Save Test file_path = join(save_path, "test_dict.json") if isfile(file_path): remove(file_path) self.assertFalse(isfile(file_path)) save_data(test_dict, file_path) self.assertTrue(isfile(file_path)) # Load Test result_dict = load_dict(file_path) # set tuple to None as save will do test_dict["tuple"] = None self.assertEqual(result_dict, test_dict)
def setUp(self): """Run at the begining of every test to setup the gui""" self.test_obj = MachineSIPMSM(type_machine=7) # IPMSM # For comp_output compatibility self.test_obj.stator = LamSlotWind(Rint=0.95, Rext=0.99) self.test_obj.rotor = LamSlotMag(Rint=0.1, Rext=0.9) self.test_obj.rotor.slot = SlotMPolar(Zs=8, W0=pi / 24, H0=5e-3) self.test_obj.rotor.slot.magnet = [MagnetType11(Wmag=pi / 24, Hmag=3e-3)] self.test_obj.rotor.slot.magnet[0].mat_type.name = "test3" self.matlib = list() self.matlib.append(Material(name="test1")) self.matlib[-1].elec.rho = 0.31 self.matlib.append(Material(name="test2")) self.matlib[-1].elec.rho = 0.32 self.matlib.append(Material(name="test3")) self.matlib[-1].elec.rho = 0.33 self.widget = SMagnet( machine=self.test_obj, matlib=self.matlib, is_stator=False )
def test_build_geometry_out(self): """check that curve_list is correct (outwards magnet)""" lam = LamSlotMag( Rint=40e-3, Rext=90e-3, is_internal=False, is_stator=False, L1=0.45, Nrvd=1, Wrvd=0.05, ) magnet = [MagnetType11(Wmag=pi / 10, Hmag=0.2)] lam.slot = SlotMPolar(Zs=8, W0=pi / 10, H0=0.2, magnet=magnet) test_obj = lam.slot.magnet[0] Z1 = (40e-3 + 0.2) * exp(-1j * pi / 10 / 2) Z2 = (40e-3 + 0.2) * exp(1j * pi / 10 / 2) Z = abs(Z1) Z3 = (Z - 0.2) * exp(1j * angle(Z1)) Z4 = (Z - 0.2) * exp(1j * angle(Z2)) # # Creation of curve curve_list = list() curve_list.append(Segment(Z1, Z3)) curve_list.append(Arc1(Z3, Z4, abs(Z3))) curve_list.append(Segment(Z4, Z2)) curve_list.append(Arc1(Z2, Z1, -abs(Z2))) surface = test_obj.build_geometry() result = surface[0].get_lines() for i in range(0, len(result)): a = result[i].begin b = curve_list[i].begin self.assertAlmostEqual((a - b) / a, 0, delta=DELTA) a = result[i].end b = curve_list[i].end self.assertAlmostEqual((a - b) / a, 0, delta=DELTA)
def test_Lam_Mag_14_inset(self): """Test machine plot with Magnet 14 inset""" plt.close("all") rotor = LamSlotMag( Rint=40e-3, Rext=90e-3, is_internal=True, is_stator=False, L1=0.4, Nrvd=5, Wrvd=0.02, ) magnet = [MagnetType14(Lmag=0.5, Hmag=0.02, Wmag=0.628, Rtop=0.04)] rotor.slot = SlotMPolar(Zs=4, W0=0.628, H0=0.02, magnet=magnet) rotor.mat_type.mag = MatMagnetics(Wlam=0.5e-3) stator = Lamination( Rint=130e-3, Rext=0.2, is_internal=False, is_stator=True, L1=0.4, Nrvd=5, Wrvd=0.02, ) stator.mat_type.mag = MatMagnetics(Wlam=0.5e-3) rotor.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 6) fig.savefig(join(save_path, "test_Lam_Mag_14i_2-Rotor.png")) stator.plot() fig = plt.gcf() self.assertEqual(len(fig.axes[0].patches), 2) fig.savefig(join(save_path, "test_Lam_Mag_14i_3-Stator.png"))
Nwppc_tan=1, Nwppc_rad=1, Wwire=2e-3, Hwire=2e-3, Wins_wire=1e-6, type_winding_shape=0, ) # Rotor setup rotor = LamSlotMag(Rext=0.1, Rint=0.0225, L1=0.4, Kf1=0.95, is_internal=True, is_stator=False, Nrvd=0) rotor.slot = SlotMPolar(Zs=2, W3=0, W0=2.82743338823, H0=0) rotor.slot.magnet = [MagnetType11(Wmag=2.82743338823, Hmag=0.012)] shaft = Shaft(Lshaft=0.442, Drsh=45e-3) frame = None # Set Materials stator.mat_type = M400_50A rotor.mat_type = M400_50A stator.winding.conductor.cond_mat = Copper1 rotor.slot.magnet[0].mat_type = Magnet3 SPMSM_003 = MachineSIPMSM( name="SPMSM_003", desc= "polar SIPMSM with surface magnet from Lubin, S. Mezani, and A. Rezzoug publication",
from unittest import TestCase from ddt import ddt, data from pyleecan.Classes.LamSlotMag import LamSlotMag from pyleecan.Classes.SlotMPolar import SlotMPolar from pyleecan.Classes.MagnetType14 import MagnetType14 from numpy import pi, exp, sqrt from pyleecan.Methods.Machine.Magnet.comp_height import comp_height from pyleecan.Methods.Machine.Magnet.comp_surface import comp_surface Mag14_test = list() # Internal Slot inset lam = LamSlotMag(Rint=40e-3, Rext=90e-3, is_internal=True) lam.slot = SlotMPolar(Zs=4, W0=0.628, H0=0.02) lam.slot.magnet = [MagnetType14(Lmag=0.5, Hmag=0.02, Wmag=0.628, Rtop=0.04)] Mag14_test.append({"test_obj": lam, "S_exp": 9.022e-4, "Ao": 0.628, "H_exp": 0.02}) # Internal slot surface lam = LamSlotMag(Rint=40e-3, Rext=90e-3, is_internal=True) lam.slot = SlotMPolar(Zs=8, W0=0.628, H0=0) lam.slot.magnet = [MagnetType14(Lmag=0.5, Hmag=0.02, Wmag=0.628, Rtop=0.05)] Mag14_test.append({"test_obj": lam, "S_exp": 1.1089e-3, "Ao": 0.628, "H_exp": 0.02}) # For AlmostEqual DELTA = 1e-4 @ddt class test_Magnet_Type_14_meth(TestCase):
stator.winding.conductor = CondType12(Nwppc=1, Wwire=0.0007, Wins_wire=1e-6, Kwoh=0.5) # Rotor setup rotor = LamSlotMag( Rext=0.085, Rint=0.082, L1=0.035, Kf1=0.95, is_internal=False, is_stator=False, Nrvd=0, ) rotor.slot = SlotMPolar(Zs=18, W3=0, W0=0.23529412, H0=0) rotor.slot.magnet = [MagnetType11(Wmag=0.23529412, Hmag=0.002)] shaft = None frame = None # Set Materials stator.mat_type = M400_50A rotor.mat_type = M400_50A stator.winding.conductor.cond_mat = Copper1 rotor.slot.magnet[0].mat_type = Magnet5 SPMSM_015 = MachineSIPMSM( name="SPMSM_015", desc="outer rotor SPMSM Machine B from Vu Xuan Hung thesis", stator=stator,
# Stator setup stator = LamSlotWind( Rint=0.026, Rext=0.048, Nrvd=0, L1=0.09, Kf1=0.96, is_internal=False, is_stator=True ) stator.slot = SlotW22(Zs=6, H0=0.002, H2=0.01, W0=0.44, W2=0.628) stator.winding = WindingCW1L(qs=3, Lewout=0.015, p=2, Ntcoil=42, Npcpp=1) stator.winding.conductor = CondType12( Nwppc=1, Wwire=0.0011283792, Wins_wire=1e-6, Kwoh=0.5 ) # Rotor setup rotor = LamSlotMag( Rext=0.025, Rint=0.005, L1=0.09, Kf1=0.95, is_internal=True, is_stator=False, Nrvd=0 ) rotor.slot = SlotMPolar(Zs=4, W3=0, W0=1.3351769, H0=0.007) rotor.slot.magnet = [MagnetType11(Wmag=1.3351769, Hmag=0.007)] shaft = Shaft(Lshaft=0.442, Drsh=0.01) frame = None # Set Materials stator.mat_type = M400_50A rotor.mat_type = M400_50A stator.winding.conductor.cond_mat = Copper1 rotor.slot.magnet[0].mat_type = Magnet1 SIPMSM_001 = MachineSIPMSM( name="SIPMSM_001", desc="polar SIPMSM with inset magnet from A. Rahideh and T. Korakianitis publication", stator=stator,
machine5.stator = LamSlotWind() machine5.stator.winding = WindingDW2L() machine5.rotor = LamHole() machine5.rotor.hole = list() machine5.rotor.hole.append(HoleM50()) machine5.rotor.hole[0].remove_magnet() machine5._set_None() # Empty machine machine5.type_machine = 5 machine5.stator.is_stator = True machine5.rotor.is_stator = False machine6 = MachineSIPMSM() machine6.stator = LamSlotWind() machine6.stator.winding = WindingDW2L() machine6.rotor = LamSlotMag() machine6.rotor.slot = SlotMPolar() machine6.rotor.slot.magnet = [MagnetType11()] machine6._set_None() # Empty machine machine6.type_machine = 6 machine6.stator.is_stator = True machine6.rotor.is_stator = False machine7 = MachineSIPMSM(init_dict=machine6.as_dict()) machine7.type_machine = 7 machine8 = MachineIPMSM() machine8.stator = LamSlotWind() machine8.stator.winding = WindingDW2L() machine8.rotor = LamHole() machine8.rotor.hole = list() machine8.rotor.hole.append(HoleM50())
from ddt import ddt, data from pyleecan.Classes.Arc1 import Arc1 from pyleecan.Classes.Segment import Segment from pyleecan.Classes.MagnetType11 import MagnetType11 from pyleecan.Classes.LamSlotMag import LamSlotMag from pyleecan.Classes.SlotMPolar import SlotMPolar from numpy import pi, exp, angle, array from pyleecan.Methods.Machine.Magnet.comp_surface import comp_surface Mag11_test = list() # Internal Slot surface lam = LamSlotMag(is_internal=True, Rext=0.5) lam.slot = SlotMPolar(H0=0, W0=pi / 4, Zs=4) lam.slot.magnet = [MagnetType11(Hmag=1, Wmag=pi / 4)] Mag11_test.append({"test_obj": lam, "S_exp": 0.78539616, "Ao": pi / 4, "H_exp": 1}) # Internal Slot inset lam = LamSlotMag(is_internal=True, Rext=0.5) lam.slot = SlotMPolar(H0=40e-3, W0=pi / 4, Zs=4) lam.slot.magnet = [MagnetType11(Hmag=20e-3, Wmag=pi / 4)] Mag11_test.append({"test_obj": lam, "S_exp": 7.3827e-3, "Ao": pi / 4, "H_exp": 20e-3}) # Outward Slot inset lam = LamSlotMag(is_internal=False, Rext=0.1325) lam.slot = SlotMPolar(H0=5e-3, W0=pi / 10, Zs=8) lam.slot.magnet = [MagnetType11(Hmag=8e-3, Wmag=pi / 12)] Mag11_test.append({"test_obj": lam, "S_exp": 2.09439e-6, "Ao": pi / 12, "H_exp": 8e-3})