A Finite Difference Code for the Navier-Stokes Equations in Vorticity/Stream Function Formulation Instructor: Hong G

A Finite Difference Code for the Navier-Stokes Equations in Vorticity/Stream Function Formulation Instructor: Hong G

<p>WPI Computational <a href="/tags/Fluid/" rel="tag">Fluid</a> Dynamics I A Finite Difference Code for the Navier-Stokes Equations in Vorticity/<a href="/tags/Stream_function/" rel="tag">Stream Function</a> Formulation Instructor: Hong G. Im University of Michigan Fall 2001 Computational <a href="/tags/Fluid_dynamics/" rel="tag">Fluid Dynamics</a> I WPPII Objectives:</p><p>Develop an understanding of the steps involved in solving the Navier-Stokes equations using a numerical method</p><p>Write a simple code to solve the “driven cavity” problem using the Navier-Stokes equations in vorticity form Computational Fluid Dynamics I WPPII Outline</p><p>• The Driven Cavity Problem • The Navier-Stokes Equations in Vorticity/Stream Function form • Boundary Conditions • Finite Difference Approximations to the Derivatives • The Grid • Finite Difference Approximation of the Vorticity/Streamfunction equations • Finite Difference Approximation of the Boundary Conditions • Iterative Solution of the Elliptic Equation • The Code • Results • Convergence Under Grid Refinement WPIPI Computational Fluid Dynamics I WPI The Driven Cavity Problem</p><p>Moving wall</p><p>Stationary walls Computational Fluid Dynamics I WPPI∂I ∂Nondimensional N-S Equation ∂ ∂ Incompressible∂ N-S Equation ∂in 2-D ∂ ∂ u u u ρ1 ∂p ν  2u ∂ 2u  + u + v = − +  ∂ +   2 ∂ 2  ∂ t x y x  x y  ∂ Nondimensionalization∂ ∂ ~ 2 u~ = u /U∂, ~x = x / L, t = tU∂/ L, ~p = p / ρU ∂ ν ∂ 2 ~ ~ ~ 2 ~ 2 ~ ∂ 2 ~ U ∂ u ~ u ~ u  U ∂p U  u u   + u∂ + v  = − +  ∂ +  ∂ ~ ~ ∂ ~ ~ 2 ~ 2 ∂~ 2 L  t ∂x y  ∂ L x L  x y  ∂ ν ∂ u~ u~ u~ ∂~p 1  2u~ ∂ 2u~  + ~ + ~ = − +  ∂ +  ~ u v  2 2  t ~x ~y ~x ULRe  ~x ∂~y  WPI Computational Fluid Dynamics I The vorticity/stream function equations The <a href="/tags/Vorticity_equation/" rel="tag">Vorticity Equation</a> ∂ ∂u ∂u ∂u ∂p 1  ∂ 2u ∂ 2u − + u + v =− + + ∂y ∂t ∂x ∂y ∂x Re  ∂x2 ∂y2  </p><p>∂ ∂v ∂v ∂v ∂p 1  ∂ 2v ∂ 2v + u + v =− + + ∂x ∂t ∂x ∂y ∂y Re  ∂x2 ∂y2  </p><p>∂ω ∂ω ∂ω 1  ∂ 2ω ∂ 2ω  + u + v = + ∂t ∂x ∂y Re  ∂x2 ∂y2  ∂ ∂ ω = v − u ∂x ∂y WPI Computational Fluid Dynamics I The vorticity/stream function equations</p><p>The Stream Function Equation Define the stream function ∂ ψ ∂ ψ u = , v = − ∂y ∂x which automatically satisfies the incompressibility conditions ∂ u ∂ v ∂ + = 0 x ∂y by substituting ∂ ∂ψ ∂ ∂ψ − = 0 ∂x ∂y ∂y ∂x WPI Computational Fluid Dynamics I The vorticity/stream function equations</p><p>Substituting ∂ψ ∂ψ u = ; v =− ∂y ∂x</p><p> into the definition of the vorticity ∂ ∂ ω = v − u ∂x ∂y yields ∂ 2ψ ∂ 2ψ + =−ω ∂x2 ∂y2 WPI Computational Fluid Dynamics I The vorticity/stream function equations</p><p>The Navier-Stokes equations in vorticity-stream function form are: <a href="/tags/Advection/" rel="tag">Advection</a>/<a href="/tags/Diffusion/" rel="tag">diffusion</a> equation ∂ω ∂ψ ∂ω ∂ψ ∂ω  ∂ 2ω ∂ 2ω  =− + + 1  + ∂t ∂y ∂x ∂x ∂y Re  ∂x2 ∂y2  </p><p>Elliptic equation ∂ 2ψ ∂ 2ψ + =−ω ∂x2 ∂y2 WPI Computational Fluid Dynamics I Boundary Conditions for the Stream Function</p><p>At the right and the left boundary: ∂ψ u = 0 ⇒ = 0 ∂y ⇒ ψ = Constant WPI Computational Fluid Dynamics I Boundary Conditions for the Stream Function</p><p>At the top and the bottom boundary: ∂ψ v = 0 ⇒ = 0 ∂x ⇒ ψ = Constant WPI Computational Fluid Dynamics I Boundary Conditions for the Stream Function</p><p>Since the boundaries meet, the constant must be the same on all boundaries</p><p>ψ = Constant WPI Computational Fluid Dynamics I Boundary Conditions for the Vorticity</p><p>The normal <a href="/tags/Velocity/" rel="tag">velocity</a> is zero since the stream function is a constant on the wall, but the zero tangential velocity must be enforced: At the right and left boundary: At the bottom boundary: ∂ψ ∂ψ v = 0 ⇒ = 0 u = 0 ⇒ = 0 ∂x ∂y</p><p>At the top boundary: ∂ψ u = U ⇒ = U wall ∂y wall WPI Computational Fluid Dynamics I Boundary Conditions for the Vorticity</p><p>The wall vorticity must be found from the streamfunction. The stream function is constant on the walls. </p><p>At the right and the left boundary: ∂ 2ψ ∂ 2ψ ∂ 2ψ + =−ω ⇒ ω =− ∂x2 ∂y2 wall ∂x 2 Similarly, at the top and the bottom boundary: ∂ 2ψ ∂ 2ψ ∂ 2ψ ⇒ ω =− + =−ω wall 2 ∂x2 ∂y2 ∂y Computational Fluid Dynamics I WPI Summary of Boundary Conditions ∂ψ ∂ 2ψ = U ; ω =− ∂y wall wall ∂y2</p><p>∂ψ ∂ψ = 0 = ∂ 0 x ψ = ∂x 2 Constant ∂ ψ 2 ω =− ∂ ψ wall ω =− ∂ 2 wall x ∂x 2</p><p>∂ψ ∂ 2ψ = 0; ω =− ∂y wall ∂y2 WPI Computational Fluid Dynamics I Finite Difference Approximations</p><p>To compute an approximate solution numerically, the continuum equations must be discretized. There are a few different ways to do this, but we will use FINITE DIFFERENCE approximations here. Computational Fluid Dynamics I WPI Discretizing the Domain</p><p>Uniform mesh (h=constant)</p><p> j=NY ψ ω i, j and i , j Stored at each grid point</p><p> j=2 j=1 i=1 i=2 i=NX WPI Computational Fluid Dynamics I Finite Difference Approximations</p><p>When using FINITE DIFFERENCE approximations, the values of f are stored at discrete points and the derivatives of the function are approximated using a Taylor series:</p><p>Start by expressing the value of f(x+h) and f(x-h) in terms of f(x)</p><p> f(x-h) f(x) f(x+h)</p><p> hh WPI Computational Fluid Dynamics I Finite Difference Approximations ∂ Finite difference approximations ∂ ∂ + − − ∂ 3 2 f (x) = f (x h) f (x h) + f (x) h + ∂x 2h ∂x3 6 ! 2 + − + − ∂ 4 2 f (x) = f (x h) 2 f (h) f (x h) + f (x) h + x2 h2 ∂x4 12 ! ∂ +∆ − ∂ 2 ∆ f(t) = f(t t) f(t) + f(t) t + ∂t ∆t ∂t 2 2 ! "" 2nd order in space, 1st order in time WPI Computational Fluid Dynamics I Finite Difference Approximations</p><p>For a two-dimensional flow discretize the variables on a two-dimensional grid (x, y) j+1 = fi , j f (x,y) j = + fi +1, j f (x h, y) j-1 = + fi , j +1 f (x, y h) i -1 i i+1 WPI Computational Fluid Dynamics I Finite Difference Approximations</p><p>Laplacian</p><p>∂ 2 ∂ 2 f + f = ∂x2 ∂y2 f n − 2 f n + f n f n − 2 f n + f n i +1, j i, j i−1,j + i, j +1 i, j i , j −1 = h 2 h2 n + n + n + n − n fi +1, j fi −1,j fi, j +1 fi , j −1 4 fi , j h2 W∂ωPI Computational Fluid Dynamics I ∂ψFinite∂ω Difference Approximations ∂ ∂ψ ∂ ∂ω ∂ ∂ ∂ ω ∂ 1  2 ∂ ω2  = − + +  ∂ +  ω 2 ∂ 2 ω t y x x y Re  x y  Using these approximations, the vorticity equation becomes: ψn+1 − n i, j ψi, j = ω ∆t ω  n n  n n  ψ n n  n n  + − − + − − + ψ− − + − − −  i, jω1 i, j 1  i 1, j i 1, j  +  i 1, j i 1, j ω i, j 1 i, j 1   ω    ω   2h  ω2h   2h  2h  ω  n + n + n + n − 4ω n  + 1  i+1, j i−1, j i, j+1 i, j−1 i, j   2  Re  h  WPI Computational Fluid Dynamics I Finite Difference Approximations ω The vorticityω at theψ new time is given by: ψ ω ω  n − n  n − n  n+1 = ψn − ∆  i, j+1 i, j−1  i+1, j i−1, j  i, j i, j t ψ    2ωh 2h  ω   n n  n n  + − − + − − − i 1,ωj i 1, j  i, j 1 i, j 1   ω   2h  ω2h  ω  n + n + n + n − 4ω n  + 1  i+1, j i−1, j i, j+1 i, j−1 i, j   2  Re  h  WPI Computational Fluid Dynamics I Finite Difference Approximations</p><p>The stream function equation is:</p><p>∂ 2ψ ∂ 2ψ + =−ω ∂x2 ∂y2</p><p> n n n n n ψ + +ψ − +ψ + +ψ − − 4ψ i 1, j i 1, j i, j 1 i, j 1 i, j =−ω n h 2 i, j WPI Computational Fluid Dynamics I Discretized Domain</p><p>Discretize the domain j=ny ψ = i, j 0 for i =1 i = nx j =1 j = ny j=2 j=1 i=1 i=2 i=nx WPI Computational Fluid Dynamics I Discrete Boundary Condition</p><p> j=3</p><p> j=2 ω = ω j=1 wall i, j =1 Uwall i -1 i i+1 2 2 ∂ψ = ∂ ψ = h ψ =ψ + i, j 1 h + i , j 1 + O(h3 ) i, j = 2 i, j =1 ∂y ∂y2 2 WPI Computational Fluid Dynamics I Discrete Boundary Condition</p><p>2 2 ∂ψ = ∂ ψ = h ψ =ψ + i, j 1 h + i , j 1 + O(h3 ) i, j = 2 i, j =1 ∂y ∂y2 2 Using: ∂ 2ψ ∂ψ ω =− i, j =1 ; U = i, j =1 wall ∂y2 wall ∂y This becomes: h2 ψ =ψ + U h −ω + O(h 3) i, j = 2 i, j =1 wall wall 2 Solving for the wall vorticity: 2 2 ω = ()ψ = −ψ = +U +O(h) wall i , j 1 i , j 2 h 2 wall h WPI Computational Fluid Dynamics I Discrete Boundary Condition</p><p>At the bottom wall (j=1): 2 2 ω = ()ψ = −ψ = +U +O(h) wall i , j 1 i , j 2 h 2 wall h Similarly,ω at the top wall (j=ny): ψ ()2 2 = = −ψ = − −U + O(h) wall i, j ny i, j ny 1 h2 wall h At the left wall (i=1):</p><p>Fill the blank At the right wall (i=nx): Fill the blank WPI Computational Fluid Dynamics I Solving the Stream Function Equation</p><p>Solving the elliptic equation:</p><p>ψ n +ψ n +ψ n +ψ n − 4ψ n i +1, j i −1, j i, j +1 i, j −1 i, j =−ω n h 2 i, j Rewrite as ψ n+1 = ψ n +ψ n +ψ n +ψ n + 2ωn i, j 0.25 ( i +1, j i−1,j i, j +1 i, j −1 h i, j )</p><p> j+1 j j-1 i-1 ii+1 WPI Computational Fluid Dynamics I Solving the Stream Function Equation</p><p>If the grid points are done in order, half of the points have already been updated:</p><p> j+1 j j-1 i-1 ii+1</p><p>Successive Over Relaxation (SOR) ψ n+1 = β ψ n +ψ n +1 +ψ n +ψ n+1 + 2ω n i, j 0.25 ( i+1,j i−1,j i, j +1 i , j −1 h i , j ) + − β ψ n (1 ) i, j WPI Computational Fluid Dynamics I Time Step Control</p><p>Limitations on the time step</p><p>ν∆t 1 (|u | + | v |)∆t ≤ ≤ 2 h2 4 ν WPI Computational Fluid Dynamics I Solution Algorithm</p><p>Initial vorticity given for i=1:MaxIterations for i=2:nx-1; for j=2:ny-1 s(i,j)=SOR for the stream function Solve for the stream function end; end end Find vorticity on boundary v(i,j)=</p><p> for i=2:nx-1; for j=2:ny-1 Find RHS of vorticity equation rhs(i,j)=Advection+diffusion end; end Update vorticity in interior v(i,j)=v(i,j)+dt*rhs(i,j)</p><p> t=t+∆t WPI Computational Fluid Dynamics I MATLAB Code</p><p>1 clf;nx=9; ny=9; MaxStep=60; Visc=0.1; dt=0.02; % resolution & governing para meters 2 MaxIt=100; Beta=1.5; MaxErr=0.001; % para meters for SOR iteration 3 sf=zeros(nx,ny); vt=zeros(nx,ny); w=zeros(nx,ny); h=1.0/(nx-1); t=0.0; 4for istep=1:MaxStep, % start the time integration 5 for iter=1: M a xIt, % solve for the streamfunction 6 w=sf; % by SOR iteration 7 for i=2:nx-1; for j=2:ny-1 8 sf(i,j)=0.25* Beta*(sf(i+1,j)+sf(i-1,j)... 9 +sf(i,j+1)+sf(i,j-1)+h*h*vt(i,j))+(1.0-Beta)*sf(i,j); 10 end; end; 11 Err=0.0; for i=1:nx; for j=1:ny, Err=Err+abs(w(i,j)-sf(i,j)); end; end; 12 ifErr <= MaxErr, break, end % stop if iteration has converged 13 end; 14 vt(2:nx-1,1)=-2.0*sf(2:nx-1,2)/(h*h); % vorticity on botto m w all 15 vt(2:nx-1,ny)=-2.0*sf(2:nx-1,ny-1)/(h*h)-2.0/h; % vorticity on top wall 16 vt(1,2:ny-1)=-2.0*sf(2,2:ny-1)/(h*h); % vorticity on right wall 17 vt(nx,2:ny-1)=-2.0*sf(nx-1,2:ny-1)/(h*h); % vorticity on left wall 18 for i=2:nx-1; for j=2:n y-1 % compute 19 w(i,j)=-0.25*((sf(i,j+1)-sf(i,j-1))*(vt(i+1,j)-vt(i-1,j))... % the RHS 20 -(sf(i+1,j)-sf(i-1,j))*(vt(i,j+1)-vt(i,j-1)))/(h*h)... % of the 21 + Visc*(vt(i+1,j)+vt(i-1,j)+vt(i,j+1)+vt(i,j-1)-4.0*vt(i,j))/(h*h); % vorticity 22 end; end; % equation 23 vt(2:nx-1,2:ny-1)=vt(2:nx-1,2:ny-1)+dt* w(2:nx-1,2:ny-1); % update the vorticity 24 t=t+dt % print out t 25 subplot(121), contour(rot90(fliplr(vt))), axis('square'); % plot vorticity 26 subplot(122), contour(rot90(fliplr(sf))), axis('square');pause(0.01) % streamfunction 27 end; WPI Computational Fluid Dynamics I Solution Fields</p><p> nx=17, ny=17, dt = 0.005, Re = 10, Uwall = 1.0 WPI Computational Fluid Dynamics I Solution Fields</p><p> nx=17, ny=17, dt = 0.005, Re = 10, Uwall = 1.0 WPI Computational Fluid Dynamics I Accuracy by Resolution Stream Function at t = 1.2</p><p>9 × 9Grid 17 × 17 Grid 1 1</p><p> y 0.5 y 0.5</p><p>0 0 0 0.25 0.5 0.75 0 0.25 0.5 0.75 x x WPI Computational Fluid Dynamics I Accuracy by Resolution Vorticity at t = 1.2</p><p>9 × 9Grid 17 × 17 Grid 1 1 y y 0.5 0.5</p><p>0 0 0 0.25 0.5 0.75 0 0.25 0.5 0.75 x x WPI Computational Fluid Dynamics I Mini-Project</p><p>Mini-project:</p><p>Add the <a href="/tags/Temperature/" rel="tag">temperature</a> equation to the vorticity- streamfunction equation and compute the increase in heat transfer rate: WPI Computational Fluid Dynamics I <a href="/tags/Convection/" rel="tag">Convection</a></p><p>∂T ∂T ∂T ∂ 2T ∂ 2T + u + v = α + ∂t ∂x ∂y  ∂x2 ∂y2  where α = D ρ cp WPI Computational Fluid Dynamics I Natural convection</p><p>Natural convection in a closed cavity. The left vertical wall is heated.</p><p>0 WPI Computational Fluid Dynamics I Natural convection</p><p>Natural convection in a closed cavity. The left vertical wall is heated.</p><p>125 WPI Computational Fluid Dynamics I Natural convection</p><p>Natural convection in a closed cavity. The left vertical wall is heated.</p><p>250 WPI Computational Fluid Dynamics I Natural convection</p><p>Natural convection in a closed cavity. The left vertical wall is heated.</p><p>375 WPI Computational Fluid Dynamics I Natural convection</p><p>Natural convection in a closed cavity. The left vertical wall is heated.</p><p>500 WPI Computational Fluid Dynamics I Natural convection</p><p>Natural convection in a closed cavity. The left vertical wall is heated.</p><p>750 WPI Computational Fluid Dynamics I Natural convection</p><p>Natural convection in a closed cavity. The left vertical wall is heated.</p><p>1000 WPI Computational Fluid Dynamics I Natural convection</p><p>Heat Transfer Rate 0.2</p><p>0.15</p><p>0.1 Natural convection</p><p>0.05 Conduction only 0 200 400 600 800 1000</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    0 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us