Exemplo n.º 1
0
def test_max_thickness(ta_u,
                       ta_l,
                       tb_u,
                       tb_l,
                       alpha_b,
                       alpha_c,
                       expected_value,
                       tolerance=1e-4):
    r"""Test the max_thickness() function of the NURBS foil generator

    Parameters
    ----------
    ...
    expected_value : float
        The expected value from max_thickness()

    tolerance : float (optional, default is 1e-4)
        The tolerance for the value calculation

    """
    k = {'ta_u': ta_u,
         'ta_l': ta_l,
         'tb_u': tb_u,
         'tb_l': tb_l,
         'alpha_b': alpha_b,
         'alpha_c': alpha_c}
    section = NURBS(k)
    assert expected_value - tolerance <= section.max_thickness() <= expected_value + tolerance
Exemplo n.º 2
0
def nurbs_example():
    r"""Runs an example'''"""
    k = dict()
    # sample coefficients: Coefficients for generating NACA5410
    k['ta_u'] = 0.15
    k['ta_l'] = 0.09
    k['tb_u'] = 2.9
    k['tb_l'] = 2.9
    k['alpha_b'] = 6
    k['alpha_c'] = -1.

    nurbs_foil = NURBS(k)
    print(nurbs_foil)
    print(nurbs_foil.get_coords_plain())
    nurbs_foil.plot_foil(title="NURBS")
Exemplo n.º 3
0
def test_is_symmetrical(ta_u,
                        ta_l,
                        tb_u,
                        tb_l,
                        alpha_b,
                        alpha_c,
                        is_symmetrical_value):
    r"""Test the is_symmetrical() function of the NURBS foil generator

    Parameters
    ----------
    ta_u
    ta_l
    tb_u
    tb_l
    alpha_b
    alpha_c
    is_symmetrical_value : bool
        The expected value from is_symmetrical()

    """
    k = {'ta_u': ta_u,
         'ta_l': ta_l,
         'tb_u': tb_u,
         'tb_l': tb_l,
         'alpha_b': alpha_b,
         'alpha_c': alpha_c}
    assert NURBS(k).is_symmetrical() is is_symmetrical_value
Exemplo n.º 4
0
def test_is_valid(ta_u, ta_l, tb_u, tb_l, alpha_b, alpha_c, is_valid_value):
    r"""Test the is_valid() function of the NURBS foil generator

    Parameters
    ----------
    ...
    is_valid_value : bool
        The expected value from is_valid()

    """
    k = {'ta_u': ta_u,
         'ta_l': ta_l,
         'tb_u': tb_u,
         'tb_l': tb_l,
         'alpha_b': alpha_b,
         'alpha_c': alpha_c}
    section = NURBS(k)
    assert section.is_valid() is is_valid_value
Exemplo n.º 5
0
def test_area(ta_u, ta_l, tb_u, tb_l, alpha_b, alpha_c):
    r"""Test the area() function of the NURBS generator"""
    k = {'ta_u': ta_u,
         'ta_l': ta_l,
         'tb_u': tb_u,
         'tb_l': tb_l,
         'alpha_b': alpha_b,
         'alpha_c': alpha_c}
    assert NURBS(k).area() > 0.0
Exemplo n.º 6
0
def test_wrong_constructor_values(ta_u, ta_l, tb_u, tb_l, alpha_b, alpha_c):
    r"""Test instantiation with wrong parameters"""
    k = {'ta_u': ta_u,
         'ta_l': ta_l,
         'tb_u': tb_u,
         'tb_l': tb_l,
         'alpha_b': alpha_b,
         'alpha_c': alpha_c}
    with pytest.raises(ValueError):
        NURBS(k)
def nurbs_foil():
    with open(join(getcwd(), "global_best_nurbs.data")) as f:
        lines = f.readlines()

    ta = float(lines[3])
    tb = float(lines[4])
    alpha = float(lines[5])

    k = {
        'ta_u': ta,
        'ta_l': ta,
        'tb_u': tb,
        'tb_l': tb,
        'alpha_b': 2 * alpha,
        'alpha_c': -alpha
    }

    foil = NURBS(k)
    return foil
Exemplo n.º 8
0
    def nurbs_params_changed(self, change):
        r"""The nurbs definition parameters changed

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

        """
        self.k = {
            'ta_u': self.ta_u,
            'ta_l': self.ta_l,
            'tb_u': self.tb_u,
            'tb_l': self.tb_l,
            'alpha_b': self.alpha_b,
            'alpha_c': self.alpha_c
        }
        # self.points = NURBS(self.k).get_coords()
        # x_l, y_l, x_u, y_u = tuple(NURBS(self.k)._spline())
        # print(tuple(NURBS(self.k)._spline()))
        # self.points = (y_u, x_u, y_l, x_l)
        self.points = NURBS(self.k).get_coords()
        self.notify("nurbs_params_changed", change)
Exemplo n.º 9
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
Exemplo n.º 10
0
def example_nurbs_drag():
    r"""Example Nurbs foils drag analysis"""
    reynolds = 100000
    Cl = 0.2

    drags = np.zeros((5, 3))

    tb_u = np.linspace(1.8, 2.2, 6)
    alpha_b = np.linspace(11.1, 12, 4)

    for i in range(1, 6):
        for j in range(1, 4):
            # make new airfoil
            k = dict()
            k['ta_u'] = 0.1584
            k['ta_l'] = 0.1565
            k['tb_u'] = tb_u[i]
            k['tb_l'] = 1.8255
            k['alpha_b'] = alpha_b[j]
            k['alpha_c'] = 3.8270
            nurbs_foil = NURBS(k)

            # make unique filename
            temp_af_filename = "temp_airfoil_{}{}.dat".format(i, j)

            # Save coordinates
            with open(temp_af_filename, 'w') as nurbs_foil_file:
                nurbs_foil_file.write(nurbs_foil.get_coords_plain())

            # Let Xfoil do its thing
            polar = oper_visc_cl(temp_af_filename, Cl, reynolds, iterlim=1000)

            # Save Cd
            try:
                drags[i - 1][j - 1] = polar[0][0][2]
            except IndexError:
                raise Warning("Shit! XFOIL didn't converge on NACA{}{}15 at "
                              "Cl={}.".format(i, j, Cl))

            yu, xu, yl, xl, = nurbs_foil.get_coords()

            def translated_plt(x, y, *args):
                r"""Translated plot

                Parameters
                ----------
                x
                y

                """
                plt.plot(x * 0.8 + (j - .9), y * 0.8 + (i - 0.5), *args)

            translated_plt(yl, xl, 'w')
            translated_plt(yu, xu, 'w')

            os.remove(temp_af_filename)

    print(drags)

    plt.pcolor(drags, cmap=plt.cm.RdBu)
    plt.pcolor(drags, cmap=plt.cm.coolwarm)

    cbar = plt.colorbar()
    cbar.ax.set_ylabel("Drag coefficient $C_d$")
    plt.yticks((.5, 1.5, 2.5, 3.5, 4.5), ("1", "2", "3", "4", "5"))
    plt.xticks((.5, 1.5, 2.5), ("1", "2", "3"))
    plt.tight_layout()
    plt.show()