def parsec_foil():
    with open(join(getcwd(), "global_best_parsec.data")) as f:
        lines = f.readlines()

    thickness = float(lines[3])
    le_radius = float(lines[4])
    max_thickness_x = float(lines[5])
    curvature = float(lines[6])
    te_angle = float(lines[7])

    k = {
        'rle': le_radius,
        'x_pre': max_thickness_x,
        'y_pre': -thickness / 2.,
        'd2ydx2_pre': -curvature,
        'th_pre': te_angle,
        'x_suc': max_thickness_x,
        'y_suc': thickness / 2.,
        'd2ydx2_suc': curvature,
        'th_suc': -te_angle,
        'xte': 1.,
        'yte': 0.
    }

    foil = PARSEC(k)
    return foil
Beispiel #2
0
def test_is_symmetrical(rle, x_pre, y_pre, d2ydx2_pre, th_pre, x_suc, y_suc,
                        d2ydx2_suc, th_suc, xte, yte, is_symmetrical_value):
    r"""Test the is_symmetrical() function of the PARSEC foil generator

    Parameters
    ----------
    rle
    x_pre
    y_pre
    d2ydx2_pre
    th_pre
    x_suc
    y_suc
    d2ydx2_suc
    th_suc
    xte
    yte
    is_symmetrical_value : bool
        The expected value from is_symmetrical()

    """
    k = {
        'rle': rle,
        'x_pre': x_pre,
        'y_pre': y_pre,
        'd2ydx2_pre': d2ydx2_pre,
        'th_pre': th_pre,
        'x_suc': x_suc,
        'y_suc': y_suc,
        'd2ydx2_suc': d2ydx2_suc,
        'th_suc': th_suc,
        'xte': xte,
        'yte': yte
    }
    assert PARSEC(k).is_symmetrical() is is_symmetrical_value
Beispiel #3
0
def test_max_thickness(rle,
                       x_pre,
                       y_pre,
                       d2ydx2_pre,
                       th_pre,
                       x_suc,
                       y_suc,
                       d2ydx2_suc,
                       th_suc,
                       xte,
                       yte,
                       expected_value,
                       tolerance=1e-4):
    r"""Test the max_thickness() function of the PARSEC foil generator

    Parameters
    ----------
    rle
    x_pre
    y_pre
    d2ydx2_pre
    th_pre
    x_suc
    y_suc
    d2ydx2_suc
    th_suc
    xte
    yte
    expected_value : float
        The expected value from max_thickness()
    tolerance : float (optional, default is 1e-4)
        The tolerance for the value calculation

    """
    k = {
        'rle': rle,
        'x_pre': x_pre,
        'y_pre': y_pre,
        'd2ydx2_pre': d2ydx2_pre,
        'th_pre': th_pre,
        'x_suc': x_suc,
        'y_suc': y_suc,
        'd2ydx2_suc': d2ydx2_suc,
        'th_suc': th_suc,
        'xte': xte,
        'yte': yte
    }
    section = PARSEC(k)
    assert expected_value - tolerance <= section.max_thickness(
    ) <= expected_value + tolerance
Beispiel #4
0
def test_area(rle, x_pre, y_pre, d2ydx2_pre, th_pre, x_suc, y_suc, d2ydx2_suc,
              th_suc, xte, yte):
    r"""Test the area() function of the PARSEC generator"""
    k = {
        'rle': rle,
        'x_pre': x_pre,
        'y_pre': y_pre,
        'd2ydx2_pre': d2ydx2_pre,
        'th_pre': th_pre,
        'x_suc': x_suc,
        'y_suc': y_suc,
        'd2ydx2_suc': d2ydx2_suc,
        'th_suc': th_suc,
        'xte': xte,
        'yte': yte
    }
    assert PARSEC(k).area() > 0.0
Beispiel #5
0
    def parsec_params_changed(self, change):
        r"""The parsec definition parameters changed

        Parameters
        ----------
        change : dict

        """
        self.k = {'rle': self.le_radius, 'x_pre': self.max_thickness_x,
                  'y_pre': -self.thickness / 2.,
                  'd2ydx2_pre': self.curvature,
                  'th_pre': self.te_angle, 'x_suc': self.max_thickness_x,
                  'y_suc': self.thickness / 2.,
                  'd2ydx2_suc': -self.curvature,
                  'th_suc': -self.te_angle, 'xte': 1., 'yte': 0.}
        self.points = PARSEC(self.k).get_coords()
        self.notify("parsec_params_changed", change)
Beispiel #6
0
def test_wrong_constructor_values(rle, x_pre, y_pre, d2ydx2_pre, th_pre, x_suc,
                                  y_suc, d2ydx2_suc, th_suc, xte, yte):
    r"""Test instantiation with wrong parameters"""
    k = {
        'rle': rle,
        'x_pre': x_pre,
        'y_pre': y_pre,
        'd2ydx2_pre': d2ydx2_pre,
        'th_pre': th_pre,
        'x_suc': x_suc,
        'y_suc': y_suc,
        'd2ydx2_suc': d2ydx2_suc,
        'th_suc': th_suc,
        'xte': xte,
        'yte': yte
    }
    with pytest.raises(ValueError):
        PARSEC(k)
Beispiel #7
0
def assymmetrical_foil_section():
    r"""Assymmetrical PARSEC foil section"""
    k = {
        'rle': .01,
        'x_pre': .45,
        'y_pre': -0.006,
        'd2ydx2_pre': -.2,
        'th_pre': 2,
        'x_suc': .35,
        'y_suc': .055,
        'd2ydx2_suc': -.35,
        'th_suc': -10,
        'xte': 1.0,
        'yte': -0.05
    }

    foil = PARSEC(k)
    print(foil)
    print(foil.get_coords_plain())
    foil.plot_foil("PARSEC")
Beispiel #8
0
def test_is_valid(rle, x_pre, y_pre, d2ydx2_pre, th_pre, x_suc, y_suc,
                  d2ydx2_suc, th_suc, xte, yte, is_valid_value):
    r"""Test the is_valid() function of the PARSEC foil generator

    Parameters
    ----------
    rle
    x_pre
    y_pre
    d2ydx2_pre
    th_pre
    x_suc
    y_suc
    d2ydx2_suc
    th_suc
    xte
    yte
    is_valid_value : bool
        The expected value from is_valid()

    """
    k = {
        'rle': rle,
        'x_pre': x_pre,
        'y_pre': y_pre,
        'd2ydx2_pre': d2ydx2_pre,
        'th_pre': th_pre,
        'x_suc': x_suc,
        'y_suc': y_suc,
        'd2ydx2_suc': d2ydx2_suc,
        'th_suc': th_suc,
        'xte': xte,
        'yte': yte
    }
    section = PARSEC(k)
    if section.is_symmetrical() is False:
        with pytest.raises(NotImplementedError):
            section.is_valid()
    else:
        assert section.is_valid() is is_valid_value
Beispiel #9
0
def test_symmetrical_parsec():
    r"""Test that comes from an old doctest"""
    # Symmetrical foil section
    x = 0.25
    y = 0.03
    d2ydx2 = 0.25
    th = 6.
    k = {
        'rle': .005,
        'x_pre': x,
        'y_pre': -y,
        'd2ydx2_pre': d2ydx2,
        'th_pre': th,
        'x_suc': x,
        'y_suc': y,
        'd2ydx2_suc': -d2ydx2,
        'th_suc': -th,
        'xte': 1.,
        'yte': 0.
    }
    foil = PARSEC(k)
    assert foil.is_symmetrical() is True
    assert foil.is_valid() is True
Beispiel #10
0
    def foil_points(self):
        r"""Points describing the 2D foil section

        Returns
        -------
        ([x_lower],[y_lower],[x_upper],[y_upper])

        """
        k = {
            'rle': self.le_radius_lsv.numeric_value(),
            'x_pre': self.max_thickness_x_lsv.numeric_value() / 100,
            'y_pre': -self.thickness_lsv.numeric_value() / 100. / 2.,
            'd2ydx2_pre': self.curvature_at_max_thickness_lsv.numeric_value(),
            'th_pre': self.te_angle_lsv.numeric_value(),
            'x_suc': self.max_thickness_x_lsv.numeric_value() / 100,
            'y_suc': self.thickness_lsv.numeric_value() / 100. / 2.,
            'd2ydx2_suc': -self.curvature_at_max_thickness_lsv.numeric_value(),
            'th_suc': -self.te_angle_lsv.numeric_value(),
            'xte': 1.,
            'yte': 0.
        }

        return PARSEC(k).get_coords()
Beispiel #11
0
def symmetrical_foil_section_invalid():
    r"""Symmetrical PARSEC foil section but invalid"""
    x = 0.25
    y = 0.03
    d2ydx2 = 0.47
    th = 6.
    k = {
        'rle': .005,
        'x_pre': x,
        'y_pre': -y,
        'd2ydx2_pre': d2ydx2,
        'th_pre': th,
        'x_suc': x,
        'y_suc': y,
        'd2ydx2_suc': -d2ydx2,
        'th_suc': -th,
        'xte': 1.,
        'yte': 0.
    }

    foil = PARSEC(k)
    print(foil)
    print(foil.get_coords_plain())
    foil.plot_foil("PARSEC-SYMMETRICAL-INVALID")
Beispiel #12
0
    def update(self, message, n, i_par, pts, score, foil_parameterization_type):
        r"""

        Parameters
        ----------
        message : str
            Message prefix
        n : int
        i_par : int
        pts : str
            String representation of a pso position
        score : float
        foil_parameterization_type : str

        """
        item = self.ultimate_list.InsertStringItem(self.nb_records, message)
        if message == "global_best":
            self.ultimate_list.SetItemBackgroundColour(item,
                                                       wx.Colour(255, 100, 220))
        elif message == "particle_best":
            self.ultimate_list.SetItemBackgroundColour(item,
                                                       wx.Colour(240, 240, 240))

        self.ultimate_list.SetStringItem(self.nb_records, 1, str(n))
        self.ultimate_list.SetStringItem(self.nb_records, 2, str(i_par))
        self.ultimate_list.SetStringItem(self.nb_records, 3, str(pts))
        self.ultimate_list.SetStringItem(self.nb_records, 4, str(score))
        self.ultimate_list.SetStringItem(self.nb_records, 5, str(1/score))

        if foil_parameterization_type == "SYM_PARSEC":
            from foilix.foil_generators.parsec import PARSEC
            k = dict()
            k['rle'] = pts[1]
            k['x_pre'] = pts[2]
            # Thickness 6%
            k['y_pre'] = -pts[0] / 2.0
            k['d2ydx2_pre'] = -pts[3]
            # Trailing edge angle
            k['th_pre'] = pts[4]
            # Suction part
            k['x_suc'] = k['x_pre']
            k['y_suc'] = -k['y_pre']
            k['d2ydx2_suc'] = -k['d2ydx2_pre']
            k['th_suc'] = -k['th_pre']
            # Trailing edge x and y position
            k['xte'] = 1.0  # beware of PARSEC generator check
            k['yte'] = 0.0
            foil = PARSEC(k)
            self.ultimate_list.SetStringItem(self.nb_records,
                                             6,
                                             str(foil.max_thickness()))
            self.ultimate_list.SetStringItem(self.nb_records,
                                             7,
                                             str(k['x_pre']))
        elif foil_parameterization_type == "SYM_NURBS":
            from foilix.foil_generators.nurbs import NURBS
            ta = pts[0]
            tb = pts[1]
            alpha = pts[2]
            k = {'ta_u': ta,
                 'ta_l': ta,
                 'tb_u': tb,
                 'tb_l': tb,
                 'alpha_b': 2*alpha,
                 'alpha_c': -alpha}
            foil = NURBS(k)
            self.ultimate_list.SetStringItem(self.nb_records,
                                             6,
                                             str(foil.max_thickness()))
            # x_l, y_l, x_u, y_u, = foil.get_coords()
            _, _, x_u, y_u, = foil.get_coords()
            self.ultimate_list.SetStringItem(self.nb_records,
                                             7,
                                             str(x_u[y_u.tolist().index(max(y_u))]))
        elif foil_parameterization_type == "NURBS" \
                or foil_parameterization_type == "SYM_PARSEC":
            raise NotImplementedError

        self.nb_records += 1