# -*- coding: utf-8 -*-
import pytest
from pyleecan.Classes.SlotW23 import SlotW23
from numpy import ndarray, arcsin, pi
from pyleecan.Classes.LamSlot import LamSlot
from pyleecan.Classes.Slot import Slot
from pyleecan.Methods.Slot.SlotW23 import S23_H1rCheckError
# For AlmostEqual
DELTA = 1e-4
slotW23_test = list()
# Internal Slot
lam = LamSlot(is_internal=True, Rext=0.1325)
lam.slot = SlotW23(
H0=1e-3, H1=1.5e-3, H1_is_rad=False, H2=30e-3, W0=12e-3, W1=14e-3, W2=12e-3
)
slotW23_test.append(
{
"test_obj": lam,
"S_exp": 4.2080459e-4,
"Aw": 0.112537,
"SW_exp": 3.8834260e-04,
"H_exp": 0.032438,
}
)
# External Slot
lam = LamSlot(is_internal=False, Rint=0.1325)
lam.slot = SlotW23(
H0=1e-3, H1=1.5e-3, H1_is_rad=False, H2=30e-3, W0=12e-3, W1=14e-3, W2=12e-3
)
slotW23_test.append(
{
"test_obj": lam,
"S_exp": 4.2116997e-4,
"Aw": 0.086598,
"SW_exp": 3.906568e-04,
"H_exp": 0.032455,
}
)
# Rad H1
lam = LamSlot(is_internal=False, Rint=0.1325)
lam.slot = SlotW23(
H0=1e-3, H1=pi / 4, H1_is_rad=True, H2=30e-3, W0=12e-3, W1=14e-3, W2=12e-3
)
slotW23_test.append(
{
"test_obj": lam,
"S_exp": 0.010646,
"Aw": 0.013918,
"SW_exp": 3.89935e-4,
"H_exp": 0.81626,
}
)
[docs]class Test_SlotW23_meth(object):
"""pytest for SlotW23 methods"""
[docs] @pytest.mark.parametrize("test_dict", slotW23_test)
def test_schematics(self, test_dict):
"""Check that the schematics is correct"""
test_obj = test_dict["test_obj"]
point_dict = test_obj.slot._comp_point_coordinate()
# Check width
assert abs(point_dict["Z1"] - point_dict["Z8"]) == pytest.approx(
test_obj.slot.W0
)
assert abs(point_dict["Z3"] - point_dict["Z6"]) == pytest.approx(
test_obj.slot.W1
)
assert abs(point_dict["Z4"] - point_dict["Z5"]) == pytest.approx(
test_obj.slot.W2
)
# Check height
assert abs(point_dict["Z1"] - point_dict["Z2"]) == pytest.approx(
test_obj.slot.H0
)
assert abs(point_dict["Z2"].real - point_dict["Z3"].real) == pytest.approx(
test_obj.slot.H1
)
assert abs(point_dict["Z3"] - point_dict["Z4"]) == pytest.approx(
test_obj.slot.H2
)
assert abs(point_dict["Z8"] - point_dict["Z7"]) == pytest.approx(
test_obj.slot.H0
)
assert abs(point_dict["Z6"].real - point_dict["Z7"].real) == pytest.approx(
test_obj.slot.H1
)
assert abs(point_dict["Z5"] - point_dict["Z6"]) == pytest.approx(
test_obj.slot.H2
)
[docs] @pytest.mark.parametrize("test_dict", slotW23_test)
def test_build_geometry_active(self, test_dict):
"""Check that the active geometry is correctly split"""
test_obj = test_dict["test_obj"]
surf_list = test_obj.slot.build_geometry_active(Nrad=3, Ntan=2)
# Check label
assert surf_list[0].label == "Wind_Stator_R0_T0_S0"
assert surf_list[1].label == "Wind_Stator_R1_T0_S0"
assert surf_list[2].label == "Wind_Stator_R2_T0_S0"
assert surf_list[3].label == "Wind_Stator_R0_T1_S0"
assert surf_list[4].label == "Wind_Stator_R1_T1_S0"
assert surf_list[5].label == "Wind_Stator_R2_T1_S0"
# Check tangential position
assert surf_list[0].point_ref.imag < 0
assert surf_list[1].point_ref.imag < 0
assert surf_list[2].point_ref.imag < 0
assert surf_list[3].point_ref.imag > 0
assert surf_list[4].point_ref.imag > 0
assert surf_list[5].point_ref.imag > 0
# Check radial position
if test_obj.is_internal:
# Tan=0
assert surf_list[0].point_ref.real > surf_list[1].point_ref.real
assert surf_list[1].point_ref.real > surf_list[2].point_ref.real
# Tan=1
assert surf_list[3].point_ref.real > surf_list[4].point_ref.real
assert surf_list[4].point_ref.real > surf_list[5].point_ref.real
else:
# Tan=0
assert surf_list[0].point_ref.real < surf_list[1].point_ref.real
assert surf_list[1].point_ref.real < surf_list[2].point_ref.real
# Tan=1
assert surf_list[3].point_ref.real < surf_list[4].point_ref.real
assert surf_list[4].point_ref.real < surf_list[5].point_ref.real
[docs] @pytest.mark.parametrize("test_dict", slotW23_test)
def test_comp_surface(self, test_dict):
"""Check that the computation of the surface is correct"""
test_obj = test_dict["test_obj"]
result = test_obj.slot.comp_surface()
a = result
b = test_dict["S_exp"]
msg = "Return " + str(a) + " expected " + str(b)
assert abs((a - b) / a - 0) < DELTA, msg
# Check that the analytical method returns the same result as the numerical one
b = Slot.comp_surface(test_obj.slot)
msg = "Return " + str(a) + " expected " + str(b)
assert abs((a - b) / a - 0) < DELTA, msg
[docs] @pytest.mark.parametrize("test_dict", slotW23_test)
def test_comp_surface_active(self, test_dict):
"""Check that the computation of the winding surface is correct"""
test_obj = test_dict["test_obj"]
result = test_obj.slot.comp_surface_active()
a = result
b = test_dict["SW_exp"]
msg = "Return " + str(a) + " expected " + str(b)
assert abs((a - b) / a - 0) < DELTA, msg
# Check that the analytical method returns the same result as the numerical one
b = Slot.comp_surface_active(test_obj.slot)
msg = "Return " + str(a) + " expected " + str(b)
assert abs((a - b) / a - 0) < DELTA, msg
[docs] @pytest.mark.parametrize("test_dict", slotW23_test)
def test_comp_height(self, test_dict):
"""Check that the computation of the height is correct"""
test_obj = test_dict["test_obj"]
result = test_obj.slot.comp_height()
a = result
b = test_dict["H_exp"]
msg = "Return " + str(a) + " expected " + str(b)
assert abs((a - b) / a - 0) < DELTA, msg
# Check that the analytical method returns the same result as the numerical one
b = Slot.comp_height(test_obj.slot)
msg = "Return " + str(a) + " expected " + str(b)
assert abs((a - b) / a - 0) < DELTA, msg
[docs] @pytest.mark.parametrize("test_dict", slotW23_test)
def test_comp_angle_opening(self, test_dict):
"""Check that the computation of the average opening angle iscorrect"""
test_obj = test_dict["test_obj"]
a = test_obj.slot.comp_angle_opening()
assert a == 2 * arcsin(test_obj.slot.W0 / (2 * 0.1325))
# Check that the analytical method returns the same result as the numerical one
b = Slot.comp_angle_opening(test_obj.slot)
msg = "Return " + str(a) + " expected " + str(b)
assert abs((a - b) / a - 0) < DELTA, msg
[docs] @pytest.mark.parametrize("test_dict", slotW23_test)
def test_comp_angle_active_eq(self, test_dict):
"""Check that the computation of the average angle is correct"""
test_obj = test_dict["test_obj"]
result = test_obj.slot.comp_angle_active_eq()
a = result
b = test_dict["Aw"]
msg = "Return " + str(a) + " expected " + str(b)
assert abs((a - b) / a - 0) < DELTA, msg
[docs] def test_check_error(self):
"""Check that the check method is correctly raising an error"""
lam = LamSlot(is_internal=True, Rext=0.1325)
lam.slot = SlotW23(Zs=69, H2=0.0015, W3=12e-3, H1_is_rad=True, H1=3.14)
with pytest.raises(S23_H1rCheckError) as context:
lam.slot.check()
[docs] def test_get_surface_active(self):
"""Check that the get_surface_active works when stator = false"""
lam = LamSlot(is_internal=True, Rext=0.1325, is_stator=False)
lam.slot = SlotW23(
H0=1e-3, H1=1.5e-3, H1_is_rad=False, H2=30e-3, W0=12e-3, W1=14e-3, W2=12e-3
)
result = lam.slot.get_surface_active()
assert result.label == "Wind_Rotor_R0_T0_S0"
assert len(result.get_lines()) == 4
[docs] def test_comp_W(self):
"""Check that the computations of the Ws are right"""
lam = LamSlot(is_internal=True, Rext=0.1325, is_stator=False)
lam.slot = SlotW23(
H0=1e-3, H1=1.5e-3, H1_is_rad=False, H2=30e-3, W0=12e-3, W1=14e-3, W2=12e-3
)
lam.slot._comp_W()
assert lam.slot.W1 == 0.012681779210634543
assert lam.slot.W2 == 0.0074524346457750515
lam = LamSlot(is_internal=False, Rext=0.1325, is_stator=False, Rint=0.154)
lam.slot = SlotW23(
H0=1e-3, H1=1.5e-3, H1_is_rad=False, H2=30e-3, W0=12e-3, W1=14e-3, W2=12e-3
)
lam.slot._comp_W()
assert lam.slot.W1 == 0.017303874301855315
assert lam.slot.W2 == 0.022533218866714805