From Script | Spoken-Tutorial
Jump to: navigation, search

Title of the script: Setting-up a test case in OpenFOAM

Author: Ashley Melvin

Keywords: OpenFOAM, ParaView, lid driven cavity, pre-processing, blockMesh, controlDict, post-processing, video tutorial

Visual Cue Narration
Slide: Opening Slide Hello and welcome to this tutorial on Setting up a test case in OpenFOAM.
Slide: Learning Objective In this tutorial, we will learn to:
  • Set up a case in OpenFOAM
  • Access the case files using terminal
  • Pre-process a case
  • Run a case, and
  • Post-process a case
Slide: System Specifications This tutorial is recorded using,
  • Ubuntu Linux OS version 18.04
  • OpenFOAM version 7
  • ParaView version 5.6.0, and
  • gedit Text editor

You may use any other text editor of your choice.

Slide: Prerequisites

As a prerequisite:
  • You should be familiar with basic Linux commands.
  • If not, please go through the prerequisite Linux tutorials on this website.
Slide: Lid Driven Cavity In this tutorial, we will learn to set up the lid driven cavity case.

Lid driven cavity is one of the most widely used 2D test cases for the validation of a CFD code.

Slide: Diagram This is the diagram of Lid Driven Cavity Flow.

It consists of 3 fixed walls and a moving top wall.

Highlight Terminal on the machine Open a terminal by pressing the Ctrl, Alt and T keys together.
Only Narration Here onwards please remember to press the Enter key after typing each command.
[Terminal] Type:

mkdir -p $FOAM_RUN

Now, let’s create a RUN directory.

To do so, type the command as shown.

[Terminal] Highlight


Tutorial cases will later be copied into the RUN directory.
[Terminal] Type:


Go to the RUN directory using the cd command.

Now our present working directory is the RUN directory.

Only Narration OpenFOAM installation comes with a set of test cases.

The TUTORIALS directory contains these test cases.

The Lid driven cavity case already exists inside the TUTORIALS directory.

[Terminal] Type:

cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity .

We’ll now copy the Lid driven cavity case from the TUTORIALS directory into the RUN directory.

To do so, type the following command.

Slide: blockMesh
  • The mesh generator for OpenFOAM is a utility called blockMesh.
  • The input dictionary for blockMesh utility is blockMeshDict.
[Terminal] Type:

gedit cavity/system/blockMeshDict

The blockMeshDict file is located in the system folder.

Open the blockMeshDict file in a text editor.

[gedit - blockMeshDict] Highlight

vertices, blocks, edges and boundary

Now let’s look at the contents of the file.

The blockMeshDict contains details of the geometry like vertices, blocks, edges and boundaries.

[gedit - blockMeshDict] Close the window Close the blockMeshDict file.
[Terminal] Type:

cd cavity/0

The 0 folder contains the initial and boundary conditions for the simulation.

Type the following command to move into the 0 folder inside the cavity case directory.

[Terminal] Type:


Type ls and press Enter to view the files in the 0 folder.
[Terminal] Highlight

p and U

The 0 folder contains the kinematic pressure file p and the velocity file U.
[Terminal] Type:

gedit p

Open the kinematic pressure file p in a text editor.
Only Narration The p file contains the initial and boundary conditions of kinematic pressure.
[gedit - p] Highlight

dimensions [0 2 -2 0 0 0 0]

The dimensions of kinematic pressure is meter squared per second squared.
[gedit - p] Highlight


The internalField defines the values in the interior of the domain.
[gedit - p] Highlight

uniform 0

The initial field is set as 0 kinematic pressure.

This field is uniform across the domain.

[gedit - p] Highlight

Both the zeroGradient

You can see that all walls are imposed with a zero gradient pressure boundary condition.
[gedit - p] Close the window Let us close the p file.
[Terminal] Type:

gedit U

Now open the velocity file U in a text editor.
Only Narration The U file contains the initial and boundary conditions of velocity.
[gedit - U] Highlight

uniform (1 0 0);

You can see that the moving wall is imposed with a velocity of 1 m/s in the x direction.
[gedit - U] Highlight


Also notice that the no-slip condition is imposed on the three fixed walls.
[gedit - U] Close the window Now let us close the U file.
[Terminal] Type:

cd ..

We’ll go back to the cavity folder.

Type cd (space)(dot)(dot)

[Terminal] Type:

gedit constant/transportProperties

Next, we will view the transport properties file which is in the constant folder.
[gedit - transportProperties] Highlight


The transportProperties file contains the details of kinematic viscosity.
[gedit - transportProperties]

Highlight [0 2 -1 0 0 0 0]

The dimensions of kinematic viscosity is meter squared per second.
Slide: Kinematic Viscosity

The kinematic viscosity is defined by: nu equals magnitude of U times d by Re


  • velocity is 1 m per second
  • characteristic length is 0.1 meters

The Reynolds number (Re) for the flow is taken as 10.

The kinematic viscosity is therefore 0.01 meter squared per second

Narration Only Now let me switch back to transportProperties file.
[gedit - transportProperties]

Highlight 0.01

The value of kinematic viscosity is indicated in the transportProperties file.
[gedit - transportProperties] Close the window Close the transportProperties file.
[Terminal] Type:

cd system

To move into the system folder, type the following command.
[Terminal] Type:


Type ls to view the contents of the system folder.
[Terminal] Highlight

blockMeshDict controlDict fvSchemes fvSolution

The system folder contains the following files:

blockMeshDict, controlDict, fvSchemes and fvSolution.

[Terminal] Highlight


The fvSchemes dictionary contains the finite volume discretisation schemes.
[Terminal] Highlight


The fvSolution dictionary contains the linear equation solvers and tolerances.

It contains other algorithm controls as well.

[Terminal] Highlight


The controlDict dictionary contains the simulation control parameters.

The dictionary input includes the control of time and reading and writing of the solution data.

[Terminal] Type:

gedit controlDict

Let’s open the controlDict file in a text editor.
[Terminal] Highlight

startFrom and startTime

The start and stop times and the time step for the run must be set.
[gedit - controlDict] Highlight

startTime 0;

The start time is set at 0 seconds.
[gedit - controlDict] Highlight

stopAt endTime;

The time at which the simulation stops, is specified using the keyword stopAt.

Here, stopAt is specified using the keyword endTime.

[gedit - controlDict] Highlight

endTime 0.5;

The endTime is set at 0.5 seconds.

This means that simulation stops after 0.5 seconds.

[gedit - controlDict] Highlight

deltaT 0.005;

The value of the keyword deltaT defines the time step for the simulation.

The time step for the current simulation is set as 0.005 seconds.

Temporal accuracy and numerical stability is essential while running the simulation.

To achieve this, a Courant number of less than 1 is required.

Keeping this in mind, the time step is set to 0.005 seconds.

Please refer to the additional reading material on this tutorial page for details.

It mentions the steps used to calculate the time-step.

[gedit - controlDict] Highlight

application icoFoam;

icoFoam is the OpenFOAM solver used to simulate the lid driven cavity flow.
[gedit - controlDict] Close the window Close the controlDict file.
[Terminal] Type:

cd ..

Go back to the cavity folder using cd command.
[Terminal] Type:

blockMesh >> Enter

Type the command blockMesh and press Enter to mesh the geometry.

The command takes input from the blockMeshDict dictionary and creates the geometry and meshes it.

[Terminal] Highlight End The meshing is now complete.
[Terminal] Type:


The lid driven cavity flow is an incompressible flow.

It is solved using the OpenFOAM solver icoFoam.

To start the simulation, type icoFoam in the terminal.

[Terminal] Highlight End The iterations are now complete.
[Terminal] Type:


Let us view the simulated results in ParaView.

So, type paraFoam in the terminal.

[ParaView] Properties Tab

Click on Apply

In the ParaView window, go to the Properties tab on the left.

Then click on the green coloured Apply button.


Click on vtkBlockColors >> Click on U

Go to the Active Variable Controls at the top.

Click on the vtkBlockColors dropdown and select U.

Ensure that you click on the U option with a point icon and not the box icon, in the dropdown.

The box icon would display contours without any grading.


Velocity Contours in the Layout

The velocity contour at the start of the simulation is now displayed in the layout.

Go to VCR Controls and click on the Play Button

Let us see how the velocity contours develop through the simulation.

To do so, go to the VCR Controls and click on the Play button.


Final Velocity Contours in the Layout

The velocity contour at the end of the simulation is now displayed in the layout.
[ParaView] Close the Window Close the ParaView window.
Only Narration With this we have come to the end of the tutorial.
Slide: Summary To summarise, in this tutorial we have learnt to:
  • Set up a case in OpenFOAM
  • Access the case files using terminal
  • Pre-process a case
  • Run a case, and
  • Post-process a case
Slide: About the Spoken Tutorial Project The video at the following link summarises the Spoken Tutorial project.

Please download and watch it.

Slide: Spoken Tutorial Workshops We conduct workshops using Spoken Tutorials and give certificates.

Please contact us.

Slide: Spoken Tutorial Forum Please post your timed queries in this forum.
Slide: FOSSEE Forum
  • Do you have any general/technical questions?
  • Please visit the forum given in this link.
Slide: FOSSEE Case Study Project
  • The FOSSEE team coordinates solving feasible CFD problems of reasonable complexity using OpenFOAM.
  • We give honorarium and certificates to those who do this.
  • For more details, please visit these sites.
Slide: Spoken Tutorial The Spoken Tutorial project is supported by MHRD, Govt. of India.

The script for this tutorial is contributed by Ashley Melvin.

And this is Swetha Sridhar from IIT Bombay signing off.

Thank you for joining.

Contributors and Content Editors

Ashleymelvin, Nancyvarkey