Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NF] Ring Magnet in FEMM #462

Merged
merged 18 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
732 changes: 0 additions & 732 deletions Tests/Data/Retrocompatibility/Magnet/SPMSM_001.json

This file was deleted.

37 changes: 37 additions & 0 deletions Tests/Data/test_surf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"__class__": "SurfLine",
"__save_date__": "2021_10_21 21h09min23s ",
"__version__": "pyleecan_1.3.6",
"label": "Slot",
"line_list": [
{
"__class__": "Arc1",
"begin": "(0.08199945121767584-0.00030000000000000003j)",
"end": "(0.08259945121767584+8.131516293641283e-20j)",
"is_trigo_direction": true,
"prop_dict": {
"IS_DRAW": false
},
"radius": 0.00037499999999999985
},
{
"__class__": "Arc1",
"begin": "(0.08259945121767584+8.131516293641283e-20j)",
"end": "(0.08199945121767584+0.00030000000000000003j)",
"is_trigo_direction": true,
"prop_dict": {
"IS_DRAW": false
},
"radius": 0.00037499999999999985
},
{
"__class__": "Arc1",
"begin": "(0.08199945121767584+0.00030000000000000003j)",
"end": "(0.08199945121767584-0.00030000000000000003j)",
"is_trigo_direction": false,
"prop_dict": null,
"radius": -0.082
}
],
"point_ref": "(0.0822614375439922+2.349104707051926e-19j)"
}
28 changes: 0 additions & 28 deletions Tests/Functions/test_retrocompatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@
}
)

# 1: LamSlotMag convertion (magnet from slot to lamination)
mag_list = list()
mag_list.append(
{
"ref": join(DATA_DIR, "Machine", "SPMSM_001.json"),
"old": join(TEST_DATA_DIR, "Retrocompatibility", "Magnet", "SPMSM_001.json"),
}
)


@pytest.mark.parametrize("file_dict", hole_list)
def test_save_load_hole_retro(file_dict):
Expand All @@ -84,23 +75,6 @@ def test_save_load_hole_retro(file_dict):
assert hole_ref == hole_old, msg


@pytest.mark.parametrize("file_dict", mag_list)
def test_save_load_mag_retro(file_dict):
"""Check that the LamSlotMag convertion works"""
ref = load(file_dict["ref"])
old = load(file_dict["old"])

# Don't track material update
ref.rotor.mat_type = None
ref.rotor.magnet.mat_type = None
old.rotor.mat_type = None
old.rotor.magnet.mat_type = None

# Check old file is converted to current version
msg = "Error for " + ref.name + ": " + str(ref.rotor.compare(old.rotor, "rotor"))
assert ref.rotor == old.rotor, msg


@pytest.mark.parametrize("file_dict", wind_list)
def test_save_load_wind_retro(file_dict):
"""Check that the winding convertion works (convert to WindingUD instead of Winding)"""
Expand Down Expand Up @@ -133,8 +107,6 @@ def test_save_load_wind_retro(file_dict):
if __name__ == "__main__":
for file_dict in hole_list:
test_save_load_hole_retro(file_dict)
for file_dict in mag_list:
test_save_load_mag_retro(file_dict)

for file_dict in wind_list:
test_save_load_wind_retro(file_dict)
Expand Down
Empty file.
126 changes: 126 additions & 0 deletions Tests/GUI/DMachineSetup/PMSlot/test_PMSlot10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# -*- coding: utf-8 -*-

import sys

from PySide2 import QtWidgets
from PySide2.QtTest import QTest
from numpy import pi
from Tests.GUI import gui_option # Set unit as [m]
from pyleecan.Classes.LamSlotMag import LamSlotMag
from pyleecan.Classes.SlotM10 import SlotM10
from pyleecan.GUI.Dialog.DMachineSetup.SMSlot.PMSlot10.PMSlot10 import PMSlot10


import pytest


class TestPMSlot10(object):
"""Test that the widget PMSlot10 behave like it should"""

def setup_method(self):
self.test_obj = LamSlotMag(Rint=0.1, Rext=0.2)
self.test_obj.slot = SlotM10(H0=0.10, W0=0.13, Wmag=0.14, Hmag=0.15)
self.widget = PMSlot10(self.test_obj)

@classmethod
def setup_class(cls):
"""Start the app for the test"""
print("\nStart Test TestPMSlot10")
if not QtWidgets.QApplication.instance():
cls.app = QtWidgets.QApplication(sys.argv)
else:
cls.app = QtWidgets.QApplication.instance()

@classmethod
def teardown_class(cls):
"""Exit the app after the test"""
cls.app.quit()

def test_init(self):
"""Check that the Widget spinbox initialise to the lamination value"""

assert self.widget.lf_H0.value() == 0.10
assert self.widget.lf_Hmag.value() == 0.15
assert self.widget.lf_W0.value() == 0.13
assert self.widget.lf_Wmag.value() == 0.14

def test_set_W0(self):
"""Check that the Widget allow to update W0"""
# Check Unit
assert self.widget.unit_W0.text() == "[m]"
# Change value in GUI
self.widget.lf_W0.clear()
QTest.keyClicks(self.widget.lf_W0, "0.31")
self.widget.lf_W0.editingFinished.emit() # To trigger the slot

assert self.widget.slot.W0 == 0.31
assert self.test_obj.slot.W0 == 0.31

def test_set_Wmag(self):
"""Check that the Widget allow to update Wmag"""
# Check Unit
assert self.widget.unit_Wmag.text() == "[m]"
# Change value in GUI
self.widget.lf_Wmag.clear()
QTest.keyClicks(self.widget.lf_Wmag, "0.33")
self.widget.lf_Wmag.editingFinished.emit() # To trigger the slot

assert self.widget.slot.Wmag == 0.33
assert self.test_obj.slot.Wmag == 0.33

def test_set_H0(self):
"""Check that the Widget allow to update H0"""
# Check Unit
assert self.widget.unit_H0.text() == "[m]"
# Change value in GUI
self.widget.lf_H0.clear()
QTest.keyClicks(self.widget.lf_H0, "0.34")
self.widget.lf_H0.editingFinished.emit() # To trigger the slot

assert self.widget.slot.H0 == 0.34
assert self.test_obj.slot.H0 == 0.34

def test_set_Hmag(self):
"""Check that the Widget allow to update Hmag"""
# Check Unit
assert self.widget.unit_Hmag.text() == "[m]"
# Change value in GUI
self.widget.lf_Hmag.clear()
QTest.keyClicks(self.widget.lf_Hmag, "0.36")
self.widget.lf_Hmag.editingFinished.emit() # To trigger the slot

assert self.widget.slot.Hmag == pytest.approx(0.36)
assert self.test_obj.slot.Hmag == pytest.approx(0.36)

def test_output_txt(self):
"""Check that the Output text is computed and correct"""
self.test_obj.slot = SlotM10(H0=0.005, Hmag=0.005, W0=0.01, Wmag=0.01)
self.widget = PMSlot10(self.test_obj)
assert self.widget.w_out.out_slot_height.text() == "Slot height: 0.005063 [m]"

def test_check(self):
"""Check that the check is working correctly"""
self.test_obj = LamSlotMag(Rint=0.1, Rext=0.2)
# H0
self.test_obj.slot = SlotM10(H0=None, Hmag=0.10, W0=0.10, Wmag=0.10)
self.widget = PMSlot10(self.test_obj)
assert self.widget.check(self.test_obj) == "You must set H0 !"
# Hmag
self.test_obj.slot = SlotM10(H0=0.10, Hmag=None, W0=0.10, Wmag=0.10)
assert self.widget.check(self.test_obj) == "You must set Hmag !"
# W0
self.test_obj.slot = SlotM10(H0=0.10, Hmag=0.10, W0=None, Wmag=0.10)
assert self.widget.check(self.test_obj) == "You must set W0 !"
# Wmag
self.test_obj.slot = SlotM10(H0=0.10, Hmag=0.10, W0=0.10, Wmag=None)
assert self.widget.check(self.test_obj) == "You must set Wmag !"


if __name__ == "__main__":
a = TestPMSlot10()
a.setup_class()
a.setup_method()
a.test_init()
a.test_output_txt()
a.teardown_class()
print("Done")
166 changes: 166 additions & 0 deletions Tests/GUI/DMachineSetup/PMSlot/test_PMSlot11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# -*- coding: utf-8 -*-

import sys

from PySide2 import QtWidgets
from PySide2.QtTest import QTest
from numpy import pi
from Tests.GUI import gui_option # Set unit as [m]
from pyleecan.Classes.LamSlotMag import LamSlotMag
from pyleecan.Classes.SlotM11 import SlotM11
from pyleecan.GUI.Dialog.DMachineSetup.SMSlot.PMSlot11.PMSlot11 import PMSlot11


import pytest


class TestPMSlot11(object):
"""Test that the widget PMSlot11 behave like it should"""

def setup_method(self):
self.test_obj = LamSlotMag(Rint=0.1, Rext=0.2)
self.test_obj.slot = SlotM11(Zs=8, H0=0.10, W0=0.13, Wmag=0.14, Hmag=0.15)
self.widget = PMSlot11(self.test_obj)

@classmethod
def setup_class(cls):
"""Start the app for the test"""
print("\nStart Test TestPMSlot11")
if not QtWidgets.QApplication.instance():
cls.app = QtWidgets.QApplication(sys.argv)
else:
cls.app = QtWidgets.QApplication.instance()

@classmethod
def teardown_class(cls):
"""Exit the app after the test"""
cls.app.quit()

def test_init(self):
"""Check that the Widget spinbox initialise to the lamination value"""

assert self.widget.lf_H0.value() == 0.10
assert self.widget.lf_Hmag.value() == 0.15
assert self.widget.lf_W0.value() == 0.13
assert self.widget.lf_Wmag.value() == 0.14
assert self.widget.c_W0_unit.currentText() == "rad"
assert self.widget.c_Wmag_unit.currentText() == "rad"

def test_set_W0(self):
"""Check that the Widget allow to update W0"""
# Check Unit
assert self.widget.c_W0_unit.currentText() == "rad"
# Change value in GUI
self.widget.lf_W0.clear()
QTest.keyClicks(self.widget.lf_W0, "0.31")
self.widget.lf_W0.editingFinished.emit() # To trigger the slot

assert self.widget.slot.W0 == 0.31
assert self.test_obj.slot.W0 == 0.31

def test_set_W0_deg(self):
"""Check that the Widget allow to update W0"""
# Check Unit
self.widget.c_W0_unit.setCurrentIndex(1)
assert self.widget.c_W0_unit.currentText() == "deg"
# Change value in GUI
self.widget.lf_W0.clear()
QTest.keyClicks(self.widget.lf_W0, "45")
self.widget.lf_W0.editingFinished.emit() # To trigger the slot

assert self.widget.slot.W0 == pi / 4
assert self.test_obj.slot.W0 == pi / 4

def test_set_Wmag(self):
"""Check that the Widget allow to update Wmag"""
# Check Unit
assert self.widget.c_W0_unit.currentText() == "rad"
# Change value in GUI
self.widget.lf_Wmag.clear()
QTest.keyClicks(self.widget.lf_Wmag, "0.33")
self.widget.lf_Wmag.editingFinished.emit() # To trigger the slot

assert self.widget.slot.Wmag == 0.33
assert self.test_obj.slot.Wmag == 0.33

def test_set_Wmag_deg(self):
"""Check that the Widget allow to update Wmag"""
# Check Unit
self.widget.c_Wmag_unit.setCurrentIndex(1)
assert self.widget.c_Wmag_unit.currentText() == "deg"
# Change value in GUI
self.widget.lf_Wmag.clear()
QTest.keyClicks(self.widget.lf_Wmag, "45")
self.widget.lf_Wmag.editingFinished.emit() # To trigger the slot

assert self.widget.slot.Wmag == pi / 4
assert self.test_obj.slot.Wmag == pi / 4

def test_set_H0(self):
"""Check that the Widget allow to update H0"""
# Check Unit
assert self.widget.unit_H0.text() == "[m]"
# Change value in GUI
self.widget.lf_H0.clear()
QTest.keyClicks(self.widget.lf_H0, "0.34")
self.widget.lf_H0.editingFinished.emit() # To trigger the slot

assert self.widget.slot.H0 == 0.34
assert self.test_obj.slot.H0 == 0.34

def test_set_Hmag(self):
"""Check that the Widget allow to update Hmag"""
# Check Unit
assert self.widget.unit_Hmag.text() == "[m]"
# Change value in GUI
self.widget.lf_Hmag.clear()
QTest.keyClicks(self.widget.lf_Hmag, "0.36")
self.widget.lf_Hmag.editingFinished.emit() # To trigger the slot

assert self.widget.slot.Hmag == pytest.approx(0.36)
assert self.test_obj.slot.Hmag == pytest.approx(0.36)

def test_output_txt(self):
"""Check that the Output text is computed and correct"""
self.test_obj.slot = SlotM11(H0=0.005, Hmag=0.005, W0=0.01, Wmag=0.01)
self.widget = PMSlot11(self.test_obj)
assert self.widget.w_out.out_slot_height.text() == "Slot height: 0.005 [m]"

def test_check(self):
"""Check that the check is working correctly"""
self.test_obj = LamSlotMag(Rint=0.1, Rext=0.9)
# H0
self.test_obj.slot = SlotM11(H0=None, Hmag=0.10, W0=0.10, Wmag=0.10)
self.widget = PMSlot11(self.test_obj)
assert self.widget.check(self.test_obj) == "You must set H0 !"
# Hmag
self.test_obj.slot = SlotM11(H0=0.10, Hmag=None, W0=0.10, Wmag=0.10)
assert self.widget.check(self.test_obj) == "You must set Hmag !"
# W0
self.test_obj.slot = SlotM11(H0=0.10, Hmag=0.10, W0=None, Wmag=0.10)
assert self.widget.check(self.test_obj) == "You must set W0 !"
# Wmag
self.test_obj.slot = SlotM11(H0=0.10, Hmag=0.10, W0=0.10, Wmag=None)
assert self.widget.check(self.test_obj) == "You must set Wmag !"
# Wmag < W0
self.test_obj.slot = SlotM11(H0=0.10, Hmag=0.10, W0=0.10, Wmag=0.12)
assert self.widget.check(self.test_obj) == "You must have Wmag <= W0"
# Wmag < pi/p
self.test_obj.slot = SlotM11(Zs=8, H0=0.10, Hmag=0.10, W0=pi / 4, Wmag=pi / 4)
assert (
self.widget.check(self.test_obj)
== "You must have Wmag < pi/p (use ring magnet instead)"
)
self.test_obj.slot = SlotM11(
Zs=8, H0=0.10, Hmag=0.10, W0=(pi / 4) * 0.99, Wmag=(pi / 4) * 0.99
)
assert self.widget.check(self.test_obj) is None


if __name__ == "__main__":
a = TestPMSlot11()
a.setup_class()
a.setup_method()
a.test_check()
a.teardown_class()
print("Done")
Loading