ttp://www.d.edu/~gtryggva/cfd-course/ Outlie Solvig te Navier-Stokes Equatios i Primitive Variables Te projectio metod review Metods for te Navier-Stokes Equatios Moi ad Kim Bell, et al Colocated grids Boudary coditios Grétar Tryggvaso Sprig 011 u +1 i, j "u +1 = 0 Discretizatio i time Summary of discrete vector equatios = A i, j # + D i, j Costrait o velocity No explicit equatio for te pressure Evolutio of te velocity Split t u Discretizatio i time u +1 i, j = A i, j # + D i, j ito ad = A i, j + D i, j t # u +1 t u = # P u +1 t by itroducig te temporary velocity u t Projectio Metod + A i, j # ( + D i, j ) +1 t # "u +1 = 0 Discretizatio i time To derive a equatio for te pressure we take te divergece of ad use te mass coservatio equatio Te result is 0 "u +1 t = " # t " = 1 # u t i, j t u Discretizatio i time 1. Fid a temporary velocity usig te advectio ad te diffusio terms oly: ( + D i, j ) + t "A. Fid te pressure eeded to make te velocity field icompressible = 1 # u t i, j 3. Correct te velocity by addig te pressure gradiet: u +1 t = u #
Algoritm Iitial field give Determie u, v boudary coditios Poisso equatio for t=t+δt ( A ) Advect u + t i, j = ui, j + " t i, j Di, j P i, (iteratio) Projectio u +1 t = u # j Forward i time, cetered i space (summary): u * u p = 1 u* u +1 = u * p Time step limitatios = A ( u ) + # u t " # & t " 1 U 4 # were U = max(u + v ) Forward i time, cetered i space: t adv " # & t U diff " 1 4 # Defie = L U Terefore te odimesioal time step is: t' = t " # U U L = Re t' = t " # 1 U 4 L = 1 ( ad ' * Re 4 & L) Forward i time, cetered i space: Δt 0 for Re 0 ad Re Wat is te maximum timestep? t' = Re t' = 1 Δt " ' Re 4 # L& Icreasig Re t' max = ad t' max = 1 8 L L Ad Δt 0 for Re 0 ad Re 0 Re Advaced Solvers For low Re, use implicit metods for diffusio term For ig Re, use stable advectio scemes Combie bot for scemes iteded for all Re Fully Implicit u +1 u = 1 A(u ) + A(u +1 ) u +1 = 0 Solve by iteratio [ ( ) +# ( u + u +1 )] p Rarely used due to te complicatios of te oliear system tat must be solved for te advectio terms
Predictor-Corrector A secod order metod ca be developed by first takig a forward step, te a backward step ad average te results: u * u = #u u + # u # p * = 1 # u* u 1 = u * #p * Backward step usig te predicted velocity: u ** u 1 = #u 1 u 1 +# u 1 # p ** = 1 ** # u u = u ** #p ** Te average te results u +1 = 1 ( u + u ) Adam-Basford/Crak-Nicolso u +1 u # = 3 A(u ) 1 A(u1 ) & + ' ( u + ( u +1 ( ) u +1 = 0 Split: u u = # 3 A(u ) 1 A(u1 ) & + ' ( u +1 - u = (p + ' ( u +1 ( ) u +1 = 0 ( ) (p u p = 1 # u Te correctio equatio is implicit ad must be solved by a iteratio i te same way as te pressure equatio Metod of Kim ad Moi (JCP 59 (1985), 8-3) u u = # 3 A(u ) 1 A(u1 ) & + ' ( u + ( u u +1 u = () ( * u +1 = 0 " = 1 #t u ( ) Te first equatio is implicit ad must be solved by a iteratio i te same way as te pressure equatio Notice tat Φ is ot exactly p. Addig te first two equatios gives u +1 u # = 3 A(u ) 1 A(u1 ) & + ' ( u + ( u +1 Were we ave added ad subtracted a implicit diffusio term. Usig u +1 u = # we ca rewrite te last terms as: ( " u #" u +1 ) #" = " #" = "p ( ) + ' ( ( u ( u +1 ) () p Metod of Bell, Colella ad Glaz (JCP 85 (1989), 7-83) u +1 u u +1 = 0 = A(u +1/ ) + # ( u + u +1 ) p A Goduov metod is used for te advectio terms A complete Ruge-Kutta time itegratio (Weia E.) First a alf step: u * u 1 = #u u +# u # p * = # u * u 1 = u * #p * cotiue for te secod step: u ** u 1 = #u 1 u 1 +# u 1 # p ** = ** # u u = u ** ** #p
A complete Ruge-Kutta time itegratio (cotiued) Take a full step usig te predicted velocity Te compute Ad fially u *** u = #u u +# u # p *** = 1 *** # u u 3 = u *** #p *** k = t("#u 3 u 3 +# u 3 ) u + = 1 3 ( u + u 1 + u + u 3 ) + 1 k 6 " p + = 1 #t " u + u +1 = u + #t"p + Simplified Fourt order metod u * u 1 = #u u +# u u ** u * 1 = #u * u * +# u * u *** u = #u * u * +# u * ( ) + ( ) u + = 1 3 u + u * + u ** + u *** # p + = 1 # u+ u +1 = u + #p + 6 #u *** u *** +# u *** Colocated grids Colocated grids Altoug staggered grids ave bee very successful, i some cases it is desirable to use co-located (or colocated) grids were all variables are located at te same pysical poit. Staggered grids vi,j+1/ Colocated grids v * A(u i, j ) u +1 i, j = u * i, j (p e p w ) u +1 e u +1 w + v +1 v +1 s = 0 Split equatios for te u velocity ui-1/,j Pi,j vi,j-1/ ui+1/,j u w P i,j,u i,j,v i,j u e v s First idea: use averagig for te variables o te edges: p e = 1 ( p i+1, j + p i, j ) u e = 1 ( u i+1, j + ) All variables are stored at te same locatio +1 * +1 * # 1 p + i, j ( ) 1 ( p + p i, j i1, j ) ( p i1, j ) & ( '
Substitutig ito yields u e = 1 ( u i+1, j + ) ad u e +1 u w +1 + v +1 v s +1 = 0 u +1 * i, j p i +,j + p i, j + p i, j + + p i, j 4 p i, j = ( p i+1, j p i, j1 ) * * * * ( u i+1, j u i1, j + v i, j +1 v i, j1 ) A straigt forward applicatio discretizatio o colocated grids results i a very wide stecil for te pressure Te pressure poits are also ucoupled ad te pressure field ca develop oscillatios Te remedy is to fid te pressures tat make te edge velocities icompressible Te Rie ad Cow metod Istead of iterpolatig (te fial velocity) u +1 e = 1 u +1 +1 + ) Rie ad Cow. AIAA Joural. 1 (1983), 155-153. iterpolate (te itermediate velocity) u * e = 1 u * * + ) v u w P i,j,u i,j,v i,j u e ad te fid u +1 e = u * e ( p i, j ) I effect, preted we are usig a staggered grid v s Substitute ( ) u +1 e = u * e p i, j ito u e +1 u w +1 + v +1 v s +1 = 0 were givig # u e* ( p i, j ) & # u * w ( p i, j p i1, j ) & u * e = 1 u * * + ) # + v * p p ( i, j +1 i, j )& # v * s p p ( i, j i, j 1 )& = 0 Rearrage: + p i1, j + p i, j +1 + p i, j 1 4 p i, j = u * e u * w + v * * v s ( ) Substitutig for te velocities: + p i1, j + p i, j +1 + p i, j 1 4 p i, j = u * * * * u i1, j + v i, j +1 v i, j 1 ) For te correctio of te mometum equatio we still use te average of te pressures givig +1 * p e = 1 ( p i+1, j + p i, j ) ( p i+1, j p i1, j )
Te boudary coditios for te velocity are ow very simple: Te velocity at odes o te wall is simply te wall velocity. Te pressure boudary is more complex: Fid te pressure gradiet by applyig te Navier- Stokes equatios at a poit at te boudary # "v + u"v "x + v "v & "y ' = ("p "y + µ # " v + " v & ) "x "y ' At te wall, most of te terms are zero p y = µ v p i, = µ " v # y "y Evaluated by oe-sided differeces i, p i, = µ v v i, + v i,3 Defie: We ca write: p i, = µ v v i, + v i,3 p i, = v * ( ) = µt ( ) v * = t p " p i, v " v i, + v i,3 Write te pressure equatio for j= p i +1, + p i1, + p i,3 + p 4 p i, = Ad use p i, = v * For te pressure at j=1 * * * * ( u i +1, u i1, + v i,3 v ) i, Te algoritm is terefore: 1. First fid predicted velocities: A(u ) ad = v i, j A(v ) *. Fid pressure by solvig: + p i1, j + p i, j +1 + p i, j 1 4 p i, j = u * * * * u i1, j + v i, j +1 v i, j 1 ) suitably modified at te boudaries 3. Correct te velocities: +1 * ( ) ad p i+1, j p i1, j * v i, j v i, j +1 * = v i, j ( p i, j +1 p i. j1 ) projectio metod i primitive variables o a colocated mes x=19;y=19;dt=0.005;step=300;mu=0.1;maxit=0;beta=1.;=1/x; time=0; u=zeros(x,y);v=zeros(x,y);p=zeros(x,y); ut=zeros(x,y);vt=zeros(x,y); u(:x-1,y)=1.0; for is=1:step for i=:x-1,for j=:y-1 ut(i,j)=u(i,j)+dt*(-(0.5/)*(u(i,j)*(u(i+1,j)-u(i-1,j))+v(i,j)*(u(i,j+1)-u(i,j-1)))+(mu/^)*(u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1)-4*u(i,j))); vt(i,j)=v(i,j)+dt*(-(0.5/)*(u(i,j)*(v(i+1,j)-v(i-1,j))+v(i,j)*(v(i,j+1)-v(i,j-1)))+ (mu/^)*(v(i+1,j)+v(i-1,j)+v(i,j+1)+v(i,j-1)-4*v(i,j))); ed,ed vt(:x-1,1)=(mu*dt/^)*(v(:x-1,3)-*v(:x-1,)); vt(:x-1,y)=(mu*dt/^)*(v(:x-1,y-)-*v(:x-1,y-1)); ut(1,:y-1)=(mu*dt/^)*(u(3,:y-1)-*u(,:y-1)); ut(x,:y-1)=(mu*dt/^)*(u(x-,:y-1)-*u(x-1,:y-1)); for it=1:maxit solvig for pressure p(:x-1,1)=p(:x-1,)+(/dt)*vt(:x-1,1); p(:x-1,y)=p(:x-1,y-1)-(/dt)*vt(:x-1,y); p(1,:y-1)=p(,:y-1)+(/dt)*ut(1,:y-1); p(x,:y-1)=p(x-1,:y-1)-(/dt)*ut(x,:y-1); for i=:x-1,for j=:y-1 p(i,j)=beta*0.5*(p(i+1,j)+p(i-1,j)+p(i,j+1)+p(i,j-1)- (0.5*/dt)*(ut(i+1,j)-ut(i-1,j)+vt(i,j+1)-vt(i,j-1)))+(1-beta)*p(i,j); ed,ed p(floor(x/),floor(y/))=0.0; set te pressure i te ceter. Needed sice bc is ot icorporated ito eq ed u(:x-1,:y-1)=ut(:x-1,:y-1)-(0.5*dt/)*(p(3:x,:y-1)-p(1:x-,:y-1)); v(:x-1,:y-1)=vt(:x-1,:y-1)-(0.5*dt/)*(p(:x-1,3:y)-p(:x-1,1:y-)); time=time+dt old off,quiver(flipud(rot90(u)),flipud(rot90(v)),'r'); old o;axis([1 x 1 y]);axis square,pause(0.01) ed plot(*u(floor(y/),1:x)+floor(x/),1:x),old o; plot([1,x],[floor(y/),floor(y/)]),plot([floor(x/),floor(x/)],[1,y]) plot(*v(1:x,floor(y/))+floor(y/));axis square,axis([1,x, 1,y])
Colocated grids 18 16 14 1 Wy colocated grids: Sometimes simpler for body fitted grids Easy to use metods for yperbolic equatios Easier to implemet AMR Some people just do t like staggered grids 8 6 4 4 6 8 1 14 16 18 Boudary coditios Boudary coditios Iflow ad outflow Fully eclosed flow Drive cavity Iteral flow (iflow & outflow) Exteral flow Flow over bodies For fully eclosed domais, suc as i te drive cavity problem, te applicatio of te boudary coditios is relatively straigt forward. Te Backward Facig Step Problem For domais wit iflows it is usually reasoable to specify te velocity profile at te ilet Te major problem is ow to adle outflow boudaries i suc a way tat te fluid leaves i a pysically plausible way u = u(y) v = 0 Velocity give v u
u P v x+1,j u x,j P x,j u x+1,j v u P u u v x+,j v u v u(x+1,j)=u(x,j); v(x+,1:y+1)=v(x+1,1:y+1); Example For te pressure, obtai a equatio by applyig coservatio of mass to te cotrol volume ext to te boudary p(x,j)=(1/)*(p(x,j+1)+p(x,j-1)-(/dt)*(v(x+1,j+1)-v(x+1,j))); Simplified Backward Facig Step Problem 0 18 Velocity 16 u = u(y) v = 0 Velocity give v u Velocity gradiet give 14 1 8 6 4 0 0 5 15 0 5 30 35 Velocity+vorticity Pressure 18 16 0.5 14 0 1-0.5-1 8-1.5-6 4 -.5 40 30 0 5 15 0 5 30 0 0 0 5 15 Iflow
Periodic Boudary coditios I may cases it is possible to use periodic boudary coditios, were wat flows out troug oe boudary reappears flowig i troug te opposite boudary. Suc coditios are particularly suitable for teoretical studies of idealized flows. For suc boudaries it is easiest to specify te pressure drop, but by adjustig te pressure gradiet it is possible to specify te volume flux Exteral flow Free stream (uiform flow, for example) Free outflow Boudary of computatioal domai Oter ways to deal wit free-stream boudaries Iclude potetial flow perturbatio Compute flow from vorticity distributio Map te boudary at ifiity to a fiite distace Te two-dimesioal programs developed i te project ad sow ere ca be exteded to fully tree-dimesioal flows i a relatively straigt forward way, replacig u(i,j) by u(i,j,k), etc. Te time required to ru te code icreases sigificatly ad visualizig te output becomes more callegig. Fudametally, te specificatio of te boudary coditios does ot ave a uique solutio ad is also faced by experimetalists. However, by takig te boudaries far away ad ceckig te solutio for te effect of movig te boudaries, good results ca be obtaied