lecture 1000

Upload: saad-al-hely

Post on 14-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Lecture 1000

    1/47

    Computational Fluid Dynamics IPPPPIIIIWWWW

    A Finite Difference Code

    for the Navier-StokesEquations in

    Vorticity/Stream Function

    FormulationInstructor: Hong G. Im

    University of Michigan

    Fall 2001

  • 7/27/2019 Lecture 1000

    2/47

    Computational Fluid Dynamics IPPPPIIIIWWWW

    Develop an understanding of the steps involved in

    solving the Navier-Stokes equations using a numerical

    method

    Write a simple code to solve the driven cavity

    problem using the Navier-Stokes equations in vorticity

    form

    Objectives:

  • 7/27/2019 Lecture 1000

    3/47

    Computational Fluid Dynamics IPPPPIIIIWWWW

    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

    Outline

  • 7/27/2019 Lecture 1000

    4/47

    Computational Fluid Dynamics IPPPPIIIIWWWW

    Moving wall

    Stationarywalls

    The Driven Cavity Problem

  • 7/27/2019 Lecture 1000

    5/47

    Computational Fluid Dynamics IPPPPIIIIWWWW

    ++=++ 2

    2

    2

    21

    y

    u

    x

    u

    x

    p

    y

    u

    vx

    u

    ut

    u

    Nondimensional N-S Equation

    Incompressible N-S Equation in 2-D

    Nondimensionalization

    ,/~ Uuu = ,/~ Lxx = 2/~ Upp =,/~ LtUt =

    ++=

    ++

    2

    2

    2

    2

    2

    22

    ~

    ~

    ~

    ~

    ~

    ~

    ~

    ~~

    ~

    ~~

    ~

    ~

    y

    u

    x

    u

    L

    U

    x

    p

    L

    U

    y

    uv

    x

    uu

    t

    u

    L

    U

    ++=++ 2

    2

    2

    2

    ~

    ~

    ~

    ~

    ~

    ~

    ~

    ~~

    ~

    ~~

    ~

    ~

    y

    u

    x

    u

    ULx

    p

    y

    uv

    x

    uu

    t

    u

    Re

    1

  • 7/27/2019 Lecture 1000

    6/47

    Computational Fluid Dynamics IPIW

    u

    t + uu

    x + vu

    y = p

    x +1

    Re

    2u

    x2 +2u

    y2

    v

    t + uv

    x + vv

    y = p

    y +1

    Re

    2v

    x2 +2v

    y2

    y

    x

    t

    + u x

    + v y

    = 1Re

    2

    x

    2 + 2

    y

    2

    = vx uy

    The vorticity/stream function equations

    The Vorticity Equation

  • 7/27/2019 Lecture 1000

    7/47

    Computational Fluid Dynamics IPIW

    0=+

    y

    v

    x

    u

    xv

    yu

    == ,

    which automatically satisfies the incompressibility conditions

    Define the stream function

    x

    y

    y

    x =0

    by substituting

    The vorticity/stream function equations

    The Stream Function Equation

  • 7/27/2019 Lecture 1000

    8/47

    Computational Fluid Dynamics IPIW

    2

    x2 +

    2

    y2 =

    =v

    x

    u

    y

    u = y

    ; v = x

    Substituting

    into the definition of the vorticity

    yields

    The vorticity/stream function equations

  • 7/27/2019 Lecture 1000

    9/47

    Computational Fluid Dynamics IPIW

    t

    = y

    x

    + x

    y

    + 1Re

    2

    x

    2 + 2

    y

    2

    2

    x2 +

    2

    y2 =

    The Navier-Stokes equations in vorticity-stream

    function form are:

    Elliptic equation

    Advection/diffusion equation

    The vorticity/stream function equations

  • 7/27/2019 Lecture 1000

    10/47

  • 7/27/2019 Lecture 1000

    11/47

    Computational Fluid Dynamics IPIW

    v = 0

    x = 0

    = Constant

    At the top and the

    bottom boundary:

    Boundary Conditions for the Stream Function

  • 7/27/2019 Lecture 1000

    12/47

  • 7/27/2019 Lecture 1000

    13/47

    Computational Fluid Dynamics IPIWBoundary Conditions for the Vorticity

    At the right and left boundary:

    At the top boundary:

    The normal velocity is zero since the stream function

    is a constant on the wall, but the zero tangential

    velocity must be enforced:

    v = 0 x

    = 0 u = 0 y

    = 0

    At the bottom boundary:

    wallwall Uy

    Uu =

    =

    PIW

  • 7/27/2019 Lecture 1000

    14/47

    Computational Fluid Dynamics IPIW

    At the right and the left boundary:

    Similarly, at the top and the bottom boundary:

    wall = 2

    x 2

    wall = 2

    y2

    The wall vorticity must be found from the streamfunction.

    The stream function is constant on the walls.

    2

    x2

    + 2

    y2

    =

    2

    x2+

    2

    y2=

    Boundary Conditions for the Vorticity

    PIW

  • 7/27/2019 Lecture 1000

    15/47

    Computational Fluid Dynamics IPIW

    y= Uwall; wall =

    2

    y2

    y

    = 0; wall = 2

    y2

    x = 0

    wall

    = 2

    x2

    Summary of Boundary Conditions

    = Constant

    x= 0

    wall =

    2

    x2

    PIW

  • 7/27/2019 Lecture 1000

    16/47

    Computational Fluid Dynamics IPIWFinite Difference Approximations

    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.

    PIW

  • 7/27/2019 Lecture 1000

    17/47

    Computational Fluid Dynamics IPIW

    i=1 i=2 i=NX

    j=1j=2

    j=NY

    i,j

    and i ,j

    Stored ateach grid

    point

    Discretizing the Domain

    Uniform mesh (h=constant)

    PIW

  • 7/27/2019 Lecture 1000

    18/47

    Computational Fluid Dynamics IPIW

    When using FINITE DIFFERENCE approximations,

    the values offare stored at discrete points and thederivatives of the function are approximated using a

    Taylor series:

    Start by expressing the value off(x+h) andf(x-h)

    in terms off(x)

    Finite Difference Approximations

    h h

    f(x-h) f(x) f(x+h)

    PIW

  • 7/27/2019 Lecture 1000

    19/47

    Computational Fluid Dynamics IPIW

    !+++=6

    )(

    2

    )()()( 2

    3

    3 h

    x

    xf

    h

    hxfhxf

    x

    xf

    Finite difference approximations

    Finite Difference Approximations

    !++++=12

    )()()(2)()( 2

    4

    4

    22

    2 h

    x

    xf

    h

    hxfhfhxf

    x

    xf

    ""

    f(t)t

    = f(t+ t) f(t)t

    + 2f(t)

    t2t2

    +!

    2nd order in space, 1st order in time

  • 7/27/2019 Lecture 1000

    20/47

    C t ti l Fl id D i IPIW

  • 7/27/2019 Lecture 1000

    21/47

    Computational Fluid Dynamics IPIWFinite Difference Approximations

    Laplacian

    2f

    x2+

    2f

    y2=

    fi +1, jn 2 fi,jn + fi1,jn

    h2

    + fi,j +1n 2fi,jn + fi ,j 1n

    h2

    =

    fi +1, jn + fi 1,jn + fi, j +1n + fi ,j 1n 4fi ,jnh2

    C t ti l Fl id D i IPIW

  • 7/27/2019 Lecture 1000

    22/47

    Computational Fluid Dynamics IPIW

    ++++

    +

    =

    ++

    ++++

    +

    2,1,1,,1,1

    1,1,,1,1,1,11,1,

    ,1

    ,

    4Re1

    2222

    h

    hhhh

    t

    n

    ji

    n

    ji

    n

    ji

    n

    ji

    n

    ji

    n

    ji

    n

    ji

    n

    ji

    n

    ji

    n

    ji

    n

    ji

    n

    ji

    n

    ji

    nji

    nji

    Using these approximations, the vorticity equation becomes:

    Finite Difference Approximations

    +++= 22

    2

    2

    Re

    1

    yxyxxyt

    C t ti l Fl id D i IPIW

  • 7/27/2019 Lecture 1000

    23/47

    Computational Fluid Dynamics IPIW

    ++++

    =

    ++

    ++

    +++

    2

    ,1,1,,1,1

    1,1,,1,1

    ,1,11,1,

    ,

    1

    ,

    4

    Re

    1

    22

    22

    h

    hh

    hht

    nji

    nji

    nji

    nji

    nji

    nji

    nji

    nji

    nji

    nji

    nji

    nji

    njin

    ji

    n

    ji

    The vorticity at the new time is given by:

    Finite Difference Approximations

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    24/47

    Computational Fluid Dynamics IPIW

    i +1,jn + i 1,jn + i,j +1n + i,j 1n 4i,jn

    h2

    = i,j

    n

    The stream function equation is:

    2

    x2

    +2

    y2

    =

    Finite Difference Approximations

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    25/47

    Computational Fluid Dynamics IPIW

    Discretize the domain

    i,j = 0

    i=1 i=2 i=nxj=1

    j=2

    j=ny

    i =1i = nx

    j =1j = ny

    Discretized Domain

    for

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    26/47

    Computational Fluid Dynamics IPIW

    i -1 i i+1

    Discrete Boundary Condition

    j=3

    j=2

    j=1

    i,j = 2 = i,j =1 +i,j =1

    yh + i ,j =1

    y2

    h2

    2+ O(h3 )

    wall = i,j =1Uwall

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    27/47

    Computational Fluid Dynamics IPIW

    i,j = 2 = i,j =1 +U

    wallh

    wallh2

    2 +O(h3)

    wall = i ,j =1 i ,j =2( )2

    h2 +Uwall

    2

    h +O(h)

    wall =

    i,j =1

    y2 ; Uwall =

    i,j =1

    y

    Solving for the wall vorticity:

    Using:

    This becomes:

    Discrete Boundary Condition

    i,j=2 = i,j

    =1 +

    i,j =1

    yh +

    i ,j =1

    y2

    h2

    2+ O(h3 )

  • 7/27/2019 Lecture 1000

    28/47

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    29/47

    Computational Fluid Dynamics IPIW

    i,jn+1 = 0.25 (i +1,j

    n + i1,jn + i,j +1

    n + i,j 1n + h2i,j

    n)

    i +1,jn + i 1,j

    n + i,j +1n + i,j 1

    n 4i,jn

    h2=

    i,j

    n

    Solving the elliptic equation:

    Rewrite as

    j

    j-1

    j+1

    i i+1i-1

    Solving the Stream Function Equation

  • 7/27/2019 Lecture 1000

    30/47

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    31/47

    Computational Fluid Dynamics IPIW

    Limitations on the time step

    th2

    1

    4

    (|u | + | v |)t 2

    Time Step Control

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    32/47

    Computational Fluid Dynamics IPIW

    for i=1:MaxIterations

    for i=2:nx-1; for j=2:ny-1s(i,j)=SOR for the stream function

    end; end

    end

    for i=2:nx-1; for j=2:ny-1

    rhs(i,j)=Advection+diffusion

    end; end

    Solution Algorithm

    Solve for the stream function

    Find vorticity on boundary

    Find RHS of vorticity equation

    Initial vorticity given

    t=t+t

    Update vorticity in interior

    v(i,j)=

    v(i,j)=v(i,j)+dt*rhs(i,j)

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    33/47

    p yPIW

    1 clf;nx=9; ny=9; MaxStep=60; Visc=0.1; dt=0.02; % resolution & governing parameters

    2 MaxIt=100; Beta=1.5; MaxErr=0.001; % parameters for SOR iteration

    3 sf=zeros(nx,ny); vt=zeros(nx,ny); w=zeros(nx,ny); h=1.0/(nx-1); t=0.0;

    4foristep=1:MaxStep, % start the time integration

    5 foriter=1:MaxIt, % solve for the streamfunction6 w=sf; % by SOR iteration

    7 fori=2:nx-1;forj=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;fori=1:nx;forj=1:ny, Err=Err+abs(w(i,j)-sf(i,j));end; end;

    12 ifErr

  • 7/27/2019 Lecture 1000

    34/47

    p yPIW

    nx=17, ny=17, dt = 0.005, Re = 10, Uwall = 1.0

    Solution Fields

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    35/47

    p yPIW

    nx=17, ny=17, dt = 0.005, Re = 10, Uwall = 1.0

    Solution Fields

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    36/47

    p yPIW

    Stream Function at t = 1.2

    Accuracy by Resolution

    x

    y

    0 0.25 0.5 0.750

    0.5

    1

    9 9 Grid

    x

    y

    0 0.25 0.5 0.750

    0.5

    1

    17 17 Grid

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    37/47

    PIW

    Vorticity at t = 1.2

    Accuracy by Resolution

    x

    y

    0 0.25 0.5 0.750

    0.5

    1

    9 9 Grid

    x

    y

    0 0.25 0.5 0.750

    0.5

    1

    17 17 Grid

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    38/47

    PIWMini-Project

    Add the temperature equation to the vorticity-

    streamfunction equation and compute the

    increase in heat transfer rate:

    Mini-project:

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    39/47

    PIWConvection

    T

    t + uT

    x + vT

    y = 2T

    x2 +

    2T

    y2

    = Dcp

    where

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    40/47

    PIWNatural convection

    Natural convection in a

    closed cavity. The left

    vertical wall is heated.

    0

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    41/47

    PIWNatural convection

    Natural convection in a

    closed cavity. The left

    vertical wall is heated.

    125

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    42/47

    Natural convection

    Natural convection in a

    closed cavity. The left

    vertical wall is heated.

    250

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    43/47

    Natural convection

    Natural convection in a

    closed cavity. The left

    vertical wall is heated.

    375

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    44/47

    Natural convection

    Natural convection in a

    closed cavity. The left

    vertical wall is heated.

    500

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    45/47

    Natural convection

    Natural convection in a

    closed cavity. The left

    vertical wall is heated.

    750

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    46/47

    Natural convection

    Natural convection in a

    closed cavity. The left

    vertical wall is heated.

    1000

    Computational Fluid Dynamics IPIW

  • 7/27/2019 Lecture 1000

    47/47

    200 400 600 800 10000

    0.05

    0.1

    0.15

    0.2

    Natural convection

    Heat Transfer Rate

    Conduction only

    Natural convection