sepx4.f 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. *DECK SEPX4
  2. SUBROUTINE SEPX4 (IORDER, A, B, M, MBDCND, BDA, ALPHA, BDB, BETA,
  3. + C, D, N, NBDCND, BDC, BDD, COFX, GRHS, USOL, IDMN, W, PERTRB,
  4. + IERROR)
  5. C***BEGIN PROLOGUE SEPX4
  6. C***PURPOSE Solve for either the second or fourth order finite
  7. C difference approximation to the solution of a separable
  8. C elliptic partial differential equation on a rectangle.
  9. C Any combination of periodic or mixed boundary conditions is
  10. C allowed.
  11. C***LIBRARY SLATEC (FISHPACK)
  12. C***CATEGORY I2B1A2
  13. C***TYPE SINGLE PRECISION (SEPX4-S)
  14. C***KEYWORDS ELLIPTIC, FISHPACK, HELMHOLTZ, PDE, SEPARABLE
  15. C***AUTHOR Adams, J., (NCAR)
  16. C Swarztrauber, P. N., (NCAR)
  17. C Sweet, R., (NCAR)
  18. C***DESCRIPTION
  19. C
  20. C Purpose SEPX4 solves for either the second-order
  21. C finite difference approximation or a
  22. C fourth-order approximation to the
  23. C solution of a separable elliptic equation
  24. C AF(X)*UXX+BF(X)*UX+CF(X)*U+UYY = G(X,Y)
  25. C
  26. C on a rectangle (X greater than or equal to A
  27. C and less than or equal to B; Y greater than
  28. C or equal to C and less than or equal to D).
  29. C Any combination of periodic or mixed boundary
  30. C conditions is allowed.
  31. C If boundary conditions in the X direction
  32. C are periodic (see MBDCND=0 below) then the
  33. C coefficients must satisfy
  34. C AF(X)=C1,BF(X)=0,CF(X)=C2 for all X.
  35. C Here C1,C2 are constants, C1.GT.0.
  36. C
  37. C The possible boundary conditions are
  38. C in the X-direction:
  39. C (0) Periodic, U(X+B-A,Y)=U(X,Y) for all Y,X
  40. C (1) U(A,Y), U(B,Y) are specified for all Y
  41. C (2) U(A,Y), dU(B,Y)/dX+BETA*U(B,Y) are
  42. C specified for all Y
  43. C (3) dU(A,Y)/dX+ALPHA*U(A,Y),dU(B,Y)/dX+
  44. C BETA*U(B,Y) are specified for all Y
  45. C (4) dU(A,Y)/dX+ALPHA*U(A,Y),U(B,Y) are
  46. C specified for all Y
  47. C
  48. C In the Y-direction:
  49. C (0) Periodic, U(X,Y+D-C)=U(X,Y) for all X,Y
  50. C (1) U(X,C),U(X,D) are specified for all X
  51. C (2) U(X,C),dU(X,D)/dY are specified for all X
  52. C (3) dU(X,C)/DY,dU(X,D)/dY are specified for
  53. C all X
  54. C (4) dU(X,C)/DY,U(X,D) are specified for all X
  55. C
  56. C Usage Call SEPX4(IORDER,A,B,M,MBDCND,BDA,ALPHA,BDB,
  57. C BETA,C,D,N,NBDCND,BDC,BDD,COFX,
  58. C GRHS,USOL,IDMN,W,PERTRB,IERROR)
  59. C
  60. C Arguments
  61. C
  62. C IORDER
  63. C = 2 If a second-order approximation is sought
  64. C = 4 If a fourth-order approximation is sought
  65. C
  66. C A,B
  67. C The range of the X-independent variable;
  68. C i.e., X is greater than or equal to A and
  69. C less than or equal to B. A must be less than
  70. C B.
  71. C
  72. C M
  73. C The number of panels into which the interval
  74. C [A,B] is subdivided. Hence, there will be
  75. C M+1 grid points in the X-direction given by
  76. C XI=A+(I-1)*DLX for I=1,2,...,M+1 where
  77. C DLX=(B-A)/M is the panel width. M must be
  78. C less than IDMN and greater than 5.
  79. C
  80. C MBDCND
  81. C Indicates the type of boundary condition at
  82. C X=A and X=B
  83. C = 0 If the solution is periodic in X; i.e.,
  84. C U(X+B-A,Y)=U(X,Y) for all Y,X
  85. C = 1 If the solution is specified at X=A and
  86. C X=B; i.e., U(A,Y) and U(B,Y) are
  87. C specified for all Y
  88. C = 2 If the solution is specified at X=A and
  89. C the boundary condition is mixed at X=B;
  90. C i.e., U(A,Y) and dU(B,Y)/dX+BETA*U(B,Y)
  91. C are specified for all Y
  92. C = 3 If the boundary conditions at X=A and X=B
  93. C are mixed; i.e., dU(A,Y)/dX+ALPHA*U(A,Y)
  94. C and dU(B,Y)/dX+BETA*U(B,Y) are specified
  95. C for all Y
  96. C = 4 If the boundary condition at X=A is mixed
  97. C and the solution is specified at X=B;
  98. C i.e., dU(A,Y)/dX+ALPHA*U(A,Y) and U(B,Y)
  99. C are specified for all Y
  100. C
  101. C BDA
  102. C A one-dimensional array of length N+1 that
  103. C specifies the values of dU(A,Y)/dX+
  104. C ALPHA*U(A,Y) at X=A, when MBDCND=3 or 4.
  105. C BDA(J) = dU(A,YJ)/dX+ALPHA*U(A,YJ);
  106. C J=1,2,...,N+1
  107. C When MBDCND has any other value, BDA is a
  108. C dummy parameter.
  109. C
  110. C On Input ALPHA
  111. C The scalar multiplying the solution in case
  112. C of a mixed boundary condition AT X=A (see
  113. C argument BDA). If MBDCND = 3,4 then ALPHA is
  114. C a dummy parameter.
  115. C
  116. C BDB
  117. C A one-dimensional array of length N+1 that
  118. C specifies the values of dU(B,Y)/dX+
  119. C BETA*U(B,Y) at X=B. when MBDCND=2 or 3
  120. C BDB(J) = dU(B,YJ)/dX+BETA*U(B,YJ);
  121. C J=1,2,...,N+1
  122. C When MBDCND has any other value, BDB is a
  123. C dummy parameter.
  124. C
  125. C BETA
  126. C The scalar multiplying the solution in case
  127. C of a mixed boundary condition at X=B (see
  128. C argument BDB). If MBDCND=2,3 then BETA is a
  129. C dummy parameter.
  130. C
  131. C C,D
  132. C The range of the Y-independent variable;
  133. C i.e., Y is greater than or equal to C and
  134. C less than or equal to D. C must be less than
  135. C D.
  136. C
  137. C N
  138. C The number of panels into which the interval
  139. C [C,D] is subdivided. Hence, there will be
  140. C N+1 grid points in the Y-direction given by
  141. C YJ=C+(J-1)*DLY for J=1,2,...,N+1 where
  142. C DLY=(D-C)/N is the panel width. In addition,
  143. C N must be greater than 4.
  144. C
  145. C NBDCND
  146. C Indicates the types of boundary conditions at
  147. C Y=C and Y=D
  148. C = 0 If the solution is periodic in Y; i.e.,
  149. C U(X,Y+D-C)=U(X,Y) for all X,Y
  150. C = 1 If the solution is specified at Y=C and
  151. C Y = D, i.e., U(X,C) and U(X,D) are
  152. C specified for all X
  153. C = 2 If the solution is specified at Y=C and
  154. C the boundary condition is mixed at Y=D;
  155. C i.e., dU(X,C)/dY and U(X,D)
  156. C are specified for all X
  157. C = 3 If the boundary conditions are mixed at
  158. C Y= C and Y=D i.e., dU(X,D)/DY
  159. C and dU(X,D)/dY are specified
  160. C for all X
  161. C = 4 If the boundary condition is mixed at Y=C
  162. C and the solution is specified at Y=D;
  163. C i.e. dU(X,C)/dY+GAMA*U(X,C) and U(X,D)
  164. C are specified for all X
  165. C
  166. C BDC
  167. C A one-dimensional array of length M+1 that
  168. C specifies the value dU(X,C)/DY
  169. C at Y=C. When NBDCND=3 or 4
  170. C BDC(I) = dU(XI,C)/DY
  171. C I=1,2,...,M+1.
  172. C When NBDCND has any other value, BDC is a
  173. C dummy parameter.
  174. C
  175. C
  176. C BDD
  177. C A one-dimensional array of length M+1 that
  178. C specifies the value of dU(X,D)/DY
  179. C at Y=D. When NBDCND=2 or 3
  180. C BDD(I)=dU(XI,D)/DY
  181. C I=1,2,...,M+1.
  182. C When NBDCND has any other value, BDD is a
  183. C dummy parameter.
  184. C
  185. C
  186. C COFX
  187. C A user-supplied subprogram with
  188. C parameters X, AFUN, BFUN, CFUN which
  189. C returns the values of the X-dependent
  190. C coefficients AF(X), BF(X), CF(X) in
  191. C the elliptic equation at X.
  192. C If boundary conditions in the X direction
  193. C are periodic then the coefficients
  194. C must satisfy AF(X)=C1,BF(X)=0,CF(X)=C2 for
  195. C all X. Here C1.GT.0 and C2 are constants.
  196. C
  197. C Note that COFX must be declared external
  198. C in the calling routine.
  199. C
  200. C GRHS
  201. C A two-dimensional array that specifies the
  202. C values of the right-hand side of the elliptic
  203. C equation; i.e., GRHS(I,J)=G(XI,YI), for
  204. C I=2,...,M; J=2,...,N. At the boundaries,
  205. C GRHS is defined by
  206. C
  207. C MBDCND GRHS(1,J) GRHS(M+1,J)
  208. C ------ --------- -----------
  209. C 0 G(A,YJ) G(B,YJ)
  210. C 1 * *
  211. C 2 * G(B,YJ) J=1,2,...,N+1
  212. C 3 G(A,YJ) G(B,YJ)
  213. C 4 G(A,YJ) *
  214. C
  215. C NBDCND GRHS(I,1) GRHS(I,N+1)
  216. C ------ --------- -----------
  217. C 0 G(XI,C) G(XI,D)
  218. C 1 * *
  219. C 2 * G(XI,D) I=1,2,...,M+1
  220. C 3 G(XI,C) G(XI,D)
  221. C 4 G(XI,C) *
  222. C
  223. C where * means these quantities are not used.
  224. C GRHS should be dimensioned IDMN by at least
  225. C N+1 in the calling routine.
  226. C
  227. C USOL
  228. C A two-dimensional array that specifies the
  229. C values of the solution along the boundaries.
  230. C At the boundaries, USOL is defined by
  231. C
  232. C MBDCND USOL(1,J) USOL(M+1,J)
  233. C ------ --------- -----------
  234. C 0 * *
  235. C 1 U(A,YJ) U(B,YJ)
  236. C 2 U(A,YJ) * J=1,2,...,N+1
  237. C 3 * *
  238. C 4 * U(B,YJ)
  239. C
  240. C NBDCND USOL(I,1) USOL(I,N+1)
  241. C ------ --------- -----------
  242. C 0 * *
  243. C 1 U(XI,C) U(XI,D)
  244. C 2 U(XI,C) * I=1,2,...,M+1
  245. C 3 * *
  246. C 4 * U(XI,D)
  247. C
  248. C where * means the quantities are not used in
  249. C the solution.
  250. C
  251. C If IORDER=2, the user may equivalence GRHS
  252. C and USOL to save space. Note that in this
  253. C case the tables specifying the boundaries of
  254. C the GRHS and USOL arrays determine the
  255. C boundaries uniquely except at the corners.
  256. C If the tables call for both G(X,Y) and
  257. C U(X,Y) at a corner then the solution must be
  258. C chosen. For example, if MBDCND=2 and
  259. C NBDCND=4, then U(A,C), U(A,D), U(B,D) must be
  260. C chosen at the corners in addition to G(B,C).
  261. C
  262. C If IORDER=4, then the two arrays, USOL and
  263. C GRHS, must be distinct.
  264. C
  265. C USOL should be dimensioned IDMN by at least
  266. C N+1 in the calling routine.
  267. C
  268. C IDMN
  269. C The row (or first) dimension of the arrays
  270. C GRHS and USOL as it appears in the program
  271. C calling SEPX4. This parameter is used to
  272. C specify the variable dimension of GRHS and
  273. C USOL. IDMN must be at least 7 and greater
  274. C than or equal to M+1.
  275. C
  276. C W
  277. C A one-dimensional array that must be provided
  278. C by the user for work space.
  279. C 10*N+(16+INT(log2(N)))*(M+1)+23 will suffice
  280. C as a length for W. The actual length of
  281. C W in the calling routine must be set in W(1)
  282. C (see IERROR=11).
  283. C
  284. C On Output USOL
  285. C Contains the approximate solution to the
  286. C elliptic equation. USOL(I,J) is the
  287. C approximation to U(XI,YJ) for I=1,2...,M+1
  288. C and J=1,2,...,N+1. The approximation has
  289. C error O(DLX**2+DLY**2) if called with
  290. C IORDER=2 and O(DLX**4+DLY**4) if called with
  291. C IORDER=4.
  292. C
  293. C W
  294. C W(1) contains the exact minimal length (in
  295. C floating point) required for the work space
  296. C (see IERROR=11).
  297. C
  298. C PERTRB
  299. C If a combination of periodic or derivative
  300. C boundary conditions (i.e., ALPHA=BETA=0 if
  301. C MBDCND=3) is specified and if CF(X)=0 for all
  302. C X, then a solution to the discretized matrix
  303. C equation may not exist (reflecting the non-
  304. C uniqueness of solutions to the PDE). PERTRB
  305. C is a constant calculated and subtracted from
  306. C the right hand side of the matrix equation
  307. C insuring the existence of a solution.
  308. C SEPX4 computes this solution which is a
  309. C weighted minimal least squares solution to
  310. C the original problem. If singularity is
  311. C not detected PERTRB=0.0 is returned by
  312. C SEPX4.
  313. C
  314. C IERROR
  315. C An error flag that indicates invalid input
  316. C parameters or failure to find a solution
  317. C = 0 No error
  318. C = 1 If A greater than B or C greater than D
  319. C = 2 If MBDCND less than 0 or MBDCND greater
  320. C than 4
  321. C = 3 If NBDCND less than 0 or NBDCND greater
  322. C than 4
  323. C = 4 If attempt to find a solution fails.
  324. C (the linear system generated is not
  325. C diagonally dominant.)
  326. C = 5 If IDMN is too small (see discussion of
  327. C IDMN)
  328. C = 6 If M is too small or too large (see
  329. C discussion of M)
  330. C = 7 If N is too small (see discussion of N)
  331. C = 8 If IORDER is not 2 or 4
  332. C = 10 If AFUN is less than or equal to zero
  333. C for some interior mesh point XI
  334. C = 11 If the work space length input in W(1)
  335. C is less than the exact minimal work
  336. C space length required output in W(1).
  337. C = 12 If MBDCND=0 and AF(X)=CF(X)=constant
  338. C or BF(X)=0 for all X is not true.
  339. C
  340. C *Long Description:
  341. C
  342. C Dimension of BDA(N+1), BDB(N+1), BDC(M+1), BDD(M+1),
  343. C Arguments USOL(IDMN,N+1), GRHS(IDMN,N+1),
  344. C W (see argument list)
  345. C
  346. C Latest Revision October 1980
  347. C
  348. C Special Conditions NONE
  349. C
  350. C Common Blocks SPL4
  351. C
  352. C I/O NONE
  353. C
  354. C Precision Single
  355. C
  356. C Required Library NONE
  357. C Files
  358. C
  359. C Specialist John C. Adams, NCAR, Boulder, Colorado 80307
  360. C
  361. C Language FORTRAN
  362. C
  363. C
  364. C Entry Points SEPX4,SPELI4,CHKPR4,CHKSN4,ORTHO4,MINSO4,TRIS4,
  365. C DEFE4,DX4,DY4
  366. C
  367. C History SEPX4 was developed by modifying the ULIB
  368. C routine SEPELI during October 1978.
  369. C It should be used instead of SEPELI whenever
  370. C possible. The increase in speed is at least
  371. C a factor of three.
  372. C
  373. C Algorithm SEPX4 automatically discretizes the separable
  374. C elliptic equation which is then solved by a
  375. C generalized cyclic reduction algorithm in the
  376. C subroutine POIS. The fourth order solution
  377. C is obtained using the technique of
  378. C deferred corrections referenced below.
  379. C
  380. C
  381. C References Keller, H.B., 'Numerical Methods for Two-point
  382. C Boundary-value Problems', Blaisdel (1968),
  383. C Waltham, Mass.
  384. C
  385. C Swarztrauber, P., and R. Sweet (1975):
  386. C 'Efficient FORTRAN Subprograms For The
  387. C Solution of Elliptic Partial Differential
  388. C Equations'. NCAR Technical Note
  389. C NCAR-TN/IA-109, pp. 135-137.
  390. C
  391. C***REFERENCES H. B. Keller, Numerical Methods for Two-point
  392. C Boundary-value Problems, Blaisdel, Waltham, Mass.,
  393. C 1968.
  394. C P. N. Swarztrauber and R. Sweet, Efficient Fortran
  395. C subprograms for the solution of elliptic equations,
  396. C NCAR TN/IA-109, July 1975, 138 pp.
  397. C***ROUTINES CALLED CHKPR4, SPELI4
  398. C***REVISION HISTORY (YYMMDD)
  399. C 801001 DATE WRITTEN
  400. C 890531 Changed all specific intrinsics to generic. (WRB)
  401. C 890531 REVISION DATE from Version 3.2
  402. C 891214 Prologue converted to Version 4.0 format. (BAB)
  403. C 920122 Minor corrections and modifications to prologue. (WRB)
  404. C 920501 Reformatted the REFERENCES section. (WRB)
  405. C***END PROLOGUE SEPX4
  406. C
  407. DIMENSION GRHS(IDMN,*) ,USOL(IDMN,*)
  408. DIMENSION BDA(*) ,BDB(*) ,BDC(*) ,BDD(*) ,
  409. 1 W(*)
  410. EXTERNAL COFX
  411. C***FIRST EXECUTABLE STATEMENT SEPX4
  412. CALL CHKPR4(IORDER,A,B,M,MBDCND,C,D,N,NBDCND,COFX,IDMN,IERROR)
  413. IF (IERROR .NE. 0) RETURN
  414. C
  415. C COMPUTE MINIMUM WORK SPACE AND CHECK WORK SPACE LENGTH INPUT
  416. C
  417. L = N+1
  418. IF (NBDCND .EQ. 0) L = N
  419. K = M+1
  420. L = N+1
  421. C ESTIMATE LOG BASE 2 OF N
  422. LOG2N=INT(LOG(REAL(N+1))/LOG(2.0)+0.5)
  423. LENGTH=4*(N+1)+(10+LOG2N)*(M+1)
  424. IERROR = 11
  425. LINPUT = INT(W(1)+0.5)
  426. LOUTPT = LENGTH+6*(K+L)+1
  427. W(1) = LOUTPT
  428. IF (LOUTPT .GT. LINPUT) RETURN
  429. IERROR = 0
  430. C
  431. C SET WORK SPACE INDICES
  432. C
  433. I1 = LENGTH+2
  434. I2 = I1+L
  435. I3 = I2+L
  436. I4 = I3+L
  437. I5 = I4+L
  438. I6 = I5+L
  439. I7 = I6+L
  440. I8 = I7+K
  441. I9 = I8+K
  442. I10 = I9+K
  443. I11 = I10+K
  444. I12 = I11+K
  445. I13 = 2
  446. CALL SPELI4(IORDER,A,B,M,MBDCND,BDA,ALPHA,BDB,BETA,C,D,N,
  447. 1NBDCND,BDC,BDD,COFX,W(I1),W(I2),W(I3),
  448. 2 W(I4),W(I5),W(I6),W(I7),W(I8),W(I9),W(I10),W(I11),
  449. 3 W(I12),GRHS,USOL,IDMN,W(I13),PERTRB,IERROR)
  450. RETURN
  451. END