├── images ├── output.PNG └── parameters.PNG ├── LICENSE.md ├── xfoil_bem_tool.py └── README.md /images/output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewvigne/xfoil_bem_tool/HEAD/images/output.PNG -------------------------------------------------------------------------------- /images/parameters.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewvigne/xfoil_bem_tool/HEAD/images/parameters.PNG -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Andrew Vigne, George Loubimov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /xfoil_bem_tool.py: -------------------------------------------------------------------------------- 1 | """ 2 | Authors: Andrew Vigne, George Loubimov 3 | 4 | Script to quickly extract Re vs. AoA, Cl, and Cd 5 | for any given airfoil geometry using XFoil. 6 | Made for Blade Element Momentum virtual disks. 7 | 8 | Created: 8/13/2020 9 | """ 10 | 11 | from subprocess import Popen, PIPE, STDOUT 12 | import numpy as np 13 | import itertools as itr 14 | import csv 15 | 16 | def xfoil_interact(foil, re, alfa_strt, alfa_end, alfa_step): 17 | def get_cmd(foil, re, alfa_strt, alfa_end, alfa_step): 18 | 19 | if foil is not None: 20 | load_cmd = 'LOAD ' + foil 21 | else: 22 | load_cmd = 'NACA 0012' 23 | cmd = ''' 24 | {} 25 | 26 | OPER 27 | VISC {} 28 | ITER 29 | 1000 30 | PACC 31 | OUTPUT/{}_SAVE 32 | 33 | ASEQ 34 | {} 35 | {} 36 | {} 37 | 38 | '''.format(load_cmd, re, re, alfa_strt, alfa_end, alfa_step) 39 | 40 | return cmd 41 | 42 | p = Popen(['C:\\XFoil\\xfoil.exe'], stdout=PIPE, stdin=PIPE, stderr=STDOUT) 43 | stdout = p.communicate(input=get_cmd(foil=foil, re=re, alfa_strt=alfa_strt, 44 | alfa_end=alfa_end, 45 | alfa_step=alfa_step).encode())[0] 46 | print(stdout) 47 | print('=====================================================') 48 | 49 | return None 50 | 51 | ######################## PARAMETERS ######################## 52 | 53 | re_strt = 200000 54 | re_end = 270000 55 | re_step = 10000 56 | re_num = int((re_end-re_strt)/re_step) + 1 57 | 58 | 59 | alfa_strt = 0 60 | alfa_end = 10 61 | alfa_step = 5 62 | alfa_num = int((alfa_end-alfa_strt)/alfa_step) + 1 63 | 64 | foil = None # None or file name 'example.dat' 65 | 66 | tbl = np.zeros([int(re_num*alfa_num), 4]) # main output in csv 67 | 68 | ############################################################ 69 | 70 | i = 0 71 | for re in range(re_strt , re_end+re_step, re_step): 72 | xfoil_interact(foil, re, alfa_strt, alfa_end, alfa_step) 73 | i = i + 1 74 | tbl_end = alfa_num*i 75 | 76 | if i == 1: 77 | tbl_strt = 0 78 | else: 79 | tbl_strt = alfa_num*i-alfa_num 80 | 81 | aa_list = [] 82 | cl_list = [] 83 | cd_list = [] 84 | 85 | tbl[tbl_strt:tbl_end,0] = re # stores set of Reynolds 86 | 87 | with open('output/{}_save'.format(re),'r') as infile: 88 | for x in itr.islice(infile, 12, None): # ignores first 13 lines 89 | x = x.split() 90 | aa_list.append(float(x[0])) 91 | cl_list.append(float(x[1])) 92 | cd_list.append(float(x[2])) 93 | 94 | tbl[tbl_strt:tbl_end,1] = aa_list 95 | tbl[tbl_strt:tbl_end,2] = cl_list 96 | tbl[tbl_strt:tbl_end,3] = cd_list 97 | 98 | outfile = open('output/outfile.csv', 'w+', newline = '') 99 | with outfile: 100 | write = csv.writer(outfile) 101 | write.writerows(tbl) 102 | 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XFoil BEM Tool 2 | Python script to quickly extract Re vs. AoA, Cl, and Cd for any given airfoil geometry using XFoil. Made for Blade Element Momentum (BEM) applications with computational fluid dynamics software. 3 | 4 | ### About 5 | The cycling industry has long relied on expensive wind tunnel testing when designing new aerodynamic products. However, with the recent advent of computational fluid dynamics (CFD), the industry now has an economical tool that supplements this iterative design process. While current CFD methods can reliably simulate static bicycle components, the complex aerodynamics of rotating, spoked wheels make them particularly difficult to efficiently simulate as they consume valuable computational time. My research project investigates a new CFD method that can accurately model a bicycle wheel at a lower computational cost. 6 | 7 | XFoil BEM Tool was specifically made for my research project. While this was its specific application, this script can be useful in any context involving BEM and CFD. It is particularly good with Star-CCM+. 8 | 9 | ### Requirements 10 | - [XFoil 6.99](https://web.mit.edu/drela/Public/web/xfoil/) 11 | - [Python 3.8.5](https://www.python.org/downloads/) 12 | - [Spyder IDE (preffered)](https://www.spyder-ide.org/) 13 | 14 | ## Installation 15 | 16 | **1. XFoil** 17 | Download the latest version of XFoil (I used 6.99). Place the executable as close to your main drive as possible. 18 | ``` 19 | C/XFoil/xfoil.exe 20 | ``` 21 | 22 | **2. Python** 23 | Install with standard settings being sure to add to environment PATH. 24 | 25 | **3. Spyder** 26 | Install with standard settings. 27 | 28 | **4. XFoil BEM Tool** 29 | Download xfoil_bem_tool.py and place it in your XFoil directory. 30 | ``` 31 | C/XFoil/xfoil_bem_tool.py 32 | ``` 33 | 34 | ## Running the script 35 | Open xfoil_bem_tool.py in Spyder and configure your desired parameters. 36 | 37 | - re_strt is the starting Reynolds number 38 | - re_end is the ending Reynolds number 39 | - XFoil will iterate between this range of Reynolds numbers for your desired step size, re_step 40 | - alfa_strt, alfa_end, and alfa_step work on the same principle for angle of attacks 41 | 42 | For custom airfoils place the .dat file in the same directory as XFoil and XFoil BEM Tool. Instead of typing None type your foil file name 'example.dat'. 43 | 44 | Click the play button. XFoil will run every Reynolds number and for every angle of attack. 45 | 46 | ## Interpreting data 47 | XFoil will dump save files for every Reynolds number tested called '#_SAVE". In each file the angle of attacks are stored with corresponding Cl and Cd data. 48 | 49 | XFoil BEM Tool automatically sweeps these files and dumps another file called "outfile.csv". This is the main output file containing Re vs. AoA, Cl, and Cd. Use this for your BEM applications with your compatible CFD software. 50 | 51 | 52 | 53 | When using virtual disks with Star-CCM+'s BEM solver, you are asked to load a CSV file containing this exact data. Simply load this csv file into your CFD software and you should be good to go. BEM computations use this 2D airfoil data to approximate 3D fluid scales, forces, and moments. 54 | 55 | ## Acknowledgments 56 | Thank you to this script's co-author, George Loubimov, who accelerated my learning of Python. 57 | 58 | ## To do 59 | - Clean up code 60 | - Add non-convergence sensing 61 | - Reconfigure using DataFrame and pandas 62 | --------------------------------------------------------------------------------