def spline_data(file): """ The "spline_data" function takes 1 argument : - file: string, the name of the file which contains the data to load Returns 8 values given by the function "calculate_spline_data", just with the name of the file in argument. """ (nUpper, nLower, ix, iy) = load_foil(file) nUpper = int(nUpper[0]) nLower = int(nLower[0]) return calculate_spline_data(ix, iy, nUpper, nLower)
def spline_data(file): """ The "spline_data" function takes 1 argument : - file: string, the name of the file which contains the data to load Returns 8 values given by the function "calculate_spline_data", just with the name of the file in argument. """ (nUpper,nLower,ix,iy) = load_foil(file) nUpper=int(nUpper[0]) nLower=int(nLower[0]) return calculate_spline_data(ix, iy, nUpper, nLower)
def wings_interpolation(filename, eps=0.001): """ The "wings_interpolation" function takes 2 arguments : - filename: string, the name of the file to load - eps: real, step for x Returns tables of cubic-spline interpolated values y, for x from 0 to 1 (step eps), for the upper and lower part. """ (nUpper, nLower, ix, iy) = load_foil(filename) nUpper = int(nUpper[0]) nLower = int(nLower[0]) return splint_improved(ix, iy, nUpper, nLower, eps)
def wings_interpolation(filename,eps=0.001): """ The "wings_interpolation" function takes 2 arguments : - filename: string, the name of the file to load - eps: real, step for x Returns tables of cubic-spline interpolated values y, for x from 0 to 1 (step eps), for the upper and lower part. """ (nUpper,nLower,ix,iy) = load_foil(filename) nUpper=int(nUpper[0]) nLower=int(nLower[0]) return splint_improved(ix, iy, nUpper, nLower, eps)
def get_foil(a, b, N, file): (dim, ex, ey, ix, iy) = load_foil(file) pas = (b - a) / N ex2 = [a + pas * k for k in range(N + 1)] ey2 = [splint(ex, ey, x) for x in ex2] ix2 = [a + pas * k for k in range(N + 1)] iy2 = [splint(ix, iy, x) for x in ix2] return ex2, ey2, ix2, iy2
def test_foil(): file = "foil.txt" (dim, ex, ey, ix, iy) = load_foil(file) (ex2, ey2, ix2, iy2) = get_foil(0, 1, 100, file) plt.axis('equal') plt.plot(ex, ey, 'o') plt.plot(ix, iy, 'o') plt.plot(ex2, ey2) plt.plot(ix2, iy2) plt.show()
def test_wing(filename, eps=0.001): """ The "test_wing" function takes 2 arguments : - filename: string, the name of the file to load - eps: real, step for x Checks that every yTable data are consonant with the yUpper and yLower arrays data """ (nx1, nx2, xTable, yTable) = load_foil(filename) nUpper = int(nx1[0]) nLower = int(nx2[0]) yUpper, yLower = splint_improved(xTable, yTable, nUpper, nLower, eps) x = [0] i = 0 while (x[i] < 1): x += [x[i] + eps] i += 1 x = x[:(len(yUpper))] for i in range(nUpper): if (xTable[i] in x): assert (yTable[i] in yUpper) for i in range(nUpper, nLower, 1): if (xTable[i] in x): assert (yTable[i] in yLower) print("Test interpolation : PASSED.")
def test_wing(filename, eps=0.001): """ The "test_wing" function takes 2 arguments : - filename: string, the name of the file to load - eps: real, step for x Checks that every yTable data are consonant with the yUpper and yLower arrays data """ (nx1,nx2,xTable,yTable) = load_foil(filename) nUpper=int(nx1[0]) nLower=int(nx2[0]) yUpper,yLower = splint_improved(xTable, yTable, nUpper, nLower, eps) x=[0] i=0 while (x[i]<1): x+=[x[i]+eps] i+=1 x=x[:(len(yUpper))] for i in range (nUpper): if (xTable[i] in x): assert(yTable[i] in yUpper) for i in range (nUpper,nLower,1): if (xTable[i] in x): assert(yTable[i] in yLower) print("Test interpolation : PASSED.")
a = (xa[khi] - x) / h b = (x - xa[klo]) / h return a * ya[klo] + b * ya[khi] + (((a**3) - a) * y2a[klo] + ( (b**3) - b) * y2a[khi]) * (h * h) / 6.0 # Return the spline function passing through each provided point where # xa is the array containing the x coordinate of each point # ya is the array containing the y coordinate of each point # n is the number of points def spline_fun(xa, ya, n): y2 = spline(xa, ya, n) return lambda x: splint(xa, ya, y2, n, x) if __name__ == "__main__": (dim, ex, ey, ix, iy) = lf.load_foil("k1.dat") espline = spline_fun(ex, ey, int(dim[0])) ispline = spline_fun(ix, iy, int(dim[1])) r = np.arange(0, 1.00001, 0.001) mp.plot(r, list(map(espline, r)), linewidth=1.0) mp.plot(ex, ey, marker='.', linestyle="None") mp.plot(r, list(map(ispline, r)), linewidth=1.0) mp.plot(ix, iy, marker='.', linestyle="None") mp.axis('equal') mp.title("Cubic spline interpolation of the airfoil") mp.show()
-f is a cubic-spline interpolating g -n is the length of x Returns average of relatives error between f and y """ cpt = 0.0 for i in range(0, n): if (y[i] > 1e-6): cpt = cpt + (f(x[i]) - y[i]) / y[i] cpt = cpt / n return cpt #--------------------------------------------------- #-------Airfoil refinment, application-------------- #--------------------------------------------------- (ex, ey, ix, iy) = foil.load_foil("goe281.dat") plt.plot(ex, ey) plt.plot(ix, iy) plt.title("Wing curve goe281 without spline") #plt.axis([-0.1,1.1,-0.1,1.1]) plt.savefig("goe281_no_spline") plt.show() #Taille des tableaux de points de l'aile #e correspond à extrados #i correspond à intrados ne = ex.shape[0] ni = ix.shape[0] #On prend les dérivées premières comme nulles yp1 = 0.0
-x is an array containing abscissae -y is an array containing the values of g(x). y[i] = g(x[i]) -f is a cubic-spline interpolating g -n is the length of x Returns average of relatives error between f and y """ cpt = 0.0 for i in range(0,n): if( y[i] > 1e-6 ): cpt = cpt + (f(x[i]) - y[i])/y[i] cpt = cpt / n return cpt #--------------------------------------------------- #-------Airfoil refinment, application-------------- #--------------------------------------------------- (ex,ey,ix,iy) = foil.load_foil("goe281.dat") plt.plot(ex,ey) plt.plot(ix,iy) plt.title("Wing curve goe281 without spline") #plt.axis([-0.1,1.1,-0.1,1.1]) plt.savefig("goe281_no_spline") plt.show() #Taille des tableaux de points de l'aile #e correspond à extrados #i correspond à intrados ne = ex.shape[0] ni = ix.shape[0] #On prend les dérivées premières comme nulles yp1 = 0.0
# Import import os import sys import numpy as np import matplotlib.pyplot as mp import load_foil as fl # Constante globale epsilon = 0.1**2 # Variable globale (chargee a partir de foilload) (ex, ey, ix, iy) = fl.load_foil('BACNLF.DAT'); # Aile extrados def extrados(ix, iy): extrados_x = []; extrados_y = []; for i in range(0, ix.size-1): if(iy[i]>=0): extrados_x.append(ix[i]); extrados_y.append(iy[i]); return (extrados_x, extrados_y); # Aile intrados def intrados(ix, iy): intrados_x = []; intrados_y = []; for i in range(0, ix.size-1): if(iy[i]<=0): intrados_x.append(ix[i]); intrados_y.append(iy[i]);
## Import import numpy as np import matplotlib.pyplot as mp import load_foil as fl # Constantes eps = 0.1 ** 2 (ex, ey, ix, iy) = fl.load_foil("BACNLF.DAT") # Fonction mettant en equation les polynomes interpolateurs de lagrange def lagrange_polynomial(x1, x2, y1, y2): def lagrange(x): A = (x - x2) / (x1 - x2) B = (x - x1) / (x2 - x1) C = y1 * A + y2 * B return C return lagrange # Fonction permettant de mettre en place es derivees def lagrange_derivative(x1, x2, y1, y2): def deriv(x): A = 1 / (x1 - x2) B = 1 / (x2 - x1) C = y1 * A + y2 * B return C return deriv