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   June 12, 2014, 19:43
Default
  #21
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,

I'm facing one more problem with the script; and I can't understand if there's a problem with python:

Code:
>>>  p, li { white-space: pre-wrap; }  execfile(r"/home/michele/Documents/Salome/SalomeToOpenFOAM.py")
 found selected mesh exporting to //tubo/constant/polyMesh
 Traceback (most recent call last):
   File "<input>", line 1, in <module>
   File "/home/michele/Documents/Salome/SalomeToOpenFOAM.py", line 602, in <module>
     exportToFoam(mesh,mesh.GetName())
   File "/home/michele/Documents/Salome/SalomeToOpenFOAM.py", line 88, in exportToFoam
     os.makedirs(dirname)
   File "/home/michele/salome/SALOME-MECA-2014.1-LGPL/prerequisites/Python_273/lib/python2.7/os.py", line 157, in makedirs
     mkdir(name, mode)
 OSError: [Errno 13] Permission denied: 'tubo'


can you help me?

I'm using Salome version 7.3.0

thanks

Last edited by student666; June 13, 2014 at 03:09.
student666 is offline   Reply With Quote

Old   June 13, 2014, 07:17
Default
  #22
Senior Member
 
Bernhard Linseisen
Join Date: May 2010
Location: Heilbronn
Posts: 183
Blog Entries: 1
Rep Power: 16
Linse is on a distinguished road
Dear Michele,

though not being Nicolas, maybe I have an idea on the reason of the problem.
To me the output looks as if you were calling the script from the top of your root directory. Obviously, your system would not let you as a normal user write data into / .

Does the problem occur also if you start Salome (if you call the script from within Salome) or the script (if you call it directly from the shell) from your user home folder?

A short side remark to Nicolas nevertheless: Would it be painfully difficult to add a routine asking for the place where the folder should be put?
The last time I was using that awesome script it put the folder into the directory from which Salome was called...

Cheers,
Bernhard
Linse is offline   Reply With Quote

Old   June 13, 2014, 07:27
Default
  #23
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 student666 View Post
Hi Nicolas,

I'm facing one more problem with the script; and I can't understand if there's a problem with python:

Code:
>>>  p, li { white-space: pre-wrap; }  execfile(r"/home/michele/Documents/Salome/SalomeToOpenFOAM.py")
 found selected mesh exporting to //tubo/constant/polyMesh

...

     mkdir(name, mode)
 OSError: [Errno 13] Permission denied: 'tubo'


can you help me?

I'm using Salome version 7.3.0

thanks
Hi Michele,

The error messeage (last two lines) would suggest that you don't have write permission where you wan't to store the mesh. Also note one of the first lines

Quote:
found selected mesh exporting to //tubo/constant/polyMesh
You are trying to save the mesh to /tubo/constant/polyMesh. It seems like an unlikely path. If you use the GUI to start the script it will store the mesh in the current path. When you ran it it would seem it was the root dir.

To change the path, open the python interpreter and type
(you can ignore the lines starting with #.

Code:
import os
#show the current path
os.getcwd()
#set it to something sensible
os.chdir("/home/user/somefolder")
Then rerun the script.

Best of luck

Nicolas
6863523 likes this.
nsf is offline   Reply With Quote

Old   June 13, 2014, 07:29
Default
  #24
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 Bernhard,

the problem to me arise from within Salome.

I perform: select the mesh --> File --> load script --> select salomeToOpenFoam.py (in home/michele/Documents/salomeToOpenFoam.py

Never used the call within the shell.

Anyway I fear there's something wrong within python 2.7.3, but I don't know how to check.
student666 is offline   Reply With Quote

Old   June 13, 2014, 07:34
Default
  #25
Senior Member
 
Bernhard Linseisen
Join Date: May 2010
Location: Heilbronn
Posts: 183
Blog Entries: 1
Rep Power: 16
Linse is on a distinguished road
Well before you start looking for errors within your Python installation (that definitely would be out of my league, as well), just give it a try if it works when starting Salome from your home folder!
I remember that the location of the script does NOT matter for the position where the mesh folder goes, but the location from which Salome is started definitely does.

Try:
cd $HOME ; runSalome (or whatever command you use for starting Salome)

Let us know if it works, please!
Linse is offline   Reply With Quote

Old   June 13, 2014, 08:04
Default
  #26
Senior Member
 
M. C.
Join Date: May 2013
Location: Italy
Posts: 286
Blog Entries: 6
Rep Power: 17
student666 is on a distinguished road
Bernard, you're right!.

Quote:

cd $HOME ; runSalome (or whatever command you use for starting Salome)
Starting salome by double-clicking on icon on Desktop was the problem. If I run the program within the installation directory, all works perfectly, but it save the mesh inside the installation directory of Salome

Code:
/home/michele/salome/apply_v7_3_0
Nicolas, I test your proposal, but I wasn't able to change the directory.

when I type
Code:
import os
os.getcwd()
my directory is /home/user, If I changed within the same terminal it changes, but If I close and open a new terminal, all go back to default. maybe I miss root privileges?
student666 is offline   Reply With Quote

Old   June 13, 2014, 08:18
Default
  #27
Senior Member
 
Bernhard Linseisen
Join Date: May 2010
Location: Heilbronn
Posts: 183
Blog Entries: 1
Rep Power: 16
Linse is on a distinguished road
Nicolas was right, too! I just was quicker this one time! ;-)

My opinion: Basically when using applications you never miss root privileges - if they are required, the software is set up wrongly. I strongly suggest not to try anything to breach the root-barrier. It just makes your system more vulnerable.

Now comes the part of speculation on my side: Maybe it is possible to change the icon on the desktop in a way it changes to your home directory and starts Salome only after that? How to do that, I would have to experiment, unfortunately.

For changing the script or the working directory called from salomeToOpenFOAM.py, I refer to Nicolas. HE is the man concerning the magic script and python. ;-)

Cheers,
Bernhard
Linse is offline   Reply With Quote

Old   June 13, 2014, 11:35
Default
  #28
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
Hi Bernhard!

I guess you posted while I was still typing =).

Michele, as Berhard says you should not need root privileges. It sounds like you've opened a separate "terminal". What I meant was to use a the python console inside salome.

Code:
os.getcwd()
returns a string with the current path. What you need is
Code:
os.chdir("/home/YOURuserNAME/somepath/polyMesh")
I you do this inside salome it should work. I does for me.

Or you can start salome from another directory by providing the full path to runAppli.

Code:
/home/michele/salome/apply_v7_3_0/runAppli
Good luck
Nicolas
nsf is offline   Reply With Quote

Old   June 14, 2014, 07:39
Default
  #29
Senior Member
 
M. C.
Join Date: May 2013
Location: Italy
Posts: 286
Blog Entries: 6
Rep Power: 17
student666 is on a distinguished road
Sorry,

didn't think about it, but now it works well! typing inside Salome solved the problem as well.

Thanks a lot again both of you, Nicolas and Bernhard!
student666 is offline   Reply With Quote

Old   November 21, 2014, 15:22
Default
  #30
New Member
 
Fa-Gung Fan
Join Date: Nov 2009
Posts: 8
Rep Power: 17
ffan is on a distinguished road
Hi OpenFOAM users,

Do the meshes at the inter-region patches to OpenFOAM have to be conforming? Thanks.

- ffan

Quote:
Originally Posted by nsf View Post
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
ffan is offline   Reply With Quote

Old   December 12, 2014, 13:27
Default
  #31
Member
 
pici's Avatar
 
Pierluigi Cirrottola
Join Date: Jun 2013
Posts: 52
Rep Power: 13
pici is on a distinguished road
Hi Nicolas,
I discovered your contribution while I was searching this Forum for other issues, but I think it can be very useful.
A.s.a.p. I will test it, using Salomé 7.4 and oF 2.3. I will write you back my feelings.
Ciao
Piero
pici is offline   Reply With Quote

Old   December 12, 2014, 18:54
Default SalomeToOpenFOAM.py with Salome 7.4 and OF 2.3.
  #32
Senior Member
 
Bernhard Linseisen
Join Date: May 2010
Location: Heilbronn
Posts: 183
Blog Entries: 1
Rep Power: 16
Linse is on a distinguished road
Quote:
Originally Posted by pici View Post
Hi Nicolas,
I discovered your contribution while I was searching this Forum for other issues, but I think it can be very useful.
A.s.a.p. I will test it, using Salomé 7.4 and oF 2.3. I will write you back my feelings.
Ciao
Piero
At least for me it worked fine, recently. Although it seemed to take surprisingly long (given the memory of prior experiences with the script) to export a fully hexa-mesh with approximately one million cells.

But in case you bump into problems, please do post it here! In the worst case you trip a heisenbug, in the best case you help some other users not to repeat avoidable mistakes. ;-)
Linse is offline   Reply With Quote

Old   December 13, 2014, 05:55
Default
  #33
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,
I discovered your contribution while I was searching this Forum for other issues, but I think it can be very useful.
A.s.a.p. I will test it, using Salomé 7.4 and oF 2.3. I will write you back my feelings.
Ciao
Piero
Hi Piero!

I wish you the best of luck. But keep in mind that this script was one of the first things I did in python. It can most definitely be speed up. As Bernhard pointed out at approximately 1M cells the conversion takes really long time. Possibly longer than it took to generate the mesh in the first place. In part this is because it's a python script but mostly because of the algorithm. Every time it converts one face from salome to openfoam it has to check if that face already has been added. So the conversion time is in the order \mathcal{O}(n^2 ). I've tried to use dictionaries which supposedly are of order \mathcal{O}(n^0 ) but that doesn't seem to be the case when the cell count is large.

If you have any suggestions on how to improve the conversion, please let me know.

Best Regards
Nicolas
nsf is offline   Reply With Quote

Old   December 13, 2014, 07:50
Default just a stupid correction
  #34
Member
 
pici's Avatar
 
Pierluigi Cirrottola
Join Date: Jun 2013
Posts: 52
Rep Power: 13
pici is on a distinguished road
Hi Nicolas,
I'm sending to you a a very small correction I made, because the out directory was not the correct one.
For example, if mesh name is Mesh_1, outdir was "(cwd)/Mesh_1" instead of "(cwd)/Mesh_1/constant/polyMesh".
Attached you will find source code, with my correction well signaled (-pici-).
Thank you for you attention. Bye
Piero
Attached Files
File Type: txt salomeToOpenFOAM.txt (21.8 KB, 13 views)
pici is offline   Reply With Quote

Old   December 13, 2014, 11:46
Default Thanks!
  #35
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,
I'm sending to you a a very small correction I made, because the out directory was not the correct one.
For example, if mesh name is Mesh_1, outdir was "(cwd)/Mesh_1" instead of "(cwd)/Mesh_1/constant/polyMesh".
Attached you will find source code, with my correction well signaled (-pici-).
Thank you for you attention. Bye
Piero
Hi, Thanks for the contribution. I've corrected the script although in a different manner than you did. The new version has been pushed to github.

Best Regards
Nicolas
nsf is offline   Reply With Quote

Old   December 13, 2014, 13:53
Default Python scripting
  #36
Member
 
pici's Avatar
 
Pierluigi Cirrottola
Join Date: Jun 2013
Posts: 52
Rep Power: 13
pici is on a distinguished road
Quote:
Originally Posted by nsf View Post
Hi, Thanks for the contribution. I've corrected the script although in a different manner than you did. The new version has been pushed to github.

Best Regards
Nicolas
Hi Nicolas,
I'm really a beginner in Python, so I will be obliged if you would explain how is 'different' the manner you used.
Many thanks
. . . Piero
pici is offline   Reply With Quote

Old   December 15, 2014, 02:21
Default
  #37
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,
I'm really a beginner in Python, so I will be obliged if you would explain how is 'different' the manner you used.
Many thanks
. . . Piero
I'll give it a try. The last fiew lines below
Code:
if __name__ == "__main__":
are only evaluated if the script is run standalone. But if you would like to import the functions as a module then it isn't evaluated and the variable "outdir" isn't set. If for instance you use salome's dump script functionality and in that script directly export the mesh via the function exportToFoam. In that case the code wouldn't run at all.

Now I moved all the code under "__main__" to it's own function so the variables aren't global and only exits in the namespace of that function.

/Nicolas
nsf is offline   Reply With Quote

Old   December 21, 2014, 15:25
Default
  #38
Member
 
Anil Kunwar
Join Date: Jun 2013
Posts: 64
Rep Power: 12
Annier is an unknown quantity at this point
Hi Nicolas,
Thank you very much. I am using the salomeToOpenFoam.py script in Salome 7.4.0.
Your creative work has helped us a lot. Also, your explanations are lucid.

Yours
Anil Kunwar
Annier is offline   Reply With Quote

Old   February 2, 2015, 13:49
Default Error while trying the script
  #39
New Member
 
Ralf Schüßler
Join Date: Feb 2015
Posts: 1
Rep Power: 0
rals is on a distinguished road
Hello,

while I've tried the script I got an error message:

>>> execfile(r"/home/user/salomeToOpenFOAM-master/salomeToOpenFOAM.py")
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/user/salomeToOpenFOAM-master/salomeToOpenFOAM.py", line 46, in <module>
from salome.smesh import smeshBuilder
ImportError: cannot import name smeshBuilder
>>>
and te script won't continue.
My salome-version is 6 / 2013.1 , 32 bit, linux.

I would like to know, how to get the script running. Many thanks in advance,

Ralf
rals is offline   Reply With Quote

Old   February 15, 2015, 06:52
Default
  #40
nsf
Senior Member
 
Nicolas Edh
Join Date: Mar 2010
Location: Uppsala, Sweden
Posts: 123
Rep Power: 18
nsf is on a distinguished road
Hi Ralph,

I've only tried the scripts with salome versions 7.2,7.3 and 7.4. Most likely you need to install a more recent version of Salome.

Best Regards
Nicolas
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 13:26.