Professional Documents
Culture Documents
ZALIZNIAK
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
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)
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
(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 ) )
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
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
(6)
( )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
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
(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 =
(12
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
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
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)
where
c1 =
a a , c2 = 2 , c3 = 2 ( c1 + c2 ) b . 2 hy hx
(17)
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)
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
bn,m ,
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
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.
(20)
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)
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
(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
(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
(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:
12
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
Input parameters
bl,br
fbl, fbr
fs
Output parameters
uu
14
Input parameters
bl,br
fbl, fbr
fs
uu
15
Input parameters
fbxl, fbxr
byl,byr
fbyl, fbyr
fs
Output parameters
uu
16
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
Input parameters
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
Input parameters
Otput parameters
time d,u,p,e
22
Input parameters
Otput parameters
time d,u,p,e
Input and output parameters have the same meaning as for the function lw_gasdynamics.
23
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
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
Intput parameters
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
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