Difference between revisions of "OpenFOAM-version-7/C2/Setting-up-a-Test-Case-in-OpenFOAM/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 28: Line 28:
 
* '''OpenFOAM''' version 7
 
* '''OpenFOAM''' version 7
 
* '''ParaView''' version 5.6.0, and
 
* '''ParaView''' version 5.6.0, and
* '''gedit''' Text editor
+
* '''gedit Text editor'''
 +
 
 
You may use any other '''text editor''' of your choice.
 
You may use any other '''text editor''' of your choice.
 
|-  
 
|-  
 
|| Slide: Prerequisites
 
|| Slide: Prerequisites
* If not, please go through the prerequisite '''Linux '''tutorials on https://spoken-tutorial.org
+
 
 +
 
 +
 
 
|| As a prerequisite:
 
|| As a prerequisite:
 
* You should be familiar with basic '''Linux commands'''.
 
* You should be familiar with basic '''Linux commands'''.
Line 55: Line 58:
 
|| [Terminal] Type:
 
|| [Terminal] Type:
 
'''mkdir -p $FOAM_RUN'''
 
'''mkdir -p $FOAM_RUN'''
|| Now, let’s create a '''run directory'''.
+
|| Now, let’s create a '''RUN directory'''.
  
 
To do so, type the '''command''' as shown.
 
To do so, type the '''command''' as shown.
Line 62: Line 65:
  
 
'''FOAM_RUN'''
 
'''FOAM_RUN'''
|| '''Tutorial cases''' will later be copied into the '''run directory'''.
+
|| '''Tutorial cases''' will later be copied into the '''RUN directory'''.
 
|-  
 
|-  
 
|| [Terminal] Type:
 
|| [Terminal] Type:
  
 
'''cd $FOAM_RUN'''
 
'''cd $FOAM_RUN'''
|| Go to the '''run directory''' using the '''cd command'''.
+
|| Go to the '''RUN directory''' using the '''cd command'''.
  
Now our '''present working directory''' is the '''run directory'''.
+
Now our present working directory is the '''RUN directory'''.
 
|-  
 
|-  
 
|| Only Narration
 
|| Only Narration
Line 81: Line 84:
  
 
'''cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity .'''
 
'''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'''.
+
|| We’ll now copy the '''Lid driven cavity case''' from the '''tutorial directory''' into the '''RUN directory'''.
  
 
To do so, type the following '''command'''.
 
To do so, type the following '''command'''.
Line 110: Line 113:
  
 
'''cd cavity/0'''
 
'''cd cavity/0'''
|| The '''0''' folder contains the initial and boundary conditions for the '''simulation'''.
+
|| 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'''.
 
Type the following '''command''' to move into the '''0''' folder inside the '''cavity case directory'''.
Line 130: Line 133:
 
|-  
 
|-  
 
|| Only Narration
 
|| Only Narration
|| The '''p''' file contains the '''initial''' and '''boundary''' conditions of '''kinematic''' pressure.
+
|| The '''p''' file contains the '''initial''' and '''boundary conditions''' of '''kinematic pressure'''.
 
|-  
 
|-  
 
|| [gedit - '''p'''] Highlight
 
|| [gedit - '''p'''] Highlight
Line 152: Line 155:
  
 
Both the '''zeroGradient'''
 
Both the '''zeroGradient'''
|| You can see that all walls are imposed with a '''zero gradient''' pressure boundary condition.
+
|| You can see that all walls are imposed with a '''zero gradient pressure boundary condition'''.
 
|-  
 
|-  
 
|| [gedit - '''p'''] Close the window
 
|| [gedit - '''p'''] Close the window
Line 163: Line 166:
 
|-  
 
|-  
 
|| Only Narration
 
|| Only Narration
|| The '''U file''' contains the initial and boundary conditions of '''velocity'''.
+
|| The '''U file''' contains the '''initial''' and '''boundary conditions''' of '''velocity'''.
 
|-  
 
|-  
 
|| [gedit - '''U'''] Highlight
 
|| [gedit - '''U'''] Highlight
  
 
'''uniform (1 0 0);'''
 
'''uniform (1 0 0);'''
|| You can see that the '''moving wall''' is imposed with a '''velocity''' of '''1 m/s''' in the x direction.
+
|| You can see that the moving wall is imposed with a '''velocity''' of '''1 m/s''' in the x direction.
 
|-  
 
|-  
 
|| [gedit - '''U'''] Highlight
 
|| [gedit - '''U'''] Highlight
  
 
'''noSlip '''
 
'''noSlip '''
|| Also notice that the '''no-slip''' condition is imposed on the three '''fixed walls'''.
+
|| Also notice that the '''no-slip condition''' is imposed on the three fixed walls.
 
|-  
 
|-  
 
|| [gedit - '''U'''] Close the window
 
|| [gedit - '''U'''] Close the window
Line 193: Line 196:
  
 
'''nu '''
 
'''nu '''
|| The '''transportProperties''' file contains the details of '''kinematic''' '''viscosity'''.
+
|| The '''transportProperties''' file contains the details of '''kinematic viscosity'''.
 
|-  
 
|-  
 
|| [gedit - '''transportProperties''']  
 
|| [gedit - '''transportProperties''']  
Line 202: Line 205:
 
|| Slide: Kinematic Viscosity
 
|| Slide: Kinematic Viscosity
 
||  
 
||  
* The '''kinematic viscosity''' is defined by:
+
The '''kinematic viscosity''' is defined by:
𝜈 = |U|𝑑 / 𝑅𝑒
+
'''''nu'' equals magnitude of ''U'' times ''d'' by ''Re'''''
where '''velocity''' (|U|) = '''1 m/s'''
+
 
characteristic length (d) = '''0.1 m'''
+
where  
* The '''Reynolds number (Re)''' for the '''flow''' is taken as '''10'''
+
*'''velocity''' is '''1 m per second'''
* The '''kinematic viscosity (𝜈) '''is therefore '''0.01 m<sup>2</sup>/s'''
+
*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
 
|| Narration Only
Line 215: Line 224:
  
 
Highlight '''0.01'''
 
Highlight '''0.01'''
|| The value of '''kinematic''' '''viscosity''' is indicated in the '''transportProperties''' file.
+
|| The value of '''kinematic viscosity''' is indicated in the '''transportProperties''' file.
 
|-  
 
|-  
 
|| [gedit - '''transportProperties'''] Close the window
 
|| [gedit - '''transportProperties'''] Close the window
Line 236: Line 245:
 
|| The '''system''' folder contains the following files:
 
|| The '''system''' folder contains the following files:
  
'''blockMeshDict''', '''controlDict''', '''fvSchemes''' and '''fvSolution'''.
+
'''blockMeshDict, controlDict, fvSchemes''' and '''fvSolution'''.
 
|-  
 
|-  
 
|| [Terminal] Highlight  
 
|| [Terminal] Highlight  
  
 
'''fvSchemes'''
 
'''fvSchemes'''
|| The '''fvSchemes dictionary''' contains the '''finite''' '''volume''' '''discretisation''' '''schemes'''.
+
|| The '''fvSchemes dictionary''' contains the '''finite volume discretisation schemes'''.
 
|-  
 
|-  
 
|| [Terminal] Highlight  
 
|| [Terminal] Highlight  
  
 
'''fvSolution'''
 
'''fvSolution'''
|| The '''fvSolution dictionary''' contains the '''linear''' '''equation''' '''solvers''' and '''tolerances'''.
+
|| The '''fvSolution dictionary''' contains the '''linear equation solvers''' and '''tolerances'''.
  
 
It contains other '''algorithm controls''' as well.
 
It contains other '''algorithm controls''' as well.
Line 253: Line 262:
  
 
'''controlDict'''
 
'''controlDict'''
|| The '''controlDict dictionary''' contains the '''simulation''' '''control''' '''parameters'''.  
+
|| The '''controlDict dictionary''' contains the '''simulation control parameters'''.  
  
The '''dictionary''' input includes the '''control''' '''of time''' and '''reading''' and '''writing''' of the '''solution''' '''data'''.
+
The '''dictionary''' input includes the '''control''' of '''time''' and '''reading''' and '''writing''' of the '''solution data'''.
 
|-  
 
|-  
 
|| [Terminal] Type:  
 
|| [Terminal] Type:  
  
 
'''gedit controlDict'''
 
'''gedit controlDict'''
|| Let’s now open the '''controlDict''' file in a '''text editor'''.
+
|| Let’s open the '''controlDict''' file in a '''text editor'''.
 
|-  
 
|-  
 
|| [Terminal] Highlight  
 
|| [Terminal] Highlight  
Line 275: Line 284:
  
 
'''stopAt''' '''endTime;'''
 
'''stopAt''' '''endTime;'''
|| The time at which the '''simulation''' stops is specified using the '''keyword stopAt'''.
+
|| The time at which the '''simulation''' stops, is specified using the '''keyword stopAt'''.
  
 
Here, '''stopAt''' is specified using the keyword '''endTime'''.
 
Here, '''stopAt''' is specified using the keyword '''endTime'''.
Line 282: Line 291:
  
 
'''endTime''' '''0.5;'''
 
'''endTime''' '''0.5;'''
|| The '''endTime''' is set at '''0.5''' seconds.
+
|| The '''endTime''' is set at '''0.5 seconds'''.
  
This means that '''simulation''' stops after '''0.5''' seconds.
+
This means that '''simulation''' stops after '''0.5 seconds'''.
 
|-  
 
|-  
 
|| [gedit - '''controlDict'''] Highlight
 
|| [gedit - '''controlDict'''] Highlight
Line 291: Line 300:
 
|| The value of the '''keyword deltaT''' defines the '''time step''' for the '''simulation'''.
 
|| 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.
+
The '''time step''' for the current '''simulation''' is set as '''0.005 seconds'''.
  
 
'''Temporal accuracy''' and '''numerical stability''' is essential while running the '''simulation'''.
 
'''Temporal accuracy''' and '''numerical stability''' is essential while running the '''simulation'''.
Line 297: Line 306:
 
To achieve this, a''' Courant number''' of less than 1 is required.
 
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.
+
Keeping this in mind, the '''time step''' is set to '''0.005 seconds'''.
 
|-
 
|-
 
|-
 
|-
Line 304: Line 313:
  
 
'''application''' '''icoFoam'''<nowiki>;</nowiki>
 
'''application''' '''icoFoam'''<nowiki>;</nowiki>
|| '''icoFoam''' is the '''OpenFOAM solver''' used to '''simulate''' the '''lid driven cavity''' '''flow'''.
+
|| '''icoFoam''' is the '''OpenFOAM solver''' used to '''simulate''' the '''lid driven cavity flow'''.
 
|-  
 
|-  
 
|| [gedit - '''controlDict'''] Close the window
 
|| [gedit - '''controlDict'''] Close the window
Line 317: Line 326:
  
 
'''blockMesh''' >> '''Enter'''
 
'''blockMesh''' >> '''Enter'''
|| Type the '''command blockMesh''' and press '''Enter''' to '''mesh''' the '''geometry'''.
+
|| 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.
+
The '''command''' takes input from the '''blockMeshDict dictionary''' and creates the geometry and '''meshes''' it.
 
|-  
 
|-  
 
|| [Terminal] Highlight '''End'''
 
|| [Terminal] Highlight '''End'''
Line 349: Line 358:
 
|| In the '''ParaView''' window, go to the '''Properties''' tab on the left.
 
|| In the '''ParaView''' window, go to the '''Properties''' tab on the left.
  
Then click on the green coloured '''Apply '''button'''.'''
+
Then click on the green coloured '''Apply '''button.
 
|-  
 
|-  
 
|| [ParaView]
 
|| [ParaView]
Line 365: Line 374:
  
 
Velocity Contours in the Layout
 
Velocity Contours in the Layout
|| The '''velocity''' '''contour''' at the start of the '''simulation''' is now displayed in the''' layout'''.
+
|| The '''velocity contour''' at the start of the '''simulation''' is now displayed in the''' layout'''.
 
|-  
 
|-  
 
|| [ParaView]
 
|| [ParaView]
Line 385: Line 394:
 
|| With this we have come to the end of the tutorial.
 
|| With this we have come to the end of the tutorial.
  
To summarize.
 
 
|-  
 
|-  
 
|| Slide: Summary
 
|| Slide: Summary
|| In this tutorial, we have learnt to:
+
|| To summarise, in this tutorial we have learnt to:
 
* Set up a''' case''' in '''OpenFOAM'''
 
* Set up a''' case''' in '''OpenFOAM'''
 
* Access the '''case files''' using '''terminal'''
 
* Access the '''case files''' using '''terminal'''
Line 415: Line 423:
 
|| Slide: FOSSEE Case Study Project
 
|| Slide: FOSSEE Case Study Project
 
||  
 
||  
* The FOSSEE team coordinates solving feasible CFD problems of reasonable complexity using OpenFOAM.
+
* The FOSSEE team coordinates solving feasible '''CFD''' problems of reasonable complexity using '''OpenFOAM'''.
 
* We give honorarium and certificates to those who do this.
 
* We give honorarium and certificates to those who do this.
 
* For more details, please visit these sites.
 
* For more details, please visit these sites.

Revision as of 14:38, 21 July 2020

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

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
  • 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:

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

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

where

  • 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:

ls

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

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 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.


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.

[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.
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