Skip to content

OpenFOAM

OpenFOAM is the free, open source CFD software first released by OpenCFD Ltd in 2004. It has a large user base across most areas of engineering and science, from both commercial and academic organisations. OpenFOAM has an extensive range of features to solve anything from complex fluid flows involving chemical reactions, turbulence and heat transfer, to acoustics, solid mechanics and electromagnetism.

The FOAM in OpenFOAM stands for Field Operation And Manipulation, since the software is used to calculate velocity, pressure, density, temperature, concentration, etc. fields. OpenFOAM includes more than 100 readily available solvers and many pre- and post-processing utilities. For example, simpleFoam, sonicFoam and rhoReactingFoam are three popular included solvers, and blockMesh and snappyHexMesh are two mesh generation tools.

There are two major branches of OpenFOAM development:

  • An ESI-OpenCFD branch developed by OpenFOAM trademark owners OpenCFD Limited which is based at www.openfoam.com. These versions are named using the form OpenFOAM-vYYMM where YY and MM are, respectively, the year and month of the released version. The most recent EasyBuild version as of 2023/04 is OpenFOAM-v2206
  • An OpenFOAM Foundation branch started in 2011 that uses the OpenFOAM trademark with permission, and which is based at www.openfoam.org. These versions are named with the form Openfoam-N where N is the release number. The most recent EasyBuild version as of 2023/04 is OpenFoam-11.

There is also a foam-extend branch that attempts to integrate community contributions to OpenFOAM. It is based at sourceforge.net/projects/foam-extend/ and is also supported by EasyBuild, although the latest available version is three years old.

The history of and details about all releases can be found at the Unofficial OpenFOAM Wiki.

The branch with which you will work can be based on a recommendation, a need to replicate previous work, the need for a feature contained within only one branch, or some other factor. Or you can try both branches.

Environment Set-Up

OpenFOAM is available on the Grace, FASTER, and ACES clusters.

Modules

⚠️ It's recommended to load a versioned module versus the latest available (e.g. OpenFOAM/v1912 instead of just OpenFOAM) to ensure compatibility with your workload, reproducibility, and record-keeping

Grace

View available versions of OpenFOAM:

mla OpenFOAM

Select a version, and pass it the the "module spider" command to see any prerequisite modules required:

module spider OpenFOAM/v1912

This particular version allows two different sets of prerequisite modules, only one set needs to be loaded:

GCC/8.3.0  OpenMPI/3.1.4                # we'll use this one for this example
iccifort/2019.5.281  impi/2018.5.288

Load the OpenFOAM module to configure your shell environment for access to OpenFOAM:

module purge                            # ensure your working environment is clean
module load GCC/8.3.0 OpenMPI/3.1.4     # load prerequisite modules
module load OpenFOAM/v1912              # load OpenFOAM/v1912

Setting Up OpenFOAM Variables

Once the OpenFOAM module is loaded, the environment variables needed to use OpenFOAM can be sourced:

source ${FOAM_BASH}

The shell is now ready for use with OpenFOAM.

Usage

Interactive

This method is recommended for quick testing that '''require only a small amount of computational resources''', as this method takes place on the login nodes. Please see our policy regarding login node usage for additional information.

Load the modules for the appropriate cluster:

# Grace
module purge                            # ensure your working environment is clean
module load GCC/8.3.0 OpenMPI/3.1.4     # load prerequisite modules
module load OpenFOAM/v1912              # load OpenFOAM/v1912

Source the environment script:

source ${FOAM_BASH}

Copy the tutorial and update file permissions:

mkdir -p ${SCRATCH}/openfoam-examples
cp -R ${FOAM_TUTORIALS}/basic/laplacianFoam/flange ${SCRATCH}/openfoam-examples
chmod -R +w ${SCRATCH}/openfoam-examples

Change into the tutorial directory:

cd ${SCRATCH}/openfoam-examples/flange

Run the tutorial:

./Allrun

Batch/Job Submission

This method is recommend for workloads that '''require a large amount of computational resources''', and takes place on the compute nodes by accessing the job submission system.

Example 1: General Usage

Grace

#!/bin/bash
#SBATCH -J openfoam-sample-1-grace      # set the job name to "openfoam-sample1-grace"
#SBATCH -t 1:00:00                      # set the wall clock limit to 1hr 
#SBATCH -N 1                            # request 1 node
#SBATCH --ntasks-per-node=8             # request 8 tasks per node
#SBATCH --mem=16G                       # request 16G per node
#SBATCH -o %x.%j                        # send stdout/err to "moose-sample-1-grace.[jobID]"

# environment set-up
module purge                            # ensure your working environment is clean
module load GCC/8.3.0 OpenMPI/3.1.4     # load prerequisite modules
module load OpenFOAM/v1912              # load OpenFOAM/v1912
source ${FOAM_BASH}                     # set up OpenFOAM environment variables

# run OpenFOAM example 1
mkdir -p ${SCRATCH}/openfoam-examples                                                   # create a destination directory for a copy of the tutorial
cp -R ${FOAM_TUTORIALS}/basic/laplacianFoam/flange ${SCRATCH}/openfoam-examples         # copy the tutorial to your newly created directory
chmod -R +w ${SCRATCH}/openfoam-examples                                                # add write permissions to the copied tutorial
cd ${SCRATCH}/openfoam-examples/flange                                                  # navigate into the tutorial directory
./Allrun                                                                                # run the tutorial
Back to top