Exporting a salome mesh to OpenFOAM
This forum is DEPRECATED, please create new topics in the new SALOME forum.
For existing topics please transfer them to the new forum.
Hi all,
I've made little python script that exports a mesh to OpenFOAM.
It's available here: https://github.com/nicolasedh/salomeToOpenFOAM
I know there already are ways to export a mesh, like the unv-format but that format doesn't support pyramids. This script should handle any type of cell, I've tested pyramids, "wedges", tetrahedrons and hexahedrons. The script doesn't require any additional installation. It runs from inside salome as it is.
The way to use the script would be to select the mesh you wish to export and the "load script" (ctrl-T) and selection salomeToOpenFOAM.py. I've included a couple of sample scripts in the above link as well.
Anyways, since I've put some time into the script my hope is that others won't have to. I hope you find it useful.
Best
Nicolas
Hello Nicolas,
Thank you very much ! Very nice initiative
Your code looks very nice
All the best
William
By now I am using the same script also for batch-mode meshing for testing different meshes for OpenFOAM.
It does run nicely and I will provide you with a full example script as soon as I have solved one or two issues which still exist.
Thanks a lot again, Nicolas, for your script! It arrived just at the right time for my work!
Sorry Nicolas, this time I am quicker!
A short information for all who want to use the script for MED-meshes: It is possible as well! But at least in my case it required some additional steps:
- Import the MED-file into SMESH
- "Compute" the imported mesh. You will receive some error message(s) about missing hypotheses or algorithm definitions. Just ignore these.
- Remove all groups but the ones for faces
- Within the "Groups of Faces", remove "Group of all Faces"
- Run Nicolas' script and be happy about your new OpenFoam-mesh!
Cheers,
Bernhard
PS: At some point you might receive errors about a list assignment out of range. In my case that was due to a non-conformal mesh which would have failed in OF anyway...
Hi Nicolas,
I would like to use your script for my mesh, but when i run it i geti this error:
>>> execfile(r"/home/salvo/salomeToOpenFOAM-master/salomeToOpenFOAM.py") Traceback (most recent call last): File "<input>", line 1, in <module> File "/home/salvo/salomeToOpenFOAM-master/salomeToOpenFOAM.py", line 46, in <module> from salome.smesh import smeshBuilder ImportError: cannot import name smeshBuilder >>> |
I guess coz i use salome 6.6.0, could u suggest me please how can i solve this problem?
Thank you very much,
salvo
Hi Salvo
Reading http://docs.salome-platform.org/latest/gui/SMESH/smesh_migration_page.html lets you know what API changes were made after 6.6.0 and how to convert old scripts.
St.Michael
Hi St.Michael,
thank you very much for your reply. I tried and it works perfectly!
best regards
Salvo
Dear All,
While several of us have come to like Nicolas' script, I would like to continue working with OpenFOAM's snappyHexMesh as well. This program requires a list of points and lines contained on the different edges of the geometry within an eMesh-file.
I wonder, if it was possible to modify Nicolas' script in a way as to write this eMesh-file? Unfortunately I do not have the capabilities wrt python programming, so I have to ask: Has anyone of you done such a thing already?
And would that person be kind enough to upload the script somewhere accessible?
Thank you already in advance!
Cheers,
Bernhard
Previously salvatore wrote:
Hi St.Michael,
thank you very much for your reply. I tried and it works perfectly!
best regards
Salvo
Hello Salvo.
Could You share Your modified salomeToOpenFOAM.py script? I can't get through def findSelectedMeshes()
Hi Nicolas,
I tried Meshing a cylinder using Radial Quadrangle 1D2D. However when I exported using the UNV format and later the script you provided, unused Points error was displayed when checking the Mesh.
How do I solve this?
Thanks in Advance.
Hello,
If you met the same error using the UNV format and the Nicolas' script, so the mistake should not be during export.
Possible sources of error:
- Only a part of the geometry associated to the mesh was meshed (and standalone nodes stand on vertexes of non-meshed parts of the geometry).
- The mesh was not extruded before export (since OpenFOAM needs 3D meshes even for 2D computations).
- ...
For more specific support, please, share here your study / study dump / geometry, or at least some screenshot(s).
Best regards,
William
Hello,
Thank you William, attached is the hdf file for my cylinder. Please look at it and let me know the errors. Thanks again.
Regards,
John
Hello,
Using Salome 7.7.1 on Linux and OpenFOAM 2.3.0, everything works fine for me.
Here, the output after exporting the mesh in UNV and imported it into OpenFOAM:
user@machine $ ideasUnvToFoam *.unv
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.3.0 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 2.3.0-f5222ca19ce6
Exec : ideasUnvToFoam Mesh_1.unv
Date : Feb 08 2016
Time : 10:06:23
Host : "tougeron-prace"
PID : 13341
Case : /home/tougeron/documents/home/Desktop/of_test
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Processing tag:164
Starting reading units at line 3.
l:1
units:" SI: Meter (newton)"
unitType:2
Unit factors:
Length scale : 1
Force scale : 1
Temperature scale : 1
Temperature offset : 273.15
Processing tag:2420
Skipping tag 2420 on line 9
Skipping section at line 9.
Processing tag:2411
Starting reading points at line 20.
Read 2821 points.
Processing tag:2412
Starting reading cells at line 5665.
First occurrence of element type 11 for cell 1 at line 5666
First occurrence of element type 44 for cell 31 at line 5936
First occurrence of element type 41 for cell 33 at line 5940
First occurrence of element type 115 for cell 1171 at line 8096
First occurrence of element type 112 for cell 1231 at line 8216
Read 2700 cells and 1080 boundary faces.
Processing tag:2467
Starting reading patches at line 13498.
For group 1 named inlet trying to read 90 patch face indices.
For group 2 named outlet trying to read 90 patch face indices.
For group 3 named wall trying to read 900 patch face indices.
Sorting boundary faces according to group (patch)
0: inlet is patch
1: outlet is patch
2: wall is patch
Constructing mesh with non-default patches of size:
inlet 90
outlet 90
wall 900
End
user@machine $ checkMesh
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.3.0 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 2.3.0-f5222ca19ce6
Exec : checkMesh
Date : Feb 08 2016
Time : 10:09:20
Host : "tougeron-prace"
PID : 14056
Case : /home/tougeron/documents/home/Desktop/of_test
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Create polyMesh for time = 0
Time = 0
Mesh stats
points: 2821
faces: 8190
internal faces: 7110
cells: 2700
faces per cell: 5.66667
boundary patches: 3
point zones: 0
face zones: 0
cell zones: 0
Overall number of cells of each type:
hexahedra: 1800
prisms: 900
wedges: 0
pyramids: 0
tet wedges: 0
tetrahedra: 0
polyhedra: 0
Checking topology...
Boundary definition OK.
Cell to face addressing OK.
Point usage OK.
Upper triangular ordering OK.
Face vertices OK.
Number of regions: 1 (OK).
Checking patch topology for multiply connected surfaces...
Patch Faces Points Surface topology
inlet 90 91 ok (non-closed singly connected)
outlet 90 91 ok (non-closed singly connected)
wall 900 930 ok (non-closed singly connected)
Checking geometry...
Overall domain bounding box (-5 -4.97261 0) (5 4.97261 100)
Mesh (non-empty, non-wedge) directions (1 1 1)
Mesh (non-empty) directions (1 1 1)
Boundary openness (2.56326e-18 -2.33391e-17 -3.20007e-17) OK.
Max cell openness = 5.30175e-16 OK.
Max aspect ratio = 20.3071 OK.
Minimum face area = 0.257635. Maximum face area = 5.93849. Face area magnitudes OK.
Min volume = 0.860464. Max volume = 5.07388. Total volume = 7796.69. Cell volumes OK.
Mesh non-orthogonality Max: 0.059133 average: 0.0308002
Non-orthogonality check OK.
Face pyramids OK.
Max skewness = 0.31696 OK.
Coupled point location match (average 0) OK.
Mesh OK.
End
Here, the output after using the Nicolas' script:
user@machine $ checkMesh
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.3.0 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 2.3.0-f5222ca19ce6
Exec : checkMesh
Date : Feb 08 2016
Time : 10:09:05
Host : "tougeron-prace"
PID : 14027
Case : /home/tougeron/Mesh_1
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Create polyMesh for time = 0
Time = 0
Mesh stats
points: 2821
faces: 8190
internal faces: 7110
cells: 2700
faces per cell: 5.66667
boundary patches: 3
point zones: 0
face zones: 0
cell zones: 0
Overall number of cells of each type:
hexahedra: 1800
prisms: 900
wedges: 0
pyramids: 0
tet wedges: 0
tetrahedra: 0
polyhedra: 0
Checking topology...
Boundary definition OK.
Cell to face addressing OK.
Point usage OK.
Upper triangular ordering OK.
Face vertices OK.
Number of regions: 1 (OK).
Checking patch topology for multiply connected surfaces...
Patch Faces Points Surface topology
inlet 90 91 ok (non-closed singly connected)
outlet 90 91 ok (non-closed singly connected)
wall 900 930 ok (non-closed singly connected)
Checking geometry...
Overall domain bounding box (-5 -4.97261 0) (5 4.97261 100)
Mesh (non-empty, non-wedge) directions (1 1 1)
Mesh (non-empty) directions (1 1 1)
Boundary openness (-2.29344e-18 -1.24284e-17 7.15119e-18) OK.
Max cell openness = 6.31392e-16 OK.
Max aspect ratio = 20.3068 OK.
Minimum face area = 0.257634. Maximum face area = 5.93844. Face area magnitudes OK.
Min volume = 0.860452. Max volume = 5.07384. Total volume = 7796.69. Cell volumes OK.
Mesh non-orthogonality Max: 0.0591394 average: 0.0308026
Non-orthogonality check OK.
Face pyramids OK.
Max skewness = 0.316962 OK.
Coupled point location match (average 0) OK.
Mesh OK.
End
Best regards,
William
Hello William
Thank You for replying.I am getting the unused point error when I use a more refined Mesh. this is the result I get. Please let me know if I can rectify this.
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.4.0 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 2.4.0-f0842aea0e77
Exec : checkMesh
Date : Feb 08 2016
Time : 15:48:46
Host : "Kakas"
PID : 5628
Case : /home/student/Desktop/cylinderrefined
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Create polyMesh for time = 0
Time = 0
Mesh stats
points: 142135
faces: 162900
internal faces: 159300
cells: 54000
faces per cell: 5.96667
boundary patches: 3
point zones: 0
face zones: 0
cell zones: 0
Overall number of cells of each type:
hexahedra: 52200
prisms: 1800
wedges: 0
pyramids: 0
tet wedges: 0
tetrahedra: 0
polyhedra: 0
Checking topology...
Boundary definition OK.
Cell to face addressing OK.
***Unused points found in the mesh, number unused by faces: 87174 number unused by cells: 87174
<<Writing 87174 unused points to set unusedPoints
Upper triangular ordering OK.
Face vertices OK.
Number of regions: 1 (OK).
Checking patch topology for multiply connected surfaces...
Patch Faces Points Surface topology
inlet 900 901 ok (non-closed singly connected)
outlet 900 901 ok (non-closed singly connected)
wall 1800 1830 ok (non-closed singly connected)
Checking geometry...
Overall domain bounding box (-5 -4.97261 0) (5 4.97261 100)
Mesh (non-empty, non-wedge) directions (1 1 1)
Mesh (non-empty) directions (1 1 1)
Boundary openness (5.26142e-18 -1.30861e-17 -1.56472e-17) OK.
Max cell openness = 6.75814e-16 OK.
Max aspect ratio = 96.1967 OK.
Minimum face area = 0.00288761. Maximum face area = 1.74219. Face area magnitudes OK.
Min volume = 0.00481249. Max volume = 0.283967. Total volume = 7796.69. Cell volumes OK.
Mesh non-orthogonality Max: 0.00380046 average: 0.000741252
Non-orthogonality check OK.
Face pyramids OK.
Max skewness = 0.318768 OK.
Coupled point location match (average 0) OK.
Failed 1 mesh checks.
End
Regards
John
Hello,
On my computer, after exporting manually your mesh through UNV or the Nicolas' script, everything is OK.
Overall number of cells of each type:
hexahedra: 52200
prisms: 1800
wedges: 0
pyramids: 0
tet wedges: 0
tetrahedra: 0
polyhedra: 0
Checking topology...
Boundary definition OK.
Cell to face addressing OK.
Point usage OK.
Upper triangular ordering OK.
Face vertices OK.
Number of regions: 1 (OK).
I have however met this situation recently that Salome works fine on a computer and makes strange things on another, while using the same script, at the step of mesh generation/export.
So far, I have used Salome on several Ubuntu-based distributions (but also on OpenSUSE, a while ago) without problem. I know someone having today troubles to generate meshes for OpenFOAM with Salome on OpenSUSE. What works fine for me does not work for him.
So, please, give your complete configuration and let's wish the developer team to have a look at this issue.
Mine is: Salome 7.7.1 (universal binaries), Linux Mint 13 64bits (with Mate), OpenFOAM 2.3.0
Sorry for not being able to help more...
Best regards,
William
Hello William,
Thank you for your prompt response. My configuration is: Salome 7.6.0(universal binaries), Linux Ubuntu 14.04 LTS, OpenFOAM 2.4.0. Do you think my Salome version could be a problem?? Thanks again and hope this will help.
Regards,
John
Hello,
I tested now your script with Salome 7.6.0 and the result was the same (checkMesh OK), so the Salome version is not the problem.
Best regards,
Willam
Hello,
Then, do you think the Problem is with openFoam or openFoam not installed properly?
Regards
John
Hi all,
First of all, thanks for your script Nicolas Edh.
I made modification of "SalomeToOpenFoam" script to add a simple graphical interface. I am an amateur programmer, so I apologize for the thoroughness of the code.
The code it's available here: https://github.com/psicofil/salomeToOpenFOAM
A YouTube video demonstration: https://www.youtube.com/watch?v=JQbkhz984lM
Sorry for my bad English.
Regards.
Hi, Lucio,
Very nice!
I didn't know it was possible to launch graphical interfaces from the "Load Script" option!
Very inspiring...
(I would have said, nevertheless, that for a better visibility, it would have been maybe better to start a new thread with a link to this one...)
All the best
William
Dear Friends
i have had the same error " Foam::error::printStack(Foam::Ostream& in "/opt/openfoam211/platforms/linux64GccDPOpt/lib/libOpenFOAM.so" when i was trying to convert my mesh from Salome to OpenFOAM. i tired many theories and finally i found out the reason was in mesh generating option when you have to select a 3D algorithm. all of those algorithms like (Hexahedron and ...) lead to that error for me but the only one worked OK was 3D Extrusion!
so for others who has the same problem and can change their algorithm, changing it to 3D Extrusion may work for you.
Best
Kasra
Dear Nicolas :-
Thank you for your valuable code. When I loaded the script, it run successfully and gives me the following:-
p, li { white-space: pre-wrap; }Number of nodes: 20770
Number of cells: 31200
Counting number of faces:
total number of faces: 82312, internal: 73688, external 8624
Converting mesh to OpenFOAM
Warning, some elements don't have a group (BC). Adding to a new group called defaultPatches
Finished processing boundary faces
. . . . . . . . . : . . . . . . . . . : . . . . . . . . . : . . . . . . . . . : . . . . Finished processing volumes.
Sorting faces in upper triangular order
Writing the file points
Writing the file faces
Writing the file owner
Writing the file neighbour
Writing the file boundary
Finished writing to /home/ali//home/ali/Mesh_1/constant/polyMesh
Converted mesh in 2s
Wrote mesh in 1s
Total time: 3s
finished exporting
now, what is the next step to produce polymesh file ?
my best
Hi all,
I've made little python script that exports a mesh to OpenFOAM.
It's available here: https://github.com/nicolasedh/salomeToOpenFOAM
I know there already are ways to export a mesh, like the unv-format but that format doesn't support pyramids. This script should handle any type of cell, I've tested pyramids, "wedges", tetrahedrons and hexahedrons. The script doesn't require any additional installation. It runs from inside salome as it is.
The way to use the script would be to select the mesh you wish to export and the "load script" (ctrl-T) and selection salomeToOpenFOAM.py. I've included a couple of sample scripts in the above link as well.
Anyways, since I've put some time into the script my hope is that others won't have to. I hope you find it useful.
Best
Nicolas
I know the next step is to export the file as .UNV then executing :-
ideasUnvToFoam Mesh_1.unv
but unfortunately I got:-
Create polyMesh for time = 0
Time = 0
Mesh stats
points: 20770
faces: 82312
internal faces: 73688
cells: 31200
faces per cell: 5
boundary patches: 1
point zones: 0
face zones: 0
cell zones: 0
Overall number of cells of each type:
hexahedra: 0
prisms: 31200
wedges: 0
pyramids: 0
tet wedges: 0
tetrahedra: 0
polyhedra: 0
Checking topology...
Boundary definition OK.
Cell to face addressing OK.
***Unused points found in the mesh, number unused by faces: 570 number unused by cells: 570
<<Writing 570 unused points to set unusedPoints
Upper triangular ordering OK.
Face vertices OK.
*Number of regions: 4
The mesh has multiple regions which are not connected by any face.
<<Writing region information to "0/cellToRegion"
<<Writing region 0 with 7800 cells to cellSet region0
<<Writing region 1 with 7800 cells to cellSet region1
<<Writing region 2 with 7800 cells to cellSet region2
<<Writing region 3 with 7800 cells to cellSet region3
Checking patch topology for multiply connected surfaces...
Patch Faces Points Surface topology
defaultPatches 8624 8320 ok (closed singly connected)
Checking geometry...
Overall domain bounding box (-5.4 -1.45 0) (5.4 41.4 160)
Mesh (non-empty, non-wedge) directions (1 1 1)
Mesh (non-empty) directions (1 1 1)
Boundary openness (-2.02532e-18 -7.59056e-18 -3.0062e-18) OK.
Max cell openness = 3.2864e-16 OK.
Max aspect ratio = 15.6609 OK.
Minimum face area = 0.0457798. Maximum face area = 3.22331. Face area magnitudes OK.
Min volume = 0.0732477. Max volume = 2.48227. Total volume = 23472.9. Cell volumes OK.
Mesh non-orthogonality Max: 14.9383 average: 3.34947
Non-orthogonality check OK.
Face pyramids OK.
Max skewness = 0.347155 OK.
Coupled point location match (average 0) OK.
Failed 1 mesh checks.
End
So, may be that is because SALOME has different attitude for different computers as one member highlighted !
I am using SALOME V8_2_0
Regards
I think you have messed the original python file of Nicolas. Try to download it again and run it. It should work fine.
I think you have messed the original python file of Nicolas. Try to download it again and run it. It should work fine.
Previously suneel wrote:
Hello everyone,
Previously Nicolas Edh wrote:
Hi all,
I've made little python script that exports a mesh to OpenFOAM.
It's available here: https://github.com/nicolasedh/salomeToOpenFOAM
I know there already are ways to export a mesh, like the unv-format but that format doesn't support pyramids. This script should handle any type of cell, I've tested pyramids, "wedges", tetrahedrons and hexahedrons. The script doesn't require any additional installation. It runs from inside salome as it is.
The way to use the script would be to select the mesh you wish to export and the "load script" (ctrl-T) and selection salomeToOpenFOAM.py. I've included a couple of sample scripts in the above link as well.
Anyways, since I've put some time into the script my hope is that others won't have to. I hope you find it useful.
Best
Nicolas
Dear Nicolas:-
Thank you so much for your valuable code. I have NETGEN2D-3D mesh created in Salome 8.2.0 to be exported to openFoam 2.4.0. I export it as .Unv file. When I load your script, Salome shows me the following:-
p, li { white-space: pre-wrap; }found selected mesh exporting to /home/ali/Mesh_1/constant/polyMesh.
Number of nodes: 3873594
Number of cells: 2816410
Counting number of faces:
total number of faces: 5682885, internal: 5582755, external 100130
Converting mesh to OpenFOAM
Finished processing boundary faces
. . . . . . . . . : . . . . . . . . . : . . . . . . . . . : . . . . . . . . . : . . . . . . . . . Finished processing volumes.
Sorting faces in upper triangular order
Writing the file points
Writing the file faces
Writing the file owner
Writing the file neighbour
Writing the file boundary
Finished writing to /home/ali//home/ali/Mesh_1/constant/polyMesh
Converted mesh in 290s
Wrote mesh in 77s
Total time: 367s
finished exporting
What is the next step to get the file in its OpenFoam format ? If you tell me export it as .unv file, I would tell you that there is no difference wether or not I run your script!
Thank you again with my best.
This forum is DEPRECATED, please create new topics in the new SALOME forum.
For existing topics please transfer them to the new forum.