This piece of code solves the Navier Stokes equation using the SIMPLE method on a staggered grid to obtain the solution to the lid driven cavity problem.

Note this code is at the moment not fully validated and may change as we have noticed the velocity values are under predicted.

Download the Excel VBA source code for the lid driven cavity problem here.

Lid Driven Cavity Velocity Vector Plot Re=1000

The Excel workbook contains the code, as illustrated below:-

The calculation matrix is shown on the worksheet and is updated every 20 iterations during the solution.

Pressure Values on the grid are shown in Blue

V Values on the grid are shown in Red

U Values on the grid are shown in Green

To start the solution press the solve button and the VBA code will continue to iterate until interrupted by the Esc button. The iteration number is displayed in the top left hand cell.

Notes on solution:-

1) Stop the program when the grid does not seem to be changing much

2) The number of iterations to reach a steady state depends on the time step and Re number

3) Too small a time step and solution will take a long long time

4) For higher Re numbers a finer grid is require to resolve the secondary corner vortices.

5) For Re number 100 a time step of about 0.01 seems ok and wait a few thousand iterations

6) Check row and cols of velocity add up to give conservation across the whole grid.

To change parameters – enter the Excel VBA editor (Tools->Macro->Visual Basic Editor) and the code is on sheet 1. Here you can change the Re number, time step, number of grid points etc

To create a vector plot of the solution press the Report button on the worksheet and a vector plot script suitable for M3d (download here) is written to worksheet2. This plot routine can be custermised in the code to any format. To create the plot in M3d cut and paste the data on worksheet2 into notepad to get a text script file, like below.

Copy the text and paste it into the command line in M3d (Note: to paste to M3d command line you need to right click the mouse and select paste, the ctrl-V doesn’t work)

Note: Vectors of a very small magnitudes have been given a fixed length.