rc3jj.f 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. *DECK RC3JJ
  2. SUBROUTINE RC3JJ (L2, L3, M2, M3, L1MIN, L1MAX, THRCOF, NDIM, IER)
  3. C***BEGIN PROLOGUE RC3JJ
  4. C***PURPOSE Evaluate the 3j symbol f(L1) = ( L1 L2 L3)
  5. C (-M2-M3 M2 M3)
  6. C for all allowed values of L1, the other parameters
  7. C being held fixed.
  8. C***LIBRARY SLATEC
  9. C***CATEGORY C19
  10. C***TYPE SINGLE PRECISION (RC3JJ-S, DRC3JJ-D)
  11. C***KEYWORDS 3J COEFFICIENTS, 3J SYMBOLS, CLEBSCH-GORDAN COEFFICIENTS,
  12. C RACAH COEFFICIENTS, VECTOR ADDITION COEFFICIENTS,
  13. C WIGNER COEFFICIENTS
  14. C***AUTHOR Gordon, R. G., Harvard University
  15. C Schulten, K., Max Planck Institute
  16. C***DESCRIPTION
  17. C
  18. C *Usage:
  19. C
  20. C REAL L2, L3, M2, M3, L1MIN, L1MAX, THRCOF(NDIM)
  21. C INTEGER NDIM, IER
  22. C
  23. C CALL RC3JJ (L2, L3, M2, M3, L1MIN, L1MAX, THRCOF, NDIM, IER)
  24. C
  25. C *Arguments:
  26. C
  27. C L2 :IN Parameter in 3j symbol.
  28. C
  29. C L3 :IN Parameter in 3j symbol.
  30. C
  31. C M2 :IN Parameter in 3j symbol.
  32. C
  33. C M3 :IN Parameter in 3j symbol.
  34. C
  35. C L1MIN :OUT Smallest allowable L1 in 3j symbol.
  36. C
  37. C L1MAX :OUT Largest allowable L1 in 3j symbol.
  38. C
  39. C THRCOF :OUT Set of 3j coefficients generated by evaluating the
  40. C 3j symbol for all allowed values of L1. THRCOF(I)
  41. C will contain f(L1MIN+I-1), I=1,2,...,L1MAX+L1MIN+1.
  42. C
  43. C NDIM :IN Declared length of THRCOF in calling program.
  44. C
  45. C IER :OUT Error flag.
  46. C IER=0 No errors.
  47. C IER=1 Either L2.LT.ABS(M2) or L3.LT.ABS(M3).
  48. C IER=2 Either L2+ABS(M2) or L3+ABS(M3) non-integer.
  49. C IER=3 L1MAX-L1MIN not an integer.
  50. C IER=4 L1MAX less than L1MIN.
  51. C IER=5 NDIM less than L1MAX-L1MIN+1.
  52. C
  53. C *Description:
  54. C
  55. C Although conventionally the parameters of the vector addition
  56. C coefficients satisfy certain restrictions, such as being integers
  57. C or integers plus 1/2, the restrictions imposed on input to this
  58. C subroutine are somewhat weaker. See, for example, Section 27.9 of
  59. C Abramowitz and Stegun or Appendix C of Volume II of A. Messiah.
  60. C The restrictions imposed by this subroutine are
  61. C 1. L2 .GE. ABS(M2) and L3 .GE. ABS(M3);
  62. C 2. L2+ABS(M2) and L3+ABS(M3) must be integers;
  63. C 3. L1MAX-L1MIN must be a non-negative integer, where
  64. C L1MAX=L2+L3 and L1MIN=MAX(ABS(L2-L3),ABS(M2+M3)).
  65. C If the conventional restrictions are satisfied, then these
  66. C restrictions are met.
  67. C
  68. C The user should be cautious in using input parameters that do
  69. C not satisfy the conventional restrictions. For example, the
  70. C the subroutine produces values of
  71. C f(L1) = ( L1 2.5 5.8)
  72. C (-0.3 1.5 -1.2)
  73. C for L1=3.3,4.3,...,8.3 but none of the symmetry properties of the 3j
  74. C symbol, set forth on page 1056 of Messiah, is satisfied.
  75. C
  76. C The subroutine generates f(L1MIN), f(L1MIN+1), ..., f(L1MAX)
  77. C where L1MIN and L1MAX are defined above. The sequence f(L1) is
  78. C generated by a three-term recurrence algorithm with scaling to
  79. C control overflow. Both backward and forward recurrence are used to
  80. C maintain numerical stability. The two recurrence sequences are
  81. C matched at an interior point and are normalized from the unitary
  82. C property of 3j coefficients and Wigner's phase convention.
  83. C
  84. C The algorithm is suited to applications in which large quantum
  85. C numbers arise, such as in molecular dynamics.
  86. C
  87. C***REFERENCES 1. Abramowitz, M., and Stegun, I. A., Eds., Handbook
  88. C of Mathematical Functions with Formulas, Graphs
  89. C and Mathematical Tables, NBS Applied Mathematics
  90. C Series 55, June 1964 and subsequent printings.
  91. C 2. Messiah, Albert., Quantum Mechanics, Volume II,
  92. C North-Holland Publishing Company, 1963.
  93. C 3. Schulten, Klaus and Gordon, Roy G., Exact recursive
  94. C evaluation of 3j and 6j coefficients for quantum-
  95. C mechanical coupling of angular momenta, J Math
  96. C Phys, v 16, no. 10, October 1975, pp. 1961-1970.
  97. C 4. Schulten, Klaus and Gordon, Roy G., Semiclassical
  98. C approximations to 3j and 6j coefficients for
  99. C quantum-mechanical coupling of angular momenta,
  100. C J Math Phys, v 16, no. 10, October 1975,
  101. C pp. 1971-1988.
  102. C 5. Schulten, Klaus and Gordon, Roy G., Recursive
  103. C evaluation of 3j and 6j coefficients, Computer
  104. C Phys Comm, v 11, 1976, pp. 269-278.
  105. C***ROUTINES CALLED R1MACH, XERMSG
  106. C***REVISION HISTORY (YYMMDD)
  107. C 750101 DATE WRITTEN
  108. C 880515 SLATEC prologue added by G. C. Nielson, NBS; parameters
  109. C HUGE and TINY revised to depend on R1MACH.
  110. C 891229 Prologue description rewritten; other prologue sections
  111. C revised; LMATCH (location of match point for recurrences)
  112. C removed from argument list; argument IER changed to serve
  113. C only as an error flag (previously, in cases without error,
  114. C it returned the number of scalings); number of error codes
  115. C increased to provide more precise error information;
  116. C program comments revised; SLATEC error handler calls
  117. C introduced to enable printing of error messages to meet
  118. C SLATEC standards. These changes were done by D. W. Lozier,
  119. C M. A. McClain and J. M. Smith of the National Institute
  120. C of Standards and Technology, formerly NBS.
  121. C 910415 Mixed type expressions eliminated; variable C1 initialized;
  122. C description of THRCOF expanded. These changes were done by
  123. C D. W. Lozier.
  124. C***END PROLOGUE RC3JJ
  125. C
  126. INTEGER NDIM, IER
  127. REAL L2, L3, M2, M3, L1MIN, L1MAX, THRCOF(NDIM)
  128. C
  129. INTEGER I, INDEX, LSTEP, N, NFIN, NFINP1, NFINP2, NFINP3, NLIM,
  130. + NSTEP2
  131. REAL A1, A1S, A2, A2S, C1, C1OLD, C2, CNORM, R1MACH,
  132. + DENOM, DV, EPS, HUGE, L1, M1, NEWFAC, OLDFAC,
  133. + ONE, RATIO, SIGN1, SIGN2, SRHUGE, SRTINY, SUM1,
  134. + SUM2, SUMBAC, SUMFOR, SUMUNI, THREE, THRESH,
  135. + TINY, TWO, X, X1, X2, X3, Y, Y1, Y2, Y3, ZERO
  136. C
  137. DATA ZERO,EPS,ONE,TWO,THREE /0.0,0.01,1.0,2.0,3.0/
  138. C
  139. C***FIRST EXECUTABLE STATEMENT RC3JJ
  140. IER=0
  141. C HUGE is the square root of one twentieth of the largest floating
  142. C point number, approximately.
  143. HUGE = SQRT(R1MACH(2)/20.0)
  144. SRHUGE = SQRT(HUGE)
  145. TINY = 1.0/HUGE
  146. SRTINY = 1.0/SRHUGE
  147. C
  148. C LMATCH = ZERO
  149. M1 = - M2 - M3
  150. C
  151. C Check error conditions 1 and 2.
  152. IF((L2-ABS(M2)+EPS.LT.ZERO).OR.
  153. + (L3-ABS(M3)+EPS.LT.ZERO))THEN
  154. IER=1
  155. CALL XERMSG('SLATEC','RC3JJ','L2-ABS(M2) or L3-ABS(M3) '//
  156. + 'less than zero.',IER,1)
  157. RETURN
  158. ELSEIF((MOD(L2+ABS(M2)+EPS,ONE).GE.EPS+EPS).OR.
  159. + (MOD(L3+ABS(M3)+EPS,ONE).GE.EPS+EPS))THEN
  160. IER=2
  161. CALL XERMSG('SLATEC','RC3JJ','L2+ABS(M2) or L3+ABS(M3) '//
  162. + 'not integer.',IER,1)
  163. RETURN
  164. ENDIF
  165. C
  166. C
  167. C
  168. C Limits for L1
  169. C
  170. L1MIN = MAX(ABS(L2-L3),ABS(M1))
  171. L1MAX = L2 + L3
  172. C
  173. C Check error condition 3.
  174. IF(MOD(L1MAX-L1MIN+EPS,ONE).GE.EPS+EPS)THEN
  175. IER=3
  176. CALL XERMSG('SLATEC','RC3JJ','L1MAX-L1MIN not integer.',IER,1)
  177. RETURN
  178. ENDIF
  179. IF(L1MIN.LT.L1MAX-EPS) GO TO 20
  180. IF(L1MIN.LT.L1MAX+EPS) GO TO 10
  181. C
  182. C Check error condition 4.
  183. IER=4
  184. CALL XERMSG('SLATEC','RC3JJ','L1MIN greater than L1MAX.',IER,1)
  185. RETURN
  186. C
  187. C This is reached in case that L1 can take only one value,
  188. C i.e. L1MIN = L1MAX
  189. C
  190. 10 CONTINUE
  191. C LSCALE = 0
  192. THRCOF(1) = (-ONE) ** INT(ABS(L2+M2-L3+M3)+EPS) /
  193. 1 SQRT(L1MIN + L2 + L3 + ONE)
  194. RETURN
  195. C
  196. C This is reached in case that L1 takes more than one value,
  197. C i.e. L1MIN < L1MAX.
  198. C
  199. 20 CONTINUE
  200. C LSCALE = 0
  201. NFIN = INT(L1MAX-L1MIN+ONE+EPS)
  202. IF(NDIM-NFIN) 21, 23, 23
  203. C
  204. C Check error condition 5.
  205. 21 IER = 5
  206. CALL XERMSG('SLATEC','RC3JJ','Dimension of result array for 3j '//
  207. + 'coefficients too small.',IER,1)
  208. RETURN
  209. C
  210. C
  211. C Starting forward recursion from L1MIN taking NSTEP1 steps
  212. C
  213. 23 L1 = L1MIN
  214. NEWFAC = 0.0
  215. C1 = 0.0
  216. THRCOF(1) = SRTINY
  217. SUM1 = (L1+L1+ONE) * TINY
  218. C
  219. C
  220. LSTEP = 1
  221. 30 LSTEP = LSTEP + 1
  222. L1 = L1 + ONE
  223. C
  224. C
  225. OLDFAC = NEWFAC
  226. A1 = (L1+L2+L3+ONE) * (L1-L2+L3) * (L1+L2-L3) * (-L1+L2+L3+ONE)
  227. A2 = (L1+M1) * (L1-M1)
  228. NEWFAC = SQRT(A1*A2)
  229. IF(L1.LT.ONE+EPS) GO TO 40
  230. C
  231. C
  232. DV = - L2*(L2+ONE) * M1 + L3*(L3+ONE) * M1 + L1*(L1-ONE) * (M3-M2)
  233. DENOM = (L1-ONE) * NEWFAC
  234. C
  235. IF(LSTEP-2) 32, 32, 31
  236. C
  237. 31 C1OLD = ABS(C1)
  238. 32 C1 = - (L1+L1-ONE) * DV / DENOM
  239. GO TO 50
  240. C
  241. C If L1 = 1, (L1-1) has to be factored out of DV, hence
  242. C
  243. 40 C1 = - (L1+L1-ONE) * L1 * (M3-M2) / NEWFAC
  244. C
  245. 50 IF(LSTEP.GT.2) GO TO 60
  246. C
  247. C
  248. C If L1 = L1MIN + 1, the third term in the recursion equation vanishes,
  249. C hence
  250. X = SRTINY * C1
  251. THRCOF(2) = X
  252. SUM1 = SUM1 + TINY * (L1+L1+ONE) * C1*C1
  253. IF(LSTEP.EQ.NFIN) GO TO 220
  254. GO TO 30
  255. C
  256. C
  257. 60 C2 = - L1 * OLDFAC / DENOM
  258. C
  259. C Recursion to the next 3j coefficient X
  260. C
  261. X = C1 * THRCOF(LSTEP-1) + C2 * THRCOF(LSTEP-2)
  262. THRCOF(LSTEP) = X
  263. SUMFOR = SUM1
  264. SUM1 = SUM1 + (L1+L1+ONE) * X*X
  265. IF(LSTEP.EQ.NFIN) GO TO 100
  266. C
  267. C See if last unnormalized 3j coefficient exceeds SRHUGE
  268. C
  269. IF(ABS(X).LT.SRHUGE) GO TO 80
  270. C
  271. C This is reached if last 3j coefficient larger than SRHUGE,
  272. C so that the recursion series THRCOF(1), ... , THRCOF(LSTEP)
  273. C has to be rescaled to prevent overflow
  274. C
  275. C LSCALE = LSCALE + 1
  276. DO 70 I=1,LSTEP
  277. IF(ABS(THRCOF(I)).LT.SRTINY) THRCOF(I) = ZERO
  278. 70 THRCOF(I) = THRCOF(I) / SRHUGE
  279. SUM1 = SUM1 / HUGE
  280. SUMFOR = SUMFOR / HUGE
  281. X = X / SRHUGE
  282. C
  283. C As long as ABS(C1) is decreasing, the recursion proceeds towards
  284. C increasing 3j values and, hence, is numerically stable. Once
  285. C an increase of ABS(C1) is detected, the recursion direction is
  286. C reversed.
  287. C
  288. 80 IF(C1OLD-ABS(C1)) 100, 100, 30
  289. C
  290. C
  291. C Keep three 3j coefficients around LMATCH for comparison with
  292. C backward recursion.
  293. C
  294. 100 CONTINUE
  295. C LMATCH = L1 - 1
  296. X1 = X
  297. X2 = THRCOF(LSTEP-1)
  298. X3 = THRCOF(LSTEP-2)
  299. NSTEP2 = NFIN - LSTEP + 3
  300. C
  301. C
  302. C
  303. C
  304. C Starting backward recursion from L1MAX taking NSTEP2 steps, so
  305. C that forward and backward recursion overlap at three points
  306. C L1 = LMATCH+1, LMATCH, LMATCH-1.
  307. C
  308. NFINP1 = NFIN + 1
  309. NFINP2 = NFIN + 2
  310. NFINP3 = NFIN + 3
  311. L1 = L1MAX
  312. THRCOF(NFIN) = SRTINY
  313. SUM2 = TINY * (L1+L1+ONE)
  314. C
  315. L1 = L1 + TWO
  316. LSTEP = 1
  317. 110 LSTEP = LSTEP + 1
  318. L1 = L1 - ONE
  319. C
  320. OLDFAC = NEWFAC
  321. A1S = (L1+L2+L3)*(L1-L2+L3-ONE)*(L1+L2-L3-ONE)*(-L1+L2+L3+TWO)
  322. A2S = (L1+M1-ONE) * (L1-M1-ONE)
  323. NEWFAC = SQRT(A1S*A2S)
  324. C
  325. DV = - L2*(L2+ONE) * M1 + L3*(L3+ONE) * M1 + L1*(L1-ONE) * (M3-M2)
  326. C
  327. DENOM = L1 * NEWFAC
  328. C1 = - (L1+L1-ONE) * DV / DENOM
  329. IF(LSTEP.GT.2) GO TO 120
  330. C
  331. C If L1 = L1MAX + 1, the third term in the recursion formula vanishes
  332. C
  333. Y = SRTINY * C1
  334. THRCOF(NFIN-1) = Y
  335. SUMBAC = SUM2
  336. SUM2 = SUM2 + TINY * (L1+L1-THREE) * C1*C1
  337. C
  338. GO TO 110
  339. C
  340. C
  341. 120 C2 = - (L1 - ONE) * OLDFAC / DENOM
  342. C
  343. C Recursion to the next 3j coefficient Y
  344. C
  345. Y = C1 * THRCOF(NFINP2-LSTEP) + C2 * THRCOF(NFINP3-LSTEP)
  346. C
  347. IF(LSTEP.EQ.NSTEP2) GO TO 200
  348. C
  349. THRCOF(NFINP1-LSTEP) = Y
  350. SUMBAC = SUM2
  351. SUM2 = SUM2 + (L1+L1-THREE) * Y*Y
  352. C
  353. C See if last unnormalized 3j coefficient exceeds SRHUGE
  354. C
  355. IF(ABS(Y).LT.SRHUGE) GO TO 110
  356. C
  357. C This is reached if last 3j coefficient larger than SRHUGE,
  358. C so that the recursion series THRCOF(NFIN), ... ,THRCOF(NFIN-LSTEP+1)
  359. C has to be rescaled to prevent overflow
  360. C
  361. C LSCALE = LSCALE + 1
  362. DO 130 I=1,LSTEP
  363. INDEX = NFIN - I + 1
  364. IF(ABS(THRCOF(INDEX)).LT.SRTINY) THRCOF(INDEX) = ZERO
  365. 130 THRCOF(INDEX) = THRCOF(INDEX) / SRHUGE
  366. SUM2 = SUM2 / HUGE
  367. SUMBAC = SUMBAC / HUGE
  368. C
  369. C
  370. GO TO 110
  371. C
  372. C
  373. C The forward recursion 3j coefficients X1, X2, X3 are to be matched
  374. C with the corresponding backward recursion values Y1, Y2, Y3.
  375. C
  376. 200 Y3 = Y
  377. Y2 = THRCOF(NFINP2-LSTEP)
  378. Y1 = THRCOF(NFINP3-LSTEP)
  379. C
  380. C
  381. C Determine now RATIO such that YI = RATIO * XI (I=1,2,3) holds
  382. C with minimal error.
  383. C
  384. RATIO = ( X1*Y1 + X2*Y2 + X3*Y3 ) / ( X1*X1 + X2*X2 + X3*X3 )
  385. NLIM = NFIN - NSTEP2 + 1
  386. C
  387. IF(ABS(RATIO).LT.ONE) GO TO 211
  388. C
  389. DO 210 N=1,NLIM
  390. 210 THRCOF(N) = RATIO * THRCOF(N)
  391. SUMUNI = RATIO * RATIO * SUMFOR + SUMBAC
  392. GO TO 230
  393. C
  394. 211 NLIM = NLIM + 1
  395. RATIO = ONE / RATIO
  396. DO 212 N=NLIM,NFIN
  397. 212 THRCOF(N) = RATIO * THRCOF(N)
  398. SUMUNI = SUMFOR + RATIO*RATIO*SUMBAC
  399. GO TO 230
  400. C
  401. 220 SUMUNI = SUM1
  402. C
  403. C
  404. C Normalize 3j coefficients
  405. C
  406. 230 CNORM = ONE / SQRT(SUMUNI)
  407. C
  408. C Sign convention for last 3j coefficient determines overall phase
  409. C
  410. SIGN1 = SIGN(ONE,THRCOF(NFIN))
  411. SIGN2 = (-ONE) ** INT(ABS(L2+M2-L3+M3)+EPS)
  412. IF(SIGN1*SIGN2) 235,235,236
  413. 235 CNORM = - CNORM
  414. C
  415. 236 IF(ABS(CNORM).LT.ONE) GO TO 250
  416. C
  417. DO 240 N=1,NFIN
  418. 240 THRCOF(N) = CNORM * THRCOF(N)
  419. RETURN
  420. C
  421. 250 THRESH = TINY / ABS(CNORM)
  422. DO 251 N=1,NFIN
  423. IF(ABS(THRCOF(N)).LT.THRESH) THRCOF(N) = ZERO
  424. 251 THRCOF(N) = CNORM * THRCOF(N)
  425. C
  426. RETURN
  427. END