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)

nsf October 16, 2013 14:14

Script for converting a mesh from Salome-Platform to OpenFOAM
 
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

nsf November 2, 2013 10:57

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

Linse November 4, 2013 09:14

Thanks a lot!
 
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

student666 November 29, 2013 16:49

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


nsf November 30, 2013 02:43

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

student666 December 2, 2013 06:58

1 Attachment(s)
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

nsf December 2, 2013 08:29

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

student666 December 2, 2013 14:35

1 Attachment(s)
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.

student666 December 2, 2013 14:47

1 Attachment(s)
Here's the hdf file.

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

Regards

nsf December 2, 2013 16:34

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

student666 December 3, 2013 00:45

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 December 3, 2013 02:16

solved (?)
 
1 Attachment(s)
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

nsf December 3, 2013 15:29

1 Attachment(s)
Hi,

I'm glad to hear you got it working!

Quote:

Originally Posted by student666 (Post 464523)
...
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 (Post 464523)
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

student666 December 3, 2013 18:28

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

nsf December 4, 2013 01:38

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

Jakob1 January 11, 2014 07:00

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 January 11, 2014 17:52

Quote:

Originally Posted by Jakob1 (Post 469566)
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

skuznet January 16, 2014 11:50

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.

Linse January 16, 2014 18:28

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 January 18, 2014 11:55

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

student666 June 12, 2014 18:43

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

Linse June 13, 2014 06:17

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

nsf June 13, 2014 06:27

Quote:

Originally Posted by student666 (Post 496840)
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

student666 June 13, 2014 06:29

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.

Linse June 13, 2014 06:34

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!

student666 June 13, 2014 07:04

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?

Linse June 13, 2014 07:18

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

nsf June 13, 2014 10:35

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

student666 June 14, 2014 06:39

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!

ffan November 21, 2014 14:22

Hi OpenFOAM users,

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

- ffan

Quote:

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


pici December 12, 2014 12:27

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

Linse December 12, 2014 17:54

SalomeToOpenFOAM.py with Salome 7.4 and OF 2.3.
 
Quote:

Originally Posted by pici (Post 523680)
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. ;-)

nsf December 13, 2014 04:55

Quote:

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

pici December 13, 2014 06:50

just a stupid correction
 
1 Attachment(s)
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

nsf December 13, 2014 10:46

Thanks!
 
Quote:

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

pici December 13, 2014 12:53

Python scripting
 
Quote:

Originally Posted by nsf (Post 523781)
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 :o in Python, so I will be obliged if you would explain how is 'different' the manner you used.
Many thanks
. . . Piero

nsf December 15, 2014 01:21

Quote:

Originally Posted by pici (Post 523790)
Hi Nicolas,
I'm really a beginner :o 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

Annier December 21, 2014 14:25

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

rals February 2, 2015 12:49

Error while trying the script
 
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

nsf February 15, 2015 05:52

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


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