Airfoil simulations - A little contribution for meshing

Examples of flow modelling using Code_Saturne.
Forum rules
As this forum is intended to post modelling examples, for better clarity, posts may be edited, and questions may be removed in some cases once the parent is updated.
Post Reply
César Vecchio

Airfoil simulations - A little contribution for meshing

Post by César Vecchio »

Hi everybody.
Well, this is not directly related to Code_Saturne, but you may find it useful if you want to have a fully hexahedral mesh around an arbitrary airfoil, only for 2D cases. It's a routine I made for Octave, but works without inconvenience in MatLab too (I haven't tried, but SciLab has an import function for .m scripts), which creates a Gmsh script ready for meshing. The tutorial is below:
1) Download the foilgmsh.m script and place it in a directory inside the path of Octave/MatLab
2) To check if it's accesible, type from within Octave:
 
help foilgmsh
 
A somewhat lengthy help text should appear. I highly reccomend you to read it. If you get an error, check you copied the script to a valid directory inside Octave's path.
3) Any plain text airfoil coordinate file will do (just check it's made in the same way as in XFoil or JavaFoil softwares, it's a pretty standard structure) but for this example we will use the n23012.dat file provided in the attachments. Copy that file to your current working directory.
4) Let's suppose we want a mesh with 100 elements along the chord (that's 100 along the upper surface and 100 along the lower surface), 40 rows of elements close to the airfoil on both sides, 25 elements before and after the airfoil and 15 elements above and below. The simulation should be run for a case of Re=3e6, Mach=0.3, a stagnation temperature of 15ºC and air as the fluid. We also want our mesh to be finer towards the airfoil edges, and let's suppose we will use the k-epsilon turbulence model, so an y+=50 will do good. The angle of attack is 7.5º. The following line includes all this information:
 
foilgmsh ('n23012.dat',7.5,50,'a',3000000,0.3,198.16,[100,40,25,15],0.01)
 
If you don't understand what all this parameters are, read the help as stated in step 2.
5) Look at the output info on the screen, it will be useful for setting up your simulation in CS according to all your input parameters. That info is not saved anywhere, so note it down or copy it to some other textfile.
6) Ok, check your working directory, you should see a new file called "n23012.dat.geo". If you open it with a text editor, you will notice it contains a Gmsh script. You may exit Octave now if you wish.
7) Open Gmsh, go to File-->Open and load the newly created n23012.dat.geo file. You should your airfoil surrounded by a small semiellipse and a bigger box with some ugly inclined lines (don't worry, it's on purpose); if you rotate the view you will see the plane figure is actually extruded by a little amount. Press the "m" key to activate the meshing module, and click on "3D". After a second or less you will see your new pseudo-2D hexahedral mesh. Save it as a MED file without any extra options (UNV and MSH types don't save the group names properly) under File--> Save as (not "save mesh", as strange as it sounds).
8) From now on it's only CS, the mesh and you... If you're going to write the group names in some of the Fortran routines like usproj, usini1, etc., write them enclosed in double quotation marks (the full name is, for example, "walls", not walls, otherwise it's incorrect). Also, as stated in the user guide, check the orientation correction option in the GUI as Gmsh may define them wrongly.
 
Ok, I hope you find this useful. Happy simulations.
 
César
Attachments
n23012.dat
(2.23 KiB) Downloaded 1972 times
foilgmsh.m
(20.11 KiB) Downloaded 2110 times
David Monfort

Re: Airfoil simulations - A little contribution for meshing

Post by David Monfort »

Hello César,
Thank you very much for sharing your work with us!
I cannot test your script yet because I don't have Matlab / Scilab at hand, but I'm pretty sure that it will be of some help for people willing to run NACA simulations, without having the hassle of creating a good mesh ;-)
David
Luc Blecha

Re: Airfoil simulations - A little contribution for meshing

Post by Luc Blecha »

Hi César,
Very nice script.
I followed the steps you indicate in your post, i.e. generate a gmsh script with your script, importe it in gmsh and saved it as MED file. Now, when I import this MED mesh in saturn, I receive a connectivity error for some elements (see MED file attached). Do you know how to correct this error?
Thanks for your help
Luc
Attachments
check_mesh.med
(3.61 MiB) Downloaded 1794 times
Yvan Fournier

Re: Airfoil simulations - A little contribution for meshing

Post by Yvan Fournier »

Hello,
Some tools (possibly Gmsh) are bad at orienting cells according to the MED numbering, or orienting all cells consistently when using operations such as symmetry.
I am not sure this is the case here, but did you try the "reorient" feature of the Code_Saturne Preprocessor (either through an option in the mesh selection with the GUI, or as a --reorient command-line option to cs_preprocess)) ?
Best regards,
  Yvan
Luc Blecha

Re: Airfoil simulations - A little contribution for meshing

Post by Luc Blecha »

Hi
Thanks for the hint. The complete sequence look like this for me:
1) generate the GMSH file using Cesar's script, for example: 
$ foilgmsh ('n23012.dat',7.5,50,'a',3000000,0.3,198.16,[100,40,25,15],0.01)
2) generate the MED mesh via gmsh (see above description), and save it as MED (file name in this example n23012.med)
3) run code saturne mesh check with following options:
$ cs_preprocess --reorient --med --volume -m n23012.med
4) load the file named "preprocess.med" in code_saturne and run your analysis.
Here you are! You have it runing!
Thank you for your help
Luc
Attachments
speed-150s.png
César Vecchio

Re: Airfoil simulations - A little contribution for meshing

Post by César Vecchio »

I'm very glad my script could be helpful to you, Luc.

As side notes on my script, I must warn that the generated mesh may not be of high quality. This is due to the tricks I have to employ in order to obtain a square domain around the airfoil, while mantaining a structured mesh. The reason is that I wanted to simulate an airfoil in a wind-tunnel.
 
César
tcp
Posts: 2
Joined: Fri Sep 07, 2018 12:43 am

Re: Airfoil simulations - A little contribution for meshing

Post by tcp »

Dear César

Hope you are still watching the site.
I'm porting your code to Python - intending to use it for a demonstration of a new optimization technique. Of course you will get a mention in any publication. Hope this is acceptable.

One question. In your function ypar(), you use a statement
while i<10
but it looks like i has not been initialised. I'm not sure how Octave handles this ...

tcp
CAVT
Posts: 9
Joined: Wed Mar 14, 2012 9:10 pm

Re: Airfoil simulations - A little contribution for meshing

Post by CAVT »

tcp wrote: Fri Sep 07, 2018 11:56 am Dear César

Hope you are still watching the site.
I'm porting your code to Python - intending to use it for a demonstration of a new optimization technique. Of course you will get a mention in any publication. Hope this is acceptable.

One question. In your function ypar(), you use a statement
while i<10
but it looks like i has not been initialised. I'm not sure how Octave handles this ...

tcp
Hi, there.
Sure, port it and modify it as much as you wish, I didn't include any specific license with the code but feel free to consider it open source. The reason I made it for Octave is simply that's the programming language I best know, a Python port (or any oher port) is a great improvement. Actually, if I'm not mistaken, this code could be implemented directly in Gmsh's .geo files as they are aparently a subset of C language, but I didn't try it because I don't know C or its variants.
About your observation on "i" not being initialized, you're right, it should be initialized. The reason the code does not crash is that "i" is internally defined in Octave as the imaginary constant, i.e. 0+1i. Therefore, in every step the quantity rises as 1+1i, 2+1i, etc., which by pure luck still works but is ill defined anyways, so thanks for noticing it :). I'd suggest you change the variable name to any other one of your preference.
tcp
Posts: 2
Joined: Fri Sep 07, 2018 12:43 am

Re: Airfoil simulations - A little contribution for meshing

Post by tcp »

Thanks César

Will let you know how it turns out. ;)

tcp
someguy
Posts: 1
Joined: Tue Jun 18, 2019 4:10 am

Re: Airfoil simulations - A little contribution for meshing

Post by someguy »

I cannot get this utility to work, either from the command line or from within octave. It seems like it doesn't like the parameter list. What am I missing ?

$ uname -a
Linux Brix 5.1.8-300.fc30.x86_64 #1 SMP Sun Jun 9 17:09:32 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$ octave
GNU Octave, version 4.4.1
...
Octave was configured for "x86_64-redhat-linux-gnu".

$ foilgmsh ('n23012.dat',7.5,50,'a',3000000,0.3,198.16,[100,40,25,15],0.01)
bash: syntax error near unexpected token `'n23012.dat',7.5,50,'a',3000000,0.3,198.16,[100,40,25,15],0.01'

$ octave foilgmsh ('n23012.dat',7.5,50,'a',3000000,0.3,198.16,[100,40,25,15],0.01)
bash: syntax error near unexpected token `('

When you state "1) Download the foilgmsh.m script and place it in a directory inside the path of Octave/MatLab", where are you referring to ?

"2) To check if it's accesible, type from within Octave:"

you mean:

octave:1> help foilgmsh
'foilgmsh' is a function from the file /home/me/Downloads/OpenFOAM/Chapter 5 Beginners Tutorial/foilgmsh.m

foilgmsh(archi,alfa,yplus,eter,Re,M,T0,N,bump) ...

but yet...

$ octave --eval foilgmsh.m ('n23012.dat',7.5,50,'a',3000000,0.3,198.16,[100,40,25,15],0.01)
bash: syntax error near unexpected token `('

Or

$ octave "foilgmsh ('n23012.dat',7.5,50,'a',3000000,0.3,198.16,[100,40,25,15],0.01)"error: no such file, '/home/me/Downloads/OpenFOAM/.../foilgmsh ('n23012.dat',7.5,50,'a',3000000,0.3,198.16,[100,40,25,15],0.01)'
error: source: error sourcing file '/home/me/Downloads/OpenFOAM/.../foilgmsh ('n23012.dat',7.5,50,'a',3000000,0.3,198.16,[100,40,25,15],0.01)'



Thank you for contributing this utility !
Post Reply