OpenFOAM

OpenFOAM

OpenFOAM [1] is a free, open source CFD software package developed by OpenCFD Ltd at ESI Group and distributed by the OpenFOAM Foundation . 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 solid dynamics and electromagnetics.

Installed Versions

All the available versions of OpenFOAM for use can be viewed by issuing the following commands. This applies for other applications as well.

module spider openfoam

output:

------------------------------------------------------------------------------------------------------------

  openfoam: openfoam/4.1

------------------------------------------------------------------------------------------------------------

    Description:

      OpenFOAM is free, open source software for CFD from the OpenFOAM Foundation.

     Other possible modules matches:

        .base/openfoam

    You will need to load all module(s) on any one of the lines below before the "openfoam/4.1" module is available to load.

      gcc/6.3.0  openmpi/2.0.1 

------------------------------------------------------------------------------------------------------------

The default module can be loaded by loading gcc and openmpi as indicated by the module spider command:

module load gcc/6.3.0 openmpi/2.0.1 openfoam/4.1

The other versions of OpenFOAM (when available) can be loaded as:

module load openfoam/<version>

After loading OpenFOAM, we will need to source the initialization scripts:

source $OPENFOAM_BASHRC

NOTE: the sourcing only needs to be done once just right after loading the module.

Running OpenFOAM in HPC

IMPORTANT NOTE: Always allocate a compute node first. Since we are working with a sourced environment, some variables need to be set up after the module is loaded. If you load the module on the head node and then you allocate a compute node, you might not have access to some of these variables.

Interactive

Allocate a compute node with enough resources. For this example we will use the default resources:

srun --pty --time=30 -c 5 --mem=20g /bin/bash

Then load the module:

module load gcc/6.3.0 openmpi/2.0.1 openfoam/4.1

Then source the OpenFOAM initialization scripts:

source $OPENFOAM_BASHRC

Now you can issue OpenFOAM commands, e.g:

simpleFoam -help

Output:

Usage: simpleFoam [OPTIONS]

options:

  -case <dir>       specify alternate case directory, default is the cwd

  -noFunctionObjects

                    do not execute functionObjects

  -parallel         run in parallel

  -postProcess      Execute functionObjects only

  -roots <(dir1 .. dirN)>

                    slave root directories for distributed running

  -srcDoc           display source code in browser

  -doc              display application documentation in browser

  -help             print the usage

Using: OpenFOAM-4.1 (see www.OpenFOAM.org)

Build: 4.1

Batch - Serial

Example (from the OpenFOAM Manual):

Copy the cavity directory [2] from /usr/local/DOC/OPENFOAM/ to your home directory

cp -r /usr/local/DOC/OPENFOAM/cavity .

Change directory to that location 

cd cavity

You will find the job file, job.slurm. Now, submit the job.

sbatch job.slurm

Find the output log at OpenFOAM.o<jobid>

output:

/*---------------------------------------------------------------------------*\

| =========                 |                                                 |

| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |

|  \\    /   O peration     | Version:  4.1                                   |

|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |

|    \\/     M anipulation  |                                                 |

\*---------------------------------------------------------------------------*/

Build  : 4.1

Exec   : blockMesh

...

Writing polyMesh

----------------

Mesh Information

----------------

  boundingBox: (0 0 0) (0.1 0.1 0.01)

  nPoints: 882

  nCells: 400

  nFaces: 1640

  nInternalFaces: 760

----------------

Patches

----------------

  patch 0 (start: 760 size: 20) name: movingWall

  patch 1 (start: 780 size: 60) name: fixedWalls

  patch 2 (start: 840 size: 800) name: frontAndBack

End


Batch - Parallel

Copy the testCase41 directory from /usr/local/DOC/OPENFOAM and cd to it

cp -r /usr/local/doc/OPENFOAM/testCase41 .

cd testCase41

Run the job

sbatch HPCrun.slurm

Find the following MPI dump in "log.interFoam" file

/*---------------------------------------------------------------------------*\

| =========                 |                                                 |

| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |

|  \\    /   O peration     | Version:  4.1                                   |

|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |

|    \\/     M anipulation  |                                                 |

\*---------------------------------------------------------------------------*/

Build  : 4.1

Exec   : interFoam -parallel

Date   : May 19 2018

Time   : 00:53:14

Host   : "comp239t"

PID    : 196052

Case   : /scratch/pbsjobs/job.7800438.hpc

nProcs : 4

Slaves : 

3

(

"comp239t.196053"

"comp239t.196054"

"comp239t.196055"

)

...

...

ExecutionTime = 4.22 s  ClockTime = 5 s

Expression atmosphereVelocity on atmosphere:  average=0.00748013

End


References:

[1] OpenFOAM Home

[2] OpenFOAM Tutorial