matplotlib 用Python在Spyder中实现无法院线数据文件的翼型绘制

nc1teljy  于 2023-03-03  发布在  Python
关注(0)|答案(1)|浏览(209)

我使用的是Barba集团的AeroPython codes;

#import libraries and modules needed
import os
import numpy
from scipy import integrate, linalg
from matplotlib import pyplot

# load geometry from data file
naca_filepath = os.path.join('resources', 'naca0012.dat')
with open(naca_filepath, 'r') as infile:
    x, y = numpy.loadtxt(infile, dtype=float, unpack=True)

# plot geometry
width = 10
pyplot.figure(figsize=(width, width))
pyplot.grid()
pyplot.xlabel('x', fontsize=16)
pyplot.ylabel('y', fontsize=16)
pyplot.plot(x, y, color='k', linestyle='-', linewidth=2)
pyplot.axis('scaled', adjustable='box')
pyplot.xlim(-0.1, 1.1)
pyplot.ylim(-0.1, 0.1);

并从airfoil.comnaca0012 data file使用(将名称“n0012.dat”更改为“naca0012.dat”并删除文件内的标题,因为程序不使用数据文件中的字符串)
在这节课上看起来像这样

但我用的是包括球场线在内的编码图

有什么不对劲,到底是什么?

hgncfbus

hgncfbus1#

翼型数据库的链接包含Lednicer格式的NACA 0012坐标,而AeroPython课程中的代码是为Selig格式的翼型编写的(Notebook使用源面板方法计算翼型周围的流动)。

Selig格式从机翼后缘开始,经过上表面,然后经过下表面,回到后缘。
Lednicer格式列出上表面上的点(从前缘到后缘),然后列出下表面上的点(从前缘到后缘)。

可按如下方式加载Selig格式(跳过标题“NACA 0012 AIRFOILS”,skiprows=1numpy.loadtxt中):

import urllib

# Retrieve and save geometry to file.
selig_url = 'http://airfoiltools.com/airfoil/seligdatfile?airfoil=n0012-il'
selig_path = 'naca0012-selig.dat'
urllib.request.urlretrieve(selig_url, selig_path)
# Load coordinates from file.
with open(selig_path, 'r') as infile:
    x1, y1 = numpy.loadtxt(infile, unpack=True, skiprows=1)

NACA 0012翼型包含131个点,您将看到后缘具有有限厚度:

print('Number of points:', x1.size)  # -> 131
print(f'First point: ({x1[0]}, {y1[0]})')  # -> (1.0, 0.00126)
print(f'Last point: ({x1[-1]}, {y1[-1]})')  # -> (1.0, -0.00126)

如果你对Lednicer的格式做同样的处理(头部为skiprows=2),你将加载132点(前缘点是重复的),上表面上的点被翻转(从前缘到后缘)。(这就是为什么你在中间观察到这条线pyplot.plot;该线连接从上表面的后缘到从下表面的前缘)。
重新定向点以遵循Selig格式的一种方法是跳过上表面上的前缘(即跳过复制的点)并翻转上表面上的点。以下是一种可能的解决方案:

import numpy

# Retrieve and save geometry to file.
lednicer_url = 'http://airfoiltools.com/airfoil/lednicerdatfile?airfoil=n0012-il'
lednicer_path = 'naca0012-lednicer.dat'
urllib.request.urlretrieve(lednicer_url, lednicer_path)

# Load coordinates from file (re-orienting points in Selig format).
with open(lednicer_path, 'r') as infile:
    # Second line of the file contains the number of points on each surface.
    _, info = (next(infile) for _ in range(2))
    # Get number of points on upper surface (without the leading edge).
    num = int(info.split('.')[0]) - 1
    # Load coordinates, skipping the first point (leading edge on upper surface).
    x2, y2 = numpy.loadtxt(infile, unpack=True, skiprows=2)
    # Flip points on the upper surface.
    x2[:num], y2[:num] = numpy.flip(x2[:num]), numpy.flip(y2[:num])

您将以131点结束,其方向与Selig格式相同。

print('Number of points:', x2.size)  # -> 131
print(f'First point: ({x2[0]}, {y2[0]})')  # -> (1.0, 0.00126)
print(f'Last point: ({x2[-1]}, {y2[-1]})')  # -> (1.0, -0.00126)

最后,我们还可以检查坐标是否与numpy.allclose相同:

assert numpy.allclose(x1, x2, rtol=0.0, atol=1e-6)  # -> True
assert numpy.allclose(y1, y2, rtol=0.0, atol=1e-6)  # -> True

相关问题