(git:7fc1fe1)
Loading...
Searching...
No Matches
cg_test.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Test of the Gaunt coefficients
10!> \note
11!> Checks that the Gaunt coefficients returned by libwignernj agree with a
12!> Lebedev quadrature of the corresponding triple product of the spherical
13!> harmonics of spherical_harmonics::y_lm. This guards the phase and
14!> normalisation conventions on both sides; the values themselves are
15!> exact by construction in libwignernj.
16!> \par History
17!> JGH 1-Mar-2002 : Clebsch-Gordon coefficients
18!> 09.2026 rewritten against libwignernj [Susi Lehtola]
19!> \author JGH 1-Mar-2002
20! **************************************************************************************************
21MODULE cg_test
22
24 USE kinds, ONLY: dp
29 USE mathconstants, ONLY: pi
30 USE spherical_harmonics, ONLY: y_lm
33#include "../base/base_uses.f90"
34
35 IMPLICIT NONE
36 PRIVATE
37 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cg_test'
39
40CONTAINS
41
42! **************************************************************************************************
43!> \brief Compare the Gaunt coefficients against a Lebedev quadrature of the
44!> triple product of spherical harmonics
45! **************************************************************************************************
47
48 INTEGER, PARAMETER :: lmax = 7
49 REAL(kind=dp), PARAMETER :: eps = 1.0e-10_dp
50
51 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: yc
52 INTEGER :: i1, i2, i3, iw, l, ll, m, n, na, nfun, &
53 nfun1
54 INTEGER, ALLOCATABLE, DIMENSION(:) :: lof, mof
55 REAL(kind=dp) :: dmax_complex, dmax_real, ref
56 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: wa
57 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: yr
58
60
61 IF (iw <= 0) RETURN
62
63 WRITE (iw, '(/,A,/)') " Test of the Gaunt coefficients"
64 WRITE (iw, '(T40,A,T77,I4)') " Maximum l value tested:", lmax
65
66 na = 500
69 na = lebedev_grid(ll)%n
70 ALLOCATE (wa(na))
71 wa(1:na) = 4.0_dp*pi*lebedev_grid(ll)%w(1:na)
72
73 ! The two harmonics that are multiplied run up to lmax, their product
74 ! is expanded in harmonics up to 2*lmax
75 nfun1 = (lmax + 1)**2
76 nfun = (2*lmax + 1)**2
77 ALLOCATE (lof(nfun), mof(nfun))
78 ALLOCATE (yr(na, nfun), yc(na, nfun))
79 n = 0
80 DO l = 0, 2*lmax
81 DO m = -l, l
82 n = n + 1
83 lof(n) = l
84 mof(n) = m
85 CALL y_lm(lebedev_grid(ll)%r, yr(:, n), l, m)
86 CALL y_lm(lebedev_grid(ll)%r, yc(:, n), l, m)
87 END DO
88 END DO
89 cpassert(n == nfun)
90
91 dmax_real = 0.0_dp
92 dmax_complex = 0.0_dp
93 DO i1 = 1, nfun1
94 DO i2 = 1, nfun1
95 DO i3 = 1, nfun
96 ! Real spherical harmonics
97 ref = real_gaunt(lof(i1), mof(i1), lof(i2), mof(i2), lof(i3), mof(i3))
98 dmax_real = max(dmax_real, &
99 abs(ref - sum(wa*yr(:, i1)*yr(:, i2)*yr(:, i3))))
100 ! Complex spherical harmonics. Unlike the real ones, the complex
101 ! harmonics of y_lm are defined without the Condon-Shortley phase
102 ! (see cvy_lm: P_l^|m| with no (-1)^m), so they are related to the
103 ! Condon-Shortley harmonics that libwignernj uses by
104 ! Y_cp2k(l,m) = (-1)^max(m,0) Y_cs(l,m).
105 ! The Gaunt coefficient vanishes unless m1 + m2 + m3 = 0, in which
106 ! case the integral is real.
107 ref = complex_gaunt(lof(i1), mof(i1), lof(i2), mof(i2), lof(i3), mof(i3))
108 ref = ref*(-1.0_dp)**(max(mof(i1), 0) + max(mof(i2), 0) + max(mof(i3), 0))
109 dmax_complex = max(dmax_complex, &
110 abs(cmplx(ref, 0.0_dp, kind=dp) - &
111 sum(wa*yc(:, i1)*yc(:, i2)*yc(:, i3))))
112 END DO
113 END DO
114 WRITE (iw, '(A,I2,A)') " Test for l = ", lof(i1), " done"
115 END DO
116
117 WRITE (iw, '(/,T30,A,T71,ES10.3)') " Real spherical harmonics, max deviation ", dmax_real
118 WRITE (iw, '(T30,A,T71,ES10.3)') " Complex spherical harmonics, max deviation ", dmax_complex
119
120 DEALLOCATE (wa, lof, mof, yr, yc)
122
123 IF (max(dmax_real, dmax_complex) > eps) THEN
124 cpabort("The Gaunt coefficients disagree with the numerical integration")
125 END IF
126
127 END SUBROUTINE gaunt_coefficient_test
128
129END MODULE cg_test
Test of the Gaunt coefficients.
Definition cg_test.F:21
subroutine, public gaunt_coefficient_test()
Compare the Gaunt coefficients against a Lebedev quadrature of the triple product of spherical harmon...
Definition cg_test.F:47
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
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
Calculate spherical harmonics.
Interface to libwignernj for the angular momentum algebra.
real(kind=dp) function, public real_gaunt(l1, m1, l2, m2, l3, m3)
Gaunt coefficient of three real spherical harmonics, int S(l1,m1) S(l2,m2) S(l3,m3) dOmega.
real(kind=dp) function, public complex_gaunt(l1, m1, l2, m2, l3, m3)
Gaunt coefficient of three complex spherical harmonics, int Y(l1,m1) Y(l2,m2) Y(l3,...