pois3d.f 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. *DECK POIS3D
  2. SUBROUTINE POIS3D (LPEROD, L, C1, MPEROD, M, C2, NPEROD, N, A, B,
  3. + C, LDIMF, MDIMF, F, IERROR, W)
  4. C***BEGIN PROLOGUE POIS3D
  5. C***PURPOSE Solve a three-dimensional block tridiagonal linear system
  6. C which arises from a finite difference approximation to a
  7. C three-dimensional Poisson equation using the Fourier
  8. C transform package FFTPAK written by Paul Swarztrauber.
  9. C***LIBRARY SLATEC (FISHPACK)
  10. C***CATEGORY I2B4B
  11. C***TYPE SINGLE PRECISION (POIS3D-S)
  12. C***KEYWORDS ELLIPTIC PDE, FISHPACK, HELMHOLTZ, POISSON
  13. C***AUTHOR Adams, J., (NCAR)
  14. C Swarztrauber, P. N., (NCAR)
  15. C Sweet, R., (NCAR)
  16. C***DESCRIPTION
  17. C
  18. C Subroutine POIS3D solves the linear system of equations
  19. C
  20. C C1*(X(I-1,J,K)-2.*X(I,J,K)+X(I+1,J,K))
  21. C + C2*(X(I,J-1,K)-2.*X(I,J,K)+X(I,J+1,K))
  22. C + A(K)*X(I,J,K-1)+B(K)*X(I,J,K)+C(K)*X(I,J,K+1) = F(I,J,K)
  23. C
  24. C for I=1,2,...,L , J=1,2,...,M , and K=1,2,...,N .
  25. C
  26. C The indices K-1 and K+1 are evaluated modulo N, i.e.
  27. C X(I,J,0) = X(I,J,N) and X(I,J,N+1) = X(I,J,1). The unknowns
  28. C X(0,J,K), X(L+1,J,K), X(I,0,K), and X(I,M+1,K) are assumed to take
  29. C on certain prescribed values described below.
  30. C
  31. C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  32. C
  33. C
  34. C * * * * * * * * Parameter Description * * * * * * * * * *
  35. C
  36. C
  37. C * * * * * * On Input * * * * * *
  38. C
  39. C LPEROD Indicates the values that X(0,J,K) and X(L+1,J,K) are
  40. C assumed to have.
  41. C
  42. C = 0 If X(0,J,K) = X(L,J,K) and X(L+1,J,K) = X(1,J,K).
  43. C = 1 If X(0,J,K) = X(L+1,J,K) = 0.
  44. C = 2 If X(0,J,K) = 0 and X(L+1,J,K) = X(L-1,J,K).
  45. C = 3 If X(0,J,K) = X(2,J,K) and X(L+1,J,K) = X(L-1,J,K).
  46. C = 4 If X(0,J,K) = X(2,J,K) and X(L+1,J,K) = 0.
  47. C
  48. C L The number of unknowns in the I-direction. L must be at
  49. C least 3.
  50. C
  51. C C1 The real constant that appears in the above equation.
  52. C
  53. C MPEROD Indicates the values that X(I,0,K) and X(I,M+1,K) are
  54. C assumed to have.
  55. C
  56. C = 0 If X(I,0,K) = X(I,M,K) and X(I,M+1,K) = X(I,1,K).
  57. C = 1 If X(I,0,K) = X(I,M+1,K) = 0.
  58. C = 2 If X(I,0,K) = 0 and X(I,M+1,K) = X(I,M-1,K).
  59. C = 3 If X(I,0,K) = X(I,2,K) and X(I,M+1,K) = X(I,M-1,K).
  60. C = 4 If X(I,0,K) = X(I,2,K) and X(I,M+1,K) = 0.
  61. C
  62. C M The number of unknowns in the J-direction. M must be at
  63. C least 3.
  64. C
  65. C C2 The real constant which appears in the above equation.
  66. C
  67. C NPEROD = 0 If A(1) and C(N) are not zero.
  68. C = 1 If A(1) = C(N) = 0.
  69. C
  70. C N The number of unknowns in the K-direction. N must be at
  71. C least 3.
  72. C
  73. C
  74. C A,B,C One-dimensional arrays of length N that specify the
  75. C coefficients in the linear equations given above.
  76. C
  77. C If NPEROD = 0 the array elements must not depend upon the
  78. C index K, but must be constant. Specifically, the
  79. C subroutine checks the following condition
  80. C
  81. C A(K) = C(1)
  82. C C(K) = C(1)
  83. C B(K) = B(1)
  84. C
  85. C for K=1,2,...,N.
  86. C
  87. C LDIMF The row (or first) dimension of the three-dimensional
  88. C array F as it appears in the program calling POIS3D.
  89. C This parameter is used to specify the variable dimension
  90. C of F. LDIMF must be at least L.
  91. C
  92. C MDIMF The column (or second) dimension of the three-dimensional
  93. C array F as it appears in the program calling POIS3D.
  94. C This parameter is used to specify the variable dimension
  95. C of F. MDIMF must be at least M.
  96. C
  97. C F A three-dimensional array that specifies the values of
  98. C the right side of the linear system of equations given
  99. C above. F must be dimensioned at least L x M x N.
  100. C
  101. C W A one-dimensional array that must be provided by the
  102. C user for work space. The length of W must be at least
  103. C 30 + L + M + 2*N + MAX(L,M,N) +
  104. C 7*(INT((L+1)/2) + INT((M+1)/2)).
  105. C
  106. C
  107. C * * * * * * On Output * * * * * *
  108. C
  109. C F Contains the solution X.
  110. C
  111. C IERROR An error flag that indicates invalid input parameters.
  112. C Except for number zero, a solution is not attempted.
  113. C = 0 No error
  114. C = 1 If LPEROD .LT. 0 or .GT. 4
  115. C = 2 If L .LT. 3
  116. C = 3 If MPEROD .LT. 0 or .GT. 4
  117. C = 4 If M .LT. 3
  118. C = 5 If NPEROD .LT. 0 or .GT. 1
  119. C = 6 If N .LT. 3
  120. C = 7 If LDIMF .LT. L
  121. C = 8 If MDIMF .LT. M
  122. C = 9 If A(K) .NE. C(1) or C(K) .NE. C(1) or B(I) .NE.B(1)
  123. C for some K=1,2,...,N.
  124. C = 10 If NPEROD = 1 and A(1) .NE. 0 or C(N) .NE. 0
  125. C
  126. C Since this is the only means of indicating a possibly
  127. C incorrect call to POIS3D, the user should test IERROR
  128. C after the call.
  129. C
  130. C *Long Description:
  131. C
  132. C * * * * * * * Program Specifications * * * * * * * * * * * *
  133. C
  134. C Dimension of A(N),B(N),C(N),F(LDIMF,MDIMF,N),
  135. C Arguments W(see argument list)
  136. C
  137. C Latest December 1, 1978
  138. C Revision
  139. C
  140. C Subprograms POIS3D,POS3D1,TRIDQ,RFFTI,RFFTF,RFFTF1,RFFTB,
  141. C Required RFFTB1,COSTI,COST,SINTI,SINT,COSQI,COSQF,COSQF1
  142. C COSQB,COSQB1,SINQI,SINQF,SINQB,CFFTI,CFFTI1,
  143. C CFFTB,CFFTB1,PASSB2,PASSB3,PASSB4,PASSB,CFFTF,
  144. C CFFTF1,PASSF1,PASSF2,PASSF3,PASSF4,PASSF,PIMACH,
  145. C
  146. C Special NONE
  147. C Conditions
  148. C
  149. C Common NONE
  150. C Blocks
  151. C
  152. C I/O NONE
  153. C
  154. C Precision Single
  155. C
  156. C Specialist Roland Sweet
  157. C
  158. C Language FORTRAN
  159. C
  160. C History Written by Roland Sweet at NCAR in July 1977
  161. C
  162. C Algorithm This subroutine solves three-dimensional block
  163. C tridiagonal linear systems arising from finite
  164. C difference approximations to three-dimensional
  165. C Poisson equations using the Fourier transform
  166. C package FFTPAK written by Paul Swarztrauber.
  167. C
  168. C Space 6561(decimal) = 14641(octal) locations on the
  169. C Required NCAR Control Data 7600
  170. C
  171. C Timing and The execution time T on the NCAR Control Data
  172. C Accuracy 7600 for subroutine POIS3D is roughly proportional
  173. C to L*M*N*(log2(L)+log2(M)+5), but also depends on
  174. C input parameters LPEROD and MPEROD. Some typical
  175. C values are listed in the table below when NPEROD=0.
  176. C To measure the accuracy of the algorithm a
  177. C uniform random number generator was used to create
  178. C a solution array X for the system given in the
  179. C 'PURPOSE' with
  180. C
  181. C A(K) = C(K) = -0.5*B(K) = 1, K=1,2,...,N
  182. C
  183. C and, when NPEROD = 1
  184. C
  185. C A(1) = C(N) = 0
  186. C A(N) = C(1) = 2.
  187. C
  188. C The solution X was substituted into the given sys-
  189. C tem and, using double precision, a right side Y was
  190. C computed. Using this array Y subroutine POIS3D was
  191. C called to produce an approximate solution Z. Then
  192. C the relative error, defined as
  193. C
  194. C E = MAX(ABS(Z(I,J,K)-X(I,J,K)))/MAX(ABS(X(I,J,K)))
  195. C
  196. C where the two maxima are taken over I=1,2,...,L,
  197. C J=1,2,...,M and K=1,2,...,N, was computed. The
  198. C value of E is given in the table below for some
  199. C typical values of L,M and N.
  200. C
  201. C
  202. C L(=M=N) LPEROD MPEROD T(MSECS) E
  203. C ------ ------ ------ -------- ------
  204. C
  205. C 16 0 0 272 1.E-13
  206. C 15 1 1 287 4.E-13
  207. C 17 3 3 338 2.E-13
  208. C 32 0 0 1755 2.E-13
  209. C 31 1 1 1894 2.E-12
  210. C 33 3 3 2042 7.E-13
  211. C
  212. C
  213. C Portability American National Standards Institute FORTRAN.
  214. C The machine dependent constant PI is defined in
  215. C function PIMACH.
  216. C
  217. C Required COS,SIN,ATAN
  218. C Resident
  219. C Routines
  220. C
  221. C Reference NONE
  222. C
  223. C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  224. C
  225. C***REFERENCES (NONE)
  226. C***ROUTINES CALLED POS3D1
  227. C***REVISION HISTORY (YYMMDD)
  228. C 801001 DATE WRITTEN
  229. C 890531 Changed all specific intrinsics to generic. (WRB)
  230. C 890531 REVISION DATE from Version 3.2
  231. C 891214 Prologue converted to Version 4.0 format. (BAB)
  232. C***END PROLOGUE POIS3D
  233. DIMENSION A(*) ,B(*) ,C(*) ,
  234. 1 F(LDIMF,MDIMF,*) ,W(*) ,SAVE(6)
  235. C***FIRST EXECUTABLE STATEMENT POIS3D
  236. LP = LPEROD+1
  237. MP = MPEROD+1
  238. NP = NPEROD+1
  239. C
  240. C CHECK FOR INVALID INPUT.
  241. C
  242. IERROR = 0
  243. IF (LP.LT.1 .OR. LP.GT.5) IERROR = 1
  244. IF (L .LT. 3) IERROR = 2
  245. IF (MP.LT.1 .OR. MP.GT.5) IERROR = 3
  246. IF (M .LT. 3) IERROR = 4
  247. IF (NP.LT.1 .OR. NP.GT.2) IERROR = 5
  248. IF (N .LT. 3) IERROR = 6
  249. IF (LDIMF .LT. L) IERROR = 7
  250. IF (MDIMF .LT. M) IERROR = 8
  251. IF (NP .NE. 1) GO TO 103
  252. DO 101 K=1,N
  253. IF (A(K) .NE. C(1)) GO TO 102
  254. IF (C(K) .NE. C(1)) GO TO 102
  255. IF (B(K) .NE. B(1)) GO TO 102
  256. 101 CONTINUE
  257. GO TO 104
  258. 102 IERROR = 9
  259. 103 IF (NPEROD.EQ.1 .AND. (A(1).NE.0. .OR. C(N).NE.0.)) IERROR = 10
  260. 104 IF (IERROR .NE. 0) GO TO 122
  261. IWYRT = L+1
  262. IWT = IWYRT+M
  263. IWD = IWT+MAX(L,M,N)+1
  264. IWBB = IWD+N
  265. IWX = IWBB+N
  266. IWY = IWX+7*((L+1)/2)+15
  267. GO TO (105,114),NP
  268. C
  269. C REORDER UNKNOWNS WHEN NPEROD = 0.
  270. C
  271. 105 NH = (N+1)/2
  272. NHM1 = NH-1
  273. NODD = 1
  274. IF (2*NH .EQ. N) NODD = 2
  275. DO 111 I=1,L
  276. DO 110 J=1,M
  277. DO 106 K=1,NHM1
  278. NHPK = NH+K
  279. NHMK = NH-K
  280. W(K) = F(I,J,NHMK)-F(I,J,NHPK)
  281. W(NHPK) = F(I,J,NHMK)+F(I,J,NHPK)
  282. 106 CONTINUE
  283. W(NH) = 2.*F(I,J,NH)
  284. GO TO (108,107),NODD
  285. 107 W(N) = 2.*F(I,J,N)
  286. 108 DO 109 K=1,N
  287. F(I,J,K) = W(K)
  288. 109 CONTINUE
  289. 110 CONTINUE
  290. 111 CONTINUE
  291. SAVE(1) = C(NHM1)
  292. SAVE(2) = A(NH)
  293. SAVE(3) = C(NH)
  294. SAVE(4) = B(NHM1)
  295. SAVE(5) = B(N)
  296. SAVE(6) = A(N)
  297. C(NHM1) = 0.
  298. A(NH) = 0.
  299. C(NH) = 2.*C(NH)
  300. GO TO (112,113),NODD
  301. 112 B(NHM1) = B(NHM1)-A(NH-1)
  302. B(N) = B(N)+A(N)
  303. GO TO 114
  304. 113 A(N) = C(NH)
  305. 114 CONTINUE
  306. CALL POS3D1 (LP,L,MP,M,N,A,B,C,LDIMF,MDIMF,F,W,W(IWYRT),W(IWT),
  307. 1 W(IWD),W(IWX),W(IWY),C1,C2,W(IWBB))
  308. GO TO (115,122),NP
  309. 115 DO 121 I=1,L
  310. DO 120 J=1,M
  311. DO 116 K=1,NHM1
  312. NHMK = NH-K
  313. NHPK = NH+K
  314. W(NHMK) = .5*(F(I,J,NHPK)+F(I,J,K))
  315. W(NHPK) = .5*(F(I,J,NHPK)-F(I,J,K))
  316. 116 CONTINUE
  317. W(NH) = .5*F(I,J,NH)
  318. GO TO (118,117),NODD
  319. 117 W(N) = .5*F(I,J,N)
  320. 118 DO 119 K=1,N
  321. F(I,J,K) = W(K)
  322. 119 CONTINUE
  323. 120 CONTINUE
  324. 121 CONTINUE
  325. C(NHM1) = SAVE(1)
  326. A(NH) = SAVE(2)
  327. C(NH) = SAVE(3)
  328. B(NHM1) = SAVE(4)
  329. B(N) = SAVE(5)
  330. A(N) = SAVE(6)
  331. 122 CONTINUE
  332. RETURN
  333. END