Пример #1
0
def split_half(self, is_begin=True):
    """Cut the line in half (modify the object Arc3 => Arc2)

    Parameters
    ----------
    self : Arc3
        An Arc3 object
    is_begin : bool
        True to keep the part begin=>middle, False for the part middle=>end

    Returns
    -------
    """

    if self.is_trigo_direction:
        sign = 1
    else:
        sign = -1

    if is_begin:
        arc = Arc2(begin=self.begin,
                   center=self.get_center(),
                   angle=sign * pi / 2)
    else:
        arc = Arc2(begin=self.get_middle(),
                   center=self.get_center(),
                   angle=sign * pi / 2)
    # Change the object type from Arc3 => Arc2
    self.__class__ = Arc2
    self.__dict__.update(arc.__dict__)
    def test_comp_radius(self):
        """Check that the radius is correct
        """
        test_obj = Arc2(1, 0, pi / 2)
        result = test_obj.comp_radius()

        self.assertAlmostEqual(result, 1)

        test_obj = Arc2(2 * exp(1j * 3 * pi / 4), 0, -pi / 2)
        result = test_obj.comp_radius()

        self.assertAlmostEqual(result, 2)
Пример #3
0
def build_geometry(self):
    """Compute the curve (Segment) needed to plot the object.
    The ending point of a curve is the starting point of the next curve in
    the list

    Parameters
    ----------
    self : SlotW22
        A SlotW22 object

    Returns
    -------
    curve_list: llist
        A list of 5 Segment and 3 Arc2

    """
    Rbo = self.get_Rbo()

    # comp point coordinate (in complex)
    Z1 = Rbo * exp(-1j * self.W0 / 2)
    if self.is_outwards():
        R1 = Rbo + self.H0
        R2 = Rbo + self.H0 + self.H2
    else:  # inward slot
        R1 = Rbo - self.H0
        R2 = Rbo - self.H0 - self.H2
    Z2 = R1 * exp(-1j * self.W0 / 2.0)
    Z3 = R1 * exp(-1j * self.W2 / 2.0)
    Z4 = R2 * exp(-1j * self.W2 / 2.0)

    # symetry
    Z5 = Z4.conjugate()
    Z6 = Z3.conjugate()
    Z7 = Z2.conjugate()
    Z8 = Z1.conjugate()
    Zc = 0

    # Creation of curve
    curve_list = list()
    if self.H0 > 0:
        curve_list.append(Segment(Z1, Z2))
    if self.W2 != self.W0:
        curve_list.append(Arc2(Z2, Zc, -(self.W2 - self.W0) / 2))
    curve_list.append(Segment(Z3, Z4))
    curve_list.append(Arc2(Z4, Zc, self.W2))
    curve_list.append(Segment(Z5, Z6))
    if self.W2 != self.W0:
        curve_list.append(Arc2(Z6, Zc, -(self.W2 - self.W0) / 2))
    if self.H0 > 0:
        curve_list.append(Segment(Z7, Z8))

    return curve_list
Пример #4
0
    def test_build_geometry(self):
        """check that curve_list is correct"""
        test_obj = SlotW22(W0=pi / 10, H0=0.1, W2=pi / 5, H2=0.1)
        lam = LamSlot(is_internal=False, slot=test_obj, Rint=1)

        Z1 = cos(pi / 20) + 1j * sin(pi / 20)
        Z2 = 1.1 * (cos(pi / 20) + 1j * sin(pi / 20))
        Z3 = 1.1 * (cos(pi / 10) + 1j * sin(pi / 10))
        Z4 = 1.2 * (cos(pi / 10) + 1j * sin(pi / 10))
        Z5 = 1.2 * (cos(pi / 10) - 1j * sin(pi / 10))
        Z6 = 1.1 * (cos(pi / 10) - 1j * sin(pi / 10))
        Z7 = 1.1 * (cos(pi / 20) - 1j * sin(pi / 20))
        Z8 = cos(pi / 20) - 1j * sin(pi / 20)
        [Z8, Z7, Z6, Z5, Z4, Z3, Z2, Z1] = [Z1, Z2, Z3, Z4, Z5, Z6, Z7, Z8]

        # Creation of curve
        curve_list = list()
        Zc = 0  # center
        curve_list.append(Segment(Z1, Z2))
        curve_list.append(Arc2(Z2, Zc, -pi / 20))
        curve_list.append(Segment(Z3, Z4))
        curve_list.append(Arc2(Z4, Zc, pi / 5))
        curve_list.append(Segment(Z5, Z6))
        curve_list.append(Arc2(Z6, Zc, -pi / 20))
        curve_list.append(Segment(Z7, Z8))

        result = test_obj.build_geometry()
        self.assertEqual(len(result), len(curve_list))
        for i in range(0, len(result)):
            if isinstance(result[i], Segment):
                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)
            else:  # Arc2
                a = result[i].begin
                b = curve_list[i].begin
                self.assertAlmostEqual((a - b) / a, 0, delta=DELTA)

                a = result[i].center
                b = curve_list[i].center
                self.assertAlmostEqual(a, b)

                a = result[i].angle
                b = curve_list[i].angle
                self.assertAlmostEqual((a - b) / a, 0, delta=DELTA)
Пример #5
0
def build_geometry(self):
    """Compute the curve needed to plot the object.
    The ending point of a curve is the starting point of the next curve in
    the list

    Parameters
    ----------
    self : SlotW24
        A SlotW24 object

    Returns
    -------
    curve_list: list
        A list of 2 Segment and 1 Arc

    """
    (alpha_0, alpha_2) = self.comp_alphas()
    [Z1, Z2, Z3, Z4] = self._comp_point_coordinate()
    Zc = 0
    # Creation of curve
    curve_list = list()
    curve_list.append(Segment(Z1, Z2))
    curve_list.append(Arc2(Z2, Zc, alpha_2))
    curve_list.append(Segment(Z3, Z4))

    return curve_list
    def test_comp_length(self, test_dict):
        """Check that you the length return by comp_length is correct
        """
        arc = Arc2(test_dict["begin"], test_dict["center"], test_dict["angle"])

        a = float(arc.comp_length())
        b = float(test_dict["length"])
        self.assertAlmostEqual((a - b) / a, 0, delta=DELTA)
    def test_get_end(self):
        """Check that the end is correct
        """
        test_obj = Arc2(1, 0, pi / 2)
        result = test_obj.get_end()

        self.assertEqual(result, 1 * exp(1j * pi / 2))

        test_obj = Arc2(0, 1, -pi / 2)
        result = test_obj.get_end()

        a = abs(result)
        b = 1.414213
        self.assertAlmostEqual((a - b) / a, 0, delta=DELTA)

        a = angle(result)
        b = pi / 4
        self.assertAlmostEqual((a - b) / a, 0, delta=DELTA)
Пример #8
0
 def test_get_angle(self, test_dict):
     """Check that the arc2 computed angle is correct
     """
     arc = Arc2(
         begin=test_dict["begin"],
         center=test_dict["center"],
         angle=test_dict["angle"],
     )
     result = arc.get_angle(test_dict["is_deg"])
     self.assertAlmostEqual(result, test_dict["exp_angle"])
 def test_get_middle(self, test_dict):
     """Check that the middle is computed correctly
     """
     arc = Arc2(
         begin=test_dict["begin"],
         center=test_dict["center"],
         angle=test_dict["angle"],
     )
     result = arc.get_middle()
     self.assertAlmostEqual(abs(result - test_dict["expect"]), 0, delta=1e-3)
Пример #10
0
def build_geometry(self):
    """Compute the curve (Line) needed to plot the Slot.
    The ending point of a curve is always the starting point of the next
    curve in the list

    Parameters
    ----------
    self : SlotMPolar
        A SlotMPolar object

    Returns
    -------
    curve_list: list
        A list of 2 Segment and 1 Arc1

    """

    Rbo = self.get_Rbo()
    alpha = self.comp_angle_opening()
    alpha_mag = self.comp_angle_opening_magnet()

    # Point coordinate for a slot center on Ox
    Z1 = Rbo * exp(-1j * alpha_mag / 2)
    Z2 = Rbo * exp(1j * alpha_mag / 2)
    if self.is_outwards():
        Rbot = Rbo + self.H0
    else:
        Rbot = Rbo - self.H0
    Z3 = Rbot * exp(-1j * alpha_mag / 2)
    Z4 = Rbot * exp(1j * alpha_mag / 2)

    # Curve list of a single slot
    curve_list = list()
    if self.H0 > 0:
        curve_list.append(Segment(Z1, Z3))
    curve_list.append(Arc1(Z3, Z4, Rbot))
    if self.H0 > 0:
        curve_list.append(Segment(Z4, Z2))

    # Complete curve list for all the slots (for one pole)
    slot_list = list()
    for ii in range(len(self.magnet)):
        # Compute angle of the middle of the slot
        beta = -alpha / 2 + alpha_mag / 2 + ii * (self.W3 + alpha_mag)
        # Duplicate and rotate the slot + bore for each slot
        for line in curve_list:
            new_line = type(line)(init_dict=line.as_dict())
            new_line.rotate(beta)
            slot_list.append(new_line)
        if ii != len(self.magnet) - 1:  # Add the W3 except for the last slot
            slot_list.append(Arc2(slot_list[-1].get_end(), 0, self.W3))

    return slot_list
Пример #11
0
 def test_split_half(self, test_dict):
     """Check that the arc2 split is correct
     """
     arc = Arc2(
         begin=test_dict["begin"],
         center=test_dict["center"],
         angle=test_dict["angle"],
     )
     arc.split_half(is_begin=test_dict["is_begin"])
     self.assertAlmostEqual(arc.begin, test_dict["N_begin"])
     self.assertAlmostEqual(arc.center, test_dict["N_center"])
     self.assertAlmostEqual(arc.angle, test_dict["N_angle"])
Пример #12
0
    def test_dicretize(self, test_dict):
        """Check that you can discretize an arc2
        """
        arc = Arc2(test_dict["begin"], test_dict["center"], test_dict["angle"])

        result = arc.discretize(test_dict["nb_point"])

        self.assertEqual(result.size, test_dict["result"].size)
        for i in range(0, result.size):
            a = result[i]
            b = test_dict["result"][i]
            self.assertAlmostEqual((a - b) / a, 0, delta=DELTA)
Пример #13
0
    def test_translate(self, test_dict):
        """Check that you can translate the arc2
        """
        arc = Arc2(
            begin=test_dict["begin"],
            center=test_dict["center"],
            angle=test_dict["angle"],
        )
        expect_angle = arc.angle
        arc.translate(test_dict["delta"])

        self.assertAlmostEqual(abs(test_dict["exp_begin"] - arc.begin), 0)
        self.assertAlmostEqual(abs(expect_angle - arc.angle), 0)
        self.assertAlmostEqual(abs(test_dict["exp_center"] - arc.center), 0)
Пример #14
0
 def test_translate(self):
     """Check that you can rotate the surface
     """
     line1 = Arc1(begin=1, end=1j, radius=1)
     line2 = Arc2(begin=1, center=0, angle=pi / 2)
     line3 = Segment(begin=1j, end=0)
     surface = SurfLine(line_list=[line1, line2, line3],
                        label="test",
                        point_ref=0)
     surface.translate(1j)
     self.assertAlmostEqual(abs(line1.begin - 1j), 1)
     self.assertAlmostEqual(line1.end, 2j)
     self.assertAlmostEqual(abs(line2.begin - 1j), 1)
     self.assertAlmostEqual(abs(line2.center - 1j), 0)
     self.assertAlmostEqual(abs(line3.begin - 2j), 0)
     self.assertAlmostEqual(line3.end, 1j)
Пример #15
0
    def test_comp_length(self):
        """Check that you can compute the length of the Surface
        """
        line1 = Arc1(begin=1, end=1j, radius=1)
        line1.comp_length = MagicMock(return_value=1)
        line2 = Arc2(begin=1, center=0, angle=pi / 2)
        line2.comp_length = MagicMock(return_value=1)
        line3 = Segment(begin=1j, end=0)
        line3.comp_length = MagicMock(return_value=1)

        surface = SurfLine(line_list=[line1, line2, line3],
                           label="test",
                           point_ref=0)
        length = surface.comp_length()
        line1.comp_length.assert_called_once()
        line2.comp_length.assert_called_once()
        line3.comp_length.assert_called_once()
        self.assertAlmostEqual(abs(length - 3), 0)
Пример #16
0
 def test_comp_length_Point_error(self):
     """Check that comp_length can detect a one point arc2
     """
     arc = Arc2(0, 0, 2)
     with self.assertRaises(PointArc2Error):
         arc.comp_length()
Пример #17
0
 def test_check_Point(self):
     """Check that you can detect a one point arc"""
     arc = Arc2(0, 0, 1)
     with self.assertRaises(PointArc2Error):
         arc.check()
Пример #18
0
        ],  # Expected intersection points
        "Zs_top": [
            Arc1(
                begin=-1j + 3 * exp(1j * pi / 4),
                end=-1j + 3 * exp(1j * 3 * pi / 4),
                radius=3,
                is_trigo_direction=True,
            )
        ],  # Expected result for slip is_top
        "Zs_bot": [],  # Expected result for slip not is_top
    }
)
# 14) Arc2, 1 Intersection
split_test.append(
    {
        "arc": Arc2(begin=1j, center=0, angle=pi),  # Arc to split
        "Z1": -3,  # First point of cutting line
        "Z2": 1,  # Second point of cutting line
        "center": 0,  # Center of the arc (should not be changed by the split)
        "Zi": [-1],  # Expected intersection points
        "Zs_top": [
            Arc1(begin=1j, end=-1, radius=1, is_trigo_direction=True)
        ],  # Expected result for slip is_top
        "Zs_bot": [
            Arc1(begin=-1, end=-1j, radius=1, is_trigo_direction=True)
        ],  # Expected result for slip not is_top
    }
)
# 15) Case 14 with angle = -angle
split_test.append(
    {
Пример #19
0
 def test_check_Angle(self):
     """Check that you can detect null angle"""
     arc = Arc2(0, 1, 0)
     with self.assertRaises(AngleArc2Error):
         arc.check()
Пример #20
0
 def test_get_center(self):
     """Check that the center is returned correctly
     """
     test_obj = Arc2(1, 1 + 1j, pi)
     result = test_obj.get_center()
     self.assertEqual(result, 1 + 1j)
Пример #21
0
def build_geometry_wind(self,
                        Nrad,
                        Ntan,
                        is_simplified=False,
                        alpha=0,
                        delta=0):
    """Split the slot winding area in several zone

    Parameters
    ----------
    self : SlotW23
        A SlotW23 object
    Nrad : int
        Number of radial layer
    Ntan : int
        Number of tangentiel layer
    is_simplified : bool
        boolean to specify if coincident lines are considered as one or different lines (Default value = False)
    alpha : float
        Angle for rotation (Default value = 0) [rad]
    delta : Complex
        complex for translation (Default value = 0)

    Returns
    -------
    surf_list:
        List of surface delimiting the winding zone

    """

    if self.get_is_stator():  # check if the slot is on the stator
        st = "S"
    else:
        st = "R"

    [Z8, Z7, Z6, Z5, Z4, Z3, Z2, Z1] = self._comp_point_coordinate()
    X = linspace(Z6, Z5, Nrad + 1)

    # Nrad+1 and Ntan+1 because 3 points => 2 zones
    Z = zeros((Nrad + 1, Ntan + 1), dtype=complex)
    for ii in range(Nrad + 1):
        Z[ii][:] = linspace(X[ii], X[ii].conjugate(), Ntan + 1)

    # The bottom and top are Arc and not a line
    Z[0][:] = abs(Z6) * exp(1j * linspace(angle(Z6), angle(Z3), Ntan + 1))
    Z[Nrad][:] = abs(Z5) * exp(1j * linspace(angle(Z5), angle(Z4), Ntan + 1))

    assert abs(Z[0][0] - Z6) < 1e-6
    assert abs(Z[Nrad][0] - Z5) < 1e-6
    assert abs(Z[0][Ntan] - Z3) < 1e-6
    assert abs(Z[Nrad][Ntan] - Z4) < 1e-6

    Zc = 0  # Center of the machine

    # We go thought the zone by Rad then Tan, starting by (0,0)
    surf_list = list()
    for jj in range(Ntan):  # jj from 0 to Ntan-1
        for ii in range(Nrad):  # ii from 0 to Nrad-1
            Z1 = Z[ii][jj]
            Z2 = Z[ii][jj + 1]
            Z3 = Z[ii + 1][jj + 1]
            Z4 = Z[ii + 1][jj]
            point_ref = (Z1 + Z2 + Z3 + Z4) / 4
            # With one zone the order would be [Z6,Z3,Z4,Z5]
            if is_simplified:  # No doubling Line allowed
                curve_list = list()
                if ii == 0:
                    curve_list.append(Segment(Z1, Z2))
                if jj != Ntan - 1:
                    curve_list.append(Segment(Z2, Z3))
                if ii != Nrad - 1:
                    curve_list.append(Segment(Z3, Z4))
                surface = SurfLine(
                    line_list=curve_list,
                    label="Wind" + st + "_R" + str(ii) + "_T" + str(jj) +
                    "_S0",
                    point_ref=point_ref,
                )
                surf_list.append(surface)
            else:
                curve_list = list()
                curve_list.append(Segment(Z1, Z2))
                curve_list.append(Segment(Z2, Z3))
                if ii == Nrad - 1:  # Top zone
                    curve_list.append(Arc2(Z3, Zc, angle(Z4) - angle(Z3)))
                else:
                    curve_list.append(Segment(Z3, Z4))
                curve_list.append(Segment(Z4, Z1))
                surface = SurfLine(
                    line_list=curve_list,
                    label="Wind" + st + "_R" + str(ii) + "_T" + str(jj) +
                    "_S0",
                    point_ref=point_ref,
                )
                surf_list.append(surface)

    for surf in surf_list:
        surf.rotate(alpha)
        surf.translate(delta)
    return surf_list
Пример #22
0
 def test_discretize_Nb_Type_error(self):
     """Check that discretize can detect a wrong arg
     """
     arc = Arc2(0, 1, 1)
     with self.assertRaises(NbPointArc2DError):
         arc.discretize("test")
Пример #23
0
 def test_discretize_Angle_error(self):
     """Check that discretize can detect a null angle arc2
     """
     arc = Arc2(0, 1, 0)
     with self.assertRaises(AngleArc2Error):
         arc.discretize(5)
Пример #24
0
 def test_discretize_Point_error(self):
     """Check that dicretize can detect a one point arc2
     """
     arc = Arc2(0, 0, 2)
     with self.assertRaises(PointArc2Error):
         arc.discretize(5)
Пример #25
0
 def test_comp_length_angle_error(self):
     """Check that comp_length can detect a null angle arc2
     """
     arc = Arc2(0, 1, 0)
     with self.assertRaises(AngleArc2Error):
         arc.comp_length()
Пример #26
0
def build_geometry(self):
    """Compute the curve (Line) needed to plot the Slot.
    The ending point of a curve is always the starting point of the next curve
    in the list

    Parameters
    ----------
    self : SlotMFlat2
        A SlotMFlat2 object

    Returns
    -------
    curve_list: list
        A list of 7 Segments for each slot + W3 arc

    """
    Rbo = self.get_Rbo()
    alpha = self.comp_angle_opening()
    alpha_slot = self.comp_angle_opening_magnet()
    alpha_mag = self.comp_angle_magnet()

    # Point coordinate for a slot center on Ox
    Z1 = Rbo * exp(-1j * alpha_slot / 2)
    Z8 = Rbo * exp(1j * alpha_slot / 2)

    R1 = self.comp_W0m() / (2 * sin(alpha_mag / 2))
    Z3 = R1 * exp(-1j * alpha_mag / 2)
    Z6 = R1 * exp(1j * alpha_mag / 2)

    if self.is_outwards():
        Z2 = Z1 + self.H1
        Z7 = Z8 + self.H1
        Z4 = Z3 + self.H0
        Z5 = Z6 + self.H0
    else:
        Z2 = Z1 - self.H1
        Z7 = Z8 - self.H1
        Z4 = Z3 - self.H0
        Z5 = Z6 - self.H0

    # Curve list of a single slot
    curve_list = list()
    if self.H1 > 0:
        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))

    if self.H1 > 0:
        curve_list.append(Segment(Z7, Z8))

    # Copied from SlotMFlat. Probably not working for more than one Magnet
    # Complete curve list for all the slots (for one pole)
    slot_list = list()
    for ii in range(len(self.magnet)):
        # Compute angle of the middle of the slot
        beta = -alpha / 2 + alpha_slot / 2 + ii * (self.W3 + alpha_slot)
        # Duplicate and rotate the slot + bore for each slot
        for line in curve_list:
            new_line = type(line)(init_dict=line.as_dict())
            new_line.rotate(beta)
            slot_list.append(new_line)
        if ii != len(self.magnet) - 1:  # Add the W3 except for the last slot
            slot_list.append(Arc2(slot_list[-1].get_end(), 0, self.W3))

    return slot_list