You are on page 1of 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 in Computational physics and Numerical methods courses as well as in students research projects. Additional information on how to use the accompanying programs can be found in examples. Although great care is taken to eliminate all program errors, the author does not take any responsibility for the consequences of application of these programs. This manual consists of two parts: A short description of mathematical models and finite-difference schemes and A short description of MATLAB functions.

V. Zalizniak, 2005

A short description of mathematical models and finite-difference schemes

Heat transfer
One-dimensional heat transfer (uniform medim). Equation: u
t 2 u x2

, 0 t T , 0 x l ,

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: u u(0, t ) = f1 (t ) or a (0, t ) = f1 (t ) , x
u(l, t ) = f2 (t ) or a

u x

(l, t ) = f2 (t ) .

Finite-difference scheme:
k +1 k +1 k +1 k k k k +1 k un + un un un un +1 2un 1 +1 2un + un 1 = + (1 ) h2 h2 , 0 1, k = 0,1,...; n = 1,..., N 1

(1)

One-dimensional heat transfer (nonuniform medim). Equation:


(x )c(x ) u t = u a(x ) , 0 t T , 0 x l . x x

Initial conditions: u(x,0)=g(x). Bundary conditions: u u(0, t ) = f1 (t ) or a (0, t ) = f1 (t ) , x


u(l, t ) = f2 (t ) or a u x (l, t ) = f2 (t ) .

Finite-difference scheme:

(c)n

k +1 k +1 k +1 k +1 k +1 k un un un un un +1 un 1 = + a a n +1/ 2 n 1/ 2 h2 h2

uk uk uk uk (1 ) an +1/ 2 n +1 2 n an 1/ 2 n 2 n 1 h h Nonlinear equation: u a u ( (u )c(u ) u ) = ( ) , t x x

(2)

0 t T , 0 x l
Finite-difference scheme:
k k n cn k +1 k +1 k +1 k +1 k +1 k un un un un un +1 un k k 1 , = an an +1/ 2 1/ 2 2 2 k h h

(3)

where
k k n = (un ) k k cn = c(un ) k k k 1 an +1/ 2 = a ( 2 (un +1 + un ) )

Two-dimensional heat transfer (uniform medim). Equation: u

2 u 2 u + fs (x , y, t ) , = x 2 + y2 t

0 t T , 0 x lx , 0 y ly
The explicit splitting-up scheme:
k vn,m un ,m k = x un ,m + fs (x n , ym , tk ), n = 1,..., N 1; m = ms ,..., me

(4)
vn,m = y vn,m , n = ns ,..., ne ; m = 1,..., M 1
k +1 un ,m

where

1 k k k ( un +1,m 2un ,m + un 1,m ) h2 . 1 k k k k y un = u u + u 2 ( ) ,m n ,m +1 n ,m n ,m 1 h2 Papameters ns, ne, ms, me depend on boundary conditions: 1 , boundary conditions of the 1st kind at x = 0 , ns = 0 , boundary conditions of the 2nd kind at x = 0
k x un ,m =

N 1 , boundary conditions of the 1st kind at x = lx ne = N , boundary conditions of the 2nd kind at x = lx 1 , boundary conditions of the 1st kind at y = 0 ms = , 0 , boundary conditions of the 2nd kind at y = 0 M 1 , boundary conditions of the 1st kind at y = ly . me = M , boundary conditions of the 2nd kind at y = ly

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


u a(x , t ) , 0 x l ,t > 0 , x t x cs u , u < u p H (u ) = c u (cl cs )u p + L , u u p l where H enthalpy, u temperature, a thermal conductivity coefficient, c specific heat, - density, up H =

melting temperature, L latent heat of melting. Subscript s means solid phase and l means liquid phase. Local fraction of solid phase is defined as 1, H (x , t ) cs u p s(H ) = s(x , t ) = 1 (H cs u p )/ L , cs u p < H (x , t ) < cs u p + L 0, H (x , t ) cs u p + L and then thermal conductivity coefficient is defined as as , s(x , t ) = 1 . a(s ) = a(x , t ) = a , 0 s(x , t ) < 1 l Finite-difference scheme:
k k k +1 k k k un Hn Hn un un +1 un 1 k k , = an a n 1/ 2 +1/ 2 h2 h2 n = 1,..., N 1; k = 0,1,...

(5)

where
k 1 an +1/2 = a ( 2 ( s(x n +1, tk ) + s(x n , tk ) ) ) = k k 1 a(2 ( s(H n +1 ) + s(H n ) ) ), k k un = u (Hn

Propagation of acoustic waves


Second order differential equation: 2 2u 2 u = c , 0 x l , 0 t T , t2 x2 where u velocity or pressure and c speed of sound. u Initial conditions: u(x , 0) = g1 (x ) , (x , 0) = g2 (x ) , t Boundary conditions: u 1u(0, t ) + 2 (0, t ) = f1 (t ) , x u 3u(l , t ) + 4 (l, t ) = f2 (t ) . x Finite difference scheme cross:
k k k +1 k k 1 u k 2un + un un 2un + un 1 = c 2 n +1 2 2 , h n = 1 , ..., N 1 , k = 2 , 3 , ...

(6)

System of differential equations: s s +A = o , 0 x l , 0 t T , t x where


0 1/ 0 u o = s= , , A = 2 0 p 0 c

u velocity, p pressure, - density and c speed of sound.


Initial conditions: u(x , 0) = g1(x ) , p(x , 0) = g2 (x ) , Boundary conditions: 1u(0, t ) + 2 p(0, t ) = f1 (t ) , 3u(l, t ) + 4 p(l, t ) = f2 (t ) . Lax-Wendroff scheme:
1 k A ( sk n +1 sn 1 ) + 2h 2 h n = 1 , ... , N 1
+1 sk = sk n n

( )A
2

k ( sk n +1 2sn

+ sk n 1 )

(7)

or in expanded form
r 1 2 k k k k k pn ( +1 pn 1 ) + r ( un +1 2un + un 1 ) , 2c 2 rc k 1 2 k k +1 k k k k = pn pn ( un +1 un 1 ) + r ( pn +1 2pn + pn 1 ) 2 2 . n = 1 , ... , N 1
k +1 k = un un

Nondissipative scheme of P. Roe [2]:

k +1 k k 1 k Rn 1 Rn Rk Rn Rk Rn 1 1 +c n + n 1 = 0, 2 h k 1 k k +1 k S k Sn S k Sn Sn 1 Sn +1 c n +1 + n +1 = 0, h 2

(8)

n = 1 , ... , N 1
k k k k k k Rn = pn + c un = pn c un , Sn , k k k k k k un = 0.5(Rn Sn )/ c , pn = 0.5(Rn + Sn ).

Godunov scheme:
k +1 k un +1/ 2 un +1/ 2

k +1 k pn +1/ 2 pn +1/ 2

k k pn + 3 / 2 pn 1/ 2

2h

c k k 2un (uk +1/ 2 + un 1/ 2 ) , 2h n + 3 / 2

(9)
= c 2 n = 1,..., N 2 ; k = 0,1,...
k k un + 3 / 2 un 1/ 2

2h

c k k 2pn ( pk +1/ 2 + pn 1/ 2 ) . 2h n + 3 / 2

PEM scheme [4]: +1 k +1 k fnk+ fnk +1(u ) u u 1 (u ) 1 , A = p p 1 1 k + k + h ( ) ( ) f p f p n +1 n n +1/ 2 n +1/ 2 where 1 k +1 k +1 un = ( Rk +1 Sn )= 2c n , a a3 k k k k k + 2 ( Rn + a1un S R S ( n +1 ) 1/2 n +1/2 ) 2c 2c n 1 1 fnk +1(u ) = ( f k (R) fnk (S ) ) = 2c n , b b3 k k k k k b1un + 2 ( Rn S + R S ( ) n +1 1/ 2 n +1/ 2 ) 2c 2c n 1 1 k +1 k +1 k +1 pn = ( Rn + Sn )= 2 , a a3 k k k k k a1 pn S R S + 2 ( Rn + + ( ) ) n +1 n +1/2 1/2 2 2 n 1 1 fnk +1 (p) = ( fnk (R) + fnk (S ) ) = 2 , b b3 k k k k k b1pn S R S + 2 ( Rn + + ( ) ) 1 1 n n + n +1/2 1/2 2 2 k k k k k k Rn = pn + c un , Sn = pn c un . Substitution of a grid solution of the form k un = u exp ( i(tk kx n ) )

(10)

(11)

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 d Re = cg . dk

Gasdynamics
Equations of motion in the form of conservation laws: s f (s) + = o, t x where s and f(s) have the form

s1 s u = s= 2 , 2 1 s3 (e + 2 u ) u s2 f1 2 2 = u + p f (s) = f2 = s2 / s1 + p . 2 1 f ( ) + s s p / s + + u e u p ) 1 3 2 3 2 (
Equation of state:
e = p , ( 1)

then

s2 p = e ( 1 ) = ( 1 ) s3 2 . 2s1
Here u velocity, p pressure, - density and e specific internal energy, -adiabatic exponent. Two-stage Lax-Wendroff scheme with artificial viscosity:
k 1 k k k ( s + sk ( f ( sn +1 ) f ( sn ) ) n ) 2 n +1 2h , n = 0 , ... , N 1
+1/2 sk n +1/ 2 =

k +1/2 k +1/2 +1 k k k sk = sk ( f ( sk n n n +1/2 ) f ( sn 1/2 ) ) + ( sn +1 2sn + sn 1 ) h , n = 1 , ... , N 1

(12

where - constant parameter of artificial viscosity.

Godunov scheme:
k f ( sk n +1 ) f ( sn ) =o . k h n = 0 , ... , N 1
+1 k sk n +1/2 sn +1/2

(13)

Values of sk n = s ( w ( x n , tk +1 ) ) are determined from the solution of Riemann problem with the initial condition wk n 1/ 2 , x x n , w ( x , tk ) = k , x x w > n n +1/2 where w= u . p A state version of the method WAF (Weighted Average Flux) [3] plus artificial viscosity term:

(14)

k k f ( sn +1 ) f ( sn ) k k = ( sk n +1 2sn + sn 1 ) , k h n = 0 , ... , N 1.
+1 k sk n +1/ 2 sn +1/2

(15)

where

k  sn = s ( wk n ),

1  wk n = h

x n +h /2 x n h /2

w(x , tk + 0.5k )dx

and w(x,t) the solution of Riemann problem with the initial condition (14). A TVD version of the method WAF [3]:

k k f ( sn +1 ) f ( sn ) =o , k h n = 0 , ... , N 1.
+1 k sk n +1/ 2 sn +1/ 2

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

local change for some gasdynamical variable, r is the Courant number. In [3] q= or q=e, here this method is modified by introducing q= (,u,p) and, therefore, =(1,2,3).

Stationary equations
Two-dimensional Helmgoltz equation with constant coefficients: 2u 2 u + bu = f ( x , y ), a 2 + 2 y x

D = {0 x lx , 0 y ly } with Dirichlet boundary conditions u(0,y ) = g1 (y ) and u(lx ,y )=g 3 (y ) ,


u(x ,0)=g2 (x ) and u(x ,ly )=g4 (x ) .

Five-point approximation:
c1un,m -1 + c2un -1,m c3un,m + c2un +1,m + c1un,m +1 = fn,m , n = 1,..., N 1; m = 1,..., M 1 ,

(16)

u 0,m = g1 ( ym ), uN,m = g 3 ( ym ) , m =0,..., M , un,0 = g2 ( x n ), un,M = g 4 ( x n ), n =1,..., N -1 ,

where

c1 =

a a , c2 = 2 , c3 = 2 ( c1 + c2 ) b . 2 hy hx

Two-dimensional Helmgoltz equation with variable coefficients: u u ( ) ( ) , , a x y a x y + + b ( x , y ) u = f ( x , y ), x y y x

(17)

D = {0 x lx , 0 y ly } with Dirichlet boundary conditions u(0,y )=g1 (y ) and u(lx ,y )=g 3 (y ) ,


u(x ,0)=g2 (x ) and u(x ,ly )=g 4 (x ) .

Five-point approximation:
(1) (2) (3) (2) (1) cn ,m - 1un,m - 1 + cn - 1,m un -1,m cn,m un,m + cn ,m un +1,m + cn ,m un ,m +1 = fn ,m ,

(18)

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

where
(1) cn ,m =

an,m +1/2
2 hy

, ,
2 hx

(2) cn ,m =

an +1/2,m
2 hx

(3) cn ,m =

an +1/2,m + an 1/2,m

an,m +1/2 + an,m 1/2


2 hy

bn,m ,

1 an +1/ 2,m =a ( x n + 2 hx , ym ) , 1 an,m +1/ 2 =a ( x n , ym + 2 hy ) ,

bn,m =b ( x n , ym ) , n =1,..., N -1; m =1,..., M -1 .

Iterative method SOR for solving system of difference equations (18) has the form: k (1) (k +1) (2) (k +1) (k +1) (2) (k ) (1) (k ) un = (3) (cn ,m ,m -1un ,m -1 + cn - 1,m un - 1,m + cn ,m un +1,m + cn ,m un ,m +1 fn ,m ) + cn,m ,
(k ) ( 1 k ) un ,m

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


(k +1) (k +1) u 0, = g1 (ym ) , uN m ,m = g 3 (ym ) , m = 0 , ... , M , (k +1) (k +1) un = g 2 (x n ) , un = g 4 (x n ) , n = 0 , ... , N , ,0 ,M

where k is 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 2v (k +1) v (k +1) = ( f1 ( x ) ) v (k ) + f2 ( x ) , xn 2 n =1

(19)

k=0, 1, .
where

v = u a(x) .
f1 ( x ) =
2 2 ( a(x) ) b(x) 1 , xn 2 a(x) a(x) n =1

f2 ( x ) =
=

f (x) , a(x)

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

Two-dimensional nonlinear Poisson equation: u u ( ) ( ) , , , , a u x y + a u x y = f ( x , y ), x x y y

(20)

D = {0 x lx , 0 y ly } with Dirichlet boundary conditions u(0,y )=g1 (y ) and u(lx ,y )=g 3 (y ) ,


u(x ,0)=g2 (x ) and u(x ,ly )=g 4 (x ) .

Method of time development based on ADI scheme for parabolic PDE: k k k an an wn,m vn +1/ 2,m 1/ 2,m ,m ( wn,m wn 1,m ) + = w w ( ) + 1, , n m n m 2 2 k 2hx 2hx
k k an an 1 ,m +1/ 2 ,m 1/ 2 k k k k v v ( ) ( vn + , 1 , ,m vn ,m 1 ) f (x n , ym ) n m n m 2 2 2 2hy 2hy

(21)

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

10

k k +1 ak an vn 1/ 2,m ,m wn ,m ( wn +1,m wn,m ) n +1/22,m = 2 ( wn,m wn 1,m ) + k 2hx 2hx , k k an an 1 ,m +1/ 2 , 1/ 2 m + + + + 1 1 1 1 k k k k ( vn,m +1 vn,m ) ( vn,m vn,m 1 ) f (x n , ym ) 2h 2 2h 2 2 y y n = 1,..., N 1; m = 1,..., N 1; k = 0,1,... .
0 vn ,m = g(x n , ym ) ,
k +1 k +1 v 0, m = g1 (ym ) , vN ,m = g 3 (ym ) , m = 0 , ... , M ,

k +1 k +1 vn ,0 = g2 (x n ) , vn ,M = g 4 (x n ) , n = 0 , ... , N ,

where

k k k 1 an +1/ 2,m = a ( 2 ( vn +1,m + vn ,m ), x n +1/ 2 , ym ) , k k k 1 an ,m +1/ 2 = a ( 2 ( vn ,m +1 + vn ,m ), x n , ym +1/ 2 ) .

Viscous incompressible fluid


Two dimensional Navier-Stokes equations in variables stream function-vorticity: 2 2 1 +u +v = + + fs (x , y, t ) , 2 2 t x y Re x x
g 0,2 g 0,1 , (x , y, 0) = x y
( x , y ) D = { 0 x l x , 0 y ly } , t 0 ,

(22)

2 2 + = (x , y, t ) , x2 y2
y u = , v x

where u, v components of velocity, Re Reynolds number, - stream function, - vorticity. Boundary conditions: 0 0 u u , , = = v v ( , ) ( , ) g y t g y t 1 3 ( 0,y ) ( lx ,y )
u v g2 (x , t ) , = 0 g 4 (x , t ) u , = v ( x ,ly ) 0 x 0 , = g 3 (y, t )

( x ,0 )

or
x 0 , = g1 (y, t )

( 0,y )

( lx ,y )

11

( x ,0 )

0 , = g (x , t ) 2

0 . = y ( , ) g x t ( x ,ly ) 4

The explicit splitting-up scheme: ds 0,m dsN ,m = 0, = 0, dt dt dsn,m sn +1,m sn 1,m sn +1,m 2sn,m + sn 1,m k = un + , ,m 2 dt 2hx Re hx

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


k sn ,m ( tk ) = n ,m .

(23)
dqn,0 dqn,M = 0, = 0, dt dt dqn,m qn,m +1 qn,m 1 qn,m +1 2qn,m + sn,m 1 k , = vn + ,m 2 dt 2hy Re hy

tkttk+k n=1, , N-1 ; m=1, , M-1, qn ,m ( tk ) = sn ,m ( tk + k ) .


The successive solution of these systems gives k +1 n ,m = qn ,m ( tk + k ) . After that, find the stream function from the finite-difference equation k +1 k +1 k +1 k +1 k +1 k +1 n n +1,m 2n ,m + n -1,m ,m +1 2n ,m + n ,m -1 k +1 + = n ,m , 2 2 hx hy n = 1,..., N 1; m = 1,..., M 1 and then compute the components of velocity: k +1 k +1 n ,m +1 n ,m 1 k +1 , un ,m = 2hy
k +1 vn ,m = k +1 k +1 n +1,m n 1,m , 2hx n = 1,..., N 1; m = 1,..., M 1 .

(24)

(25)

Systems of ordinary differential equations (23) are solved with the use of 3rd order Runge-Kutta scheme, which is defined by the following Butcher table:

0 1/2 3/4 1/2 0 2/9 3/4 1/3 4/9

12

A short description of MATLAB functions

Main function heat_1d_un heat_1d_nun heat_2d_es

stefan_1d properties cross lw_acoustics roe godunov_ acoustics pem lw_gasdynamics godunov_gasdynamics waf_gasdynamics waf_tvd_gasdynamics

Examples and auxiliary functions example4_1, f1_e41, f2_e41, fs_e41 example4_2, f1_e42, f2_e42, fs_e42 example4_3, g1_e43, g2_e43, g3_e43, g4_e43, fs_e43 example4_4, f1_e44, f2_e44, fs_e44 example5_1, f1_e51, f2_e51 example5_2, f1_e51, f2_e51 example5_3, f1_e51, f2_e51 example5_4, f1_e51, f2_e51 example5_5, f1_e51, f2_e51 example6_1, example6_2 example6_3 example6_4 example6_5, limiter_mina, limiter_supera, limiter_ultraa, limiter_vanAlbada, limiter_vanLeer, limiter_Lin example7_1, g1_e71, g2_e71, g3_e71, g4_e71, a_e71, b_e71, f_e71 example7_2, g1_e71, g2_e71, g3_e71, g4_e71, f_e71 example7_3, g1_e73, g2_e73, g3_e73, g4_e73, a_e73, b_e73, f_e73 example7_4, g1_e74, g2_e74, g3_e74, g4_e74, a_e74, f_e74 example8_1, g1_e81, g2_e81, g3_e81, g4_e81

riemann helmgoltz_2d_sor

helmgoltz_2d_fft

helmgoltz_2d_cg

poisson_2d_td

ns_2d_vsf

13

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 from scheme (1) ud kappa a nx h time tau b gamma Temperature at the instant of time tk Thermal diffusion coefficient () Thermal conductivity coefficient Number of grid nodes Space step Instant of time tk+1 Time step Parameter /h2 Parameter = 0 explicit scheme > 0 implicit scheme Type of boundary condition at x=0 x=l, respectively. = 0 boundary condition of the 1st kind = 1 boundary condition of the 2nd kind Names of m-files in which the dependence of temperature or heat flux on time is defined at x=0 and x=l, respectively. Name of m-file in which the dependence of external source on space and time is defined. Temperature at the instant of time tk+1

Input parameters

bl,br

fbl, fbr

fs

Output parameters

uu

14

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 from scheme (2) ud roc a nx h time tau gamma Temperature at the instant of time tk Array of values of c in the nodes of main grid. Array of values of a in the nodes of auxiliary grid. Number of grid nodes. Space step. Instant of time tk+1 Time step Parameter = 0 explicit scheme > 0 implicit scheme Type of boundary condition at x=0 x=l, respectively. = 0 boundary condition of the 1st kind = 1 boundary condition of the 2nd kind. Names of m-files in which the dependence of temperature or heat flux on time is defined at x=0 and x=l, respectively. Name of m-file in which the dependence of external source on space and time is defined. Temperature at the instant of time tk+1 This function can be used for solving of nonlinear equation (scheme (3)). One needs only to recalculate the values of roc, a and tau on every time step.

Input parameters

bl,br

fbl, fbr

fs

Output parameters Note

uu

15

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 from scheme (4) ud kappa a nx, ny hx, hy time tau bxl,bxr Temperature at the instant of time tk Thermal diffusion coefficient () Thermal conductivity coefficient Number of grid nodes along x y, respectively. Space steps along x y, respectively. Instant of time tk+1 Time step Type of boundary condition at x=0 x=lx, respectively. = 0 boundary condition of the 1st kind = 1 boundary condition of the 2nd kind. Names of m-files in which the dependence of temperature or heat flux on time and y is defined at x=0 and x= lx, respectively. Type of boundary condition at y=0 y=ly, respectively. = 0 boundary condition of the 1st kind = 1 boundary condition of the 2nd kind. Names of m-files in which the dependence of temperature or heat flux on time and x is defined at y=0 and y= ly, respectively. Name of m-file in which the dependence of external source on space and time is defined. Temperature at the instant of time tk+1

Input parameters

fbxl, fbxr

byl,byr

fbyl, fbyr

fs

Output parameters

uu

16

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 from scheme (5) ud, entd ro cs, cl as, al lh up nx h time tau bl,br Temperature and enthalpy at the instant of time tk Density Specific heat of solid and liquid phase, respectively. Thermal conductivity coefficient of solid and liquid phase, respectively. Latent heat of melting. Temperature of melting. Number of grid nodes. Space step. Instant of time tk+1 Time step. Type of boundary condition at x=0 x=l, respectively. = 0 boundary condition of the 1st kind = 1 boundary condition of the 2nd kind. Names of m-files in which the dependence of temperature or heat flux on time is defined at x=0 and x=l, respectively. Name of m-file in which the dependence of external source on space and time is defined. Temperature and enthalpy at the instant of time tk+1 Local fraction of solid phase at the instant of time tk+1

Input parameters

fbl, fbr

fs

Output parameters

uu, entu sf

17

function [dis,cg]=properties(kh,r,method)
Purpose Computation of dissipation coefficient and the nondimensional group velocity of harmonic wave (11) for various schemes. kh r method Product of wave number by space step Courant number Method 'crs' scheme cross 'lxw' Lax-Wendroff scheme 'roe' scheme of P. Roe 'god' Godunov scheme 'pem' PEM scheme Dissipation coefficient Nondimensional group velocity

Input parameters

Output parameters

dis cg

function [uu]=cross(ud,um,c,ro,nx,h,time,tau,bl,br,fbl,fbr)
Purpose Computation of one time step from scheme (6) ud, um c ro nx h time tau bl,br Solution at the instants of times tk-1 tk, respectivel. Speed of sound Density Number of grid nodes Space step Instant of time tk+1 Time step Type of boundary condition at x=0 x=l, respectively. = 0 boundary condition of the 1st kind = 1 boundary condition of the 2nd kind. Names of m-files in which the dependence of a solution or its derivative on time is defined at x=0 and x=l, respectively. Solution at the instant of time tk+1

Input parameters

fbl, fbr

Output parameters

uu

18

function [uu,pu]=lw_acoustics(ud,pd,imp,nx,time,r,bl,br,fbl,fbr)
Purpose Computation of one time step from LaxWendroff scheme (7) ud, pd imp nx time r bl,br Velocity and pressure at the instant of time tk Value of c Number of grid nodes Instant of time tk+1 Courant number Type of boundary condition at x=0 x=l, respectively. = 0 boundary condition on u = 1 boundary condition on p Names of m-files in which the dependence of velocity or pressure on time is defined at x=0 and x=l, respectively. Velocity and pressure at the instant of time tk+1

Input parameters

fbl, fbr

Output parameters

uu, pu

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) ud, pd um, pm imp nx time r bl,br Velocity and pressure at the instant of time tk-1 Velocity and pressure at the instant of time tk Value of c Number of grid nodes Instant of time tk+1 Courant number Type of boundary condition at x=0 x=l, respectively. = 0 boundary condition on u = 1 boundary condition on p Names of m-files in which the dependence of velocity or pressure on time is defined at x=0 and x=l, respectively. Velocity and pressure at the instant of time tk+1

Input parameters

fbl, fbr

Output parameters

uu, pu

19

function [uu,pu]=godunov_acoustics(ud,pd,imp,nx,time,r,bl,br,fbl,fbr)
Purpose Computation of one time step from Godunov scheme (9) ud, pd imp nx time r bl,br Velocity and pressure at the instant of time tk Value of c Number of grid nodes Instant of time tk+1 Courant number Type of boundary condition at x=0 x=l, respectively. = 0 boundary condition on u = 1 boundary condition on p Names of m-files in which the dependence of velocity or pressure on time is defined at x=0 and x=l, respectively. Velocity and pressure at the instant of time tk+1

Input parameters

fbl, fbr

Output parameters

uu, pu

20

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 PEM scheme (10) ua, pa Average values of velocity and pressure on every difference interval at the instant of time tk Values of velocity and pressure in every node of a grid at the instant of time tk Value of c Number of grid nodes Instant of time tk+1 Courant number Time step Parameters of PEM scheme (given in example5_5.m) Type of boundary condition at x=0 x=l, respectively. = 0 boundary condition on u = 1 boundary condition on p Names of m-files in which the dependence of velocity or pressure on time is defined at x=0 and x=l, respectively. Average values of velocity and pressure on every difference interval at the instant of time tk+1 Values of velocity and pressure in every node of a grid at the instant of time tk+1

Input parameters

ud, pd imp nx time R tau a1,a2,a3, b1,b2,b3 bl,br

fbl, fbr

Output parameters

ub, pb

uu, pu

21

function [rf,uf,pf]=riemann(x,t,r1,u1,p1,r2,u2,p2,gamma)
Purpose Computation of the exact solution of Riemann problem for an ideal gas x t r1,u1,p1 r2,u2,p2 gamma Output parameters rf,uf,pf Coordinate Time Initial density, velocity and pressure at x<0 Initial density, velocity and pressure at x>0 Adiabatic exponent Density, velocity and pressure at x and at instant of time t

Input parameters

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 LaxWendroff scheme (12) dd,ud,pd h nx r cad tp gamma bcl,bcr Density, velocity and pressure at time t=0 Space step Number of grid nodes Courant number Artificial viscosity coefficient Flow duration (approximate) Adiabatic exponent Type of boundary condition at x=0 x=l, respectively. = 0 rigid wall = 1 open boundary Real duration of the flow Density, velocity, pressure and specific internal energy at time time

Input parameters

Otput parameters

time d,u,p,e

22

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 Godunov scheme (13) dd,ud,pd h nx r tp gamma bcl,bcr Density, velocity and pressure at time t=0 Space step Number of grid nodes Courant number Flow duration (approximate) Adiabatic exponent Type of boundary condition at x=0 x=l, respectively. = 0 rigid wall = 1 open boundary Real duration of the flow Density, velocity, pressure and specific internal energy at time time

Input parameters

Otput parameters

time d,u,p,e

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 WAF scheme (15).

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

23

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 TVD version of the WAF scheme dd,ud,pd h nx r tp gamma bcl,bcr Density, velocity and pressure at time t=0 Space step Number of grid nodes Courant number Flow duration (approximate) Adiabatic exponent Type of boundary condition at x=0 x=l, respectively. = 0 rigid wall = 1 open boundary Name of m-file in which a limiter function is defined. Several limiters are enclosed. Real duration of the flow Density, velocity, pressure and specific internal energy at time time

Input parameters

limiter

Otput parameters

time d,u,p,e

24

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. f ac bc lx, ly nx, ny g1, g3 Name of m-file in which the right-hand side function f(x, y) is defined. Name of m-file in which the coefficient a(x, y) is defined. Name of m-file in which the coefficient b(x, y) is defined. Domain size in x y directions, respectively. Number of grid nodes in x y directions, respectively. Names of m-files in which the dependence of a solution on y is defined at x=0 and x= lx, respectively. Names of m-files in which the dependence of a solution on x is defined at y=0 and y=ly, respectively. Approximate solution Number of iterations Iterative process is completed when either relative error of approximate -5 solution becomes less then 10 , or number of iterations reaches the value 3max(nx, ny).

Input parameters

g2, g4

Output parameters

u k

Note

25

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, FFTbased method. f a B lx, ly nx, ny g1, g3 Name of m-file in which the right-hand side function f(x, y) is defined. Name of m-file in which the coefficient a(x, y) is defined. Name of m-file in which the coefficient b(x, y) is defined. Domain size in x y directions, respectively. Number of grid nodes in x y directions, respectively. Names of m-files in which the dependence of a solution on y is defined at x=0 and x= lx, respectively. Names of m-files in which the dependence of a solution on x is defined at y=0 and y=ly, respectively. Approximate solution FFT is applied in x direction, therefore, p one should set nx=2 +1 for the most efficient computation.

Input parameters

g2, g4

Output parameters Note

26

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. up f a b lx, ly nx, ny g1, g3 Initial approximation Name of m-file in which the right-hand side function f(x, y) is defined. Name of m-file in which the coefficient a(x, y) is defined. Name of m-file in which the coefficient b(x, y) is defined. Domain size in x y directions, respectively. Number of grid nodes in x y directions, respectively. Names of m-files in which the dependence of a solution on y is defined at x=0 and x= lx, respectively. Names of m-files in which the dependence of a solution on x is defined at y=0 and y=ly, respectively. Approximate solution Number of iterations Iterative process is completed when relative error of approximate solution -5 becomes less then 10 . FFT is applied in x direction, therefore, one should set nx=2p+1 for the most efficient computation.

Input parameters

g2, g4

Output parameters

u it

Note

27

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

Purpose

Computation of a solution of nonlinear equation (20) with Dirichlet boundary conditions, method of time development (21) up f a lx, ly nx, ny g1, g3 Initial approximation Name of m-file in which the right-hand side function f(x, y) is defined. Name of m-file in which the coefficient a(u, x, y) is defined. Domain size in x y directions, respectively. Number of grid nodes in x y directions, respectively. Names of m-files in which the dependence of a solution on y is defined at x=0 and x= lx, respectively. Names of m-files in which the dependence of a solution on x is defined at y=0 and y=ly, respectively. Approximate solution Number of iterations Iterative process is completed when relative error of approximate solution becomes less then 10-5.

Input parameters

g2, g4

Output parameters

u k

Note

28

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 Re tp lx, ly nx, ny bxl,bxr

Components of velocity and vorticity at time t=0. Reynolds number Flow duration (approximate) Domain size in x y directions, respectively. Number of grid nodes in x y directions, respectively. Type of boundary condition on v at x=0 and x=lx, respectively: =0 value of velocity is assigned =1 v/y is zero. Type of boundary condition on u at y=0 and y= ly, respectively: =0 value of velocity is assigned, =1 u/x is zero. Names of m-files in which the dependence of v on y and time is defined at x=0 and x= lx, respectively. Names of m-files in which the dependence of u on x and time is defined at y=0 y=ly, respectively. Real duration of the flow Components of velocity and vorticity at time time. Stream function at time time. For normal to the boundaries components of velocity the following conditions are assumed: u=0 at x=0 and x=lx, v=0 at y=0 and y=ly

byl,byr

g1, g3

g2, g4

Output parameters

time u,v,w psi

Note

29

References
1. Concus P. and Golub G. H. Use of fast direct methods for the efficient numerical solution of non-separable elliptic 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.

30

You might also like