1

我有一个文本文件,其中填充了由 NACA 翼型的 x、y 和 z 坐标组成的点。我想最终使用名为 simflow 的软件以不同的攻角在机翼上运行 cfd 模拟。如何将这些数据导入到软件中以便运行模拟?

4

1 回答 1

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 数据,但只会创建顶点。

于 2017-11-24T21:11:19.993 回答