Tuesday, December 2, 2008

Relaxation Technique using fortran

c Program of Relaxation Technique

dimension forcef(10,10),ngrid(10,10),ogrid(10,10)
real forcef,ngrid,ogrid,residue
integer n,k

print*,'Enter the size of grid excluding boundary:'
read*,n
print*,'Enter the distance between grid points :'
read*,d


do i=1,n+2
forcef(1,i)=0
forcef(i,1)=0
forcef(n+2,i)=0
forcef(i,n+2)=0
ngrid(1,i)=0
ngrid(i,1)=0
ngrid(n+2,i)=0
ngrid(i,n+2)=0
ogrid(1,i)=0
ogrid(i,1)=0
ogrid(n+2,i)=0
ogrid(i,n+2)=0
enddo

open (1,file='force.dat')
read (1,*)((forcef(i,j),j=2,n+1),i=2,n+1)
close(1)

do i=2,n+1
do j=2,n+1
ngrid(i,j)=0
enddo
enddo

k=1
10 print*,'Trial :',k

do i=2,n+1
do j=2,n+1
ogrid(i,j)=ngrid(i,j)
enddo
enddo

do i=2,n+1
do j=2,n+1
residue=ogrid(i-1,j)+ogrid(i+1,j)+ogrid(i,j-1)+ogrid(i,j+1)-(4*ogrid(i,j))+(d*d*forcef(i,j))

ngrid(i,j)=ogrid(i,j)+(residue/4)
enddo
enddo

do i=2,n+1
do j=2,n+1
if((ngrid(i,j)-ogrid(i,j)).gt.0.0001) then
k=k+1
goto 10
endif
enddo
enddo


write(*,*)'Grid values'
do i=2,n+1
write(*,*) (ngrid(i,j),j=2,n+1
enddo
stop
end

No comments: