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

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

Register Blogs Community New Posts Updated Threads Search

Like Tree17Likes

Reply
 
LinkBack Thread Tools Search this Thread 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: 43
Rep Power: 13
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, 421 views)
File Type: txt TemplateOpenFoamToSU2_2D.txt (81 Bytes, 403 views)
File Type: txt TemplateOpenFoamToSU2_3D.txt (79 Bytes, 429 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: 13
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: 43
Rep Power: 13
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, 385 views)
elvis, EMolina, Mehrez and 2 others like this.
Combas is offline   Reply With Quote

Old   March 20, 2014, 03:25
Default
  #4
Senior Member
 
Join Date: Jun 2011
Posts: 163
Rep Power: 15
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: 43
Rep Power: 13
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: 163
Rep Power: 15
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: 43
Rep Power: 13
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: 163
Rep Power: 15
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: 43
Rep Power: 13
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: 43
Rep Power: 13
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, 95 views)
brugiere_olivier and dkokron like this.
Combas is offline   Reply With Quote

Old   May 16, 2014, 08:33
Default
  #11
New Member
 
Wouter
Join Date: May 2014
Posts: 26
Rep Power: 12
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, 16:21
Default
  #12
Member
 
Join Date: Sep 2013
Posts: 43
Rep Power: 13
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, 07:46
Default
  #13
New Member
 
Wouter
Join Date: May 2014
Posts: 26
Rep Power: 12
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, 04:53
Default
  #14
New Member
 
Wouter
Join Date: May 2014
Posts: 26
Rep Power: 12
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, 16:47
Default
  #15
Member
 
Join Date: Sep 2013
Posts: 43
Rep Power: 13
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

Old   December 22, 2016, 09:04
Default
  #16
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 173
Rep Power: 14
pbachant is on a distinguished road
Hi Combas,

Looks like a great tool! Can you attach an open source license to it so others can create new versions?

Thanks!
__________________
Home | Twitter | GitHub
pbachant is offline   Reply With Quote

Old   December 23, 2016, 13:08
Default
  #17
Member
 
Join Date: Sep 2013
Posts: 43
Rep Power: 13
Combas is on a distinguished road
Hello,

I am glad that these tools can be useful for others.
You can of course use and modify them as you want: I have added a message at the beginning of the files to precise it.
You will find in attachment the last versions of these tools.

Laurent
Attached Files
File Type: gz ConvertOpenFoam2SU2.py.gz (5.1 KB, 119 views)
File Type: gz TransformSU2MeshFile_v2.py.gz (6.4 KB, 112 views)
Combas is offline   Reply With Quote

Old   March 22, 2017, 08:34
Default
  #18
Member
 
Kisorthman Vimalakanthan
Join Date: Apr 2011
Posts: 49
Rep Power: 15
k.vimalakanthan is on a distinguished road
Quote:
Originally Posted by Combas View Post
Hello,

I am glad that these tools can be useful for others.
You can of course use and modify them as you want: I have added a message at the beginning of the files to precise it.
You will find in attachment the last versions of these tools.

Laurent
Hi Combas,

I am glad I found your script, but unfortunately I'm not about to use it successfully

I have a simple OpenFoam grid of a cube (see attached image) containing all types of elements (hex, prism, pyramids and tetra) that was generated using pointwise. Could you please try your script to convert it to SU2 format?
Grid file: https://www.dropbox.com/s/ice4w7fxd0...yMesh.zip?dl=0

Kind regards,
Kishore
Attached Images
File Type: png Grid.PNG (177.3 KB, 75 views)
__________________
Kisorthman Vimalakanthan
Dept. of Power and Propulsion
Cranfield University
Email: k.vimalakanthan@gmail.com
k.vimalakanthan is offline   Reply With Quote

Old   August 11, 2017, 06:57
Default Bug in the Foam to SU2 mesh converter
  #19
New Member
 
Prakriteesh Sarma
Join Date: Oct 2016
Posts: 6
Rep Power: 10
fluxCatcher is on a distinguished road
Quote:
Originally Posted by Combas View Post
Hello,

I am glad that these tools can be useful for others.
You can of course use and modify them as you want: I have added a message at the beginning of the files to precise it.
You will find in attachment the last versions of these tools.

Laurent
Hi Laurent,

I am unable to use it for conversion of my snappyHexMeshes to su2. ("Problem during the format conversion process"). When I remove the "try / except" to spew out the actual error, seems there is a bug on like 439:

Code:
                            if (len(CommonPoints(listFaces[listCells[i][j]], listFaces[listCells[i][listLateralFacesOrdered[p]]]) == True) == 2):
                                listLateralFacesOrdered.append(j)
                                p = p + 1
The error is :
Quote:
Beginning of the format conversion process
Traceback (most recent call last):
File "ConvertOpenFoam2SU2.py", line 439, in <module>
if (len(CommonPoints(listFaces[listCells[i][j]], listFaces[listCells[i][listLateralFacesOrdered[p]]]) == True) == 2):
TypeError: object of type 'bool' has no len()
Not sure what you meant by line 439. Can you please fix it?
fluxCatcher is offline   Reply With Quote

Old   August 11, 2017, 12:30
Default
  #20
Member
 
Join Date: Sep 2013
Posts: 43
Rep Power: 13
Combas is on a distinguished road
Hi Sarma,

Indeed there is a bug on this line. You can replace:
if (len(CommonPoints(listFaces[listCells[i][j]], listFaces[listCells[i][listLateralFacesOrdered[p]]]) == True) == 2):
by:
if (len(CommonPoints(listFaces[listCells[i][j]], listFaces[listCells[i][listLateralFacesOrdered[p]]])) == 2):

The corrected script is in attachment.

Best regards,
Laurent
Attached Files
File Type: gz ConvertOpenFoam2SU2.py.gz (5.1 KB, 227 views)
ashishmagar600 likes this.
Combas is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 20:50.