poistg.f 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. *DECK POISTG
  2. SUBROUTINE POISTG (NPEROD, N, MPEROD, M, A, B, C, IDIMY, Y,
  3. + IERROR, W)
  4. C***BEGIN PROLOGUE POISTG
  5. C***PURPOSE Solve a block tridiagonal system of linear equations
  6. C that results from a staggered grid finite difference
  7. C approximation to 2-D elliptic PDE's.
  8. C***LIBRARY SLATEC (FISHPACK)
  9. C***CATEGORY I2B4B
  10. C***TYPE SINGLE PRECISION (POISTG-S)
  11. C***KEYWORDS ELLIPTIC, FISHPACK, HELMHOLTZ, PDE, TRIDIAGONAL
  12. C***AUTHOR Adams, J., (NCAR)
  13. C Swarztrauber, P. N., (NCAR)
  14. C Sweet, R., (NCAR)
  15. C***DESCRIPTION
  16. C
  17. C Subroutine POISTG solves the linear system of equations
  18. C
  19. C A(I)*X(I-1,J) + B(I)*X(I,J) + C(I)*X(I+1,J)
  20. C + X(I,J-1) - 2.*X(I,J) + X(I,J+1) = Y(I,J)
  21. C
  22. C for I=1,2,...,M and J=1,2,...,N.
  23. C
  24. C The indices I+1 and I-1 are evaluated modulo M, i.e.
  25. C X(0,J) = X(M,J) and X(M+1,J) = X(1,J), and X(I,0) may be equal to
  26. C X(I,1) or -X(I,1) and X(I,N+1) may be equal to X(I,N) or -X(I,N)
  27. C depending on an input parameter.
  28. C
  29. C
  30. C * * * * * * * * Parameter Description * * * * * * * * * *
  31. C
  32. C * * * * * * On Input * * * * * *
  33. C
  34. C NPEROD
  35. C Indicates the values which X(I,0) and X(I,N+1) are assumed
  36. C to have.
  37. C = 1 If X(I,0) = -X(I,1) and X(I,N+1) = -X(I,N)
  38. C = 2 If X(I,0) = -X(I,1) and X(I,N+1) = X(I,N)
  39. C = 3 If X(I,0) = X(I,1) and X(I,N+1) = X(I,N)
  40. C = 4 If X(I,0) = X(I,1) and X(I,N+1) = -X(I,N)
  41. C
  42. C N
  43. C The number of unknowns in the J-direction. N must
  44. C be greater than 2.
  45. C
  46. C MPEROD
  47. C = 0 If A(1) and C(M) are not zero
  48. C = 1 If A(1) = C(M) = 0
  49. C
  50. C M
  51. C The number of unknowns in the I-direction. M must
  52. C be greater than 2.
  53. C
  54. C A,B,C
  55. C One-dimensional arrays of length M that specify the coefficients
  56. C in the linear equations given above. If MPEROD = 0 the array
  57. C elements must not depend on the index I, but must be constant.
  58. C Specifically, the subroutine checks the following condition
  59. C
  60. C A(I) = C(1)
  61. C B(I) = B(1)
  62. C C(I) = C(1)
  63. C
  64. C for I = 1, 2, ..., M.
  65. C
  66. C IDIMY
  67. C The row (or first) dimension of the two-dimensional array Y as
  68. C it appears in the program calling POISTG. This parameter is
  69. C used to specify the variable dimension of Y. IDIMY must be at
  70. C least M.
  71. C
  72. C Y
  73. C A two-dimensional array that specifies the values of the
  74. C right side of the linear system of equations given above.
  75. C Y must be dimensioned at least M X N.
  76. C
  77. C W
  78. C A one-dimensional work array that must be provided by the user
  79. C for work space. W may require up to 9M + 4N + M(INT(log2(N)))
  80. C locations. The actual number of locations used is computed by
  81. C POISTG and returned in location W(1).
  82. C
  83. C
  84. C * * * * * * On Output * * * * * *
  85. C
  86. C Y
  87. C Contains the solution X.
  88. C
  89. C IERROR
  90. C An error flag that indicates invalid input parameters. Except
  91. C for number zero, a solution is not attempted.
  92. C = 0 No error
  93. C = 1 If M .LE. 2
  94. C = 2 If N .LE. 2
  95. C = 3 IDIMY .LT. M
  96. C = 4 If NPEROD .LT. 1 or NPEROD .GT. 4
  97. C = 5 If MPEROD .LT. 0 or MPEROD .GT. 1
  98. C = 6 If MPEROD = 0 and
  99. C A(I) .NE. C(1) or B(I) .NE. B(1) or C(I) .NE. C(1)
  100. C for some I = 1, 2, ..., M.
  101. C = 7 If MPEROD .EQ. 1 .AND. (A(1).NE.0 .OR. C(M).NE.0)
  102. C
  103. C W
  104. C W(1) contains the required length of W.
  105. C
  106. C *Long Description:
  107. C
  108. C * * * * * * * Program Specifications * * * * * * * * * * * *
  109. C
  110. C Dimension of A(M),B(M),C(M),Y(IDIMY,N),
  111. C Arguments W(see argument list)
  112. C
  113. C Latest June 1, 1977
  114. C Revision
  115. C
  116. C Subprograms POISTG,POSTG2,COSGEN,MERGE,TRIX,TRI3,PIMACH
  117. C Required
  118. C
  119. C Special NONE
  120. C Conditions
  121. C
  122. C Common NONE
  123. C Blocks
  124. C
  125. C I/O NONE
  126. C
  127. C Precision Single
  128. C
  129. C Specialist Roland Sweet
  130. C
  131. C Language FORTRAN
  132. C
  133. C History Written by Roland Sweet in 1973
  134. C Revised by Roland Sweet in 1977
  135. C
  136. C
  137. C Space 3297(decimal) = 6341(octal) locations on the
  138. C Required NCAR Control Data 7600
  139. C
  140. C Timing and The execution time T on the NCAR Control Data
  141. C Accuracy 7600 for subroutine POISTG is roughly proportional
  142. C to M*N*log2(N). Some typical values are listed
  143. C in the table below. More comprehensive timing
  144. C charts may be found in the reference.
  145. C To measure the accuracy of the algorithm a
  146. C uniform random number generator was used to create
  147. C a solution array X for the system given in the
  148. C 'PURPOSE ' with
  149. C
  150. C A(I) = C(I) = -0.5*B(I) = 1, I=1,2,...,M
  151. C
  152. C and, when MPEROD = 1
  153. C
  154. C A(1) = C(M) = 0
  155. C B(1) = B(M) =-1.
  156. C
  157. C The solution X was substituted into the given sys-
  158. C tem and, using double precision, a right side Y was
  159. C computed. Using this array Y subroutine POISTG was
  160. C called to produce an approximate solution Z. Then
  161. C the relative error, defined as
  162. C
  163. C E = MAX(ABS(Z(I,J)-X(I,J)))/MAX(ABS(X(I,J)))
  164. C
  165. C where the two maxima are taken over all I=1,2,...,M
  166. C and J=1,2,...,N, was computed. The value of E is
  167. C given in the table below for some typical values of
  168. C M and N.
  169. C
  170. C
  171. C M (=N) MPEROD NPEROD T(MSECS) E
  172. C ------ ------ ------ -------- ------
  173. C
  174. C 31 0-1 1-4 45 9.E-13
  175. C 31 1 1 21 4.E-13
  176. C 31 1 3 41 3.E-13
  177. C 32 0-1 1-4 51 3.E-12
  178. C 32 1 1 32 3.E-13
  179. C 32 1 3 48 1.E-13
  180. C 33 0-1 1-4 42 1.E-12
  181. C 33 1 1 30 4.E-13
  182. C 33 1 3 34 1.E-13
  183. C 63 0-1 1-4 186 3.E-12
  184. C 63 1 1 91 1.E-12
  185. C 63 1 3 173 2.E-13
  186. C 64 0-1 1-4 209 4.E-12
  187. C 64 1 1 128 1.E-12
  188. C 64 1 3 199 6.E-13
  189. C 65 0-1 1-4 143 2.E-13
  190. C 65 1 1 160 1.E-11
  191. C 65 1 3 138 4.E-13
  192. C
  193. C Portability American National Standards Institute FORTRAN.
  194. C The machine dependent constant PI is defined in
  195. C function PIMACH.
  196. C
  197. C Required COS
  198. C Resident
  199. C Routines
  200. C
  201. C Reference Schumann, U. and R. Sweet,'A Direct Method for
  202. C the Solution of Poisson's Equation With Neumann
  203. C Boundary Conditions on a Staggered Grid of
  204. C Arbitrary Size,' J. Comp. Phys. 20(1976),
  205. C pp. 171-182.
  206. C
  207. C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  208. C
  209. C***REFERENCES U. Schumann and R. Sweet, A direct method for the
  210. C solution of Poisson's equation with Neumann boundary
  211. C conditions on a staggered grid of arbitrary size,
  212. C Journal of Computational Physics 20, (1976),
  213. C pp. 171-182.
  214. C***ROUTINES CALLED POSTG2
  215. C***REVISION HISTORY (YYMMDD)
  216. C 801001 DATE WRITTEN
  217. C 861211 REVISION DATE from Version 3.2
  218. C 891214 Prologue converted to Version 4.0 format. (BAB)
  219. C 920501 Reformatted the REFERENCES section. (WRB)
  220. C***END PROLOGUE POISTG
  221. C
  222. C
  223. DIMENSION Y(IDIMY,*)
  224. DIMENSION W(*) ,B(*) ,A(*) ,C(*)
  225. C***FIRST EXECUTABLE STATEMENT POISTG
  226. IERROR = 0
  227. IF (M .LE. 2) IERROR = 1
  228. IF (N .LE. 2) IERROR = 2
  229. IF (IDIMY .LT. M) IERROR = 3
  230. IF (NPEROD.LT.1 .OR. NPEROD.GT.4) IERROR = 4
  231. IF (MPEROD.LT.0 .OR. MPEROD.GT.1) IERROR = 5
  232. IF (MPEROD .EQ. 1) GO TO 103
  233. DO 101 I=1,M
  234. IF (A(I) .NE. C(1)) GO TO 102
  235. IF (C(I) .NE. C(1)) GO TO 102
  236. IF (B(I) .NE. B(1)) GO TO 102
  237. 101 CONTINUE
  238. GO TO 104
  239. 102 IERROR = 6
  240. RETURN
  241. 103 IF (A(1).NE.0. .OR. C(M).NE.0.) IERROR = 7
  242. 104 IF (IERROR .NE. 0) RETURN
  243. IWBA = M+1
  244. IWBB = IWBA+M
  245. IWBC = IWBB+M
  246. IWB2 = IWBC+M
  247. IWB3 = IWB2+M
  248. IWW1 = IWB3+M
  249. IWW2 = IWW1+M
  250. IWW3 = IWW2+M
  251. IWD = IWW3+M
  252. IWTCOS = IWD+M
  253. IWP = IWTCOS+4*N
  254. DO 106 I=1,M
  255. K = IWBA+I-1
  256. W(K) = -A(I)
  257. K = IWBC+I-1
  258. W(K) = -C(I)
  259. K = IWBB+I-1
  260. W(K) = 2.-B(I)
  261. DO 105 J=1,N
  262. Y(I,J) = -Y(I,J)
  263. 105 CONTINUE
  264. 106 CONTINUE
  265. NP = NPEROD
  266. MP = MPEROD+1
  267. GO TO (110,107),MP
  268. 107 CONTINUE
  269. GO TO (108,108,108,119),NPEROD
  270. 108 CONTINUE
  271. CALL POSTG2 (NP,N,M,W(IWBA),W(IWBB),W(IWBC),IDIMY,Y,W,W(IWB2),
  272. 1 W(IWB3),W(IWW1),W(IWW2),W(IWW3),W(IWD),W(IWTCOS),
  273. 2 W(IWP))
  274. IPSTOR = W(IWW1)
  275. IREV = 2
  276. IF (NPEROD .EQ. 4) GO TO 120
  277. 109 CONTINUE
  278. GO TO (123,129),MP
  279. 110 CONTINUE
  280. C
  281. C REORDER UNKNOWNS WHEN MP =0
  282. C
  283. MH = (M+1)/2
  284. MHM1 = MH-1
  285. MODD = 1
  286. IF (MH*2 .EQ. M) MODD = 2
  287. DO 115 J=1,N
  288. DO 111 I=1,MHM1
  289. MHPI = MH+I
  290. MHMI = MH-I
  291. W(I) = Y(MHMI,J)-Y(MHPI,J)
  292. W(MHPI) = Y(MHMI,J)+Y(MHPI,J)
  293. 111 CONTINUE
  294. W(MH) = 2.*Y(MH,J)
  295. GO TO (113,112),MODD
  296. 112 W(M) = 2.*Y(M,J)
  297. 113 CONTINUE
  298. DO 114 I=1,M
  299. Y(I,J) = W(I)
  300. 114 CONTINUE
  301. 115 CONTINUE
  302. K = IWBC+MHM1-1
  303. I = IWBA+MHM1
  304. W(K) = 0.
  305. W(I) = 0.
  306. W(K+1) = 2.*W(K+1)
  307. GO TO (116,117),MODD
  308. 116 CONTINUE
  309. K = IWBB+MHM1-1
  310. W(K) = W(K)-W(I-1)
  311. W(IWBC-1) = W(IWBC-1)+W(IWBB-1)
  312. GO TO 118
  313. 117 W(IWBB-1) = W(K+1)
  314. 118 CONTINUE
  315. GO TO 107
  316. 119 CONTINUE
  317. C
  318. C REVERSE COLUMNS WHEN NPEROD = 4.
  319. C
  320. IREV = 1
  321. NBY2 = N/2
  322. NP = 2
  323. 120 DO 122 J=1,NBY2
  324. MSKIP = N+1-J
  325. DO 121 I=1,M
  326. A1 = Y(I,J)
  327. Y(I,J) = Y(I,MSKIP)
  328. Y(I,MSKIP) = A1
  329. 121 CONTINUE
  330. 122 CONTINUE
  331. GO TO (108,109),IREV
  332. 123 CONTINUE
  333. DO 128 J=1,N
  334. DO 124 I=1,MHM1
  335. MHMI = MH-I
  336. MHPI = MH+I
  337. W(MHMI) = .5*(Y(MHPI,J)+Y(I,J))
  338. W(MHPI) = .5*(Y(MHPI,J)-Y(I,J))
  339. 124 CONTINUE
  340. W(MH) = .5*Y(MH,J)
  341. GO TO (126,125),MODD
  342. 125 W(M) = .5*Y(M,J)
  343. 126 CONTINUE
  344. DO 127 I=1,M
  345. Y(I,J) = W(I)
  346. 127 CONTINUE
  347. 128 CONTINUE
  348. 129 CONTINUE
  349. C
  350. C RETURN STORAGE REQUIREMENTS FOR W ARRAY.
  351. C
  352. W(1) = IPSTOR+IWP-1
  353. RETURN
  354. END