18 #include "./base/base_uses.f90"
24 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_grid_atom'
28 REAL(KIND=
dp),
DIMENSION(3) :: rcenter
30 REAL(dp),
DIMENSION(:, :),
ALLOCATABLE :: rco
31 REAL(dp),
DIMENSION(:),
ALLOCATABLE :: weight
32 END TYPE grid_batch_type
34 TYPE atom_integration_grid_type
37 INTEGER :: lebedev_grid
38 REAL(dp),
DIMENSION(:),
ALLOCATABLE :: rr
39 REAL(dp),
DIMENSION(:),
ALLOCATABLE :: wr, wa
41 TYPE(grid_batch_type),
DIMENSION(:),
ALLOCATABLE :: batch
42 END TYPE atom_integration_grid_type
46 INTEGER :: nr, ng_sphere
47 REAL(dp),
DIMENSION(:),
POINTER :: rad, rad2, &
49 azi, cos_azi, sin_azi, &
50 pol, cos_pol, sin_pol, usin_azi
51 REAL(dp),
DIMENSION(:, :), &
52 POINTER :: rad2l, oorad2l, weight
53 END TYPE grid_atom_type
56 PUBLIC :: grid_atom_type
74 TYPE(grid_atom_type),
POINTER :: grid_atom
80 NULLIFY (grid_atom%rad)
81 NULLIFY (grid_atom%rad2)
82 NULLIFY (grid_atom%wr)
83 NULLIFY (grid_atom%wa)
84 NULLIFY (grid_atom%weight)
85 NULLIFY (grid_atom%azi)
86 NULLIFY (grid_atom%cos_azi)
87 NULLIFY (grid_atom%sin_azi)
88 NULLIFY (grid_atom%pol)
89 NULLIFY (grid_atom%cos_pol)
90 NULLIFY (grid_atom%sin_pol)
91 NULLIFY (grid_atom%usin_azi)
92 NULLIFY (grid_atom%rad2l)
93 NULLIFY (grid_atom%oorad2l)
105 TYPE(grid_atom_type),
POINTER :: grid_atom
107 IF (
ASSOCIATED(grid_atom))
THEN
109 IF (
ASSOCIATED(grid_atom%rad))
THEN
110 DEALLOCATE (grid_atom%rad)
113 IF (
ASSOCIATED(grid_atom%rad2))
THEN
114 DEALLOCATE (grid_atom%rad2)
117 IF (
ASSOCIATED(grid_atom%wr))
THEN
118 DEALLOCATE (grid_atom%wr)
121 IF (
ASSOCIATED(grid_atom%wa))
THEN
122 DEALLOCATE (grid_atom%wa)
125 IF (
ASSOCIATED(grid_atom%weight))
THEN
126 DEALLOCATE (grid_atom%weight)
129 IF (
ASSOCIATED(grid_atom%azi))
THEN
130 DEALLOCATE (grid_atom%azi)
133 IF (
ASSOCIATED(grid_atom%cos_azi))
THEN
134 DEALLOCATE (grid_atom%cos_azi)
137 IF (
ASSOCIATED(grid_atom%sin_azi))
THEN
138 DEALLOCATE (grid_atom%sin_azi)
141 IF (
ASSOCIATED(grid_atom%pol))
THEN
142 DEALLOCATE (grid_atom%pol)
145 IF (
ASSOCIATED(grid_atom%cos_pol))
THEN
146 DEALLOCATE (grid_atom%cos_pol)
149 IF (
ASSOCIATED(grid_atom%sin_pol))
THEN
150 DEALLOCATE (grid_atom%sin_pol)
153 IF (
ASSOCIATED(grid_atom%usin_azi))
THEN
154 DEALLOCATE (grid_atom%usin_azi)
157 IF (
ASSOCIATED(grid_atom%rad2l))
THEN
158 DEALLOCATE (grid_atom%rad2l)
161 IF (
ASSOCIATED(grid_atom%oorad2l))
THEN
162 DEALLOCATE (grid_atom%oorad2l)
165 DEALLOCATE (grid_atom)
167 CALL cp_abort(__location__, &
168 "The pointer grid_atom is not associated and "// &
169 "cannot be deallocated")
184 TYPE(grid_atom_type),
POINTER :: grid_atom
185 INTEGER,
INTENT(IN) :: nr, na, llmax, ll, quadrature
187 CHARACTER(len=*),
PARAMETER :: routinen =
'create_grid_atom'
189 INTEGER :: handle, ia, ir, l
190 REAL(
dp) :: cosia, pol
191 REAL(
dp),
DIMENSION(:),
POINTER :: rad, rad2, wr
193 CALL timeset(routinen, handle)
195 NULLIFY (rad, rad2, wr)
197 IF (
ASSOCIATED(grid_atom))
THEN
200 CALL reallocate(grid_atom%rad, 1, nr)
201 CALL reallocate(grid_atom%rad2, 1, nr)
202 CALL reallocate(grid_atom%wr, 1, nr)
203 CALL reallocate(grid_atom%wa, 1, na)
204 CALL reallocate(grid_atom%weight, 1, na, 1, nr)
205 CALL reallocate(grid_atom%azi, 1, na)
206 CALL reallocate(grid_atom%cos_azi, 1, na)
207 CALL reallocate(grid_atom%sin_azi, 1, na)
208 CALL reallocate(grid_atom%pol, 1, na)
209 CALL reallocate(grid_atom%cos_pol, 1, na)
210 CALL reallocate(grid_atom%sin_pol, 1, na)
211 CALL reallocate(grid_atom%usin_azi, 1, na)
212 CALL reallocate(grid_atom%rad2l, 1, nr, 0, llmax + 1)
213 CALL reallocate(grid_atom%oorad2l, 1, nr, 0, llmax + 1)
217 rad2 => grid_atom%rad2
220 grid_atom%quadrature = quadrature
221 CALL radial_grid(nr, rad, rad2, wr, quadrature)
223 grid_atom%rad2l(:, 0) = 1._dp
224 grid_atom%oorad2l(:, 0) = 1._dp
226 grid_atom%rad2l(:, l) = grid_atom%rad2l(:, l - 1)*rad(:)
227 grid_atom%oorad2l(:, l) = grid_atom%oorad2l(:, l - 1)/rad(:)
234 grid_atom%weight(ia, ir) = grid_atom%wr(ir)*grid_atom%wa(ia)
241 grid_atom%cos_pol(ia) = cosia
243 IF (abs(
lebedev_grid(ll)%r(2, ia)) < epsilon(1.0_dp) .AND. &
245 grid_atom%azi(ia) = 0.0_dp
249 grid_atom%cos_azi(ia) = cos(grid_atom%azi(ia))
251 grid_atom%pol(ia) = pol
252 grid_atom%sin_pol(ia) = sin(grid_atom%pol(ia))
254 grid_atom%sin_azi(ia) = sin(grid_atom%azi(ia))
255 IF (abs(grid_atom%sin_azi(ia)) > epsilon(1.0_dp))
THEN
256 grid_atom%usin_azi(ia) = 1.0_dp/grid_atom%sin_azi(ia)
258 grid_atom%usin_azi(ia) = 1.0_dp
266 cpabort(
"The pointer grid_atom is not associated")
269 CALL timestop(handle)
286 TYPE(atom_integration_grid_type),
POINTER :: int_grid
287 INTEGER,
INTENT(IN) :: nr, na
288 REAL(kind=
dp),
INTENT(IN) :: rmax
289 INTEGER,
INTENT(IN),
OPTIONAL :: quadrature, iunit
291 INTEGER :: ia, ig, ir, ix, iy, iz, la, ll, my_quad, &
292 n1, n2, n3, nbatch, ng, no, np, ntot, &
294 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: icell
295 REAL(kind=
dp) :: ag, dd, dmax, r1, r2, r3
296 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: rad, rad2, wa, wc, wr
297 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: rang, rco
298 REAL(kind=
dp),
DIMENSION(10) :: dco
299 REAL(kind=
dp),
DIMENSION(3) :: rm
300 TYPE(atom_integration_grid_type),
POINTER :: igr
305 IF (
PRESENT(quadrature))
THEN
313 ALLOCATE (rad(nr), rad2(nr), wr(nr))
314 CALL radial_grid(nr, rad, rad2, wr, my_quad)
317 ALLOCATE (igr%rr(nr))
318 ALLOCATE (igr%wr(nr))
320 IF (rad(1) > rad(nr))
THEN
322 igr%rr(nr - ir + 1) = rad(ir)
323 igr%wr(nr - ir + 1) = wr(ir)
326 igr%rr(1:nr) = rad(1:nr)
327 igr%wr(1:nr) = wr(1:nr)
332 IF (igr%rr(ir) < rmax)
THEN
345 ALLOCATE (rang(3, np), wa(np))
348 igr%lebedev_grid = ll
349 ALLOCATE (igr%wa(np))
351 igr%wa(1:np) = wa(1:np)
356 ALLOCATE (rco(3, ntot), wc(ntot))
361 rco(1:3, ig) = rang(1:3, ia)*rad(ir)
362 wc(ig) = wa(ia)*wr(ir)
366 ng = nint((real(ntot,
dp)/32._dp)**0.33333_dp)
367 ng = ng + mod(ng + 1, 2)
370 ag = real(igr%np,
dp)/ng
371 cpassert(
SIZE(dco) >= (ng + 1)/2)
373 ir = min(nint(ag)*ig, igr%np)
378 ALLOCATE (icell(ntot))
382 ix = grid_coord(rco(1, ig), dco, nx + 1) + nx
383 iy = grid_coord(rco(2, ig), dco, nx + 1) + nx
384 iz = grid_coord(rco(3, ig), dco, nx + 1) + nx
385 icell(ig) = iz*ng*ng + iy*ng + ix + 1
388 igr%nbatch = ng*ng*ng
389 ALLOCATE (igr%batch(igr%nbatch))
393 igr%batch(ia)%np = igr%batch(ia)%np + 1
395 DO ig = 1, igr%nbatch
396 np = igr%batch(ig)%np
397 ALLOCATE (igr%batch(ig)%rco(3, np), igr%batch(ig)%weight(np))
402 igr%batch(ia)%np = igr%batch(ia)%np + 1
403 np = igr%batch(ia)%np
404 igr%batch(ia)%rco(1:3, np) = rco(1:3, ig)
405 igr%batch(ia)%weight(np) = wc(ig)
408 DEALLOCATE (rad, rad2, rang, wr, wa)
409 DEALLOCATE (rco, wc, icell)
413 ALLOCATE (int_grid%rr(igr%nr), int_grid%wr(igr%nr), int_grid%wa(igr%na))
417 int_grid%ntot = igr%ntot
418 int_grid%lebedev_grid = igr%lebedev_grid
419 int_grid%rr(:) = igr%rr(:)
420 int_grid%wr(:) = igr%wr(:)
421 int_grid%wa(:) = igr%wa(:)
425 DO ig = 1, igr%nbatch
426 IF (igr%batch(ig)%np == 0)
THEN
428 ELSE IF (igr%batch(ig)%np <= 48)
THEN
433 nbatch = nbatch + nint(igr%batch(ig)%np/32._dp)
436 int_grid%nbatch = nbatch
437 ALLOCATE (int_grid%batch(nbatch))
440 DO ig = 1, igr%nbatch
441 IF (igr%batch(ig)%np == 0)
THEN
443 ELSE IF (igr%batch(ig)%np <= 48)
THEN
446 np = igr%batch(ig)%np
447 ALLOCATE (int_grid%batch(n1)%rco(3, np), int_grid%batch(n1)%weight(np))
448 int_grid%batch(n1)%np = np
449 int_grid%batch(n1)%rco(1:3, 1:np) = igr%batch(ig)%rco(1:3, 1:np)
450 int_grid%batch(n1)%weight(1:np) = igr%batch(ig)%weight(1:np)
453 n2 = nint(igr%batch(ig)%np/32._dp)
454 n3 = igr%batch(ig)%np/n2
455 DO ia = n1 + 1, n1 + n2
456 nu = (ia - n1 - 1)*n3 + 1
458 IF (ia == n1 + n2) no = igr%batch(ig)%np
460 ALLOCATE (int_grid%batch(ia)%rco(3, np), int_grid%batch(ia)%weight(np))
461 int_grid%batch(ia)%np = np
462 int_grid%batch(ia)%rco(1:3, 1:np) = igr%batch(ig)%rco(1:3, nu:no)
463 int_grid%batch(ia)%weight(1:np) = igr%batch(ig)%weight(nu:no)
468 cpassert(nbatch == n1)
470 DO ig = 1, int_grid%nbatch
471 np = int_grid%batch(ig)%np
473 rm(1) = sum(int_grid%batch(ig)%rco(1, 1:np))
474 rm(2) = sum(int_grid%batch(ig)%rco(2, 1:np))
475 rm(3) = sum(int_grid%batch(ig)%rco(3, 1:np))
476 rm(1:3) = rm(1:3)/real(np, kind=
dp)
480 int_grid%batch(ig)%rcenter(1:3) = rm(1:3)
483 dd = sum((int_grid%batch(ig)%rco(1:3, ia) - rm(1:3))**2)
486 int_grid%batch(ig)%rad = sqrt(dmax)
491 IF (
PRESENT(iunit))
THEN
493 WRITE (iunit,
"(/,A)")
" Atomic Integration Grid Information"
494 WRITE (iunit,
"(A,T51,3I10)")
" Number of grid points [radial,angular,total]", &
495 int_grid%np, int_grid%na, int_grid%ntot
496 WRITE (iunit,
"(A,T71,I10)")
" Lebedev grid number", int_grid%lebedev_grid
497 WRITE (iunit,
"(A,T61,F20.5)")
" Maximum of radial grid [Bohr]", &
498 int_grid%rr(int_grid%np)
499 nbatch = int_grid%nbatch
500 WRITE (iunit,
"(A,T71,I10)")
" Total number of gridpoint batches", nbatch
503 n3 = nint(real(int_grid%ntot,
dp)/real(nbatch,
dp))
505 n1 = min(n1, int_grid%batch(ig)%np)
506 n2 = max(n2, int_grid%batch(ig)%np)
508 WRITE (iunit,
"(A,T51,3I10)")
" Number of grid points/batch [min,max,ave]", n1, n2, n3
512 DO ig = 1, int_grid%nbatch
513 r1 = min(r1, int_grid%batch(ig)%rad)
514 r2 = max(r2, int_grid%batch(ig)%rad)
515 r3 = r3 + int_grid%batch(ig)%rad
517 r3 = r3/real(ng*ng*ng, kind=
dp)
518 WRITE (iunit,
"(A,T51,3F10.2)")
" Batch radius (bohr) [min,max,ave]", r1, r2, r3
532 FUNCTION grid_coord(x, dco, ng)
RESULT(igrid)
533 REAL(kind=
dp),
INTENT(IN) :: x
534 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: dco
535 INTEGER,
INTENT(IN) :: ng
539 REAL(kind=
dp) :: xval
544 IF (xval <= dco(ig))
THEN
549 IF (x < 0.0_dp) igrid = -igrid
550 cpassert(abs(igrid) < ng)
551 END FUNCTION grid_coord
558 TYPE(atom_integration_grid_type),
POINTER :: int_grid
562 IF (
ASSOCIATED(int_grid))
THEN
563 IF (
ALLOCATED(int_grid%rr))
DEALLOCATE (int_grid%rr)
564 IF (
ALLOCATED(int_grid%wr))
DEALLOCATE (int_grid%wr)
565 IF (
ALLOCATED(int_grid%wa))
DEALLOCATE (int_grid%wa)
567 IF (
ALLOCATED(int_grid%batch))
THEN
568 DO ib = 1,
SIZE(int_grid%batch)
569 IF (
ALLOCATED(int_grid%batch(ib)%rco))
DEALLOCATE (int_grid%batch(ib)%rco)
570 IF (
ALLOCATED(int_grid%batch(ib)%weight))
DEALLOCATE (int_grid%batch(ib)%weight)
572 DEALLOCATE (int_grid%batch)
575 DEALLOCATE (int_grid)
596 SUBROUTINE radial_grid(n, r, r2, wr, radial_quadrature)
598 INTEGER,
INTENT(IN) :: n
599 REAL(
dp),
DIMENSION(:),
INTENT(INOUT) :: r, r2, wr
600 INTEGER,
INTENT(IN) :: radial_quadrature
603 REAL(
dp) :: cost, f, sint, sint2, t, w, x
605 f =
pi/real(n + 1,
dp)
607 SELECT CASE (radial_quadrature)
618 r(i) = (1.0_dp + x)/(1.0_dp - x)
620 wr(i) = w/sqrt(1.0_dp - x**2)
621 wr(i) = 2.0_dp*wr(i)*r2(i)/(1.0_dp - x)**2
634 x = real(2*i - n - 1,
dp)/real(n + 1,
dp) - &
635 2.0_dp*(1.0_dp + 2.0_dp*sint2/3.0_dp)*cost*sint/
pi
636 w = 16.0_dp*sint2**2/real(3*(n + 1),
dp)
637 r(n + 1 - i) = (1.0_dp + x)/(1.0_dp - x)
638 r2(n + 1 - i) = r(n + 1 - i)**2
639 wr(n + 1 - i) = 2.0_dp*w*r2(n + 1 - i)/(1.0_dp - x)**2
652 x = real(2*i - n - 1,
dp)/real(n + 1,
dp) - &
653 2.0_dp*(1.0_dp + 2.0_dp*sint2/3.0_dp)*cost*sint/
pi
654 w = 16.0_dp*sint2**2/real(3*(n + 1),
dp)
655 r(n + 1 - i) = log(2.0_dp/(1.0_dp - x))/log(2.0_dp)
656 r2(n + 1 - i) = r(n + 1 - i)**2
657 wr(n + 1 - i) = w*r2(n + 1 - i)/(log(2.0_dp)*(1.0_dp - x))
662 cpabort(
"Invalid radial quadrature type specified")
666 END SUBROUTINE radial_grid
Defines the basic variable types.
integer, parameter, public dp
Generation of the spherical Lebedev grids. All Lebedev grids were generated with a precision of at le...
type(oh_grid), dimension(nlg), target, public lebedev_grid
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 of mathematical constants and functions.
real(kind=dp), parameter, public pi
Utility routines for the memory handling.
subroutine, public deallocate_atom_int_grid(int_grid)
...
subroutine, public deallocate_grid_atom(grid_atom)
Deallocate a Gaussian-type orbital (GTO) basis set data set.
subroutine, public allocate_grid_atom(grid_atom)
Initialize components of the grid_atom_type structure.
subroutine, public create_grid_atom(grid_atom, nr, na, llmax, ll, quadrature)
...
subroutine, public initialize_atomic_grid(int_grid, nr, na, rmax, quadrature, iunit)
Initialize atomic grid.