rc3jm.f 13 KB

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