|
[Sponsors] |
Tool to convert OpenFoam mesh to SU2 mesh (2D and 3D) |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
December 11, 2013, 10:39 |
Tool to convert OpenFoam mesh to SU2 mesh (2D and 3D)
|
#1 |
Member
Join Date: Sep 2013
Posts: 43
Rep Power: 13 |
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... |
|
December 15, 2013, 08:03 |
|
#2 |
Member
Anant Diwakar
Join Date: Jan 2013
Posts: 68
Rep Power: 13 |
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 Thanks Anant |
|
December 15, 2013, 17:51 |
|
#3 |
Member
Join Date: Sep 2013
Posts: 43
Rep Power: 13 |
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 |
|
March 20, 2014, 03:25 |
|
#4 | |
Senior Member
Join Date: Jun 2011
Posts: 163
Rep Power: 15 |
Quote:
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 |
||
March 20, 2014, 11:31 |
|
#5 |
Member
Join Date: Sep 2013
Posts: 43
Rep Power: 13 |
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 |
|
March 20, 2014, 12:10 |
|
#6 |
Senior Member
Join Date: Jun 2011
Posts: 163
Rep Power: 15 |
Dear Laurent
Do you have a plan for create it ? Best Regards |
|
March 20, 2014, 15:24 |
|
#7 |
Member
Join Date: Sep 2013
Posts: 43
Rep Power: 13 |
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 |
|
March 21, 2014, 09:09 |
|
#8 |
Senior Member
Join Date: Jun 2011
Posts: 163
Rep Power: 15 |
OK,
please let me know how can I generate this code ? Best Regards |
|
March 21, 2014, 10:10 |
|
#9 |
Member
Join Date: Sep 2013
Posts: 43
Rep Power: 13 |
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 |
|
March 21, 2014, 10:35 |
|
#10 |
Member
Join Date: Sep 2013
Posts: 43
Rep Power: 13 |
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 |
|
May 16, 2014, 08:33 |
|
#11 |
New Member
Wouter
Join Date: May 2014
Posts: 26
Rep Power: 12 |
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.
|
|
May 18, 2014, 16:21 |
|
#12 |
Member
Join Date: Sep 2013
Posts: 43
Rep Power: 13 |
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". |
|
May 20, 2014, 07:46 |
|
#13 |
New Member
Wouter
Join Date: May 2014
Posts: 26
Rep Power: 12 |
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.
|
|
May 21, 2014, 04:53 |
|
#14 |
New Member
Wouter
Join Date: May 2014
Posts: 26
Rep Power: 12 |
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?
|
|
May 29, 2014, 16:47 |
|
#15 |
Member
Join Date: Sep 2013
Posts: 43
Rep Power: 13 |
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 |
|
December 23, 2016, 13:08 |
|
#17 |
Member
Join Date: Sep 2013
Posts: 43
Rep Power: 13 |
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 |
|
March 22, 2017, 08:34 |
|
#18 | |
Member
Kisorthman Vimalakanthan
Join Date: Apr 2011
Posts: 49
Rep Power: 15 |
Quote:
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
__________________
Kisorthman Vimalakanthan Dept. of Power and Propulsion Cranfield University Email: k.vimalakanthan@gmail.com |
||
August 11, 2017, 06:57 |
Bug in the Foam to SU2 mesh converter
|
#19 | ||
New Member
Prakriteesh Sarma
Join Date: Oct 2016
Posts: 6
Rep Power: 10 |
Quote:
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 Quote:
|
|||
August 11, 2017, 12:30 |
|
#20 |
Member
Join Date: Sep 2013
Posts: 43
Rep Power: 13 |
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 |
|
|
|