[Fortran] 纯文本查看 复制代码
PROGRAM WATER_HAMMER
implicit none
!***数组说明,变量赋值
real(4) :: h(301,6),v(301,6),Tao(301),T(301)
real(4) :: D,e,RL,g,f,c,Ts,Tr,ds,dt,v0,Cf,Ch,Cp
integer N,Tm,h0,Q,M,i,j
data D/4.6/,e/0.02/,RL/395/,N/5/
data Ts/7/,Tm/14/,h0/40/,Q/45/,g/9.81/,f/0.025/
!***计算基本参数
c=1435/sqrt(1+0.01*D/e)
c=790
Tr=2*RL/c
ds=RL/N
dt=ds/c
v0=Q/(0.7845*D*D)
M=int(Tm/dt+2)
Tao(1)=1.000
Cf=f*ds/D/2/g
write(*,*) 'ds,dt,v0,c,Tr', ds,dt,v0,c,Tr
!***确定初始条件
do i=1,N+1
v(1,i)=v0
h(1,i)=h0-Cf*(i-1)*v(1,i)**2
end do
!***计算流速压强
do j=2,M
T(j)=(j-1)*dt
Tao(j)=real(1-T(j)/Ts)
if (Tao(j).LT.0.0) Tao=0.0
!***管道内点计算
do i=2,N
h(j,i)=0.5*(h(j-1,i-1)+h(j-1,i+1)+c/g*(v(j-1,i-1)-v(j-1,i+1))&
& -Cf*(v(j-1,i-1)*abs(v(j-1,i-1))-v(j-1,i+1)*abs(v(j-1,i+1))))
v(j,i)=0.5*(g/c*(h(j-1,i-1)-h(j-1,i-1))+(v(j-1,i-1)+v(j-1,i+1))&
& -g/c*Cf*(v(j-1,i+1)*abs(v(j-1,i-1))+v(j-1,i+1)*abs(v(j-1,i+1))))
end do
!***上游边界计算
i=1
h(j,i)=h0
v(j,i)=v(j-1,i+1)+g/c*(h(j,i)-h(j-1,i+1)-Cf*v(j-1,i+1)*abs(v(j-1,i+1)))
!***下游边界计算
i=N+1
Ch=v0**2*Tao(j)**2/2/h0*c/g
Cp=h(j-1,N)+v(j-1,N)*(c/g-Cf*abs(v(j-1,N)))
v(j,i)=-Ch+sqrt(Ch*Ch+2*Ch*Cp*g/c)
h(j,i)=h(j-1,i-1)-c/g*(v(j,i)-v(j-1,i-1))-Cf*v(j-1,i-1)*abs(v(j-1,i-1))
write(*,*) Tao(j)
write(*,12) j,T(j),Tao(j),(h(j,i),i=1,N+1)
! 》》》》》》》》》》》》》》》》》我是分界线--这之前Tao这个数组(全部为小于1的数)都能正常输出,但是在“end do”之后,即跳出循环之后,Tao无论怎么格式化输出,都显示为0.
end do
!***输出计算结果
write(*,*) T
OPEN(UNIT=11,FILE='hvt.txt')
do j=1,M
write(11,*) j,T(j),Tao(j),(h(j,i),i=1,N+1)
end do
12 format(i4,8f9.3)
CLOSE(11)
STOP
END