Answers to Exercises Computational Fluid Dynamics Exercise - Artificial diffusion upwind computations.9 k=. exact.8 k=..7 k=..6 k=..5.4.3.2...2.3.4.5.6.7.8.9 x For k =.,. and., and for N = 2, the discrete upwind solutions outside the boundary layer approach, the analytic solution for k =.25. Explanation: the effective viscosity of the upwind solution is given by and this approaches.25 when k. k eff = k + uh 2 = k + 4, upwind computations.9 k=.25 exact.8 k=..7 k=..6 k=..5.4.3.2...2.3.4.5.6.7.8.9 x
Exercise 2 - Various discretization methods.5 upwind.5 B3.5 smart upwind.5 QUICK N=2 k=. discrete exact central.5.5.5.5 upwind nonuniform.5 central nonuniform A.5 central nonuniform B.5.5.5.5.5.5 Solutions for k =..5 upwind.5 B3.5 smart upwind.5 QUICK N=2 k=. discrete exact central.5.5.5.5 upwind nonuniform.5 central nonuniform A.5 central nonuniform B.5.5.5.5.5.5 Solutions for k =. 2
Question 4: Stretched grid With Method B, the first time one of the eigenvalues of the coefficient matrix crosses the imaginary axis is for k.425. For a slightly smaller value of k, viz. k.342576, an eigenvalue passes through zero (within MATLAB accuracy) and the matrix becomes singular. Question 5: Monotonicity of λ-schemes The λ-schemes applied to our convection-diffusion equation yield a difference scheme given by λ h φ i 2 ( k h 2 + 6λ+ 2h )φ i +( 2k h 2 + 3λ h )φ i ( k h 2 + 2λ 2h )φ i+ = RHS. This scheme is of the type aφ i 2 +bφ i +cφ i +dφ i+ = RHS. The characteristic roots r of this equation satisfy dr 3 + cr 2 + br + a =. Since r = is a solution of this equation (why?), the factor r can be divided. There remains dr 2 +(c+d)r a =, where the coefficient of r, given by c+d k + 4λ+ h 2 2h, is always positive. The product of both roots is given by a/d, whereas their sum is given by (c + d)/d. With a always positive, it is observed that for d < both the sum and the product of the roots are positive, hence both roots are positive. But for d > the product is negative, hence one of the roots is negative. In the latter situation (d > ) with a negative root, oscillations are possible. More precise, when applied to the difference equation for the λ-scheme, oscillations can occur when d k h 2 + 2λ 2h <. For the B3 scheme, with λ = /2, this can never happen. For the QUICK scheme, with λ = /8, the oscillation boundary P = 8/3 results, where P is the mesh-péclet number. By determining the discrete solution for a number of values of k close to the boundary (for N = 2 it is given by k =.875), it is observed that also in practice this boundary separates the monotone QUICK solutions from the oscillating ones. Remark Note that the coefficient of φ i 2 is always positive. Hence the discretization will never lead to a positive operator, and the theory from Appendix A..3 is not applicable. Question 6: One interior grid point With one interior grid point located at x = 2k the discretization for Methods A becomes (φ + φ ) k ( 2k)φ + φ +2kφ k( 2k) =. and that of Method B ( 2k) 2 φ + +((2k) 2 ( 2k) 2 )φ (2k) 2 φ 2k( 2k) k ( 2k)φ + φ +2kφ k( 2k) =. 3
.5 upwind.5.5 smart upwind.5 N=2 k=.34258 discrete exact B3 QUICK central.5.5.5.5 upwind nonuniform.5 central nonuniform A.5 central nonuniform B.5.5.5.5.5.5 Solutions for k =.342576 With φ = and φ + =, the solution in the interior grid point becomes and Method A: φ =, Method B: φ = ( 2k)( 4k). 6k Forsmallk thelattervalueiscloseto. Theanalytical solution in x = 2k is given by.8.6.4.2 exact Lagrange symmetric φ = e( 2k)/k e /k,..2.3.4.5.6.7.8.9 which tends to e 2.35 for small k. Remark The studied problem is a slightly simplified version of the problem with which the QUICK method was introduced (B.P. Leonard: A stable and accurate convective modelling procedure based on quadratic upstream interpolation, Comp. Meth. Appl. Mech. Engng. 9, pp. 59 98, 979). In this paper the B3 method was not entered as a comparison. Many years later Leonard did make this comparison (Int. J. Num. Meth. Engng. 3, pp. 729 766, 99) and found, just like we did, that B3 is a serious competitor for QUICK. 4
Exercise 3 - JOR and SOR. Theoretically, Gauss Seidel converges twice as fast as Jacobi. uniform Jacobi method Gauss Seidel method grid convergent? # iterations convergent? # iterations upwind yes 26 yes central no no 2. Empirically obtained optimum and maximum values for the relaxation factor ω: uniform JOR method SOR method grid ω opt # it. ω max # it. ω opt # it. ω max # it. upwind. 26.3 4.9 6.999 5499 central.485 38.88 > 5.3452 26.3534 > 2 The relevant Jacobi eigenvalues are.52572 (upwind) and 4.6592i (central). 3. Stretched grids: Jacobi versus Gauss Seidel. stretched Jacobi method Gauss-Seidel method grid convergent? # iterations convergent? # iterations upwind yes 83 yes 4 central A no no central B no no Again, when converging, Gauss Seidel is twice as fast as Jacobi(upwind eigenvalue.898). The central methods are in trouble; observe the position of the eigenvalues with respect to the unit circle. Central A: 7.6843i; Central B: 7.6423i and.5. 4. Stretched grids with tuned relaxation factors: stretched JOR method SOR method grid ω opt # it. ω max # it. ω opt # it. ω max # it. upwind.983 79.57 238.382 5.999 2256 central A.247 73.333 >.2294 53.233 > central B.77 79.73 722 ) The iterations reach the convergence criterion, but will eventually diverge. Note that the upwind method and the central method A can be made convergent with suitably chosen relaxation factors. Central method B cannot be made convergent, because of the Jacobi eigenvalue.5. 5. The upwind matrix reads or with some scaling [ diag u h k u h 2, h + 2k h 2, k ] h 2, diag[ P, P +2, ], where P is the mesh-péclet number. The Jacobi matrix then becomes [ diag P + P +2,, ]. P +2 5
Its eigenvalues µ J,upw are given by µ J,upw = 2 iπ P + cos( ), i =,...,N, () P +2 N where N is the number of grid cells. These are obviously real for all P and satisfy µ J. As already given, for the central discretization the Jacobi eigenvalues are given by µ J,cent = 2 4 P 2 cos( iπ ), i =,...,N, (2) N 6. Let the eigenvalues of the Jacobi matrix be either real µ J = µ r or purely imaginary µ J = iµ I. In case of real eigenvalues the optimum and maximum relaxation factors for JOR and SOR are given by (derive these yourself), and JOR: ω JOR,opt =, ω JOR,max = 2 +µ R, (3) SOR: ω SOR,opt = 2, ω SOR,max = 2 (4) + µ 2 R (see Section A.3.2). For purely imaginary Jacobi eigenvalues, the optimum and maximum relaxation factors are given by JOR: ω JOR,opt = +µ 2, ω JOR,max = 2 I +µ 2, (5) I and respectively. SOR: ω SOR,opt = + 2, ω SOR,max = 2, (6) +µ 2 +µ I I 7. When k =. and N =, the mesh Péclet number is given by P =. On a uniform grid the Jacobi eigenvalues can be predicted theoretically. From () we find that the relevant Jacobi eigenvalue for upwind discretization becomes µ J,upw =.5257. Similarly, from (2), for central discretization the relevant Jacbi eigenvalue is µ J,cent = 4.6592. Now the optimum and maximum relaxation factors can be estimated with the formulas from Question 6: uniform equations JOR method SOR method grid for ω ω opt ω max ω opt ω max upwind (3), (4)..39.87 2. central (5), (6).44.88.3469.3534 Notice the excellent agreement with the findings from Question 2. 6
8. On a stretched grid, the Jacobi eigenvalues cannot be predicted theoretically. Instead we have to use the computed Jacobi eigenvalues found in Question 3 to produce estimates for optimum and maximum relaxation factors. As in the previous question, the optimum and maximum relaxation factors for JOR and SOR can be obtained from the above formulas. Note that for the Central A the numbers below are based on the largest imaginary eigenvalue, although also real eigenvalues exist which may interfere. Central B never converges because of the Jacobi eigenvalue.5. stretched equations JOR method SOR method grid for ω ω opt ω max ω opt ω max upwind (3), (4)..572.377 2. central A (5), (6).67.334.2286.233 central B 7
Exercise 4 - Time integration The discretization with the generalized Crank-Nicolson method with parameter ω reads: T n+ i Ti n ω d 2 (Tn+ i+ 2Tn+ i +Ti n+ ) ( ω)d 2 (Tn i+ 2Ti n +Ti ) n =, where d = 2δt/h 2. A positive operator results if and only if < d < /( ω). a) Explicit T.5 expliciet d = e+7 T 5e+6 expliciet d =.2 2 3 4 t -5e+6 -e+7 2 3 4 t For ω = the Fourier amplification factor is given by g(θ) = d( cos θ). Hence, the explicit method is Fourier stable if and only if d. For the chosen value of h this limit corresponds with δt =.5. This coincides with the limit of being a positive operator. b) Crank-Nicolson T.5 ω =.5 d = T.5 ω =.5 d = 2 3 4 t 2 3 4 t For general ω the amplification factor reads g(θ) = ( ω)d( cos θ), +ωd( cos θ) hence the method is stable if and only if d /( 2ω) in case ω < /2, and unconditionally stable when ω /2. As a particular case, the second-order Crank-Nicolson method is unconditionally stable. 8
For large time steps δt, hence large d, the amplification factor behaves as g(θ) (ω )/ω. For ω = /2 we have g(θ) as d. For a slightly larger value of ω the oscillations drastically decrease in amplitude, as shown below for ω =.6 and δt =.5 (d = ). T.5 ω =.6 d = 2 3 4 t c) Fully implicit T.5 ω =. d = T.5 ω =. d = 2 3 4 t 2 3 4 t Above it has been shown already that the fully implicit method (ω = ) is unconditionally stable. It always gives rise to a positive operator as the sign of all neighbouring coefficients is OK. An even easier way is to look at the sign of the amplification factor, which is positive for all frequencies θ, hence no wiggles can occur (these would require g < ). 9
Exercise 5 - Navier Stokes Part : Treatment of div u n Question exact solution TFin = 25, δt =.25 T=.25E+2 div=.6845e-6 -.98 -.255.56 t = 2.5e+ : streamfunction..2.3.4.5.6.7.8.9 Questions without div u n ) ε =, initial solution p = : a) TFin=25, δt =.25 T=.2E+2 div=.2544e+2.65 -.257.34755 T=.2E+2 div=.2724e+2 2.654.535.377 T=.22E+2 div=.2927e+2.74.3234.44 T=.23E+2 div=.2e+2.74.4475.446 T=.24E+2 div=.227e+2 2.758.5372.46994 T=.25E+2 div=.242e+2 2.754.627.495 TFin=, δt =.25 T=.953E+2 div=.9522e+2 2 -.59.9989.526 T=.964E+2 div=.955e+2 2 -.56.25.5959 T=.974E+2 div=.958e+2 2 -.496.49.585 T=.984E+2 div=.95e+2 2 -.486.62.5739 T=.994E+2 div=.9492e+2 2 -.479.782.5623 T=.E+3 div=.9484e+2 2 -.474.948.552 The magnitude of the divergence divu keeps changing linearly with time: divu n = divu εnδt divu εt. The solution is completely wrong.
t = 2.5e+ : streamfunction.2 t =.e+2 : streamfunction.8..6.8.4.6.2.4..2.8.6.4.2.2.4.6.2 b) δt =.25 T=.2E+2 div=.2547e+2 2.68 -.953.34392 T=.2E+2 div=.2692e+2 2.667.436.36397 T=.22E+2 div=.2867e+2 2.694.28.3935 T=.23E+2 div=.244e+2 2.722.3355.42277 T=.24E+2 div=.227e+2 2.734.44.4554 T=.25E+2 div=.2354e+2.728.525.4765 Note that the time step has hardly any influence on divu εt, independent of the time step. Also, the solution at 25 seconds does not change that much, although in time it is rapidly changing (compare the solution after 25 seconds with that after seconds). 2) ε = 3, initial solution p =. Tfin=25, δt =.25 T=.2E+2 div=.47469e+ -.85 -.9822.49768 T=.2E+2 div=.49685e+ -.86 -.985.49745 T=.22E+2 div=.5888e+ -.798 -.9787.49722 T=.23E+2 div=.5478e+ -.789 -.977.49698 T=.24E+2 div=.56256e+ -.78 -.9752.49674 T=.25E+2 div=.5842e+ -.772 -.9735.4965 The level of divu has dropped two orders of magnitude, proportional to the decrease in ε: divu n εt. The solution begins to look like the correct solution. t = 2.5e+ : streamfunction..2.3.4.5.6.7.8.9
3) ε = 3, initial solution p = pold δt =.25 T=.2E+2 div=.37338e- -.29 -.26.58 T=.2E+2 div=.3733e- -.29 -.26.58 T=.22E+2 div=.37329e- -.29 -.26.58 T=.23E+2 div=.37326e- -.29 -.26.58 T=.24E+2 div=.37326e- -.29 -.26.58 T=.25E+2 div=.37325e- -.29 -.26.58 The divergence divu is not yet really small. 4) ε =, initial solution p = pold δt =.25 T=.2E+2 div=.335e+ -.238 -.22422.555 T=.2E+2 div=.335e+ -.238 -.22423.556 T=.22E+2 div=.335e+ -.238 -.22423.556 T=.23E+2 div=.335e+ -.238 -.22423.556 T=.24E+2 div=.335e+ -.238 -.22423.556 T=.25E+2 div=.335e+ -.238 -.22423.556 With larger ε the solution becomes worse (as might be expected). Questions with div u n 5) ε =, initial solution p = a) δt =.25 T=.2E+2 div=.242e+ 3 -.967 -.986.59 T=.2E+2 div=.242e+ 3 -.967 -.986.59 T=.22E+2 div=.242e+ 3 -.967 -.986.59 T=.23E+2 div=.242e+ 3 -.967 -.986.59 T=.24E+2 div=.242e+ 3 -.967 -.986.59 T=.25E+2 div=.242e+ 3 -.967 -.986.59 b) δt =.25 T=.2E+2 div=.2242e- 3 -.979 -.229.545 T=.2E+2 div=.2242e- 3 -.979 -.23.545 T=.22E+2 div=.2242e- 3 -.979 -.23.545 T=.23E+2 div=.2242e- 3 -.979 -.23.545 T=.24E+2 div=.2242e- 3 -.979 -.23.545 T=.25E+2 div=.2242e- 3 -.979 -.23.545 The level of divu has dropped an order of magnitude, proportional to the decrease in δt: divu n εδt. 2
6) ε = 3, initial solution p = δt =.25 T=.2E+2 div=.6234e-3 -.98 -.254.56 T=.2E+2 div=.625e-3 -.98 -.254.56 T=.22E+2 div=.623e-3 -.98 -.254.56 T=.23E+2 div=.629e-3 -.98 -.254.56 T=.24E+2 div=.6234e-3 -.98 -.254.56 T=.25E+2 div=.6246e-3 -.98 -.254.56 The reduction of ε has led to a proportional reduction of divu. 7) ε = 3, initial solution p = pold δt =.25 T=.2E+2 div=.72e-5 -.98 -.254.56 T=.2E+2 div=.65e-5 -.98 -.254.56 T=.22E+2 div=.85228e-6 -.98 -.255.56 T=.23E+2 div=.9586e-6 -.98 -.255.56 T=.24E+2 div=.8889e-6 -.98 -.255.56 T=.25E+2 div=.59969e-6 -.98 -.255.56 The divergence becomes quite small (in fact machine accuracy). 8) ε =, initial solution p = pold δt =.25 T=.2E+2 div=.9433e-6 -.98 -.254.56 T=.2E+2 div=.7579e-6 -.98 -.254.56 T=.22E+2 div=.9626e-6 -.98 -.255.56 T=.23E+2 div=.785e-6 -.98 -.255.56 T=.24E+2 div=.69635e-6 -.98 -.255.56 T=.25E+2 div=.247e-5 -.98 -.255.56 Even at higher ε, the divergence divu is at a low level (in fact machine accuracy, hence the irregularities), because each time step at least one Poisson iteration is made (in fact: has to be made before convergence can be checked), although the convergence criterion has been met already. 9) By comparing Question and Question 8, we notice that even with a crude convergence criterion a good solution can be obtained, provided the term divu n is kept in the righthand side of the Poisson equation. 3
Part 2: Influence of boundary conditions Questions with prescribed outflow ) ν =..8.7.6 Y=.5 T=5 T= 5 T= 4 T= 3 T= 2 T=.5.4.3.2. 2 2 4 6 8 2 X Figure : Horizontal velocity along center line for ν =. at outflow condition u =. ) ν =.5.5.45.4.35 Y=.5 T=5 T= 5 T= 4 T= 3 T= 2 T=.3.25.2.5..5 2 2 4 6 8 2 X Figure 2: Horizontal velocity along center line for ν =.5 at outflow condition u =. 2) ν =...4.35.3 Y=.5 T=5 T= 5 T= 4 T= 3 T= 2 T=.25.2.5..5 2 2 4 6 8 2 X Figure 3: Horizontal velocity along center line for ν =. at outflow condition u =. 4
t =.5e+ : velocity.2 T= 4.9998 X= 9.532.2.8.6.8 Y.4.6.2.4.2.2.6.4.2.2.4.6.8.2.4 Figure 4: Left: Absolute velocity and velocity vectors for x [9, ]. Right: Horizontal velocity profile at x = 9.53 (i = 32). Questions with free outflow 3) ν =..5.45.4.35 Y=.5 T=5 T= 5 T= 4 T= 3 T= 2 T=.3.25.2.5..5 2 2 4 6 8 2 X Figure 5: Horizontal velocity at center line for ν =. with free outflow..2 T= 4.9998 X= 9.532.8.6 Y.4.2.2.5.5 Figure 6: Horizontal velocity profile at x = 9.53 (i = 32) for ν =.. It has a more or less parabolic shape. 5
4) ν =.5.5.45.4.35 Y=.5 T=5 T= 5 T= 4 T= 3 T= 2 T=.3.25.2.5..5 2 2 4 6 8 2 X Figure 7: Horizontal velocity at center line for ν =.5 with free outflow. 5) ν =..4.35.3 Y=.5 T=5 T= 5 T= 4 T= 3 T= 2 T=.25.2.5..5 2 2 4 6 8 2 X Figure 8: Horizontal velocity at center line for ν =. with free outflow..2 T= 4.9999 X= 9.532.8.6 Y.4.2.2.2.4.6.8.2.4 Figure 9: Horizontal velocity profile at x = 9.53 (i = 32) for ν =.. The profile does not really look like a parabola. 6
.45 T= 29.9997 Y=.5.5 T= 49.9995 Y=.5.4.45.35.4.3.25.2.5..5 5 5 5 2 25 X.35.3.25.2.5..5 2 3 4 5 6 X Figure : The at the center line for ν =. and a free outflow condition is prescribed, at channel length 2 (left) and 5 (right), respectively. t = 5.e+ : velocity.2 T= 5.7 X= 49.288.4.2.8.6 Y.8.4.6.2.4.2.2.5.5 Figure : Left: Absolute velocity and velocity vectors for x [49, 5]. Right: Horizontal velocity profile near exit. Viscosity ν =.; the parabola has developed now. Conclusion: Smaller viscosity requires more length for a flow to become fully developed. 7