Reputation: 19
I have a text file filled with points that consist of x, y, and z coordinates of a NACA airfoil. I want to ultimately run a cfd simulation over the wing at different angles of attack using software called simflow. How do I import this data into the software so I can run my simulation?
Upvotes: 1
Views: 570
Reputation:
I'm assuming that your data is delimited and doesn't contain any headers e.g.
1.002 -0.001 -0.002
0.986 0.246 0.234
.
.
1.200 0.897 0.672
Assuming you are on a UNIX or UNIX-like system with Python installed, save the following piece of code as a new file called 'convert_to_obj.py'. This script converts an airfoil .dat file into an '.OBJ' file which can be manually imported into SimFlow before meshing.
#!/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.
To run this script do (from the terminal/command line)
$ python convert_to_obj.py './relative/path/to/airfoil.dat'
Or you can convert a bunch of files at a time
$ python convert_to_obj.py './relative/path/to/airfoil*.dat'
Note that the above script will create vertices. I'm also a bit confused as to why your airfoil has 3 coordinates. Airfoils are two-dimensional. This script will work for 3d data, but will only create vertices.
Upvotes: 1