Aifroil plottin通过python在Spyder中使用数据文件而不使用法院线

2024-09-28 03:23:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用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);

并从翼型.comnaca0012 data file使用(将名称“n0012.dat”更改为“naca0012.dat”,并删除文件中的标题,因为程序不使用数据文件中的字符串)

在本课中,请看下面的图

但我用的是代码图这包括了球场线

有什么不对劲,那是什么


Tags: fromimportnumpydataplotoswidthinfile
1条回答
网友
1楼 · 发布于 2024-09-28 03:23:11

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

Selig的格式从机翼的后缘开始,经过上表面,然后经过下表面,回到后缘

Lednicer格式列出上表面上的点(从前缘到后缘),然后列出下表面上的点(从前缘到后缘)

您可以按如下方式加载Selig格式(跳过标题“NACA 0012翼型”,在numpy.loadtxt中使用skiprows=1):

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)

此处NACA0012翼型包含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点(前缘点重复),上表面上的点将翻转(从前缘到后缘)。 (这就是为什么你在中间用^ {CD6>}来观察这条线,这条线将后缘从上表面连接到下表面的前缘。)

按照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

相关问题 更多 >

    热门问题