sepeli.f 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. *DECK SEPELI
  2. SUBROUTINE SEPELI (INTL, IORDER, A, B, M, MBDCND, BDA, ALPHA, BDB,
  3. + BETA, C, D, N, NBDCND, BDC, GAMA, BDD, XNU, COFX, COFY, GRHS,
  4. + USOL, IDMN, W, PERTRB, IERROR)
  5. C***BEGIN PROLOGUE SEPELI
  6. C***PURPOSE Discretize and solve a second and, optionally, a fourth
  7. C order finite difference approximation on a uniform grid to
  8. C the general separable elliptic partial differential
  9. C equation on a rectangle with any combination of periodic or
  10. C mixed boundary conditions.
  11. C***LIBRARY SLATEC (FISHPACK)
  12. C***CATEGORY I2B1A2
  13. C***TYPE SINGLE PRECISION (SEPELI-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 Dimension of BDA(N+1), BDB(N+1), BDC(M+1), BDD(M+1),
  21. C Arguments USOL(IDMN,N+1), GRHS(IDMN,N+1),
  22. C W (see argument list)
  23. C
  24. C Latest Revision March 1977
  25. C
  26. C Purpose SEPELI solves for either the second-order
  27. C finite difference approximation or a
  28. C fourth-order approximation to a separable
  29. C elliptic equation.
  30. C
  31. C 2 2
  32. C AF(X)*d U/dX + BF(X)*dU/dX + CF(X)*U +
  33. C 2 2
  34. C DF(Y)*d U/dY + EF(Y)*dU/dY + FF(Y)*U
  35. C
  36. C = G(X,Y)
  37. C
  38. C on a rectangle (X greater than or equal to A
  39. C and less than or equal to B; Y greater than
  40. C or equal to C and less than or equal to D).
  41. C Any combination of periodic or mixed boundary
  42. C conditions is allowed.
  43. C
  44. C Purpose The possible boundary conditions are:
  45. C in the X-direction:
  46. C (0) Periodic, U(X+B-A,Y)=U(X,Y) for all Y,X
  47. C (1) U(A,Y), U(B,Y) are specified for all Y
  48. C (2) U(A,Y), dU(B,Y)/dX+BETA*U(B,Y) are
  49. C specified for all Y
  50. C (3) dU(A,Y)/dX+ALPHA*U(A,Y),dU(B,Y)/dX+
  51. C BETA*U(B,Y) are specified for all Y
  52. C (4) dU(A,Y)/dX+ALPHA*U(A,Y),U(B,Y) are
  53. C specified for all Y
  54. C
  55. C in the Y-direction:
  56. C (0) Periodic, U(X,Y+D-C)=U(X,Y) for all X,Y
  57. C (1) U(X,C),U(X,D) are specified for all X
  58. C (2) U(X,C),dU(X,D)/dY+XNU*U(X,D) are specified
  59. C for all X
  60. C (3) dU(X,C)/dY+GAMA*U(X,C),dU(X,D)/dY+
  61. C XNU*U(X,D) are specified for all X
  62. C (4) dU(X,C)/dY+GAMA*U(X,C),U(X,D) are
  63. C specified for all X
  64. C
  65. C Arguments
  66. C
  67. C On Input INTL
  68. C = 0 On initial entry to SEPELI or if any of
  69. C the arguments C, D, N, NBDCND, COFY are
  70. C changed from a previous call
  71. C = 1 If C, D, N, NBDCND, COFY are unchanged
  72. C from the previous call.
  73. C
  74. C IORDER
  75. C = 2 If a second-order approximation is sought
  76. C = 4 If a fourth-order approximation is sought
  77. C
  78. C A,B
  79. C The range of the X-independent variable;
  80. C i.e., X is greater than or equal to A and
  81. C less than or equal to B. A must be less than
  82. C B.
  83. C
  84. C M
  85. C The number of panels into which the interval
  86. C [A,B] is subdivided. Hence, there will be
  87. C M+1 grid points in the X-direction given by
  88. C XI=A+(I-1)*DLX for I=1,2,...,M+1 where
  89. C DLX=(B-A)/M is the panel width. M must be
  90. C less than IDMN and greater than 5.
  91. C
  92. C MBDCND
  93. C Indicates the type of boundary condition at
  94. C X=A and X=B
  95. C = 0 If the solution is periodic in X; i.e.,
  96. C U(X+B-A,Y)=U(X,Y) for all Y,X
  97. C = 1 If the solution is specified at X=A and
  98. C X=B; i.e., U(A,Y) and U(B,Y) are
  99. C specified for all Y
  100. C = 2 If the solution is specified at X=A and
  101. C the boundary condition is mixed at X=B;
  102. C i.e., U(A,Y) and dU(B,Y)/dX+BETA*U(B,Y)
  103. C are specified for all Y
  104. C = 3 If the boundary conditions at X=A and X=B
  105. C are mixed; i.e., dU(A,Y)/dX+ALPHA*U(A,Y)
  106. C and dU(B,Y)/dX+BETA*U(B,Y) are specified
  107. C for all Y
  108. C = 4 If the boundary condition at X=A is mixed
  109. C and the solution is specified at X=B;
  110. C i.e., dU(A,Y)/dX+ALPHA*U(A,Y) and U(B,Y)
  111. C are specified for all Y
  112. C
  113. C BDA
  114. C A one-dimensional array of length N+1 that
  115. C specifies the values of dU(A,Y)/dX+
  116. C ALPHA*U(A,Y) at X=A, when MBDCND=3 or 4.
  117. C BDA(J) = dU(A,YJ)/dX+ALPHA*U(A,YJ);
  118. C J=1,2,...,N+1
  119. C when MBDCND has any other value, BDA is a
  120. C dummy parameter.
  121. C
  122. C On Input ALPHA
  123. C The scalar multiplying the solution in case
  124. C of a mixed boundary condition at X=A (see
  125. C argument BDA). If MBDCND = 3,4 then ALPHA is
  126. C a dummy parameter.
  127. C
  128. C BDB
  129. C A one-dimensional array of length N+1 that
  130. C specifies the values of dU(B,Y)/dX+
  131. C BETA*U(B,Y) at X=B. When MBDCND=2 or 3
  132. C BDB(J) = dU(B,YJ)/dX+BETA*U(B,YJ);
  133. C J=1,2,...,N+1
  134. C When MBDCND has any other value, BDB is a
  135. C dummy parameter.
  136. C
  137. C BETA
  138. C The scalar multiplying the solution in case
  139. C of a mixed boundary condition at X=B (see
  140. C argument BDB). If MBDCND=2,3 then BETA is a
  141. C dummy parameter.
  142. C
  143. C C,D
  144. C The range of the Y-independent variable;
  145. C i.e., Y is greater than or equal to C and
  146. C less than or equal to D. C must be less than
  147. C D.
  148. C
  149. C N
  150. C The number of panels into which the interval
  151. C [C,D] is subdivided. Hence, there will be
  152. C N+1 grid points in the Y-direction given by
  153. C YJ=C+(J-1)*DLY for J=1,2,...,N+1 where
  154. C DLY=(D-C)/N is the panel width. In addition,
  155. C N must be greater than 4.
  156. C
  157. C NBDCND
  158. C Indicates the types of boundary conditions at
  159. C Y=C and Y=D
  160. C = 0 If the solution is periodic in Y; i.e.,
  161. C U(X,Y+D-C)=U(X,Y) for all X,Y
  162. C = 1 If the solution is specified at Y=C and
  163. C Y = D, i.e., U(X,C) and U(X,D) are
  164. C specified for all X
  165. C = 2 If the solution is specified at Y=C and
  166. C the boundary condition is mixed at Y=D;
  167. C i.e., U(X,C) and dU(X,D)/dY+XNU*U(X,D)
  168. C are specified for all X
  169. C = 3 If the boundary conditions are mixed at
  170. C Y=C and Y=D; i.e., dU(X,D)/dY+GAMA*U(X,C)
  171. C and dU(X,D)/dY+XNU*U(X,D) are specified
  172. C for all X
  173. C = 4 If the boundary condition is mixed at Y=C
  174. C and the solution is specified at Y=D;
  175. C i.e. dU(X,C)/dY+GAMA*U(X,C) and U(X,D)
  176. C are specified for all X
  177. C
  178. C BDC
  179. C A one-dimensional array of length M+1 that
  180. C specifies the value of dU(X,C)/dY+GAMA*U(X,C)
  181. C at Y=C. When NBDCND=3 or 4
  182. C BDC(I) = dU(XI,C)/dY + GAMA*U(XI,C);
  183. C I=1,2,...,M+1.
  184. C When NBDCND has any other value, BDC is a
  185. C dummy parameter.
  186. C
  187. C GAMA
  188. C The scalar multiplying the solution in case
  189. C of a mixed boundary condition at Y=C (see
  190. C argument BDC). If NBDCND=3,4 then GAMA is a
  191. C dummy parameter.
  192. C
  193. C BDD
  194. C A one-dimensional array of length M+1 that
  195. C specifies the value of dU(X,D)/dY +
  196. C XNU*U(X,D) at Y=C. When NBDCND=2 or 3
  197. C BDD(I) = dU(XI,D)/dY + XNU*U(XI,D);
  198. C I=1,2,...,M+1.
  199. C When NBDCND has any other value, BDD is a
  200. C dummy parameter.
  201. C
  202. C XNU
  203. C The scalar multiplying the solution in case
  204. C of a mixed boundary condition at Y=D (see
  205. C argument BDD). If NBDCND=2 or 3 then XNU is
  206. C a dummy parameter.
  207. C
  208. C COFX
  209. C A user-supplied subprogram with
  210. C parameters X, AFUN, BFUN, CFUN which
  211. C returns the values of the X-dependent
  212. C coefficients AF(X), BF(X), CF(X) in
  213. C the elliptic equation at X.
  214. C
  215. C COFY
  216. C A user-supplied subprogram with
  217. C parameters Y, DFUN, EFUN, FFUN which
  218. C returns the values of the Y-dependent
  219. C coefficients DF(Y), EF(Y), FF(Y) in
  220. C the elliptic equation at Y.
  221. C
  222. C NOTE: COFX and COFY must be declared external
  223. C in the calling routine. The values returned in
  224. C AFUN and DFUN must satisfy AFUN*DFUN greater
  225. C than 0 for A less than X less than B,
  226. C C less than Y less than D (see IERROR=10).
  227. C The coefficients provided may lead to a matrix
  228. C equation which is not diagonally dominant in
  229. C which case solution may fail (see IERROR=4).
  230. C
  231. C GRHS
  232. C A two-dimensional array that specifies the
  233. C values of the right-hand side of the elliptic
  234. C equation; i.e., GRHS(I,J)=G(XI,YI), for
  235. C I=2,...,M; J=2,...,N. At the boundaries,
  236. C GRHS is defined by
  237. C
  238. C MBDCND GRHS(1,J) GRHS(M+1,J)
  239. C ------ --------- -----------
  240. C 0 G(A,YJ) G(B,YJ)
  241. C 1 * *
  242. C 2 * G(B,YJ) J=1,2,...,N+1
  243. C 3 G(A,YJ) G(B,YJ)
  244. C 4 G(A,YJ) *
  245. C
  246. C NBDCND GRHS(I,1) GRHS(I,N+1)
  247. C ------ --------- -----------
  248. C 0 G(XI,C) G(XI,D)
  249. C 1 * *
  250. C 2 * G(XI,D) I=1,2,...,M+1
  251. C 3 G(XI,C) G(XI,D)
  252. C 4 G(XI,C) *
  253. C
  254. C where * means these quantities are not used.
  255. C GRHS should be dimensioned IDMN by at least
  256. C N+1 in the calling routine.
  257. C
  258. C USOL
  259. C A two-dimensional array that specifies the
  260. C values of the solution along the boundaries.
  261. C At the boundaries, USOL is defined by
  262. C
  263. C MBDCND USOL(1,J) USOL(M+1,J)
  264. C ------ --------- -----------
  265. C 0 * *
  266. C 1 U(A,YJ) U(B,YJ)
  267. C 2 U(A,YJ) * J=1,2,...,N+1
  268. C 3 * *
  269. C 4 * U(B,YJ)
  270. C
  271. C NBDCND USOL(I,1) USOL(I,N+1)
  272. C ------ --------- -----------
  273. C 0 * *
  274. C 1 U(XI,C) U(XI,D)
  275. C 2 U(XI,C) * I=1,2,...,M+1
  276. C 3 * *
  277. C 4 * U(XI,D)
  278. C
  279. C where * means the quantities are not used in
  280. C the solution.
  281. C
  282. C If IORDER=2, the user may equivalence GRHS
  283. C and USOL to save space. Note that in this
  284. C case the tables specifying the boundaries of
  285. C the GRHS and USOL arrays determine the
  286. C boundaries uniquely except at the corners.
  287. C If the tables call for both G(X,Y) and
  288. C U(X,Y) at a corner then the solution must be
  289. C chosen. For example, if MBDCND=2 and
  290. C NBDCND=4, then U(A,C), U(A,D), U(B,D) must be
  291. C chosen at the corners in addition to G(B,C).
  292. C
  293. C If IORDER=4, then the two arrays, USOL and
  294. C GRHS, must be distinct.
  295. C
  296. C USOL should be dimensioned IDMN by at least
  297. C N+1 in the calling routine.
  298. C
  299. C IDMN
  300. C The row (or first) dimension of the arrays
  301. C GRHS and USOL as it appears in the program
  302. C calling SEPELI. This parameter is used to
  303. C specify the variable dimension of GRHS and
  304. C USOL. IDMN must be at least 7 and greater
  305. C than or equal to M+1.
  306. C
  307. C W
  308. C A one-dimensional array that must be provided
  309. C by the user for work space. Let
  310. C K=INT(log2(N+1))+1 and set L=2**(K+1).
  311. C then (K-2)*L+K+10*N+12*M+27 will suffice
  312. C as a length of W. THE actual length of W in
  313. C the calling routine must be set in W(1) (see
  314. C IERROR=11).
  315. C
  316. C On Output USOL
  317. C Contains the approximate solution to the
  318. C elliptic equation. USOL(I,J) is the
  319. C approximation to U(XI,YJ) for I=1,2...,M+1
  320. C and J=1,2,...,N+1. The approximation has
  321. C error O(DLX**2+DLY**2) if called with
  322. C IORDER=2 and O(DLX**4+DLY**4) if called with
  323. C IORDER=4.
  324. C
  325. C W
  326. C Contains intermediate values that must not be
  327. C destroyed if SEPELI is called again with
  328. C INTL=1. In addition W(1) contains the exact
  329. C minimal length (in floating point) required
  330. C for the work space (see IERROR=11).
  331. C
  332. C PERTRB
  333. C If a combination of periodic or derivative
  334. C boundary conditions (i.e., ALPHA=BETA=0 if
  335. C MBDCND=3; GAMA=XNU=0 if NBDCND=3) is
  336. C specified and if the coefficients of U(X,Y)
  337. C in the separable elliptic equation are zero
  338. C (i.e., CF(X)=0 for X greater than or equal to
  339. C A and less than or equal to B; FF(Y)=0 for
  340. C Y greater than or equal to C and less than
  341. C or equal to D) then a solution may not exist.
  342. C PERTRB is a constant calculated and
  343. C subtracted from the right-hand side of the
  344. C matrix equations generated by SEPELI which
  345. C insures that a solution exists. SEPELI then
  346. C computes this solution which is a weighted
  347. C minimal least squares solution to the
  348. C original problem.
  349. C
  350. C IERROR
  351. C An error flag that indicates invalid input
  352. C parameters or failure to find a solution
  353. C = 0 No error
  354. C = 1 If A greater than B or C greater than D
  355. C = 2 If MBDCND less than 0 or MBDCND greater
  356. C than 4
  357. C = 3 If NBDCND less than 0 or NBDCND greater
  358. C than 4
  359. C = 4 If attempt to find a solution fails.
  360. C (the linear system generated is not
  361. C diagonally dominant.)
  362. C = 5 If IDMN is too small (see discussion of
  363. C IDMN)
  364. C = 6 If M is too small or too large (see
  365. C discussion of M)
  366. C = 7 If N is too small (see discussion of N)
  367. C = 8 If IORDER is not 2 or 4
  368. C = 9 If INTL is not 0 or 1
  369. C = 10 If AFUN*DFUN less than or equal to 0 for
  370. C some interior mesh point (XI,YJ)
  371. C = 11 If the work space length input in W(1)
  372. C is less than the exact minimal work
  373. C space length required output in W(1).
  374. C
  375. C NOTE (concerning IERROR=4): for the
  376. C coefficients input through COFX, COFY, the
  377. C discretization may lead to a block
  378. C tridiagonal linear system which is not
  379. C diagonally dominant (for example, this
  380. C happens if CFUN=0 and BFUN/(2.*DLX) greater
  381. C than AFUN/DLX**2). In this case solution may
  382. C fail. This cannot happen in the limit as
  383. C DLX, DLY approach zero. Hence, the condition
  384. C may be remedied by taking larger values for M
  385. C or N.
  386. C
  387. C Entry Points SEPELI, SPELIP, CHKPRM, CHKSNG, ORTHOG, MINSOL,
  388. C TRISP, DEFER, DX, DY, BLKTRI, BLKTR1, INDXB,
  389. C INDXA, INDXC, PROD, PRODP, CPROD, CPRODP,
  390. C PPADD, PSGF, BSRH, PPSGF, PPSPF, COMPB,
  391. C TRUN1, STOR1, TQLRAT
  392. C
  393. C Special Conditions NONE
  394. C
  395. C Common Blocks SPLP, CBLKT
  396. C
  397. C I/O NONE
  398. C
  399. C Precision Single
  400. C
  401. C Specialist John C. Adams, NCAR, Boulder, Colorado 80307
  402. C
  403. C Language FORTRAN
  404. C
  405. C History Developed at NCAR during 1975-76.
  406. C
  407. C Algorithm SEPELI automatically discretizes the separable
  408. C elliptic equation which is then solved by a
  409. C generalized cyclic reduction algorithm in the
  410. C subroutine, BLKTRI. The fourth-order solution
  411. C is obtained using 'Deferred Corrections' which
  412. C is described and referenced in sections,
  413. C references and method.
  414. C
  415. C Space Required 14654 (octal) = 6572 (decimal)
  416. C
  417. C Accuracy and Timing The following computational results were
  418. C obtained by solving the sample problem at the
  419. C end of this write-up on the Control Data 7600.
  420. C The op count is proportional to M*N*log2(N).
  421. C In contrast to the other routines in this
  422. C chapter, accuracy is tested by computing and
  423. C tabulating second- and fourth-order
  424. C discretization errors. Below is a table
  425. C containing computational results. The times
  426. C given do not include initialization (i.e.,
  427. C times are for INTL=1). Note that the
  428. C fourth-order accuracy is not realized until the
  429. C mesh is sufficiently refined.
  430. C
  431. C Second-order Fourth-order Second-order Fourth-order
  432. C M N Execution Time Execution Time Error Error
  433. C (M SEC) (M SEC)
  434. C 6 6 6 14 6.8E-1 1.2E0
  435. C 14 14 23 58 1.4E-1 1.8E-1
  436. C 30 30 100 247 3.2E-2 9.7E-3
  437. C 62 62 445 1,091 7.5E-3 3.0E-4
  438. C 126 126 2,002 4,772 1.8E-3 3.5E-6
  439. C
  440. C Portability There are no machine-dependent constants.
  441. C
  442. C Required Resident SQRT, ABS, LOG
  443. C Routines
  444. C
  445. C References Keller, H.B., 'Numerical Methods for Two-point
  446. C Boundary-value Problems', Blaisdel (1968),
  447. C Waltham, Mass.
  448. C
  449. C Swarztrauber, P., and R. Sweet (1975):
  450. C 'Efficient FORTRAN Subprograms for The
  451. C Solution of Elliptic Partial Differential
  452. C Equations'. NCAR Technical Note
  453. C NCAR-TN/IA-109, pp. 135-137.
  454. C
  455. C***REFERENCES H. B. Keller, Numerical Methods for Two-point
  456. C Boundary-value Problems, Blaisdel, Waltham, Mass.,
  457. C 1968.
  458. C P. N. Swarztrauber and R. Sweet, Efficient Fortran
  459. C subprograms for the solution of elliptic equations,
  460. C NCAR TN/IA-109, July 1975, 138 pp.
  461. C***ROUTINES CALLED CHKPRM, SPELIP
  462. C***REVISION HISTORY (YYMMDD)
  463. C 801001 DATE WRITTEN
  464. C 890531 Changed all specific intrinsics to generic. (WRB)
  465. C 890531 REVISION DATE from Version 3.2
  466. C 891214 Prologue converted to Version 4.0 format. (BAB)
  467. C 920501 Reformatted the REFERENCES section. (WRB)
  468. C***END PROLOGUE SEPELI
  469. C
  470. DIMENSION GRHS(IDMN,*) ,USOL(IDMN,*)
  471. DIMENSION BDA(*) ,BDB(*) ,BDC(*) ,BDD(*) ,
  472. 1 W(*)
  473. EXTERNAL COFX ,COFY
  474. C***FIRST EXECUTABLE STATEMENT SEPELI
  475. CALL CHKPRM (INTL,IORDER,A,B,M,MBDCND,C,D,N,NBDCND,COFX,COFY,
  476. 1 IDMN,IERROR)
  477. IF (IERROR .NE. 0) RETURN
  478. C
  479. C COMPUTE MINIMUM WORK SPACE AND CHECK WORK SPACE LENGTH INPUT
  480. C
  481. L = N+1
  482. IF (NBDCND .EQ. 0) L = N
  483. LOGB2N = INT(LOG(L+0.5)/LOG(2.0))+1
  484. LL = 2**(LOGB2N+1)
  485. K = M+1
  486. L = N+1
  487. LENGTH = (LOGB2N-2)*LL+LOGB2N+MAX(2*L,6*K)+5
  488. IF (NBDCND .EQ. 0) LENGTH = LENGTH+2*L
  489. IERROR = 11
  490. LINPUT = INT(W(1)+0.5)
  491. LOUTPT = LENGTH+6*(K+L)+1
  492. W(1) = LOUTPT
  493. IF (LOUTPT .GT. LINPUT) RETURN
  494. IERROR = 0
  495. C
  496. C SET WORK SPACE INDICES
  497. C
  498. I1 = LENGTH+2
  499. I2 = I1+L
  500. I3 = I2+L
  501. I4 = I3+L
  502. I5 = I4+L
  503. I6 = I5+L
  504. I7 = I6+L
  505. I8 = I7+K
  506. I9 = I8+K
  507. I10 = I9+K
  508. I11 = I10+K
  509. I12 = I11+K
  510. I13 = 2
  511. CALL SPELIP (INTL,IORDER,A,B,M,MBDCND,BDA,ALPHA,BDB,BETA,C,D,N,
  512. 1 NBDCND,BDC,GAMA,BDD,XNU,COFX,COFY,W(I1),W(I2),W(I3),
  513. 2 W(I4),W(I5),W(I6),W(I7),W(I8),W(I9),W(I10),W(I11),
  514. 3 W(I12),GRHS,USOL,IDMN,W(I13),PERTRB,IERROR)
  515. RETURN
  516. END