Command line interface user @openfoam:~$…

OpenFOAM comprises many applications, primarily designed to be driven by the command line. Whilst sometimes unfamiliar to new users, this interface provides the most flexible means by which to control the phases of case set-up, execution and evaluation of results, and lends itself to automation and batch-processing.

Basic usage

Applications are invoked using commands of the form:

<application> [OPTIONS] <arguments>

More detailed usage information is available using the help option; for example, when applied to the blockMesh application as:

blockMesh -help

the following text is presented:


Usage: blockMesh [OPTIONS]
Options:
  -case <dir>       Case directory (instead of current directory)
  -dict <file>      Alternative blockMeshDict
  -merge-points     Geometric point merging instead of topological merging
                    [default for 1912 and earlier].
  -no-clean         Do not remove polyMesh/ directory or files
  -region <name>    Specify alternative mesh region
  -sets             Write cellZones as cellSets too (for processing purposes)
  -time <time>      Specify a time to write mesh to (default: constant)
  -verbose          Force verbose output. (Can be used multiple times)
  -write-vtk        Write topology as VTU file and exit
  -doc              Display documentation in browser
  -help             Display short help and exit
  -help-compat      Display compatibility options and exit
  -help-full        Display full help and exit

Block mesh generator.

  The ordering of vertex and face labels within a block as shown below.
  For the local vertex numbering in the sequence 0 to 7:
    Faces 0, 1 (x-direction) are left, right.
    Faces 2, 3 (y-direction) are front, back.
    Faces 4, 5 (z-direction) are bottom, top.

                        7 ---- 6
                 f5     |\     :\     f3
                 |      | 4 ---- 5     \
                 |      3.|....2 |      \
                 |       \|     \|      f2
                 f4       0 ---- 1
    Y  Z
     \ |                f0 ------ f1
      \|
       o--- X

Using: OpenFOAM-2306 (2306) - visit www.openfoam.com
Build: _fbf00d6b-20230626
Arch:  LSB;label=32;scalar=64


Moving around the source code and cases is easily performed using standard linux commands, e.g.

  • ls: list directory contents
  • cd: change directory

In addition, several aliases are available which provide short cuts to many OpenFOAM directories. These include:

  • foam: change to the main OpenFOAM project directory
  • src: change to the top-level source directory
  • sol: change to the top-level solver directory
  • util: change to the top-level utilities directory
  • tut: change to the top-level tutorial directory

Command line tab completion of OpenFOAM applications presents users with selections that are tailored for the current action. For example, issuing

checkMesh <TAB> <TAB>

returns the list of available options for the checkMesh utility:

-allGeometry        -allRegions         -allTopology        -case               
-constant           -decomposeParDict   -latestTime         -meshQuality        
-noTopology         -noZero             -parallel           -region             
-regions            -time               -writeAllFields     -writeFields        
-writeSets          -doc                -help               

Many options require additional user inputs, identified by -option <value> entries when requesting help via the -help option, as shown in the previous blockMesh example.

If using the -time option, the completion will limit the options to the list of available times, e.g. after running the tutorial:

Invoking the following:

checkMesh -time <TAB> <TAB>

returns:

0    0.1  0.2  0.3  0.4  0.5

Multi-region cases are notoriously complex to set-up and process. The -region option will limit the available options to the list of regions, e.g. applied to the tutorial:

Invoking the following:

checkMesh -region <TAB> <TAB>

returns:

air     porous

Manual pages provide a straightforward interface to access the options available to all OpenFOAM applications. See the full list of options here: