Ejemplo n.º 1
0
def hello():
    x = request.args.get('x')
    y = request.args.get('y')
    Re = float(request.args.get('Re'))
    M = float(request.args.get('M'))
    Alpha = float(request.args.get('Alpha'))
    x = x.split()
    y = y.split()
    ctrlX = [float(ele) for ele in x]
    ctrlY = [float(ele) for ele in y]
    bezierX, bezierY = airfoil(ctrlX, ctrlY, 16)

    xf = XFoil()
    xf.Re = Re
    xf.M = 0
    xf.max_iter = 100
    xf.airfoil = Airfoil(np.array(bezierX), np.array(bezierY))
    aero = xf.a(Alpha)
    xcp, cp = xf.get_cp_distribution()
    y = savgol_filter(cp, 5, 2)
    for i in range(30):
        y = savgol_filter(y, 5, 2)
    LD = aero[0] / aero[1]
    vol = PolyArea(bezierX, bezierY)

    print(len(xcp))

    return jsonify(result=str(round(aero[0], 3)) + " " +
                   str(round(aero[1], 3)) + " " + str(round(aero[2], 3)) +
                   " " + str(round(LD, 2)) + " " + str(round(vol, 3)),
                   xcp=xcp.tolist(),
                   cp=y.tolist())
Ejemplo n.º 2
0
def alpha_inv_analysis(airfoil, alpha_i, alpha_f, alpha_step, max_iter, id):
    """Inviscid analysis over range of angle of attacks."""
    # Initializes airfoil and assigns NACA
    xf = XFoil()
    xf.naca(airfoil)
    xf.max_iter = max_iter
    # Collects values
    a, cl, cd, cm, cp = xf.aseq(alpha_i, alpha_f, alpha_step)
    x, cp_0 = xf.get_cp_distribution()
    # Plots all the data
    plot(a, cl, cd, cm, cp, x, cp_0, id)
Ejemplo n.º 3
0
def cl_visc_analysis(airfoil, cl_i, cl_f, cl_step, re, mach, max_iter, id):
    """Viscous analysis over range of lift coefficients."""
    # Initializes airfoil and assigns NACA
    xf = XFoil()
    xf.naca(airfoil)
    xf.max_iter = max_iter
    xf.Re = re
    xf.M = mach
    # Collects values
    a, cl, cd, cm, cp = xf.cseq(cl_i, cl_f, cl_step)
    x, cp_0 = xf.get_cp_distribution()
    # Plots all the data
    plot(a, cl, cd, cm, cp, x, cp_0, id)
Ejemplo n.º 4
0
def feature_xfoil(cst_u,
                  cst_l,
                  t,
                  Minf: float,
                  Re,
                  AoA,
                  n_crit=0.1,
                  fname='feature-xfoil.txt'):
    '''
    Evaluate by xfoil and extract features.

    Inputs:
    ---
    cst-u, cst-l:   list of upper/lower CST coefficients of the airfoil. \n
    t:      airfoil thickness or None \n
    Minf:   free stream Mach number for wall Mach number calculation \n
    Re, AoA (deg): flight condition (s), float or list, for Xfoil \n
    n_crit: critical amplification ratio for transition in xfoil \n
    fname:  output file name. If None, then no output \n

    ### Dependencies: cst-modeling3d, xfoil  
    '''

    from cst_modeling.foil import cst_foil
    from xfoil import XFoil
    from xfoil.model import Airfoil

    #TODO: Build foil
    #! 201 is the maximum amount of points that xfoil can handle
    #! tail = 0.001 is to avoid point overlap
    xx, yu, yl, t0, R0 = cst_foil(201, cst_u, cst_l, x=None, t=t, tail=0.001)

    #! xfoil do not support leading edge of (0,0) on both upper and lower surface
    x = np.array(list(reversed(xx[1:])) + xx[1:])
    y = np.array(list(reversed(yu[1:])) + yl[1:])
    foil = Airfoil(x, y)

    #TODO: Xfoil
    xf = XFoil()
    xf.print = False
    xf.airfoil = foil
    xf.max_iter = 40

    #* Transition by power law
    xf.n_crit = n_crit

    #TODO: Xfoil calculation
    if not isinstance(Re, list):
        Re = [Re]
        AoA = [AoA]

    n = len(Re)
    for i in range(n):

        xf.reset_bls()

        if Re[i] is not None:
            xf.Re = Re[i]

        cl, cd, cm, cp = xf.a(AoA[i])
        x, cp = xf.get_cp_distribution()

        print(xf.Re, AoA[i], cl)

        #* Extract features
        fF = PhysicalXfoil(Minf, AoA[i], Re[i])
        fF.setdata(x, y, cp)
        fF.extract_features()

        #* Output
        if fname is None:
            continue

        if i == 0:
            f = open(fname, 'w')
        else:
            f = open(fname, 'a')

        f.write('\n')
        f.write('%10s   %15.6f \n' % ('Minf', Minf))
        f.write('%10s   %15.6f \n' % ('AoA', AoA[i]))
        f.write('%10s   %15.6f \n' % ('Re', Re[i] / 1e6))
        f.write('%10s   %15.6f \n' % ('CL', cl))
        f.write('%10s   %15.6f \n' % ('Cd', cd))
        f.write('%10s   %15.6f \n' % ('Cm', cm))
        f.close()

        fF.output_features(fname=fname, append=True)
Ejemplo n.º 5
0
    xf = XFoil()
    xf.print = False
    xf.max_iter = 40
    xf.airfoil = foil
    xf.xtr = [0.0, 0.0]

    Minf = 0.2
    AoA  = 8.0
    Re   = 1e7
    fname = 'feature-xfoil.txt'

    xf.M = Minf
    xf.Re = Re

    cl, cd, cm, cp = xf.a(AoA)
    x, cp = xf.get_cp_distribution()

    with open(fname, 'w') as f:
        f.write('%10s   %15.6f \n'%('Minf', Minf))
        f.write('%10s   %15.6f \n'%('AoA', AoA))
        f.write('%10s   %15.6f \n'%('Re', Re/1e6))
        f.write('%10s   %15.6f \n'%('CL', cl))
        f.write('%10s   %15.6f \n'%('Cd', cd))
        f.write('%10s   %15.6f \n'%('Cm', cm))

    fF = PhysicalXfoil(Minf, AoA, Re)
    fF.setdata(x,y,cp)
    fF.extract_features()
    fF.output_features(fname=fname, append=True)

    t1 = time.perf_counter()