PROGRAM Heat_conduction_with_Implicit_Scheme
parameter(kx=8,ky=8,kxx=10)
real::T(kxx),T1(kxx),a1(kx,kx),b1(kx),dt,dx,k,c
integer::i,j,count
open(1,file='input_gauss')
open(2,file='heat_implicit.dat')
T(1)=100.0
T(kxx)=100.0
dt=10;dx=0.1;k=.004
c=k*dt/dx**2
count=0
do i=2,kxx-1
T(i)=27.0
enddo
do i=1,kx
do j=1,kx
if(i==j)then
a1(i,j)=1.0+2*c
else
if(j==i+1 .or. i==j+1)then
a1(i,j)=-c
else
a1(i,j)=0
endif
endif
enddo
enddo
do i=1,kx
write(1,*)(a1(i,j),j=1,kx)
enddo
close(1)
5 count=count+1
do i=1,kx
if (i==1) b1(i)=T(i+1)+c*T(i)
if(i==kx) b1(i)=T(i+1)+c*T(i+2)
if(i /=1 .and. i/=kx) b1(i)=T(i+1)
enddo
write(1,*)(b1(i),i=1,kx)
call gauss(b1,kx,T1)
do i=1,kx
if(abs(T1(i)-T(i+1)) >0.001) then
do j=1,kx
T(j+1)=T1(j)
enddo
write(2,*)dt*count,T(4),T(6)
goto 5
endif
enddo
write(1,*)count
END PROGRAM
subroutine gauss(b,n,x)
integer::n,i,j,k
real:: a(n,n),b(n),x(n),ratio,s
open(1,file="input_gauss")
do i=1,n
read(1,*)(a(i,j),j=1,n)
enddo
do k=1,n-1
do i=k+1,n
ratio=a(i,k)/a(k,k)
do j=k,n
a(i,j)=a(i,j)-ratio*a(k,j)
enddo
b(i)=b(i)-ratio*b(k)
enddo
enddo
do i=1,n
x(i)=0.0
enddo
x(n)=b(n)/a(n,n)
do i=n-1,1,-1
s=0.0
do j=n,i+1,-1
s=s+a(i,j)*x(j)
enddo
x(i)=(b(i)-s)/a(i,i)
enddo
close(1)
return
end subroutine
parameter(kx=8,ky=8,kxx=10)
real::T(kxx),T1(kxx),a1(kx,kx),b1(kx),dt,dx,k,c
integer::i,j,count
open(1,file='input_gauss')
open(2,file='heat_implicit.dat')
T(1)=100.0
T(kxx)=100.0
dt=10;dx=0.1;k=.004
c=k*dt/dx**2
count=0
do i=2,kxx-1
T(i)=27.0
enddo
do i=1,kx
do j=1,kx
if(i==j)then
a1(i,j)=1.0+2*c
else
if(j==i+1 .or. i==j+1)then
a1(i,j)=-c
else
a1(i,j)=0
endif
endif
enddo
enddo
do i=1,kx
write(1,*)(a1(i,j),j=1,kx)
enddo
close(1)
5 count=count+1
do i=1,kx
if (i==1) b1(i)=T(i+1)+c*T(i)
if(i==kx) b1(i)=T(i+1)+c*T(i+2)
if(i /=1 .and. i/=kx) b1(i)=T(i+1)
enddo
write(1,*)(b1(i),i=1,kx)
call gauss(b1,kx,T1)
do i=1,kx
if(abs(T1(i)-T(i+1)) >0.001) then
do j=1,kx
T(j+1)=T1(j)
enddo
write(2,*)dt*count,T(4),T(6)
goto 5
endif
enddo
write(1,*)count
END PROGRAM
subroutine gauss(b,n,x)
integer::n,i,j,k
real:: a(n,n),b(n),x(n),ratio,s
open(1,file="input_gauss")
do i=1,n
read(1,*)(a(i,j),j=1,n)
enddo
do k=1,n-1
do i=k+1,n
ratio=a(i,k)/a(k,k)
do j=k,n
a(i,j)=a(i,j)-ratio*a(k,j)
enddo
b(i)=b(i)-ratio*b(k)
enddo
enddo
do i=1,n
x(i)=0.0
enddo
x(n)=b(n)/a(n,n)
do i=n-1,1,-1
s=0.0
do j=n,i+1,-1
s=s+a(i,j)*x(j)
enddo
x(i)=(b(i)-s)/a(i,i)
enddo
close(1)
return
end subroutine
Comments
Post a Comment