我有一个文本文件,其中充满了由NACA翼型的x、y和z坐标组成的点。我想最终使用名为simflow的软件在不同攻角的机翼上运行cfd模拟。如何将此数据导入到软件中,以便运行我的模拟?
发布于 2017-11-25 05:11:20
我假设您的数据是有分隔符的,并且不包含任何标头。
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数据,但仅创建顶点。
https://stackoverflow.com/questions/44802742
复制相似问题