Feb 03, 2014, 09:04 PM
Sink stinks
Discussion

XoptFoil: airfoil optimization with XFoil

A few years ago I started a thread about airfoil optimization with XFoil. The thread is here:

https://www.rcgroups.com/forums/show....php?t=1246998

At the time, I was using Matlab and running XFoil externally each time a new design had to be evaluated. This was very slow, and required a timer for each instance of XFoil to kill it in case it got into an infinite loop condition for a bad design. I recently decided I'd like to work on airfoil optimization again, but this time with my own code. So I took the relevant parts of the XFoil source code and incorporated them into my own program. This allowed me to put in checks for convergence and infinite loop conditions. The fact that it is a compiled program instead of a Matlab script also makes it much faster.

The code is available on SourceForge:

https://sourceforge.net/projects/xoptfoil/

Code development can be tracked on GitHub:

https://github.com/montagdude/Xoptfoil

In case anyone wants to try it. Pre-compiled binaries are included for Linux and Windows for x86-64 architectures in the bin/x86-64/Linux or bin/x86-64/Windows directories. If you can use them, you will need to compile it yourself. Detailed instructions are included in the user guide in the doc directory.

XoptFoil is driven by an input file, a copy of which is included. Most of the inputs are commented, so the important ones at least should be fairly self-explanatory. Basically, you select a seed airfoil, optimization options, operating points (each of which consists of a lift coefficient or angle of attack, Reynolds number, Mach number, and relative weighting of the operating point) , constraints (such as minimum moment, thickness, trailing edge wedge angle), XFoil options, etc., and let it go.

As for the details about the optimization, right now you can use either particle swarm or the Nelder-Mead simplex algorithm (which is the same as Matlab's fminsearch function). Particle swarm is a global search method which is rather computationally expensive but has the best chance of finding the best design. The simplex algorithm is more of a local search which could be run after particle swarm. Airfoils are paramterized by adding a user-defined number of perturbation functions to the top and bottom surfaces of the seed airfoil. Right now, I am using what are referred to as NACA shape functions, but I'm planning to add another type in the near future. Eventually I'm also going to parallelize the particle swarm routine to speed it up a bit.

If anyone wants to give it a try and has questions about compiling or setting up the input files, feel free to post here.
Last edited by Montag DP; May 25, 2016 at 10:53 PM.
Feb 03, 2014, 09:12 PM
Sink stinks
Here is an example I did to improve the Clark-Y airfoil for a Reynolds number of 300,000 at lift coefficients of 0, 0.3, 0.6, 0.8, and 1.0. The video below shows the progression of airfoil designs throughout the optimization and the improvements made in the airfoil polar.

 XoptFoil airfoil optimization (0 min 17 sec)

It looks like the optimization stagnates in the middle, but really it is making very small incremental improvements. At the end, some noticeable improvements occur when the code switches from particle swarm to simplex search. The final design is a bit thinner and gets significantly better performance up to Cl = 0.8. Above that, the performance is about the same as the Clark-Y.

I plan to use this for a real-world design soon. That's actually the reason why I decided to make the program. The plan is to make a powered flying-wing glider optimized for duration and thermal soaring.
Last edited by Montag DP; Feb 03, 2014 at 09:21 PM.
 Feb 03, 2014, 09:20 PM Sink stinks EDIT: See the user guide for compiling instructions. Last edited by Montag DP; Mar 07, 2015 at 11:05 PM. Reason: Edited link for GNU Make
 Feb 04, 2014, 01:15 PM solastagia Very cool! Thanks so much for sharing your amazing work Dan. Kevin Edit: The GnuWin link didn't work for me. I went to : http://sourceforge.net/projects/gnuw...?source=navbar Last edited by kcaldwel; Feb 04, 2014 at 01:22 PM.
Feb 04, 2014, 01:46 PM
Sink stinks
Quote:
 Originally Posted by kcaldwel Very cool! Thanks so much for sharing your amazing work Dan. Kevin Edit: The GnuWin link didn't work for me. I went to : http://sourceforge.net/projects/gnuw...?source=navbar
Thanks Kevin, I updated the link to something that *looks* like an official website for GNU Make for Windows.

Thanks for your comments, too. I do have Windows 7 on my laptop (64 bit). Maybe I will compile it on there and include the binary on my SourceForge page next time I update it. That will make it easier for people on Windows.
Feb 04, 2014, 04:11 PM
Sink stinks
I ran XFoil on the optimized airfoil in post #2 at Re = 300,000 (which is where it was optimized) and Re = 90,000 (an off-design condition). The results are shown in the XFoil plots below.

Interestingly, the improvements are even more pronounced at Re = 90,000. The Clark-Y does do better at high lift coefficients above 1.0. But over the rest of the range, the optimized airfoil is much better. The optimized airfoil also has a lower pitching moment coefficient in pretty much all operating conditions, even though pitching moment wasn't a constraint in this particular optimization. The rightmost plot makes it appear that some portion of the performance improvements are achieved by the fact that the optimized airfoil has a later transition to turbulence on the bottom side. (At least I think that's the bottom side -- the XFoil plots don't make it quite clear.)

Images

Last edited by Montag DP; Feb 04, 2014 at 04:18 PM.
 Feb 04, 2014, 04:48 PM Striving to Rip the Bring Thank you for posting this update as well as the original thread. This is a special area of interest for me. At the moment I am an aerospace engineering student and my programming isn't yet up to utilizing the posted code, but I intend to see what I can accomplish with it in the next year or so.
Feb 05, 2014, 08:47 PM
Registered User
Quote:
 Originally Posted by Montag DP On Mac OSX, gfortran binaries are available at http://gcc.gnu.org/wiki/GFortranBinaries#MacOS and Make is available by installing the Xcode developer tools from the App Store. Once you have gfortran and Make installed on your system, compiling is really easy. Just go to the bin/ directory and type "make". This will build xoptfoil as well as a couple additional tools.
I'm having some problems getting this to work on Mac OSX Mavericks. I've followed these instructions and compiled xoptfoil successfully, but when i try to run the program I receive the following error: "Error: could not find input file inputs.txt."

The input file is in the "bin" folder, just like the xoptfoil executable, and this problem also occurs when I try using the xfoil_only.

Any idea how I can fix this?
Feb 05, 2014, 10:18 PM
Sink stinks
Quote:
 Originally Posted by elio_xh I'm having some problems getting this to work on Mac OSX Mavericks. I've followed these instructions and compiled xoptfoil successfully, but when i try to run the program I receive the following error: "Error: could not find input file inputs.txt." The input file is in the "bin" folder, just like the xoptfoil executable, and this problem also occurs when I try using the xfoil_only. Any idea how I can fix this?
That's weird. It appears that when you run your compiled executables they must be running from some different directory. My wife has a Mac, so I will see if I can reproduce this problem and let you know what I find out.
Feb 06, 2014, 01:45 AM
Skillful

Airfoil Optimiser

Hi Dan
I have been following along this thread for a while. I am an 'ol timer and my programming experience goes as far as BASIC and VBA. I jumped for joy when I saw your comment " Maybe I will compile it on there and include the binary on my SourceForge page next time I update it. That will make it easier for people on Windows". YES Please! I have windows 7 64 bit and 4 cores. I am sorry but I just don't know how to get gfortran and Make file to work. I have a few aerodynamics ideas I want to work on and would rather not spend my time messing with a compiler that does not even have a "go" button!
Thanks for all your great work. I am sure there are lots of people out there like me who want to use your program but cant get past the need to set up the compiler etc.
Thanks and Best Regards
Skillful
Feb 06, 2014, 11:15 AM
Sink stinks
Quote:
 Originally Posted by Skillful Hi Dan I have been following along this thread for a while. I am an 'ol timer and my programming experience goes as far as BASIC and VBA. I jumped for joy when I saw your comment " Maybe I will compile it on there and include the binary on my SourceForge page next time I update it. That will make it easier for people on Windows". YES Please! I have windows 7 64 bit and 4 cores. I am sorry but I just don't know how to get gfortran and Make file to work. I have a few aerodynamics ideas I want to work on and would rather not spend my time messing with a compiler that does not even have a "go" button! Thanks for all your great work. I am sure there are lots of people out there like me who want to use your program but cant get past the need to set up the compiler etc. Thanks and Best Regards Skillful
Hey Skillful,

Thanks for reminding me. I'm planning on adding a new feature in the next few days, and when I do that I will also include binaries for Windows and Linux on x86-64 architecture (that's what my computer is). I will also include more detailed compiling instructions. It's really not hard, but on Windows and Mac it's a little bit more trouble to get the compiler installed.

However, even if you have a working executable, you still need to be comfortable with changing things in the input file to get it to do what you want. Because of that, I'll also work on a reference guide to what all the inputs do and which ones are important, etc.

Dan
Feb 06, 2014, 11:21 AM
Sink stinks
Quote:
 Originally Posted by elio_xh I'm having some problems getting this to work on Mac OSX Mavericks. I've followed these instructions and compiled xoptfoil successfully, but when i try to run the program I receive the following error: "Error: could not find input file inputs.txt." The input file is in the "bin" folder, just like the xoptfoil executable, and this problem also occurs when I try using the xfoil_only. Any idea how I can fix this?
I've been thinking about this and I think I know what the problem might be. To run XoptFoil, you should use the following approach:

Open up a terminal ("Command prompt" on Windows) and navigate to the XoptFoil/bin/ directory where the program is compiled and the input file resides. This is important, because by having the command prompt open in the correct directory, you have set this as your working directory and now the program should be able to see the input file. Once you have the command prompt ready to go in the correct directory, assuming the program is already compiled, type:

Code:
`xoptfoil.exe`
if you are on Windows or

Code:
`./xoptfoil`
if you are on Linux or Mac. I will include more detailed instructions in a PDF the next time I update the code.

Dan
Feb 06, 2014, 02:52 PM
Registered User
Many thanks for the new toy, Dan.

Just to let you know that it compiles with no problems at all on my old steam-powered WinXP box (dual core x86) using GFortran and GNU Make.

Quote:
 Originally Posted by Montag DP ...Particle swarm is a global search method which is rather computationally expensive ...
Don't I know it. Running your test file, it took 1.5 hrs to complete at 53% CPU usage on both cores.
I guess I'll have to update my system one of those days to keep up with all of this great stuff that you're coming up with.

Thanks again.

Feb 06, 2014, 03:57 PM
Sink stinks
Quote:
 Originally Posted by Derfy Many thanks for the new toy, Dan. Just to let you know that it compiles with no problems at all on my old steam-powered WinXP box (dual core x86) using GFortran and GNU Make. Don't I know it. Running your test file, it took 1.5 hrs to complete at 53% CPU usage on both cores. I guess I'll have to update my system one of those days to keep up with all of this great stuff that you're coming up with. Thanks again.
That's great to hear! I haven't actually tried compiling on Windows yet, but considering you're using gfortran I wouldn't expect any problems. I should try other compilers too, to catch possible bugs.

1.5 hours is actually pretty quick for that test case. Particle swarm is kind of a "smart" brute force approach, similar to a genetic algorithm. They both require large populations of designs to find the best solution, and lots of objective function evaluations. But they both work pretty well in aerodynamic problems like this where there are a lot of potential "local" optimal solutions. Of course, the more XFoil operating points you include in your optimization, the longer it takes. Parallelizing the particle swarm algorithm is on my eventual to-do list, though.

Dan
Feb 07, 2014, 02:56 PM
Registered User
Quote:
 Originally Posted by Montag DP ...1.5 hours is actually pretty quick for that test case...
That's good to know, Dan, maybe I don't need to update just yet.

Quote:
 Originally Posted by Montag DP ... Particle swarm is kind of a "smart" brute force approach...
That reminds me of back in the 1980s when we used to run Monte Carlo SPICE simulations (1000s of runs), on the departmental VAX, to check circuit tolerancing. Talk about brute force, it slowed the machine down so much that the system manager banned us from running them in real time and forced us to batch them instead. Of course, on the batch you could maybe expect your results the next day, or the day after, or the day after that, or.....

Anyway I'm going to try it out this weekend on a few different foils and if I find anything untoward I'll let you know.