ECP1 Software Manual

Embed Size (px)

Citation preview

  • 7/30/2019 ECP1 Software Manual

    1/30

    V. ZALIZNIAK

    ESSENTIALS OF COMPUTATIONAL PHYSICS

    Part 1: An Introduction to finite-difference methods

    The manual contains a short description of programs accompanying this text. These programs can be used inComputational physics and Numerical methods courses as well as in students research projects. Additionalinformation on how to use the accompanying programs can be found in examples. Although great care is takento eliminate all program errors, the author does not take any responsibility for the consequences of application ofthese programs.

    This manual consists of two parts: A short description of mathematical models and finite-difference schemesand A short description of MATLAB functions.

    V. Zalizniak, 2005

  • 7/30/2019 ECP1 Software Manual

    2/30

    2

    A short description of mathematical models and finite-difference schemes

    Heat transfer

    One-dimensional heat transfer (uniform medim).

    Equation:2

    2, 0 , 0

    u ut T x l

    t x

    =

    ,

    where u temperature, =a/c - thermal diffusion coefficient, a thermal conductivity coefficient, c specific

    heat, - density.

    Initial conditions: u(x,0)=g(x).

    Bundary conditions:

    or1(0, ) ( )u t f t = 1(0, ) ( )u

    a t fx

    =

    t ,

    or2( , ) ( )u l t f t = 2( , ) ( )

    u

    a l t f t x

    = .

    Finite-difference scheme:

    1 1 111 1 1

    2

    2 2(1 )

    0 1, 0,1,...; 1,..., 1

    k k k k k kk knn n n n n n u u u u u uu u

    h

    k n N

    + + ++

    + + + + = +

    = =

    12

    n

    h , (1)

    One-dimensional heat transfer (nonuniform medim).

    Equation:

    ( ) ( ) ( ) , 0 , 0u u

    x c x a x t T x l t x x

    = .

    Initial conditions: u(x,0)=g(x).

    Bundary conditions:

    or1(0, ) ( )u t f t = 1(0, ) ( )u

    a t fx

    =

    t ,

    or2( , ) ( )u l t f t = 2( , ) ( )u

    a l t f t x

    =

    .

    Finite-difference scheme:

  • 7/30/2019 ECP1 Software Manual

    3/30

    3

    1 1 1 111 1

    1/2 1/22 2

    1 11/2 1/22 2

    ( )

    (1 )

    k k k kk kn nnn n n

    n n n

    k k k kn n n n

    n n

    u u u uu uc a a

    h h

    u u u ua a

    h h

    + + + +++

    +

    + +

    = +

    (2)

    Nonlinear equation:

    ( )( ) ( ) ( ) ,

    0 , 0

    uu c u u a u

    t x

    t T x l

    =

    x

    Finite-difference scheme:

    1 1 1 111 1

    1/2 1/22

    k k k kk kn nnn nk k k k n

    n n n nk

    u u u uu uc a a

    h h

    + + + +++

    +

    =

    2, (3)

    where

    ( )1 11/2 2

    ( )

    ( )

    ( )

    k kn n

    k kn n

    k kn nn

    u

    c c u

    a a u u

    ++

    =

    =

    = +k

    .

    Two-dimensional heat transfer (uniform medim).

    Equation:2 2

    2 2( , , ) ,

    0 , 0 , 0

    s

    x y

    u u uf x y t

    t x y

    t T x l y l

    = + +

    The explicit splitting-up scheme:

    , ,, ( , , ),

    1,..., 1; ,...,

    kn m n m k

    x n m s n m k

    s e

    v uu f x y t

    n N m m m

    = +

    = =

    (4)1

    , ,, ,

    ,..., ; 1,..., 1

    kn m n m

    y n m

    s e

    u vv

    n n n m M

    + =

    = =

    where

    ( )

    ( )

    , 1, ,2

    , , 1 , ,2

    12

    12

    k k k k x n m n m n m n m

    k k k k y n m n m n m n m

    u u u u h

    u u u u h

    +

    +

    = +

    = +

    1,

    1

    .

    Papameters ns, ne, ms, medepend on boundary conditions:

    ,1 , 1 0

    0 , 2 0s

    boundary conditions of the st kindat xn

    boundary conditions of the nd kind at x

    ==

    =

  • 7/30/2019 ECP1 Software Manual

    4/30

    4

    1 , 1

    , 2

    x

    ex

    N boundary conditions of the st kindat x ln

    N boundary conditions of the nd kindat x l

    == =

    ,1 , 1 0

    0 , 2 0sboundary conditions of the st kindat y

    mboundary conditions of the nd kindat y

    == =

    .1 , 1

    , 2

    y

    ey

    M boundary conditions of the st kindat y lm

    M boundary conditions of the nd kindat y l

    == =

    One-dimensional heat transfer with phase transition (Stefan problem)

    Equation:

    ( , ) , 0 , 0H u

    a x t x l t t x x

    = >

    ,

    ,( )

    ( ) ,

    s p

    l l s p

    c u u u H u

    c u c c u L u u

  • 7/30/2019 ECP1 Software Manual

    5/30

    5

    Propagation of acoustic waves

    Second order differential equation:2 2

    22 2

    , 0 , 0u u

    c x l t t x

    =

    T,

    where u velocity or pressure andc speed of sound.

    Initial conditions: 1 2( , 0) ( ) , ( , 0) ( )u

    u x g x x g x t

    = =

    ,

    Boundary conditions:

    1 2(0, ) (0, ) ( )uu t t f t x + =

    1,

    3 4( , ) ( , ) ( )u

    u l t l t f t x

    + = 2

    .

    Finite difference scheme cross:

    1 11 12

    2

    22

    1 , ..., 1 , 2 , 3 , ...

    k k kk k kn n nn n n u u uu u u c

    hn N k

    + + + +

    =

    = =

    2 , (6)

    System of differential equations:

    , 0 , 0x l t T t x

    + =

    s s

    A o ,

    where

    , , u

    p =

    s2

    0 1/

    0c

    = A

    0

    0

    = o

    u velocity, p pressure, - density andc speed of sound.

    Initial conditions: ,1 2( , 0) ( ) , ( , 0) ( )u x g x p x g x = =

    Boundary conditions:

    ,1 2(0, ) (0, ) ( )u t p t f t + = 1

    2 .3 4( , ) ( , ) ( )u l t p l t f t + =

    Lax-Wendroff scheme:

    ( ) ( ) ( )2

    1 21 1 1

    12

    2 21 , ... , 1

    k k k k k k k n n n n n n n h h

    n N

    +

    + + = + +

    =

    s s A s s A s s s 1, (7)

    or in expanded form

    ( ) ( )1 21 1 11

    22 2

    k k k k k k k n n n n n n n

    ru u p p r u u u

    c+

    + + = + + 1 ,

    ( ) ( )1 21 1 11

    22 2

    1 , ... , 1

    k k k k k k k n n n n n n n

    rcp p u u r p p p

    n N

    +

    + + = + +

    =

    1.

    Nondissipative scheme of P. Roe [2]:

  • 7/30/2019 ECP1 Software Manual

    6/30

    6

    1 1

    1 1 11 02

    k k k k k k n n n n n n R R R R R Rc

    h

    + + +

    = ,

    111 1 11 0

    2

    k k k k k kn n n n n n S S S S S S c

    h

    ++ + +

    + =

    , (8)

    1 , ... , 1n N=

    , ,k k knn nR p c u = + k k kn n nS p c u =

    = 0.5( )k k kn n nS= +, p R .0.5( )/k k kn n nu R S c

    Godunov scheme:

    ( )11/2 1/2 3/2 1/2

    3/2 1/2 1/222 2

    k k k k n n n n k k k

    n n n

    u u p p cu u u

    h h

    +

    + + + + +

    = + + ,

    (9)

    ( )11/2 1/2 3/2 1/22

    3/2 1/2 1/222 21,..., 2 ; 0,1,...

    k k k k n n n n k k k

    n n n

    p p u u cc p p

    h hn N k

    +

    + + + + +

    = + +

    = =

    p.

    PEM scheme [4]:

    1 11 1

    1 11/2 1/2 1

    ( ) ( )1

    ( ) ( )

    k kk k nn

    k kn n nn

    u u f u f p p h

    u

    f p f p

    + ++ +

    + +

    + + +

    = A

    , (10)

    where

    ( )

    ( ) ( )

    1 1 1

    2 31 11/2 1/2

    1

    2

    2 2

    k k kn n n

    k k k k k n nn n

    u R Sc

    a aa u R S R S

    c c

    + + +

    + +

    = =

    + + 1n,

    ( )

    ( ) ( )

    1

    2 31 11/2 1/2

    1( ) ( ) ( )

    2

    2 2

    k k kn n n

    k k k k k n nn n

    f u f R f Sc

    b bb u R S R S

    c c

    +

    + +

    = =

    + + 1n

    ,

    ( )

    ( ) ( )

    1 1 1

    2 31 11/2 1/2

    1

    2

    2 2

    k k kn n n

    k k k k k n nn n

    p R S

    a aa p R S R S

    + + +

    + +

    = + =

    + + + 1n,

    ( )

    ( ) ( )

    1

    2 31 11/2 1/2

    1( ) ( ) ( )

    2

    2 2

    k k kn n n

    k k k k k n nn n

    f p f R f S

    b bb p R S R S

    +

    + +

    = + =

    + + + 1n

    n nR p c u = + k k kn n nS p c u =

    ,

    , .k k kn

    Substitution of a grid solution of the form

    ( )exp ( )kn ku u i t kx = n (11)

  • 7/30/2019 ECP1 Software Manual

    7/30

    7

    into finite-difference scheme produces dispersion relation =(k,,h), where - circular frequency and k

    wave number. Then this solution dissipates as exp(-(Im )t)=exp(-t), - dissipation coefficient, and the group

    velocity of harmonic wave (11) is defined as

    Re gd

    cd k

    = .

    Gasdynamics

    Equations of motion in the form of conservation laws:( )

    t x

    + =

    s f s

    o ,

    where s andf(s) have the form

    ( )

    1

    2

    2132

    s

    s u

    s e u

    = = +

    s ,

    ( ) ( )

    21

    2 2

    2 2

    213 2 3 12

    ( ) //

    u sf

    f u p s sf s s p s u e u p

    = = + = + + + +

    f s1 p .

    Equation of state:

    ( )1

    pe

    =

    ,

    then

    ( ) ( )22

    31

    1 12

    sp e s

    s

    = = .

    Here u velocity, p pressure, - density ande specific internal energy, -adiabatic exponent.

    Two-stage Lax-Wendroff scheme with artificial viscosity:

    ( ) ( ) ( )( )1/2 1 11/ 21

    2 20 , ... , 1

    k kk k k k n n n n n h

    n N

    ++ ++

    = +

    =

    s s s f s f s,

    (12

    ( ) ( )( ) ( )1/2 1/21 1 11/2 1/2 21 , ... , 1

    k kkk k k k k n n n n n n nh

    n N

    + ++

    + + = + +

    =

    s s f s f s s s s,

    where - constant parameter of artificial viscosity.

  • 7/30/2019 ECP1 Software Manual

    8/30

    8

    Godunov scheme:

    ( ) ( )1 11/2 1/2

    0 , ... , 1

    k k k kn nn n

    k h

    n N

    +

    ++ +

    +

    =

    s s f s f so=

    . (13)

    Values of

    ( )( )1,kn n kx t+=s s w

    are determined from the solution of Riemann problem with the initial condition

    , (14)( )1/2

    1/ 2

    ,

    , ,

    knn

    k knn

    x x

    x t x x

    +

    = >

    w

    ww

    where

    .u

    p

    =

    w

    A state version of the method WAF (Weighted Average Flux) [3] plus artificial viscosity term:

    ( ) ( )(

    111/2 1/2

    1 2

    0 , ... , 1.

    k k k kn nn n k k k

    n n nk h

    n N

    +

    ++ +

    +

    = +

    =

    s s f s f ss s s

    )1, (15)

    where

    ,( )k kn n=s s w

    /2

    /2

    1( , 0.5 )

    n

    n

    x h

    kn k

    x h

    x t dx h

    +

    = +w w

    k

    andw(x,t) the solution of Riemann problem with the initial condition (14).

    A TVD version of the method WAF [3]:

    ( ) ( )

    1

    11/2 1/2

    0 , ... , 1.

    k k k k

    n nn nk h

    n N

    +

    ++ +

    =

    =

    s s f s f s

    o

    ,

    where is modified with the use of a scalar limiter function (q,r), qis the ratio of the upwind change to the

    local change for some gasdynamical variable, ris the Courant number. In [3] q= orq=e, here this method is

    modified by introducing q= (,u,p) and, therefore, =(

    knw

    1,2,3).

  • 7/30/2019 ECP1 Software Manual

    9/30

    9

    Stationary equations

    Two-dimensional Helmgoltz equation with constant coefficients:

    ( )

    22

    2 2, ,

    {0 , 0 }x y

    uua bu

    x y

    D x l y l

    + + = =

    f x y

    )

    M

    with Dirichlet boundary conditions

    and ,1( ) g (u 0,y = y 3( , )=g ( )xu l y y

    and .2( ,0)=g ( )u x x 4( , )=g ( )yu x l x

    Five-point approximation:

    , (16)1 -1 2 -1 3 2 +1, 1 +1n,m n ,m n,m n m n,m n,m c u c u c u c u c u f + + + =

    ,1,..., 1; 1,..., 1n N m M = =

    ,( ) ( )0, 1 3, , =0,...,m m N,m m u g y u g y m = =

    ,( ) ( ),0 2 , 4, , =1,..., -1n n n M n u g x u g x n N = =

    where

    ( )1 2 3 1 22 2, , 2y x

    a ac c c c c

    h h= = = + b .

    Two-dimensional Helmgoltz equation with variable coefficients:

    ( ) ( ) ( ) ( ), , ,

    {0 , 0 }x y

    u ua x y a x y b x y u f x y

    x x y y

    D x l y l

    + + = =

    , ,

    ,m

    (17)

    with Dirichlet boundary conditions

    and ,1(0, )= ( )u y g y 3( , )= ( )xu l y g y

    and .2( ,0)= ( )u x g x 4( , )= ( )yu x l g x

    Five-point approximation:

    , (18)(1) (2) (3) (2) (1)

    , 1 -1, , , , +1, , , +1, 1 1,

    n m- n m n m n m n m n m n m n m n n m- n- m

    c u c u c u c u c u f + + + =

    .=1,..., -1; =1,..., -1n N m M

    where, +1/2(1)

    , 2

    n mn m

    y

    ac

    h= ,

    1/2,(2), 2

    n mn m

    x

    ac

    h

    += ,

    1/2, 1/2, , 1/2 , 1/2(3), ,2 2

    n m n m n m n m n m n m

    x y

    a a a a c b

    h h

    + + + += + ,

    ( )11/2, 2= ,n m n x m a a x h y + + ,

    ( )1, 1/2 2= ,n m n m y a a x y + + h ,

  • 7/30/2019 ECP1 Software Manual

    10/30

    10

    ,( ), = ,n m n m b b x y

    .=1,..., -1; =1,..., -1n N m M

    Iterative method SOR for solving system of difference equations (18) has the form:

    ( )

    ( )

    (1) ( +1) (2) ( +1) ( ) ( )( +1) (2) (1), ,, -1 , -1 1, 1, 1, , +1(3)

    ,

    ( ),1

    k k k k kkn m n m n m n m n m n m n- m n - m n m n m

    n m

    kk n m

    u c u c u c u c u f c

    u

    += + + + +

    , ,

    M

    N

    ,

    ,=1, ... , -1 ; =1, ... , -1 ; =0 , 1 , ...n N m M k

    ,( 1) ( 1)

    1 30, ,( ) , ( ) , 0 , ... ,k k

    m mm N mu g y u g y m + +

    = = =

    ,( 1) ( 1)

    2 4,0 ,( ) , ( ) , 0 , ... ,k k

    n nn n Mu g x u g x n + +

    = = =

    where kis the relaxation parameter, which is computed on every iteration with the use of the power method.

    Iterative method of Concus and Golub [1] for solving equation (17) has the form:

    ( )( ) ( )2 2 ( 1)

    ( 1) ( )12

    1

    kk k

    nn

    vv f v f

    x

    +

    +

    =

    = +

    x 2 x , (19)

    k=0, 1, .

    where

    ( )v u a= x .

    ( ) ( )22

    1 21

    ( ) ( )1( )( ) nn

    a bfaxa

    =

    =

    x xxxx

    ,

    ( )2( )

    ( )

    ff

    a=

    xx

    x,

    ( ) ( )( )1 max ( ) min ( )2 D Da a = +x xx x .To solve equation (19) five-point approximation of the form (16) can be used.

    Two-dimensional nonlinear Poisson equation:

    ( ) ( ) ( ), , , , , ,

    {0 , 0 }x y

    u ua u x y a u x y f x y

    x x y y

    D x l y l

    + =

    =

    (20)

    with Dirichlet boundary conditions

    and ,1(0, )= ( )u y g y 3( , )= ( )xu l y g y

    and .2( ,0)= ( )u x g x 4( , )= ( )yu x l g x

    Method of time development based on ADI scheme for parabolic PDE:

    ( ) ( )

    ( ) ( )

    1/2, 1/2,, ,1, , , 1,2 2

    , 1/2 , 1/2, 1 , , , 12 2

    2 2

    1( , )

    22 2

    k kkn m n m n m n m

    n m n m n m n m k x x

    k kn m n m k k k k

    n m n m n m n m n m y y

    a aw vw w w w

    h h

    a av v v v f x y

    h h

    + +

    + +

    = +

    , (21)

    ,1,..., 1; 1,..., 1; 0,1,...n N m N k =

    =

    =

  • 7/30/2019 ECP1 Software Manual

    11/30

    11

    ( ) ( )

    ( ) ( )

    11/2, 1/2,, ,

    1, , , 1,2 2

    , 1/2 , 1/21 1 1 1, ,, 1 , 12 2

    2 2

    1( , )

    22 2

    k kkn m n m n m n m

    n m n m n m n m k x x

    k kn m n m k k k k

    n m n m n m n m n m y y

    a av ww w w w

    h h

    a av v v v f x y

    h h

    ++

    +

    + + + + ++

    = +

    ,

    .1,..., 1; 1,..., 1; 0,1,...n N m N k = = =

    ,0, g( , )n m n m v x y=

    ,1 11 30, ,g ( ) , g ( ) , 0 , ... ,k k

    m mm N mv y v y m + +

    = = = M

    N ,1 12 4,0 ,g ( ) , g ( ) , 0 , ... ,k kn nn n Mv x v x n + += = =

    where

    ( )( )1 1, , 1/21/2, 2 , ,k k k

    n m n m n m n ma a v v x + ++ = + y ,

    ( )( )1 , 1 , 1/2, 1/2 2 , ,k k k

    n m n m n m n ma a v v x y + ++ = + .

    Viscous incompressible fluid

    Two dimensional Navier-Stokes equations in variables stream function-vorticity:

    2 2

    2 2

    1( , , )

    Resu v f x y

    t x y x x

    + + = + +

    t ,

    0,2 0,1( , , 0)

    g gx y

    y x

    = ,

    , (22)( ) { }, = 0 , 0 ,x yx y D x l y l t 0

    2 2

    2 2( , , )x y t

    x y

    + =

    ,

    u y

    v x

    = ,

    where u, v components of velocity, Re Reynolds number, - stream function, - vorticity.

    Boundary conditions:

    ( ) 10,

    0

    ( , )y

    u

    v g y t

    = ,

    ( ) 3,

    0

    ( , )xl y

    u

    v g y t

    = ,

    ( )

    2

    ,0

    ( , )

    0x

    u g x t

    v

    = ,

    ( )

    4

    ,

    ( , )

    0yx l

    u g x t

    v

    = ,

    or

    ( )10,

    0

    ( , )y

    x g y t

    = ,

    ( ) 3,

    0

    ( , )xl y

    x g y t

    = ,

  • 7/30/2019 ECP1 Software Manual

    12/30

    12

    ( )2,0

    0

    ( , )x

    y g x t

    = ,

    ( ) 4,

    0

    ( , )yx l

    y g x t

    = .

    The explicit splitting-up scheme:

    0,0

    mds

    dt= ,

    ,0

    N mds

    dt= ,

    , 1, 1, 1, ,, 2

    2

    2 Re

    n m n m n m n m n m n m kn m

    x x

    ds s s s s s u

    dt h h

    + + += +

    1,

    ,

    tkttk+kn=1, , N-1; m=1, , M-1,

    .( ), ,kn m k n m s t =

    (23)

    ,00

    ndq

    dt= ,

    ,0

    n Mdq

    dt= ,

    , , 1 , 1 , 1 ,, 2

    2

    2 Re

    n m n m n m n m n m n m kn m

    y y

    dq q q q q s v

    dt h h

    + + += +

    , 1

    ,

    tkttk+k n=1, , N-1 ; m=1, , M-1,

    .( ) ( ), ,n m k n m k k q t s t = +

    The successive solution of these systems gives

    .( )1, ,kn m n m k k q t

    += +

    After that, find the stream function from the finite-difference equation1 1 1 1 1 1, ,+1, -1, , +1 , -1 1

    ,2 2

    2 2k k k k k k n m n m n m n m n m n m kn m

    x yh h

    + + + + + +

    + + +

    + = , (24)

    1,..., 1; 1,..., 1n N m M = =

    and then compute the components of velocity:1 1

    , 1 , 11, 2

    k kn m n m k

    n my

    uh

    + ++ +

    = , (25)

    1 11, 1,1

    , 2

    k kn m n m k

    n mx

    vh

    + ++ +

    = ,

    .1,..., 1; 1,..., 1n N m M = =

    Systems of ordinary differential equations (23) are solved with the use of 3rd

    order Runge-Kutta scheme, whichis defined by the following Butcher table:

    0

    1/2 1/2

    3/4 0 3/4

    2/9 1/3 4/9

  • 7/30/2019 ECP1 Software Manual

    13/30

    13

    A short description of MATLAB functions

    Main function Examples and auxiliary functions

    heat_1d_un example4_1,f1_e41, f2_e41, fs_e41

    heat_1d_nun example4_2,

    f1_e42, f2_e42, fs_e42heat_2d_es example4_3,

    g1_e43, g2_e43, g3_e43, g4_e43,fs_e43

    stefan_1d example4_4,f1_e44, f2_e44, fs_e44

    properties cross example5_1,

    f1_e51, f2_e51lw_acoustics example5_2,

    f1_e51, f2_e51roe example5_3,

    f1_e51, f2_e51godunov_ acoustics example5_4,

    f1_e51, f2_e51pem example5_5,

    f1_e51, f2_e51lw_gasdynamics example6_1, example6_2godunov_gasdynamics example6_3waf_gasdynamics example6_4waf_tvd_gasdynamics example6_5,

    limiter_mina, limiter_supera,limiter_ultraa, limiter_vanAlbada,limiter_vanLeer, limiter_Lin

    riemann

    helmgoltz_2d_sor example7_1,g1_e71, g2_e71, g3_e71, g4_e71,a_e71, b_e71, f_e71

    helmgoltz_2d_fft example7_2,g1_e71, g2_e71, g3_e71, g4_e71,f_e71

    helmgoltz_2d_cg example7_3,g1_e73, g2_e73, g3_e73, g4_e73,a_e73, b_e73, f_e73

    poisson_2d_td example7_4,g1_e74, g2_e74, g3_e74, g4_e74,a_e74, f_e74

    ns_2d_vsf example8_1,

    g1_e81, g2_e81, g3_e81, g4_e81

  • 7/30/2019 ECP1 Software Manual

    14/30

    14

    function [uu]=heat_1d_un(ud,kappa,a,nx,h,time,tau,b,gamma,bl,br,fbl,fbr,fs)

    Purpose Computation of one time step fromscheme (1)

    Input parameters ud Temperature at the instant of time tk kappa Thermal diffusion coefficient ()

    a Thermal conductivity coefficient

    nx Number of grid nodesh Space step

    time Instant of time tk+1tau Time stepb Parameter/h

    2

    gamma Parameter=0 explicit scheme>0 implicit scheme

    bl,br Type of boundary condition at x=0x=l,respectively.

    =0 boundary condition of the 1st kind=1 boundary condition of the 2ndkind

    fbl, fbr Names of m-files in which thedependence of temperature or heat flux

    on time is defined at x=0 and x=l,respectively.

    fs Name of m-file in which the dependenceof external source on space and time isdefined.

    Output parameters uu Temperature at the instant of time tk+1

  • 7/30/2019 ECP1 Software Manual

    15/30

    15

    function [uu]=heat_1d_nun(ud,roc,a,nx,h,time,tau,b,gamma,bl,br,fbl,fbr,fs)

    Purpose Computation of one time step fromscheme (2)

    Input parameters ud Temperature at the instant of time tk roc Array of values of c in the nodes of

    main grid.

    a Array of values of a in the nodes ofauxiliary grid.

    nx Number of grid nodes.h Space step.time Instant of time tk+1tau Time stepgamma Parameter

    =0 explicit scheme>0 implicit scheme

    bl,br Type of boundary condition at x=0x=l,respectively.=0 boundary condition of the 1st kind=1 boundary condition of the 2ndkind.

    fbl, fbr Names of m-files in which thedependence of temperature or heat flux

    on time is defined at x=0 and x=l,respectively.

    fs Name of m-file in which the dependenceof external source on space and time is

    defined.

    Output parameters uu Temperature at the instant of time tk+1

    Note This function can be used for solving of

    nonlinear equation (scheme (3)). Oneneeds only to recalculate the values of

    roc, a andtauon every time step.

  • 7/30/2019 ECP1 Software Manual

    16/30

    16

    function [uu]=heat_2d_es(ud,kappa,a,nx,ny,hx,hy,tau,time,bxl,bxr,fbxl,fbxr,byl,byr,fbyl,fbyr,fs)

    Purpose Computation of one time step fromscheme (4)

    Input parameters ud Temperature at the instant of time tk kappa Thermal diffusion coefficient ()

    a Thermal conductivity coefficient

    nx, ny Number of grid nodes along x y,respectively.

    hx, hy Space steps along xy, respectively.time Instant of time tk+1tau Time stepbxl,bxr Type of boundary condition at x=0

    x=lx, respectively.=0 boundary condition of the 1st kind=1 boundary condition of the 2ndkind.

    fbxl, fbxr Names of m-files in which thedependence of temperature or heat flux

    on time andy is defined at x=0 andx=lx,respectively.

    byl,byr Type of boundary condition at y=0 y=ly, respectively.=0 boundary condition of the 1st kind=1 boundary condition of the 2ndkind.

    fbyl, fbyr Names of m-files in which thedependence of temperature or heat fluxon time andx is defined at y=0 andy=ly,respectively.

    fs Name of m-file in which the dependenceof external source on space and time is

    defined.

    Output parameters uu Temperature at the instant of time tk+1

  • 7/30/2019 ECP1 Software Manual

    17/30

    17

    function [entu,uu,sf]=stefan_1d(entd,ud,ro,cs,cl,as,al,lh,up,nx,h,tau,time,bl,br,fbl,fbr,fs)

    Purpose Computation of one time step fromscheme (5)

    Input parameters ud, entd Temperature and enthalpy at the instantof time tk

    ro Densitycs, cl Specific heat of solid and liquid phase,

    respectively.

    as, al Thermal conductivity coefficient of solidand liquid phase, respectively.

    lh Latent heat of melting.up Temperature of melting.nx Number of grid nodes.h Space step.time Instant of time tk+1

    tau Time step.bl,br Type of boundary condition at x=0x=l,

    respectively.=0 boundary condition of the 1st kind=1 boundary condition of the 2ndkind.

    fbl, fbr Names of m-files in which thedependence of temperature or heat flux

    on time is defined at x=0 and x=l,

    respectively.fs Name of m-file in which the dependence

    of external source on space and time isdefined.

    Output parameters uu, entu Temperature and enthalpy at the instantof time tk+1

    sf Local fraction of solid phase at the instantof time tk+1

  • 7/30/2019 ECP1 Software Manual

    18/30

    18

    function [dis,cg]=properties(kh,r,method)

    Purpose Computation of dissipation coefficientand the nondimensional group velocity ofharmonic wave (11) for various schemes.

    Input parameters kh Product of wave number by space stepr Courant numbermethod Method

    'crs' scheme cross'lxw' Lax-Wendroff scheme'roe' scheme of P. Roe

    'god' Godunov scheme'pem' PEM scheme

    Output parameters dis Dissipation coefficientcg Nondimensional group velocity

    function [uu]=cross(ud,um,c,ro,nx,h,time,tau,bl,br,fbl,fbr)

    Purpose Computation of one time step from

    scheme (6)

    Input parameters ud, um Solution at the instants of times tk-1tk,respectivel.

    c Speed of sound

    ro Density

    nx Number of grid nodesh Space steptime Instant of time tk+1tau Time stepbl,br Type of boundary condition at x=0x=l,

    respectively.=0 boundary condition of the 1st kind=1 boundary condition of the 2ndkind.

    fbl, fbr Names of m-files in which thedependence of a solution or its derivative

    on time is defined at x=0 and x=l,respectively.

    Output parameters uu Solution at the instant of time tk+1

  • 7/30/2019 ECP1 Software Manual

    19/30

    19

    function [uu,pu]=lw_acoustics(ud,pd,imp,nx,time,r,bl,br,fbl,fbr)

    Purpose Computation of one time step from Lax-Wendroff scheme (7)

    Input parameters ud, pd Velocity and pressure at the instant oftime tk

    imp Value ofcnx Number of grid nodestime Instant of time tk+1r Courant numberbl,br Type of boundary condition at x=0x=l,

    respectively.=0 boundary condition on u=1 boundary condition on p

    fbl, fbr Names of m-files in which thedependence of velocity or pressure on

    time is defined at x=0 and x=l,respectively.

    Output parameters uu, pu Velocity and pressure at the instant oftime tk+1

    function [uu,pu]=roe(ud,pd,um,pm,imp,nx,time,r,bl,br,fbl,fbr)

    Purpose Computation of one time step from

    scheme of P. Roe (8)

    Input parameters ud, pd Velocity and pressure at the instant oftime tk-1

    um, pm Velocity and pressure at the instant oftime tk

    imp Value ofc

    nx Number of grid nodestime Instant of time tk+1r Courant numberbl,br Type of boundary condition at x=0x=l,

    respectively.=0 boundary condition on u=1 boundary condition on p

    fbl, fbr Names of m-files in which thedependence of velocity or pressure on

    time is defined at x=0 and x=l,respectively.

    Output parameters uu, pu Velocity and pressure at the instant oftime tk+1

  • 7/30/2019 ECP1 Software Manual

    20/30

    20

    function [uu,pu]=godunov_acoustics(ud,pd,imp,nx,time,r,bl,br,fbl,fbr)

    Purpose Computation of one time step fromGodunov scheme (9)

    Input parameters ud, pd Velocity and pressure at the instant oftime tk

    imp Value ofcnx Number of grid nodestime Instant of time tk+1r Courant numberbl,br Type of boundary condition at x=0x=l,

    respectively.=0 boundary condition on u=1 boundary condition on p

    fbl, fbr Names of m-files in which thedependence of velocity or pressure on

    time is defined at x=0 and x=l,respectively.

    Output parameters uu, pu Velocity and pressure at the instant oftime tk+1

  • 7/30/2019 ECP1 Software Manual

    21/30

    21

    function [ub,pb,uu,pu]=pem(ua,pa,ud,pd,imp,nx,r,time,tau,a1,a2,a3,b1,b2,b3,bl,br,fbl,fbr)

    Purpose Computation of one time step from PEMscheme (10)

    Input parameters ua, pa Average values of velocity and pressureon every difference interval at the instantof time tk

    ud, pd Values of velocity and pressure in everynode of a grid at the instant of time tk

    imp Value ofcnx Number of grid nodestime Instant of time tk+1R Courant numbertau Time stepa1,a2,a3,b1,b2,b3

    Parameters of PEM scheme (given in

    example5_5.m)

    bl,br Type of boundary condition at x=0x=l,respectively.

    =0 boundary condition on u=1 boundary condition on p

    fbl, fbr Names of m-files in which thedependence of velocity or pressure ontime is defined at x=0 and x=l,respectively.

    Output parameters ub, pb Average values of velocity and pressureon every difference interval at the instant

    of time tk+1 uu, pu Values of velocity and pressure in every

    node of a grid at the instant of time tk+1

  • 7/30/2019 ECP1 Software Manual

    22/30

    22

    function [rf,uf,pf]=riemann(x,t,r1,u1,p1,r2,u2,p2,gamma)

    Purpose Computation of the exact solution ofRiemann problem for an ideal gas

    Input parameters x Coordinatet Timer1,u1,p1 Initial density, velocity and pressure at

    x0gamma Adiabatic exponent

    Output parameters rf,uf,pf Density, velocity and pressure at x and atinstant of time t

    function [d,u,p,e,time]=lw_gasdynamics(dd,ud,pd,h,nx,r,cad,tp,gamma,bcl,bcr)

    Purpose Computation of a gas flow from Lax-

    Wendroff scheme (12)

    Input parameters dd,ud,pd Density, velocity and pressure at time t=0h Space stepnx Number of grid nodesr Courant numbercad Artificial viscosity coefficienttp Flow duration (approximate)gamma Adiabatic exponentbcl,bcr Type of boundary condition at x=0x=l,

    respectively.=0 rigid wall=1 open boundary

    Otput parameters time Real duration of the flowd,u,p,e Density, velocity, pressure and specific

    internal energy at time time

  • 7/30/2019 ECP1 Software Manual

    23/30

    23

    function [d,u,p,e,time]=godunov_gasdynamics(dd,ud,pd,h,nx,r,tp,gamma,bcl,bcr)

    Purpose Computation of a gas flow from Godunovscheme (13)

    Input parameters dd,ud,pd Density, velocity and pressure at time t=0h Space stepnx Number of grid nodesr Courant numbertp Flow duration (approximate)gamma Adiabatic exponentbcl,bcr Type of boundary condition at x=0x=l,

    respectively.=0 rigid wall=1 open boundary

    Otput parameters time Real duration of the flowd,u,p,e Density, velocity, pressure and specific

    internal energy at time time

    function [d,u,p,e,time]=waf_gasdynamics(dd,ud,pd,h,nx,r,cad,tp,gamma,bcl,bcr)

    Purpose Computation of a gas flow from the WAFscheme (15).

    Input and output parameters have the same meaning as for the function lw_gasdynamics.

  • 7/30/2019 ECP1 Software Manual

    24/30

    24

    function [d,u,p,e,time]=waf_tvd_gasdynamics(dd,ud,pd,h,nx,r,tp,gamma,bcl,bcr,limiter)

    Purpose Computation of a gas flow from a TVDversion of the WAF scheme

    Input parameters dd,ud,pd Density, velocity and pressure at time t=0h Space stepnx Number of grid nodesr Courant numbertp Flow duration (approximate)gamma Adiabatic exponentbcl,bcr Type of boundary condition at x=0x=l,

    respectively.=0 rigid wall=1 open boundary

    limiter Name of m-file in which a limiterfunction is defined. Several limiters are

    enclosed.

    Otput parameters time Real duration of the flowd,u,p,e Density, velocity, pressure and specific

    internal energy at time time

  • 7/30/2019 ECP1 Software Manual

    25/30

    25

    function [u,k]=helmgoltz_2d_sor(f,ac,bc,lx,ly,nx,ny,g1,g2,g3,g4)

    Purpose Computation of a solution of system (18)with Dirichlet boundary conditions,method SOR.

    Input parameters f Name of m-file in which the right-hand

    side function f(x, y) is defined.ac Name of m-file in which the coefficient

    a(x, y) is defined.bc Name of m-file in which the coefficient

    b(x, y)is defined.

    lx, ly Domain size in x y directions,respectively.

    nx, ny Number of grid nodes in x ydirections, respectively.

    g1, g3 Names of m-files in which thedependence of a solution on y is definedat x=0 andx=lx, respectively.

    g2, g4 Names of m-files in which thedependence of a solution on x is definedat y=0 andy=ly, respectively.

    Output parameters u Approximate solutionk Number of iterations

    Note Iterative process is completed when

    either relative error of approximate

    solution becomes less then 10-5

    , ornumber of iterations reaches the value

    3max(nx, ny).

  • 7/30/2019 ECP1 Software Manual

    26/30

    26

    function [u]=helmgoltz_2d_fft(f,a,b,lx,ly,nx,ny,g1,g2,g3,g4)

    Purpose Computation of a solution of system (16)with Dirichlet boundary conditions, FFT-based method.

    Input parameters f Name of m-file in which the right-hand

    side function f(x, y) is defined.a Name of m-file in which the coefficient

    a(x, y) is defined.B Name of m-file in which the coefficient

    b(x, y)is defined.

    lx, ly Domain size in x y directions,respectively.

    nx, ny Number of grid nodes in x ydirections, respectively.

    g1, g3 Names of m-files in which thedependence of a solution on y is definedat x=0 andx=lx, respectively.

    g2, g4 Names of m-files in which thedependence of a solution on x is definedat y=0 andy=ly, respectively.

    Output parameters u Approximate solution

    Note FFT is applied in x direction, therefore,one should set nx=2p+1 for the mostefficient computation.

  • 7/30/2019 ECP1 Software Manual

    27/30

    27

    function [u,it]=helmgoltz_2d_cg(up,f,a,b,lx,ly,nx,ny,g1,g2,g3,g4)

    Purpose Computation of a solution of equation(17) with Dirichlet boundary conditions.Method of Concus and Golub (19) based

    on FFT.

    Input parameters up Initial approximationf Name of m-file in which the right-hand

    side function f(x, y) is defined.a Name of m-file in which the coefficient

    a(x, y) is defined.b Name of m-file in which the coefficient

    b(x, y) is defined.lx, ly Domain size in x y directions,

    respectively.

    nx, ny Number of grid nodes in x ydirections, respectively.

    g1, g3 Names of m-files in which thedependence of a solution on y is definedat x=0 andx=lx, respectively.

    g2, g4 Names of m-files in which thedependence of a solution on x is definedat y=0 andy=ly, respectively.

    Output parameters u Approximate solutionit Number of iterations

    Note Iterative process is completed whenrelative error of approximate solution

    becomes less then 10-5

    .FFT is applied in x direction, therefore,one should set nx=2

    p+1 for the mostefficient computation.

  • 7/30/2019 ECP1 Software Manual

    28/30

    28

    function [u,k]=poisson_2d_td(up,f,a,lx,ly,nx,ny,g1,g2,g3,g4)

    Purpose Computation of a solution of nonlinearequation (20) with Dirichlet boundary

    conditions, method of time development(21)

    Input parameters up Initial approximationf Name of m-file in which the right-hand

    side function f(x, y) is defined.a Name of m-file in which the coefficient

    a(u, x, y) is defined.lx, ly Domain size in x y directions,

    respectively.

    nx, ny Number of grid nodes in x ydirections, respectively.

    g1, g3 Names of m-files in which thedependence of a solution on y is definedat x=0 andx=lx, respectively.

    g2, g4 Names of m-files in which thedependence of a solution on x is definedat y=0 andy=ly, respectively.

    Output parameters u Approximate solutionk Number of iterations

    Note Iterative process is completed whenrelative error of approximate solution

    becomes less then 10-5

    .

  • 7/30/2019 ECP1 Software Manual

    29/30

    29

    function [u,v,w,psi,time]=ns_2d_vsf(u,v,w,Re,tp,lx,ly,nx,ny,bxl,bxr,byl,byr,g1,g2,g3,g4)

    Purpose Computation of a solution of equations(22) from the scheme (23)-(25).

    Intput parameters u, v,w Components of velocity and vorticity attime t=0.

    Re Reynolds number

    tp Flow duration (approximate)

    lx, ly Domain size in x y directions,respectively.

    nx, ny Number of grid nodes in x ydirections, respectively.

    bxl,bxr Type of boundary condition on v at x=0andx=lx, respectively:=0 value of velocity is assigned=1 v/y is zero.

    byl,byr Type of boundary condition on u at y=0andy=ly, respectively:=0 value of velocity is assigned,=1 u/x is zero.

    g1, g3 Names of m-files in which thedependence ofv on y and time is defined

    at x=0 andx=lx, respectively.g2, g4 Names of m-files in which thedependence ofu on x and time is definedat y=0y=ly, respectively.

    Output parameters time Real duration of the flowu,v,w Components of velocity and vorticity at

    time time.psi Stream function at time time.

    Note For normal to the boundaries componentsof velocity the following conditions are

    assumed:u=0 at x=0 andx=lx, v=0 at y=0 andy=ly

  • 7/30/2019 ECP1 Software Manual

    30/30

    References

    1. Concus P. and Golub G. H. Use of fast direct methods for the efficient numerical solution of non-separableelliptic equations, SIAM J. Num. Anal., v. 10, pp. 1103-1120 (1973).

    2. Roe P. Linear bicharacteristic scheme without dissipation, SIAM J. Sci. Comput., v.19, N5, pp. 1405-1427(1998).

    3. Toro E. F. Riemann solvers and numerical methods for fluid dynamics, Springer-Verlag, 1997.

    4. Zalizniak V. The piecewise exponential method (PEM) for the numerical simulation of wave propogation,Communications in Numerical Methods in Engineering, v. 13, N3, pp163-171.