[請益] 迴圈跳不出來??
請教大家,我在做一個一維擴散的模擬,
在我一步一步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
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.211.150
→
12/18 09:52, , 1F
12/18 09:52, 1F
→
12/18 12:25, , 2F
12/18 12:25, 2F
→
12/18 12:26, , 3F
12/18 12:26, 3F
→
12/18 12:26, , 4F
12/18 12:26, 4F
→
12/18 12:30, , 5F
12/18 12:30, 5F
→
12/18 12:30, , 6F
12/18 12:30, 6F
謝謝~
目前我把迴圈數設定成100的話都可以執行成功,所以應該是迴圈太大的問題,
0.25*L*L/D/10.0**8.0有改過但還是跑不完~
這問題滿棘手的..因為有些參數就是得這麼小阿......QQ
※ 編輯: YmemY 來自: 140.112.4.209 (12/18 13:46)
→
12/18 13:56, , 7F
12/18 13:56, 7F
→
12/18 13:56, , 8F
12/18 13:56, 8F
→
12/18 13:57, , 9F
12/18 13:57, 9F
→
12/18 14:00, , 10F
12/18 14:00, 10F
→
12/18 14:00, , 11F
12/18 14:00, 11F
t最多可能要到100...囧
不過我想或許我的D數字錯了,他可能是10^-10這麼小,所以smallt可以不用這麼小..
雖然試了一次還是行不通 但方向應該沒錯 再搞搞看...謝謝
→
12/18 14:17, , 12F
12/18 14:17, 12F
→
12/18 14:18, , 13F
12/18 14:18, 13F
挖賽!!!!!
原來真的要這麼久XD
※ 編輯: YmemY 來自: 140.112.211.150 (12/18 22:53)
推
12/19 22:32, , 14F
12/19 22:32, 14F
→
12/19 22:33, , 15F
12/19 22:33, 15F
感謝各位的提示,經由將參數調整地平易近人一點後,模擬出正確的結果了!
※ 編輯: YmemY 來自: 140.112.211.150 (12/28 02:08)
Fortran 近期熱門文章
PTT數位生活區 即時熱門文章