Example #1
0
def get_max_cl(Re, r):
    """
    Analyze airfoil at a fixed Re,
    changing aoa from 10 to 15 by 0.1
    and returns cl, cd, aoa that makes maximum cl
    """
    xf = XFoil()
    if r <= 0.175:
        xf.airfoil = naca6409
    else:
        xf.airfoil = naca2412
    xf.Re = Re
    xf.Re = Re
    xf.max_iter = 200
    xf.n_crit = 9.00
    xf.xtr = [1.00, 1.00]
    xf.M = 0
    a_seq, cl_seq, cd_seq, cm_seq, cp_seq = xf.aseq(10, 15, 0.1)
    # ignore nan by making it 0
    cl_seq = np.nan_to_num(cl_seq)
    # find the maximum cl
    cl_maxi = np.max(cl_seq)
    # index of the maximum cl
    idx = np.argmax(cl_seq)
    return round(cl_maxi, 2), round(a_seq[idx], 2), round(cd_seq[idx], 2)
Example #2
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())
Example #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)
Example #4
0
def alpha_visc_analysis(airfoil, alpha_i, alpha_f, alpha_step, re, mach,
                        max_iter, id):
    """Viscous analysis over range of angle of attacks."""
    # 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.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)
def get_torque(angular_velocity):
    torque_sum_small = 0
    torque_sum_large = 0
    w = angular_velocity
    for key, value in dfdict.items():
        value["blade_velocity"] = value['r_position'] * w
        value["relative_velocity"] = round(
            math.sqrt(value["blade_velocity"]**2 + value["wind_velocity"]**2),
            2)
        value["arctan"] = math.degrees(
            math.atan2(value["wind_velocity"], value["blade_velocity"]))
        aoa = round(value["arctan"] - value["pitch_angle"], 2)
        value["angle_of_attack"] = aoa
        re_n = round(
            value["relative_velocity"] * value["chord_length"] / 0.00001511, 3)
        value["Reynolds_number"] = re_n
        xf = XFoil()
        if key < 13:
            xf.airfoil = naca6409
        else:
            xf.airfoil = naca2412
        xf.Re = re_n
        xf.max_iter = 100
        xf.n_crit = 9.00
        xf.xtr = [1.00, 1.00]
        xf.M = 0
        value["Cl"], value["Cd"], value["Cm"], value["Cp"] = xf.a(aoa)
        force_reference = 0.5 * density * value["relative_velocity"]**2
        if math.isnan(value["Cl"]):
            value["torque"] = 0
        else:
            lift = value["Cl"] * force_reference * 0.0125 * value[
                'chord_length']
            drag = value["Cd"] * force_reference * 0.0125 * value[
                'chord_length']
            value["torque"] = value["r_position"] * (
                lift * math.sin(math.radians(value["pitch_angle"])) -
                drag * math.cos(math.radians(value["pitch_angle"])))
        if key < 13:
            torque_sum_small += value["torque"]
        else:
            pass
        if key > 0:
            torque_sum_large += value["torque"]
        else:
            pass
    df2 = pd.DataFrame.from_dict(dfdict, orient="index")
    df_collection.append(df2)
    torque_sum_avg = 0.5 * (torque_sum_small + torque_sum_large)
    return torque_sum_avg
def total_dict(angular_velocity):
    torque_sum = 0
    w = angular_velocity
    for key, value in dfdict.items():
        value["blade_velocity"] = value['r_position'] * w
        value["relative_velocity"] = round(
            math.sqrt(value["blade_velocity"]**2 + value["wind_velocity"]**2),
            2)
        value["arctan"] = math.degrees(
            math.atan2(value["wind_velocity"], value["blade_velocity"]))
        aoa = round(value["arctan"] - value["pitch_angle"], 1)
        value["angle_of_attack"] = aoa
        re_n = round(value["relative_velocity"] * value["chord_length"] /
                     0.00001511)
        value["Reynolds_number"] = re_n
        xf = XFoil()
        if key < 13:
            xf.airfoil = naca6409
        else:
            xf.airfoil = naca2412
        xf.Re = round(re_n / 100) * 100
        xf.max_iter = 200
        xf.n_crit = 9.00
        xf.xtr = [1.00, 1.00]
        xf.M = 0
        c_l, c_d, c_m, c_p = xf.a(aoa)
        force_reference = 0.5 * density * value["relative_velocity"]**2
        if math.isnan(c_l):
            pass
        else:
            value["Cl"] = c_l
            value["Cd"] = c_d
            value["Cm"] = c_m
            value["Cp"] = c_p
            lift = c_l * force_reference * 0.0125 * value['chord_length']
            drag = c_d * force_reference * 0.0125 * value['chord_length']
            value["lift"] = lift
            value["drag"] = drag
            # value["torque"] = value["r_position"] * lift * math.sin(math.radians(value["pitch_angle"]))
            torque = value["r_position"] * (
                lift * math.sin(math.radians(value["pitch_angle"])) -
                drag * math.cos(math.radians(value["pitch_angle"])))
            value["torque"] = torque
            torque_sum += torque
        xf.reset_bls()
    # detailed_df = pd.DataFrame.from_dict(dfdict, orient="index")
    # print(detailed_df)
    print(torque_sum, angular_velocity)
    return dfdict, torque_sum
    c = (a_max * 8 * pi * r * math.sin(phi) ** 2) / ((1 - a_max) * prop_blades * c_l * math.cos(phi))
    re = (v_r * c) / (nu_mars)

    # XFOIL #######

    from xfoil import XFoil
    xf = XFoil()

    # Import an airfoil
    from xfoil.test import XXXXX
    xf.airfoil = XXXXX

    # Setting up the analysis parameters
    xf.Re = re
    xf.max_iter = 100
    xf.M = 0.7

    # Obtaining the angle of attack, lift coefficient, drag coefficient and momentum coefficient of the airfoil
    a, cl, cd, cm = xf.aseq(0, 30, 0.5)











Example #8
0
def analyze_airfoil(x,
                    y_u,
                    y_l,
                    cl,
                    rey,
                    mach=0,
                    xf=None,
                    pool=None,
                    show_output=False):
    """
    Analyze an airfoil at a given lift coefficient for given Reynolds and Mach numbers using XFoil.

    Parameters
    ----------
    x : array_like
        Airfoil x-coordinates
    y_u, y_l : array_like
        Airfoil upper and lower curve y-coordinates
    cl : float
        Target lift coefficient
    rey, mach : float
        Reynolds and Mach numbers
    xf : XFoil, optional
        An instance of the XFoil class to use to perform the analysis. Will be created if not given
    pool : multiprocessing.ThreadPool, optional
        An instance of the multiprocessing.Threadpool class used to run the xfoil_worker. Will be created if not given
    show_output : bool, optional
        If True, a debug string will be printed after analyses. False by default.

    Returns
    -------
    cd, cm : float or np.nan
        Drag and moment coefficients of the airfoil at specified conditions, or nan if XFoil did not run successfully
    """
    # If the lower and upper curves swap, this is a bad, self-intersecting airfoil. Return 1e27 immediately.
    if np.any(y_l > y_u):
        return np.nan
    else:
        clean_xf = False
        if xf is None:
            xf = XFoil()
            xf.print = show_output
            clean_xf = True

        clean_pool = False
        if pool is None:
            pool = ThreadPool(processes=1)
            clean_pool = True

        xf.airfoil = Airfoil(x=np.concatenate((x[-1:0:-1], x)),
                             y=np.concatenate((y_u[-1:0:-1], y_l)))
        xf.Re = rey
        xf.M = mach
        xf.max_iter = 100
        xf.n_crit = 0.1
        cd, cm = pool.apply(xfoil_worker, args=(xf, cl))

    if clean_xf:
        del xf
    if clean_pool:
        del pool

    return cd, cm, None if clean_xf else xf
Example #9
0
#!/usr/bin/python3
from xfoil import XFoil
import matplotlib.pyplot as plt
xf = XFoil()

xf.load("revclarky.dat")
xf.Re = 1e5
xf.M = 0
xf.max_iter = 100
a, cl, cd, cm, cp = xf.aseq(-2, 2, 0.5)
plt.plot(a, cl)
plt.title("alfa vs cl")
plt.show()

#plt.plot(xf.airfoil.x,xf.airfoil.y)
#plt.axis('equal')
#plt.show()
Example #10
0
    y = np.concatenate((np.flip(yu[1:]), yl[1:]), axis=0)
    foil = Airfoil(x, y)

    #TODO: Xfoil
    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)