我的文本文件中填充了由NACA翼型的x,y和z坐标组成的点。我想最终使用名为simflow的软件在不同攻角下对机翼进行cfd模拟。如何将此数据导入软件以便运行模拟?
答案 0 :(得分:1)
我假设您的数据是分隔的,并且不包含任何标题,例如
1.002 -0.001 -0.002
0.986 0.246 0.234
.
.
1.200 0.897 0.672
假设您使用的是安装了Python的UNIX或类UNIX系统,请将以下代码保存为名为“convert_to_obj.py”的新文件。此脚本将翼型.dat文件转换为'.OBJ'文件,可在网格化之前手动导入SimFlow。
#!/usr/bin/env python
'''
Script to convert a NACA airfoil in the Selig format into an OBJ file
which can be read by SimFlow.
'''
# Make sure that your airfoil .dat file has the '.dat' extension!!!!
# Argument parser from the command line
import argparse
parser = argparse.ArgumentParser( description='Script to convert a NACA'
'airfoil in the Selig format into an'
' OBJ file that can be read by SimFlow')
parser.add_argument('files', type=str,
help='Choose files to convert, specify path.'
' Enclose entire path in single-quotes')
args = parser.parse_args()
# Import and convert file
import glob
AllFiles = glob.glob( args.files)
for datfile in AllFiles:
InFileID = open( datfile, 'r')
# If you have header files in the .dat file, specify the number of
# header lines below. (for Selig, numheader = 1)
numheader = 0
for i in range(numheader):
InFileID.readline()
# Slurp all the remaining lines of the .dat file and close it
DataLines = InFileID.readlines()
InFileID.close()
# Open a new file to write to (change extension)
OutFileID = open( datfile[:-4] + '.OBJ', 'w')
# Write the name of the group (in our case, its just 'Airfoil')
OutFileID.write('g Airfoil\n')
for line in DataLines:
OutFileID.write('v ' + line )
OutFileID.close()
# This should create an .OBJ file that can be imported into SimFlow.
要运行此脚本,请执行(从终端/命令行)
$ python convert_to_obj.py './relative/path/to/airfoil.dat'
或者您可以一次转换一堆文件
$ python convert_to_obj.py './relative/path/to/airfoil*.dat'
请注意,上面的脚本将创建顶点。我也有点困惑为什么你的翼型有3个坐标。翼型是二维的。此脚本适用于3d数据,但只会创建顶点。