You are on page 1of 25

# COMPUTER ASSIGNMENT#2

(Implicit Algorithm)

SUBMITTED BY
MD AYAZ
PhD STUDENT
Y9103068

Problem No: 1
Write an implicit code for the convective diffusion equation on rectangular grid with given
parameters and following schemes:
1. Simple upwind
2. Quick

y

= 0 =0

y = V*t U = 1 m/s =0 1m
= 1 V = 1 m/s
= 1 = 0 x
x = U*t
2m
Initial condition: = 0 throughout the domain
Discretized Governing Equation is given by

Given Parameters are:
Nx = Ny = 50,100
Lx = 2m Ly = 1m
U = 1 m/s V = 1 m/s
D = 0.01

Simple Upwind
FORTRAN code for Simple upwind (Implicit) is given below:

real phi(500,500),phi1(500,500),u(500,500),v(500,500),
1 B(500,500),y(500)
real A(500,500),C(500,500),LHS(500,500),RHS(500,500),
1 R(500,500),x(500)
double precision::lx,ly,delx,dely,sum,cc,l,D,t
integer::nx,ny
delt=0.05
D=0.01
lx=2.
ly=1.
ccccccccccccccccccccccccccccccccccc
write(*,*)'enter the value of nx,ny'
c2 format(2f5.2,2i3)
delx=lx/dfloat(nx)
dely=ly/dfloat(ny)
write(*,*)delx,dely
t=0
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c initilization of array
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
do 10 i=2,nx+1
do 10 j=2,ny+1
phi(i,j)=0.0
10 continue
cccccccccccccccccccccccc
do 20 i=1,nx+2
do 20 j=1,ny+2
u(i,j)=1.
v(i,j)=1.
20 continue
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c initial conditions for fictitious cells
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c left boundary
do 11 j=2,ny+1
if((j-1.5)*dely.le.t)then
phi(1,j)=2.-phi(2,j)
else
phi(1,j)=0.-phi(2,j)
end if
c right boundary
phi(nx+2,j)=phi(nx+1,j)
11 continue
ccccccccccccccccccc
do 12 i=2,nx+1
c bottom boundary
if((i-1.5)*delx.gt.t)then
phi(i,1)=0.-phi(i,2)
else
phi(i,1)=2.-phi(i,2)
end if
12 continue
c top boundary
do 33 i=2,nx+1
33 phi(i,ny+2)=phi(i,ny+1)
cccccccccccccccccccccccccccccccccc
phi(1,1)=0.0
phi(1,ny+2)=0.0
phi(nx+2,ny+2)=0.0
phi(nx+2,1)=0.0
cccccccccccccccccccccccccccccccccccccccccccc
c guess for n+1 th level be the value of nth level
ccccccccccc
phi1(1,1)=0.0
phi1(1,ny+2)=0.0
phi1(nx+2,ny+2)=0.0
phi1(nx+2,1)=0.0
do 51 i=1,nx+2
do 51 j=1,ny+2
phi1(i,j)=phi(i,j)
51 continue
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c STARTING TIME COUNTER
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
n=0
170 t=t+delt
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
c Starting Gauss Seidal
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
160 n=n+1
sum=0.0
ccccccccccccccccccccccccccccccccccccccccccccccc
c sweeping all cells and updating values
ccccccccccccccccccccccccccccccccccccccccccccccc
C Real cells
ccccccccccccccccc
ccccccccccccccccc
do 60 i=2,nx+1
do 60 j=2,ny+1
A(i,j)=delx*dely/delt+0.5*(u(i+1,j)+u(i,j))*dely+2*D*delx/dely+
1 2*D*dely/delx+0.5*(v(i,j+1)+v(i,j))*delx
B(i,j)=0.5*(u(i-1,j)+u(i,j))*dely+D*dely/delx
C(i,j)=0.5*(v(i,j-1)+v(i,j))*delx+D*delx/dely
LHS(i,j)=phi1(i,j)*A(i,j)-phi1(i-1,j)*B(i,j)-phi1(i,j-1)*C(i,j)-
1 phi1(i+1,j)*D*(dely/delx)-phi1(i,j+1)*D*(delx/dely)

RHS(i,j)=phi(i,j)*delx*dely/delt
R(i,j)=RHS(i,j)-LHS(i,j)
sum=sum+R(i,j)**2
60 continue
cc updation
do 70 i=2,nx+1
do 70 j=2,ny+1
cc=delx*dely/delt+0.5*(u(i+1,j)+u(i,j))*dely+2*D*delx/dely+
1 2*D*dely/delx+0.5*(v(i,j+1)+v(i,j))*delx
phi1(i,j)=phi1(i,j)+R(i,j)/cc
70 continue
ccccccccccccccccccccccccccccccccccccccccccccccccccc
C Fictitious cells
ccccccccccccccccccccccccccccc
ccccccccccccccccccccccccccccc
c left boundary
ccccccccccccccc
do 80 j=2,ny+1
LHS(1,j)=0.5*(phi1(1,j)+phi1(2,j))
if((j-1.5)*dely.le.t)then
RHS(1,j)=1.
else
RHS(1,j)=0.
end if

R(1,j)=RHS(1,j)-LHS(1,j)
sum=sum+R(1,j)**2
80 continue
cc updation
cc=0.5
do 90 j=2,ny+1
phi1(1,j)=phi1(1,j)+R(1,j)/cc
90 continue
cccccccccccccccccccccccccccccccccccc
c right boundary
ccccccccccccccccccc
do 100 j=2,ny+1
LHS(nx+2,j)=(phi1(nx+2,j)-phi1(nx+1,j))/delx
RHS(nx+2,j)=0.0
R(nx+2,j)=RHS(nx+2,j)-LHS(nx+2,j)
sum=sum+R(nx+2,j)**2
100 continue
cc updation
cc=1.0/delx
do 110 j=2,ny+1
phi1(nx+2,j)=phi1(nx+2,j)+R(nx+2,j)/cc
110 continue
ccccccccccccccccccccccccccccccccccccc
c top boundary
cccccccccccccccccc
do 120 i=2,nx+1
LHS(i,ny+2)=(phi1(i,ny+2)-phi1(i,ny+1))/dely
RHS(i,ny+2)=0.0
R(i,ny+2)=RHS(i,ny+2)-LHS(i,ny+2)
sum=sum+R(i,ny+2)**2
120 continue
cc updation
cc=1.0/dely
do 130 i=2,nx+1
phi1(i,ny+2)=phi1(i,ny+2)+R(i,ny+2)/cc
130 continue
ccccccccccccccccccccccccccccccccccccc
c bottom boundary
cccccccccccccccccccc
do 140 i=2,nx+1
LHS(i,1)=0.5*(phi1(i,1)+phi1(i,2))
if((i-1.5)*delx.gt.t)then
RHS(i,1)=0.
else
RHS(i,1)=1.
end if
R(i,1)=RHS(i,1)-LHS(i,1)
sum=sum+R(i,1)**2
140 continue
cc updation
cc=0.5
do 150 i=2,nx+1
phi1(i,1)=phi1(i,1)+R(i,1)/cc
150 continue
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c residue check for inner loop
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
l=sqrt(sum/(nx*ny))
if(l.GT.0.000001)goto 160
write(*,*)l,n
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c conversion of value of phi1 to phi
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
do i=1,nx+2
do j=1,ny+2
phi(i,j)=phi1(i,j)
end do
end do
ccccccccccccccccccccccccccccccccccccccccccccccccccc
c check for time counter
ccccccccccccccccccccccccccccccccccccccccccccccccccc
if(t.le.1)then
write(*,*)t
goto 170
end if

cccccccccccccccccccccccccccccccccccccccccccccccccccc
c printing of final value
cccccccccccccccccccccccccccc
do i=2,nx+1
write(*,9)(phi(i,j),j=2,ny+1)
9 format(1x,20(3x,f12.7))
end do
ccccccccccccccccc
do 401 i=2,nx+1
do 401 j=2,ny+1
x(i)=(i-1.5)*delx
y(j)=(j-1.5)*dely
401 continue
cccccccccccccccccccccccccc
cccccccccccccccccc
open(17,file='sapna.dat',status='old')

write(17,*)'zone i=',nx,'j=',ny
do 40 j=2,ny+1
do 40 i=2,nx+1
40 write(17,*) x(i),y(j),phi1(i,j)
stop
end

Profile of on x-y at t = 1 sec (Simple Upwind Scheme) for different time steps:

Figure:1 Profile of Phi (Simple Upwind Scheme) for grid size (100 x 100), t = 0.001sec

Figure:2 Profile of Phi (Simple Upwind Scheme) for grid size (100 x 100), t = 0.002sec

Figure:3 Profile of Phi (Simple Upwind Scheme) for grid size (100 x 100), t = 0.004sec

Figure:4 Profile of Phi (Simple Upwind Scheme) for grid size (100 x 100), t = 0.01sec

Figure:5 Profile of Phi (Simple Upwind Scheme) for grid size (100 x 100), t = 0.02sec

Figure:6 Profile of Phi (Simple Upwind Scheme) for grid size (100 x 100), t = 0.05sec
QUICK Scheme
FORTRAN code for QUICK (Implicit) is given below:
real phi(500,500),phi1(500,500),u(500,500),v(500,500),
1 B(500,500),y(500)
real A(500,500),C(500,500),LHS(500,500),RHS(500,500),
1 R(500,500),x(500)
double precision::sum,l
real::lx,ly,delx,dely,D,t,cc
integer::nx,ny
delt=0.05
D=0.01
lx=2.
ly=1.
ccccccccccccccccccccccccccccccccccc
write(*,*)'enter the value of nx,ny'
c2 format(2f5.2,2i3)
delx=lx/dfloat(nx)
dely=ly/dfloat(ny)
write(*,*)delx,dely
t=0
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c initilization of array
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
do 10 i=2,nx+1
do 10 j=2,ny+1
phi(i,j)=0.0
10 continue
cccccccccccccccccccccccc
do 20 i=1,nx+2
do 20 j=1,ny+2
u(i,j)=1.
v(i,j)=1.
20 continue
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c initial conditions for fictitious cells
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c left boundary
do 11 j=2,ny+1
if((j-1.5)*dely.le.t)then
phi(1,j)=2.-phi(2,j)
else
phi(1,j)=0.-phi(2,j)
end if
c right boundary
phi(nx+2,j)=phi(nx+1,j)
11 continue
ccccccccccccccccccc
do 12 i=2,nx+1
c bottom boundary
if((i-1.5)*delx.gt.t)then
phi(i,1)=0.-phi(i,2)
else
phi(i,1)=2.-phi(i,2)
end if
12 continue
c top boundary
do 33 i=2,nx+1
33 phi(i,ny+2)=phi(i,ny+1)
cccccccccccccccccccccccccccccccccc
phi(1,1)=0.0
phi(1,ny+2)=0.0
phi(nx+2,ny+2)=0.0
phi(nx+2,1)=0.0
cccccccccccccccccccccccccccccccccccccccccccc
c guess for n+1 th level be the value of nth level
ccccccccccc
phi1(1,1)=0.0
phi1(1,ny+2)=0.0
phi1(nx+2,ny+2)=0.0
phi1(nx+2,1)=0.0
do 51 i=1,nx+2
do 51 j=1,ny+2
phi1(i,j)=phi(i,j)
51 continue
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c Starting Time counter
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
n=0
170 t=t+delt
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c Starting Gauss Seidal
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
160 n=n+1
sum=0.0
ccccccccccccccccccccccccccccccccccccccccccccccc
c sweeping all cells and updating values
ccccccccccccccccccccccccccccccccccccccccccccccc
C Real cells
ccccccccccccccccc
ccccccccccccccccc
c left boundary cells(simple upwind)
ccccccccccccccccccccccccc
do 60 i=2,2
do 60 j=2,ny+1
A(i,j)=delx*dely/delt+0.5*(u(i+1,j)+u(i,j))*dely+2*D*delx/dely+
1 2*D*dely/delx+0.5*(v(i,j+1)+v(i,j))*delx

B(i,j)=0.5*(u(i-1,j)+u(i,j))*dely+D*dely/delx

C(i,j)=0.5*(v(i,j-1)+v(i,j))*delx+D*delx/dely
LHS(i,j)=phi1(i,j)*A(i,j)-phi1(i-1,j)*B(i,j)-phi1(i,j-1)*C(i,j)-
1 phi1(i+1,j)*D*(dely/delx)-phi1(i,j+1)*D*(delx/dely)
RHS(i,j)=phi(i,j)*delx*dely/delt
R(i,j)=RHS(i,j)-LHS(i,j)
sum=sum+R(i,j)**2
60 continue
cc updation
do 70 i=2,2
do 70 j=2,ny+1
cc=delx*dely/delt+0.5*(u(i+1,j)+u(i,j))*dely+2*D*delx/dely+
1 2*D*dely/delx+0.5*(v(i,j+1)+v(i,j))*delx
phi1(i,j)=phi1(i,j)+R(i,j)/cc
70 continue
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
ccccccccc
c bottom boundary cells(simple upwind)
ccccccccccccccccccccccccccccccccccccccccc
do 610 i=2,nx+1
do 610 j=2,2
A(i,j)=delx*dely/delt+0.5*(u(i+1,j)+u(i,j))*dely+2*D*delx/dely+
1 2*D*dely/delx+0.5*(v(i,j+1)+v(i,j))*delx
B(i,j)=0.5*(u(i-1,j)+u(i,j))*dely+D*dely/delx
C(i,j)=0.5*(v(i,j-1)+v(i,j))*delx+D*delx/dely

LHS(i,j)=phi1(i,j)*A(i,j)-phi1(i-1,j)*B(i,j)-phi1(i,j-1)*C(i,j)-
1 phi1(i+1,j)*D*(dely/delx)-phi1(i,j+1)*D*(delx/dely)
RHS(i,j)=phi(i,j)*delx*dely/delt
R(i,j)=RHS(i,j)-LHS(i,j)
sum=sum+R(i,j)**2
610 continue
cc updation
do 710 i=2,nx+1
do 710 j=2,2
cc=delx*dely/delt+0.5*(u(i+1,j)+u(i,j))*dely+2*D*delx/dely+
1 2*D*dely/delx+0.5*(v(i,j+1)+v(i,j))*delx
phi1(i,j)=phi1(i,j)+R(i,j)/cc
710 continue
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c quick
do 600 i=3,nx+1
do 600 j=3,ny+1
LHS(i,j)=((delx*dely)/delt)*phi1(i,j)+((-phi1(i-1,j)+6*phi1
1 (i,j)+3*phi1(i+1,j))/8.)*dely-( (-phi1(i-2,j)+6*phi1(i-1,j)+
1 3*phi1(i,j))/8.)*dely+ ((-phi1(i,j-1)+6*phi1(i,j)+3*phi1(i,j+1
1 ))/8.)*delx- ((-phi1(i,j-2)+6*phi1(i,j-1)+3*phi1(i,j))/8.)*
1 delx+D*((phi1(i,j)-phi1(i+1,j))/delx)*dely+ D*((phi1(i,j)-phi1
1 (i-1,j))/delx)*dely+ D*((phi1(i,j)-phi1(i,j+1))/dely)*delx
1 + D*((phi1(i,j)-phi1(i,j-1))/dely)*delx

RHS(i,j)=((delx*dely)/delt)*phi(i,j)
R(i,j)=RHS(i,j)-LHS(i,j)
sum=sum+R(i,j)**2
600 continue
ccccccccccccc
do 700 i=3,nx+1
do 700 j=3,ny+1
cc= delx*dely/delt+(3./8.)*0.5*(u(i+1,j)+u(i,j))*dely+2*D*delx/
1 dely+2*D*dely/delx+(3./8.)*0.5*(v(i,j+1)+v(i,j))*delx
phi1(i,j)=phi1(i,j)+R(i,j)/cc
700 continue
ccccccccccccccccccccccccccccccccccccccccccccccccccc
C Fictitious cells
ccccccccccccccccccccccccccccc
ccccccccccccccccccccccccccccc
c left boundary
ccccccccccccccc
do 80 j=2,ny+1
LHS(1,j)=0.5*(phi1(1,j)+phi1(2,j))
if((j-1.5)*dely.le.t)then
RHS(1,j)=1.
else
RHS(1,j)=0.
end if

R(1,j)=RHS(1,j)-LHS(1,j)
sum=sum+R(1,j)**2
80 continue
cc updation
cc=0.5
do 90 j=2,ny+1
phi1(1,j)=phi1(1,j)+R(1,j)/cc
90 continue
cccccccccccccccccccccccccccccccccccc
c right boundary
ccccccccccccccccccc
do 100 j=2,ny+1
LHS(nx+2,j)=(phi1(nx+2,j)-phi1(nx+1,j))/delx
RHS(nx+2,j)=0.0
R(nx+2,j)=RHS(nx+2,j)-LHS(nx+2,j)
sum=sum+R(nx+2,j)**2
100 continue
cc updation
cc=1.0/delx
do 110 j=2,ny+1
phi1(nx+2,j)=phi1(nx+2,j)+R(nx+2,j)/cc
110 continue
ccccccccccccccccccccccccccccccccccccc
c top boundary
cccccccccccccccccc
do 120 i=2,nx+1
LHS(i,ny+2)=(phi1(i,ny+2)-phi1(i,ny+1))/dely
RHS(i,ny+2)=0.0
R(i,ny+2)=RHS(i,ny+2)-LHS(i,ny+2)
sum=sum+R(i,ny+2)**2
120 continue
cc updation
cc=1.0/dely
do 130 i=2,nx+1
phi1(i,ny+2)=phi1(i,ny+2)+R(i,ny+2)/cc
130 continue
ccccccccccccccccccccccccccccccccccccc
c bottom boundary
cccccccccccccccccccc
do 140 i=2,nx+1
LHS(i,1)=0.5*(phi1(i,1)+phi1(i,2))
if((i-1.5)*delx.gt.t)then
RHS(i,1)=0.
else
RHS(i,1)=1.
end if
R(i,1)=RHS(i,1)-LHS(i,1)
sum=sum+R(i,1)**2
140 continue
cc updation
cc=0.5
do 150 i=2,nx+1
phi1(i,1)=phi1(i,1)+R(i,1)/cc
150 continue
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c residue check for inner loop
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
l=sqrt(sum/(dfloat(nx)*dfloat(ny)))
if(l.GT.0.000001)goto 160
write(*,*)l,n
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c conversion of value of phi1 to phi
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
do i=1,nx+2
do j=1,ny+2
phi(i,j)=phi1(i,j)
end do
end do
ccccccccccccccccccccccccccccccccccccccccccccccccccc
c check for time counter
ccccccccccccccccccccccccccccccccccccccccccccccccccc
if(t.le.1)then
write(*,*)t
goto 170
end if
cccccccccccccccccccccccccccccccccccccccccccccccccccc
c printing of final value
cccccccccccccccccccccccccccc
do i=2,nx+1
write(*,9)(phi(i,j),j=2,ny+1)
9 format(1x,20(3x,f12.7))
end do
ccccccccccccccccc
do 401 i=2,nx+1
do 401 j=2,ny+1
x(i)=(i-1.5)*delx
y(j)=(j-1.5)*dely
401 continue
cccccccccccccccccccccccccc
open(17,file='sapna.dat',status='old')
write(17,*)'zone i=',nx,'j=',ny
do 40 j=2,ny+1
do 40 i=2,nx+1
40 write(17,*) x(i),y(j),phi1(i,j)
stop
end
Profile of on x-y at t = 1 sec (QUICK Scheme) for different time steps:

Figure:7 Profile of Phi (QUICK Scheme) for grid size (100 x 100), t = 0.001sec

Figure:8 Profile of Phi (QUICK Scheme) for grid size (100 x 100), t = 0.002sec

Figure:9 Profile of Phi (QUICK Scheme) for grid size (100 x 100), t = 0.004sec

Figure:10 Profile of Phi (QUICK Scheme) for grid size (100 x 100), t = 0.01sec

Figure:11 Profile of Phi (QUICK Scheme) for grid size (100 x 100), t = 0.02sec