Skip to content

Commit

Permalink
Merge pull request #18 from EOMYS-Public/Convertisseur
Browse files Browse the repository at this point in the history
Convertisseur
  • Loading branch information
AdrienLeduqueEomys authored Dec 13, 2023
2 parents 659c061 + 782a42f commit f97e3ab
Show file tree
Hide file tree
Showing 351 changed files with 48,447 additions and 31,706 deletions.
1,947 changes: 1,947 additions & 0 deletions Tests/Data/Retrocompatibility/WmagHmag/Benchmark_old.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Tests/Functions/test_gmsh2.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_gmsh_spm():

# Import the machine from a script
PMSM_A = load(join(DATA_DIR, "Machine", "SPMSM_001.json"))
PMSM_A.rotor.slot = SlotM10(Wmag=15e-3, Hmag=3e-3, H0=0.0, W0=15e-3, Zs=8)
PMSM_A.rotor.slot = SlotM10(W1=15e-3, H1=3e-3, H0=0.0, W0=15e-3, Zs=8)

# PMSM_A.plot()
save_path = join(save_plot_path, "GMSH")
Expand Down
84 changes: 81 additions & 3 deletions Tests/Functions/test_retrocompatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from numpy import array_equal
from pyleecan.definitions import DATA_DIR
from pyleecan.Functions.load import load
from pyleecan.Functions.Load.retrocompatibility import is_before_version
from pyleecan.Functions.Load.retrocompatibility import (
is_before_version,
convert_Wmag_Hmag,
is_Wmag_Hmag,
)
from Tests import TEST_DATA_DIR

# 4: OP_matrix convertion (ndarray to object)
Expand Down Expand Up @@ -123,6 +127,16 @@
}
)

Hmag_Wmag_list = list()
Hmag_Wmag_list.append( # WindingCW1L
{
"ref": join(DATA_DIR, "Machine", "Benchmark.json"),
"old": join(
TEST_DATA_DIR, "Retrocompatibility", "WmagHmag", "Benchmark_old.json"
),
}
)


def test_save_OPM_None_retro():
"""Check that the OP_matrix convertion works with None"""
Expand Down Expand Up @@ -234,6 +248,67 @@ def test_load_opti(file_dict):
assert isinstance(designvar, type(ref.problem.design_var[ii])), msg


@pytest.mark.parametrize("file_dict", Hmag_Wmag_list)
def test_load_Hmag_Wmag(file_dict):
"""Check that the Hmag_Wmag into Hmag_Wmag convertion works"""
ref = load(file_dict["ref"])
old = load(file_dict["old"])

# Check old file is converted to current version
assert ref.rotor.slot.W1 == old.rotor.slot.W1
assert ref.rotor.slot.H1 == old.rotor.slot.H1


def test_fct_Hmag_Wmag():
"""Check that Hmag/Wmag update works for all slots"""

for ii in range(7):
test_dict = {
"H0": 0.1,
"Hmag": 0.2,
"W0": 0.3,
"Wmag": 0.4,
"Zs": 10,
"__class__": "SlotM1" + str(ii),
"is_bore": True,
"wedge_mat": None,
}
assert is_Wmag_Hmag(test_dict)
updated_dict = convert_Wmag_Hmag(test_dict)
assert "Hmag" not in updated_dict
assert "Wmag" not in updated_dict
assert updated_dict["H1"] == 0.2
assert updated_dict["W1"] == 0.4

# SlotM18 case
test_dict = {
"Hmag": 0.2,
"Zs": 10,
"__class__": "SlotM18",
"is_bore": True,
"wedge_mat": None,
}
assert is_Wmag_Hmag(test_dict)
updated_dict = convert_Wmag_Hmag(test_dict)
assert "Hmag" not in updated_dict
assert updated_dict["H0"] == 0.2

# SlotM19 case
test_dict = {
"Hmag": 0.2,
"W0": 0.3,
"W1": 0.4,
"Zs": 10,
"__class__": "SlotM19",
"is_bore": True,
"wedge_mat": None,
}
assert is_Wmag_Hmag(test_dict)
updated_dict = convert_Wmag_Hmag(test_dict)
assert "Hmag" not in updated_dict
assert updated_dict["H0"] == 0.2


def test_before_version():
"""Check that we can detect previous version"""
assert is_before_version("1.2.3", "1.2.1")
Expand All @@ -249,12 +324,15 @@ def test_before_version():

if __name__ == "__main__":
test_save_OPM_None_retro()
for file_dict in OPM_list:
test_save_OPM_retro(file_dict)
# for file_dict in OPM_list:
# test_save_OPM_retro(file_dict)

# for file_dict in hole_list:
# test_save_load_hole_retro(file_dict)

# for file_dict in wind_list:
# test_save_load_wind_retro(file_dict)
for file_dict in Hmag_Wmag_list:
test_load_Hmag_Wmag(file_dict)

print("Done")
10 changes: 5 additions & 5 deletions Tests/Functions/test_save_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_save_load_machine():
test_obj.stator.slot = SlotW10(Zs=10, H0=0.21, W0=0.23)
test_obj.stator.winding = Winding(qs=5, Nlayer=1, p=3)
test_obj.rotor = LamSlotMag(L1=0.55)
test_obj.rotor.slot = SlotM11(W0=pi / 4, Wmag=pi / 4, Hmag=3)
test_obj.rotor.slot = SlotM11(W0=pi / 4, W1=pi / 4, H1=3)
test_obj.shaft = Shaft(Lshaft=0.65)
test_obj.frame = None

Expand Down Expand Up @@ -93,8 +93,8 @@ def test_save_load_machine():
assert type(result.rotor.slot) is SlotM11
assert result.rotor.slot.W0 == pi / 4

assert result.rotor.slot.Wmag == pi / 4
assert result.rotor.slot.Hmag == 3
assert result.rotor.slot.W1 == pi / 4
assert result.rotor.slot.H1 == 3

assert type(result.shaft) is Shaft
assert result.shaft.Lshaft == 0.65
Expand Down Expand Up @@ -312,7 +312,7 @@ def test_save_load_list():
test_obj_1.stator.slot = SlotW10(Zs=10, H0=0.21, W0=0.23)
test_obj_1.stator.winding = Winding(qs=5, p=3, Nlayer=1)
test_obj_1.rotor = LamSlotMag(L1=0.55)
test_obj_1.rotor.slot = SlotM11(W0=pi / 4, Wmag=pi / 4, Hmag=3)
test_obj_1.rotor.slot = SlotM11(W0=pi / 4, W1=pi / 4, H1=3)
test_obj_1.shaft = Shaft(Lshaft=0.65)
test_obj_1.frame = None

Expand Down Expand Up @@ -352,7 +352,7 @@ def test_save_load_dict():
test_obj_1.stator.slot = SlotW10(Zs=10, H0=0.21, W0=0.23)
test_obj_1.stator.winding = Winding(qs=5, p=3)
test_obj_1.rotor = LamSlotMag(L1=0.55)
test_obj_1.rotor.slot = SlotM11(W0=pi / 4, Wmag=pi / 4, Hmag=3)
test_obj_1.rotor.slot = SlotM11(W0=pi / 4, W1=pi / 4, H1=3)
test_obj_1.shaft = Shaft(Lshaft=0.65)
test_obj_1.frame = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,18 +497,18 @@ def test_Benchmark(self):
assert wid_slot.w_mag.c_type_magnetization.currentText() == "Radial"

assert wid_slot.lf_W0.value() is None
assert wid_slot.lf_Wmag.value() is None
assert wid_slot.lf_W1.value() is None
assert wid_slot.lf_H0.value() is None
assert wid_slot.lf_Hmag.value() is None
assert wid_slot.lf_H1.value() is None

wid_slot.lf_W0.setValue(0.6048)
wid_slot.lf_W0.editingFinished.emit()
wid_slot.lf_Wmag.setValue(0.6048)
wid_slot.lf_Wmag.editingFinished.emit()
wid_slot.lf_W1.setValue(0.6048)
wid_slot.lf_W1.editingFinished.emit()
wid_slot.lf_H0.setValue(0)
wid_slot.lf_H0.editingFinished.emit()
wid_slot.lf_Hmag.setValue(0.005)
wid_slot.lf_Hmag.editingFinished.emit()
wid_slot.lf_H1.setValue(0.005)
wid_slot.lf_H1.editingFinished.emit()

assert wid_slot.w_out.out_Wlam.text() == "Rotor width: 0.0305 [m]"
assert wid_slot.w_out.out_slot_height.text() == "Slot height: 0 [m]"
Expand All @@ -520,9 +520,9 @@ def test_Benchmark(self):
assert wid_slot.w_out.out_op_angle.text() == "Opening angle: 0.6048 [rad]"

assert self.widget.w_step.machine.rotor.slot.W0 == 0.6048
assert self.widget.w_step.machine.rotor.slot.Wmag == 0.6048
assert self.widget.w_step.machine.rotor.slot.W1 == 0.6048
assert self.widget.w_step.machine.rotor.slot.H0 == 0
assert self.widget.w_step.machine.rotor.slot.Hmag == 0.005
assert self.widget.w_step.machine.rotor.slot.H1 == 0.005
assert self.widget.w_step.machine.rotor.magnet.mat_type.name == "MagnetPrius"
self.widget.w_step.b_plot.clicked.emit()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,18 +500,18 @@ def test_Benchmark(self):
assert wid_slot.w_mag.c_type_magnetization.currentText() == "Radial"

assert wid_slot.lf_W0.value() is None
assert wid_slot.lf_Wmag.value() is None
assert wid_slot.lf_W1.value() is None
assert wid_slot.lf_H0.value() is None
assert wid_slot.lf_Hmag.value() is None
assert wid_slot.lf_H1.value() is None

wid_slot.lf_W0.setValue(0.6048)
wid_slot.lf_W0.editingFinished.emit()
wid_slot.lf_Wmag.setValue(0.6048)
wid_slot.lf_Wmag.editingFinished.emit()
wid_slot.lf_W1.setValue(0.6048)
wid_slot.lf_W1.editingFinished.emit()
wid_slot.lf_H0.setValue(0)
wid_slot.lf_H0.editingFinished.emit()
wid_slot.lf_Hmag.setValue(0.005)
wid_slot.lf_Hmag.editingFinished.emit()
wid_slot.lf_H1.setValue(0.005)
wid_slot.lf_H1.editingFinished.emit()

assert wid_slot.w_out.out_Wlam.text() == "Rotor width: 0.0305 [m]"
assert wid_slot.w_out.out_slot_height.text() == "Slot height: 0 [m]"
Expand All @@ -523,9 +523,9 @@ def test_Benchmark(self):
assert wid_slot.w_out.out_op_angle.text() == "Opening angle: 0.6048 [rad]"

assert self.widget.w_step.machine.rotor.slot.W0 == 0.6048
assert self.widget.w_step.machine.rotor.slot.Wmag == 0.6048
assert self.widget.w_step.machine.rotor.slot.W1 == 0.6048
assert self.widget.w_step.machine.rotor.slot.H0 == 0
assert self.widget.w_step.machine.rotor.slot.Hmag == 0.005
assert self.widget.w_step.machine.rotor.slot.H1 == 0.005
assert (
self.widget.w_step.machine.rotor.magnet_north.mat_type.name == "MagnetPrius"
)
Expand Down Expand Up @@ -568,18 +568,18 @@ def test_Benchmark(self):
assert wid_slot2.w_mag.c_type_magnetization.currentText() == "Parallel"

assert wid_slot2.lf_W0.value() is None
assert wid_slot2.lf_Wmag.value() is None
assert wid_slot2.lf_W1.value() is None
assert wid_slot2.lf_H0.value() is None
assert wid_slot2.lf_Hmag.value() is None
assert wid_slot2.lf_H1.value() is None

wid_slot2.lf_W0.setValue(0.6)
wid_slot2.lf_W0.editingFinished.emit()
wid_slot2.lf_Wmag.setValue(0.6)
wid_slot2.lf_Wmag.editingFinished.emit()
wid_slot2.lf_W1.setValue(0.6)
wid_slot2.lf_W1.editingFinished.emit()
wid_slot2.lf_H0.setValue(0)
wid_slot2.lf_H0.editingFinished.emit()
wid_slot2.lf_Hmag.setValue(0.004)
wid_slot2.lf_Hmag.editingFinished.emit()
wid_slot2.lf_H1.setValue(0.004)
wid_slot2.lf_H1.editingFinished.emit()
wid_slot2.lf_Rtopm.setValue(0.02)
wid_slot2.lf_Rtopm.editingFinished.emit()

Expand All @@ -593,9 +593,9 @@ def test_Benchmark(self):
assert wid_slot2.w_out.out_op_angle.text() == "Opening angle: 0.6 [rad]"

assert self.widget.w_step.machine.rotor.slot_south.W0 == 0.6
assert self.widget.w_step.machine.rotor.slot_south.Wmag == 0.6
assert self.widget.w_step.machine.rotor.slot_south.W1 == 0.6
assert self.widget.w_step.machine.rotor.slot_south.H0 == 0
assert self.widget.w_step.machine.rotor.slot_south.Hmag == 0.004
assert self.widget.w_step.machine.rotor.slot_south.H1 == 0.004
assert self.widget.w_step.machine.rotor.slot_south.Rtopm == 0.02
assert self.widget.w_step.machine.rotor.magnet_south.mat_type.name == "Magnet3"

Expand Down
Loading

0 comments on commit f97e3ab

Please sign in to comment.