(git:34ef472)
cg_test.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief Test of Clebsch-Gordon Coefficients
10 !> \par History
11 !> none
12 !> \author JGH (28.02.2002)
13 ! **************************************************************************************************
14 MODULE cg_test
15 
17  USE kinds, ONLY: dp
22  USE machine, ONLY: m_walltime
23  USE mathconstants, ONLY: pi
24  USE spherical_harmonics, ONLY: clebsch_gordon,&
27  y_lm
28 #include "../base/base_uses.f90"
29 
30  IMPLICIT NONE
31 
32  PRIVATE
33  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cg_test'
34  PUBLIC :: clebsch_gordon_test
35 
36 CONTAINS
37 
38 ! **************************************************************************************************
39 !> \brief ...
40 ! **************************************************************************************************
41  SUBROUTINE clebsch_gordon_test()
42 
43  INTEGER, PARAMETER :: l = 7
44 
45  COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:) :: a1, a2, a3
46  INTEGER :: il, iw, l1, l2, ll, lp, m1, m2, mm, mp, &
47  na
48  REAL(kind=dp) :: ca, cga(10), cn, rga(10, 21), tend, &
49  tstart
50  REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: b1, b2, b3, wa
51 
53 
54  IF (iw > 0) THEN
55 
56  WRITE (iw, '(/,A,/)') " Test of Clebsch-Gordon Coefficients"
57  WRITE (iw, '(T40,A,T77,I4)') " Maximum l value tested:", l
58 
59  na = 500
62  na = lebedev_grid(ll)%n
63  ALLOCATE (wa(na))
64  ALLOCATE (a1(na), a2(na), a3(na))
65  ALLOCATE (b1(na), b2(na), b3(na))
66 
67  wa(1:na) = 4.0_dp*pi*lebedev_grid(ll)%w(1:na)
68 
69  tstart = m_walltime()
70  CALL clebsch_gordon_init(l)
71  tend = m_walltime()
72  tend = tend - tstart
73  WRITE (iw, '(T30,A,T71,F10.3)') " Time for Clebsch-Gordon Table [s] ", tend
74  lp = (l**4 + 6*l**3 + 15*l**2 + 18*l + 8)/8
75  lp = 2*lp*(l + 1)
76  WRITE (iw, '(T30,A,T71,I10)') " Size of Clebsch-Gordon Table ", lp
77  WRITE (iw, '(/,A)') " Start Test for Complex Spherical Harmonics "
78 
79  DO l1 = 0, l
80  DO m1 = -l1, l1
81  CALL y_lm(lebedev_grid(ll)%r, a1, l1, m1)
82  DO l2 = 0, l
83  DO m2 = -l2, l2
84  CALL y_lm(lebedev_grid(ll)%r, a2, l2, m2)
85  CALL clebsch_gordon(l1, m1, l2, m2, cga)
86  DO lp = mod(l1 + l2, 2), l1 + l2, 2
87  mp = m1 + m2
88  IF (lp < abs(mp)) cycle
89  CALL y_lm(lebedev_grid(ll)%r, a3, lp, mp)
90  cn = real(sum(a1*a2*conjg(a3)*wa), kind=dp)
91  il = lp/2 + 1
92  ca = cga(il)
93  IF (abs(ca - cn) > 1.e-10_dp) THEN
94  WRITE (*, '(A,3I5,A,F20.12)') " l ", l1, l2, lp, " A ", ca
95  WRITE (*, '(A,3I5,A,F20.12)') " m ", m1, m2, mp, " N ", cn
96  WRITE (*, *)
97  END IF
98  END DO
99  END DO
100  END DO
101  END DO
102  WRITE (iw, '(A,i2,A)') " Test for l = ", l1, " done"
103  END DO
104 
105  WRITE (iw, '(/,A)') " Start Test for Real Spherical Harmonics "
106  DO l1 = 0, l
107  DO m1 = -l1, l1
108  CALL y_lm(lebedev_grid(ll)%r, b1, l1, m1)
109  DO l2 = 0, l
110  DO m2 = -l2, l2
111  CALL y_lm(lebedev_grid(ll)%r, b2, l2, m2)
112  CALL clebsch_gordon(l1, m1, l2, m2, rga)
113  mp = m1 + m2
114  mm = m1 - m2
115  IF (m1*m2 < 0 .OR. (m1*m2 == 0 .AND. (m1 < 0 .OR. m2 < 0))) THEN
116  mp = -abs(mp)
117  mm = -abs(mm)
118  ELSE
119  mp = abs(mp)
120  mm = abs(mm)
121  END IF
122  DO lp = mod(l1 + l2, 2), l1 + l2, 2
123  IF (abs(mp) <= lp) THEN
124  CALL y_lm(lebedev_grid(ll)%r, b3, lp, mp)
125  cn = sum(b1*b2*b3*wa)
126  il = lp/2 + 1
127  ca = rga(il, 1)
128  IF (abs(ca - cn) > 1.e-10_dp) THEN
129  WRITE (*, '(A,3I5,A,F20.12)') " l ", l1, l2, lp, " A ", ca
130  WRITE (*, '(A,3I5,A,F20.12)') " m ", m1, m2, mp, " N ", cn
131  WRITE (*, *)
132  END IF
133  END IF
134  IF (mp /= mm .AND. abs(mm) <= lp) THEN
135  CALL y_lm(lebedev_grid(ll)%r, b3, lp, mm)
136  cn = sum(b1*b2*b3*wa)
137  il = lp/2 + 1
138  ca = rga(il, 2)
139  IF (abs(ca - cn) > 1.e-10_dp) THEN
140  WRITE (*, '(A,3I5,A,F20.12)') " l ", l1, l2, lp, " A ", ca
141  WRITE (*, '(A,3I5,A,F20.12)') " m ", m1, m2, mm, " N ", cn
142  WRITE (*, *)
143  END IF
144  END IF
145  END DO
146  END DO
147  END DO
148  END DO
149  WRITE (iw, '(A,i2,A)') " Test for l = ", l1, " done"
150  END DO
151 
152  DEALLOCATE (wa)
153  DEALLOCATE (a1, a2, a3)
154  DEALLOCATE (b1, b2, b3)
155 
158 
159  END IF
160 
161  END SUBROUTINE clebsch_gordon_test
162 
163 END MODULE cg_test
164 
Test of Clebsch-Gordon Coefficients.
Definition: cg_test.F:14
subroutine, public clebsch_gordon_test()
...
Definition: cg_test.F:42
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Generation of the spherical Lebedev grids. All Lebedev grids were generated with a precision of at le...
Definition: lebedev.F:57
subroutine, public deallocate_lebedev_grids()
...
Definition: lebedev.F:324
type(oh_grid), dimension(nlg), target, public lebedev_grid
Definition: lebedev.F:85
integer function, public get_number_of_lebedev_grid(l, n)
Get the number of the Lebedev grid, which has the requested angular momentum quantnum number l or siz...
Definition: lebedev.F:114
subroutine, public init_lebedev_grids()
Load the coordinates and weights of the nonredundant Lebedev grid points.
Definition: lebedev.F:344
Machine interface based on Fortran 2003 and POSIX.
Definition: machine.F:17
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition: machine.F:123
Definition of mathematical constants and functions.
Definition: mathconstants.F:16
real(kind=dp), parameter, public pi
Calculate spherical harmonics.
subroutine, public clebsch_gordon_init(l)
...
subroutine, public clebsch_gordon_deallocate()
...