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

Automating Openfoam

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By piu58

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 28, 2022, 19:34
Talking Automating Openfoam
  #1
New Member
 
Aniruddha Saha
Join Date: Mar 2022
Posts: 9
Rep Power: 4
saurcerer is on a distinguished road
Hi all,

Could you please guide me with the possible ways of automating openfoam using shell script or any other method?
I am using Ubuntu and it gets difficult to enter the OpenFoam environment using shell script.
saurcerer is offline   Reply With Quote

Old   March 29, 2022, 03:09
Default
  #2
Senior Member
 
piu58's Avatar
 
Uwe Pilz
Join Date: Feb 2017
Location: Leipzig, Germany
Posts: 744
Rep Power: 15
piu58 is on a distinguished road
OF is a command line driven programm. It can be skripted easily.
joshwilliams likes this.
__________________
Uwe Pilz
--
Die der Hauptbewegung überlagerte Schwankungsbewegung ist in ihren Einzelheiten so hoffnungslos kompliziert, daß ihre theoretische Berechnung aussichtslos erscheint. (Hermann Schlichting, 1950)
piu58 is offline   Reply With Quote

Old   March 29, 2022, 10:15
Default
  #3
New Member
 
Aniruddha Saha
Join Date: Mar 2022
Posts: 9
Rep Power: 4
saurcerer is on a distinguished road
I know it is a command line software and hence I said I need some help with the way how to do it
saurcerer is offline   Reply With Quote

Old   March 29, 2022, 15:03
Default
  #4
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
You can try out pyfoam. https://openfoamwiki.net/index.php/Contrib/PyFoam

Have a look. Maybe it helps
mAlletto is offline   Reply With Quote

Old   April 1, 2022, 08:36
Default Example
  #5
Member
 
Join Date: Mar 2018
Posts: 33
Rep Power: 8
ghastbug is on a distinguished road
Here is an example of a script in shell.



How to run a script (input in shell window):
Code:
./scriptname.sh
What this script does:

I have 73 folders with names AoA0, AoA5 etc. For each of them, openfoam gets inside the folder, decomposes the case in parallel, runs simplefoam in parallel, reconstructs the parallel folders, and then runs foamlog
Script:
Code:
#!/bin/bash
#cd "${0%/*}" || exit                                # Run from this directory

folders=( AoA0 AoA5 AoA10 AoA15 AoA20 AoA25 AoA30 AoA35 AoA40
       AoA45 AoA50 AoA55 AoA60 AoA65 AoA70 AoA75 AoA80 AoA85 AoA90
        AoA95 AoA100 AoA105 AoA110 AoA115 AoA120 AoA125 AoA130 AoA135
       AoA140 AoA145 AoA150 AoA155 AoA160 AoA165 AoA170 AoA175 AoA180
       AoA185 AoA190 AoA195 AoA200 AoA205 AoA210 AoA215 AoA220 
       AoA225 AoA230 AoA235 AoA240 AoA245 AoA250 AoA255 AoA260 AoA265
         AoA270 AoA275 AoA280 AoA285 AoA290 AoA295 AoA300 AoA305 AoA310
        AoA315 AoA320 AoA325 AoA330 AoA335 AoA340 AoA345 AoA350 AoA355
        AoA360)
        

for i in ${folders[@]} ; do
    cd $i
    echo "Carpeta actual: $i"
    decomposePar
    mpiexec -n 4 simpleFoam >log -parallel
    reconstructPar
    foamLog log
    cd ..
done
ghastbug is offline   Reply With Quote

Old   April 1, 2022, 10:46
Default
  #6
Senior Member
 
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22
cnsidero is on a distinguished road
<cue shameless plug>

We've developed an open-source Python library, called CPL, that does precisely this:

https://caelus.readthedocs.io/en/latest/

Check out the Parametric Runs section to automate multiple CFD runs. You install it with, ideally, conda or pip. The source code is available here:

https://bitbucket.org/appliedccm/cpl/src/master/

Despite Caelus (an OpenFOAM derivative) being in the name, it works equally well with OpenFOAM.

-Chris
cnsidero is offline   Reply With Quote

Old   April 11, 2022, 17:10
Default
  #7
Senior Member
 
Josh Williams
Join Date: Feb 2021
Location: Scotland
Posts: 113
Rep Power: 5
joshwilliams is on a distinguished road
Quote:
Originally Posted by saurcerer View Post
I know it is a command line software and hence I said I need some help with the way how to do it

Then, could you elaborate more on what you specifically need help with?
joshwilliams is offline   Reply With Quote

Old   April 11, 2022, 17:15
Default
  #8
Senior Member
 
Josh Williams
Join Date: Feb 2021
Location: Scotland
Posts: 113
Rep Power: 5
joshwilliams is on a distinguished road
For general scripting help, I found this tutorial really useful when I started using Ubuntu and OpenFOAM.


I recently started using PyFoam (as mentioned above by mAlletto). It is incredibly useful for automating setup of various dicts etc for parametric studies and does not require a massive amount of python experience.


If you are having issues accessing openfoam environment when using shell script, it sounds like your foam is not installed correctly, or you have some fundamental issue in your bash script. Joszef Nagy has some videos on installation I believe. Maybe they will be useful for you.
joshwilliams is offline   Reply With Quote

Old   April 11, 2022, 17:32
Default
  #9
New Member
 
Aniruddha Saha
Join Date: Mar 2022
Posts: 9
Rep Power: 4
saurcerer is on a distinguished road
Thanks a lot for your message ! I am trying to learn using PyFoam. My doubt regarding she’ll script was using it to modify text files such as BlockMeshDict and even exporting values from the vtk files. But now I think after all these helps, I’ll be able to pull off.
saurcerer is offline   Reply With Quote

Old   April 12, 2022, 05:15
Default
  #10
Senior Member
 
Josh Williams
Join Date: Feb 2021
Location: Scotland
Posts: 113
Rep Power: 5
joshwilliams is on a distinguished road
Quote:
Originally Posted by saurcerer View Post
Thanks a lot for your message ! I am trying to learn using PyFoam. My doubt regarding she’ll script was using it to modify text files such as BlockMeshDict and even exporting values from the vtk files. But now I think after all these helps, I’ll be able to pull off.
To export values from your simulations to a python script as a numpy array, you can use the OpenFOAMparser. There are some different versions on github, here is mine.
joshwilliams is offline   Reply With Quote

Reply

Tags
automating, shell script, terminal


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
Frequently Asked Questions about Installing OpenFOAM wyldckat OpenFOAM Installation 3 November 14, 2023 12:58
How to develop OpenFOAM with CMake and popular IDEs cosscholar OpenFOAM Programming & Development 0 March 16, 2022 16:17
OpenFOAM Foundation releases OpenFOAM® 3.0.0 CFDFoundation OpenFOAM Announcements from OpenFOAM Foundation 1 November 7, 2015 16:16
OpenFOAM Training, London, Chicago, Munich, Sep-Oct 2015 cfd.direct OpenFOAM Announcements from Other Sources 2 August 31, 2015 14:36
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 19:07


All times are GMT -4. The time now is 09:46.