1.4.1. Lid Driven Cavity

1.4.1.1. Problem Specification

For the open cavity, what is the influence of:

  • Increased mesh resolution?

  • Increased mesh grading?

  • Reynolds Number?

  • Turbulent flow?

The open cavity is defined as shown below:

../../_images/lid_driven_cavity.png

Case 1 - icoFoam Solver:

  • Laminar

  • Isothermal

  • Incompressible

Case 2 - pisoFoam Solver:

  • Turbulent

  • Isothermal

  • Incompressible

1.4.1.2. Pre-Processing

I use Kate for processing the text files. I have set $FOAM_RUN = /home/andrew/Dropbox/7_OpenFOAM/run. Now I copy the files from the tutorial directory:

$ cd $FOAM_RUN/1_tutorials/1_lid_driven_cavity
$ cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
$ cd cavity

This copies the following ascii dictionaries into cavity (the case directory):

  • 0
    • p (ics and bcs values)

    • U (ics and bcs values)

  • constant
    • transportProperties (viscosity)

  • system
    • blockMeshDict (mesh, domain and bcs application)

    • controlDict (parameters for solver)

    • fvSchemes (time and space numerical schemes)

    • fvSolution (parameters for numerical schemes)

1.4.1.2.1. Mesh Generation

OpenFOAM always uses a 3D system, but 2D can be used by specifying an empty bc on the 3rd dimension. The right-hand rule for node numbering:

../../_images/mesh.png

The components of the blockMeshDict are given below.

1.4.1.2.1.1. Header information

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  3.0.x                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/

1.4.1.2.1.2. File information

FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

1.4.1.2.1.3. Scaling factor for the vertex coordinates

All the coordinates given in the vertices section are multiplied by 0.1, or whatever factor is given. Looking at the vertices coordinates, this sets the sides of the cavity to 0.1m x 0.1m and it’s depth to 0.01m.

convertToMeters 0.1;

1.4.1.2.1.4. Vertices

Ordering of vertices is 0, 1, 2, 3, 4, 5, 6, 7 as per the figure above.

vertices
(
    (0 0 0)
    (1 0 0)
    (1 1 0)
    (0 1 0)
    (0 0 0.1)
    (1 0 0.1)
    (1 1 0.1)
    (0 1 0.1)
);

1.4.1.2.1.5. Block

Ordered list of vertex labels, number of nodes in three directions (x, y, z) and grading in three directions (x, y, z).

blocks
(
    hex (0 1 2 3 4 5 6 7) (20 20 1) simpleGrading (1 1 1)
);

1.4.1.2.1.6. Edges

This is blank because it is used to describe arc or spline edges.

edges
(
);

1.4.1.2.1.7. Boundary Conditions

This is a description of the boundary patches, using the vertex numbers.

boundary
(
    movingWall
    {
        type wall;
        faces
        (
            (3 7 6 2)
        );
    }
    fixedWalls
    {
        type wall;
        faces
        (
            (0 4 7 3)
            (2 6 5 1)
            (1 5 4 0)
        );
    }
    frontAndBack
    {
        type empty;
        faces
        (
            (0 3 2 1)
            (4 5 6 7)
        );
    }
);

1.4.1.2.1.8. Merge Patch Pairs

This is blank because there is only one block, so no merging is needed.

mergePatchPairs
(
);

1.4.1.2.1.9. How to generate a mesh?

The mesh is generated by running

$ cd $FOAM_RUN/1_tutorials/1_lid_driven_cavity/cavity
$ blockMesh

This creates the following subfolder:

  • constant
    • polyMesh
      • boundary

      • faces

      • neighbours

      • owner

      • points

1.4.1.2.2. Boundary and Initial Conditions

The ICs and BCs are set in this folder:

  • 0
    • p

    • U

The components of the p and U files:

1.4.1.2.2.1. Dimensions

This specifies that kinematic pressure \(m^2/s^2\) is being used, i.e. kinematic pressure \(P = p/\rho_0\). The dimensions for u are m/s according to [M L T Temp Quantity Current Luminosity].

dimensions      [0 2 -2 0 0 0 0];
dimensions      [0 1 -1 0 0 0 0];

1.4.1.2.2.2. Internal Field

The internal field in given a value, a uniform value of 0 in this case for the scalar pressure and (0 0 0) for the velocity vector.

internalField   uniform 0;
internalField   uniform (0 0 0);

1.4.1.2.2.3. Boundary Field

This specified that the pressure gradient is zero on the moving and fixed walls. The fixed walls have a noslip condition and the moving wall as a velocity of 1m/s. On the front and back the 2D condition is specified i.e. empty.

boundaryField
{
    movingWall
    {
        type            zeroGradient;
    }

    fixedWalls
    {
        type            zeroGradient;
    }

    frontAndBack
    {
        type            empty;
    }
}
boundaryField
{
    movingWall
    {
        type            fixedValue;
        value           uniform (1 0 0);
    }

    fixedWalls
    {
        type            fixedValue;
        value           uniform (0 0 0);
    }

    frontAndBack
    {
        type            empty;
    }
}

1.4.1.2.3. Physical Properties

The physical properties are located in this folder:

  • constant
    • transportProperties

The Reynolds Number is 10, such that the kinematic viscosity must be 0.01, if the velocity is 1 and the characteristic length is 0.1m.

nu              [0 2 -1 0 0 0 0] 0.01;

1.4.1.2.4. Control

The control dictionary is located here:

  • system
    • controlDict

This dictionary controls the time and reading and writing of the solution data and is described as follows:

1.4.1.2.4.1. Solver

This selects the incompressible, isothermal and laminar solver.

application     icoFoam;

1.4.1.2.4.2. Start and End Times

This sets the start and end times of the simulation. Usually the solution runs for 10 circulation times, which would be 10 x (0.1m / 1m/s) = 1s, however with hindsight, 0.5s is sufficient.

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         0.5;

1.4.1.2.4.3. Timestep

The timestep is set according to the Counrant Number. For a Courant Number of 1, a velocity of 1, a spatial step of 0.1/20 = 0.005m, the timestep is 0.005s.

deltaT          0.005;

1.4.1.2.4.4. Write Interval

In order to write out the data (U and p for the icoFoam solver) every 0.1s, we must specify a write interval of 20.

writeInterval   20;

1.4.1.2.4.5. Additional Settings

The additional settings are given below for the control dictionary, and are probably not changed very much from case to case.

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;

1.4.1.2.5. Finite Volume Discretisation Schemes

The finite volume discretisation scheme selection is made in fvSchemes:

  • system
    • fvSchemes

ddtSchemes
{
    default         Euler;
}

gradSchemes
{
    default         Gauss linear;
    grad(p)         Gauss linear;
}

divSchemes
{
    default         none;
    div(phi,U)      Gauss linear;
}

laplacianSchemes
{
    default         Gauss linear orthogonal;
}

interpolationSchemes
{
    default         linear;
}

snGradSchemes
{
    default         orthogonal;
}

1.4.1.2.6. Finite Volume Solvers

The selection of the finite volume solvers is made in fvSolution. In a closed incompressible system such as the cavity, pressure is relative: it is the pressure range that matters not the absolute values. In cases such as this, the solver sets a reference level by pRefValue in cell pRefCell. In this example both are set to 0. Changing either of these values will change the absolute pressure field, but not, of course, the relative pressures or velocity field.

  • system
    • fvSolution

solvers
{
    p
    {
        solver          PCG;
        preconditioner  DIC;
        tolerance       1e-06;
        relTol          0.05;
    }

    pFinal
    {
        $p;
        relTol          0;
    }

    U
    {
        solver          smoothSolver;
        smoother        symGaussSeidel;
        tolerance       1e-05;
        relTol          0;
    }
}

PISO
{
    nCorrectors     2;
    nNonOrthogonalCorrectors 0;
    pRefCell        0;
    pRefValue       0;
}

1.4.1.3. Viewing the Mesh

ParaView is loaded

$ cd $FOAM_RUN/1_tutorials/1_lid_driven_cavity/cavity
$ paraFoam

Load the mesh:

  • cavity.OpenFOAM is loaded.

  • Properties > Mesh Parts > Click X by Mesh Parts

  • Properties > Apply

Change the colors:

  • Properties > Display > Representation > Wireframe

  • Properties > Coloring > Solid Color > Edit > Black

  • Properties > View > Background > Single color > White

Change the representation:

  • Layout > Toggle to 2D (if 3D)

  • Click in white area

1.4.1.4. Running the Application

Run the application

$ cd $FOAM_RUN/1_tutorials/1_lid_driven_cavity/cavity
$ icoFoam

Or with the optional case argument

$ cd $FOAM_RUN/1_tutorials/1_lid_driven_cavity/cavity
$ icoFoam -case $FOAM_RUN/1_tutorials/1_lid_driven_cavity/cavity

The progress of the job is written to the terminal window. It tells the user the current time, maximum Courant number, initial and final residuals for all fields.

1.4.1.5. Post-processing

1.4.1.5.1. Contours

ParaView is loaded

$ cd $FOAM_RUN/1_tutorials/1_lid_driven_cavity/cavity
$ paraFoam

Load the mesh:

  • cavity.OpenFOAM is loaded.

  • Properties > Mesh Parts > Click X by Mesh Parts

  • Properties > Apply

Colours:

  • Properties > Representation > Surface

  • Last Frame

  • Properties > Coloring > Rescale

  • Properties > Background = White

  • Properties > Coloring > Edit > Choose Preset > Blue to Red Rainbow

  • Properties > Coloring > Edit > Save Current Colormap as default

  • Properties > Coloring > Edit > Edit Color Legend Properties > Title Text = Pressure (Pa)

  • Properties > Lighting > Specular = 1

  • Move legend to central position

1.4.1.5.2. Slice

  • Hold left mouse button to rotate view

  • Filters > Slice (icon)

  • Properties > Origin = 0.05, 0.05, 0.005

  • Properties > Normal = 0, 0, 1

  • Properties > Apply

  • Filters > Contour (icon) I’m not sure this adds anything

  • Properties > Contour by > p I’m not sure this adds anything

  • Isosurfaces > Range = 10 I’m not sure this adds anything

1.4.1.5.3. Vectors, slice

Outline:

  • Remove the eye from Slice and Contour filters

  • cavity.OpenFOAM > Representation > Outline

  • cavity.OpenFOAM > Coloring > Solid Colour > Black

  • cavity.OpenFOAM > Orientation Axes > Orentiation Axes Labrl Color > Black

Cell Centres:

  • Filter > Alphabetical > Cell Centres

  • CellCenters1 > Coloring > U

  • Apply

Arrows:

  • Filter > Alphabetical > Glyph

  • Glyph1 > scalars: p, vectors: U

  • Apply

To Save State:

  • File > Save State > contours_vectors.pvsm

1.4.1.5.4. Streamlines

Streamlines:

  • Filter > Alphabetical > Stream Tracer

  • Properties > Seeds > Seed Type > High Res Line Source

  • P1 = 0.05 0 0.005, P2 = 0.05 0.1 0.005

  • Resolution = 21

  • Max step = 0.5

  • Initial step = 0.2

  • Direction = BOTH

  • Type = Runge-Kutta-4-5

  • Properties > Coloring > U

  • Apply

Tube:

  • Filter > Alphabetical > Tube

  • Tube1 > Radius Factor = 10, Number of Sides = 6, Radius = 0.0003

  • Apply

1.4.1.6. Increased Mesh Resolution

  • Increase mesh density by a factor of 2

  • Map results of coarser mesh onto finer mesh

  • Compare results of fine and coarse mesh

1.4.1.6.1. Create new case from existing case

$ cd $FOAM_RUN/1_tutorials/1_lid_driven_cavity
$ mkdir cavityFine
$ cp -r cavity/constant cavityFine
$ cp -r cavity/system cavityFine
$ cd cavityFine

1.4.1.6.2. Create fine mesh - How to re-generate a mesh?

Open blockMeshDict file and change (20 20 1) to (40 40 1), i.e.

blocks
(
    hex (0 1 2 3 4 5 6 7) (40 40 1) simpleGrading (1 1 1)
);

Now run blockMesh to generate the constant folder:

$ cd $FOAM_RUN/1_tutorials/1_lid_driven_cavity/cavityFine
$ blockMesh

1.4.1.6.3. How to map the coarse mesh results onto the fine mesh?

Open controlDict file and change startTime 0 to startTime 0.5

startTime       0.5;

Check the predicates of mapFields

mapFields -help

Now map coarse to fine grid (consistent is used because the boundary conditions, boundary types and geometry are identical):

mapFields ../cavity -consistent

1.4.1.6.4. Control adjustments - How to maintain a Courant number of 1?

To maintain a Courant number of 1, the timestep must be halved, as the spatial step was halved.

Open controlDict file and change deltaT 0.005 to deltaT 0.0025

deltaT       0.0025;

Also specify output every 0.1 seconds by changing writeControl timeStep to writeControl runTime and writeInterval 20 to writeInterval 0.1:

writeControl    runTime;
writeInterval   0.1;

Also specify an end time of 0.7 seconds, by changing endTime 0.5 to endTime 0.7;

endTime    0.7;

1.4.1.6.5. How to run the code in the background?

This will send the output to a file called log and then view it with cat.

$ cd $FOAM_RUN/1_tutorials/1_lid_driven_cavity/cavityFine
$ icoFoam > log &
$ cat log

1.4.1.6.6. How to do a vector plot comparing unrefined with a refined mesh?

Create files with .OpenFOAM extension:

$ cd $FOAM_RUN/1_tutorials/1_lid_driven_cavity/cavity
$ paraFoam -touch
$ cd ../cavityFine
$ paraFoam -touch
$ paraFoam

Outline:

  • cavityFine.OpenFOAM > Properties > Apply

  • cavityFine.OpenFOAM > Properties > Representation > Outline

  • cavityFine.OpenFOAM > Properties > Coloring > Solid Colour > Black

  • Change from 3D to 2D

Cell Centres:

  • Filters > Alphabetical > Cell Centres

  • CellCentres1 > Properties > Apply

  • CellCentres1 > Properties > Coloring = U

Arrows:

  • Filters > Alphabetical > Glyphs

  • Glyph1 > Properties > Apply

  • Glyph1 > Propeties > Active Attributes > Vectors = U

  • Glyph1 > Propeties > Glyph Source > Glyph type = 2D Glyph

  • Glyph1 > Propeties > Scaling > Scale factor = 0.005

  • Glyph1 > Properties > Apply

Open coarse mesh:

  • File > Open > cavity.OpenFOAM

  • Repeat Outline, Cell Centres and Arrows (above)

  • File > Save State > vectors_fine_vs_coarse.pvsm

1.4.1.6.7. How to plot the velocity in the x-direction versus y?

  • List the functions possible in post processing (not really needed):

$ postProcess -list
  • Create volume fields Ux, Uy, Uz for all the time periods in the directories:

$ postProcess -func "components(U)"
$ paraFoam
  • Select cavityFine.OpenFOAM in Pipeline Browser

  • Check that the velocities have been created in Properties > Volume Fields > Ux, Uy, Uz

  • Properties tab > Properties > Mesh Parts > Select only internalMesh to avoid interpolation error.

  • Properties tab > Apply

  • Filter > Data Analysis > Plot Over Line

  • Select LineChartView1 (the panel on the right)

  • Select PlotOverLine1 in PipeLine Browser

  • Properties tab > Properties(PlotOverLine1)
    • Point 1 0.05, 0, 0.005

    • Point 2 0.05, 0.1, 0.005

    • Resolution 100

  • Properties tab > Display(XYChartRepresentation)
    • Attibute Type = Point data

    • Array name = arc_length (distance from base of cavity)

    • Deselect everything except Ux variable (U_X was created by default, so the PostProcess calculation wasn’t really needed)

    • Double click colour to change it

    • Line Style = None

    • Marker Style = Cross

  • Properties tab > View(Line Chart View)
    • Deselect Show Legend

    • Left axis title = Velocity in x-direction, Ux (m/s)

    • Left Axis Range Minimum = -0.3

    • Left Axis Range Maximum = 1.0

    • Bottom axis title = Distance from cavity base, y (m)

    • Bottom Axis Range Minimum = 0

    • Bottom Axis Range Maximum = 0.1

  • File > Save State > u_velocity_profile.pvsm

  • File > Exit

  • To the future: I can’t work out how to plot to charts on the same chart, because only one PlotOverLine seems possible per ParaView session