2. Xfoil Module Documentation

The functions herein defined are purposely made for use with Xfoil.

2.1. Core Function

xfoil_module.call(airfoil, alfas='none', output='Cp', Reynolds=0, Mach=0, plots=False, NACA=False, GDES=False, iteration=10, flap=None)[source]

Call xfoil through Python.

The input variables are:

Parameters:
  • airfoil – if NACA is false, airfoil is the name of the plain filewhere the airfoil geometry is stored (variable airfoil). If NACA is True, airfoil is the naca series of the airfoil (i.e.: naca2244). By default NACA is False.
  • alfas – list/array/float/int of angles of attack.
  • output
    defines the kind of output desired from xfoil. There
    are four posssible choices (by default, Cp is chosen):
    • Cp: generates files with Pressure coefficients for
      desired alfas.
    • Dump: generates file with Velocity along surface, Delta
      star,theta and Cf vs s,x,y for several alfas.
    • Polar: generates file with CL, CD, CM, CDp, Top_Xtr,
      Bot_Xtr.
    • Alfa_L_0: generates a file with the value of the angle
      of attack that lift is equal to zero.
    • Coordinates: returns the coordinates of a NACA airfoil.
  • Reynolds – Reynolds number in case the simulation is for a viscous flow. In case not informed, the code will assume inviscid.
  • Mach – Mach number in case the simulation has to take in account compressibility effects through the Prandtl-Glauert correlation. If not informed, the code will not use the correction. For logical reasons, if Mach is informed a Reynolds number different from zero must also be informed.
  • plots – the code is able to save in a .ps file all the plots of Cp vs.alfa. By default, this option is deactivated.
  • NACA – Boolean variable that defines if the code imports an airfoil from a file or generates a NACA airfoil.
  • GDES – XFOIL function that improves the airfoil shape in case the selected points do not provide a good shape. The CADD function is also used. For more information about these functions, use the XFOIL manual.
  • iteration – changes how many times XFOIL will try to make the results converge. Speciallt important for viscous flows
  • flap – determines if there is a flap. In case there is the expected input is [x_hinge, y_hinge, deflection(angles)]. y_hinge is determined to be exactly in the middle between the upper and lower surfaces.
Return type:

dictionary with outputs relevant to the specific output type

As a side note, it is much more eficient to run a single run with multiple angles of attack rather than multiple runs, each with a single angle of attack.

Created on Sun Mar 9 14:58:25 2014

Last update Fr Jul 13 15:38:40 2015

@author: Pedro Leal (Based on Hakan Tiftikci’s code)

2.2. Auxiliary Functions

xfoil_module.alfa_for_file(alfa)[source]

Generate standard name for angles. This is mainly used by the file_name function.

@author: Pedro Leal

xfoil_module.create_input(x, y_u, y_l, filename)[source]

Create a plain file that XFOIL can read.

XFOIL only reads file from the TE to the LE from the upper part first and then from the LE to the TE through the pressure surface.

Inputs:
  • x: list of coordinates along the chord
  • y_u: list of coordinates normal to the chord for the upper surface
  • y_l: list of coordinates normal to the chord for the lower surface
  • file_name: label used for the file created

Created on Thu Feb 27 2014

@author: Pedro Leal

xfoil_module.create_x(c)[source]

Create set of points along the chord befitting for Xfoil. The x output is conviniently ordered from TE to LE.

Parameters:c – float value for the chord.
Return type:x: numpy.array of values of x

Because Xfoil it is not efficient or sometimes possible to create a uniform distribution of points because the front part of the airfoil requires a big amount of points to create a smooth surface representing the round leading edge. However there is a maximum of points that Xfoil will accept, therefore there is a need to overcome this obstacle. This was done by dividing the airfoil in to 3 parts.

  • tip: correpondent to 0 to .3% of the chord length, it is the most densily populated part of the airfoil to compensate the wide variation of slopes
  • middle: correpondent to .3% to 30% of the chord length ( Shortly above a quarter of the chord length). The second most densily populated and the segment with the most amount of points. Represents the round section of the airfoil except for the tip. Such an amount of points is necessary because it is where most of the lift is generated.
  • endbody: correspondent to 30% to 100% of the chord length. The less densily populated section. Such unrefined mesh is possible because of the simplistic geometry of endbody’s airfoil, just straight lines.
>>> print create_x(1.0)
    array([  1.00000000e+00,   9.82051282e-01,   9.64102564e-01,
    ...
    6.66666667e-04,   3.33333333e-04,   0.00000000e+00])

Created on Thu Feb 27 2014 @author: Pedro Leal

xfoil_module.file_name(airfoil, alfas='none', output='Cp')[source]

Create standard name for the files generated by XFOIL.

Parameters:
  • airfoil – the name of the plain file where the airfoil geometry is stored (variable airfoil).
  • alfas – list/array/float/int of a single angle of attack for Cp and Dump, but the whole list for a Polar. Only the initial and the final values are used
  • output

    defines the kind of output desired from xfoil. There are three posssible choices:

    • Cp: generates files with Pressure coefficients for
      desired alfas
    • Dump: generates file with Velocity along surface, Delta
      star and theta and Cf vs s,x,y for several alfas
    • Polar: generates file with CL, CD, CM, CDp, Top_Xtr,
      Bot_Xtr
    • Alpha_L_0: calculate the angle of attack that lift is
      zero
Returns:

The output has the following format (by default, Cp is chosen):

  • for Cp and Dump: output_airfoil_alfa
    >>> file_name('naca2244', alfas=2.0, output='Cp')
    >>> Cp_naca2244_0200
    
  • for Polar: Polar_airfoil_alfa_i_alfa_f
    >>> file_name('naca2244', alfas=[-2.0, 2.0], output='Polar')
    >>> Polar_naca2244_n0200_0200
    
  • for Alpha_L_0: Alpha_L_0_airfoil
    >>> file_name('naca2244', output='Alpha_L_0')
    >>> Alpha_L_0_naca2244
    

Created on Thu Mar 16 2014 @author: Pedro Leal

xfoil_module.output_reader(filename, separator='\t', output=None, rows_to_skip=0, header=0)[source]

Function that opens files of any kind. Able to skip rows and read headers if necessary.

Inputs:
  • filename: just the name of the file to read.
  • separator: Main kind of separator in file. The code will replace any variants of this separator for processing. Extra components such as end-line, kg m are all eliminated.
  • output: defines what the kind of file we are opening to ensure we can skip the right amount of lines. By default it is None so it can open any other file.
  • rows_to_skip: amount of rows to initialy skip in the file. If the output is different then None, for the different types of files it is defined as: - Polar files = 10 - Dump files = 0 - Cp files = 2
  • header: The header list will act as the keys of the output dictionary. For the function to work, a header IS necessary. If not specified by the user, the function will assume that the header can be found in the file that it is opening.
Output:
  • Dictionary with all the header values as keys

Created on Thu Mar 14 2014 @author: Pedro Leal

xfoil_module.prepare_xfoil(Coordinates_Upper, Coordinates_Lower, chord, reposition=False, FSI=False)[source]

The upper and lower functions will be the points in ordered fashion. Because of the way that XFOIL works the points start at the Trailing Edge on the upper surface going trough the Leading Edge and returning to the Trailing Edge form the bottom surface.

2.3. Utility Functions

xfoil_module.find_coefficients(airfoil, alpha, Reynolds=0, iteration=10, NACA=True)[source]

Calculate the coefficients of an airfoil

xfoil_module.find_alpha_L_0(airfoil, Reynolds=0, iteration=10, NACA=True)[source]

Calculate the angle of attack where the lift coefficient is equal to zero.

xfoil_module.M_crit(airfoil, pho, speed_sound, lift, c)[source]

Calculate the Critical Mach. This function was not validated. Therefore use it with caution and please improve it.

@author: Pedro Leal