Lid-driven cavity flow
The lid-driven cavity flow tutorial is the easiest and most well documented tutorial on OpenFOAM. A incompressible flow in a two-dimensional square domain is shown in figure below. The top wall moves in the $x$-direction at a speed of 1 m/s while the other 3 are stationary. Initially, the flow will be assumed laminar and will be solved on a uniform and non mesh using the icoFoam solver for laminar, isothermal, incompressible flow. Then, the effect of increased mesh resolution and mesh grading towards the walls will be investigated.
Geometry of the lid driven cavity
Setting up the case
Running directory
As a first step, we copy the cavity case directory to the running directory.
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity <your running directory>
Mesh generation
OpenFOAM solves the case in 3 dimensions by default but can be instructed to solve in 2 dimensions by specifying a ‘special’ empty boundary condition on boundaries normal to the (3rd) dimension for which no solution is required. The mesh generator, blockMesh, generates meshes from a description specified in an input dictionary, blockMeshDict located in the system (or constant/polyMesh) directory for a given case. The blockMeshDict entries for this case are as follows:
1 | /\*--------------------------------\*- C++ -\*----------------------------------\*\ |
The mesh is generated by running blockMesh on this blockMeshDict file. From within the case directory, this is done, simply by typing in the terminal: blockMesh
Boundary and initial conditions
The initial fields set up for this case is set up to start at time t = 0 s, so the initial field data is stored in a 0 sub-directory of the cavity directory. The 0 sub-directory contains 2 files, p and U, one for each of the pressure (p) and velocity (U) fields whose initial values and boundary conditions must be set. Let us look into the file p:
1 | /\*--------------------------------\*- C++ -\*----------------------------------\*\ |
- dimensions specifies the dimensions of the field, here kinematic pressure, i.e. $ m^2s^{-2}$ (see here for more information);
- internalField the internal field data which can be uniform, described by a single value; or nonuniform, where all the values of the field must be specified (see here for more information);
- boundaryField the boundary field data that includes boundary conditions and data for all the boundary patches.
The similar configurations can be found in the velocity field in the 0/U file.
Physical properties
For an icoFoam case, the only property that must be specified is the kinematic viscosity($\nu$) which is stored from the transportProperties dictionary. We can check that the kinematic viscosity is set correctly by opening the transportProperties dictionary to view/edit its entries. This case will be run with a Reynolds number of 10, where the Reynolds number is defined as:
$$\eqalign{ \mathbf{Re} = \frac{d \vert U \vert}{\nu} }$$
where $d$ and $U$ are the characteristic length and velocity respectively, and and $\nu$ is the kinematic viscosity we are going to define. Here in our case $d$ = 0.1 m, $U$ = 1 m/s, so that for $\mathbf{Re}$ = 10, $\nu$ = 0.01 $m^2s^{-1}$. Hence, the correct file entry for kinematic viscosity should be specified below:
1 | /\*--------------------------------\*- C++ -\*----------------------------------\*\ |
Control of the simulation
Setting data relating to the control of time and reading and writing of the solution data are read in from the controlDict dictionary.
1 | /\*--------------------------------\*- C++ -\*----------------------------------\*\ |
Running an application
Viewing the mesh
It is convenient to keep ParaView open while running other commands from the terminal, we will launch it in the background using the & operator by typing paraFoam &
to run paraView at current directory. Alternatively, it can be launched from another directory location with an optional -case argument giving the case directory. paraFoam -case <your directory (relative path)> &
The geometry and the wireframe can be obtained in ParaView . The figure below shows the configuration of uniform mesh distribution.
Uniform mesh
Some modifications can be done in the blockMeshDict, if the non uniform mesh distribution is desired. We list some examples as follow:
simpleGrading The simple description specifies uniform expansions in the local $x_1$, $x_2$ and $x_3$ directions respectively with only 3 expansion ratios. The ratio is that of the width of the end cell $\delta_e$ along one edge of a block to the width of the start cell $\delta_s$ along that edge.
simpleGrading (1 2 3) // cell expansion ratios in 3 directions
Non uniform mesh - simpleGrading
edgeGrading This gives us the way to specified the expension ratio of the mesh on each edge directly.
edgeGrading (1 1 1 1 2 2 2 2 3 3 3 3)
This means the ratio of cell widths along edges 0-3 is 1, along edges 4-7 is 2 and along 8-11 is 3 ( the number and direction of the edge in a block can be seen here).
Non uniform mesh - edgeGrading
- Multi-grading of a block In our case, we might require finer cell for the mesh near the walls. OpenFOAM v2.4+ includes multi-grading functionality that can divide a block in an given direction and apply different grading within each division. It is specified by replacing any single value expansion ratio in the grading specification of the block. A example configuration for our cavity case is shown as follow.
simpleGrading (
// x1-direction expansion ratio
(
(0.2 0.3 4) // 20% y-dir, 30% cells, expansion = 4
(0.6 0.4 1) // 60% y-dir, 40% cells, expansion = 1
(0.2 0.3 0.25) // 20% y-dir, 30% cells, expansion = 0.25 (1/4)
)
// x2-direction expansion ratio
(
(0.2 0.3 4) // 20% y-dir, 30% cells, expansion = 4
(0.6 0.4 1) // 60% y-dir, 40% cells, expansion = 1
(0.2 0.3 0.25) // 20% y-dir, 30% cells, expansion = 0.25 (1/4)
)
// x3-direction expansion ratio
1
)
Non uniform mesh - multi-grading
Running
The icoFoam solver is executed either by entering the case directory and typing icoFoam
at the command prompt, or with the optional -case argument giving the case directory. icoFoam -case <your running directory>
Pressure contour and the velocity vector
- Reference: