OpenFOAM¶
Last updated/reviewed: 2025-04-09
OpenFOAM is an open-source C++ library for solving partial differential equations. It is mainly used for computational fluid dynamics, for which there are many implemented solvers and different kinds of utilities. For further info see the OpenFOAM homepage.
Available OpenFOAM versions¶
To see available OpenFOAM versions write in the terminal:
OpenFOAM best practice¶
When running OpenFOAM it is important to run from your NOBACKUP directory. This is because OpenFOAM generate a tremendous amount of files which will fill up the quota in your BACKUP directory in no time. It is therefore recommended to source OpenFOAM the following way:
module load OpenFOAM/v2406-foss-2023a
. $FOAM_BASH WM_PROJECT_USER_DIR=your_openfoam_path/$USER-$WM_PROJECT_VERSION
This will tell OpenFOAM that the user working directory is in the given directory, under version-specific directories.
New users should then (once) create some directory structure, by:
This will give you a run-directory in the given directory, which you can easily reach by the alias run
(as long as you source as described above).
It is recommended to create some aliases for the different versions, at the end of your ~/.bashrc file, as:
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi`
alias OF2406="ml OpenFOAM/v2406-foss-2023a;. $FOAM_BASH WM_PROJECT_USER_DIR=your_openfoam_path/$USER-$WM_PROJECT_VERSION"
Whenever you open a new terminal window you can then simply activate whichever version you like by each alias (e.g. OF2406
).
It is not recommended to switch between versions in the same terminal window! Open a new terminal window for each version.
Note that it is NOT RECOMMENDED to explicitly load the OpenFOAM modules in ~/.bashrc
.
It is MUCH better to load the modules in the submit script, so that each submit determines its own environment.
See the submit script below.
In the submit script you should write out the same contents as in the alias, as described above (and do not use the alias itself - it has been problematic).
OpenFOAM on Vera¶
Hyper-treading(HT) is enabled on Vera and has been evaluated for OpenFOAM. OpenFOAM showed a small benefit
from HT and the default settings should be used. To read more about HT on Vera, see Vera.
We install OpenFOAM as a complete package, i.e. the module OpenFOAM/2406
contains the OpenFOAM version and all the packages needed to use this OpenFOAM
version rather than installing them separately and creating multiple modules.
Submitting OpenFOAM jobs¶
In order to submit OpenFOAM jobs, you can structure your bash script along the following lines:
#!/usr/bin/env bash
#SBATCH -A PROJECT_NUMBER -p vera
#SBATCH -n 32 -c 2 # Uses 64 cores in total
#SBATCH -t 24:00:00
ml OpenFOAM/v2406
source $FOAM_BASH
export FOAM_FILEHANDLER=collated
...
# Set up other configurations here
...
srun interFoam -parallel
Adjust the number of tasks -n
and cores per task -c
according to what gives
the best performance for your workload. The optimal settings can vary depending
on the hardware used as well as the workload.