Espritmodel.com Telemetry Radio
Reply
Thread Tools
Old Aug 17, 2013, 08:00 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Cool
Who wants to try CFD?

Okay, so actually right now it's just a grid generator. The CFD (computational fluid dynamics) solver will be my next project. I figure this thread will be kind of like my blog for my progress on this. The grid generator I think is pretty much done, but with the CFD solver there will always be plenty of new stuff to implement to make it better (turbulence and transition models, implicit time stepping, parallelization, etc.).

The grid generator takes airfoil coordinates in the same format as XFoil and generates a grid for 2D CFD computations.

https://sourceforge.net/projects/construct2d/

The link above is for the grid generator. You can generate O- or C- topology grids using hyperbolic or elliptic grid generation. It runs through the command line, like XFoil. Included are executables for Linux and Windows for the x86_64 architecture (because that's all I have access to), but I recommend compiling it for yourself because it is easy and would be a good learning experience. You need a Fortran compiler (gfortran is a good choice, and free) and GNU Make to build it from the Makefile. All of that is explained in the user manual, though.

There's also a visualizer included, written in python. You will need python and the matplotlib and numpy libraries to use the visualizer. The output grid and grid quality information are written in Plot3D format, so if you happen to have another CFD postprocessing program it will probably be able to read the grid.

In the next posts I'll do a couple demos on how to generate good grids.

Oh, and if anyone is interested in contributing to the project, let me know! The code is available via a git repository on Sourceforge so it would be easy to collaborate.
Montag DP is online now Find More Posts by Montag DP
Last edited by Montag DP; Aug 17, 2013 at 09:47 PM.
Reply With Quote
Sign up now
to remove ads between posts
Old Aug 17, 2013, 08:55 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Let's generate an O-grid for the NACA 0012. This airfoil is included in the sample_airfoils directory. Assuming that your executable is in the top-level directory for construct2d, you can load this airfoil as follows:

Code:
./construct2d sample_airfoils/naca0012.dat
if you are running BASH shell (like in Linux or Mac OSX) or

Code:
construct2d.exe sample_airfoils\naca0012.dat
in Windows from a command line. Once you start it, some information will be printed out to the screen notifying you about the airfoil and some other things.

Code:
 This is Construct2D, the structured grid generator for airfoils
 Version: 2.0

 Successfully loaded airfoil file sample_airfoils/naca0012.dat
  Number of points:         160
  Setting default project name: naca0012
  Blunt trailing edge: O-grid topology is recommended.

 Reading settings from user-supplied file grid_options.in
The usual flow of the program is to go to the two main options menus, SOPT (for surface grid options) and VOPT (for "volume" grid options - in quotes because since it's 2D the "volume" grid is actually an "area" grid). Adjust the settings there as desired, and then go to the GRID menu to actually generate the grid. I'll go over the program options that we'll use for the NACA 0012 in the next post.

The last line notes that settings are being read from an input file called grid_options.in. This is an optional file that you can use to store settings if you don't want to navigate through the program menus. This file is present, but I've commented out all the settings in it so that the program defaults are used instead. Below the greeting, the main program commands are listed.

Code:
 Main program commands:

  SOPT  Change airfoil surface grid options
  VOPT  Change volume grid options
  OOPT  Grid output options
  LOAD  Load a new airfoil
  OPTW  Write current program options to a file
  GRID  Generate grid for currently loaded airfoil
  QUIT  Exit program

 Command >
Use any of these commands by entering the four-character code listed. You can enter it in all caps, all lower case, or with the first letter capitalized.
Montag DP is online now Find More Posts by Montag DP
Reply With Quote
Old Aug 17, 2013, 09:33 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
When you enter 'sopt' at the command prompt, the surface options menu comes up, as shown below.

Code:
 Command > sopt

 Airfoil surface grid options for hyperbolic solver:

  Basic settings:
  NSRF  Number of points on surface:    250
  TELE  Clustering ratio, TE/LE:    1.0000
  BUNC  Surface bunching parameter:    1.0000
  TEPT  Number of points on blunt trailing edge:      7
  RADI  Farfield radius:   15.0000
  NWKE  Points along the wake for C-grid:     50
  
  Navigation:
  QUIT  Leave airfoil surface grid options menu

 Input >
Right now, we are using the hyperbolic solver (the solver setting is in the VOPT menu). If we were using the elliptic solver, there would be a few more options here to control the spacing at the farfield. I'll explain each of these options here, but they are also explained in the user manual.

NSRF: the number of points on the airfoil surface. We'll leave this at the default 250. This parameter can make a big difference to the accuracy of the later CFD solution when you run it on this grid, because the truncation error in the discretized equations for CFD decreases as the number of grid points is increased. In general, more points = more accurate CFD solution.

TELE: clustering ratio of points near trailing edge relative to the leading edge. A value greater than 1 means that points are clustered more closely near the trailing edge than near the leading edge, and a value less than 1 means they are clustered more closely near the leading edge. This parameter comes straight from XFoil. In fact, I borrowed the part of the XFoil code that does surface grid smoothing and incorporated it into Construct2D. We will set this parameter to 1.15, as shown:

Code:
Input > tele

 Current TE/LE clustering ratio:     1.0000000000000000     

 New value > 1.15
BUNC: Clustering ratio. A higher value means that cells are clustered near the leading and trailing edges and farther apart near the middle of the airfoil. This parameter also comes directly from XFoil. Let's also set this to 1.15.

TEPT: For airfoils with a blunt trailing edge (there is a gap between the top surface trailing edge point and the bottom surface trailing edge point), Construct2D represents trailing edge as a rounded curve to keep skewness down. This parameter controls how many points are used initially to create this trailing edge curve. However, the point locations later get modified to ensure that growth rates are as smooth as possible near the trailing edge, so you might not see this many points on the trailing edge curve in the final grid. It does still have the effect of bunching more points towards the back, though. Let's set this to 11.

RADI: Radius of the farfield boundary. For hyperbolic grid generation, this is only approximate as the farfield boundary can't be specified exactly. In elliptic grid generation, this value is exact. We will leave this set to 15.

NWKE: This option only applies to the C-grid topology, which this particular grid is not. Airfoils with a blunt trailing edge use the O-grid topology by default. If we were using a C-grid, this option would control the number of points that get placed in the wake region behind the trailing edge of the airfoil.

After adjusting all these settings as suggested, the menu should look like this:

Code:
 Airfoil surface grid options for hyperbolic solver:

  Basic settings:
  NSRF  Number of points on surface:    250
  TELE  Clustering ratio, TE/LE:    1.1500
  BUNC  Surface bunching parameter:    1.1500
  TEPT  Number of points on blunt trailing edge:     11
  RADI  Farfield radius:   15.0000
  NWKE  Points along the wake for C-grid:     50
  
  Navigation:
  QUIT  Leave airfoil surface grid options menu

 Input >
You can then enter 'quit' (without the quotes) to return to the main menu. In the next post we'll go over the volume grid options.
Montag DP is online now Find More Posts by Montag DP
Reply With Quote
Old Aug 18, 2013, 02:00 PM
Registered User
Joined May 2006
24 Posts
Running the precompiled bin in Fedora 18, I get a 'filename too long' error whenever the program tries to save a file. Compiling it and running the new bin seems to work fine.

Not sure I can contribute anything, but I can see this program being quite useful.
nristow is offline Find More Posts by nristow
Reply With Quote
Old Aug 18, 2013, 02:42 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Quote:
Originally Posted by nristow View Post
Running the precompiled bin in Fedora 18, I get a 'filename too long' error whenever the program tries to save a file. Compiling it and running the new bin seems to work fine.

Not sure I can contribute anything, but I can see this program being quite useful.
That's odd about the pre-compiled version. Those things can sometimes be finicky when running on a different system. Just to be sure, you are running a 64 bit machine, right? I wonder if there are some shared libraries that are different.

Anyway, compiling should be pretty uneventful especially for people running Linux. On Windows it's a little more of a chore to download the compilers and put them in the path, but after that it's just as easy. Tomorrow I'm going to try with a couple other compilers just to see if there are any potential bugs that gfortran didn't pick up.
Montag DP is online now Find More Posts by Montag DP
Reply With Quote
Old Aug 18, 2013, 03:14 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
The next step is to edit the volume grid options. They are explained below.

NAME: the main project name. The output files will have this prefix. It should be set initially to naca0012 according the the file prefix. We will leave it that way.

JMAX: the number of points in the direction moving away from the airfoil surface. This, along with NSRF (and NWKE for a C-grid) controls how fine the grid is. In general, increasing the number of points will usually increase the accuracy of the CFD solution, all other things being equal, but there is a point of diminishing return. Adding more points also makes the grid generation and CFD computations take longer. We will leave it at the default 100.

SLVR: the type of equations solved to generate the grid. Enter HYPR (or Hypr or hypr) for hyperbolic, and ELLP (or Ellp or ellp) for elliptic. Hyperbolic is recommended because it is much faster and usually produces a better grid. We will leave it at the default setting.

TOPO: grid topology. Enter OGRD for O-grid or CGRD for C-grid. An O-grid is recommended for airfoils with a blunt trailing edge and a C-grid is recommended for airfoils with a sharp trailing edge to minimize skew at the trailing edge. The topology is set automatically when the airfoil is read, but you can change from the default if you want. C-grids have better wake resolution but also require more points for the same grid resolution elsewhere.

YPLS: dimensionless wall distance (y+). Controls how far the first layer is away from the airfoil surface. For turbulent CFD computations, a value of 1 or less is recommended. For laminar simulations, the value can be increased significantly and even moreso for inviscid simulations. We will leave this at the default value of 0.9.

RECD: Reynolds number based on chord length that is used to compute y+. The actual wall spacing depends on both y+ and this Reynolds number. We will leave it at the default value of 1 x 10^6.

The following settings are specific to hyperbolic grid generation. For the elliptic grid generator, there will be some other options. They are all explained in the user manual.

ALFA: implicitness parameter for the hyperbolic grid generation. Usually a value of 1.0 seems to work best, but you may need to increase it to handle sharp concave corners. For example, if you are trying to create a C-grid for an airfoil with a blunt trailing edge, increasing this to about 4.0 should help prevent grid lines from crossing at the back. In this case, we will leave this at 1.0.

EPSI: implicit smoothing parameter. Adds some stability to the hyperbolic marching algorithm and can help reduce skewness and growth rates in some cases. If you want to use a lot of area smoothing steps (explained later), you may need to increase this parameter. However, using too high a value can cause instability. We will switch this from 15.0 to 5.0.

EPSE: explicit smoothing parameter. Has a similar effect to EPSI, but is more likely to cause instability. Some others claim it is helpful in situations with sharp concave corners. We will leave it at 0 for this case.

FUNI: relative uniformness of cell areas at the farfield. A value of 1.0 means completely uniform, and a value of 0.0 means clustered the same way as at the airfoil surface. A value of 0.2 is usually pretty good for an O-grid. For a C-grid, the quality is very dependent on this parameter and setting it too high may actually cause grid lines to cross (which is bad!). For a C-grid, a value less then 0.025 is recommended and a value of 0 is usually fine. Since this is an O-grid, we will leave it at 0.2.

ASMT: number of area smoothing steps. This can help smooth out cell growth rates, but it does increase the grid generation time somewhat. In my experience, it is more useful for C-grids than O-grids. It is possible to cause instability by using too many smoothing steps. We will reduce it from 20 to 10 in this case.

After adjusting these settings, the VOPT menu should look like this:

Code:
 Volume grid options for hyperbolic solver:

  Basic settings:
  NAME  Project name:  naca0012
  JMAX  Number of points in normal direction:    100
  SLVR  Solver (hyperbolic or elliptic):  HYPR
  TOPO  Grid topology (O-GRID or C-GRID):  OGRD
  YPLS  Viscous y-plus value:    0.9000
  RECD  Chord Reynolds number for y-plus:   1.00E+06
  
  Advanced settings:
  ALFA  Hyperbolic implicitness parameter:    1.0000
  EPSI  Implicit smoothing parameter:    5.0000
  EPSE  Explicit smoothing parameter:    0.0000
  FUNI  Uniformness of farfield cell areas:    0.2000
  ASMT  Number of cell area smoothing steps:     10
  
  Navigation:
  QUIT  Leave volume grid options menu

 Input >
We can now type 'quit' to go back to the main menu.
Montag DP is online now Find More Posts by Montag DP
Reply With Quote
Old Aug 19, 2013, 08:28 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Now that we've adjusted the settings to our liking, we can generate a grid. Do this by entering 'grid' at the main menu command prompt (without the quotes, of course). When you enter this, you get the following choice:

Code:
 Generate grid for which airfoil?

   SMTH  Smoothed airfoil using current surface grid options
         (recommended)
   BUFF  Buffer airfoil defined directly by loaded geometry
         (nsrf will be set to number of points in buffer airfoil)
   QUIT  Leave menu without generating grid

 Input >
The SMTH option is the one that is normally used. This will allow the surface clustering algorithm from XFoil to do its thing (those settings were some of the ones in the SOPT menu). If you choose BUFF (for buffer airfoil), this smoothing won't be done and the input coordinates will be used to generate the grid. Note that if you use the BUFF option your choices of NSRF, TELE, BUNC, and TEPT won't be used. Actually, I haven't tested the BUFF option much so let me know if you try to use it and there are bugs.

So, we will enter 'smth' and the grid will be generated. Information like the following will be displayed on the screen:

Code:
 Growing hyperbolic grid ... 

  Level (current, total):      2,   100

  Level (current, total):      3,   100

  Level (current, total):      4,   100

  Level (current, total):      5,   100

  Level (current, total):      6,   100
Since we set JMAX to 100, 100 levels of the hyperbolic grid are grown from the surface. Once it's done you will see some final information displayed before returning to the main menu:

Code:
 Enforcing normal spacing based on y-plus ...

                     Grid quality information                     
 -----------------------------------------------------------------
 Max skew angle (deg):   17.57632
   x, y:    1.00421   0.00975
   i, j:       6     37
 Max growth in xi-direction:    0.18033
   x, y:    1.00020   0.00073
   i, j:       3     10
 Max growth in eta-direction:    0.12089
   x, y:    0.47895   0.76880
   i, j:      63     74

 Writing grid to file naca0012.p3d ...

 Writing grid quality information to file naca0012_stats.p3d ...
The max skew angles and growth rates are quite good. For max skew angle you really want it to be below 30 degrees, and anything below 20 degrees is excellent. The growth rates should be below 0.2 (20 percent) in either direction, so we are okay there too.

If the grid quality was not so good, we'd have to go back to the SOPT and/or VOPT menus and change settings there. Some of the most useful things to modify for improving grid quality are NSRF, TELE, BUNC, and TEPT (in SOPT), and ASMT and FUNI (in VOPT).
Montag DP is online now Find More Posts by Montag DP
Reply With Quote
Old Aug 19, 2013, 08:44 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
This post will talk about how to inspect the grid with the python postprocessing script, postpycess.py. In Linux or Mac OSX, run it by typing the command:

Code:
./postpycess.py
and in Windows use

Code:
python.exe postpycess.py
You will see a prompt to enter the project name. At the prompt, enter 'naca0012' (without the quotes) because that was the project name we used in the grid generator. It should notify you that it has loaded the files naca0012.p3d and naca0012_stats.p3d. Next, we get the main menu.

Code:
Select plot type or other operation:

 1) Grid plot (grid only or colored by variable)
 2) Contour plot of variables on grid
 3) Line plot of variables on surface
 O) Change PostPycess options
 L) Load new grid and data
 Q) Quit PostPycess

Input:
The menu works very similar to the one from the grid generator, except here you just enter one number or letter instead of a 4-letter code. Enter 1 for a grid plot, and then 1 again for a plain (not colored) plot. A plot window should come up. It will be zoomed out so you can see the whole grid. If you want to get closer, use the zoom control at the bottom of the window. You can also pan, save an image, and do some other things. After zooming in, you should see the grid near the airfoil looking similar to the image in the first attachment.

When you close the plot, it will take you back to the grid plot menu. This time, instead of plotting a plain grid, let's plot a grid colored by skew angle. This is option 2. Zoom in and you should see a plot similar to that shown in the second attachment. The worst skew is near the trailing edge, which is pretty common. The max is only about 17.5 degrees, so it's not really something to worry about.

If you go back to the main menu, you will see there are some options for other plots, including contour plots and line plots on the airfoil surface. You can also change plotting options, including colors, color maps, number of contour lines, etc. Feel free to play around with these. The contour and line plots will be more useful later on when the flow solver is done and there is data like pressure coefficient, mach number, etc. to plot. Have fun!
Montag DP is online now Find More Posts by Montag DP
Reply With Quote
Old Aug 20, 2013, 06:59 AM
Registered User
Joined Feb 2013
33 Posts
Even I'm planning to design such a software. So i wanna ask how do you start with the code ? Have you taken a course in CFD ?
karan_chawla is offline Find More Posts by karan_chawla
Reply With Quote
Old Aug 20, 2013, 03:04 PM
Registered User
truffaldino's Avatar
Joined Jul 2007
326 Posts
Hello Dan,

It would be nice to make a user-friendly solver/grid generator for unconventional and multiple airfoils (since x-foil already does the job much more efficiently for conventional airfoils than 2D CFD). I think that you should also implement unstructured grid generator.

A couple of years ago I have written myself an unstructured mesher, but did not have time to proceed with solver, so I have written converter to fluent format and run Fluent on my meshes (see e.g. http://www.cfd-online.com/Forums/blo...esher-f90.html )
truffaldino is offline Find More Posts by truffaldino
Reply With Quote
Old Aug 20, 2013, 07:09 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Quote:
Originally Posted by karan_chawla View Post
Even I'm planning to design such a software. So i wanna ask how do you start with the code ? Have you taken a course in CFD ?
Hi, yes, I did have a class in CFD, and one of the projects was an elliptic grid generator for a simple H-grid topology (not regular airfoils). I took that and extended it to work with actual airfoils, then I implemented a hyperbolic grid generation approach which is faster and produces better grids generally when you don't care so much about the exact farfield shape. To figure out how to do hyperbolic grid generation, I read a few papers and books. The book I used is called the Handbook of Grid Generation. I also used a few of the papers referenced in that book, including one by Steger and Chaussee (1980) and Kinsey and Barth (1984).

Quote:
Originally Posted by truffaldino View Post
Hello Dan,

It would be nice to make a user-friendly solver/grid generator for unconventional and multiple airfoils (since x-foil already does the job much more efficiently for conventional airfoils than 2D CFD). I think that you should also implement unstructured grid generator.

A couple of years ago I have written myself an unstructured mesher, but did not have time to proceed with solver, so I have written converter to fluent format and run Fluent on my meshes (see e.g. http://www.cfd-online.com/Forums/blo...esher-f90.html )
That's a cool idea. I know XFoil already does a good job with most airfoils, in fact, better than 2D RANS in many cases. This isn't really intended to be the most efficient thing on the planet, necessarily, but something cool that does stuff XFoil won't do. CFD does allow you to do some cool things, like transonic and supersonic flow, higher angles of attack, more unusual shapes, full flow visualization (including many quantities that XFoil can't predict), etc. Once it is matured over a decent length of time I hope it will also become useful for model-size design and analysis, maybe at least as a "second opinion" for XFoil.

An unstructured solver would be cool, though. I will kick around that idea. Of course, with an unstructured code you can still run structured grids, they just are treated as though they are unstructured.
Montag DP is online now Find More Posts by Montag DP
Reply With Quote
Old Sep 01, 2013, 01:35 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Quote:
Originally Posted by truffaldino View Post
Hello Dan,

It would be nice to make a user-friendly solver/grid generator for unconventional and multiple airfoils (since x-foil already does the job much more efficiently for conventional airfoils than 2D CFD). I think that you should also implement unstructured grid generator.

A couple of years ago I have written myself an unstructured mesher, but did not have time to proceed with solver, so I have written converter to fluent format and run Fluent on my meshes (see e.g. http://www.cfd-online.com/Forums/blo...esher-f90.html )
Another thing I was just thinking about -- perhaps more useful than an unstructured grid generator and solver would be something with overset capability. That way you could use the same (already existing) grid generator to create multiple bodies -- for instance, a multi-element airfoil, each with its own structured grid -- and then let the solver handle blanking cells and interpolating between grids. That might be even more straightforward than an unstructured grid generator for multiple bodies.
Montag DP is online now Find More Posts by Montag DP
Reply With Quote
Old Sep 07, 2013, 08:46 AM
Registered User
truffaldino's Avatar
Joined Jul 2007
326 Posts
Quote:
Originally Posted by Montag DP View Post
Another thing I was just thinking about -- perhaps more useful than an unstructured grid generator and solver would be something with overset capability. That way you could use the same (already existing) grid generator to create multiple bodies -- for instance, a multi-element airfoil, each with its own structured grid -- and then let the solver handle blanking cells and interpolating between grids. That might be even more straightforward than an unstructured grid generator for multiple bodies.
Yes, this approach could give better results, since on good structured grids there are no problems with skewness. However, there could be complications if you consider modelling flows past bodies that are more complex than multiple conventional airfoils.
truffaldino is offline Find More Posts by truffaldino
Reply With Quote
Old Sep 07, 2013, 12:44 PM
Sink stinks
Montag DP's Avatar
United States, GA, Atlanta
Joined Apr 2005
4,523 Posts
Quote:
Originally Posted by truffaldino View Post
Yes, this approach could give better results, since on good structured grids there are no problems with skewness. However, there could be complications if you consider modelling flows past bodies that are more complex than multiple conventional airfoils.
Well, I think I'll take it one step at a time. After all, if you want to model really involved configurations you probably need to do 3D CFD anyway, and my plan is to use this mostly on PCs, not clusters. That's why I'm going with 2D.
Montag DP is online now Find More Posts by Montag DP
Reply With Quote
Reply


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Discussion Who wants to control who, now.... 62pilot Life, The Universe, and Politics 6 Jan 26, 2013 01:13 PM
Poll Who will McCain Pick for VP, or who do you want him to pick? Treetop Life, The Universe, and Politics 120 Aug 31, 2008 12:57 AM
Do you want to know who has the best prices on the parts you need? G1K@home Foamies (Kits) 11 Jun 06, 2003 04:06 PM
Who do YOU want for new World Leader? leccyflyer Life, The Universe, and Politics 13 Apr 10, 2002 07:45 AM