Source code for pyleecan.Tests.Methods.Slot.test_SlotW27_meth

# -*- coding: utf-8 -*-
from unittest import TestCase

from ....Classes.SlotW27 import SlotW27
from numpy import ndarray, arcsin, exp
from ....Classes.LamSlot import LamSlot
from ....Classes.Segment import Segment
from ddt import ddt, data
from ....Methods.Slot.Slot.comp_height import comp_height
from ....Methods.Slot.Slot.comp_surface import comp_surface
from ....Methods.Slot.Slot.comp_angle_opening import comp_angle_opening
from ....Methods.Slot.SlotWind.comp_surface_wind import comp_surface_wind

# For AlmostEqual
DELTA = 1e-4

slotW27_test = list()

# Internal Slot
lam = LamSlot(is_internal=True, Rext=0.1)
lam.slot = SlotW27(
    Zs=12, H0=10e-3, W0=10e-3, H1=0.03, W1=0.02, H2=0.02, W2=0.03, W3=0.02
)
slotW27_test.append(
    {
        "test_obj": lam,
        "S_exp": 1.3508e-3,
        "Ao": 0.10004,
        "Aw": 0.3853569,
        "SW_exp": 1.25e-3,
        "H_exp": 6.0125e-2,
    }
)

# External Slot
lam = LamSlot(is_internal=False, Rint=0.1)
lam.slot = SlotW27(
    Zs=12, H0=10e-3, W0=10e-3, H1=0.03, W1=0.02, H2=0.02, W2=0.03, W3=0.02
)
slotW27_test.append(
    {
        "test_obj": lam,
        "S_exp": 1.34916e-3,
        "Ao": 0.10004,
        "Aw": 0.184928,
        "SW_exp": 1.25e-3,
        "H_exp": 6.0187e-2,
    }
)


[docs]@ddt class test_SlotW27_meth(TestCase): """unittest for SlotW27 methods""" @data(*slotW27_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) self.assertAlmostEqual((a - b) / a, 0, delta=DELTA, msg=msg) # Check that the analytical method returns the same result as the numerical one b = comp_surface(test_obj.slot) msg = "Return " + str(a) + " expected " + str(b) self.assertAlmostEqual((a - b) / a, 0, delta=DELTA, msg=msg) @data(*slotW27_test) def test_comp_surface_wind(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_wind() a = result b = test_dict["SW_exp"] msg = "Return " + str(a) + " expected " + str(b) self.assertAlmostEqual((a - b) / a, 0, delta=DELTA, msg=msg) # Check that the analytical method returns the same result as the numerical one b = comp_surface_wind(test_obj.slot) msg = "Return " + str(a) + " expected " + str(b) self.assertAlmostEqual((a - b) / a, 0, delta=DELTA, msg=msg) @data(*slotW27_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) self.assertAlmostEqual((a - b) / a, 0, delta=DELTA, msg=msg) # Check that the analytical method returns the same result as the numerical one b = comp_height(test_obj.slot) msg = "Return " + str(a) + " expected " + str(b) self.assertAlmostEqual((a - b) / a, 0, delta=DELTA, msg=msg) @data(*slotW27_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() b = test_dict["Ao"] msg = "Return " + str(a) + " expected " + str(b) self.assertAlmostEqual((a - b) / a, 0, delta=DELTA, msg=msg) # Check that the analytical method returns the same result as the numerical one b = comp_angle_opening(test_obj.slot) msg = "Return " + str(a) + " expected " + str(b) self.assertAlmostEqual((a - b) / a, 0, delta=DELTA, msg=msg) @data(*slotW27_test) def test_comp_angle_wind_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_wind_eq() a = result b = test_dict["Aw"] msg = "Return " + str(a) + " expected " + str(b) self.assertAlmostEqual((a - b) / a, 0, delta=DELTA, msg=msg)
[docs] def test_build_geometry(self): """Check if the curve_list is correct""" test_obj = SlotW27( Zs=6, H0=0.05, W0=30e-3, H1=0.125, W1=0.06, H2=0.05, W2=0.09, W3=0.04 ) lam = LamSlot(is_internal=False, slot=test_obj, Rint=1) Z1 = exp(1j * float(arcsin(30e-3 / 2.0))) Z2 = Z1 + 0.05 Z3 = Z2 + ((0.06 - 30e-3) / 2.0) * 1j Z4 = Z3 + 0.125 + ((0.09 - 0.06) / 2.0) * 1j Z5 = Z4 + 0.05 + ((0.04 - 0.09) / 2.0) * 1j Z6 = Z5.conjugate() Z7 = Z4.conjugate() Z8 = Z3.conjugate() Z9 = Z2.conjugate() Z10 = Z1.conjugate() [Z1, Z2, Z3, Z4, Z5, Z6, Z7, Z8, Z9, Z10] = [ Z10, Z9, Z8, Z7, Z6, Z5, Z4, Z3, Z2, Z1, ] curve_list = list() curve_list.append(Segment(Z1, Z2)) curve_list.append(Segment(Z2, Z3)) curve_list.append(Segment(Z3, Z4)) curve_list.append(Segment(Z4, Z5)) curve_list.append(Segment(Z5, Z6)) curve_list.append(Segment(Z6, Z7)) curve_list.append(Segment(Z7, Z8)) curve_list.append(Segment(Z8, Z9)) curve_list.append(Segment(Z9, Z10)) result = test_obj.build_geometry() self.assertEqual(len(result), len(curve_list)) 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)