Exemplo n.º 1
0
    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_13_inset(self):
        """Test machine plot with Magnet 12 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.42,
            Nrvd=4,
            Wrvd=0.02,
        )
        magnet = [MagnetType13(Lmag=0.5, Hmag=0.02, Wmag=0.04, Rtop=0.04)]
        test_obj.rotor.slot = SlotMFlat(Zs=8,
                                        W0=0.04,
                                        H0=0.02,
                                        W3=2 * pi / 64,
                                        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 = LamSlotMag(
            Rint=110e-3,
            Rext=200e-3,
            is_internal=False,
            is_stator=True,
            L1=0.42,
            Nrvd=4,
            Wrvd=0.02,
        )
        magnet2 = [MagnetType13(Lmag=0.5, Hmag=0.02, Wmag=0.04, Rtop=0.04)]
        test_obj.stator.slot = SlotMFlat(Zs=4,
                                         W0=0.04,
                                         H0=0.025,
                                         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=250e-3, Lfra=0.5)

        test_obj.plot()
        fig = plt.gcf()
        self.assertEqual(len(fig.axes[0].patches), 19)
        fig.savefig(join(save_path, "test_Lam_Mag_13i_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_13i_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_13i_3-Stator.png"))
Exemplo n.º 3
0
    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"))
Exemplo n.º 4
0
    def test_Lam_Mag_10_inset(self):
        """Test machine plot with Magnet 10 inset"""

        plt.close("all")
        rotor = LamSlotMag(
            Rint=40e-3,
            Rext=100e-3,
            is_internal=True,
            is_stator=False,
            L1=0.45,
            Nrvd=1,
            Wrvd=0.05,
        )
        magnet = [MagnetType10(Lmag=0.5, Hmag=0.02, Wmag=0.04)]
        rotor.slot = SlotMFlat(Zs=4, W0=0.04, H0=0.02, magnet=magnet)
        rotor.mat_type.mag = MatMagnetics(Wlam=0.5e-3)

        rotor.axial_vent.append(VentilationCirc(Zh=4, Alpha0=0, D0=2.5e-3, H0=50e-3))
        rotor.axial_vent.append(VentilationCirc(Zh=8, Alpha0=0, D0=5e-3, H0=60e-3))
        rotor.axial_vent.append(VentilationCirc(Zh=12, Alpha0=0, D0=10e-3, H0=70e-3))

        stator = LamSlotMag(
            Rint=110e-3,
            Rext=200e-3,
            is_internal=False,
            is_stator=True,
            L1=0.45,
            Nrvd=1,
            Wrvd=0.05,
        )

        magnet2 = [MagnetType10(Lmag=0.5, Hmag=0.02, Wmag=0.04)]
        stator.slot = SlotMFlat(Zs=8, W0=0.04, W3=2 * pi / 64, H0=0.02, magnet=magnet2)
        stator.mat_type.mag = MatMagnetics(Wlam=0.5e-3)

        stator.axial_vent.append(
            VentilationTrap(Zh=6, Alpha0=pi / 6, W1=10e-3, W2=20e-3, D0=0.02, H0=0.140)
        )
        stator.axial_vent.append(
            VentilationTrap(Zh=6, Alpha0=pi / 6, W1=20e-3, W2=40e-3, D0=0.02, H0=0.170)
        )

        rotor.plot()
        fig = plt.gcf()
        self.assertEqual(len(fig.axes[0].patches), 30)
        fig.savefig(join(save_path, "test_Lam_Mag_10i_2-Rotor.png"))

        stator.plot()
        fig = plt.gcf()
        self.assertEqual(len(fig.axes[0].patches), 22)
        fig.savefig(join(save_path, "test_Lam_Mag_10i_3-Stator.png"))
Exemplo n.º 5
0
    def test_Lam_Mag_10_surface(self):
        """Test machine plot with Magnet 10 surface"""

        plt.close("all")
        rotor = LamSlotMag(
            Rint=40e-3,
            Rext=200e-3,
            is_internal=True,
            is_stator=False,
            L1=0.5,
            Nrvd=0,
            Wrvd=0.05,
        )
        magnet = [MagnetType10(Lmag=0.5, Hmag=0.02, Wmag=0.08)]
        rotor.slot = SlotMFlat(Zs=8,
                               H0=0,
                               W0=2 * pi / 10,
                               W0_is_rad=True,
                               magnet=magnet)
        rotor.mat_type.mag = MatMagnetics(Wlam=0.5e-3)

        rotor.plot()
        fig = plt.gcf()
        self.assertEqual(len(fig.axes[0].patches), 10)
        fig.savefig(join(save_path, "test_Lam_Mag_10s_2-Rotor.png"))

        magnet2 = [MagnetType10(Lmag=0.5, Hmag=0.02, Wmag=0.04)]
        rotor.slot = SlotMFlat(Zs=8, W0=0.04, W0_is_rad=False, magnet=magnet2)
        rotor.plot()
        fig = plt.gcf()
        fig.savefig(join(save_path, "test_Lam_Mag_10s_5-Rotor 2.png"))
Exemplo n.º 6
0
    def test_Lam_Mag_10_surface(self):
        """Test machine plot with Magnet 10 surface"""

        plt.close("all")
        test_obj = Machine()
        test_obj.rotor = LamSlotMag(
            Rint=40e-3,
            Rext=200e-3,
            is_internal=True,
            is_stator=False,
            L1=0.5,
            Nrvd=0,
            Wrvd=0.05,
        )
        magnet = [MagnetType10(Lmag=0.5, Hmag=0.02, Wmag=0.08)]
        test_obj.rotor.slot = SlotMFlat(Zs=8,
                                        H0=0,
                                        W0=2 * pi / 10,
                                        W0_is_rad=True,
                                        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 = Lamination(
            Rint=230e-3,
            Rext=0.3,
            is_internal=False,
            is_stator=True,
            L1=0.5,
            Nrvd=0,
            Wrvd=0.05,
        )
        test_obj.stator.mat_type.magnetics = 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), 15)
        fig.savefig(join(save_path, "test_Lam_Mag_10s_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_10s_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_10s_3-Stator.png"))

        magnet2 = [MagnetType10(Lmag=0.5, Hmag=0.02, Wmag=0.04)]
        test_obj.rotor.slot = SlotMFlat(Zs=8,
                                        W0=0.04,
                                        W0_is_rad=False,
                                        magnet=magnet2)
        test_obj.plot()
        fig = plt.gcf()
        fig.savefig(join(save_path, "test_Lam_Mag_10s_5-Rotor 2.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_build_geometry_out(self):
        """check that curve_list is correct (outwards magnet)
        """

        lam = LamSlotMag(
            Rint=1,
            Rext=0.09,
            is_internal=False,
            is_stator=False,
            L1=0.45,
            Nrvd=1,
            Wrvd=0.05,
        )
        lam.slot = SlotMFlat(Zs=8,
                             W0=0.6,
                             H0=0.2,
                             magnet=[MagnetType10(Wmag=0.6, Hmag=0.2)])
        test_obj = lam.slot.magnet[0]
        alpha = lam.slot.comp_angle_opening_magnet()
        Z1 = 1 * exp(-1j * alpha / 2) + 0.2
        Z2 = 1 * exp(1j * alpha / 2) + 0.2
        Z3 = Z1 - 0.2
        Z4 = Z2 - 0.2

        # Creation of curve
        curve_list = list()
        curve_list.append(Segment(Z1, Z3))
        curve_list.append(Segment(Z3, Z4))
        curve_list.append(Segment(Z4, Z2))
        curve_list.append(Segment(Z2, Z1))

        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)
Exemplo n.º 9
0
    def test_Lam_Mag_13_inset(self):
        """Test machine plot with Magnet 12 inset"""

        plt.close("all")
        rotor = LamSlotMag(
            Rint=40e-3,
            Rext=90e-3,
            is_internal=True,
            is_stator=False,
            L1=0.42,
            Nrvd=4,
            Wrvd=0.02,
        )
        magnet = [MagnetType13(Lmag=0.5, Hmag=0.02, Wmag=0.04, Rtop=0.04)]
        rotor.slot = SlotMFlat(Zs=8, W0=0.04, H0=0.02, W3=2 * pi / 64, magnet=magnet)
        rotor.mat_type.mag = MatMagnetics(Wlam=0.5e-3)

        stator = LamSlotMag(
            Rint=110e-3,
            Rext=200e-3,
            is_internal=False,
            is_stator=True,
            L1=0.42,
            Nrvd=4,
            Wrvd=0.02,
        )
        magnet2 = [MagnetType13(Lmag=0.5, Hmag=0.02, Wmag=0.04, Rtop=0.04)]
        stator.slot = SlotMFlat(Zs=4, W0=0.04, H0=0.025, W3=2 * pi / 64, magnet=magnet2)
        stator.mat_type.mag = MatMagnetics(Wlam=0.5e-3)

        rotor.plot()
        fig = plt.gcf()
        self.assertEqual(len(fig.axes[0].patches), 10)
        fig.savefig(join(save_path, "test_Lam_Mag_13i_2-Rotor.png"))

        stator.plot()
        fig = plt.gcf()
        self.assertEqual(len(fig.axes[0].patches), 6)
        fig.savefig(join(save_path, "test_Lam_Mag_13i_3-Stator.png"))
    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)
Exemplo n.º 11
0
    def test_Lam_Mag_12_surface(self):
        """Test machine plot with Magnet 12 surface"""

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

        magnet = [MagnetType12(Lmag=0.5, Hmag=0.02, Wmag=0.06)]
        rotor.slot = SlotMFlat(Zs=8, W0=0.06, 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=2,
            Wrvd=0.05,
        )
        stator.mat_type.mag = MatMagnetics(Wlam=0.5e-3)

        rotor.plot()
        fig = plt.gcf()
        self.assertEqual(len(fig.axes[0].patches), 10)
        fig.savefig(join(save_path, "test_Lam_Mag_12s_2-Rotor.png"))

        stator.plot()
        fig = plt.gcf()
        self.assertEqual(len(fig.axes[0].patches), 2)
        fig.savefig(join(save_path, "test_Lam_Mag_12s_3-Stator.png"))
Exemplo n.º 12
0
    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"))
    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.magnetics = 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.magnetics = 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"))
Exemplo n.º 14
0
    def test_set_p_sipmsm(self):
        """Check that the Widget allow to update p"""
        self.test_obj = MachineSIPMSM(name="test_machine_ipmsm", type_machine=7)
        self.test_obj.stator = LamSlotWind(
            is_stator=True, is_internal=True, Rint=0.21, Rext=0.22
        )
        self.test_obj.rotor = LamSlotMag(
            is_stator=False, is_internal=False, Rint=0.11, Rext=0.12
        )
        self.widget = SMachineType(machine=self.test_obj, matlib=[], is_stator=False)

        # Clear the field before writing the new value
        self.widget.si_p.clear()
        value = int(uniform(3, 100))
        QTest.keyClicks(self.widget.si_p, str(value))
        self.widget.si_p.editingFinished.emit()  # To trigger the slot

        self.assertEqual(self.test_obj.stator.winding.p, value)
        self.assertEqual(self.test_obj.rotor.slot.Zs, 2 * value)
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
    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
        )
Exemplo n.º 17
0
"""

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
Exemplo n.º 18
0
                             Npcpp=1,
                             Nslot_shift_wind=0)

stator.winding.conductor = CondType11(
    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
Exemplo n.º 19
0
    def test_init(self):
        """Check that the Widget spinbox initialise to the lamination value"""

        self.assertEqual(self.widget.le_name.text(), "test_machine")
        self.assertEqual(self.widget.si_p.value(), 6)
        self.assertEqual(self.widget.c_type.currentIndex(), 0)
        self.assertEqual(self.widget.c_type.currentText(), "SCIM")
        self.assertEqual(self.widget.is_inner_rotor.checkState(), Qt.Checked)

        # DFIM
        self.test_obj = MachineDFIM(name="test_machine_dfim", type_machine=4)
        self.test_obj.stator = LamSlotWind(
            is_stator=True, is_internal=True, Rint=0.21, Rext=0.22
        )
        self.test_obj.stator.winding.p = 7
        self.test_obj.rotor = LamSlotWind(
            is_stator=False, is_internal=False, Rint=0.11, Rext=0.12
        )
        self.widget = SMachineType(machine=self.test_obj, matlib=[], is_stator=False)

        self.assertEqual(self.widget.le_name.text(), "test_machine_dfim")
        self.assertEqual(self.widget.si_p.value(), 7)
        self.assertEqual(self.widget.c_type.currentIndex(), 1)
        self.assertEqual(self.widget.c_type.currentText(), "DFIM")
        self.assertEqual(self.widget.is_inner_rotor.checkState(), Qt.Unchecked)

        # SyRM
        self.test_obj = MachineSyRM(name="test_machine_syrm", type_machine=5)
        self.test_obj.stator = LamSlotWind(
            is_stator=True, is_internal=True, Rint=0.21, Rext=0.22
        )
        self.test_obj.stator.winding.p = 21
        self.test_obj.rotor = LamSlotMag(
            is_stator=False, is_internal=False, Rint=0.11, Rext=0.12
        )
        self.widget = SMachineType(machine=self.test_obj, matlib=[], is_stator=False)

        self.assertEqual(self.widget.le_name.text(), "test_machine_syrm")
        self.assertEqual(self.widget.si_p.value(), 21)
        self.assertEqual(self.widget.c_type.currentIndex(), 2)
        self.assertEqual(self.widget.c_type.currentText(), "SyRM")
        self.assertEqual(self.widget.is_inner_rotor.checkState(), Qt.Unchecked)

        # SPMSM
        self.test_obj = MachineSIPMSM(name="test_machine_spmsm", type_machine=6)
        self.test_obj.stator = LamSlotWind(
            is_stator=True, is_internal=True, Rint=0.21, Rext=0.22
        )
        self.test_obj.stator.winding.p = 8
        self.test_obj.rotor = LamSlotMag(
            is_stator=False, is_internal=False, Rint=0.11, Rext=0.12
        )
        self.widget = SMachineType(machine=self.test_obj, matlib=[], is_stator=False)

        self.assertEqual(self.widget.le_name.text(), "test_machine_spmsm")
        self.assertEqual(self.widget.si_p.value(), 8)
        self.assertEqual(self.widget.c_type.currentIndex(), 3)
        self.assertEqual(self.widget.c_type.currentText(), "SPMSM")
        self.assertEqual(self.widget.is_inner_rotor.checkState(), Qt.Unchecked)

        # SIPMSM
        self.test_obj = MachineSIPMSM(name="test_machine_sipmsm", type_machine=7)
        self.test_obj.stator = LamSlotWind(
            is_stator=True, is_internal=False, Rint=0.21, Rext=0.22
        )
        self.test_obj.stator.winding.p = 9
        self.test_obj.rotor = LamSlotMag(
            is_stator=False, is_internal=True, Rint=0.11, Rext=0.12
        )
        self.widget = SMachineType(machine=self.test_obj, matlib=[], is_stator=False)

        self.assertEqual(self.widget.le_name.text(), "test_machine_sipmsm")
        self.assertEqual(self.widget.si_p.value(), 9)
        self.assertEqual(self.widget.c_type.currentIndex(), 4)
        self.assertEqual(self.widget.c_type.currentText(), "SIPMSM")
        self.assertEqual(self.widget.is_inner_rotor.checkState(), Qt.Checked)

        # IPMSM
        self.test_obj = MachineIPMSM(name="test_machine_ipmsm", type_machine=8)
        self.test_obj.stator = LamSlotWind(
            is_stator=True, is_internal=True, Rint=0.21, Rext=0.22
        )
        self.test_obj.stator.winding.p = 10
        self.test_obj.rotor = LamSlotMag(
            is_stator=False, is_internal=False, Rint=0.11, Rext=0.12
        )
        self.widget = SMachineType(machine=self.test_obj, matlib=[], is_stator=False)

        self.assertEqual(self.widget.le_name.text(), "test_machine_ipmsm")
        self.assertEqual(self.widget.si_p.value(), 10)
        self.assertEqual(self.widget.c_type.currentIndex(), 5)
        self.assertEqual(self.widget.c_type.currentText(), "IPMSM")
        self.assertEqual(self.widget.is_inner_rotor.checkState(), Qt.Unchecked)

        # WRSM
        self.test_obj = MachineWRSM(name="test_machine_wrsm", type_machine=9)
        self.test_obj.stator = LamSlotWind(
            is_stator=True, is_internal=True, Rint=0.21, Rext=0.22
        )
        self.test_obj.stator.winding.p = 5
        self.test_obj.rotor = LamSlotWind(
            is_stator=False, is_internal=False, Rint=0.11, Rext=0.12
        )
        self.widget = SMachineType(machine=self.test_obj, matlib=[], is_stator=False)

        self.assertEqual(self.widget.le_name.text(), "test_machine_wrsm")
        self.assertEqual(self.widget.si_p.value(), 5)
        self.assertEqual(self.widget.c_type.currentIndex(), 6)
        self.assertEqual(self.widget.c_type.currentText(), "WRSM")
        self.assertEqual(self.widget.is_inner_rotor.checkState(), Qt.Unchecked)
Exemplo n.º 20
0
machine5 = MachineSyRM()
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()
Exemplo n.º 21
0
from pyleecan.Tests.Validation.Material.Copper1 import Copper1

# 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",
Exemplo n.º 22
0
                              Lewout=15e-3,
                              p=9,
                              Ntcoil=57,
                              Npcpp=3,
                              Nslot_shift_wind=0)

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
from unittest import TestCase

from ddt import ddt, data

from pyleecan.Classes.LamSlotMag import LamSlotMag
from pyleecan.Classes.SlotMFlat import SlotMFlat
from pyleecan.Classes.MagnetType10 import MagnetType10
from pyleecan.Classes.Segment import Segment
from pyleecan.Methods.Machine.Magnet.comp_surface import comp_surface

from numpy import exp

Mag10_test = list()
# Internal Slot
lam = LamSlotMag(is_internal=True, Rext=0.1325)
lam.slot = SlotMFlat(H0=5e-3, W0=10e-3, Zs=12)
lam.slot.magnet = [MagnetType10(Hmag=5e-3, Wmag=10e-3)]
Mag10_test.append({
    "test_obj": lam,
    "S_exp": 5e-5,
    "Ao": 0.078449,
    "H_exp": 5e-3
})

# Outward Slot
lam = LamSlotMag(is_internal=False, Rint=0.1325)
lam.slot = SlotMFlat(H0=5e-3, W0=10e-3, Zs=12)
lam.slot.magnet = [MagnetType10(Hmag=5e-3, Wmag=10e-3)]
Mag10_test.append({
    "test_obj": lam,
Exemplo n.º 24
0
    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")
        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)
        test_obj.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),
            ],
        )
        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,
        )
        test_obj.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),
            ],
        )
        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), 31)
        fig.savefig(join(save_path, "test_Lam_Mag_11i_1_Mag_2-Machine.png"))

        test_obj.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"))

        test_obj.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"))
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})
Exemplo n.º 26
0
class MachineSIPMSM(MachineSync):
    """Inset and Surface Permanent Magnet Synchronous Machine"""

    VERSION = 1

    # Check ImportError to remove unnecessary dependencies in unused method
    # cf Methods.Machine.MachineSIPMSM.check
    if isinstance(check, ImportError):
        check = property(
            fget=lambda x: raise_(
                ImportError("Can't use MachineSIPMSM method check: " + str(check))
            )
        )
    else:
        check = check
    # cf Methods.Machine.MachineSIPMSM.get_machine_type
    if isinstance(get_machine_type, ImportError):
        get_machine_type = property(
            fget=lambda x: raise_(
                ImportError(
                    "Can't use MachineSIPMSM method get_machine_type: "
                    + str(get_machine_type)
                )
            )
        )
    else:
        get_machine_type = get_machine_type
    # save method is available in all object
    save = save

    def __init__(
        self,
        rotor=-1,
        stator=-1,
        frame=-1,
        shaft=-1,
        name="default_machine",
        desc="",
        type_machine=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 rotor == -1:
            rotor = LamSlotMag()
        if stator == -1:
            stator = LamSlotWind()
        if frame == -1:
            frame = Frame()
        if shaft == -1:
            shaft = Shaft()
        if init_dict is not None:  # Initialisation by dict
            check_init_dict(
                init_dict,
                ["rotor", "stator", "frame", "shaft", "name", "desc", "type_machine"],
            )
            # Overwrite default value with init_dict content
            if "rotor" in list(init_dict.keys()):
                rotor = init_dict["rotor"]
            if "stator" in list(init_dict.keys()):
                stator = init_dict["stator"]
            if "frame" in list(init_dict.keys()):
                frame = init_dict["frame"]
            if "shaft" in list(init_dict.keys()):
                shaft = init_dict["shaft"]
            if "name" in list(init_dict.keys()):
                name = init_dict["name"]
            if "desc" in list(init_dict.keys()):
                desc = init_dict["desc"]
            if "type_machine" in list(init_dict.keys()):
                type_machine = init_dict["type_machine"]
        # Initialisation by argument
        # rotor can be None, a LamSlotMag object or a dict
        if isinstance(rotor, dict):
            self.rotor = LamSlotMag(init_dict=rotor)
        else:
            self.rotor = rotor
        # stator can be None, a LamSlotWind object or a dict
        if isinstance(stator, dict):
            # Check that the type is correct (including daughter)
            class_name = stator.get("__class__")
            if class_name not in ["LamSlotWind", "LamSquirrelCage"]:
                raise InitUnKnowClassError(
                    "Unknow class name " + class_name + " in init_dict for stator"
                )
            # Dynamic import to call the correct constructor
            module = __import__("pyleecan.Classes." + class_name, fromlist=[class_name])
            class_obj = getattr(module, class_name)
            self.stator = class_obj(init_dict=stator)
        else:
            self.stator = stator
        # Call MachineSync init
        super(MachineSIPMSM, self).__init__(
            frame=frame, shaft=shaft, name=name, desc=desc, type_machine=type_machine
        )
        # The class is frozen (in MachineSync init), for now it's impossible to
        # add new properties

    def __str__(self):
        """Convert this objet in a readeable string (for print)"""

        MachineSIPMSM_str = ""
        # Get the properties inherited from MachineSync
        MachineSIPMSM_str += super(MachineSIPMSM, self).__str__()
        if self.rotor is not None:
            tmp = self.rotor.__str__().replace(linesep, linesep + "\t").rstrip("\t")
            MachineSIPMSM_str += "rotor = " + tmp
        else:
            MachineSIPMSM_str += "rotor = None" + linesep + linesep
        if self.stator is not None:
            tmp = self.stator.__str__().replace(linesep, linesep + "\t").rstrip("\t")
            MachineSIPMSM_str += "stator = " + tmp
        else:
            MachineSIPMSM_str += "stator = None" + linesep + linesep
        return MachineSIPMSM_str

    def __eq__(self, other):
        """Compare two objects (skip parent)"""

        if type(other) != type(self):
            return False

        # Check the properties inherited from MachineSync
        if not super(MachineSIPMSM, self).__eq__(other):
            return False
        if other.rotor != self.rotor:
            return False
        if other.stator != self.stator:
            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 MachineSync
        MachineSIPMSM_dict = super(MachineSIPMSM, self).as_dict()
        if self.rotor is None:
            MachineSIPMSM_dict["rotor"] = None
        else:
            MachineSIPMSM_dict["rotor"] = self.rotor.as_dict()
        if self.stator is None:
            MachineSIPMSM_dict["stator"] = None
        else:
            MachineSIPMSM_dict["stator"] = self.stator.as_dict()
        # The class name is added to the dict fordeserialisation purpose
        # Overwrite the mother class name
        MachineSIPMSM_dict["__class__"] = "MachineSIPMSM"
        return MachineSIPMSM_dict

    def _set_None(self):
        """Set all the properties to None (except pyleecan object)"""

        if self.rotor is not None:
            self.rotor._set_None()
        if self.stator is not None:
            self.stator._set_None()
        # Set to None the properties inherited from MachineSync
        super(MachineSIPMSM, self)._set_None()

    def _get_rotor(self):
        """getter of rotor"""
        return self._rotor

    def _set_rotor(self, value):
        """setter of rotor"""
        check_var("rotor", value, "LamSlotMag")
        self._rotor = value

        if self._rotor is not None:
            self._rotor.parent = self

    # Machine's Rotor
    # Type : LamSlotMag
    rotor = property(fget=_get_rotor, fset=_set_rotor, doc=u"""Machine's Rotor""")

    def _get_stator(self):
        """getter of stator"""
        return self._stator

    def _set_stator(self, value):
        """setter of stator"""
        check_var("stator", value, "LamSlotWind")
        self._stator = value

        if self._stator is not None:
            self._stator.parent = self

    # Machine's Stator
    # Type : LamSlotWind
    stator = property(fget=_get_stator, fset=_set_stator, doc=u"""Machine's Stator""")
Exemplo n.º 27
0
    def __init__(
        self,
        rotor=-1,
        stator=-1,
        frame=-1,
        shaft=-1,
        name="default_machine",
        desc="",
        type_machine=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 rotor == -1:
            rotor = LamSlotMag()
        if stator == -1:
            stator = LamSlotWind()
        if frame == -1:
            frame = Frame()
        if shaft == -1:
            shaft = Shaft()
        if init_dict is not None:  # Initialisation by dict
            check_init_dict(
                init_dict,
                ["rotor", "stator", "frame", "shaft", "name", "desc", "type_machine"],
            )
            # Overwrite default value with init_dict content
            if "rotor" in list(init_dict.keys()):
                rotor = init_dict["rotor"]
            if "stator" in list(init_dict.keys()):
                stator = init_dict["stator"]
            if "frame" in list(init_dict.keys()):
                frame = init_dict["frame"]
            if "shaft" in list(init_dict.keys()):
                shaft = init_dict["shaft"]
            if "name" in list(init_dict.keys()):
                name = init_dict["name"]
            if "desc" in list(init_dict.keys()):
                desc = init_dict["desc"]
            if "type_machine" in list(init_dict.keys()):
                type_machine = init_dict["type_machine"]
        # Initialisation by argument
        # rotor can be None, a LamSlotMag object or a dict
        if isinstance(rotor, dict):
            self.rotor = LamSlotMag(init_dict=rotor)
        else:
            self.rotor = rotor
        # stator can be None, a LamSlotWind object or a dict
        if isinstance(stator, dict):
            # Check that the type is correct (including daughter)
            class_name = stator.get("__class__")
            if class_name not in ["LamSlotWind", "LamSquirrelCage"]:
                raise InitUnKnowClassError(
                    "Unknow class name " + class_name + " in init_dict for stator"
                )
            # Dynamic import to call the correct constructor
            module = __import__("pyleecan.Classes." + class_name, fromlist=[class_name])
            class_obj = getattr(module, class_name)
            self.stator = class_obj(init_dict=stator)
        else:
            self.stator = stator
        # Call MachineSync init
        super(MachineSIPMSM, self).__init__(
            frame=frame, shaft=shaft, name=name, desc=desc, type_machine=type_machine
        )
Exemplo n.º 28
0
    def test_Lam_Mag_10_inset_2_mag(self):
        """Test machine plot with Magnet 10 inset with two magnet in the slot"""
        plt.close("all")
        test_obj = Machine()
        test_obj.rotor = LamSlotMag(
            Rint=40e-3,
            Rext=100e-3,
            is_internal=True,
            is_stator=False,
            L1=0.45,
            Nrvd=1,
            Wrvd=0.05,
        )
        test_obj.rotor.slot = SlotMFlat(
            Zs=4,
            W0=0.03,
            H0=0.02,
            W3=2 * pi / 60,
            magnet=[
                MagnetType10(Lmag=0.5, Hmag=0.015, Wmag=0.03),
                MagnetType10(Lmag=0.5, Hmag=0.015, Wmag=0.03),
            ],
        )
        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.rotor.axial_vent.append(
            VentilationCirc(Zh=4, Alpha0=0, D0=2.5e-3, H0=50e-3))
        test_obj.rotor.axial_vent.append(
            VentilationCirc(Zh=8, Alpha0=0, D0=5e-3, H0=60e-3))
        test_obj.rotor.axial_vent.append(
            VentilationCirc(Zh=12, Alpha0=0, D0=10e-3, H0=70e-3))
        test_obj.stator = LamSlotMag(
            Rint=110e-3,
            Rext=200e-3,
            is_internal=False,
            is_stator=True,
            L1=0.45,
            Nrvd=1,
            Wrvd=0.05,
        )

        test_obj.stator.slot = SlotMFlat(
            Zs=8,
            W0=0.03,
            W3=2 * pi / 64,
            H0=0.02,
            magnet=[
                MagnetType10(Lmag=0.5, Hmag=0.025, Wmag=0.03),
                MagnetType10(Lmag=0.5, Hmag=0.025, Wmag=0.03),
            ],
        )
        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.stator.axial_vent.append(
            VentilationTrap(Zh=6,
                            Alpha0=pi / 6,
                            W1=10e-3,
                            W2=20e-3,
                            D0=0.02,
                            H0=0.140))
        test_obj.stator.axial_vent.append(
            VentilationTrap(Zh=6,
                            Alpha0=pi / 6,
                            W1=20e-3,
                            W2=40e-3,
                            D0=0.02,
                            H0=0.170))
        test_obj.plot()
        fig = plt.gcf()
        self.assertEqual(len(fig.axes[0].patches), 67)
        fig.savefig(join(save_path, "test_Lam_Mag_10i_1_Mag_2-Machine.png"))

        test_obj.rotor.plot()
        fig = plt.gcf()
        self.assertEqual(len(fig.axes[0].patches), 34)
        fig.savefig(join(save_path, "test_Lam_Mag_10i_2_Mag_2-Rotor.png"))

        test_obj.stator.plot()
        fig = plt.gcf()
        self.assertEqual(len(fig.axes[0].patches), 30)
        fig.savefig(join(save_path, "test_Lam_Mag_10i_3_Mag_2-Stator.png"))