CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   SU2 (http://www.cfd-online.com/Forums/su2/)
-   -   Tool to convert OpenFoam mesh to SU2 mesh (2D and 3D) (http://www.cfd-online.com/Forums/su2/127445-tool-convert-openfoam-mesh-su2-mesh-2d-3d.html)

Combas December 11, 2013 10:39

Tool to convert OpenFoam mesh to SU2 mesh (2D and 3D)
 
3 Attachment(s)
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...

diwakaranant December 15, 2013 08:03

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

Combas December 15, 2013 17:51

1 Attachment(s)
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

mechy March 20, 2014 03:25

Quote:

Originally Posted by Combas (Post 466547)
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

Combas March 20, 2014 11:31

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

mechy March 20, 2014 12:10

Dear Laurent
Do you have a plan for create it ?

Best Regards

Combas March 20, 2014 15:24

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

mechy March 21, 2014 09:09

OK,
please let me know how can I generate this code ?
Best Regards

Combas March 21, 2014 10:10

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 March 21, 2014 10:35

1 Attachment(s)
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

wgvanveen May 16, 2014 07:33

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.

Combas May 18, 2014 15:21

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

wgvanveen May 20, 2014 06:46

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 May 21, 2014 03:53

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?

Combas May 29, 2014 15:47

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


All times are GMT -4. The time now is 13:17.