|
[Sponsors] |
[Salome] Script for converting a mesh from Salome-Platform to OpenFOAM |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 16, 2013, 15:14 |
Script for converting a mesh from Salome-Platform to OpenFOAM
|
#1 |
Senior Member
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18 |
Hi all,
I'd like to share a python script that converts a Salome mesh to OpenFOAM. It's really easy to use. Just create the geometry and mesh in salome, select the mesh you want to export and go to file-> load script, select salomeToOpenFOAM and the script will convert your mesh to NameOfMesh/constant/polyMesh. You can download it from https://github.com/nicolasedh/salomeToOpenFOAM. I've included a couple of sample mesh in the sample*py files. I've been searching the forums for a way to convert a mesh from Salome-Platform to OpenFOAM but I haven't found an easy way. Most frequently people seem to suggest that you save the mesh in unv-format and then use ideasUnvToFoam. The downside is that the unv format doesn't support pyramids. Another option I've found is to save the mesh in gmsh-format and then use one specific version of gmsh to save the mesh in another specific version then finally use gmshToFoam. Then there is pythonFlu, which I suppose can do the same thing but is a bit overkill for my purposes. Anyways I hope you find it useful. As people tend to point out, this script is in no way endorsed by anyone but me nor am I affiliated with anyone but myself... Happy foaming Nicolas |
|
November 2, 2013, 11:57 |
|
#2 |
Senior Member
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18 |
Hi,
I've just added support for internal patches, i.e. baffles or inter-region patches. The script has been tested with Salome 7.2 and OpenFOAM 2.2.x. Although I see no reason why it shouldn't work on other version of OpenFOAM. Included in the git repository are several sample scripts that creates a mesh using salome and exports it to OpenFOAM. For instance there is sampleMultiRegionPipeWithViscous.py which creates a pipe with a spherical solid inside. Both the pipe and the solid are meshed using layers. The mesh is exported to openfoam with cellZones for each of the regions. Just run Code:
splitMeshRegions -cellZones -overwrite Let me know if you find something that doesn't work or have any ideas for improvement. Best Nicolas |
|
November 4, 2013, 10:14 |
Thanks a lot!
|
#3 |
Senior Member
|
Hi Nicolas, just these days I was looking for some tool like that! I definitely will give it a try (also with older versions of OpenFOAM) with some mean meshes I am building in Salome. Of course I will inform you about any problems - as well as about tested capabilities! ;-) Thank you very much for that tool already now! Cheers, Bernhard
|
|
November 29, 2013, 17:49 |
|
#4 |
Senior Member
|
Hi Nicholas,
thanks a lot for your effort. I tried your script, but I ran into following error, can you tell me what does it mean? Code:
p, li { white-space: pre-wrap; } >>> execfile(r"/home/geeko/Documents/Salome_varie/salomeToOpenFOAM-master/salomeToOpenFOAM.py") found selected mesh exporting to /home/geeko/salome/appli_V7_2_0/Mesh_1/constant/polyMesh Number of nodes: 2947 Number of cells: 12780 Counting number of faces: total number of faces: 27015, internal: 24105, external 2910 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 Traceback (most recent call last): File "<input>", line 1, in <module> File "/home/geeko/Documents/Salome_varie/salomeToOpenFOAM-master/salomeToOpenFOAM.py", line 603, in <module> exportToFoam(mesh,mesh.GetName()) File "/home/geeko/Documents/Salome_varie/salomeToOpenFOAM-master/salomeToOpenFOAM.py", line 397, in exportToFoam fileBoundary.write("\tnFaces\t\t%d;\n" %grpNrFaces[ind]) IndexError: list index out of range |
|
November 30, 2013, 03:43 |
|
#5 |
Senior Member
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18 |
Hi Michele,
Thanks for posting back the problem. All I can see is that there is an issue when you write the boundary file. I haven't seen that particular error before. Would it be possible for you to upload a python-dump file so I can try it my self? I haven't tested the script on all possible combinations of meshes so it could be a bug I haven't seen. Otherwise you could try to set debug=2 on line 51 in salomeToOpenFOAM and see if you can find the error. Best Nicolas |
|
December 2, 2013, 07:58 |
|
#6 |
Senior Member
|
Hi Nicolas,
sorry for late answer, but I was on a trip. Using your script, I manually perform these steps: 1 - import step file of the geometry (a simple one in this case); 2 - create group of faces and volumes; 3 - mesh the geometry (I used Netgen 3D-2D-1D); 4 - select mesh1 and load the script. Is this a right workflow? Anyway, I tried to raise debug level up to 2, here's the message: Code:
p, li { white-space: pre-wrap; } >>> execfile(r"/home/geeko/Documents/salome/salomeToOpenFOAM.py") found selected mesh exporting to /home/geeko/Mesh_1/constant/polyMesh Number of nodes: 1362 Number of cells: 5046 Counting number of faces: total number of faces: 10953, internal: 9231, external 1722 Converting mesh to OpenFOAM found group "inlet" of type FACE, 178 found group "outlet" of type FACE, 178 found group "faninlet" of type FACE, 17 found group "fanoutlet" of type FACE, 17 found group "wall" of type FACE, 1332 total number of faces: 10953, internal: 9231, external 1722 Finished processing boundary faces bcFaces: 1722 bcFacesSorted: 1722 owner: 10953 neighbour: 9231 . . . . . . . . . : . . . . . . . . . : . . . . . . . . . : . . . . . . . . . : . . Traceback (most recent call last): File "<input>", line 1, in <module> File "/home/geeko/Documents/salome/salomeToOpenFOAM.py", line 602, in <module> exportToFoam(mesh,mesh.GetName()) File "/home/geeko/Documents/salome/salomeToOpenFOAM.py", line 248, in exportToFoam neighbour[fidinof]=ofvid IndexError: list assignment index out of range I tryed to raise debug level up to 3, here the response (I summarized it): Code:
p, li { white-space: pre-wrap; } volume id: 6881, num nodes 4, nodes:[660, 616, 659, 1262] found bc face: 1430, [660, 616, 659], cell 4997 an owner already exist for 1, [660, 1262, 616], cell 4997 an owner already exist for 2, [616, 1262, 659], cell 4997 a new face was found, 3, [660, 659, 1262], cell 4997 volume id: 6882, num nodes 4, nodes:[1199, 660, 659, 1262] an owner already exist for 0, [1199, 660, 659], cell 4998 an owner already exist for 1, [1199, 1262, 660], cell 4998 Traceback (most recent call last): File "<input>", line 1, in <module> File "/home/geeko/Documents/salome/salomeToOpenFOAM.py", line 602, in <module> exportToFoam(mesh,mesh.GetName()) File "/home/geeko/Documents/salome/salomeToOpenFOAM.py", line 248, in exportToFoam neighbour[fidinof]=ofvid IndexError: list assignment index out of range Let me know waht you need.. Regards |
|
December 2, 2013, 09:29 |
|
#7 |
Senior Member
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18 |
Hi,
Yes either the stl or the hdf would be necessary. Basically every thing I need to recreate your steps. The work flow is OK although I haven't tested to mesh from an existing stl. Netgen should work fine. It isn't necessary to create a group of volumes if you only have one region. I'll try to recreate your steps tonight when I get home. Best regards Nicolas |
|
December 2, 2013, 15:35 |
|
#8 |
Senior Member
|
Hi,
enclosed you can find the step file, as you can see is a simple model that I'm using to understand how to set up properly a basic problem concerning internal faces, before going deeper into hard ones. The model is made of 3 cylinders. For example: try to think about the one in the middle as a generic axial fan, where I want to set static pressure BC between suction and delivery. the other two cylinders are generic volume of air: one is on suction line, other is on discharge line. As mentioned bove, I performed meshing using a generic scheme as Netgen 3D-2D-1D with theta hypotesis. Only paramter impose is max size. Hope it can be of help. |
|
December 2, 2013, 17:34 |
|
#10 |
Senior Member
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18 |
Hi,
Thank you for the files. The good news is that I've found the issue. It might take some time to fix though. For some reason salome reports that your baffles are external faces which confuses the script. I'll have a look at it. In the mean time, it is possible to export internal baffles. Have a look at sampleMultiRegionPipeWithViscous.py. It might work if you create one group of volumes for each cylinder. /Nicolas |
|
December 3, 2013, 01:45 |
|
#11 |
Senior Member
|
Hi Nicolas,
sampleMultiRegionPipeWithViscosity is what I was looking for: indeed salomeToOpenFoam worked properly with your example. The only difference I found between your sample and mine is that I have pairs of faces connecting each other (see inletFan with wall for example), and only one solid region. In your sample you have several solid region. Michele |
|
December 3, 2013, 03:16 |
solved (?)
|
#12 |
Senior Member
|
Hi,
I build the step file building 3 different solids (region) according to the 3 different cylinders and defining group for faces internal patches, walls, ecc... I also created a grouup concerning 3 solid regions called "internal". I ran SalomeToOpenFOAM.py script and worked properly. Attached the screenshot of paraview. So if you have to define internal baffles, you have to define the volume containing them as well. I don't understand if this limitation comes with the OpenFOAM scripts or other: I mean, why is it not possible to have only one solid region with internal faces? Michele |
|
December 3, 2013, 16:29 |
|
#13 | ||
Senior Member
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18 |
Hi,
I'm glad to hear you got it working! Quote:
I think our first task would be to figure out how to create a proper baffle in Salome. Then figure out how to export it. Quote:
For the script to work it needs to be able to distinguish between groups that are regular patches and groups that are internal. Currently the script uses a salome filter to get a list of all faces that lie on the exterior of the domain (SMESH.FT_FreeFaces). If a group of faces has faces that aren't in the list of exterior faces then the group is considered to be a baffle. This should work as long as we can create a proper baffle in Salome. Let me know if you have any success in creating a proper baffle in Salome. After all there are scenarios where one might model a baffle that doesn't lie on the interface between two volumes. /Nicolas |
|||
December 3, 2013, 19:28 |
|
#14 | |
Senior Member
|
Hi NIcolas,
well, I "played" a bit after have accomplished to make the script run properly. First: Apart to make the script works, I'm facing some normal usage problem of meshing with Salome; so I'm focusing to understand how to set up a good mesh (viscous layer,ecc...) even if I had the same feeling that something between the mesh doesn't work right! I think I have to "play" a little more before making any conclusion. Second: Meanwhile I would like to set up a case with OpenFOAM and be able to run it (example: fan inside flow domain, conjugate heattransfer solid-gas, ecc...) So my tasks are two, and they require me a lot of time. Anyway what you made is a good starting point for me! Quote:
Let's say that for the moment for me is okay, and I'm going to use your script to generate the mesh I need. I think it's better if I take note of some other bugs i'll face before reporting you. Thank you by now! Michele |
||
December 4, 2013, 02:38 |
|
#15 |
Senior Member
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18 |
Good luck Michele!
OpenFOAM can seem daunting at first but it is worth the time spent on it. You learn a lot. So good luck with your efforts! For others reading this thread I created a new sample mesh that uses a baffle. The script will export the mesh and it runs. checkMesh will report "multiply connected (shared edge)" and write all the points on the baffle to a set nonManifoldPoints. However, the mesh will run ok. Just do Code:
git pull 1.) Create the fluid domain in (GEOM module) 2.) Create your baffle (in GEOM module) 3.) Use "partion" with the fluid domain as object and the baffle as tool (in GEOM module) 4.) Mesh and create groups from geometry. Be sure to include the baffle as a separate group. Export the mesh to OpenFOAM. /Nicolas |
|
January 11, 2014, 08:00 |
|
#16 |
New Member
Join Date: Nov 2013
Posts: 20
Rep Power: 13 |
Hey Nicolas,
this script is exactly what I need right now! Thank you so much for that, I was really having troubles getting a geometry containing pyramids converted. Btw: At first I was using Salome-MECA (I think 2013), and there your script failed due to not finding the smesh module. But using Salome 7.3.0 solved that issue. Thanks again, amazing work! |
|
January 11, 2014, 18:52 |
|
#17 | |
Senior Member
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18 |
Quote:
Thanks for the feedback! It's good to hear the code works for 7.3.0 as well. I haven't tested Salome-MECA and don't know anything about it. Maybe the smesh model isn't included in MECA or maybe something needs to be added to the python path. If you come up with a solution I'm happy to include the changes. /Nicolas |
||
January 16, 2014, 12:50 |
|
#18 |
Member
Sergey
Join Date: Nov 2013
Posts: 87
Rep Power: 13 |
Hi Nicolas!
Thank you for posting it. Look like it is exactly what i need. Hope I will figure out how to ue your script. |
|
January 16, 2014, 19:28 |
|
#19 |
Senior Member
|
I can confirm that the script works for 7.3.0 the same way as in 7.2.0.
@skuznet: The use of the script is a rather simple thing: Within Salome go to the Menu "File" -> "Load Script" and simply chose salomeToOpenFOAM.py from where you saved it. That is all! In the console window of Salome you will see that it first counts different things, then checks the boundaries, and finally the different files are written. In the end it even provides you with the time it took to convert the mesh! In my case, conversion of 80'000 cells takes approximately 20 seconds, 1 million cells takes around 250 to 300 seconds (if I remember correctly), depending on the mesh structure. The computer I am using is a Core i7 vPro, so don't wonder if it takes some time on not-so-new hardware. Nevertheless: It is a great tool and up to now it converted every mesh flawlessly! Thanks again, Nicolas! |
|
January 18, 2014, 12:55 |
|
#20 |
Senior Member
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18 |
Your welcome Bernhard, it nice to hear that the script is used!
Just be sure to have the mesh you wish to export selected before you run the script. It's also possible to run salomeToOpenFOAM from the python console inside salome. Check out the sample*py scripts that are included. They create different types of meshes and export them. The last 5 lines or so shows how to use the script from the command line. (I've only tested them with Salome 7.2.0). In order to run the script from the command line type the following: Code:
#if you you don't have the script in the current working dir import sys sys.path.append("path/to/salomeToOpenFOAM") ##### #import the module as stof since it's easier to type import salomeToOpenFOAM as stof #find the mesh you wan't to export #(have it selected in the GUI and be in the MESH module) #take the first mesh in the list of selected Meshes myMesh=stof.findSelectedMeshes()[0] #if you want it to run quiet stof.debug=0 #export it stof.exportToFoam(myMesh,"mycase/polyMesh") Happy foaming! Nicolas |
|
Tags |
mesh conversion, openfoam, salome meca |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Salome] how to setFields in openFOAM when you have imported mesh from salome or other package | 13msmemusman | OpenFOAM Meshing & Mesh Conversion | 11 | May 18, 2022 08:30 |
[Salome] import mesh from salome to openfoam | dome90 | OpenFOAM Meshing & Mesh Conversion | 2 | April 21, 2016 00:58 |
[Salome] Step to export mesh from SALOME to OpenFoam for 3D MRF geometry | aminem | OpenFOAM Meshing & Mesh Conversion | 0 | September 16, 2014 11:18 |
[Salome] Mesh Salome 7.3.0 to OpenFoam | Ahadi | OpenFOAM Meshing & Mesh Conversion | 5 | July 1, 2014 11:11 |
Mesh conversion problem from Salome to openfoam | jishnusoni | OpenFOAM | 15 | March 3, 2010 02:53 |