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)
Exemple #2
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)
    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
        )
Exemple #4
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)
Exemple #5
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",
    stator=stator,
    rotor=rotor,
    shaft=shaft,
    frame=frame,
)
Exemple #6
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)
Exemple #7
0
# 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,
    rotor=rotor,
    shaft=shaft,
    frame=frame,
)
Exemple #8
0
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,
    rotor=rotor,
    shaft=shaft,
    frame=frame,
)
Exemple #9
0
    qs=3, Lewout=15e-3, p=1, Ntcoil=12, 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

SPMSM_003 = MachineSIPMSM(
    name="SPMSM_003", stator=stator, rotor=rotor, shaft=shaft, frame=frame
)
Exemple #10
0
machine4.stator.is_stator = True
machine4.rotor.is_stator = False

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