請教大家,我在做一個一維擴散的模擬,
在我一步一步debug之後,知道問題在迴圈的部分,好像會無法結束??
可以成功編譯成執行檔,但一旦開始執行,就無法結束了,也無法輸出結果..
以下是程式碼,麻煩版有幫我看看哪邊出錯了??
program diffusion !1-D diffusion
implicit none
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!宣告區
real L,D,J,C,T,F,smallt
!L=length,D=diffusivity,J=diffusion flux,C=initial concentration
!F=Fourier's number, smallt=time interval
real, parameter :: defaultL = 10
real, parameter :: defaultD = 1.03
real, parameter :: defaultJ = 1E-5
real, parameter :: defaultC = 1E-4
real array1(-1:10001),array2(-1:10001)
!the length is divided into 10000 pieces, 10001 nodes, 2 virtual nodes
integer*8 p, pmax, x
!p=pace, x=location
character mode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!輸入設定參數
write(*,*) "press ""1"" to select the default values, or""2"" to input
them"
read(*,*) mode
if(mode=="1") then
L = defaultL
D = defaultD
J = defaultJ
C = defaultC
else
write(*,*) "please input the length:"
read(*,*)L
write(*,*) "please input the diffusivity:"
read(*,*)D
write(*,*) "please input the diffusion flux:"
read(*,*)J
write(*,*) "please input the initial concentration:"
read(*,*)C
end if
write(*,*) "please input the time:"
read(*,*)T
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!計算用到的參數
smallt = 0.25*L*L/D/10**8
pmax = T/smallt
F = D*smallt/(L*L)*10**8
array1 = C
array2 = C
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!這裡就是出錯的開始!!!
do p=1,pmax
do x=0,10000
array1(-1) = J*L/10000/D + array1(0)
array1(10001) = array1(10000) + array1(0) - array1(-1)
array2(x)=F*(array1(x+1)+array1(x-1))+(1-2*F)*array1(x)
end do
array1 = array2
end do
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!將陣列輸出到文字檔
open(unit=10,file="diffusion1.txt")
do x=-1,10001
write(10,*) array1(x)
end do
STOP
END