hwsssp.f 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. *DECK HWSSSP
  2. SUBROUTINE HWSSSP (TS, TF, M, MBDCND, BDTS, BDTF, PS, PF, N,
  3. + NBDCND, BDPS, BDPF, ELMBDA, F, IDIMF, PERTRB, IERROR, W)
  4. C***BEGIN PROLOGUE HWSSSP
  5. C***PURPOSE Solve a finite difference approximation to the Helmholtz
  6. C equation in spherical coordinates and on the surface of the
  7. C unit sphere (radius of 1).
  8. C***LIBRARY SLATEC (FISHPACK)
  9. C***CATEGORY I2B1A1A
  10. C***TYPE SINGLE PRECISION (HWSSSP-S)
  11. C***KEYWORDS ELLIPTIC, FISHPACK, HELMHOLTZ, PDE, SPHERICAL
  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 HWSSSP solves a finite difference approximation to the
  18. C Helmholtz equation in spherical coordinates and on the surface of
  19. C the unit sphere (radius of 1):
  20. C
  21. C (1/SIN(THETA))(d/dTHETA)(SIN(THETA)(dU/dTHETA))
  22. C
  23. C + (1/SIN(THETA)**2)(d/dPHI)(dU/dPHI)
  24. C
  25. C + LAMBDA*U = F(THETA,PHI)
  26. C
  27. C Where THETA is colatitude and PHI is longitude.
  28. C
  29. C * * * * * * * * Parameter Description * * * * * * * * * *
  30. C
  31. C * * * * * * On Input * * * * * *
  32. C
  33. C TS,TF
  34. C The range of THETA (colatitude), i.e., TS .LE. THETA .LE. TF.
  35. C TS must be less than TF. TS and TF are in radians. A TS of
  36. C zero corresponds to the north pole and a TF of PI corresponds to
  37. C the south pole.
  38. C
  39. C * * * * * * * * * * * * * * IMPORTANT * * * * * * * * * * * * * *
  40. C
  41. C If TF is equal to PI then it must be computed using the statement
  42. C TF = PIMACH(DUM). This insures that TF in the users program is
  43. C equal to PI in this program which permits several tests of the
  44. C input parameters that otherwise would not be possible.
  45. C
  46. C
  47. C M
  48. C The number of panels into which the interval (TS,TF) is
  49. C subdivided. Hence, there will be M+1 grid points in the
  50. C THETA-direction given by THETA(I) = (I-1)DTHETA+TS for
  51. C I = 1,2,...,M+1, where DTHETA = (TF-TS)/M is the panel width.
  52. C M must be greater than 5.
  53. C
  54. C MBDCND
  55. C Indicates the type of boundary condition at THETA = TS and
  56. C THETA = TF.
  57. C
  58. C = 1 If the solution is specified at THETA = TS and THETA = TF.
  59. C = 2 If the solution is specified at THETA = TS and the
  60. C derivative of the solution with respect to THETA is
  61. C specified at THETA = TF (see note 2 below).
  62. C = 3 If the derivative of the solution with respect to THETA is
  63. C specified at THETA = TS and THETA = TF (see notes 1,2
  64. C below).
  65. C = 4 If the derivative of the solution with respect to THETA is
  66. C specified at THETA = TS (see note 1 below) and the
  67. C solution is specified at THETA = TF.
  68. C = 5 If the solution is unspecified at THETA = TS = 0 and the
  69. C solution is specified at THETA = TF.
  70. C = 6 If the solution is unspecified at THETA = TS = 0 and the
  71. C derivative of the solution with respect to THETA is
  72. C specified at THETA = TF (see note 2 below).
  73. C = 7 If the solution is specified at THETA = TS and the
  74. C solution is unspecified at THETA = TF = PI.
  75. C = 8 If the derivative of the solution with respect to THETA is
  76. C specified at THETA = TS (see note 1 below) and the
  77. C solution is unspecified at THETA = TF = PI.
  78. C = 9 If the solution is unspecified at THETA = TS = 0 and
  79. C THETA = TF = PI.
  80. C
  81. C NOTES: 1. If TS = 0, do not use MBDCND = 3,4, or 8, but
  82. C instead use MBDCND = 5,6, or 9 .
  83. C 2. If TF = PI, do not use MBDCND = 2,3, or 6, but
  84. C instead use MBDCND = 7,8, or 9 .
  85. C
  86. C BDTS
  87. C A one-dimensional array of length N+1 that specifies the values
  88. C of the derivative of the solution with respect to THETA at
  89. C THETA = TS. When MBDCND = 3,4, or 8,
  90. C
  91. C BDTS(J) = (d/dTHETA)U(TS,PHI(J)), J = 1,2,...,N+1 .
  92. C
  93. C When MBDCND has any other value, BDTS is a dummy variable.
  94. C
  95. C BDTF
  96. C A one-dimensional array of length N+1 that specifies the values
  97. C of the derivative of the solution with respect to THETA at
  98. C THETA = TF. When MBDCND = 2,3, or 6,
  99. C
  100. C BDTF(J) = (d/dTHETA)U(TF,PHI(J)), J = 1,2,...,N+1 .
  101. C
  102. C When MBDCND has any other value, BDTF is a dummy variable.
  103. C
  104. C PS,PF
  105. C The range of PHI (longitude), i.e., PS .LE. PHI .LE. PF. PS
  106. C must be less than PF. PS and PF are in radians. If PS = 0 and
  107. C PF = 2*PI, periodic boundary conditions are usually prescribed.
  108. C
  109. C * * * * * * * * * * * * * * IMPORTANT * * * * * * * * * * * * * *
  110. C
  111. C If PF is equal to 2*PI then it must be computed using the
  112. C statement PF = 2.*PIMACH(DUM). This insures that PF in the users
  113. C program is equal to 2*PI in this program which permits tests of
  114. C the input parameters that otherwise would not be possible.
  115. C
  116. C
  117. C N
  118. C The number of panels into which the interval (PS,PF) is
  119. C subdivided. Hence, there will be N+1 grid points in the
  120. C PHI-direction given by PHI(J) = (J-1)DPHI+PS for
  121. C J = 1,2,...,N+1, where DPHI = (PF-PS)/N is the panel width.
  122. C N must be greater than 4.
  123. C
  124. C NBDCND
  125. C Indicates the type of boundary condition at PHI = PS and
  126. C PHI = PF.
  127. C
  128. C = 0 If the solution is periodic in PHI, i.e.,
  129. C U(I,J) = U(I,N+J).
  130. C = 1 If the solution is specified at PHI = PS and PHI = PF
  131. C (see note below).
  132. C = 2 If the solution is specified at PHI = PS (see note below)
  133. C and the derivative of the solution with respect to PHI is
  134. C specified at PHI = PF.
  135. C = 3 If the derivative of the solution with respect to PHI is
  136. C specified at PHI = PS and PHI = PF.
  137. C = 4 If the derivative of the solution with respect to PHI is
  138. C specified at PS and the solution is specified at PHI = PF
  139. C (see note below).
  140. C
  141. C NOTE: NBDCND = 1,2, or 4 cannot be used with
  142. C MBDCND = 5,6,7,8, or 9 (the former indicates that the
  143. C solution is specified at a pole, the latter
  144. C indicates that the solution is unspecified).
  145. C Use instead
  146. C MBDCND = 1 or 2 .
  147. C
  148. C BDPS
  149. C A one-dimensional array of length M+1 that specifies the values
  150. C of the derivative of the solution with respect to PHI at
  151. C PHI = PS. When NBDCND = 3 or 4,
  152. C
  153. C BDPS(I) = (d/dPHI)U(THETA(I),PS), I = 1,2,...,M+1 .
  154. C
  155. C When NBDCND has any other value, BDPS is a dummy variable.
  156. C
  157. C BDPF
  158. C A one-dimensional array of length M+1 that specifies the values
  159. C of the derivative of the solution with respect to PHI at
  160. C PHI = PF. When NBDCND = 2 or 3,
  161. C
  162. C BDPF(I) = (d/dPHI)U(THETA(I),PF), I = 1,2,...,M+1 .
  163. C
  164. C When NBDCND has any other value, BDPF is a dummy variable.
  165. C
  166. C ELMBDA
  167. C The constant LAMBDA in the Helmholtz equation. If
  168. C LAMBDA .GT. 0, a solution may not exist. However, HWSSSP will
  169. C attempt to find a solution.
  170. C
  171. C F
  172. C A two-dimensional array that specifies the value of the right
  173. C side of the Helmholtz equation and boundary values (if any).
  174. C For I = 2,3,...,M and J = 2,3,...,N
  175. C
  176. C F(I,J) = F(THETA(I),PHI(J)).
  177. C
  178. C On the boundaries F is defined by
  179. C
  180. C MBDCND F(1,J) F(M+1,J)
  181. C ------ ------------ ------------
  182. C
  183. C 1 U(TS,PHI(J)) U(TF,PHI(J))
  184. C 2 U(TS,PHI(J)) F(TF,PHI(J))
  185. C 3 F(TS,PHI(J)) F(TF,PHI(J))
  186. C 4 F(TS,PHI(J)) U(TF,PHI(J))
  187. C 5 F(0,PS) U(TF,PHI(J)) J = 1,2,...,N+1
  188. C 6 F(0,PS) F(TF,PHI(J))
  189. C 7 U(TS,PHI(J)) F(PI,PS)
  190. C 8 F(TS,PHI(J)) F(PI,PS)
  191. C 9 F(0,PS) F(PI,PS)
  192. C
  193. C NBDCND F(I,1) F(I,N+1)
  194. C ------ -------------- --------------
  195. C
  196. C 0 F(THETA(I),PS) F(THETA(I),PS)
  197. C 1 U(THETA(I),PS) U(THETA(I),PF)
  198. C 2 U(THETA(I),PS) F(THETA(I),PF) I = 1,2,...,M+1
  199. C 3 F(THETA(I),PS) F(THETA(I),PF)
  200. C 4 F(THETA(I),PS) U(THETA(I),PF)
  201. C
  202. C F must be dimensioned at least (M+1)*(N+1).
  203. C
  204. C *NOTE*
  205. C
  206. C If the table calls for both the solution U and the right side F
  207. C at a corner then the solution must be specified.
  208. C
  209. C
  210. C IDIMF
  211. C The row (or first) dimension of the array F as it appears in the
  212. C program calling HWSSSP. This parameter is used to specify the
  213. C variable dimension of F. IDIMF must be at least M+1 .
  214. C
  215. C W
  216. C A one-dimensional array that must be provided by the user for
  217. C work space. W may require up to 4*(N+1)+(16+INT(log2(N+1)))(M+1)
  218. C locations. The actual number of locations used is computed by
  219. C HWSSSP and is output in location W(1). INT( ) denotes the
  220. C FORTRAN integer function.
  221. C
  222. C
  223. C * * * * * * * * * * On Output * * * * * * * * * *
  224. C
  225. C F
  226. C Contains the solution U(I,J) of the finite difference
  227. C approximation for the grid point (THETA(I),PHI(J)),
  228. C I = 1,2,...,M+1, J = 1,2,...,N+1 .
  229. C
  230. C PERTRB
  231. C If one specifies a combination of periodic, derivative or
  232. C unspecified boundary conditions for a Poisson equation
  233. C (LAMBDA = 0), a solution may not exist. PERTRB is a constant,
  234. C calculated and subtracted from F, which ensures that a solution
  235. C exists. HWSSSP then computes this solution, which is a least
  236. C squares solution to the original approximation. This solution
  237. C is not unique and is unnormalized. The value of PERTRB should
  238. C be small compared to the right side F. Otherwise , a solution
  239. C is obtained to an essentially different problem. This comparison
  240. C should always be made to insure that a meaningful solution has
  241. C been obtained.
  242. C
  243. C IERROR
  244. C An error flag that indicates invalid input parameters. Except
  245. C for numbers 0 and 8, a solution is not attempted.
  246. C
  247. C = 0 No error
  248. C = 1 TS.LT.0 or TF.GT.PI
  249. C = 2 TS.GE.TF
  250. C = 3 MBDCND.LT.1 or MBDCND.GT.9
  251. C = 4 PS.LT.0 or PS.GT.PI+PI
  252. C = 5 PS.GE.PF
  253. C = 6 N.LT.5
  254. C = 7 M.LT.5
  255. C = 8 NBDCND.LT.0 or NBDCND.GT.4
  256. C = 9 ELMBDA.GT.0
  257. C = 10 IDIMF.LT.M+1
  258. C = 11 NBDCND equals 1,2 or 4 and MBDCND.GE.5
  259. C = 12 TS.EQ.0 and MBDCND equals 3,4 or 8
  260. C = 13 TF.EQ.PI and MBDCND equals 2,3 or 6
  261. C = 14 MBDCND equals 5,6 or 9 and TS.NE.0
  262. C = 15 MBDCND.GE.7 and TF.NE.PI
  263. C
  264. C Since this is the only means of indicating a possibly incorrect
  265. C call to HWSSSP, the user should test IERROR after a call.
  266. C
  267. C W
  268. C Contains intermediate values that must not be destroyed if
  269. C HWSSSP will be called again with INTL = 1. W(1) contains the
  270. C required length of W .
  271. C
  272. C *Long Description:
  273. C
  274. C * * * * * * * Program Specifications * * * * * * * * * * * *
  275. C
  276. C Dimension of BDTS(N+1),BDTF(N+1),BDPS(M+1),BDPF(M+1),
  277. C Arguments F(IDIMF,N+1),W(see argument list)
  278. C
  279. C Latest January 1978
  280. C Revision
  281. C
  282. C
  283. C Subprograms HWSSSP,HWSSS1,GENBUN,POISD2,POISN2,POISP2,COSGEN,ME
  284. C Required TRIX,TRI3,PIMACH
  285. C
  286. C Special NONE
  287. C Conditions
  288. C
  289. C Common NONE
  290. C Blocks
  291. C
  292. C I/O NONE
  293. C
  294. C Precision Single
  295. C
  296. C Specialist Paul Swarztrauber
  297. C
  298. C Language FORTRAN
  299. C
  300. C History Version 1 - September 1973
  301. C Version 2 - April 1976
  302. C Version 3 - January 1978
  303. C
  304. C Algorithm The routine defines the finite difference
  305. C equations, incorporates boundary data, and adjusts
  306. C the right side of singular systems and then calls
  307. C GENBUN to solve the system.
  308. C
  309. C Space
  310. C Required CONTROL DATA 7600
  311. C
  312. C Timing and The execution time T on the NCAR Control Data
  313. C Accuracy 7600 for subroutine HWSSSP is roughly proportional
  314. C to M*N*log2(N), but also depends on the input
  315. C parameters NBDCND and MBDCND. Some typical values
  316. C are listed in the table below.
  317. C The solution process employed results in a loss
  318. C of no more than three significant digits for N and
  319. C M as large as 64. More detailed information about
  320. C accuracy can be found in the documentation for
  321. C subroutine GENBUN which is the routine that
  322. C solves the finite difference equations.
  323. C
  324. C
  325. C M(=N) MBDCND NBDCND T(MSECS)
  326. C ----- ------ ------ --------
  327. C
  328. C 32 0 0 31
  329. C 32 1 1 23
  330. C 32 3 3 36
  331. C 64 0 0 128
  332. C 64 1 1 96
  333. C 64 3 3 142
  334. C
  335. C Portability American National Standards Institute FORTRAN.
  336. C The machine dependent constant PI is defined in
  337. C function PIMACH.
  338. C
  339. C Required SIN,COS
  340. C Resident
  341. C Routines
  342. C
  343. C References P. N. Swarztrauber,'The Direct Solution Of The
  344. C Discrete Poisson Equation On The Surface Of a
  345. C Sphere, SIAM J. Numer. Anal.,15(1974), pp 212-215
  346. C
  347. C Swarztrauber,P. and R. Sweet, 'Efficient FORTRAN
  348. C Subprograms for The Solution of Elliptic Equations'
  349. C NCAR TN/IA-109, July, 1975, 138 pp.
  350. C
  351. C * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  352. C
  353. C***REFERENCES P. N. Swarztrauber and R. Sweet, Efficient Fortran
  354. C subprograms for the solution of elliptic equations,
  355. C NCAR TN/IA-109, July 1975, 138 pp.
  356. C P. N. Swarztrauber, The direct solution of the discrete
  357. C Poisson equation on the surface of a sphere, SIAM
  358. C Journal on Numerical Analysis 15 (1974), pp. 212-215.
  359. C***ROUTINES CALLED HWSSS1, PIMACH
  360. C***REVISION HISTORY (YYMMDD)
  361. C 801001 DATE WRITTEN
  362. C 890531 Changed all specific intrinsics to generic. (WRB)
  363. C 891009 Removed unreferenced variable. (WRB)
  364. C 891009 REVISION DATE from Version 3.2
  365. C 891214 Prologue converted to Version 4.0 format. (BAB)
  366. C 920501 Reformatted the REFERENCES section. (WRB)
  367. C***END PROLOGUE HWSSSP
  368. C
  369. DIMENSION F(IDIMF,*) ,BDTS(*) ,BDTF(*) ,BDPS(*) ,
  370. 1 BDPF(*) ,W(*)
  371. C***FIRST EXECUTABLE STATEMENT HWSSSP
  372. PI = PIMACH(DUM)
  373. TPI = 2.*PI
  374. IERROR = 0
  375. IF (TS.LT.0. .OR. TF.GT.PI) IERROR = 1
  376. IF (TS .GE. TF) IERROR = 2
  377. IF (MBDCND.LT.1 .OR. MBDCND.GT.9) IERROR = 3
  378. IF (PS.LT.0. .OR. PF.GT.TPI) IERROR = 4
  379. IF (PS .GE. PF) IERROR = 5
  380. IF (N .LT. 5) IERROR = 6
  381. IF (M .LT. 5) IERROR = 7
  382. IF (NBDCND.LT.0 .OR. NBDCND.GT.4) IERROR = 8
  383. IF (ELMBDA .GT. 0.) IERROR = 9
  384. IF (IDIMF .LT. M+1) IERROR = 10
  385. IF ((NBDCND.EQ.1 .OR. NBDCND.EQ.2 .OR. NBDCND.EQ.4) .AND.
  386. 1 MBDCND.GE.5) IERROR = 11
  387. IF (TS.EQ.0. .AND.
  388. 1 (MBDCND.EQ.3 .OR. MBDCND.EQ.4 .OR. MBDCND.EQ.8)) IERROR = 12
  389. IF (TF.EQ.PI .AND.
  390. 1 (MBDCND.EQ.2 .OR. MBDCND.EQ.3 .OR. MBDCND.EQ.6)) IERROR = 13
  391. IF ((MBDCND.EQ.5 .OR. MBDCND.EQ.6 .OR. MBDCND.EQ.9) .AND.
  392. 1 TS.NE.0.) IERROR = 14
  393. IF (MBDCND.GE.7 .AND. TF.NE.PI) IERROR = 15
  394. IF (IERROR.NE.0 .AND. IERROR.NE.9) RETURN
  395. CALL HWSSS1 (TS,TF,M,MBDCND,BDTS,BDTF,PS,PF,N,NBDCND,BDPS,BDPF,
  396. 1 ELMBDA,F,IDIMF,PERTRB,W,W(M+2),W(2*M+3),W(3*M+4),
  397. 2 W(4*M+5),W(5*M+6),W(6*M+7))
  398. W(1) = W(6*M+7)+6*(M+1)
  399. RETURN
  400. END