ch5examples.doc

advertisement
Example 5.2. Use the two-step Lax-Wendroff method to solve Eq.(5.1.1) subject to the
following initial and boundary conditions
0  x 1
sin 2x
t  0,
u
(E5.2.1)
1 x  5
0
x  0,
u0
at t  4 for x  0.01 and, t  0.001, 0.01, and 0.02 , c  1 . Compare your solution with
t  x  t 1
sin 2 ( x  t )
(E5.2.2)
u
otherwise
 0
and determine the percentage error. Use second-order extrapolation on the numerical
boundary condition
(E5.2.3)
u In  2u In1  u In2 .
at x = 5
Solution
The computer program for this problem is given in the accompanying CD-ROM. Table
E5.1 allows a comparison of the numerical and analytical solutions (Max Error) as a
function of Courant number  . As discussed in Section 5.7, Eq. (5.7.20), stability
requires   1.
x  0.01
Max Error (t = 4)
  0.1
 1
0.0995775
0.0002478
Table E5.1
 2
Divergence
Example 5.3. Repeat Example 5.2 using the MacCormack method
Solution
x  0.01
  0.1
 1
 2
Max Error (t = 4)
0.0995605
0.0000018
Divergence
Table E5.2
Example 5.4. Solve the inviscid Burger’s equation, Eq.(4.2.8), subject to the initial and
boundary conditions
t  0,
u ( x,0)  x
0  x 1
(E5.4.1)
x  0,
u (0, t )  0
with the Beam-Warming method (one step trapezoidal scheme). Take x  0.02 and
t  0.01 and perform the calculations for 200 time steps. Use backward differencing for
the numerical boundary condition at x = 1.
Solution
First rewrite Burger’s equation (4.2.8) in vector form similar to Eq.(5.1.2),
u  u 2 2

0
(E5.4.2)
t
x
and then substitute


(E5.4.3)
E  u2 2 , A  u
in Eq.(5.4.8). The finite difference approximation to this equation is given by Eq. (5.4.9)
which is applicable for all i except at the outflow boundary, i = I, at which we represent

with backward differencing and write
x
t u In u In  u In1 u In1
t n
(E5.4.4)
u In 

E I  E In1
x
2
x


Figure E5.1 shows the solutions at t = 0, 0.5, 1, 1.5, 2
1
0.9
t=0
0.8
0.7
t=0.5
0.6
u 0.5
t=1
0.4
t=1.5
t=2
0.3
0.2
0.1
0
0
0.2
0.4
0.6
x
Figure E5. 1
0.8
1
Example 5.5. Use the finite volume method with (a) central and (b) upwind differencing
to solve the one-dimensional steady convection and diffusion equation
d
u   d  v d 
0 xL
(E5.5.1)
dx
dx  dx 
 ( 0)  1  ( L )  0
where u  2.5, and v  0.1 . Compare your results with the exact solution  (x)
 ( x)   (0) exp( ux / v)  1
(E5.5.2)

 ( L)   (0) exp( uL / v)  1
Solution
(a) Central differences:
First integrate Eq.(E5.5.1) [see Eq. (2.1.24)] in the interval  i , xi 1 / 2  x  xi 1 / 2 , for
the grid shown in Fig. E5.2
. . . . .
u
i - 1/2
1
i + 1/2
i
N
i
Figure E5.2 Grid for finite volume
d  d 
 dx u dx   dx  v dx dx
d
i
(E5.5.3)
i
Applying central differences to the above equation yields,
u i 1 / 2  u i1 / 2   v d    v d 
 dx  i 1 / 2  dx  i 1 / 2
and
  i
   i 1
  i
   i 1
u i 1 / 2 i 1
 u i 1 / 2 i
 vi 1 / 2 i 1
 vi 1 / 2 i
2
2
x
x
(E5.5.4)
(E5.5.5)
for 1  i  N . For i  1 and i  N , (E5.5.4) becomes
u11 / 2
 2  1
2
 u11 / 2 (0)  v11 / 2
 2  1
x
 v11 / 2
1   (0)
x / 2
(E5.5.6)
and
u N 1 / 2 ( L)  u N 1 / 2
 N   N 1
2
 v N 1 / 2
 ( L)   N
x / 2
 v N 1 / 2
respectively. .
Rearrange Eqs. (E5.5.6), (E5.5.5) and (E5.5.7) in the form
 N   N 1
x
(E5.5.7)
v
2v
 u11 / 2 v11 / 2 2v11 / 2 
u






1   11 / 2  11 / 2  2   u11 / 2  11 / 2  (0)
x
x 
x 
x 
 2
 2

(E5.5.8a)
u
v
v
v
 u i 1 / 2 vi 1 / 2 
u

u



 i 1   i 1 / 2  i 1 / 2  i 1 / 2  i 1 / 2  i   i 1 / 2  i 1 / 2  i 1  0
2
x 
2
x
x 
x 

 2
 2
(E5.5.8b)
2v
v
2v
 u N 1 / 2 v N 1 / 2 
u





 N 1   N 1 / 2  N 1 / 2  N 1 / 2  N    u N 1 / 2  N 1 / 2  ( L)
2
x 
2
x
x 
x 



(E5.5.8c)
The above system has a tridiagonal form and is solved with the Thomas algorithm given
in Table 4.7.
Figure E5.3 compares the numerical and exact solutions for N = 10 and shows that the
numerical solutions oscillate in the region 0.7  x  1 .
(b) Upwind method
Unlike central differences, the upwind method represents the convective term with the
values from upstream. Since u is positive, we can write
u i 1 / 2  ui 1 / 2i ,
u i1 / 2  ui1 / 2i1
(E5.5.9)
and Eq. (E5.5.4) is represented by
ui 1 / 2i  ui 1 / 2i 1  vi 1 / 2
At nodes 1 and N, Eq.(E5.5.4) becomes
u11 / 21  u11 / 2 (0)  v11 / 2
i 1  i
x
 2  1
and
u N 1 / 2 N  u N 1 / 2 N 1  v N 1 / 2
x
 vi 1 / 2
 v11 / 2
 ( L)   N
i  i 1
x
1   (0)
x / 2
 v N 1 / 2
 N   N 1
x / 2
x
Express Eqs.(E5.5.10-12) in a tridiagonal form and solve
v
v
v
v




 u11 / 2  11 / 2  11 / 2 1  11 / 2  2   u11 / 2  11 / 2  (0)
x
x / 2 
x
x / 2 


v
v
v
v




  u i 1 / 2  i 1 / 2  i 1   u i 1 / 2  i 1 / 2  i 1 / 2  i  i 1 / 2  i 1  0
x 
x
x 
x


v
2v
v
2v




  u N 1 / 2  N 1 / 2  N 1   u N 1 / 2  N 1 / 2  N 1 / 2  N  N 1 / 2  ( L)
x 
x
x 
x


(E5.5.10)
(E5.5.11)
(E5.5.12)
(E5.5.13a)
(E5.5.13b)
(E5.5.13c)
The calculated results obtained with the Thomas algorithm are given below. Note that
while the upwind method produces smooth solutions in the region 0.7  x  1 , the
solutions do not agree well with the exact solutions in that region. This is because the
upwind scheme is first-order accurate.
1.4
Center differences
1.2
1
0.8

Exact solution
0.6
0.4
Upwind method
0.2
0
0
0.2
0.4
0.6
0.8
x
Fig. E5.3 Comparison of numerical and exact solutions
1
(c) Problem 4.8 Lax wendroff scheme: On numerical boundary condition
 using 2nd order extrapolation
u In  2u In1  u In2
 using 1st order backward difference formula
u In  u In1
Problem 4.10 MacCormack Method for Burger’s equation
u E
u2

 q where E 
t x
2
MacCormack’s scheme   t / x
Predictor:
u i  u in   ( Ein1  Ein )  tqin
ui  uin   ( Ei  Ei 1 )  tqi where Ei  E (ui )
1
u in 1  (u i  u i )
Updating:
2
On numerical boundary condition
 using 2nd order extrapolation
u In  2u In1  u In2
 using 1st order backward difference formula
u In  u In1
Corrector:
Problem 4.11 The Beam-Warming method (trapezoidal scheme   1 / 2,   0 )
E n
E n
 t  n  n
n
1

A

Q



t
A

where


2 x
x
u
(4.5.25)
for A = c = 1
DX = 0.100 DT =0.10000 tau = 1.000
t = 0.0000
0.00000 0.58779 0.95106 0.95106
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000
t = 0.5000
0.00000 0.01071 -0.12269 -0.19260
-0.39371 -0.86338 -0.83026 -0.56509
-0.00121 -0.00040 -0.00013 -0.00004
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000
t = 1.0000
0.00000 -0.08647 0.01828 0.01559
0.68453 1.13322 1.09906 0.56161
-0.16349 -0.08659 -0.04289 -0.02008
-0.00003 -0.00001 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.58779
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
-0.58779
0.00000
0.00000
0.00000
0.00000
-0.95106
0.00000
0.00000
0.00000
0.00000
-0.95106
0.00000
0.00000
0.00000
0.00000
-0.58779
0.00000
0.00000
0.00000
0.00000
0.05133
-0.31191
-0.00001
0.00000
0.00000
0.42874
-0.14935
0.00000
0.00000
0.00000
0.93272
-0.06455
0.00000
0.00000
0.00000
0.95622 0.88302 0.40451
-0.02583 -0.00973 -0.00349
0.00000 0.00000 0.00000
0.00000 0.00000 0.00000
0.00000 0.00000 0.00000
0.13231
-0.10601
-0.00896
0.00000
0.00000
0.02445
-0.55712
-0.00384
0.00000
0.00000
-0.27691
-0.69623
-0.00158
0.00000
0.00000
-0.27292 -0.08301 0.19265
-0.61514 -0.44749 -0.28461
-0.00063 -0.00025 -0.00009
0.00000 0.00000 0.00000
0.00000 0.00000 0.00000
0.00000
t = 1.5000
0.00000
-0.15018
-0.51766
-0.00682
0.00000
0.00000
t = 2.0000
0.00000
0.00672
1.10741
-0.16418
-0.00024
0.00000
t = 3.0000
0.00000
-0.05271
0.36615
0.84849
-0.15789
-0.00050
t = 3.5000
0.00000
0.02317
-0.14573
-0.34577
-0.36180
-0.01436
t = 4.0000
0.00000
0.04772
-0.02787
0.25578
0.61507
-0.13851
-0.00447
-0.34301
-0.57892
-0.00318
0.00000
-0.06088
-0.39063
-0.50964
-0.00143
0.00000
0.01397
-0.04190
-0.38704
-0.00063
0.00000
-0.05921
0.58822
-0.26409
-0.00027
0.00000
-0.16793
1.08462
-0.16567
-0.00011
0.00000
0.00194
1.13609
-0.09699
-0.00005
0.00000
0.17045 0.10745 -0.01661
0.76282 0.21424 -0.25471
-0.05356 -0.02811 -0.01412
-0.00002 -0.00001 0.00000
0.00000 0.00000 0.00000
-0.01286
0.07856
0.91564
-0.10240
-0.00011
0.07625
0.17071
0.49485
-0.06060
-0.00005
0.02196
0.15418
0.04460
-0.03425
-0.00002
-0.06943
-0.10764
-0.29317
-0.01858
-0.00001
0.03628
-0.46382
-0.46826
-0.00972
0.00000
0.08308
-0.56465
-0.50114
-0.00491
0.00000
-0.07392
-0.22626
-0.44352
-0.00241
0.00000
-0.16456
0.38674
-0.34694
-0.00115
0.00000
-0.08539
0.91984
-0.24759
-0.00054
0.00000
-0.02575
0.01908
0.35655
0.55399
-0.10659
-0.05036
0.05670
0.01604
0.20857
-0.06881
0.05643
0.04992
-0.43510
-0.09084
-0.04269
0.08365
0.05334
-0.68507
-0.29324
-0.02556
-0.04793
0.02131
-0.55952
-0.39083
-0.01482
-0.07911
-0.10899
-0.11681
-0.40348
-0.00832
0.03089
-0.23911
0.42387
-0.36168
-0.00458
0.05063
-0.17926
0.83026
-0.29421
-0.00239
-0.03753
0.09726
0.97153
-0.22217
-0.00135
-0.01418
0.03332
-0.31653
0.14354
-0.37033
0.05158
-0.02082
-0.23444
0.60027
-0.33381
0.04437
-0.03640
0.08428
0.86929
-0.27541
-0.07486
-0.01269
0.39364
0.89672
-0.21193
-0.07017
-0.00966
0.42975
0.72193
-0.15451
0.06048
0.00049
0.13038
0.43532
-0.10671
0.07241 -0.03195 -0.04869
0.07452 0.14574 0.07376
-0.32413 -0.65275 -0.66204
0.13208 -0.11856 -0.28374
-0.07179 -0.04462 -0.02991
0.02611
-0.01452
0.12776
-0.17428
0.34499
0.01280
-0.02513
0.22422
-0.56213
0.07924
-0.06842
0.01561
0.10979
-0.70068
-0.13600
-0.03397
0.02030
-0.16461
-0.52588
-0.27134
0.08348
-0.00658
-0.36484
-0.12410
-0.34015
0.05787
-0.00502
-0.29025
0.33656
-0.33932
-0.06573
0.00495
0.03586
0.69448
-0.31688
-0.06560
-0.03430
0.37937
0.85633
-0.25169
0.03260
-0.08158
0.48281
0.81180
-0.21331
0.40000
0.00000
0.00000
0.00000
0.00000
0.50000
0.00000
0.00000
0.00000
0.00000
0.60000
0.00000
0.00000
0.00000
0.00000
0.70000
0.00000
0.00000
0.00000
0.00000
0.80000
0.00000
0.00000
0.00000
0.00000
0.90000
0.00000
0.00000
0.00000
0.00000
0.33393
0.00000
0.00000
0.00000
0.00000
0.41419
0.00000
0.00000
0.00000
0.00000
0.50865
0.00000
0.00000
0.00000
0.00000
0.55686
0.00000
0.00000
0.00000
0.00000
0.73933
0.00000
0.00000
0.00000
0.00000
0.56794
0.00000
0.00000
0.00000
0.00000
0.25297
0.18472
0.49254
0.08289
0.63763
0.63537
For Burger’s equation
DX = 0.100 DT =0.20000 tau = 2.000
Time = 0.0000000E+00
0.00000 0.10000 0.20000 0.30000
1.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000
Time = 0.2000000
0.00000 0.08333 0.16668 0.24988
1.25557 0.62779 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000
Time = 0.8000000
0.00000 0.05536 0.11271 0.15809
0.14903 0.48303
0.00000 0.00000
0.00000 0.00000
0.00000 0.00000
0.00000
Time = 1.000000
0.00000 0.04952
0.36726 0.06663
0.00000 0.00000
0.00000 0.00000
0.00000 0.00000
0.00000
Time = 2.000000
0.00000 0.02640
0.21172 0.66651
0.00000 0.00000
0.00000 0.00000
0.00000 0.00000
0.00000
Time = 3.000000
0.00000 0.00465
0.13635 0.00835
0.90725 1.27812
0.00000 0.00000
0.00000 0.00000
0.00000
Time = 3.600000
0.00000 -0.00581
0.43105 0.13955
-0.00021 0.01661
0.00000 0.00000
0.00000 0.00000
0.00000
Time = 3.800000
0.00000 -0.00859
0.47237 0.24128
-0.00021 0.00002
0.00000 0.00000
0.00000 0.00000
0.00000
Time = 4.000000
0.00000 -0.01097
0.45787 0.34864
-0.00021 0.00002
0.00000 0.00000
0.00000 0.00000
0.00000
1.27230
0.00000
0.00000
0.00000
0.90054
0.00000
0.00000
0.00000
0.09391
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.10367
0.69757
0.00000
0.00000
0.00000
0.13172
1.31215
0.00000
0.00000
0.00000
0.25467
0.68473
0.00000
0.00000
0.00000
0.09427
0.03215
0.00000
0.00000
0.00000
0.49810
0.00000
0.00000
0.00000
0.00000
0.07597
0.00000
0.00000
0.00000
0.00000
0.40646
0.00000
0.00000
0.00000
0.00000
0.73759
0.00000
0.00000
0.00000
0.00000
0.09483 -0.00906 0.23070 -0.20037
0.59685 0.13567 0.00275 0.05879
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.26475
0.80323
0.00000
0.00000
0.00000
0.47676
1.30530
0.00000
0.00000
0.00000
0.23436
0.57692
0.00000
0.00000
0.00000
0.02363
0.01636
0.00000
0.00000
0.00000
0.08889 -0.07678 0.15637
0.06040 0.46682 0.72392
0.47277 0.00764 0.00000
0.00000 0.00000 0.00000
0.00000 0.00000 0.00000
-0.14885
0.33948
0.00000
0.00000
0.00000
0.04981
0.02303
0.00000
0.00000
0.00000
0.09759
-0.00012
0.00000
0.00000
0.00000
0.39781
0.00020
0.00000
0.00000
0.00000
0.42866
0.09443
0.00000
0.00000
0.00000
0.07721
0.00684
0.57875
0.00000
0.00000
-0.09891
0.00833
1.30559
0.00000
0.00000
0.14081
0.22729
0.80148
0.00000
0.00000
-0.12217
0.68051
0.05792
0.00000
0.00000
0.07482
0.57737
0.00000
0.00000
0.00000
0.00614
0.11763
0.00000
0.00000
0.00000
0.09991
0.00146
0.00000
0.00000
0.00000
0.39453
0.00008
0.00000
0.00000
0.00000
0.07200
0.02367
0.05732
0.00000
0.00000
-0.10591
0.00112
0.79877
0.00000
0.00000
0.13899
0.06413
1.30608
0.00000
0.00000
-0.11544
0.47955
0.58132
0.00000
0.00000
0.08185
0.72137
0.01684
0.00000
0.00000
0.00711
0.32586
0.00000
0.00000
0.00000
0.04178
0.02063
0.00000
0.00000
0.00000
0.29481
0.00009
0.00000
0.00000
0.00000
0.06605
0.06573
0.00027
0.00000
0.00000
-0.11317
0.00164
0.14285
0.00000
0.00000
0.13867
0.00825
1.00443
0.00000
0.00000
-0.10941
0.23305
1.23409
0.00000
0.00000
0.08813
0.68414
0.37554
0.00000
0.00000
0.01042
0.57145
0.00316
0.00000
0.00000
0.01425
0.11374
0.00000
0.00000
0.00000
0.18697
0.00127
0.00000
0.00000
0.00000
Download