drc3jj.f 13 KB

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