HobbyKing.com New Products Flash Sale
Reply
Thread Tools
Old Feb 03, 2014, 08:04 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Discussion
XoptFoil: airfoil optimization with XFoil

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

http://www.rcgroups.com/forums/showthread.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/

In case anyone wants to try it. You will need to have a Fortran compiler (I suggest gfortran, which is free and available for all the major computing platforms) and GNU make to compile the code. It 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.
Montag DP is offline Find More Posts by Montag DP
Reply With Quote
Sign up now
to remove ads between posts
Old Feb 03, 2014, 08:12 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
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.
Montag DP is offline Find More Posts by Montag DP
Last edited by Montag DP; Feb 03, 2014 at 08:21 PM.
Reply With Quote
Old Feb 03, 2014, 08:20 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Just some quick notes on compiling.

If you are on Linux, it's easy because gfortran and GNU Make are in the repositories.

On Windows, you can get gfortran from the MinGW suite:

http://sourceforge.net/projects/ming...ingw-get-inst/.

If you use MinGW, make sure you select to install Fortran and add the directory where the executables get installed to your PATH. To get GNU Make on Windows, you can use this link:

http://gnuwin32.sourceforge.net/packages/make.htm

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.
Montag DP is offline Find More Posts by Montag DP
Last edited by Montag DP; Feb 04, 2014 at 12:43 PM. Reason: Edited link for GNU Make
Reply With Quote
Old Feb 04, 2014, 12:15 PM
"...certainty is absurd."
kcaldwel's Avatar
Joined Jan 2007
3,602 Posts
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
kcaldwel is offline Find More Posts by kcaldwel
Last edited by kcaldwel; Feb 04, 2014 at 12:22 PM.
Reply With Quote
Old Feb 04, 2014, 12:46 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Quote:
Originally Posted by kcaldwel View Post
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.
Montag DP is offline Find More Posts by Montag DP
Reply With Quote
Old Feb 04, 2014, 03:11 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
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.)
Montag DP is offline Find More Posts by Montag DP
Last edited by Montag DP; Feb 04, 2014 at 03:18 PM.
Reply With Quote
Old Feb 04, 2014, 03:48 PM
Striving to Rip the Bring
raptor22's Avatar
San Diego, socal, USA, North America, Earth, Solar System, the Orion arm, Milky way, Universe
Joined Apr 2003
6,320 Posts
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.
raptor22 is offline Find More Posts by raptor22
Reply With Quote
Old Feb 05, 2014, 07:47 PM
Registered User
Joined Feb 2014
1 Posts
Quote:
Originally Posted by Montag DP View Post
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?
elio_xh is offline Find More Posts by elio_xh
Reply With Quote
Old Feb 05, 2014, 09:18 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Quote:
Originally Posted by elio_xh View Post
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.
Montag DP is offline Find More Posts by Montag DP
Reply With Quote
Old Feb 06, 2014, 12:45 AM
Skillful
Australia, VIC, Bentleigh East
Joined Oct 2010
5 Posts
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
Skillful is offline Find More Posts by Skillful
Reply With Quote
Old Feb 06, 2014, 10:15 AM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Quote:
Originally Posted by Skillful View Post
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
Montag DP is offline Find More Posts by Montag DP
Reply With Quote
Old Feb 06, 2014, 10:21 AM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Quote:
Originally Posted by elio_xh View Post
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
Montag DP is offline Find More Posts by Montag DP
Reply With Quote
Old Feb 06, 2014, 01:52 PM
Registered User
North Britain
Joined Jun 2006
68 Posts
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 View Post

...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.

Derfy is offline Find More Posts by Derfy
Reply With Quote
Old Feb 06, 2014, 02:57 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Quote:
Originally Posted by Derfy View Post
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
Montag DP is offline Find More Posts by Montag DP
Reply With Quote
Old Feb 07, 2014, 01:56 PM
Registered User
North Britain
Joined Jun 2006
68 Posts
Quote:
Originally Posted by Montag DP View Post
...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 View Post
... 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.

Derfy is offline Find More Posts by Derfy
Reply With Quote
Reply


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Discussion Airfoil Optimization Using Genetic Algorithms Ghost_ Modeling Science 38 Apr 24, 2014 06:18 AM
Discussion Airfoil Optimization with XFOIL Montag DP Modeling Science 168 Feb 03, 2014 08:14 PM
Discussion Evolutionary airfoil design optimizer available kcaldwel Modeling Science 3 Dec 10, 2012 04:03 PM
Profili - Xfoil and reflexed / autostabilizing airfoils surfimp Modeling Science 29 Mar 30, 2005 06:32 AM