Example #1
0
    def test_constructor_NACA4(self):
        #Test NACA 4-series constructor

        naca1234 = Airfoil.NACA4('1234')

        wrong_naca_IDs = [
            'very_wrong',
            '12345',
            'NACA1234',
        ]

        for wrong_naca_ID in wrong_naca_IDs:
            with self.assertRaises(NACADefintionError):
                Airfoil.NACA4(wrong_naca_ID)
Example #2
0
def test_constructor_NACA4():
    """
    Test NACA 4-series constructor
    """

    naca1234 = Airfoil.NACA4('1234')

    wrong_naca_IDs = [
        'very_wrong',
        '12345',
        'NACA1234',
    ]

    for wrong_naca_ID in wrong_naca_IDs:
        with pytest.raises(NACADefintionError):
            Airfoil.NACA4(wrong_naca_ID)
Example #3
0
def test_morph_new_from_two_foils(airfoil):
    """
    Test that 'morph' constructor method works
    """

    Airfoil.morph_new_from_two_foils(airfoil1=airfoil, airfoil2=airfoil, eta=0.5, n_points=100)

    # TODO: add sensible tests here

    wrong_eta_values = [
        -0.1,
        1.2,
    ]

    for wrong_eta in wrong_eta_values:
        with pytest.raises(ValueError):
            Airfoil.morph_new_from_two_foils(airfoil1=airfoil, airfoil2=airfoil, eta=wrong_eta, n_points=100)
Example #4
0
def test_non_monotonic_data():
    x_upper = [0, +0.1, +0.1, +0.5, 1]
    y_upper = [0, +0.3, +0.3, +0.2, 0]
    x_lower = [0, +0.1, +0.5, 1]
    y_lower = [0, -0.3, -0.2, 0]

    upper = np.array([x_upper, y_upper])
    lower = np.array([x_lower, y_lower])

    Airfoil(upper, lower)
Example #5
0
File: main.py Project: dch777/OASYS
 def updategraph(self):
     print(
         self.NACACONVERTER(self.MAXCAMBERSLIDER.value(),
                            self.MAXCAMBERPOSITIONSLIDER.value(),
                            self.THICKNESSSLIDER.value()))
     foil = Airfoil.NACA4(
         self.NACACONVERTER(self.MAXCAMBERSLIDER.value(),
                            self.MAXCAMBERPOSITIONSLIDER.value(),
                            self.THICKNESSSLIDER.value()))
     foil.plot()
Example #6
0
def make_example():
    print('Create example plot... ', end='')
    settings = {
        'file_name': 'example.png',
        'path': HERE,
    }

    Airfoil.NACA4('4812', n_points=300).plot(show=False,
                                             save=True,
                                             settings=settings)
    print('Done!')
Example #7
0
def test_reordering():
    """
    Coordinates sorted from trailing edge to leading edge have to be reordered
    """

    x_upper = X_UPPER[::-1]
    y_upper = Y_UPPER[::-1]
    x_lower = X_LOWER[::-1]
    y_lower = Y_LOWER[::-1]

    Airfoil((x_upper, y_upper), (x_lower, y_lower))
Example #8
0
def test_plotting():
    """
    Test plotting function
    """

    settings = {
        'points': True,
        'camber': True,
        'file_name': 'test.png',
    }

    file_name = Airfoil.NACA4('2412').plot(save=True, settings=settings)
    assert os.path.isfile(file_name)
Example #9
0
    def compares_NACA4_with_file(self,name):
        """
        Tests NACA4 airfoil computed with this module and comapres it with data
        points from http://airfoiltools.com/
        """
        foil = Airfoil.NACA4(name)
        filename = 'naca' + name + '.dat'
        path = os.path.join('airfoil_files/',filename)

        precition = 6
        points_from_file = np.loadtxt(path,skiprows=1)
        points_from_file = np.around(points_from_file,precition)
        N = len(points_from_file)

        points = np.empty([N,2])
        upper = True
        error = []
        
        for p in zip(points,points_from_file):
            if upper:
                res = foil.y_upper(p[1][0])
                res_rounded = np.around(res,decimals=precition)
            else:
                res = foil.y_lower(p[1][0])
                res_rounded = np.around(res,decimals=precition)

            # Finds when to switch to lower surface
            if upper and p[1][0] == 0.:
                upper = False

            p[0][0] = p[1][0]
            p[0][1] = res_rounded
            tab = np.array([p[1][0],res_rounded])
            err = res_rounded - p[1][1]
            error.append(err)
                            
        points_reshaped = np.reshape(points,(1,2*N))
        points_from_file_reshaped = np.reshape(points_from_file,(1,2*N))
        
        test = npt.assert_almost_equal(points,
                                       points_from_file,
                                       decimal=2)
        # TODO: There is probably a better way
        if test is None:
            test = True
        else:
            test = False
        
        self.assertTrue(test)
        return error
def gen_airfoil(xoff, yoff, xscale=1, yscale=1):
	b = np.zeros((height,width), bool)

	foil = Airfoil.NACA4('4812', n_points=height)
	xu = np.copy(foil._x_upper)
	yu = np.copy(foil._y_upper)
	xl = np.copy(foil._x_lower)
	yl = np.copy(foil._y_lower)


	xu *= xscale
	xl *= xscale
	yu *= yscale
	yl *= yscale

	# Set origin by shifting
	xu += xoff
	xl += xoff
	yu += yoff
	yl += yoff

	foil._order_data_points()
	plt.plot(xu, yu, xl, yl)


	def y_up(x):
		return interp1d(
			xu, yu, kind="quadratic", bounds_error=False, fill_value="extrapolate"
		)(x)

	def y_low(x):
		return interp1d(
			xl, yl, kind="quadratic", bounds_error=False, fill_value="extrapolate"
		)(x)


	for x,y in np.ndindex(b.shape):
		if float(y_low(y)) <= x <= float(y_up(y)):
			b[x,y] = True
		else:
			b[x,y] = False

	xmin, xmax = b[:,0].min(), b[:,0].max()
	ymin, ymax = b[:,1].min(), b[:,1].max()

	return b, xmin, xmax, ymin, ymax
Example #11
0
def airfoil():
    return Airfoil(UPPER, LOWER)
Example #12
0
from airfoils import Airfoil

foil = Airfoil.NACA4('4812')
foil.plot()
Example #13
0
def airfoil1():
    return Airfoil.NACA4('1234')
Example #14
0
def airfoil2():
    return Airfoil.NACA4('2412')