Ошибка сегментации (SIGSEV) и ошибка SIGBUS при выполнении кода Fortran - PullRequest
0 голосов
/ 25 апреля 2019

Я использую код на Фортране, используя .f90, чтобы провести исследование полости для естественной конвекции.Однако я столкнулся с вышеупомянутыми ошибками.

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:

Program received signal SIGBUS: Access to an undefined portion of a memory object.

Backtrace for this error:

Мой код показан ниже:

    ! PROGRAM MAIN
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION AX(50,50),XX(50) ,AY(50,50),YY(50)
DIMENSION U(50,50),V(50,50) ,DP(50,50), P(50,50)
DIMENSION T(50,50),W(50,50) ,DT(50,50),DW(50,50) 

! INPUT NUMBER OF MESH POINTS, MAXIMUM ITERATION NUMBER, TIME STEP SIZE, CONVERGERENCE CRITERIA, PRANDTL NUMBER AND RAYLEIGH NUMBER 
WRITE(6,*) 'N,M,NTT,H,ERRT,ERRVORT,ERRSTREAM,PR,RA'
READ(5,*) N,M,NTT,H,EPS1,EPS2,EPS3,PR,RA

AX=1/(N-1)
AY=1/(M-1)

! MESH GENERATION AND SET-UP OF INITIAL FLOW FIELD
CALL GRID(N,M,XX,YY,U,V,W,T,DT,DW)

! START ITERATION
88 CONTINUE

! EULER METHOD TO SOLVE RESULTANT ORDINARY DIFFERENTIAL EQUATIONS FOR VORTICITY 
CALL EULER(M,N,U,V,T,W,DT,DW)

! CALCULATE STREAM FUNCTION USING JACOBI RELAXATION SOLVER
CALL SOLP(N,M,W,P,DP) 

! IMPLEMENT BOUNDARY CONDITIONS FOR VORTICITY 
CALL BCVOR(N,M,W,P)

! COMPUTE VELOCITY U, V
CALL CALUV(N,M,U,V,P)

 ! IMPLEMENT BOUNDARY CONDITIONS FOR TEMPERATURE
CALL BCT(N,M,T)

! FIND OUT MAXIMUM RESIDUALS 
ERR1=DT(1,1) **2
ERR2=DW(1,1) **2
ERR3=DP(1,1)**2
DO 91 I=l,N
DO 91 J=l,M
ERR1=DT(I,J)**2+ERR1
ERR2=DW(I,J)**2+ERR2
ERR3=DP(I,J)**2+ERR3
91 CONTINUE
NM=N*M
ERR1=SQRT(ERR1/NM)
ERR2 = SQRT (ERR2/NM)
ERR3=SQRT(ERR3/NM)
WRITE(6,113) NT,ERR1,ERR2,ERR3
113 FORMAT(1X,I10,5X,' ERR1=',E10.5,5X,'ERR2=',E10.5, 5X,'ERR3=',E10.5)

! CHECK CONVERGENCE CRITERIA
IF(ERR1.LE.EPS1.AND.ERR2.LE.EPS2.AND.ERR3.LE.EPS3) GO TO 92
IF(NT.GE.NTT) GO TO 92
NT=NT+1
GO TO 88
92 CONTINUE

! COMPUTE NUSSELT NUMBERS
CALL NUSEC(N,M,XX,YY,AX,U,V,T)

! INTERPOLATE NUMERICAL RESULTS FROM COARSE MESH TO FINE MESH FOR PLOTTING AND OTHER PURPOSE
CALL OUTPLT(N,M,XX,YY,U,V,W,T,P)
STOP
END

Компилятор смог скомпилировать код, поэтому я не уверен, что пошло не таквнутри кода.Надеюсь, что некоторые могут помочь мне с этим.

Дальнейшие детали кода:

! THIS SUBROUTINE IS TO GENERATE THE COORDINATES OF MESH POINTS
SUBROUTINE GRID(N,M,XX,YY,U,V,W,T,DT,DW)
IMPLICIT REAL*8 (A-H,O-Z)
DIMENSION XX(50),YY(50),U(50,50),V(50,50)
DIMENSION T(50,50),W(50,50),DT(50,50),DW(50,50)

! THIS SUBROUTINE IS TO GENERATE THE COORDINATES OF MESH POINTS
WRITE(6,*) 'ALAX,ALAY'
READ(5,*) ALAX,ALAY
PI=4. *ATAN(1.)

DO 71 I=1,N
ALFA=PI*FLOAT(I-1)/FLOAT(N-1)
71 XX(I)=0.5*(1.-COS(ALFA))
X11=XX(1)

! STRETCH THE MESH TOWARDS THE BOUNDARY, ALAX<1

DO 76 I=1,N
76 XX(I)=(1.-ALAX)*(3.*XX(I)**2-2.*XX(I)**3)+ALAX*XX(I)

DO 81 J=1,M
ALFA=PI*FLOAT(J-1)/FLOAT(M-1)
81 YY(J)=0.5*(1.-COS(ALFA))

! STRETCH THE MESH TOWARDS THE BOUNDARY, ALAY<1
DO 86 J=1,M
86 YY(J)=(1.-ALAY)*(3.*YY(J)**2-2.*YY(J)**3)+ALAY*YY(J)
YY(MH)=0.5

! SET UP INITIAL FLOW FIELD
DO 18 J=1,M
DO 10 I=1,N
U(I,J)=0D0
V(I,J)=0D0
T(I,J)=0D0
W(I,J)=0D0
DT(I,J)=0D0
DW(I,J)=0D0
10 CONTINUE
T(1,J)=1.0
18 CONTINUE
RETURN
END

! EULER METHOD TO SOLVE RESULTANT ORDINARY DIFFERENTIAL EQUATIONS FOR VORTICITY 
SUBROUTINE EULER(M,N,U,V,T,W,DT,DW)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION W(50,50),U(50,50),V(50,50),DW(50,50),T(50,50),DT(50,50)
CALL RESOVR(N,M,H,U,V,T,DT,AX,AY,W,DW,PR,RA)
DO I=2,N-1
DO J=2,M-1
W(I,J)=W(I,J)+0.25*H*DW(I,J)
END DO
END DO
RETURN
END

! COMPUTE THE RESIDUAL VORTICITY
SUBROUTINE RESOVR(N,M,H,U,V,T,DT,AX,AY,W,DW,PR,RA)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION U(50,50),V(50,50),W(50,50),DW(50,50),T(50,50),DT(50,50)
CALL SOLT(N,M,H,U,V,T,DT,AX,AY)
DO I=2,N-1
DO J=2,M-1
DWX2=(W(I+1,J)-2*W(I,J)+W(I-1,J))/(AX**2)
DWY2=(W(I,J+1)-2*W(I,J)+W(I,J-1))/(AY**2)
DWX1=U(I,J)*(W(I+1,J)-W(I-1,J))/(2*AX)
DWY1=V(I,J)*(W(I,J+1)-W(I,J-1))/(2*AY)
DW(I,J)=PR*(DWX2+DWY2)+PR*RA*T(I,J)-DWX1-DWY1
END DO
END DO
RETURN
END

! COMPUTE FOR TEMPERATURE
SUBROUTINE SOLT(N,M,H,U,V,T,DT,AX,AY)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION U(50,50),V(50,50),T(50,50),DT(50,50)
CALL REST(N,M,U,V,T,DT,AX,AY)
DO I=2,N-1
DO J=2,M-1
T(I,J)=T(I,J)+H*DT(I,J)
END DO
END DO
RETURN
END

! CALCULATE RESIDUAL TEMPERATURE
SUBROUTINE REST(N,M,U,V,T,DT,AX,AY)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION U(50,50),V(50,50),T(50,50),DT(50,50)
DO I =2,N-1
DO J=2,M-1
DTX1=0.5*(T(I+1,J)-T(I-1,J))/AX
DTY1=0.5*(T(I,J+1)-T(I,J-1))/AY
DTX2=(T(I+1,J)-2*T(I,J)+T(I-1,J))/(AX**2)
DTY2=(T(I,J+1)-2*T(I,J)+T(I,J-1))/(AY**2)
DT(I,J)=DTX2+DTY2-U(I,J)*DTX1-V(I,J)*DTY1
END DO
END DO
RETURN 
END

! CALCULATE STREAM FUNCTION USING JACOBI RELAXATION SOLVER
SUBROUTINE SOLP(N,M,W,P,DP) 
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION P(50,50),DP(50,50),W(50,50)
CALL RESP(N,M,AX,AY,W,P,DP)
B=0.1
BW=1/(AX**2)
BS=1/(AY**2)
BP=-2*(BW+BS)
DO I=2,N-1
DO J=2,M-1
P(I,J)=P(I,J)+(B*DP(I,J))/BP
END DO
END DO
RETURN 
END

! COMPUTE RESIDUAL STREAM FUNCTION
SUBROUTINE RESP(N,M,AX,AY,W,P,DP)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION W(50,50),P(50,50),DP(50,50)
DO I=2,N-1
DO J=2,M-1
DP(I,J)=W(I,J)-(P(I+1,J)-2*P(I,J)+P(I-1,J))/(AX**2)-(P(I,J+1)-2*P(I,J)+P(I,J-1))/(AY**2)
END DO
END DO
RETURN
END

! UPDATE STREAM FUNCTION AT BOUNDARY POINTS
SUBROUTINE BCP(N,M,AY,P)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION P(50,50)
DO J=2,M-1
P(2,J)=0.25*P(3,J)
P(N-1,J)=0.25*P(N-2,J)
END DO
DO I=2,N-1
P(I,2)=0.25*P(I,3)
P(I,M-1)=0.25*(P(I,M-2)-2*AY)
END DO
RETURN
END

! IMPLEMENT BOUNDARY CONDITIONS FOR VORTICITY 
SUBROUTINE BCVOR(N,M,W,P)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION W(50,50),P(50,50)
DO J=1,M
W(1,J)=3*P(2,J)/(AX**2)-0.5*W(2,J)
W(N,J)=3*P(N-1,J)/(AX**2)-0.5*W(N-1,J)
END DO
DO I=2,N-1
W(I,1)=3*P(I,2)/(AY**2)-0.5*W(I,2)
W(I,M)=3*(P(I,M-1)+AY)/(AY**2)-0.5*W(I,M-1)
END DO
RETURN 
END

! COMPUTE VELOCITY U, V
SUBROUTINE CALUV(N,M,U,V,P)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION P(50,50),U(50,50),V(50,50)
DO J=1,M
U(1,J)=0
U(N,J)=0
V(1,J)=0
V(N,J)=0
END DO
DO I=2,N-1
U(I,1)=0
V(I,1)=0
U(I,M)=0
V(I,M)=0
END DO
DO I=2,N-1
DO J=2,M-1
U(I,J)=0.5*(P(I,J+1)-P(I,J-1))/AY
V(I,J)=0.5*(P(I-1,J)-P(I+1,J))/AX
END DO
END DO
RETURN
END

! IMPLEMENT BOUNDARY CONDITIONS FOR TEMPERATURE
SUBROUTINE BCT(N,M,T)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION T(50,50)
DO I=1,N
T(I,1)=(4*T(I,2)-T(I,3))/3
T(I,M)=(4*T(I,M-1)-T(I,M-2))/3
END DO
DO J=1,M
T(1,J)=(4*T(2,J)-T(J,3))/3
T(N,J)=(4*T(N-1,J)-T(J,N-2))/3
END DO
RETURN 
END
! COMPUTE NUSSELT NUMBERS
SUBROUTINE NUSEC(N,M,XX,YY,AX,U,V,T)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION XX(50),YY(50),X2(201),Y2(201),AX(50,50),U(50,50),V(50,50)
DIMENSION T(50,50),QQ(50,50),QI(50),QT(50,201),CNU(50),CNUT(201)

! COMPUTE LOCAL HEAT FLUX IN A HORIZONTAL DIRECTION Q(X,Y)
DO 10 I=1,N
DO 10 J=1,M
DTI=0.
DO 11 K=1,N
11 DTI=DTI+AX(I,K)*T(K,J)
10 QQ(I,J)=U(I,J)*T(I,J)-DTI

! SET UP A FINE MESH
NN=81
MM=81
TDX=(XX(N)-XX(1))/FLOAT(NN-1)
TDY=(YY(M)-YY(1))/FLOAT(MM-1)
DO 20 I=1,NN
20 X2(I)=FLOAT(I-1)*TDX
DO 30 J=1,MM
30 Y2(J)=FLOAT(J-1)*TDY

! INTERPOLATE Q(X,Y) TO THE FINE MESH IN THE Y DIRECTION
DO 40 I=1,N
DO 41 J=1,M
QI(J)=QQ(I,J)
41 CONTINUE
DO 42 J=1,MM
YJ=Y2(J)
CALL CZ(M,YJ,YY,QI,QOUT)
QT(I,J)=QOUT
42 CONTINUE
40 CONTINUE

! COMPUTE AVERAGE NUSSELT NUMBER ON THE VERTICAL LINE
DO 188 I=1,N
SUM=0.0
DO 198 J=2,MM
SUM=SUM+0.5*(QT(I,J)+QT(I,J-1))*TDY
198 CONTINUE
CNU(I) = SUM
188 CONTINUE
DO 52 I=1,NN
XI=X2(I)
CALL CZ(N,XI,XX,CNU,CNUOUT)
CNUT(I)=CNUOUT
52 CONTINUE

! FIND OUT MAXIMUM LOCAL NUSSELT NUMBERS AT X=0 TOGETHER  WITH THEIR POSITIONS
AMIN=QT(1,1)
AMAX=QT(1,1)
DO 518 J=1,MM
IF(QT(1,J).LE.AMAX) GO TO 518
AMAX=QT(1,J)
YMAX=Y2(J)
518 CONTINUE
NH= (N+1) /2

! FIND OUT MAXIMUM VELOCITY  AT  VERTICAL MID-PLANE TOGETHER  WITH THEIR POSITIONS
AMAX=U(1,1)
MPV=(NN+1)/2
DO 519 J=1,MM
IF(U(MPV,J).LE.AMAX) GO TO 519
UXMAX=X2(MPV)
UYMAX=Y2(J)
519 CONTINUE
NH= (N+1) /2

! FIND OUT MAXIMUM VELOCITY  AT  HORIZONTAL  MID-PLANE TOGETHER  WITH THEIR POSITIONS
AMAX=V(1,1)
MPH=(MM+1)/2
DO 520 I=1,NN
IF(V(I,MPH).LE.AMAX) GO TO 520
VXMAX=X2(I)
VYMAX=Y2(MPH)
520 CONTINUE
NH= (N+1) /2

! OUTPUT THE NUSSELT NUMBERS
WRITE(6,70) CNU(1)
70 FORMAT (2X, 'AVERAGE NUSSELT NUMBER AT X=0',5X,F15.4)
WRITE(6,72) CNU(NH)
72 FORMAT (2X, 'AVERAGE NUSSELT NUMBER AT X=0.5',3X,F15.4)
WRITE(6,74) AMAX,YMAX
74 FORMAT (2X, 'NUMAX AND POSITION AT X=0',5X,F10.4,5X,F10.4)
WRITE(6,76) UXMAX,UYMAX
76 FORMAT (2X, 'MAXIMUM HORIZONTAL VELOCITY AT VERTICAL MIDLPANE',5X,F15.4)
WRITE(6,78) VXMAX,VYMAX
78 FORMAT (2X, 'MAXIMUM VERTICAL VELOCITY AT HORIZONTAL MIDLPANE',5X,F15.4)
RETURN
END 

! LAGRANGE INTERPOLATION
SUBROUTINE CZ(N,XX,X,F,FV)
IMPLICIT REAL*8 (A-H,O-Z)
DIMENSION X(50),F(50)
FV=0.
DO 10 I=1,N
AD=1.
DO 20 J=1,N
IF(J.EQ.I) GO TO 21
AD1=(XX-X(J))/(X(I)-X(J))
GO TO 22
21 AD1=1.
22 AD=AD*AD1
20 CONTINUE
FV=FV+AD*F(I)
10 CONTINUE
RETURN
END

! INTERPOLATE THE NUMERICAL RESULTS FROM A COARSE MESH TO A FINE MESH
SUBROUTINE OUTPLT(N,M,X1,Y1,U,V,W,G,P)
IMPLICIT REAL*8(A-H,O-Z)
DIMENSION X1(50),Y1(50),X2(81),Y2(81),P(50,50),W(50,50)
DIMENSION U(50,50),V(50,50),G(50,50),UT(81,81),VT(81,81)
DIMENSION GT(81,81),PT(81,81),WT(81,81),UI(51),UJ(51)
DIMENSION VI(51),VJ(51),W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TITLE= '
WRITE(7,*) 'VARIABLES= X,Y,U,V,T,P,W'
WRITE(7,*) 'ZONE I=',NN, ' J=',MM, ' F=POINT'
DO 850 J=1,MM
DO 850 I=1,NN
WRITE(7,950) X2(I),Y2(J),UT(I,J),VT(I,J),GT(I,J),PT(I,J),WT(I,J)
850 CONTINUE
950 FORMAT(F7.4,1X,F7.4,1X,E11.5,2X,E11.5,2X,E11.5,2X,E11.5,2X,E11.5)
CLOSE(7)
RETURN
END
...