|
8#
楼主 |
发表于 2020-6-15 21:16:11
|
只看该作者
带子程序的我的代码,和我的一整个主程序都算的不对
! MAIN (Explicit method)
! MacCormack_1D_Rimenn problem
!===============================================================
PROGRAM MacCormack_1D_Rimenn
IMPLICIT NONE
INTEGER, PARAMETER :: NMAX = 1001
REAL(KIND=8), DIMENSION(NMAX) :: X
REAL(KIND=8), DIMENSION(NMAX,0:2) :: U, UB, UBB, E, EB
REAL(KIND=8) :: uu, p
REAL(KIND=8) :: DT, t, TT=0.4 !声明时间离散变量
INTEGER :: n
REAL(KIND=8) :: DX
INTEGER :: NX, IX !声明空间离散变量
REAL(KIND=8) :: sigma, PI = 4.0d0*DATAN(1.0d0), GAMA = 1.4, R = 278.0
REAL(KIND=8) :: maxvel = 1e-10, vel
INTEGER :: I, K
WRITE (*, *) "Enter NX"
READ (*, *) NX
! DT = adjustable
! NX = 1000
IX = NX+1
DX = 2.0d0/NX ! 计算域(0,2)
DO I = 1, IX
x(i) = dble((I-1)*DX)
end do ! 网格
! Initial Condition
call Init(IX, U)
t = 0
! March
! time step(capture signal---stability)
10 DO I = 2, IX-1
uu = U(i,1)/U(i,0)
p = (GAMA-1)*(U(i,2)-0.5*U(i,0)*uu*uu)
vel = dsqrt(gama*p/U(i,0))+dabs(uu)
if (vel .gt. maxvel) then
maxvel = vel
end if
END DO
DT = 0.8*DX/maxvel
sigma = DT/DX
! Computation
t = t + DT
call MacCormack_1D_Solver(U,sigma,IX)
if ( t .lt. 0.4 ) goto 10
! Plot
call Results(IX, U, DX)
WRITE(*, *) "Numerical Solution is in MACCORMACK-1D-Rimenn.txt"
WRITE(*, *) "Calculations are successfully completed. "
WRITE(*, *) "Hit any key to close DOS window!"
STOP
END PROGRAM MacCormack_1D_Rimenn
!-------------------------------------------------------
! Shock tube initialtion condition
!-------------------------------------------------------
subroutine Init(IIX, U)
IMPLICIT NONE
INTEGER, PARAMETER :: NMAX = 1001
INTEGER, INTENT(IN) :: IIX
REAL(KIND=8), INTENT(OUT), DIMENSION(NMAX,0:2) :: U
REAL(KIND=8), DIMENSION(NMAX) :: X
REAL(KIND=8) :: GAMA=1.4, rou1, u1, p1, rou2, u2, p2
REAL(KIND=8) :: dx
INTEGER :: i
rou1=1.0
u1=0.0
p1=1.0
rou2=0.125
u2=0.0
p2=0.1
DO I = 1, IIX
if ( i .le. (IIX-1)/2 ) then
U(i,0)=rou1
U(i,1)=rou1*u1
U(i,2)=p1/(GAMA-1)+0.5*rou1*u1*u1
else
U(i,0)=rou2
U(i,1)=rou2*u2
U(i,2)=0.5*rou2*u2*u2 + p2/(GAMA-1)
end if
END DO
END subroutine Init
!-------------------------------------------------------
! 根据U计算E
! Input:U, 当前U矢量
! Export: E,计算得到的E矢量( flux term )
!-------------------------------------------------------
Subroutine U2E(U,E,ist,ie)
IMPLICIT NONE
INTEGER, PARAMETER :: NMAX = 1001
REAL(KIND=8), DIMENSION(NMAX) :: X
INTEGER, INTENT(IN) :: ist,ie
REAL(KIND=8), INTENT(IN), DIMENSION(NMAX,0:2) :: U
REAL(KIND=8), INTENT(OUT), DIMENSION(NMAX,0:2) :: E
REAL(KIND=8) :: uu, p
REAL(KIND=8) :: gama=1.4
INTEGER :: i
do i=ist,ie
uu=U(i,1)/U(i,0)
p=(GAMA-1)*U(i,2)-0.5*U(i,1)*U(i,1)/U(i,0)
E(i,0)=U(i,1)
E(i,1)=U(i,0)*uu*uu+p
E(i,2)=(U(i,2)+p)*uu
end do
end Subroutine U2E
!-------------------------------------------------------
! 1D_MacCormack差分格式求解器
! Input: U, 上一时刻U矢量
! Export: U, 计算得到得当前时刻U矢量( conserved variable )
!-------------------------------------------------------
Subroutine MacCormack_1D_Solver(U,sigma,IX)
IMPLICIT NONE
INTEGER, PARAMETER :: NMAX = 1001
REAL(KIND=8), INTENT(IN) :: sigma
INTEGER, INTENT(IN) :: IX
REAL(KIND=8), INTENT(INOUT), DIMENSION(NMAX,0:2) :: U
REAL(KIND=8), DIMENSION(NMAX) :: X
REAL(KIND=8), DIMENSION(NMAX,0:2) :: UB, UBB, E, EB,EV
INTEGER :: I, K
REAL(KIND=8) :: eta=0.25, theta
DO I = 2,IX-1
DO K = 0,2
!开关函数
theta=dabs(dabs(U(i+1,0)-U(i,0))-dabs(U(i,0)-U(i-1,0)))/(dabs(U(i+1,0)-U(i,0))+dabs(U(i,0)-U(i-1,0))+1e-10)
!人工粘性修正
EV(i,k) = U(i,k)+0.5*eta*theta*(U(i+1,k)-2*U(i,k)+U(i-1,k))
END DO
END DO
DO K = 0,2
DO I = 2,IX-1
U(i,k) = EV(i,k)
END DO
END DO
! Predictor
! UB_{i} = U^n_i - sigma * (E^n_(i+1) - E^n_i)
call U2E(U,E,1,IX)
DO I = 1, IX-1
DO K = 0, 2
UB(I,K) = U(I,K) - sigma*( E(I+1,K) - E(I,K) )
END DO
END DO
! Corrector
call U2E(UB,EB,1,IX-1)
DO I = 2, IX-1
DO k = 0,2
!UBB(I,K) = UB(I,K) - sigma * (EB(I,K) - EB(I-1,K))
U(i,k)=0.5*(U(i,k)+UB(i,k))-0.5*sigma*(EB(i,k)-EB(i-1,k))
END DO
END DO
! Updating
!DO k = 0,2
!DO I = 2, IX-1
! U(I,k) = 0.5d0*( U(I,k) + UBB(I,k) )
!END DO
!END DO
! Boundary condition
DO K = 0, 2
U(1,k) = U(2,k)
U(IX,k) = U(IX-1,k)
END DO
END Subroutine MacCormack_1D_Solver
!-------------------------------------------------------
! Plot Data
! Input: U, 上一时刻U矢量
! Export: , 计算得到得当前时刻原始变量( conserved variable )
!-------------------------------------------------------
SUBROUTINE Results(IX, U, DX)
IMPLICIT NONE
INTEGER, PARAMETER :: NMAX = 1001
INTEGER, INTENT(IN) :: IX
REAL(KIND=8), INTENT(IN) :: DX
REAL(KIND=8), INTENT(IN), DIMENSION(NMAX,0:2) :: U
REAL(KIND=8), DIMENSION(NMAX) :: X
REAL(KIND=8) :: rou, uu, p, Te,a,M,h
INTEGER :: I
REAL(KIND=8) :: GAMA = 1.4, R = 278.0
open(1,file='MacCormack_1D_Rimenn.txt',status='unknown')
DO i=1,IX
rou=U(i,0)
uu=U(i,1)/rou
p=(GAMA-1)*(U(i,2)-0.5*U(i,0)*uu*uu)
Te=p/(rou*R)
a=sqrt( gama*R*Te )
M=uu/a
h=gama*R*Te/(gama-1)
write(1,81) (I-1)*DX,rou,uu,p,Te,a,M,h
81 FORMAT(8(F10.5, 1x))
End DO
close(1)
END SUBROUTINE Results
|
|