DARcorporation / xfoil-python

Stripped down version of XFOIL as compiled python module
GNU General Public License v3.0
87 stars 60 forks source link

Mach number has no effect on calculations #5

Open spinjet opened 4 years ago

spinjet commented 4 years ago

Hello, I've correctly installed your module but when I attempt to set a Mach Number, it doesn't have any effect on the calculations. The coefficients stay the same. Here's a plot with the generated polars of a NACA 0012 with different Mach numbers.

immagine

And this is the code I used:

from xfoil import XFoil
import numpy as np
import matplotlib.pyplot as plt

xf = XFoil()

def loadAirfoil(name):
    with open(name + '.dat') as f:
        content = f.readlines()

    xcrd = []
    ycrd = []

    for line in content[1:]:
        xcrd.append(float(line.split()[0]))
        ycrd.append(float(line.split()[1]))

    airfoilObj = xf.airfoil
    airfoilObj.x = np.array(xcrd)
    airfoilObj.y = np.array(ycrd)

    return airfoilObj

n0012 = loadAirfoil('n0012')

xf.airfoil = n0012
xf.Re = 5e6
xf.max_iter = 100

Mach = np.array([0.0, 0.3, 0.4, 0.5, 0.6, 0.7])

aeroData = []

for m in Mach:
    xf.M = m
    xf.repanel()
    a, cl, cd, cm, cp = xf.aseq(-20,20,0.5)
    aeroData.append([m, [a, cl, cd, cm]])

plt.figure(1)
plt.plot(aeroData[0][1][2], aeroData[0][1][1], label='{:.2f}'.format(aeroData[0][0]))
plt.plot(aeroData[1][1][2], aeroData[1][1][1], label='{:.2f}'.format(aeroData[1][0]))
plt.plot(aeroData[2][1][2], aeroData[2][1][1], label='{:.2f}'.format(aeroData[2][0]))
plt.plot(aeroData[3][1][2], aeroData[3][1][1], label='{:.2f}'.format(aeroData[3][0]))
plt.plot(aeroData[4][1][2], aeroData[4][1][1], label='{:.2f}'.format(aeroData[4][0]))
plt.plot(aeroData[5][1][2], aeroData[5][1][1], label='{:.2f}'.format(aeroData[5][0]))
plt.legend()
plt.xlim([0.0, 0.06])
time-trader commented 4 years ago

I confirm that the current version, doesn't correctly set Mach number and using xf.M, will only compute Sonic Cp and Q/Qinf, and have no effect on Cl,Cd,Cm. The problem lies in src/api.f90. There seems to be confusion between MINf1 and MINf. So adding : MINf1 = M after line 204, seems to solve the issue, and I get the same results as in original XFOIL. Maybe the maintainers can chime in and correct the code or me..

Also I should note that the code will throw an error if you try to set mach number before loading airfoil in python.

And yet another minor but annoying issue is the way the range of angles of attack is defined: it excludes the value of last angle of attack "a_end". Maybe n = abs(int((a_end - a_start) / a_step)) + 1 on line 258 and ... byref(c_float(a_end+np.sign(a_end)*a_step)) ... on line 267 of xfoil.py is more reasonable?

Cheers!

sphh commented 2 years ago

Regarding the ‘annoying issue’: This is modelled after the original behaviour of Python's range() function, which also does not include the endpoint. But I can see the annoyance of such a behaviour. I approached it with those two changes (please note, that his has been moved to the new codeberg repository, and the corresponding issue):

  1. I added the arange() and clrange() methods as synonyms for aseq() and cseq() to show the similarity to the range() function (aseq() and cseq() are still available, but deprecated, to stay backwards compatible).
  2. I added the keyword endpoint to the methods arange(), clrange(). If True, the endpoint will be included (as suggested by you).