CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing & Mesh Conversion (https://www.cfd-online.com/Forums/openfoam-meshing/)
-   -   [Salome] Script for converting a mesh from Salome-Platform to OpenFOAM (https://www.cfd-online.com/Forums/openfoam-meshing/124982-script-converting-mesh-salome-platform-openfoam.html)

wyldckat March 21, 2015 10:28

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 March 23, 2015 04:02

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

pici June 17, 2015 12:30

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

nsf June 23, 2015 14:37

Quote:

Originally Posted by pici (Post 550794)
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

hssnjfry October 5, 2015 13:24

hi
icreated mesh and load scrip salomeToOpenFOAM.py and what happened than?
which file created ? and where?:confused:

nsf October 5, 2015 16:05

Quote:

Originally Posted by hssnjfry (Post 566628)
hi
icreated mesh and load scrip salomeToOpenFOAM.py and what happened than?
which file created ? and where?:confused:

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

Fauster January 12, 2016 07:21

problem with select a mesh
 
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

nsf January 12, 2016 16:09

Quote:

Originally Posted by Fauster (Post 580617)
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 January 14, 2016 16:39

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

Fauster January 15, 2016 04:09

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

nsf January 15, 2016 05:35

Quote:

Originally Posted by Fauster (Post 581025)
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!

Fauster January 15, 2016 06:09

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.

alanaj5 July 6, 2016 11:14

Am I converting my mesh correctly?
 
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

nsf July 6, 2016 16:16

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

Sören Sander November 2, 2016 08:10

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.

nsf November 2, 2016 14:52

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

coccone November 3, 2016 04:10

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



nsf November 3, 2016 17:19

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

coccone November 4, 2016 04:03

1 Attachment(s)
Quote:

Originally Posted by nsf (Post 624058)
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

6863523 December 13, 2016 05:31

extra faces in salome
 
3 Attachment(s)
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


All times are GMT -4. The time now is 11:57.