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 Tree33Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 21, 2015, 10:28
Default
  #41
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings to all!

@Nicolas: I've created a basic wiki page to help getting your salomeToOpenFOAM script(s) known to the community that uses OpenFOAM technology: http://openfoamwiki.net/index.php/Co...lomeToOpenFOAM

May you or anyone else feel free to update that wiki page!

Best regards,
Bruno
nsf and aadicfd like this.

Last edited by wyldckat; March 21, 2015 at 13:46.
wyldckat is offline   Reply With Quote

Old   March 23, 2015, 04:02
Default
  #42
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
Hi Bruno thanks for the stub!

Next time I modify the script I'll see if I can't find time to update the wiki as well.

/Nicolas

Last edited by nsf; March 23, 2015 at 04:03. Reason: fixed typo
nsf is offline   Reply With Quote

Old   June 17, 2015, 12:30
Default
  #43
Member
 
pici's Avatar
 
Pierluigi Cirrottola
Join Date: Jun 2013
Posts: 52
Rep Power: 12
pici is on a distinguished road
Hi Nicolas,
perhaps do you have a solution about direct reading a .vtk mesh file into Salomé?
At present I'm pushed to a work-around:
step 1) using GMESH I read .vtk and I save to .med
step 2) using Salomé I read .med and , after some editing, I use your tool to export to openFOAM.
Thanks a lot
Piero
pici is offline   Reply With Quote

Old   June 23, 2015, 14:37
Default
  #44
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 pici View Post
Hi Nicolas,
perhaps do you have a solution about direct reading a .vtk mesh file into Salomé?
At present I'm pushed to a work-around:
step 1) using GMESH I read .vtk and I save to .med
step 2) using Salomé I read .med and , after some editing, I use your tool to export to openFOAM.
Thanks a lot
Piero
Perhaps you've already solved this, but have you tried vtkUnstructuredToFoam otherwise I don't know

/Nicolas
nsf is offline   Reply With Quote

Old   October 5, 2015, 13:24
Default
  #45
Member
 
hssn
Join Date: Mar 2015
Posts: 31
Rep Power: 11
hssnjfry is on a distinguished road
hi
icreated mesh and load scrip salomeToOpenFOAM.py and what happened than?
which file created ? and where?
hssnjfry is offline   Reply With Quote

Old   October 5, 2015, 16:05
Default
  #46
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 hssnjfry View Post
hi
icreated mesh and load scrip salomeToOpenFOAM.py and what happened than?
which file created ? and where?
Hi, I think the output of the scripts tells you were it saves the files. It's probably from the same folder as you started Salome. There you hopefully find a folder called Mesh_1/polyMesh.

With the little information you've provided that's really all I can say. Please read through this thread and I think you'll find out how to use the script.

Best Regards
nsf is offline   Reply With Quote

Old   January 12, 2016, 07:21
Default problem with select a mesh
  #47
Member
 
Paul Palladium
Join Date: Jan 2016
Posts: 93
Rep Power: 10
Fauster is on a distinguished road
Hi,


I got a strange error and i don't understand the problem. I didn't find any information on the internet.


When i run the script (on Salome 7.7.1) I get an error message :

>>> execfile(r"/home/g-met/Bureau/calculB_mesh/salomeToOpenFOAM.py")

You have to select a mesh object and then run this script.
or run the export function directly from TUI

import SalomeToOpenFOAM
SalomeToOpenFOAM.exportToFoam(mesh,path)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/g-met/Bureau/calculB_mesh/salomeToOpenFOAM.py", line 615, in <module>
main()
File "/home/g-met/Bureau/calculB_mesh/salomeToOpenFOAM.py", line 605, in main
for mesh in meshes:
TypeError: 'NoneType' object is not iterable


But i did select Mesh_1 in the object Brower...


I printed
selected=salome.sg.getSelected(i)
selobjID=salome.myStudy.FindObjectID(selected)
selobj=selobjID.GetObject()


and i got

0:1:2:3
<SALOMEDS._objref_SObject instance at 0x45a24c0>
<salome.smesh.smeshBuilder.meshProxy instance at 0x279e59c0>


Do you have any idea about this ?


Thanks for your help


Best Regards
Fauster is offline   Reply With Quote

Old   January 12, 2016, 16:09
Default
  #48
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 Fauster View Post
Hi,


I got a strange error and i don't understand the problem. I didn't find any information on the internet.


When i run the script (on Salome 7.7.1) I get an error message :

>>> execfile(r"/home/g-met/Bureau/calculB_mesh/salomeToOpenFOAM.py")

You have to select a mesh object and then run this script.
or run the export function directly from TUI

import SalomeToOpenFOAM
SalomeToOpenFOAM.exportToFoam(mesh,path)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/g-met/Bureau/calculB_mesh/salomeToOpenFOAM.py", line 615, in <module>
main()
File "/home/g-met/Bureau/calculB_mesh/salomeToOpenFOAM.py", line 605, in main
for mesh in meshes:
TypeError: 'NoneType' object is not iterable


But i did select Mesh_1 in the object Brower...


I printed
selected=salome.sg.getSelected(i)
selobjID=salome.myStudy.FindObjectID(selected)
selobj=selobjID.GetObject()


and i got

0:1:2:3
<SALOMEDS._objref_SObject instance at 0x45a24c0>
<salome.smesh.smeshBuilder.meshProxy instance at 0x279e59c0>


Do you have any idea about this ?


Thanks for your help


Best Regards
Hi,

Thanks for using the code!

I havn't had time to try out Salome 7.7.1. It would seem they changed the class name of meshes. I don't have time to investigate this today but if you'd like to give it a try the snippet that checks if the user actually selected a mesh is around line 572. You could try to comment out those lines and just have the function return meshes.

But I don't know what else got changed so there might be other errors as well. I'll see if I can find some time to look at it this week. Let me know if you give it a try.

Best Regards
Nicolas
nsf is offline   Reply With Quote

Old   January 14, 2016, 16:39
Default
  #49
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
I've pushed an update to github that works for a small testcase on Salome 7.7.

I haven't had time for proper testing so please let me know if you find bugs.

Best Regards
Nicolas
nsf is offline   Reply With Quote

Old   January 15, 2016, 04:09
Default
  #50
Member
 
Paul Palladium
Join Date: Jan 2016
Posts: 93
Rep Power: 10
Fauster is on a distinguished road
Thanks Nicolas for your help,
I tried this morning on a mesh. it works. But when I refine my mesh it seems to take a long long time to convert. After 5 min the conversion is still not finished.
Is it normal ?
Regards
Fauster is offline   Reply With Quote

Old   January 15, 2016, 05:35
Default
  #51
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 Fauster View Post
Thanks Nicolas for your help,
I tried this morning on a mesh. it works. But when I refine my mesh it seems to take a long long time to convert. After 5 min the conversion is still not finished.
Is it normal ?
Regards
Yes. If you read previous post you'll find that this script is not very efficient.
I'm sure it could be speed up alot. But the main problem is that there is no information (or at least not last I checked) on neighbours of a cell face in salome. That means the script has to look up which faces it already has added. At around 1 million cells it's actually faster to generate the mesh than to convert it.

If you'd like to improve the script then please go ahead!
nsf is offline   Reply With Quote

Old   January 15, 2016, 06:09
Default
  #52
Member
 
Paul Palladium
Join Date: Jan 2016
Posts: 93
Rep Power: 10
Fauster is on a distinguished road
Thanks for your reply Nicolas.

I am afraid I can't improve your script. It's really not my domain of knowledge. In fact, I wanted to use your script because the UNV to FOAM procedure gave me a lot of errors (especially when I have prisms layers with a complex geometry shape). The mesh on salome is ok but when I convert it to openfoam I get negative volume, non orthogonal faces and/or high ratio elements).

I read a post of you explaining those problems could come from the conversation unv to foam. The speed of the conversion is not really a problem for me. I was just a bit surprised .

Thanks again for your help.
Fauster is offline   Reply With Quote

Old   July 6, 2016, 11:14
Default Am I converting my mesh correctly?
  #53
New Member
 
Sian
Join Date: Jun 2016
Posts: 5
Rep Power: 9
alanaj5 is on a distinguished road
Hi,

Thanks for all your posts. They've been really helpful.
Thanks also to Nicolas for creating the script.

I'm converting a mesh from Salome 7.8.0 for OpenFOAM 2.1.1, using the Salome 7.7 version of the script. I followed the instructions in the README file, but found that creating groups of volumes on the mesh as indicated in the file, didn't allow me to define my boundaries. I created groups of faces on my mesh instead and was able to create the required mesh and modify by boundaries. I was then able to run it in OpenFOAM and check it in paraFOAM.

I'm a little worried that creating groups of volumes on the mesh was required for another purpose, that I may have missed. Also, do I need to specify which are internal faces and should be treated as face matching or face merging? I'm a little concerned as OpenFOAM cannot converge to a solution on my mesh. This is most likely due to a completely separate issue though.

Thanks,
Siân
alanaj5 is offline   Reply With Quote

Old   July 6, 2016, 16:16
Default
  #54
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
Hi Siân,

Groups of volumes is for creating cell zones. For use with setFields or similar tools.

As you've already noted groups of faces is for creating boundaries. You should not set boundaries for internal faces. The exception would be if you want a baffle. Please check the included sample scripts.

The mesh could be a source of problem but the most probable is ill defined boundary conditions. If check mesh is fine try to run something more simple like potentialFoam and see if that works.

Best regards
Nicolas
nsf is offline   Reply With Quote

Old   November 2, 2016, 08:10
Default
  #55
Member
 
Sören Sander
Join Date: Sep 2012
Location: Germany
Posts: 43
Rep Power: 13
Sören Sander is on a distinguished road
Hello Nicolas,

thank you very much for your great work. Most of the meshes I exported are working fine. However, I cannot export a wedge to openFoam. The mesh is successfully exported, but the "wedge" is missing in the boundary file. What I did:

1. I defined a pipe-like geometry, with an inlet at the y-Plane, an outlet downstream and an axis along and on the x-Axis. The parallel side is named walls.

2. I created a netgen 1D-2D hypothesis based surface mesh

3. I created and added the boundaries (edges for walls, inlet, outlet, axis and 1 surface "front") and added them to the mesh

4. I rotated the mesh -2.5 degree around x-axis

5. I revolved the mesh 5 degree around x-axis

6. This leaves me with a 3D wedge with several boudaries (edges, surfaces, volumes). I deleted all except the groups of faces for front, back (front_rotated), walls_rotated, inlet_rotated, outlet_rotated and the groups of edges: axis.

7. I applied your script:
Code:
>>> execfile(r"/.../salomeToOpenFOAM.py")
found selected mesh exporting to /.../pipe/constant/polyMesh
Number of nodes: 18679
Number of cells: 18398
Counting number of faces:
total number of faces: 64433, internal: 27357, external 37076
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 /.../pipe 
Converted mesh in 14s
Wrote mesh in 1s
Total time: 15s
The mesh is output, but misses to detect and write the wedge(axis). The axis is no real surface, thus, it will always appear in face of edges. Can you share, how to correctly generate and export a wedge to openfoam?
I use Salome 7.6.0.
Sören Sander is offline   Reply With Quote

Old   November 2, 2016, 14:52
Default
  #56
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
Hi Sören,

It's nice to see you've found uses for the script.

I've actually never worked with wedges. Therefore I never considered them while writing the script. I'm not sure I can think of a bullet proof way for the script to know it should create a wedge. But I can offer two workarounds.

1) Export the mesh as a 3D mesh using salomeToOpenFOAM. Then go to constant/polyMesh/boundary and manually adjust the file so it works. You'll have to set "type wedge;" for the front and back patches. You'll also have to add
Code:
    axis
    {
        type            empty;
        inGroups        1(empty);
        nFaces          0;
        startFace       14855;	//since nFaces is 0 this number doesn't matter. 
    }
as an additional patch. Do remember to increase the number of patches. Have a look at for example $FOAM_TUTORIALS/multiphase/interFoam/LES/nozzleFlow2D.

2) Is to mesh a 2D surface in salome and save it as an STL, then extrude it as a wedge. Have a lookt at
$FOAM_APP/utilities/mesh/generation/extrude/extrudeMesh/extrudeMeshDict which shows how to extrude an STL to a 3D wedge. Since you cant name edges in STL-files you'll have to recreate the patches. Have a look at the autoPatch utility.

Personally I would go for option 1 first. If you encounter a major problem I would go for option 2.

Now, as I already pointed out in this thread. The script is pure python and one of the first scripts I created. It's very slow. Unbearably slow for meshes larger than 1M cells.

Good luck!

Best Regards
Nicolas
nsf is offline   Reply With Quote

Old   November 3, 2016, 04:10
Default
  #57
New Member
 
Join Date: Mar 2015
Location: Earth yet
Posts: 25
Rep Power: 11
coccone is on a distinguished road
Code:
>>> execfile(r".../openFOAM/salomeToOpenFOAM.py")
 You have to select a mesh object and then run this script.
 or run the export function directly from TUI
  import SalomeToOpenFOAM
  SalomeToOpenFOAM.exportToFoam(mesh,path)
 Traceback (most recent call last):
   File "<input>", line 1, in <module>
   File ".../openFOAM/salomeToOpenFOAM.py", line 607, in <module>
     main()
   File ".../openFOAM/salomeToOpenFOAM.py", line 597, in main
     for mesh in meshes:
 TypeError: 'NoneType' object is not iterable
 >>> 


Hi Nicholas,

I am getting the same error
report as a few post earlier on Salomé 7.8.0, I did select a mesh to export and I also used the updated 02/2016 version of salomeToFoam. I tried it on some old mesh I know I had succesfully exported with previous salomé version and your old python script, but it does not work either. Is there a workaround for that?

Thanks in advance for your effort


coccone is offline   Reply With Quote

Old   November 3, 2016, 17:19
Default
  #58
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
Hi cocccone,

I've just installed salome 7.8 and it seems to work. I can't reproduce your problem. For some reason the script doesn't recognize whatever you selected as a mesh, I can't guess as to why.

I have however just pushed a commit that will improve the error message.

Best Regards
Nicolas
nsf is offline   Reply With Quote

Old   November 4, 2016, 04:03
Default
  #59
New Member
 
Join Date: Mar 2015
Location: Earth yet
Posts: 25
Rep Power: 11
coccone is on a distinguished road
Quote:
Originally Posted by nsf View Post
Hi cocccone,

I've just installed salome 7.8 and it seems to work. I can't reproduce your problem. For some reason the script doesn't recognize whatever you selected as a mesh, I can't guess as to why.

I have however just pushed a commit that will improve the error message.

Best Regards
Nicolas
Thank you for such a quick reply Nicolas!
I just tried the last one you pushed yesterday and it works with that, no error showing up. I wondered if I was mistaken using the previous version I had (10/02/2016) so I tried with that again and it still did not work. Attached there is the troublesome version if you want to dig into it, as far as it concerns me I am fine with the new one.

Thanks again for your time, I appreciated it. Take care,
coccone
Attached Files
File Type: txt salomeToOpenFOAM.txt (21.5 KB, 14 views)
nsf likes this.
coccone is offline   Reply With Quote

Old   December 13, 2016, 05:31
Smile extra faces in salome
  #60
Senior Member
 
Bill Wang
Join Date: Aug 2014
Posts: 109
Rep Power: 11
6863523 is on a distinguished road
Dear,
I am really appreciated for Nicolas's work. It saved me a lot of time!!!
I have solved the problem about the internal faces. Just post to make the problem clear and provide possible solutions.
I met a problem with internal faces. The simple geometry is attached.
I used partition tool in Salome, which helps me to divide the whole block into several blocks, but there are extra faces, as highlighted in the attachment.
They are not expected to be defined in OpenFOAM, as they are actully in the flow domain(The small square is the solid domain).
When I read the salome file, these undefined faces will be added to a new group defaulPatches.
Code:
>>> execfile(r"/home/LEPT/ywang/OpenFOAM/ywang-3.0.1/runsalomeToOpenFOAM-mastersalomeToOpenFOAM.py")
found selected mesh exporting to /home/LEPT/ywang/OpenFOAM/ywang-3.0.1/runlome/Mesh_1/constant/polyMesh.
Number of nodes: 592480
Number of cells: 0
Counting number of faces:
total number of faces: 296880, internal: -296880, external 593760
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/LEPT/ywang/OpenFOAM/ywang-3.0.1/runlome//home/LEPT/ywang/OpenFOAM/ywang-3.0.1/runsalome/Mesh_1/constant/polyMesh 
Converted mesh in 2703s
Wrote mesh in 6s
Total time: 2709s
finished exporting
>>>
When I checkMesh in OpenFOAM, the error shows:
Code:
Sorting boundary faces according to group (patch)
0: inlet is #0 Foam::error::printStack (Foam::Ostream&) at ??:?
#1 Foam::sigSegv::sigHandler(int) at ??:?
#2 ? in "/lib/x86_64-linux-gnu/libc.so.6"
#3 ? at ??:?
#4 ___libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#5 ? at ??:?
Segmentation fault

--> FOAM FATAL IO ERROR:
Expected a ')' or a '}' while reading List, found on lie 296898 the label 4
file: /home/LEPT/ywang/OpenFOAM/ywang-3.0.1/run/UC/constant/polyMesh/faces at line 296898.
 
     From function Istream::readEndList(const char*)
     in file db/IOstreams/IOstreams/IOstream.C at line 159.
But I chekced the line 296898, it is normal, as attached.
The solution is simple but has cost me some time to figure out, just add Prism_3D in the applied algorithms.
The mesh can be successfully exported and without any defaultPatches.
Thank you.
Regards,
Bill
Attached Images
File Type: png UCgeometry.png (6.0 KB, 16 views)
File Type: png defaultPatches.png (4.8 KB, 19 views)
File Type: png line.png (9.9 KB, 15 views)
nsf likes this.

Last edited by 6863523; December 14, 2016 at 10:28.
6863523 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 07:30
[Salome] import mesh from salome to openfoam dome90 OpenFOAM Meshing & Mesh Conversion 2 April 20, 2016 23:58
[Salome] Step to export mesh from SALOME to OpenFoam for 3D MRF geometry aminem OpenFOAM Meshing & Mesh Conversion 0 September 16, 2014 10:18
[Salome] Mesh Salome 7.3.0 to OpenFoam Ahadi OpenFOAM Meshing & Mesh Conversion 5 July 1, 2014 10:11
Mesh conversion problem from Salome to openfoam jishnusoni OpenFOAM 15 March 3, 2010 01:53


All times are GMT -4. The time now is 01:43.