|
[Sponsors] | |||||
|
|
|
#1 |
|
New Member
Aniruddha Saha
Join Date: Mar 2022
Posts: 9
Rep Power: 5 ![]() |
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. |
|
|
|
|
|
|
|
|
#2 |
|
Senior Member
Uwe Pilz
Join Date: Feb 2017
Location: Leipzig, Germany
Posts: 744
Rep Power: 16 ![]() |
OF is a command line driven programm. It can be skripted easily.
__________________
Uwe Pilz -- Die der Hauptbewegung überlagerte Schwankungsbewegung ist in ihren Einzelheiten so hoffnungslos kompliziert, daß ihre theoretische Berechnung aussichtslos erscheint. (Hermann Schlichting, 1950) |
|
|
|
|
|
|
|
|
#3 |
|
New Member
Aniruddha Saha
Join Date: Mar 2022
Posts: 9
Rep Power: 5 ![]() |
I know it is a command line software and hence I said I need some help with the way how to do it
|
|
|
|
|
|
|
|
|
#4 |
|
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 17 ![]() |
You can try out pyfoam. https://openfoamwiki.net/index.php/Contrib/PyFoam
Have a look. Maybe it helps |
|
|
|
|
|
|
|
|
#5 |
|
Member
Join Date: Mar 2018
Posts: 33
Rep Power: 9 ![]() |
Here is an example of a script in shell.
How to run a script (input in shell window): Code:
./scriptname.sh 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
|
|
|
|
|
|
|
|
|
#6 |
|
Senior Member
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 23 ![]() |
<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 |
|
|
|
|
|
|
|
|
#7 |
|
Senior Member
Josh Williams
Join Date: Feb 2021
Location: Scotland
Posts: 115
Rep Power: 6 ![]() |
||
|
|
|
|
|
|
|
#8 |
|
Senior Member
Josh Williams
Join Date: Feb 2021
Location: Scotland
Posts: 115
Rep Power: 6 ![]() |
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. |
|
|
|
|
|
|
|
|
#9 |
|
New Member
Aniruddha Saha
Join Date: Mar 2022
Posts: 9
Rep Power: 5 ![]() |
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.
|
|
|
|
|
|
|
|
|
#10 | |
|
Senior Member
Josh Williams
Join Date: Feb 2021
Location: Scotland
Posts: 115
Rep Power: 6 ![]() |
Quote:
|
||
|
|
|
||
|
|
|
#11 |
|
New Member
Ahmed Hassan
Join Date: Sep 2025
Posts: 1
Rep Power: 0 ![]() |
Hi,
Yes, OpenFOAM can be automated in several ways. The most common is using shell scripts on Ubuntu, where you can set up the environment once inside the script and then run your meshing, solver, and post-processing steps automatically. This is very handy for repetitive runs. Beyond that, you can use Python (with or without libraries like PyFoam) to organize parametric studies, optimization loops, or even link OpenFOAM with machine learning workflows. Some people also use workflow managers (like Makefiles or Snakemake) or HPC job schedulers if they’re running large numbers of cases. The key point is: you don’t need to enter the environment manually each time — just include the environment setup in your script, and everything can run end-to-end automatically. 👉 I share step-by-step tutorials on automating OpenFOAM workflows with Python and open-source tools on my YouTube channel here: https://www.youtube.com/@FarseLab101 |
|
|
|
|
|
![]() |
| Tags |
| automating, shell script, terminal |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |