cmgnbn.f 12 KB

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