CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > SU2

Tool to convert OpenFoam mesh to SU2 mesh (2D and 3D)

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree4Likes
  • 3 Post By Combas
  • 1 Post By Combas

Reply
 
LinkBack Thread Tools Display Modes
Old   December 11, 2013, 10:39
Default Tool to convert OpenFoam mesh to SU2 mesh (2D and 3D)
  #1
Member
 
Join Date: Sep 2013
Posts: 38
Rep Power: 3
Combas is on a distinguished road
Since I needed to convert OpenFoam meshes to SU2 format (*), I have developed a python tool that does it.

Its use is very easy and it allows you to convert:
- "true" 3D meshes with hexas, tetras, prisms and pyramids elements
- 3D meshes obtained by extrusion (of one or several cells along X, Y or Z) to 2D meshes (so it converts hexas and prisms in quads and triangles)

How to use it (on Linux but it must be very similar under other OS):
1) Download the file "ConvertOpenFoam2SU2.py" (in attachment)
2) Create an input file (templates for 2D or 3D cases are given in attachment)
3) Write in your terminal, in the directory that contains the file "ConvertOpenFoam2SU2.py": "python ConvertOpenFoam2SU2.py" (without quotes)
4) The tool asks the name of the input file: write it!
5) After some comments to tell what the code is doing, the mesh is created!

Format of the input file (4 lines for 3D meshes, 5 lines for 2D meshes):
Line 1: Path to openfoam mesh files (it should end with "/polyMesh")
Line 2: Path where to write the .su2 mesh file
Line 3: Name of the .su2 mesh file (for example "airfoil.su2")
Line 4: "2D" or "3D"
Line 5: "X", "Y" or "Z" to give the axis of projection (only for 2D)

Kind of mesh supported:
Only 3D OpenFoam meshes, with hexas, tetras, pyramids and prisms cells are supported.

Validation:
The tool has been tested for the following meshes (and it works):
- 2D conversion from a 3D mesh with hexas
- 3D conversion from a 3D mesh with hexas
- 3D conversion from a 3D mesh with tetras and prisms

Remark:
For "big" meshes (several million cells) take care that it can be quite long (several minutes) and use a lot of RAM...

Python code:
If needed, you can modify it. It is not very long and I have written some comments to help developers to understand what is done.

I hope this tool will be helpful!

Laurent

(*) In fact, I use meshes in Fluent .msh format that I convert in a first time in OpenFoam format (with fluentMeshToFoam command) and then to SU2 format, so if anyone has a method to convert directly Fluent meshes (.msh) directly to SU2 without using Fluent, it would be easier for me... And I woud avoid bugs of fluentMeshToFoam...
Attached Files
File Type: gz ConvertOpenFoam2SU2.py.gz (4.7 KB, 58 views)
File Type: txt TemplateOpenFoamToSU2_2D.txt (81 Bytes, 62 views)
File Type: txt TemplateOpenFoamToSU2_3D.txt (79 Bytes, 53 views)
Combas is offline   Reply With Quote

Old   December 15, 2013, 08:03
Default
  #2
Member
 
Anant Diwakar
Join Date: Jan 2013
Posts: 68
Rep Power: 4
diwakaranant is on a distinguished road
Hi

I was trying to convert the open foam mesh of lid driven cavity (incompresssible/icoFoam/cavity) to
su2, but it showed error while reading "owner" file

Code:
Enter the name of the input file:input.txt
Reading of the input file input.txt
pathOpenFoamMesh = /home/anant/OpenFOAM/OpenFOAM-2.1.1/tutorials/incompressible/icoFoam/cavity/constant/polyMesh
pathSU2Mesh      = /home/anant/OpenFOAM/OpenFOAM-2.1.1/tutorials/incompressible/icoFoam/cavity/
nameSU2MeshFile  = cavity.su2
kindMesh (2D/3D) = 2D
axisProjection   = Z
Input file read correctly

Reading of the 'points' file
nb points =  882
'points' file read correctly

Reading of the 'faces' file
nb faces =  1640
'faces' file read correctly

Reading of the 'owner' file
Problem during the 'owner' file reading
Why is this error coming ?

Thanks
Anant
diwakaranant is offline   Reply With Quote

Old   December 15, 2013, 17:51
Default
  #3
Member
 
Join Date: Sep 2013
Posts: 38
Rep Power: 3
Combas is on a distinguished road
Hello,

Indeed, this case has a little difference in the "owner" file format (problem of spaces)
I have corrected the python tool and now it works. You can find it in attachment.
Don't hesitate to tell me if you get other bugs!

Laurent
Attached Files
File Type: gz ConvertOpenFoam2SU2.py.gz (4.8 KB, 81 views)
elvis, Mehrez and granbycools like this.
Combas is offline   Reply With Quote

Old   March 20, 2014, 03:25
Default
  #4
Senior Member
 
Join Date: Jun 2011
Posts: 141
Rep Power: 6
mechy is on a distinguished road
Quote:
Originally Posted by Combas View Post
Hello,

Indeed, this case has a little difference in the "owner" file format (problem of spaces)
I have corrected the python tool and now it works. You can find it in attachment.
Don't hesitate to tell me if you get other bugs!

Laurent
Dear Combas

I have used your python tool for converting OF mesh to su2 msh, it work well.
do you have a tool for inverse conversion ( su2 to OF mesh) ?
I used su2 optimization and at now I need to convert the optimum shape to openfoam

Best Regards
mechy is offline   Reply With Quote

Old   March 20, 2014, 11:31
Default
  #5
Member
 
Join Date: Sep 2013
Posts: 38
Rep Power: 3
Combas is on a distinguished road
Dear Mechy,

Sorry, I did not create this tool, but it would be a good idea to do it! (I think it would take around 1 or 2 days of work to do it in Python)

Regards,
Laurent
Combas is offline   Reply With Quote

Old   March 20, 2014, 12:10
Default
  #6
Senior Member
 
Join Date: Jun 2011
Posts: 141
Rep Power: 6
mechy is on a distinguished road
Dear Laurent
Do you have a plan for create it ?

Best Regards
mechy is offline   Reply With Quote

Old   March 20, 2014, 15:24
Default
  #7
Member
 
Join Date: Sep 2013
Posts: 38
Rep Power: 3
Combas is on a distinguished road
I have not planned to do it myself if it the question.
If you want to do it yourself and you want more information about how are organized the files, I can give you some information.

Laurent
Combas is offline   Reply With Quote

Old   March 21, 2014, 09:09
Default
  #8
Senior Member
 
Join Date: Jun 2011
Posts: 141
Rep Power: 6
mechy is on a distinguished road
OK,
please let me know how can I generate this code ?
Best Regards
mechy is offline   Reply With Quote

Old   March 21, 2014, 10:10
Default
  #9
Member
 
Join Date: Sep 2013
Posts: 38
Rep Power: 3
Combas is on a distinguished road
There are some information about the mesh format
1) in SU2 here :
http://adl-public.stanford.edu/docs/...RED/Mesh+files (to not read what is about cgns format)
and
http://www.vtk.org/VTK/img/file-formats.pdf (page 9)
2) in OpenFoam here :
http://www.openfoam.org/docs/user/mesh.php#x22-1270005
Combas is offline   Reply With Quote

Old   March 21, 2014, 10:35
Default
  #10
Member
 
Join Date: Sep 2013
Posts: 38
Rep Power: 3
Combas is on a distinguished road
There are some information about the mesh formats
1) in SU2 here:
http://adl-public.stanford.edu/docs/...RED/Mesh+files (to not read what is about cgns format)
and
http://www.vtk.org/VTK/img/file-formats.pdf (page 9)
2) in OpenFoam here:
http://www.openfoam.org/docs/user/mesh.php#x22-1270005

I put in attachment a python tool that helps me to do some operations on SU2 meshes. Maybe you can find some help inside... (some functions or mesh reading parts or python syntax)

In SU2, there is only one file that contains the following information:
- list of cells (for each one, the list of points that belong to the cell are given)
- list of points (their coordinates)
- list of boundaries (for each face element, the list of points that belong to the element are given)

In OpenFoam, there are several files (in folder "constant/polyMesh"). Just some remarks because I don't remember exactly the format of each file:
- the "cells" file contains for each cell the faces that belong to it
- the "owner" and "neighbour" files contain for each face, the cell number (if the face is a boundary, it just have a "owner" cell, and no "neighbour" cell). For the others, the two cells ("owner" and "neighbour" are equivalent and can be switched)
- it must be checked, but I believe that the faces must be ordered to get the boundary faces at the end, and they must not be mixed (since in the "boundary" file, each boundary is defined by the first face, and the number of faces)

So the main work is to transform cells that are described by points, into cells described by faces.

I hope that these pieces of information will help you...

If you don't know which tool you can use to develop in python, you can install "spyder"

Good luck!
Laurent
Attached Files
File Type: gz TransformSU2MeshFile.py.gz (4.2 KB, 21 views)
brugiere_olivier likes this.
Combas is offline   Reply With Quote

Old   May 16, 2014, 07:33
Default
  #11
New Member
 
Wouter
Join Date: May 2014
Posts: 13
Rep Power: 3
wgvanveen is on a distinguished road
Does anybody know if the ordering in the file must be of some sort? I thought it didn't matter since it is an unstructured grid, however my SU2 refuses to start with the mesh I created.
wgvanveen is offline   Reply With Quote

Old   May 18, 2014, 15:21
Default
  #12
Member
 
Join Date: Sep 2013
Posts: 38
Rep Power: 3
Combas is on a distinguished road
Indeed there is no ordering rule in the SU2 mesh file.
Just in case, It seems that there was a change of the key word "MARKERTAG" that became in SU2 V3.0 "MARKER_TAG".
Combas is offline   Reply With Quote

Old   May 20, 2014, 06:46
Default
  #13
New Member
 
Wouter
Join Date: May 2014
Posts: 13
Rep Power: 3
wgvanveen is on a distinguished road
Oke that is strange. SU2 hangs just after i load the mesh. It recognizes the faces and the points, but after that it breaks down but keeps running at 100% CPU. The ordering or the boundary conditions also have no effect? I noticed that in the script presented above that the Boundary conditions where connected with each other.
wgvanveen is offline   Reply With Quote

Old   May 21, 2014, 03:53
Default
  #14
New Member
 
Wouter
Join Date: May 2014
Posts: 13
Rep Power: 3
wgvanveen is on a distinguished road
I have also noted that if i copy paste the parts from the tutorial from the SU2 website (http://adl-public.stanford.edu/docs/...RED/Mesh+files) into a file called test.su2 and I try to run it I have the same problem. However when i download the file square.su2 from the website it runs without a problem. Are there any hidden requirements on the file format? Is it mandatory that all the numbers are separated by a tab?
wgvanveen is offline   Reply With Quote

Old   May 29, 2014, 15:47
Default
  #15
Member
 
Join Date: Sep 2013
Posts: 38
Rep Power: 3
Combas is on a distinguished road
Hello,

What you are saying is strange. Maybe you can check that you don't have a problem of windows or linux format.
I don't know exactly how works the reading program of SU2. If you don't find any solution, I think the best thing to do is to add some additional output in the SU2 reading function and perform some tests... (or to do it in debug mode if you get a tool like "Totalview")
Good luck!
Laurent
Combas is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 02:42.