声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2528|回复: 0

[Fortran] FIVOL算法语句 fortran

[复制链接]
发表于 2016-4-11 15:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
程序语句:
PROGRAM FIVOL
DIMENSION X(21,21),Y(21,21),QAB(21,21),PAB(21,21),QBC(21,21),&
&PBC(21,21),QCD(21,21),PCD(21,21),QDA(21,21),PDA(21,21),&
&PHI(21,21),PHIX(21,21)
OPEN(1,FILE='FIVOL.DAT')
OPEN(6,FILE='FIVOL.OUT')
READ(1,1)JMAX,KMAX,NMAX
READ(1,2)RW,RX,RY,RZ,THEB,THEH,EPS,OM
1 FORMAT(8(I5))
2 FORMAT(8(E10.3))
WRITE(6,3)
WRITE(6,4)JMAX,KMAX,NMAX,EPS,OM
WRITE(6,5)RW,RX,RY,RZ,THEB,THEH
3 FORMAT('LAPLACE EQUATION BY FINITE VOLUME METHOD',//)
4 FORMAT('JMAX=',I2,'KMAX=',I2,'NMAX=',I5,&
&15X,'EPS=',E10.3,'OM=',F5.3)
5 FORMAT('RW=',F5.3,'RX=',F5.3,'RY=',F5.3,'RZ=',F5.3,&
&15X,'THEB=',F5.1,'THEN=',F5.1,//)
JMAP=JMAX-1
KMAP=KMAX-1
AJM=JMAP
AKM=KMAP
DRWX=(RX-RW)/AJM
DRZY=(RY-RZ)/AKM
DTH=(THEH-THEB)/AKM
PI=3.1415927
DO 7 K=1,KMAX
AK=K-1
THK=(THEB+AK*DTH)*PI/180.
CK=COS(THK)
SK=SIN(THK)
DR=DRWX+(DRZY-DRWX)*AK/AKM
RWZ=RW+(RZ-RW)*AK/AKM
DO 6 J=1,JMAX
AJ=J-1
R=RWZ+AJ*DR
X(J,K)=R*CK
Y(J,K)=R*SK
PHIX(J,K)=SK/R
PHI(J,K)=PHIX(J,K)
6 CONTINUE
7 CONTINUE
DO 8 J=1,JMAX
PHI(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UE
RMS=SQRT(SUM/(AJM-1.)/(AKM-1.))
WRITE(6,22)N,RMS
22 FORMAT(/,'CONVERGED AFTER ',I3, ' STEPS',4X,' RMS=',E12.5)
STOP
END PROGRAM
运行结果:
LAPLACE EQUATION BY FINITE VOLUME METHOD
JMAX= 6KMAX= 6NMAX= 50 EPS= 0.100E-10OM=1.500
RW=0.100RX=1.000RY=1.000RZ=0.100 THEB= 0.0THEN= 90.0
CONVERGENCE NOT ACHIEVED IN 50STEPS RMS= 0.17568E-06
K= 1
PHI= 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
PHIX= 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
K= 2
PHI= 3.0902 1.2439 0.7445 0.5205 0.3929 0.3090
PHIX= 3.0902 1.1036 0.6718 0.4828 0.3769 0.3090
K= 3
PHI= 5.8779 2.3473 1.4036 0.9828 0.7441 0.5878
PHIX= 5.8779 2.0992 1.2778 0.9184 0.7168 0.5878
K= 4
PHI= 8.0902 3.1786 1.8990 1.3345 1.0163 0.8090
PHIX= 8.0902 2.8893 1.7587 1.2641 0.9866 0.8090
K= 5
PHI= 9.5106 3.6209 2.1680 1.5349 1.1802 0.9511
PHIX= 9.5106 3.3966 2.0675 1.4860 1.1598 0.9511
K= 6
PHI=10.0000 3.5714 2.1739 1.5625 1.2195 1.0000
PHIX=10.0000 3.5714 2.1739 1.5625 1.2195 1.0000
CONVERGED AFTER 51 STEPS RMS= 0.13258E+00

555.png

转自:http://blog.sina.com.cn/s/blog_a319f5ff0101jhth.html





回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-10 16:10 , Processed in 0.076844 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表