20#include "../base/base_uses.f90"
28 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gamma'
29 REAL(KIND=
dp),
PARAMETER :: teps = 1.0e-13_dp
33 INTEGER,
SAVE :: current_nmax = -1
37 REAL(KIND=
dp),
DIMENSION(:, :),
ALLOCATABLE,
SAVE :: ftable
64 SUBROUTINE create_md_ftable(nmax, tmin, tmax, tdelta)
66 INTEGER,
INTENT(IN) :: nmax
67 REAL(KIND=
dp),
INTENT(IN) :: tmin, tmax, tdelta
69 INTEGER :: itab, itabmax, itabmin, n
72 IF (current_nmax > -1)
THEN
73 CALL cp_abort(__location__, &
74 "An incomplete Gamma function table is already "// &
75 "allocated. Use the init routine for an update")
79 CALL cp_abort(__location__, &
80 "A negative n value for the initialization of the "// &
81 "incomplete Gamma function is invalid")
86 IF ((tmax < 0.0_dp) .OR. &
87 (tmin < 0.0_dp) .OR. &
88 (tdelta <= 0.0_dp) .OR. &
90 cpabort(
"Invalid arguments")
95 itabmin = floor(tmin/tdelta)
96 itabmax = ceiling((tmax - tmin)/tdelta)
98 ALLOCATE (ftable(0:n, itabmin:itabmax))
103 DO itab = itabmin, itabmax
104 t = real(itab,
dp)*tdelta
112 END SUBROUTINE create_md_ftable
122 IF (current_nmax > -1)
THEN
155 INTEGER,
INTENT(IN) :: nmax
156 REAL(kind=
dp),
INTENT(IN) :: t
157 REAL(kind=
dp),
DIMENSION(0:nmax),
INTENT(OUT) :: f
159 INTEGER :: itab, k, n
160 REAL(kind=
dp) :: expt, g, tdelta, tmp, ttab
169 f(n) = 1.0_dp/real(2*n + 1,
dp)
172 ELSE IF (t <= 12.0_dp)
THEN
181 IF (nmax > current_nmax)
THEN
185 itab = nint(t/tdelta)
186 ttab = real(itab,
dp)*tdelta
188 f(nmax) = ftable(nmax, itab)
193 f(nmax) = f(nmax) + ftable(nmax + k, itab)*tmp*
ifac(k)
201 DO n = nmax - 1, 0, -1
202 f(n) = (2.0_dp*t*f(n + 1) + expt)/real(2*n + 1,
dp)
210 IF (t <= 15.0_dp)
THEN
214 g = 0.4999489092_dp - 0.2473631686_dp*tmp + &
215 0.321180909_dp*tmp**2 - 0.3811559346_dp*tmp**3
216 f(0) = 0.5_dp*sqrt(
pi*tmp) - g*exp(-t)*tmp
218 ELSE IF (t <= 18.0_dp)
THEN
222 g = 0.4998436875_dp - 0.24249438_dp*tmp + 0.24642845_dp*tmp**2
223 f(0) = 0.5_dp*sqrt(
pi*tmp) - g*exp(-t)*tmp
225 ELSE IF (t <= 24.0_dp)
THEN
229 g = 0.499093162_dp - 0.2152832_dp*tmp
230 f(0) = 0.5_dp*sqrt(
pi*tmp) - g*exp(-t)*tmp
232 ELSE IF (t <= 30.0_dp)
THEN
237 f(0) = 0.5_dp*sqrt(
pi*tmp) - g*exp(-t)*tmp
243 f(0) = 0.5_dp*sqrt(
pi*tmp)
247 IF (t > real(2*nmax + 36,
dp))
THEN
257 f(n) = (0.5_dp*tmp)*(real(2*n - 1,
dp)*f(n - 1) - expt)
281 SUBROUTINE fgamma_1(nmax, t, f)
283 INTEGER,
INTENT(IN) :: nmax
284 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: t
285 REAL(kind=
dp),
DIMENSION(SIZE(t, 1), 0:nmax), &
288 INTEGER :: i, itab, k, n
289 REAL(kind=
dp) :: expt, g, tdelta, tmp, ttab
295 IF (t(i) < teps)
THEN
300 f(i, n) = 1.0_dp/real(2*n + 1,
dp)
303 ELSE IF (t(i) <= 12.0_dp)
THEN
312 IF (nmax > current_nmax)
THEN
316 itab = nint(t(i)/tdelta)
317 ttab = real(itab,
dp)*tdelta
319 f(i, nmax) = ftable(nmax, itab)
323 tmp = tmp*(ttab - t(i))
324 f(i, nmax) = f(i, nmax) + ftable(nmax + k, itab)*tmp*
ifac(k)
332 DO n = nmax - 1, 0, -1
333 f(i, n) = (2.0_dp*t(i)*f(i, n + 1) + expt)/real(2*n + 1,
dp)
340 IF (t(i) <= 15.0_dp)
THEN
344 g = 0.4999489092_dp - 0.2473631686_dp/t(i) + &
345 0.321180909_dp/t(i)**2 - 0.3811559346_dp/t(i)**3
346 f(i, 0) = 0.5_dp*sqrt(
pi/t(i)) - g*exp(-t(i))/t(i)
348 ELSE IF (t(i) <= 18.0_dp)
THEN
352 g = 0.4998436875_dp - 0.24249438_dp/t(i) + 0.24642845_dp/t(i)**2
353 f(i, 0) = 0.5_dp*sqrt(
pi/t(i)) - g*exp(-t(i))/t(i)
355 ELSE IF (t(i) <= 24.0_dp)
THEN
359 g = 0.499093162_dp - 0.2152832_dp/t(i)
360 f(i, 0) = 0.5_dp*sqrt(
pi/t(i)) - g*exp(-t(i))/t(i)
362 ELSE IF (t(i) <= 30.0_dp)
THEN
367 f(i, 0) = 0.5_dp*sqrt(
pi/t(i)) - g*exp(-t(i))/t(i)
373 f(i, 0) = 0.5_dp*sqrt(
pi/t(i))
377 IF (t(i) > real(2*nmax + 36,
dp))
THEN
387 f(i, n) = 0.5_dp*(real(2*n - 1,
dp)*f(i, n - 1) - expt)/t(i)
394 END SUBROUTINE fgamma_1
424 INTEGER,
INTENT(IN) :: nmax
425 REAL(kind=
dp),
INTENT(IN) :: t
426 REAL(kind=
dp),
DIMENSION(0:nmax) :: f
428 INTEGER,
PARAMETER :: kmax = 50
429 REAL(kind=
dp),
PARAMETER :: eps = epsilon(0.0_dp)
432 REAL(kind=
dp) :: expt, factor, p, sumterm, sumtot, term
433 REAL(kind=
dp),
DIMENSION(kmax+10) :: r
445 f(n) = 1.0_dp/real(2*n + 1,
dp)
448 ELSE IF (t <= 50.0_dp)
THEN
452 r(kmax + 10) = 0.0_dp
454 DO j = kmax + 9, 1, -1
455 r(j) = -t/(real(4*j + 2,
dp) - t*r(j + 1))
458 factor = 2.0_dp*sinh(0.5_dp*t)*exp(-0.5_dp*t)/t
464 sumtot = factor/real(2*n + 1,
dp)
471 term = term*real(2*n - 2*k + 1,
dp)/real(2*n + 2*k + 1,
dp)
481 sumterm = factor*term*p*real(2*k + 1,
dp)/real(2*n + 1,
dp)
483 IF (abs(sumterm) < eps)
THEN
489 ELSE IF (k == kmax)
THEN
493 cpabort(
"Maximum number of iterations reached")
499 sumtot = sumtot + sumterm
513 f(0) = 0.5_dp*sqrt(
pi/t)
521 f(n) = 0.5_dp*(real(2*n - 1,
dp)*f(n - 1) - expt)/t
540 INTEGER,
INTENT(IN) :: nmax
543 CALL cp_abort(__location__, &
544 "A negative n value for the initialization of the "// &
545 "incomplete Gamma function is invalid")
550 IF (nmax > current_nmax)
THEN
554 CALL create_md_ftable(nmax, 0.0_dp, 12.0_dp, 0.1_dp)
Calculation of the incomplete Gamma function F_n(t) for multi-center integrals over Cartesian Gaussia...
subroutine, public init_md_ftable(nmax)
Initialize a table of F_n(t) values in the range 0 <= t <= 12 with a stepsize of 0....
real(kind=dp) function, dimension(0:nmax), public fgamma_ref(nmax, t)
Calculation of the incomplete Gamma function F_n(t) using a spherical Bessel function expansion....
subroutine, public deallocate_md_ftable()
Deallocate the table of F_n(t) values.
subroutine, public fgamma_0(nmax, t, f)
Calculation of the incomplete Gamma function F(t) for multicenter integrals over Gaussian functions....
Defines the basic variable types.
integer, parameter, public dp
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
real(kind=dp), dimension(0:maxfac), parameter, public ifac