{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating airfoil data for various Reynolds numbers\n", "\n", "When analyzing propellors using blade element momentum theory we find that the various elements see a large variety in speeds and therefore reynolds number. Thus to keep the fidelity of the model within acceptable bounds it is required to know the properties of the airfoil at a wide range of Reynolds number.\n", "\n", "In order to so we can use tools such as xfoil. Xfoil is a command line tool developed by Mark Drela also known from AVL. It lets you analyze 2d airfoils using only a small set of commands. The software is open source and can be downloaded from [xfoil](https://web.mit.edu/drela/Public/web/xfoil/). Full documentation can be found in the same link as well.\n", "\n", "## Workflow for retrieving polar data\n", "\n", "Opening the xfoil executable will give you the screen as shown hereunder. It is a command line interface (CLI) tool thus you will have to type the commands. You can always see which commands are available at anytime by entering `?` and pressing enter. The following procedure should then be followed to retrieve the polar data.\n", "\n", "\n", "\n", "1. First we load in an airfoil, xfoil makes it very easy to load in NACA airfoils using the command `naca` with any 4 or 5 digit code so e.g `naca 4412`. However, any airfoil can be loaded in using `load example/path` where example/path points to a coordinate file.\n", "\n", "2. Once an airfoil has been chosen you go to operation mode by entering `oper`.\n", "\n", "3. Once in operation mode it is advised to increase the maximum amount of iterations for convergence sakes this can be done through `iter 40`. Where the numbers represents the maximuma amount of iterations.\n", "\n", "4. Then the viscous model should be enabled using `visc 1000000`. Where the integer represents the reynolds number, this is just an initialization and can still be changed afterwards using the command `r integer` to the desired reynolds numbers.\n", "\n", "5. To then write a text file with polar data for the current configured Reynolds number we enter the `pacc` command. Xfoil will then ask for a save path to write the file to. I recommend writing it to your downloads folder or another short path. As the path handling is not as robust and xfoil will fail to write the files with longer paths. E.g if you want to write a file named `4412_re3000000.txt` to your downloads folder you will enter the following: `C:\\Users\\JohnDoe\\Downloads\\4412_re3000000.txt`. The program will then ask for a dump path, this can safely be ignored by filling in a blank line. \n", "\n", "6. Then xfoil can compute the result of a range of angle of attack by using `aseq start_aoa end_alpha step_alpha` where `start_aoa` represents the starting angle of attack, `end_alpha` the ending angle of attack and `step_alpha` the step in the angle of attack.\n", "\n", "7. Whilst doing so it should have plotted the cp distribution as a pop up as shown below. You will now find a file in the specified directory. To now swithc to a different reynolds number we must first stop writing in the current file by typing `pacc` again. You can now change the reynolds number by using eg `r 20000000`.\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Automating the process using Python\n", "\n", "As seen from the previous explanation it would be a lot of work to do create all the necessary data for a wide range of Reynolds numbers. Hence we will automate this process using the `subprocess` module in Python which can manage subprocesses where the Python script itself is the main process. The script here under allows you to do so. The code is specifically left in Markdown as it requires a path to the xfoil executable thus you will have to copy the code below. However, a dataset is already embedded in the repository in the `examples\\data` folder. Additionally, the script can also be found in the `examples\\automation_airfoil_data.py`. Some notes about running the script can be found below.\n", "\n", "\n", "```python\n", "import subprocess\n", "import os\n", "import numpy as np\n", "\n", "\n", "# Path to the XFOIL executable\n", "xfoil_path = r'C:\\Users\\Johndoe\\Xfoil699src\\xfoil.exe'\n", "save_path = r'C:\\Users\\Johndoe\\Downloads\\data' # Path can not be too long as it wil fail when it is\n", "naca_airfoil = \"4412\"\n", "max_iter = \"40\"\n", "\n", "# Reynolds range\n", "start_reyn = 2e6\n", "ending_reyn = 50e6\n", "step_reyn = 1e6\n", "\n", "#AoA range\n", "start_alpha = \"-5\"\n", "end_alpha = \"16\"\n", "step_alpha = \"0.2\"\n", "\n", "# XFOIL start up commands\n", "startup_commands = [\n", " 'naca ' + naca_airfoil,\n", " 'oper',\n", " 'iter' + max_iter,\n", " \"visc 1000000\"\n", "]\n", "\n", "# Run XFOIL\n", "process = subprocess.Popen(xfoil_path, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)\n", "\n", "for command in startup_commands:\n", " process.stdin.write(command + '\\n') \n", " process.stdin.flush() \n", "\n", "for Reyn in np.arange(start_reyn, ending_reyn, step_reyn):\n", " Reyn = int(Reyn)\n", " process.stdin.write(\"r\"+ str(Reyn) + '\\n') \n", " process.stdin.write(\"pacc\"+ '\\n') \n", " process.stdin.write(os.path.join(save_path, \"airfoil_\" + str(Reyn)) + \".txt\" + '\\n') \n", " process.stdin.write('\\n') \n", " process.stdin.write(f'aseq {start_alpha} {end_alpha} {step_alpha}' + '\\n') \n", " process.stdin.write('pacc' + '\\n') \n", " process.stdin.flush()\n", "\n", "output, error = process.communicate()\n", "```\n", "\n", "## Operation of the Python script\n", "\n", "Using this script with the corect paths set up should result in a folder similar to the one below.\n", "\n", "

\n", "\n", "

\n", "\n", "\n", "Then some final notes when utilizing this script:\n", "\n", "\n", "1. Xfoil tends to crash at different Reynolds number. Thus sometimes you have to restart the script starting from the last successful Reynolds numbers therefore you will have to alter the variable `start_reyn`.\n", "2. Not all angle of attack converge properly to give the best possible results do the following:\n", " - Increase the maximum iterations\n", " - Decrease the step in angle of attack\n", " - Keep your airfoil open at the trailing, this tends to help the convergence\n", " " ] } ], "metadata": { "kernelspec": { "display_name": "geo", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.10.4" } }, "nbformat": 4, "nbformat_minor": 2 }