CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Meshing & Mesh Conversion

[Salome] Script for converting a mesh from Salome-Platform to OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree34Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 16, 2013, 15:14
Default Script for converting a mesh from Salome-Platform to OpenFOAM
  #1
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
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
elvis, aee, y_jiang and 11 others like this.
nsf is offline   Reply With Quote

Old   November 2, 2013, 11:57
Default
  #2
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
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
after the mesh has been exported.

Let me know if you find something that doesn't work or have any ideas for improvement.

Best
Nicolas
manju819 and skuznet like this.
nsf is offline   Reply With Quote

Old   November 4, 2013, 10:14
Default Thanks a lot!
  #3
Senior Member
 
Bernhard Linseisen
Join Date: May 2010
Location: Heilbronn
Posts: 183
Blog Entries: 1
Rep Power: 16
Linse is on a distinguished road
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
nsf likes this.
Linse is offline   Reply With Quote

Old   November 29, 2013, 17:49
Default
  #4
Senior Member
 
M. C.
Join Date: May 2013
Location: Italy
Posts: 286
Blog Entries: 6
Rep Power: 17
student666 is on a distinguished road
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
student666 is offline   Reply With Quote

Old   November 30, 2013, 03:43
Default
  #5
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
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
nsf is offline   Reply With Quote

Old   December 2, 2013, 07:58
Default
  #6
Senior Member
 
M. C.
Join Date: May 2013
Location: Italy
Posts: 286
Blog Entries: 6
Rep Power: 17
student666 is on a distinguished road
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

Question; why the internal group of volume hasn't been recognized? is it not necessary?

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
attached there's the dump file of the mesh, do you like to have the hdf file of Salome? I'm using version 7.2.

Let me know waht you need..

Regards
Attached Files
File Type: gz salomeToOpenFOAM_Michele.py.tar.gz (1.8 KB, 32 views)
student666 is offline   Reply With Quote

Old   December 2, 2013, 09:29
Default
  #7
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
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
nsf is offline   Reply With Quote

Old   December 2, 2013, 15:35
Default
  #8
Senior Member
 
M. C.
Join Date: May 2013
Location: Italy
Posts: 286
Blog Entries: 6
Rep Power: 17
student666 is on a distinguished road
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.
Attached Files
File Type: zip salomeToOpenFOAM.zip (2.9 KB, 47 views)
student666 is offline   Reply With Quote

Old   December 2, 2013, 15:47
Default
  #9
Senior Member
 
M. C.
Join Date: May 2013
Location: Italy
Posts: 286
Blog Entries: 6
Rep Power: 17
student666 is on a distinguished road
Here's the hdf file.

It's quitea a rough mesh, but upload size limit dosen't allow large file (97kb ?!?).

Regards
Attached Files
File Type: gz salomeToOpenFOAM.hdf.tar.gz (32.5 KB, 26 views)
student666 is offline   Reply With Quote

Old   December 2, 2013, 17:34
Default
  #10
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
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
nsf is offline   Reply With Quote

Old   December 3, 2013, 01:45
Default
  #11
Senior Member
 
M. C.
Join Date: May 2013
Location: Italy
Posts: 286
Blog Entries: 6
Rep Power: 17
student666 is on a distinguished road
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
student666 is offline   Reply With Quote

Old   December 3, 2013, 03:16
Default solved (?)
  #12
Senior Member
 
M. C.
Join Date: May 2013
Location: Italy
Posts: 286
Blog Entries: 6
Rep Power: 17
student666 is on a distinguished road
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
Attached Images
File Type: jpg snapshot1.jpg (34.3 KB, 200 views)
student666 is offline   Reply With Quote

Old   December 3, 2013, 16:29
Default
  #13
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
Hi,

I'm glad to hear you got it working!

Quote:
Originally Posted by student666 View Post
...
So if you have to define internal baffles, you have to define the volume containing them as well.
I'm not sure. See, I recreated your problem on a simplified geometry. In my case the baffle/internal face was not meshed and the 3D mesh did not conform the the internal baffle. I rechecked your case, although your internal face have been meshed the 3D mesh does not conform to the internal faces, see the attached picture. This could be the cause of the problem or it might another one.

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:
Originally Posted by student666 View Post
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?
Well OpenFOAM does support baffles only they are treated differently. Or rather they are treated as external patches and hence each face occurs twice, so they need special treatment in the script. I won't go in too details unless you really want to know or try to fix it your self.

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
Attached Images
File Type: jpg problem.jpg (74.6 KB, 138 views)
nsf is offline   Reply With Quote

Old   December 3, 2013, 19:28
Thumbs up
  #14
Senior Member
 
M. C.
Join Date: May 2013
Location: Italy
Posts: 286
Blog Entries: 6
Rep Power: 17
student666 is on a distinguished road
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:
I won't go in too details unless you really want to know or try to fix it your self
... and no! I really won't go any further on python script at the moment, because it will requires more extra-timel.

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
student666 is offline   Reply With Quote

Old   December 4, 2013, 02:38
Default
  #15
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
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
to update. The new sample is called samplePipeWithBaffle.py. The basic steps to generate a baffle in salome are:

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
nsf is offline   Reply With Quote

Old   January 11, 2014, 08:00
Default
  #16
New Member
 
Join Date: Nov 2013
Posts: 20
Rep Power: 13
Jakob1 is on a distinguished road
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!
nsf likes this.
Jakob1 is offline   Reply With Quote

Old   January 11, 2014, 18:52
Default
  #17
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
Quote:
Originally Posted by Jakob1 View Post
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!
Hi Jakob,

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
nsf is offline   Reply With Quote

Old   January 16, 2014, 12:50
Default
  #18
Member
 
Sergey
Join Date: Nov 2013
Posts: 87
Rep Power: 13
skuznet is on a distinguished road
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.
skuznet is offline   Reply With Quote

Old   January 16, 2014, 19:28
Default
  #19
Senior Member
 
Bernhard Linseisen
Join Date: May 2010
Location: Heilbronn
Posts: 183
Blog Entries: 1
Rep Power: 16
Linse is on a distinguished road
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!
nsf likes this.
Linse is offline   Reply With Quote

Old   January 18, 2014, 12:55
Default
  #20
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
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")
One thing to note: If the name of a bc contains the word "wall", i.e. walls, upperWall or WALL etc, then the patch type is set to wall in the file boundary otherwise the type is assumed to be "patch".

Happy foaming!

Nicolas
Gerhard likes this.
nsf is offline   Reply With Quote

Reply

Tags
mesh conversion, openfoam, salome meca


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


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


All times are GMT -4. The time now is 08:22.