<<

Solution to two-dimensional Incompressible Navier-Stokes Equations with SIMPLE, SIMPLER and Vorticity- Approaches. Driven-Lid Cavity Problem: Solution and Visualization.

by

Maciej Matyka

Computational Physics Section of Theoretical Physics University of Wrocław in Poland Department of Physics and Astronomy

Exchange Student at University of Link¨oping in Sweden

[email protected] http://panoramix.ift.uni.wroc.pl/∼maq 30 czerwca 2004 roku

Streszczenie

In that report solution to incompressible Navier - Stokes equations in non - dimensional form will be presented. Standard fundamental methods: SIMPLE, SIMPLER (SIMPLE Revised) and Vorticity-Stream function approach are compared and results of them are analyzed for standard CFD test case - Drived Cavity flow. Different aspect ratios of cavity and different Reynolds numbers are studied.

1 Introduction will be solved on rectangular, staggered grid. Then, solu- tion on non-staggered grid with vorticity-stream function The main problem is to solve two-dimensional Navier- form of NS equations will be shown. Stokes equations. I will consider two different mathemati- cal formulations of that problem:

¯ u,v,p primitive variables formulation 2 Math background

¯ ζ, ψ vorticity-stream function approach We will consider two-dimensional Navier-Stokes equations I will provide full solution with both of these methods. in non-dimensional form1: First we will consider three standard, primitive component formulations, where fundamental Navier-Stokes equation 1We consider flow without external forces i.e. without gravity. −→ Guess: Solve (3),(4) for: ∂ u −→ −→ 1 2−→ = −( u ∇) u − ∇ϕ + ∇ u (1) n n n n+1 n+1 ∂t Re (P*) ,(U*) ,(V*) (U*) ,(V*)

D = ∇−→u = 0 (2)

Where equation (2) is a continuity equation which has Solve (6) for: to be true for the final result. (P’)

3 Primitive variables formulation Calculate Visualization First we will examine SIMPLE algorithm which is ba- (U'),(V') - Appendix A sed on primitive variables formulation of NS equations. When we say ”primitive variables” we mean u,v,p where u = (u, v) is a vector, and p is . We can rewrite equation (1) in differential form for both velocity Un+1 =(U*)n+(U’) Pn+1 =(P*) n+(P’) components: Vn+1 =(V*) n+(V’)

∂u ∂u2 ∂uv ∂p 1 ∂2u ∂2v = − − − + ( + ) (3) Rysunek 1: SIMPLE Flow Diagram ∂t ∂x ∂y ∂x Re ∂x2 ∂y2

∂v ∂v2 ∂uv ∂p 1 ∂2u ∂2v 3.2 Numerical Methods in SIMPLE = − − − + ( + ) (4) ∂t ∂y ∂x ∂y Re ∂x2 ∂y2 3.2.1 Staggered Grid We rewrite continuity equation in the following form: For discretization of differential equations I am using stag- ∂u ∂v + = 0 (5) gered grid. In the figure (2) staggered grid for rectangular ∂x ∂y area is sketched. Primitive variables are placed in different These equations are to be solved with SIMPLE method. places. In points i, j on a grid pressure P values, in points i +0.5,j u x-velocity components and in points i, j +0.5 v y-velocity components are placed. That simple model of 3.1 SIMPLE algorithm staggered grid gives us possibility to use simple discreti- zation with second order accuracy which will be discussed SIMPLE algorithm is one of the fundamental algorithm to later. solve incompressible NS equations. SIMPLE means: Semi Implicit Method for Pressure Linked Equations. p u Algorithm used in my calculations is presented in the 0,0 0.5,0 figure (1). First we have to guess initial values of the pres- v0,0.5 v sure field2 (P ∗)n and set initial value of velocity field - i,j-0.5 (U ∗)n, (V ∗)n. Then equation (3) and (4) is solved to ob- u pi,j u tain values of (U ∗)n+1, (V ∗)n+1. Next we have to solve i-0.5,j i+0.5,j pressure-correction equation: vi,j+0.5 1 ∇2p′ = (∇ · V ) (6) ∆t Next - a simple relation to obtain corrected values of pressure and velocity fields is applied (see appendix A for details about velocity correction calculaion). At the end of time step we check if solution coverged. Rysunek 2: Staggered grid: filled circles P , outline circles U x-velocity, cross V y-velocity component. 2Subscripts denote computational step, where ”n+1” means cur- rent step.

2 Differential Discretization Type (v2)n − (v2)n (vu˙)n − (vu˙ )n ∂u un+1−un i,j+1.5 i,j−0.5 i+1,j+0.5 i−1,j+0.5 forward, O(h) b1 = − − ∂t ∆t 2 · ∆y 2 · ∆x (12)

2 n n n ∂ u ui+1,j −2∗ui,j +ui−1,j 2 u − 2 · u + u 2 2 central, O(h ) i+1.5,j i+0.5,j i−0.5,j ∂x (∆x) (a )= (13) 3 (∆x)2 n n n ui+0.5,j+1 − 2 · ui+0.5,j + ui+0.5,j−1 2 2 2 ∂u ui+1,j −ui−1,j 2 (a4)= 2 (14) ∂x (2·∆x) central, O(h ) (∆y) vn − 2 · vn + vn (b )= i,j+1.5 i,j+0.5 i,j−0.5 (15) 3 (∆y)2 ∂p pi+1,j −pi,j forward, O(h) ∂x (∆x) vn − 2 · vn + vn (b )= i+1,j+0.5 i,j+0.5 i−1,j+0.5 (16) 4 (∆x)2 ∂p pi,j+1 −pi,j forward, O(h) Now we have defined almost everything. Dotted velo- ∂y (∆y) cities should be also defined. I use simple expressions for it: Tabela 1: Discretizations used in SIMPLE algorithm u˙ =0.5 · (ui−0.5,j + ui−0.5,j+1) (17) 3.2.2 Discretization Schemes u˙ =0.5 · (ui+0.5,j + ui+0.5,j+1) (18) Let us now examine some numerical methods used in pre- sented solution. For algorithm presented in the figure (1) v˙ =0.5 · (v + v ) (19) we have only three equations which have to be discretized i,j+0.5 i+1,j+0.5 on a grid. First we have equations (3) and (4). Discrete schemes used in discretization of momentum v˙ =0.5 · (vi,j−0.5 + vi+1,j−0.5) (20) equations are presented in a table (1). Using presented discrete form of derivatives I obtain numerical scheme for 3.2.3 Poisson Equation momentum equations exactly in the form presented in [1]. Equations (3) , (4) discretized on staggered grid can be For equation I use simple iterative procedure. In the figure written3 as follows4: (3) points used for calculation of pressure at each (i, j) grid points are marked.

n+1 n −1 ui . ,j = ui+0.5,j + ∆t · (A − (∆x) (pi+1,j − pi,j )) (7) +0 5 Pi,j-1 n+1 n −1 vi,j+0.5 = vi,j+0.5 + ∆t · (B − (∆y) (pi,j+1 − pi,j )) (8) where A and B are defined as: Pi-1,j Pi,j Pi+1,j −1 A = −a1 + (Re) · (a3 + a4) (9)

P −1 i,j+1 B = −b1 + (Re) · (b3 + b4) (10) and respectively we define: Rysunek 3: Points on a grid used in iterative procedure for Poisson equation solving. (u2)n − (u2)n (uv˙)n − (uv˙)n a = − i+1.5,j i−0.5,j − i+0.5,j+1 i+0.5,j−1 1 2 · ∆x 2 · ∆y I use simple 4 points scheme for Laplace operator. Di- (11) rectly from [1] expression for one iterative step of poisson equation solver can be written as follows: 3Please note than cited [1] reference contains some print mistakes there. 4 Generally I show there only an idea how to write discretized equ- ′ −1 ′ ′ ′ ′ ations, they should be rewritten with ”*” and ”’” chars for concrete pi,j = −a (b · (pi+1,j + pi−1,j )+ c · (pi,j+1 + pi,j−1)+ d) steps of the algorithm (21)

3 where 4 Vorticity-Stream Function ap-

1 1 proach a = 2∆t 2 + 2 (22) ∆x ∆y  Vorticity-Stream Function approach to two-dimensional ∆t problem of solving Navier-Stokes equations is rather easy. b = − (23) ∆x2 A different form of equations can be scary at the beginning but, mathematically, we have only two variables which ha- ∆t ve to be obtained during computations: stream vorticity c = − 2 (24) ∆y vector ζ and stream function Ψ. 1 1 First let us provide some definition which will simplify d = [u − u ]+ [v − v ] (25) ∆x i+0.5,j i−0.5,j ∆y i,j+0.5 i,j−0.5 NS equation. The main goal of that is to remove explici- tly Pressure from N-S equations. We can do it with the That iterative procedure is rather simple - we use equ- procedure as follows. ation (21) for all interior points on a grid. After that one First let us define vorticity for 2D case: step of iterative procedure is done. Then we check if so- lution coverges. We can do it simply to check maximum ∂v ∂u ζ = |ζ| = |∇ × V | = − (26) change of pressure on a grid. If it is bigger than ǫ we conti- ∂x ∂y nue iterative process. Solution should finish when pressure field is exactly coverged ǫ = 0, but in practice I use diffe- And stream function definition is: rent value of ǫ for different physical properties of simulated ∂Ψ models - it will be discussed later. = u (27) ∂y ∂Ψ 3.3 SIMPLE Revised algorithm = −v (28) ∂x We can combine these definitions with equations (3) and Solve Momentum Guess (4). It will eliminate pressure from these momentum equ- eq. (without P) (U^) n, (V^) n (U^) n+1, (V^) n+1 ations. That combination will give us non-pressure vorti- city transport equation which in non-steady form can be written as follows:

Solve Poisson eq. 2 2 for (P n+1) using ∂ζ ∂ζ ∂ζ 1 ∂ ζ ∂ ζ Solve Poisson eq. + u + v = ( 2 + 2 ) (29) (U^) n+1 , (V^) n+1 ∂t ∂x ∂y Re ∂x ∂y for (P’) using If not coverged n+1 n+1 (U*) , (V*) Having combined equations (26), (27) and (28) we ob- tain poisson equation for the Ψ variable: Solve Momentum n+1 2 2 eq. (using P ) 2 ∂ Ψ ∂ Ψ (U*) n+1 , (V*) n+1 ∇ Ψ= 2 + 2 = −ζ (30) Un+1 = (U*) n + (U’) ∂x ∂y Vn+1 = (V*) n + (V’) Now we have all definitions and equations which are ne- If coverged eded for vorticity-stream solution. We will solve vorticity transport equation, then new values of ζ will be used to Visualize Results solve equation (30).

Rysunek 4: Flow chart for SIMPLER algorithm. 4.1 Non-Staggered Grid In the figure (4) I present SIMPLE Revised algorithm. Instead of using staggered grid in Vorticity-Stream appro- It is easy to extend existing SIMPLE solution to be SIM- ach, we will place both ζ and Ψ variables in the same place PLER one. as it is shown in the figure (5) Treating the boundary conditions and numerical me- Discretization is straightforward and easier to imple- thods used in SIMPLER solution is almost the same as in ment in a non-staggered grid than in a staggered grid for SIMPLE, so I will not repeat myself. the SIMPLE algorithm.

4 Set initial Solve Vorticity Transport eq.

Solve Poisson eq. for

If not coverged

Obtain U,V

Rysunek 5: ζ and Ψ variables in non staggered grid. If coverged

Differential Discretization Type Visualize Results ∂ζ ζn+1−ζn ∂t ∆t forward, O(h)

Rysunek 6: Algorithm of Vorticity-Stream solution. 2 ∂ ζ ζi+1,j −2∗ζi,j +ζi−1,j 2 ∂x2 (∆x)2 central, O(h ) 5 Two-dimensional Driven-Lid

∂ζ ζi+1,j −ζi−1,j 2 Cavity ∂x (2·∆x) central, O(h ) Let us now provide some examples of practical calculation 6 2 for implemented methods . I will show results of Driven- ∂ Ψ Ψi+1,j −2∗Ψi,j +Ψi−1,j 2 ∂x2 (∆y)2 central, O(h ) Lid Cavity flow - a standard CFD test case to check the solution.

Tabela 2: Discretizations used in Vorticity-Stream algori- u thm

4.2 Discretization We will use several schemes to discretize differential equ- ation (26). For Poisson equation we will use the same tech- nique which was presented in the SIMPLE algorithm de- scription, so we will not repeat formulas5.

4.3 Vorticity-Stream function algorithm Rysunek 7: Driven Cavity (lid moving with u constants Algorithm of solution for VS function solution is simplier velocity. than for SIMPLE method. It is sketched in the figure (6). First we have to set initial values for ζ and Ψ. I arbitrary Driven Cavity problem is sketched in the figure (7). Up- set these values to 0. Then Vorticity Transport Equation per lid is moving with u velocity. Main goal is to solve NS is solved and new ζn+1 values are obtained. After that equations inside the cavity to obtain velocity field (steady simple iterative procedure is applied to solve the poisson state). First of all we have to decide about boundary con- equation. Finally, new values of are easily found ditions for both: SIMPLE and VS approaches which will from (27) and (28) equation. be quite different.

5Formulas for poisson equation will be a little bit different but it 6In that section also boundary conditions will be provided, be- is rather easy to obtain it by simple discretization of equation (30). cause they are specified especially for the given problem.

5 5.1 Boundary Conditions - SIMPLE and 5.2 Boundary Conditions - Vorticity Stre- SIMPLER am

For SIMPLE(R) method we will use BC as follows: First In vorticity-stream formulation I use simple first order we have to clear pressure values for all boundaries. We use expressions for ζ derivatives at the wall. First, we have simple expression: to set Ψ = 0 at all boundaries. Then for NOSLIP boun- dary walls we use expression (i.e. for j = ny − 1 row): ∂p Ψ − Ψ = 0 (31) ζ =2.0 · i,0 i,1 (38) ∂n i,0 ∆y2 where n is normal to the wall. It means that for all i =0 ...NX − 1 points of a grid we apply:

pi,0 = pi,1 (32)

and

pi,ny−1 = pi,ny−2 (33)

We apply that procedure for upper and lower wall re- spectively7. Then we have to take care of velocities. We would like to apply NOSLIP boundaries for Driven Cavi- ty non-moving walls, so we have to zero values of velocities on every wall. First let us make trivial operation: for every j =0 ...NY − 1 set

v0,j = 0 (34)

and

vnx−1,j = 0 (35)

The same work should be done for u velocities, for i = 0 ...NX − 1 and for j = NY − 1. Especially for driven cavity problem we also have to set u velocity equal to 1.0 at j = 0 row, which is done in a straightforward way. One problem is to set boundary conditions at other walls, where no velocity grid points are present. We can do it with a simple linear interpolation of near velocities i.e. for u velocity, for every j =0 ...NY − 1 we set:

u0,j = −(2.0/3.0) · u1,j (36)

and

unx−2,j = −(2.0/3.0) · unx−3,j (37)

The same condition is used for other walls and v velocity components.

7 For corners simple diagonal values are taken, i.e. p0,0 = p1,1

6 6 Results

In that section some numerical results of calculations with three different techniques will be presented. Since results of calculations are the same I will try to show and compare differences between methods (accuracy, convergence speed). Please note that all comments are under figures.

6.1 Vorticity-Stream, Driven Cavity, Re = 500, Grid: 40x40

Rysunek 8: Streamlines plot for driven cavity with Re = 500 and 1 : 1 aspect ratio, grid size 40x40. Two are found in the corners of the Cavity, computed with the Vorticity-Stream approach. Solution visualized with Streamline plot technique.

7 6.2 Different Visualization Techniques, Driven Cavity, Re = 500, Grid: 40x40

Stream Vorticity Function Distribution Function Distribution

Stream Red - U velocity Function Contour Plot Green - V velocity

Rysunek 9: There are presented different types of visualizations generated by my solver. Computations as above - Re = 500 and other parameters are the same. (That is only a part of possibility visualizations, more will be available on my web page soon).

8 6.3 SIMPLE, SIMPLER, Driven Cavity, Re = 100, Grid: 21x21

40x40, Aspect Ratio 1:1

30x60, Aspect Ratio 1:2

40x60, Aspect Ratio 2:3

Rysunek 10: Streamlines plot for SIMPLE (and SIMPLER - because they are the same) calculation of driven cavity with Re = 100 and different grid sizes and aspect ratios.

6.4 Convergence for SIMPLE and Vorticity-Sream algorthms

9 1.5 SIMPLE

1.4

1.3

1.2

1.1 convergence

1

0.9

0.8 0 10000 20000 30000 40000 50000 60000 70000 time step

|vn+1| Rysunek 11: That figure shows how convergence changes during iteration steps. On y axis we have |vn| variable.

1.5 Vorticity-Stream

1.4

1.3

1.2

1.1 convergence

1

0.9

0.8 0 10000 20000 30000 40000 50000 60000 70000 time step

|vn+1| Rysunek 12: That figure shows how convergence changes during iteration steps. On y axis we have |vn| variable.

10 6.5 Convergence comparision

1 SIMPLE 0.9 SIMPLE Revised Vorticity-Stream 0.8

0.7

0.6

0.5

convergence 0.4

0.3

0.2

0.1

200 400 600 800 1000 1200 time step

Rysunek 13: Convergence test for three solution algorithms. A lot of problems appeared there. Convergence speed depends on a lot of things, so for different properties of calculation (Reynolds numbers, spatial grid resolution, poisson equation accuracy etc.) different results appears. That results computed for Re = 300 and grid 30x30 shows that Vorticity-Stream function solver converge faster than SIMPLER and SIMPLE. Anyway - more carefully study should be made there to make sure about that results. On the y axis we have |vn−1 − vn| convergence coefficient.

11 7 Calculation For Flows over Obstacles

In that section I present some calculations made to test my SIMPLE solver for problems other than Driven Cavities. There were some problems with boundary conditions and still more work is needed there, but fortunately results are really nice.

Rysunek 14: Flow of Incompressible fluid over set of holes. Calculation made for Re = 250 and grid size 60x40.

Rysunek 15: A -Karmann Street. Calculation made for Re = 400 and grid size 119x40.

More results and an application ”Hydrodynamica” for Windows operating system you can download free of a home page of an author.

12 8 Conclusion

I have developed three different methods for calculation of incompressible fluid flow. Tests for simple Driven Cavity problem were made. I compared convergence speed for all the methods and it seems that convergence speed depends on problem formulation and physical properties of simulated system. For future I will try to concern more on how to treat boundary conditions for both - pressure based and vorticity-stream function methods. Also some kind of user-friendly software will be released in near future. I would like to thank Grzegorz Juraszek for English language checking.

A Appendix A

To calculate primed velocity correction values we use approximate forms of the momentum equations:

∂u′ ∂p′ = − (39) ∂t ∂x ∂v′ ∂p′ = − (40) ∂t ∂y If we assume that velocity correction are zero at the previous time step, we can get straightforward expressions for velocity corrections at current time step:

1 ∂p′ u′ = − (41) ∆t ∂x 1 ∂p′ v′ = − (42) ∆t ∂y Then, those two equations are discretized and we obtain simple expressions for calculation of velocity corrections: 1 u′ = − (P ′ − P ′ ) (43) ∆t · ∆x i+1,j i,j 1 v′ = − (P ′ − P ′ ) (44) ∆t · ∆y i,j+1 i,j Literatura

[1] John D. Anderson, Jr. ’Computational Dynamics: The Basics with Applications’, McGraw-Hill Inc, 1995. [2] Ryszard Grybos, ’Podstawy mechaniki plynow’ (Tom 1 i 2), PWN 1998. [3] David Potter ’Metody obliczeniowe fizyki’, PWN 1982. [4] James D. Bozeman, Charles Dalton, ’Numerical Study of Viscous Flow in Cavity’, Journal of Computational Physics, vol. 12, 1973. [5] J.C. Tannehill, D.A. Anderson, ’Computational and Heat Transfer, Second Edition’, Series in Computational and Physical Processes in Mechanics and Thermal Sciences . [6] C.A.J. Fletcher, ’Computational Techniques for , Volume 2’, Springer . [7] F. H. Harlow, John P. Shannon, ’The Splash of Drop’, Journal of Applied Physics (vol. 38, n.10 Sept. 1967). [8] J. Welch, F. Harlow, J. Shannon, ’The MAC Method’, Los Alamos Scientific Laboratory of the University of California (1965). [9] N.Foster, D.Metaxas, ’Realistic Animation of ’, Center for Human Modeling and Simulation.

13