0% found this document useful (0 votes)
28 views

Lab_12

Uploaded by

Alien From Mars
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Lab_12

Uploaded by

Alien From Mars
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab-12

Consider the convection equation


f f
+u =0
t x
For 0 ≤ 𝑥 ≤ 6, 0 ≤ 𝑡 ≤ 𝑡𝑚𝑎𝑥
Let the initial condition be

1.20

1.00

0.80

0.60
T

0.40

0.20

0.00
0.00 1.00 2.00 3.00 4.00 5.00 6.00
x

1. It is proposed to use the Lax finite difference approximations given by:


𝑇 𝑛+1 −0.5(𝑇 𝑛 −𝑇 𝑛 ) 𝑓 𝑛 −𝑇 𝑛+1
𝑇𝑡 = 𝑖 𝑖+1 𝑖−1
, 𝑇𝑥 = 𝑖+12Δ𝑥𝑖−1 ,
Δ𝑡
The above when substituted in the governing differential equation gives the following nodal
equation
𝑇𝑖𝑛+1 = 0.5(𝑇𝑖+1
𝑛 𝑛
+ 𝑇𝑖−1 𝑛
) − 𝐶(𝑇𝑖+1 𝑛
− 𝑇𝑖−1 )
𝑢𝛥𝑡
Where 𝐶 = 2𝛥𝑥. Solve the equation using Lax scheme for t = 0 to tmax = 4 with C = 1, 0.5
and 0.2 with 31 spatial nodes and u = 1. Compare the numerical solutions with analytical
solutions at t = 2 and t = 4.

Analytical Solution
1.20
1.00
0.80
0.60 Analytical
T

0.40 Analytical
0.20 Analytical
0.00
0.00 2.00 4.00 6.00
x

2. Now redo the same problem with first order upwind scheme for the same values of the
parameters.
3. Finally, repeater the same problem with Lax Wendroff Scheme

Code
$DEBUG
PROGRAM MAIN
implicit double precision(a-h,o-z)
Dimension x(200),xx(200),T0(200),T(200),T_ana(200)
Open(unit=11,file='Conv_Eq.in')
Open(unit=12,file='Conv_Eq.out')
Open(unit=13,file='Conv_Eq.Txt')
Read (11,*) Tin, Cee,Tmax,Inc,dInc
Read (11,*) TLeft,TRight,U
Read (11,*) Nodes,el
write (12,*)'Tin, Cee,Tmax,Inc,dInc',Tin, Cee,Tmax,Inc,dInc
write (12,*)'TLeft,TRight,U',TLeft,TRight,U
write (12,*) 'Nodes,el',Nodes,el

C ****** COMPUTE Coordinates ****


delx=el/float(Nodes-1)
safety=0.01
x(1)=0.
xx(1)=x(1)
DO I=2,Nodes
x(i)=x(i-1)+ delx
xx(i)=x(i)
End Do
write(12,*)'X values'
WRITE(12,30)(X(I),I=1,Nodes)
30 FORMAT('X-Values OF NODES',/,11(1X,F11.4,1X))

C ****** TEMPERATURE INITIALIZATION ***


tt=0.
write(13,*)tt

DO I=1,Nodes
If(x(i).le.1.0) Then
T0(i)=x(I)
T_ana(i)=T0(I)
Elseif (x(i).le.2.0) Then
T0(i)=2.0-x(I)
T_ana(i)=T0(I)
Else
T0(i)=0.
T_ana(i)=T0(I)
Endif
write(13,20)x(i),T0(I),T_ana(I)
EndDo
T(1)=0.
T(nodes)=0.
delt=Cee*delx/U
tt=Tin+delt
Iprint=0
NN=0

C ******COMPUTATION OF TEMPERATURES ****


10 IPrint=Iprint+1
NN=NN+1
xx(1)=xx(1)+U*Delt
xx(Nodes)=xx(Nodes)+U*Delt
DO I=2,Nodes-1
T(i)=0.5*(T0(i+1)+T0(i-1))-Cee/2*(T0(i+1)-T0(i-1))
xx(i)=xx(i)+U*Delt
EndDo

If(Iprint.eq.Inc) then
write(13,*)tt

C *** Analytical Solution


Do I = 1,Nodes
Temp=x(i)-xx(i)
If ((I-NN) .le. 1)Then
T_ana(i)=0.
Elseif ((I-NN) .le. 11) Then
T_ana(i)=T0(I-1)
Else
T_ana(i)=0.
Endif
write(13,20)x(i),T(I),T_ana(I)
20 Format (3(1x,e15.7))
Enddo
Inc=Inc+dInc
Else
Endif

C ****** Check and Update


tt=tt+delt
If(tt.ge.Tmax) Then
Stop
Else
Do I = 1,Nodes
T0(i)=T(i)
End Do
Goto 10
Endif
C ******
END

You might also like