CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Scripts to manage OpenFOAM cases

Register Blogs Community New Posts Updated Threads Search

Like Tree8Likes
  • 8 Post By Logan Page

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 30, 2013, 14:27
Default Scripts to manage OpenFOAM cases
  #1
Member
 
Ye Zhang
Join Date: Dec 2009
Location: Delft,Netherland
Posts: 92
Rep Power: 16
kiddmax is on a distinguished road
Dear foamers,


I am wondering how to write a script to manage OpenFOAM cases. Since I need to simulate 2D airfoil flow at different angle of attacks. Everytime I have to copy the case files and change the velocity and lift and drag direction. This method is time consuming and use a lot of disk. I know that using a script to mange the case and change the boundary condition is possible, anyone can give me some hints?

Best regards,
Ye
kiddmax is offline   Reply With Quote

Old   September 30, 2013, 20:24
Default
  #2
New Member
 
Join Date: Sep 2013
Posts: 10
Rep Power: 12
simon-2 is on a distinguished road
you can use a custom dict, containing AoA in your case.

in your files 0/U etc include your dict und use variables depending on the entries in your dict.

for example
Ux #calc "$myVelocity*cos($myAoA)";
...
fixedValue ($Ux $Uy $Uz)


referring to myVelocity and myAoA in your dict.

this way, you only have to change the myAoA entry in a single dict to modify the case.

Further, you can also use a shellscript to do the following steps for a whole list of prepared dict-files:
copy dict_#i into the case,
./Allrun case,
make directory anywhere/#i
copy relevant output to anywhere/#i,
./Allclean case

there might be more elegant ways, but it should work
simon-2 is offline   Reply With Quote

Old   October 1, 2013, 09:08
Default
  #3
Member
 
Logan Page
Join Date: Sep 2010
Posts: 38
Rep Power: 15
Logan Page is on a distinguished road
I had a similar requirement, for which I created Python scripts (using some of pyFoam's functionality) to manage my case files and the automation of multiple CFD simulations.
Logan Page is offline   Reply With Quote

Old   October 3, 2013, 16:50
Default
  #4
Member
 
Ye Zhang
Join Date: Dec 2009
Location: Delft,Netherland
Posts: 92
Rep Power: 16
kiddmax is on a distinguished road
Thank you Logan!

Cause I am quite new to OpenFOAM. It will be better if you can describe it more detail.

Best regards,
Ye
kiddmax is offline   Reply With Quote

Old   October 4, 2013, 05:50
Default
  #5
Member
 
Logan Page
Join Date: Sep 2010
Posts: 38
Rep Power: 15
Logan Page is on a distinguished road
Hi

I effectively set up code as described in the attached images.
parameterisation.jpg optimisation.jpg

The OpenFoam utilities and solvers where called (run) through the use of pyFoam. http://openfoamwiki.net/index.php/Contrib_PyFoam

In my case the mesh file was also scripted / generated in Python and then used in blockMesh, but you can easily use another meshing program like gmsh coupled to Python.

The general process I followed is:
  1. setup a base case directory and files (e.g. AOA = 0), that has the 0, constant and system files needed for your simulations
  2. create a new directory for a new sim (e.g. AOA = 3) [I used Python to manage my directories based on the value for a given variable, e.g. `os.makedirs(some_path/AOA_03)`]
  3. I used pyFoam to clone the base case files into the new directory `pyFoam.SolutionDirectory.cloneCase`
  4. create the mesh / meshFile -- there are multiple options here depending on what meshing program you are using, for example:
    • gmsh
      • create an initial parameterized .geo file
      • there are probably ways to improve this, but I then copied the .geo file text to Python and used Python to change the parameter values and write a new .geo file to the new directory
      • I can't remember if I used `pyFoam.UtilityRunner` or a Python subprocess to then run gmsh with new the .geo file
      • you can probably also play around with the `-merge` option when calling gmsh and only use Python to write a file with the parameters in it (haven't tried this)
      • then I used `pyFoam.UtilityRunner` to run `gmshToFoam'
      • It's been awhile since I've done this, but if I recall correctly there may have been issues with boundary types after `gmshToFoam` and you may need to also update the types in the constant/polyMesh/boundary
    • blockMeshDict with m4
    • create the blockMeshDict file in Python
      • this requires the most work and I definitely don't have an optimal process / solution for this, but it is doable.
  5. I then used `pyFoam.UtilityRunner` to run`blockMesh`
  6. if I had any boundary conditions or fluid properties that needs changing, I used `pyFoam.ParsedParameterFile` to edit / change values in the specific files
  7. then finally I used one the the `pyFoam` runners to call the OpenFoam solver, e.g. `pyFoam.PlotRunner` / `pyFoam.SteadyRunner`
  8. I then used Python to extract the results I wanted from the simulation and pop the results for each simulation into a central log file.
Here are the two Python files I used that may help you on your way.
SolveFoam.txt
RunFoamS0Solution1.txt
Logan Page is offline   Reply With Quote

Old   October 4, 2013, 05:54
Default
  #6
Senior Member
 
Olivier
Join Date: Jun 2009
Location: France, grenoble
Posts: 272
Rep Power: 17
olivierG is on a distinguished road
hello,

Like Logan say, take a look at pyFoam
http://openfoamwiki.net/index.php/Contrib_PyFoam
There is a full section about manipulating case.

You can also change boundary with the changeDictionary commande, usin a "changeDictionnaryDict" file.

regards,
olivier
olivierG is offline   Reply With Quote

Old   July 17, 2020, 05:09
Default
  #7
New Member
 
liwenpeng
Join Date: Jul 2020
Posts: 11
Rep Power: 5
liwenpeng is on a distinguished road
Quote:
Originally Posted by olivierG View Post
hello,

Like Logan say, take a look at pyFoam
http://openfoamwiki.net/index.php/Contrib_PyFoam
There is a full section about manipulating case.

You can also change boundary with the changeDictionary commande, usin a "changeDictionnaryDict" file.

regards,
olivier
Do I need to install Python on Linux
liwenpeng is offline   Reply With Quote

Old   July 17, 2020, 05:14
Default
  #8
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by liwenpeng View Post
Do I need to install Python on Linux

It's hard to find a Linux distribution that hasn't got Python installed


But if you want to use PyFoam: yes. Python is necessary
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   July 17, 2020, 05:18
Default
  #9
New Member
 
liwenpeng
Join Date: Jul 2020
Posts: 11
Rep Power: 5
liwenpeng is on a distinguished road
Quote:
Originally Posted by gschaider View Post
It's hard to find a Linux distribution that hasn't got Python installed


But if you want to use PyFoam: yes. Python is necessary
My computer is a Windows system. In order to run openfoam, I have installed Ubuntu Linux. If I want to use pyform, what should I do?. Do I install Python on windows or Ubuntu Linux。
thanks
liwenpeng is offline   Reply With Quote

Old   July 17, 2020, 10:38
Default
  #10
Member
 
benoit paillard
Join Date: Mar 2010
Posts: 96
Rep Power: 16
bennn is on a distinguished road
If you want your life to be easy and enjoyable, I'd suggest sticking to a linux distribution and never use Windows for Openfoam simulations.
bennn is offline   Reply With Quote

Old   July 17, 2020, 22:41
Default
  #11
New Member
 
liwenpeng
Join Date: Jul 2020
Posts: 11
Rep Power: 5
liwenpeng is on a distinguished road
Quote:
Originally Posted by bennn View Post
If you want your life to be easy and enjoyable, I'd suggest sticking to a linux distribution and never use Windows for Openfoam simulations.
thanks for your advice
liwenpeng is offline   Reply With Quote

Reply


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
ESI-OpenCFD Releases OpenFOAM v2.2.0 opencfd OpenFOAM Announcements from ESI-OpenCFD 13 March 30, 2013 16:52
Is OpenFOAM tutorial cases valid? j-avdeev OpenFOAM Running, Solving & CFD 3 September 19, 2012 15:45
Comparison of axisymmetric case, Starccm+ and OpenFOAM linnemann OpenFOAM Running, Solving & CFD 12 June 16, 2011 05:43
Modified OpenFOAM Forum Structure and New Mailing-List pete Site News & Announcements 0 June 29, 2009 05:56
Manage openfoam solver project in KDevelop probably the last linker error any suggestion is welcome lakeat OpenFOAM Installation 0 July 7, 2007 10:01


All times are GMT -4. The time now is 05:31.