OpenFOAM-version-7/C2/Setting-up-a-Test-Case-in-OpenFOAM/English
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:
|
Slide: System Specifications | This tutorial is recorded using,
However, you may use any other text editor of your choice. |
Slide: Prerequisites
|
As a prerequisite:
|
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
FOAM_RUN |
Tutorial cases will later be copied into the run directory. |
[Terminal] Type:
cd $FOAM_RUN |
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 tutorial directory contains these test cases. The Lid driven cavity case already exists inside the tutorial directory. |
[Terminal] Type:
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity . |
We’ll now copy the Lid driven cavity case from the tutorial directory into the run directory.
To do so, type the following command. |
Slide: blockMesh |
|
[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:
ls |
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
internalField |
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
noSlip |
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
nu |
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 |
𝜈 = |U|𝑑 / 𝑅𝑒 where velocity (|U|) = 1 m/s characteristic length (d) = 0.1 m
|
Narration Only | 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:
ls |
Type ls to view the contents of the system folder. |
[Terminal] Highlight
|
The system folder contains the following files:
blockMeshDict, controlDict, fvSchemes and fvSolution. |
[Terminal] Highlight
fvSchemes |
The fvSchemes dictionary contains the finite volume discretisation schemes. |
[Terminal] Highlight
fvSolution |
The fvSolution dictionary contains the linear equation solvers and tolerances.
It contains other algorithm controls as well. |
[Terminal] Highlight
controlDict |
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 now 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. |
[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:
icoFoam |
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:
paraFoam |
Let us view the simulated results in ParaView.
|
[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. |
[ParaView]
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. |
[ParaView]
Velocity Contours in the Layout |
The velocity contour at the start of the simulation is now displayed in the layout. |
[ParaView]
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. |
[ParaView]
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.
To summarize. |
Slide: Summary | In this tutorial, we have learnt to:
|
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 |
|
Slide: FOSSEE Case Study Project |
|
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. |