Solving the cavity flow problem using the streamfunction-vorticity formulation

In this post I am going to write a (hopefully) simple code in matlab to solve the cavity flow problem using the vorticity stream function formulation. I will the compare the result to the result calculated by the OpenFOAM solver, icoFoam.  Writing your own solvers is fun, rewarding, and is a practice that really cements some of the fundamental knowledge of CFD.

Contents

1. Introduction to the Cavity Flow Problem
2. Governing Equations
3. Finite Differences and Solver Algorithm
• Understanding and setting the boundary conditions
• Semi-discretization of the governing equations
• Solving the vorticity equation in time
• Solving for the vorticity at the boundaries
• Solving for the stream function
• Putting it all together
4. Results/Comparison to icoFoam
• Re=10
• Re=100
5. Conclusion and some References

Introduction to the Cavity Flow Problem

The cavity flow problem is described in the following figure. Basically, there is a constant velocity across the top of the cavity which creates a circulating flow inside. To simulate this there is a constant velocity boundary condition applied to the lid, while the other three walls obey the no slip condition. Different Reynolds numbers give different results, so in this post I’ll simulate Re=10, and Re=800. At high Reynolds numbers we expect to see a more interesting result with secondary circulation zones forming in the corners of the cavity.