Line data Source code
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 Support routines for integrals of the Vxc/Fxc/Gxc potentials calculated
10 : !> for the atomic density in the basis set of spherical primitives
11 : ! **************************************************************************************************
12 : MODULE qs_vxc_atom_utils
13 : USE basis_set_types, ONLY: get_gto_basis_set,&
14 : gto_basis_set_type
15 : USE external_potential_types, ONLY: get_potential,&
16 : gth_potential_type,&
17 : sgp_potential_type
18 : USE kinds, ONLY: dp
19 : USE mathconstants, ONLY: fac
20 : USE orbital_pointers, ONLY: indso,&
21 : nsoset
22 : USE paw_basis_types, ONLY: get_paw_basis_info
23 : USE qs_grid_atom, ONLY: grid_atom_type
24 : USE qs_harmonics_atom, ONLY: get_none0_cg_list,&
25 : harmonics_atom_type
26 : USE qs_kind_types, ONLY: has_nlcc
27 : USE qs_rho_atom_types, ONLY: rho_atom_coeff,&
28 : rho_atom_type
29 : #include "./base/base_uses.f90"
30 :
31 : IMPLICIT NONE
32 :
33 : PRIVATE
34 :
35 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_vxc_atom_utils'
36 :
37 : TYPE tau_basis_cache_type
38 : INTEGER :: maxso = 0, na = 0, nr = 0, nsatbas = 0, &
39 : nset = 0
40 : INTEGER, DIMENSION(:), POINTER :: lmax => NULL(), lmin => NULL(), &
41 : n2oindex => NULL(), npgf => NULL(), &
42 : o2nindex => NULL()
43 : REAL(dp), DIMENSION(:, :), POINTER :: zet => NULL()
44 : REAL(dp), ALLOCATABLE, DIMENSION(:, :, :) :: grad
45 : END TYPE tau_basis_cache_type
46 :
47 : PUBLIC :: evaluate_nlcc_primitive_fields, gapw_atom_grid_support_radius, &
48 : create_tau_basis_cache, release_tau_basis_cache, &
49 : calc_rho_angular, calc_tau_atom, calc_rho_nlcc, &
50 : gaVxcgb_noGC, gaVxcgb_GC, dgaVtaudgb
51 : PUBLIC :: tau_basis_cache_type
52 : PUBLIC :: calc_weight_function
53 :
54 : ! **************************************************************************************************
55 :
56 : CONTAINS
57 :
58 : ! **************************************************************************************************
59 : !> \brief Evaluate an NLCC density and its first two Cartesian derivatives.
60 : !> \param point evaluation point
61 : !> \param center pseudopotential center
62 : !> \param gth_potential optional GTH potential
63 : !> \param sgp_potential optional separable Gaussian potential
64 : !> \param rho core density
65 : !> \param gradient Cartesian density gradient
66 : !> \param hessian Cartesian density Hessian
67 : ! **************************************************************************************************
68 112500 : SUBROUTINE evaluate_nlcc_primitive_fields(point, center, gth_potential, sgp_potential, &
69 : rho, gradient, hessian)
70 : REAL(dp), DIMENSION(3), INTENT(IN) :: point, center
71 : TYPE(gth_potential_type), INTENT(IN), POINTER :: gth_potential
72 : TYPE(sgp_potential_type), INTENT(IN), POINTER :: sgp_potential
73 : REAL(dp), INTENT(OUT) :: rho
74 : REAL(dp), DIMENSION(3), INTENT(OUT) :: gradient
75 : REAL(dp), DIMENSION(3, 3), INTENT(OUT) :: hessian
76 :
77 : INTEGER :: ic, idir, iexp, jdir, n_nlcc, nexp_nlcc, &
78 : power
79 112500 : INTEGER, DIMENSION(:), POINTER :: nct_nlcc
80 : LOGICAL :: has_sgp_nlcc, nlcc_present
81 : REAL(dp) :: alpha, beta, d2poly, dpoly, exponential, &
82 : poly, r2, rho_x, rho_xx, scaled_r2
83 : REAL(dp), DIMENSION(3) :: displacement
84 112500 : REAL(dp), DIMENSION(:), POINTER :: a_nlcc, alpha_nlcc, c_nlcc
85 112500 : REAL(dp), DIMENSION(:, :), POINTER :: cval_nlcc
86 :
87 112500 : NULLIFY (a_nlcc, alpha_nlcc, c_nlcc, cval_nlcc, nct_nlcc)
88 112500 : rho = 0.0_dp
89 112500 : rho_x = 0.0_dp
90 112500 : rho_xx = 0.0_dp
91 450000 : displacement = point - center
92 450000 : r2 = DOT_PRODUCT(displacement, displacement)
93 :
94 112500 : IF (ASSOCIATED(gth_potential)) THEN
95 : CALL get_potential(gth_potential, nlcc_present=nlcc_present, &
96 : nexp_nlcc=nexp_nlcc, alpha_nlcc=alpha_nlcc, &
97 112500 : nct_nlcc=nct_nlcc, cval_nlcc=cval_nlcc)
98 112500 : IF (nlcc_present) THEN
99 105000 : DO iexp = 1, nexp_nlcc
100 52500 : alpha = alpha_nlcc(iexp)
101 52500 : beta = 0.5_dp/(alpha*alpha)
102 52500 : scaled_r2 = r2/(alpha*alpha)
103 52500 : exponential = EXP(-0.5_dp*scaled_r2)
104 157500 : DO ic = 1, nct_nlcc(iexp)
105 52500 : power = ic - 1
106 52500 : poly = cval_nlcc(ic, iexp)*scaled_r2**power
107 52500 : dpoly = 0.0_dp
108 52500 : IF (power > 0) THEN
109 : dpoly = cval_nlcc(ic, iexp)*REAL(power, dp)* &
110 0 : scaled_r2**(power - 1)/(alpha*alpha)
111 : END IF
112 0 : d2poly = 0.0_dp
113 0 : IF (power > 1) THEN
114 : d2poly = cval_nlcc(ic, iexp)*REAL(power*(power - 1), dp)* &
115 0 : scaled_r2**(power - 2)/(alpha**4)
116 : END IF
117 52500 : rho = rho + exponential*poly
118 52500 : rho_x = rho_x + exponential*(dpoly - beta*poly)
119 105000 : rho_xx = rho_xx + exponential*(d2poly - 2.0_dp*beta*dpoly + beta*beta*poly)
120 : END DO
121 : END DO
122 : END IF
123 0 : ELSE IF (ASSOCIATED(sgp_potential)) THEN
124 : CALL get_potential(sgp_potential, has_nlcc=has_sgp_nlcc, n_nlcc=n_nlcc, &
125 0 : a_nlcc=a_nlcc, c_nlcc=c_nlcc)
126 0 : IF (has_sgp_nlcc) THEN
127 0 : DO iexp = 1, n_nlcc
128 0 : exponential = EXP(-a_nlcc(iexp)*r2)
129 0 : rho = rho + c_nlcc(iexp)*exponential
130 0 : rho_x = rho_x - a_nlcc(iexp)*c_nlcc(iexp)*exponential
131 0 : rho_xx = rho_xx + a_nlcc(iexp)**2*c_nlcc(iexp)*exponential
132 : END DO
133 : END IF
134 : END IF
135 :
136 450000 : gradient = 2.0_dp*rho_x*displacement
137 450000 : DO idir = 1, 3
138 1350000 : DO jdir = 1, 3
139 1350000 : hessian(idir, jdir) = 4.0_dp*rho_xx*displacement(idir)*displacement(jdir)
140 : END DO
141 450000 : hessian(idir, idir) = hessian(idir, idir) + 2.0_dp*rho_x
142 : END DO
143 112500 : END SUBROUTINE evaluate_nlcc_primitive_fields
144 :
145 : ! **************************************************************************************************
146 : !> \brief Compact support radius of one hard-minus-soft atom-grid field.
147 : !> \param grid_atom radial and angular source grid
148 : !> \param rho_h hard one-center density values
149 : !> \param rho_s soft one-center density values
150 : !> \param drho_h hard one-center density-gradient values
151 : !> \param drho_s soft one-center density-gradient values
152 : !> \param tau_h hard one-center kinetic-energy-density values
153 : !> \param tau_s soft one-center kinetic-energy-density values
154 : !> \return outermost radius required by any primitive hard-minus-soft field
155 : ! **************************************************************************************************
156 574 : FUNCTION gapw_atom_grid_support_radius( &
157 574 : grid_atom, rho_h, rho_s, drho_h, drho_s, tau_h, tau_s) RESULT(cutoff)
158 : TYPE(grid_atom_type), POINTER :: grid_atom
159 : REAL(dp), DIMENSION(:, :, :), INTENT(IN) :: rho_h, rho_s
160 : REAL(dp), DIMENSION(:, :, :, :), INTENT(IN) :: drho_h, drho_s
161 : REAL(dp), DIMENSION(:, :, :), INTENT(IN) :: tau_h, tau_s
162 : REAL(dp) :: cutoff
163 :
164 : INTEGER :: ir, support_ir
165 : LOGICAL :: descending
166 : REAL(dp) :: amplitude
167 :
168 574 : cutoff = 0.0_dp
169 574 : descending = grid_atom%rad(1) > grid_atom%rad(grid_atom%nr)
170 574 : IF (descending) THEN
171 8232 : DO ir = 1, grid_atom%nr
172 : amplitude = MAX( &
173 : MAXVAL(ABS(rho_h(:, ir, :) - rho_s(:, ir, :))), &
174 : MAXVAL(ABS(drho_h(1:3, :, ir, :) - drho_s(1:3, :, ir, :))), &
175 1562832 : MAXVAL(ABS(tau_h(:, ir, :) - tau_s(:, ir, :))))
176 8232 : IF (amplitude > 1.0E-12_dp) THEN
177 514 : support_ir = MAX(1, ir - 2)
178 514 : cutoff = grid_atom%rad(support_ir)
179 514 : RETURN
180 : END IF
181 : END DO
182 : ELSE
183 0 : DO ir = grid_atom%nr, 1, -1
184 : amplitude = MAX( &
185 : MAXVAL(ABS(rho_h(:, ir, :) - rho_s(:, ir, :))), &
186 : MAXVAL(ABS(drho_h(1:3, :, ir, :) - drho_s(1:3, :, ir, :))), &
187 0 : MAXVAL(ABS(tau_h(:, ir, :) - tau_s(:, ir, :))))
188 0 : IF (amplitude > 1.0E-12_dp) THEN
189 0 : support_ir = MIN(grid_atom%nr, ir + 2)
190 0 : cutoff = grid_atom%rad(support_ir)
191 0 : RETURN
192 : END IF
193 : END DO
194 : END IF
195 :
196 : END FUNCTION gapw_atom_grid_support_radius
197 :
198 : ! **************************************************************************************************
199 : !> \brief ...
200 : !> \param grid_atom ...
201 : !> \param harmonics ...
202 : !> \param nspins ...
203 : !> \param grad_func ...
204 : !> \param ir ...
205 : !> \param r_h ...
206 : !> \param r_s ...
207 : !> \param rho_h ...
208 : !> \param rho_s ...
209 : !> \param dr_h ...
210 : !> \param dr_s ...
211 : !> \param r_h_d ...
212 : !> \param r_s_d ...
213 : !> \param drho_h ...
214 : !> \param drho_s ...
215 : ! **************************************************************************************************
216 3200620 : SUBROUTINE calc_rho_angular(grid_atom, harmonics, nspins, grad_func, &
217 : ir, r_h, r_s, rho_h, rho_s, &
218 : dr_h, dr_s, r_h_d, r_s_d, drho_h, drho_s)
219 :
220 : TYPE(grid_atom_type), POINTER :: grid_atom
221 : TYPE(harmonics_atom_type), POINTER :: harmonics
222 : INTEGER, INTENT(IN) :: nspins
223 : LOGICAL, INTENT(IN) :: grad_func
224 : INTEGER, INTENT(IN) :: ir
225 : TYPE(rho_atom_coeff), DIMENSION(:), POINTER :: r_h, r_s
226 : REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: rho_h, rho_s
227 : TYPE(rho_atom_coeff), DIMENSION(:), POINTER :: dr_h, dr_s
228 : TYPE(rho_atom_coeff), DIMENSION(:, :), POINTER :: r_h_d, r_s_d
229 : REAL(KIND=dp), DIMENSION(:, :, :, :), POINTER :: drho_h, drho_s
230 :
231 : INTEGER :: ia, iso, ispin, na
232 : REAL(KIND=dp) :: rad, urad
233 :
234 3200620 : CPASSERT(ASSOCIATED(r_h))
235 3200620 : CPASSERT(ASSOCIATED(r_s))
236 3200620 : CPASSERT(ASSOCIATED(rho_h))
237 3200620 : CPASSERT(ASSOCIATED(rho_s))
238 3200620 : IF (grad_func) THEN
239 2075720 : CPASSERT(ASSOCIATED(dr_h))
240 2075720 : CPASSERT(ASSOCIATED(dr_s))
241 2075720 : CPASSERT(ASSOCIATED(r_h_d))
242 2075720 : CPASSERT(ASSOCIATED(r_s_d))
243 2075720 : CPASSERT(ASSOCIATED(drho_h))
244 2075720 : CPASSERT(ASSOCIATED(drho_s))
245 : END IF
246 :
247 3200620 : na = grid_atom%ng_sphere
248 3200620 : rad = grid_atom%rad(ir)
249 3200620 : urad = grid_atom%oorad2l(ir, 1)
250 6828500 : DO ispin = 1, nspins
251 55719500 : DO iso = 1, harmonics%max_iso_not0
252 2652309760 : DO ia = 1, na
253 : rho_h(ia, ir, ispin) = rho_h(ia, ir, ispin) + &
254 2599790880 : r_h(ispin)%r_coef(ir, iso)*harmonics%slm(ia, iso)
255 : rho_s(ia, ir, ispin) = rho_s(ia, ir, ispin) + &
256 2648681880 : r_s(ispin)%r_coef(ir, iso)*harmonics%slm(ia, iso)
257 : END DO ! ia
258 : END DO ! iso
259 : END DO ! ispin
260 :
261 3200620 : IF (grad_func) THEN
262 4417050 : DO ispin = 1, nspins
263 34985780 : DO iso = 1, harmonics%max_iso_not0
264 1817049160 : DO ia = 1, na
265 :
266 : ! components of the gradient of rho1 hard
267 : drho_h(1, ia, ir, ispin) = drho_h(1, ia, ir, ispin) + &
268 : dr_h(ispin)%r_coef(ir, iso)* &
269 : harmonics%a(1, ia)*harmonics%slm(ia, iso) + &
270 : r_h_d(1, ispin)%r_coef(ir, iso)* &
271 1782063380 : harmonics%slm(ia, iso)
272 :
273 : drho_h(2, ia, ir, ispin) = drho_h(2, ia, ir, ispin) + &
274 : dr_h(ispin)%r_coef(ir, iso)* &
275 : harmonics%a(2, ia)*harmonics%slm(ia, iso) + &
276 : r_h_d(2, ispin)%r_coef(ir, iso)* &
277 1782063380 : harmonics%slm(ia, iso)
278 :
279 : drho_h(3, ia, ir, ispin) = drho_h(3, ia, ir, ispin) + &
280 : dr_h(ispin)%r_coef(ir, iso)* &
281 : harmonics%a(3, ia)*harmonics%slm(ia, iso) + &
282 : r_h_d(3, ispin)%r_coef(ir, iso)* &
283 1782063380 : harmonics%slm(ia, iso)
284 :
285 : ! components of the gradient of rho1 soft
286 : drho_s(1, ia, ir, ispin) = drho_s(1, ia, ir, ispin) + &
287 : dr_s(ispin)%r_coef(ir, iso)* &
288 : harmonics%a(1, ia)*harmonics%slm(ia, iso) + &
289 : r_s_d(1, ispin)%r_coef(ir, iso)* &
290 1782063380 : harmonics%slm(ia, iso)
291 :
292 : drho_s(2, ia, ir, ispin) = drho_s(2, ia, ir, ispin) + &
293 : dr_s(ispin)%r_coef(ir, iso)* &
294 : harmonics%a(2, ia)*harmonics%slm(ia, iso) + &
295 : r_s_d(2, ispin)%r_coef(ir, iso)* &
296 1782063380 : harmonics%slm(ia, iso)
297 :
298 : drho_s(3, ia, ir, ispin) = drho_s(3, ia, ir, ispin) + &
299 : dr_s(ispin)%r_coef(ir, iso)* &
300 : harmonics%a(3, ia)*harmonics%slm(ia, iso) + &
301 : r_s_d(3, ispin)%r_coef(ir, iso)* &
302 1814707830 : harmonics%slm(ia, iso)
303 :
304 : END DO ! ia
305 : END DO ! iso
306 127527950 : DO ia = 1, na
307 : drho_h(4, ia, ir, ispin) = SQRT( &
308 : drho_h(1, ia, ir, ispin)*drho_h(1, ia, ir, ispin) + &
309 : drho_h(2, ia, ir, ispin)*drho_h(2, ia, ir, ispin) + &
310 123110900 : drho_h(3, ia, ir, ispin)*drho_h(3, ia, ir, ispin))
311 :
312 : drho_s(4, ia, ir, ispin) = SQRT( &
313 : drho_s(1, ia, ir, ispin)*drho_s(1, ia, ir, ispin) + &
314 : drho_s(2, ia, ir, ispin)*drho_s(2, ia, ir, ispin) + &
315 125452230 : drho_s(3, ia, ir, ispin)*drho_s(3, ia, ir, ispin))
316 : END DO ! ia
317 : END DO ! ispin
318 : END IF
319 :
320 3200620 : END SUBROUTINE calc_rho_angular
321 :
322 : ! **************************************************************************************************
323 : !> \brief Precompute radial and angular factors for GAPW meta-GGA tau contractions
324 : !> \param tau_cache precomputed compact one-center gradient basis
325 : !> \param grid_atom atom-centered integration grid
326 : !> \param basis_1c GAPW one-center basis
327 : !> \param harmonics spherical harmonics on the atom-centered grid
328 : ! **************************************************************************************************
329 1942 : SUBROUTINE create_tau_basis_cache(tau_cache, grid_atom, basis_1c, harmonics)
330 :
331 : TYPE(tau_basis_cache_type), INTENT(INOUT) :: tau_cache
332 : TYPE(grid_atom_type), POINTER :: grid_atom
333 : TYPE(gto_basis_set_type), POINTER :: basis_1c
334 : TYPE(harmonics_atom_type), POINTER :: harmonics
335 :
336 : INTEGER :: dir, ia, igrid, ip, ipgf, ir, iset, iso, &
337 : l, starti
338 1942 : REAL(dp), ALLOCATABLE, DIMENSION(:) :: a1, a2, gexp, r1, r2
339 1942 : REAL(dp), DIMENSION(:, :), POINTER :: slm
340 1942 : REAL(dp), DIMENSION(:, :, :), POINTER :: dslm_dxyz
341 :
342 1942 : NULLIFY (slm, dslm_dxyz)
343 :
344 1942 : CALL release_tau_basis_cache(tau_cache)
345 :
346 : CALL get_gto_basis_set(gto_basis_set=basis_1c, lmax=tau_cache%lmax, &
347 : lmin=tau_cache%lmin, maxso=tau_cache%maxso, &
348 : npgf=tau_cache%npgf, nset=tau_cache%nset, &
349 1942 : zet=tau_cache%zet)
350 : CALL get_paw_basis_info(basis_1c, o2nindex=tau_cache%o2nindex, &
351 : n2oindex=tau_cache%n2oindex, &
352 1942 : nsatbas=tau_cache%nsatbas)
353 :
354 1942 : tau_cache%nr = grid_atom%nr
355 1942 : tau_cache%na = grid_atom%ng_sphere
356 1942 : slm => harmonics%slm
357 1942 : dslm_dxyz => harmonics%dslm_dxyz
358 :
359 9710 : ALLOCATE (tau_cache%grad(tau_cache%na*tau_cache%nr, tau_cache%nsatbas, 3))
360 : ALLOCATE (a1(tau_cache%na), a2(tau_cache%na), gexp(tau_cache%nr), &
361 15536 : r1(tau_cache%nr), r2(tau_cache%nr))
362 380979880 : tau_cache%grad = 0.0_dp
363 :
364 7098 : DO iset = 1, tau_cache%nset
365 24586 : DO ipgf = 1, tau_cache%npgf(iset)
366 : starti = (iset - 1)*tau_cache%maxso + &
367 17488 : (ipgf - 1)*nsoset(tau_cache%lmax(iset))
368 : gexp(1:tau_cache%nr) = EXP(-tau_cache%zet(ipgf, iset)* &
369 868528 : grid_atom%rad2(1:tau_cache%nr))
370 68868 : DO iso = nsoset(tau_cache%lmin(iset) - 1) + 1, nsoset(tau_cache%lmax(iset))
371 46224 : ip = tau_cache%o2nindex(starti + iso)
372 46224 : IF (ip == 0) CYCLE
373 46224 : l = indso(1, iso)
374 :
375 2340544 : r1(1:tau_cache%nr) = grid_atom%rad(1:tau_cache%nr)**(l - 1)*gexp(1:tau_cache%nr)
376 : r2(1:tau_cache%nr) = -2.0_dp*tau_cache%zet(ipgf, iset)* &
377 2340544 : grid_atom%rad2(1:tau_cache%nr)*r1(1:tau_cache%nr)
378 :
379 202384 : DO dir = 1, 3
380 7425648 : a1(1:tau_cache%na) = dslm_dxyz(dir, 1:tau_cache%na, iso)
381 7425648 : a2(1:tau_cache%na) = harmonics%a(dir, 1:tau_cache%na)*slm(1:tau_cache%na, iso)
382 7067856 : DO ir = 1, tau_cache%nr
383 387855072 : DO ia = 1, tau_cache%na
384 380833440 : igrid = ia + (ir - 1)*tau_cache%na
385 387716400 : tau_cache%grad(igrid, ip, dir) = r1(ir)*a1(ia) + r2(ir)*a2(ia)
386 : END DO
387 : END DO
388 : END DO
389 : END DO
390 : END DO
391 : END DO
392 :
393 1942 : DEALLOCATE (a1, a2, gexp, r1, r2)
394 :
395 1942 : END SUBROUTINE create_tau_basis_cache
396 :
397 : ! **************************************************************************************************
398 : !> \brief Release precomputed GAPW meta-GGA tau factors
399 : !> \param tau_cache precomputed compact one-center gradient basis
400 : ! **************************************************************************************************
401 3884 : SUBROUTINE release_tau_basis_cache(tau_cache)
402 :
403 : TYPE(tau_basis_cache_type), INTENT(INOUT) :: tau_cache
404 :
405 3884 : IF (ALLOCATED(tau_cache%grad)) DEALLOCATE (tau_cache%grad)
406 3884 : IF (ASSOCIATED(tau_cache%n2oindex)) DEALLOCATE (tau_cache%n2oindex)
407 3884 : IF (ASSOCIATED(tau_cache%o2nindex)) DEALLOCATE (tau_cache%o2nindex)
408 3884 : NULLIFY (tau_cache%lmax, tau_cache%lmin, tau_cache%n2oindex, tau_cache%npgf, &
409 3884 : tau_cache%zet, tau_cache%o2nindex)
410 3884 : tau_cache%maxso = 0
411 3884 : tau_cache%na = 0
412 3884 : tau_cache%nr = 0
413 3884 : tau_cache%nsatbas = 0
414 3884 : tau_cache%nset = 0
415 :
416 3884 : END SUBROUTINE release_tau_basis_cache
417 :
418 : ! **************************************************************************************************
419 : !> \brief Computes tau hard and soft on the atomic grids for meta-GGA calculations
420 : !> \param tau_h the hard part of tau
421 : !> \param tau_s the soft part of tau
422 : !> \param rho_atom atom-centered density matrices
423 : !> \param tau_cache precomputed compact one-center gradient basis
424 : !> \param nspins number of spin channels
425 : !> \note This is a rewrite to correct a meta-GGA GAPW bug. This is more brute force than the original,
426 : !> which was done along in qs_rho_atom_methods.F, but makes sure that no corner is cut in
427 : !> terms of accuracy (A. Bussy)
428 : ! **************************************************************************************************
429 1761 : SUBROUTINE calc_tau_atom(tau_h, tau_s, rho_atom, tau_cache, nspins)
430 :
431 : REAL(dp), DIMENSION(:, :, :), INTENT(INOUT) :: tau_h, tau_s
432 : TYPE(rho_atom_type), POINTER :: rho_atom
433 : TYPE(tau_basis_cache_type), INTENT(IN) :: tau_cache
434 : INTEGER, INTENT(IN) :: nspins
435 :
436 : CHARACTER(len=*), PARAMETER :: routineN = 'calc_tau_atom'
437 :
438 : INTEGER :: dir, handle, ia, ibas, igrid, ir, ispin, &
439 : na, nbas, ngrid, nr
440 : REAL(dp) :: tau_sum
441 1761 : REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: work
442 :
443 1761 : CALL timeset(routineN, handle)
444 :
445 1761 : CPASSERT(ALLOCATED(tau_cache%grad))
446 :
447 : !zeroing tau, assuming it is already allocated
448 4877900 : tau_h = 0.0_dp
449 4877900 : tau_s = 0.0_dp
450 :
451 1761 : nr = tau_cache%nr
452 1761 : na = tau_cache%na
453 1761 : nbas = tau_cache%nsatbas
454 1761 : ngrid = na*nr
455 7044 : ALLOCATE (work(ngrid, nbas))
456 :
457 3650 : DO ispin = 1, nspins
458 9317 : DO dir = 1, 3
459 : CALL dgemm('N', 'T', ngrid, nbas, nbas, 0.5_dp, tau_cache%grad(:, :, dir), &
460 5667 : ngrid, rho_atom%cpc_h(ispin)%r_coef, nbas, 0.0_dp, work, ngrid)
461 : !$OMP PARALLEL DO DEFAULT(NONE) COLLAPSE(2) SCHEDULE(STATIC) &
462 : !$OMP SHARED(dir, ispin, na, nbas, nr, tau_cache, tau_h, work) &
463 5667 : !$OMP PRIVATE(ia, ibas, igrid, ir, tau_sum)
464 : DO ir = 1, nr
465 : DO ia = 1, na
466 : igrid = ia + (ir - 1)*na
467 : tau_sum = 0.0_dp
468 : DO ibas = 1, nbas
469 : tau_sum = tau_sum + tau_cache%grad(igrid, ibas, dir)*work(igrid, ibas)
470 : END DO
471 : tau_h(ia, ir, ispin) = tau_h(ia, ir, ispin) + tau_sum
472 : END DO
473 : END DO
474 : !$OMP END PARALLEL DO
475 :
476 : CALL dgemm('N', 'T', ngrid, nbas, nbas, 0.5_dp, tau_cache%grad(:, :, dir), &
477 5667 : ngrid, rho_atom%cpc_s(ispin)%r_coef, nbas, 0.0_dp, work, ngrid)
478 : !$OMP PARALLEL DO DEFAULT(NONE) COLLAPSE(2) SCHEDULE(STATIC) &
479 : !$OMP SHARED(dir, ispin, na, nbas, nr, tau_cache, tau_s, work) &
480 7556 : !$OMP PRIVATE(ia, ibas, igrid, ir, tau_sum)
481 : DO ir = 1, nr
482 : DO ia = 1, na
483 : igrid = ia + (ir - 1)*na
484 : tau_sum = 0.0_dp
485 : DO ibas = 1, nbas
486 : tau_sum = tau_sum + tau_cache%grad(igrid, ibas, dir)*work(igrid, ibas)
487 : END DO
488 : tau_s(ia, ir, ispin) = tau_s(ia, ir, ispin) + tau_sum
489 : END DO
490 : END DO
491 : !$OMP END PARALLEL DO
492 : END DO
493 : END DO
494 :
495 1761 : DEALLOCATE (work)
496 :
497 1761 : CALL timestop(handle)
498 :
499 3522 : END SUBROUTINE calc_tau_atom
500 :
501 : ! **************************************************************************************************
502 : !> \brief ...
503 : !> \param grid_atom ...
504 : !> \param nspins ...
505 : !> \param grad_func ...
506 : !> \param ir ...
507 : !> \param rho_nlcc ...
508 : !> \param rho_h ...
509 : !> \param rho_s ...
510 : !> \param drho_nlcc ...
511 : !> \param drho_h ...
512 : !> \param drho_s ...
513 : ! **************************************************************************************************
514 35650 : SUBROUTINE calc_rho_nlcc(grid_atom, nspins, grad_func, &
515 35650 : ir, rho_nlcc, rho_h, rho_s, drho_nlcc, drho_h, drho_s)
516 :
517 : TYPE(grid_atom_type), POINTER :: grid_atom
518 : INTEGER, INTENT(IN) :: nspins
519 : LOGICAL, INTENT(IN) :: grad_func
520 : INTEGER, INTENT(IN) :: ir
521 : REAL(KIND=dp), DIMENSION(:) :: rho_nlcc
522 : REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: rho_h, rho_s
523 : REAL(KIND=dp), DIMENSION(:) :: drho_nlcc
524 : REAL(KIND=dp), DIMENSION(:, :, :, :), POINTER :: drho_h, drho_s
525 :
526 : INTEGER :: ia, ispin, na
527 : REAL(KIND=dp) :: drho, dx, dy, dz, rad, rho, urad, xsp
528 :
529 35650 : CPASSERT(ASSOCIATED(rho_h))
530 35650 : CPASSERT(ASSOCIATED(rho_s))
531 35650 : IF (grad_func) THEN
532 26350 : CPASSERT(ASSOCIATED(drho_h))
533 26350 : CPASSERT(ASSOCIATED(drho_s))
534 : END IF
535 :
536 35650 : na = grid_atom%ng_sphere
537 35650 : rad = grid_atom%rad(ir)
538 35650 : urad = grid_atom%oorad2l(ir, 1)
539 :
540 35650 : xsp = REAL(nspins, KIND=dp)
541 35650 : rho = rho_nlcc(ir)/xsp
542 71300 : DO ispin = 1, nspins
543 2082150 : rho_h(1:na, ir, ispin) = rho_h(1:na, ir, ispin) + rho
544 2117800 : rho_s(1:na, ir, ispin) = rho_s(1:na, ir, ispin) + rho
545 : END DO ! ispin
546 :
547 35650 : IF (grad_func) THEN
548 26350 : drho = drho_nlcc(ir)/xsp
549 52700 : DO ispin = 1, nspins
550 1634200 : DO ia = 1, na
551 1581500 : IF (grid_atom%azi(ia) == 0.0_dp) THEN
552 : dx = 0.0_dp
553 : dy = 0.0_dp
554 : ELSE
555 1440950 : dx = grid_atom%sin_pol(ia)*grid_atom%sin_azi(ia)
556 1440950 : dy = grid_atom%sin_pol(ia)*grid_atom%cos_azi(ia)
557 : END IF
558 1581500 : dz = grid_atom%cos_pol(ia)
559 : ! components of the gradient of rho1 hard
560 1581500 : drho_h(1, ia, ir, ispin) = drho_h(1, ia, ir, ispin) + drho*dx
561 1581500 : drho_h(2, ia, ir, ispin) = drho_h(2, ia, ir, ispin) + drho*dy
562 1581500 : drho_h(3, ia, ir, ispin) = drho_h(3, ia, ir, ispin) + drho*dz
563 : ! components of the gradient of rho1 soft
564 1581500 : drho_s(1, ia, ir, ispin) = drho_s(1, ia, ir, ispin) + drho*dx
565 1581500 : drho_s(2, ia, ir, ispin) = drho_s(2, ia, ir, ispin) + drho*dy
566 1581500 : drho_s(3, ia, ir, ispin) = drho_s(3, ia, ir, ispin) + drho*dz
567 : ! norm of gradient
568 : drho_h(4, ia, ir, ispin) = SQRT( &
569 : drho_h(1, ia, ir, ispin)*drho_h(1, ia, ir, ispin) + &
570 : drho_h(2, ia, ir, ispin)*drho_h(2, ia, ir, ispin) + &
571 1581500 : drho_h(3, ia, ir, ispin)*drho_h(3, ia, ir, ispin))
572 :
573 : drho_s(4, ia, ir, ispin) = SQRT( &
574 : drho_s(1, ia, ir, ispin)*drho_s(1, ia, ir, ispin) + &
575 : drho_s(2, ia, ir, ispin)*drho_s(2, ia, ir, ispin) + &
576 1607850 : drho_s(3, ia, ir, ispin)*drho_s(3, ia, ir, ispin))
577 : END DO ! ia
578 : END DO ! ispin
579 : END IF
580 :
581 35650 : END SUBROUTINE calc_rho_nlcc
582 :
583 : ! **************************************************************************************************
584 : !> \brief ...
585 : !> \param vxc_h ...
586 : !> \param vxc_s ...
587 : !> \param int_hh ...
588 : !> \param int_ss ...
589 : !> \param grid_atom ...
590 : !> \param basis_1c ...
591 : !> \param harmonics ...
592 : !> \param nspins ...
593 : ! **************************************************************************************************
594 16996 : SUBROUTINE gaVxcgb_noGC(vxc_h, vxc_s, int_hh, int_ss, grid_atom, basis_1c, harmonics, nspins)
595 :
596 : REAL(dp), DIMENSION(:, :, :), POINTER :: vxc_h, vxc_s
597 : TYPE(rho_atom_coeff), DIMENSION(:), POINTER :: int_hh, int_ss
598 : TYPE(grid_atom_type), POINTER :: grid_atom
599 : TYPE(gto_basis_set_type), POINTER :: basis_1c
600 : TYPE(harmonics_atom_type), POINTER :: harmonics
601 : INTEGER, INTENT(IN) :: nspins
602 :
603 : CHARACTER(len=*), PARAMETER :: routineN = 'gaVxcgb_noGC'
604 :
605 : INTEGER :: handle, ia, ic, icg, ipgf1, ipgf2, ir, iset1, iset2, iso, iso1, iso2, ispin, l, &
606 : ld, lmax12, lmax_expansion, lmin12, m1, m2, max_iso_not0, max_iso_not0_local, max_s_harm, &
607 : maxl, maxso, n1, n2, na, ngau1, ngau2, nngau1, nr, nset, size1
608 : INTEGER, ALLOCATABLE, DIMENSION(:) :: cg_n_list
609 : INTEGER, ALLOCATABLE, DIMENSION(:, :, :) :: cg_list
610 16996 : INTEGER, DIMENSION(:), POINTER :: lmax, lmin, npgf
611 16996 : REAL(dp), ALLOCATABLE, DIMENSION(:) :: g1, g2
612 16996 : REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: gg, gVg_h, gVg_s, matso_h, matso_s, vx
613 16996 : REAL(dp), DIMENSION(:, :), POINTER :: zet
614 : REAL(dp), DIMENSION(:, :, :), POINTER :: my_CG
615 :
616 16996 : CALL timeset(routineN, handle)
617 :
618 16996 : NULLIFY (lmin, lmax, npgf, zet, my_CG)
619 :
620 : CALL get_gto_basis_set(gto_basis_set=basis_1c, lmax=lmax, lmin=lmin, &
621 : maxso=maxso, maxl=maxl, npgf=npgf, &
622 16996 : nset=nset, zet=zet)
623 :
624 16996 : nr = grid_atom%nr
625 16996 : na = grid_atom%ng_sphere
626 16996 : my_CG => harmonics%my_CG
627 16996 : max_iso_not0 = harmonics%max_iso_not0
628 16996 : lmax_expansion = indso(1, max_iso_not0)
629 16996 : max_s_harm = harmonics%max_s_harm
630 :
631 118972 : ALLOCATE (g1(nr), g2(nr), gg(nr, 0:2*maxl))
632 101976 : ALLOCATE (gVg_h(na, 0:2*maxl), gVg_s(na, 0:2*maxl))
633 : ALLOCATE (matso_h(nsoset(maxl), nsoset(maxl)), &
634 101976 : matso_s(nsoset(maxl), nsoset(maxl)))
635 67984 : ALLOCATE (vx(na, nr))
636 101976 : ALLOCATE (cg_list(2, nsoset(maxl)**2, max_s_harm), cg_n_list(max_s_harm))
637 :
638 16996 : g1 = 0.0_dp
639 16996 : g2 = 0.0_dp
640 16996 : m1 = 0
641 57641 : DO iset1 = 1, nset
642 40645 : n1 = nsoset(lmax(iset1))
643 40645 : m2 = 0
644 167324 : DO iset2 = 1, nset
645 : CALL get_none0_cg_list(my_CG, lmin(iset1), lmax(iset1), lmin(iset2), lmax(iset2), &
646 126679 : max_s_harm, lmax_expansion, cg_list, cg_n_list, max_iso_not0_local)
647 126679 : CPASSERT(max_iso_not0_local <= max_iso_not0)
648 :
649 126679 : n2 = nsoset(lmax(iset2))
650 468738 : DO ipgf1 = 1, npgf(iset1)
651 342059 : ngau1 = n1*(ipgf1 - 1) + m1
652 342059 : size1 = nsoset(lmax(iset1)) - nsoset(lmin(iset1) - 1)
653 342059 : nngau1 = nsoset(lmin(iset1) - 1) + ngau1
654 :
655 19562289 : g1(1:nr) = EXP(-zet(ipgf1, iset1)*grid_atom%rad2(1:nr))
656 1603342 : DO ipgf2 = 1, npgf(iset2)
657 1134604 : ngau2 = n2*(ipgf2 - 1) + m2
658 :
659 64328444 : g2(1:nr) = EXP(-zet(ipgf2, iset2)*grid_atom%rad2(1:nr))
660 1134604 : lmin12 = lmin(iset1) + lmin(iset2)
661 1134604 : lmax12 = lmax(iset1) + lmax(iset2)
662 :
663 : ! reduce expansion local densities
664 1476663 : IF (lmin12 <= lmax_expansion) THEN
665 :
666 1133659 : gg = 0.0_dp
667 1133659 : IF (lmin12 == 0) THEN
668 35341980 : gg(1:nr, lmin12) = g1(1:nr)*g2(1:nr)
669 : ELSE
670 28938269 : gg(1:nr, lmin12) = grid_atom%rad2l(1:nr, lmin12)*g1(1:nr)*g2(1:nr)
671 : END IF
672 :
673 : ! limit the expansion of the local densities to a max L
674 1133659 : IF (lmax12 > lmax_expansion) lmax12 = lmax_expansion
675 :
676 1645847 : DO l = lmin12 + 1, lmax12
677 31759887 : gg(1:nr, l) = grid_atom%rad(1:nr)*gg(:, l - 1)
678 : END DO
679 :
680 2454549 : DO ispin = 1, nspins
681 1320890 : ld = lmax12 + 1
682 78863110 : DO ir = 1, nr
683 3970483550 : vx(1:na, ir) = vxc_h(1:na, ir, ispin)
684 : END DO
685 : CALL dgemm('N', 'N', na, ld, nr, 1.0_dp, vx(1:na, 1:nr), na, &
686 1320890 : gg(1:nr, 0:lmax12), nr, 0.0_dp, gVg_h(1:na, 0:lmax12), na)
687 78863110 : DO ir = 1, nr
688 3970483550 : vx(1:na, ir) = vxc_s(1:na, ir, ispin)
689 : END DO
690 : CALL dgemm('N', 'N', na, ld, nr, 1.0_dp, vx(1:na, 1:nr), na, &
691 1320890 : gg(1:nr, 0:lmax12), nr, 0.0_dp, gVg_s(1:na, 0:lmax12), na)
692 :
693 1320890 : matso_h = 0.0_dp
694 1320890 : matso_s = 0.0_dp
695 10449208 : DO iso = 1, max_iso_not0_local
696 28625830 : DO icg = 1, cg_n_list(iso)
697 18176622 : iso1 = cg_list(1, icg, iso)
698 18176622 : iso2 = cg_list(2, icg, iso)
699 18176622 : l = indso(1, iso1) + indso(1, iso2)
700 :
701 18176622 : CPASSERT(l <= lmax_expansion)
702 937959872 : DO ia = 1, na
703 : matso_h(iso1, iso2) = matso_h(iso1, iso2) + &
704 : gVg_h(ia, l)* &
705 : my_CG(iso1, iso2, iso)* &
706 910654932 : harmonics%slm(ia, iso)
707 : matso_s(iso1, iso2) = matso_s(iso1, iso2) + &
708 : gVg_s(ia, l)* &
709 : my_CG(iso1, iso2, iso)* &
710 928831554 : harmonics%slm(ia, iso)
711 : END DO
712 : END DO
713 : END DO
714 :
715 : ! Write in the global matrix
716 5919137 : DO ic = nsoset(lmin(iset2) - 1) + 1, nsoset(lmax(iset2))
717 3464588 : iso1 = nsoset(lmin(iset1) - 1) + 1
718 3464588 : iso2 = ngau2 + ic
719 : CALL daxpy(size1, 1.0_dp, matso_h(iso1, ic), 1, &
720 3464588 : int_hh(ispin)%r_coef(nngau1 + 1, iso2), 1)
721 : CALL daxpy(size1, 1.0_dp, matso_s(iso1, ic), 1, &
722 4785478 : int_ss(ispin)%r_coef(nngau1 + 1, iso2), 1)
723 : END DO
724 :
725 : END DO ! ispin
726 :
727 : END IF ! lmax_expansion
728 :
729 : END DO ! ipfg2
730 : END DO ! ipfg1
731 294003 : m2 = m2 + maxso
732 : END DO ! iset2
733 57641 : m1 = m1 + maxso
734 : END DO ! iset1
735 :
736 16996 : DEALLOCATE (g1, g2, gg, matso_h, matso_s, gVg_s, gVg_h, vx)
737 :
738 16996 : DEALLOCATE (cg_list, cg_n_list)
739 :
740 16996 : CALL timestop(handle)
741 :
742 16996 : END SUBROUTINE gaVxcgb_noGC
743 :
744 : ! **************************************************************************************************
745 : !> \brief Integrate gradient-corrected Vxc and Vxg potentials with spherical primitive pairs.
746 : !> \param vxc_h ...
747 : !> \param vxc_s ...
748 : !> \param vxg_h ...
749 : !> \param vxg_s ...
750 : !> \param int_hh ...
751 : !> \param int_ss ...
752 : !> \param grid_atom ...
753 : !> \param basis_1c ...
754 : !> \param harmonics ...
755 : !> \param nspins ...
756 : !> \note Pre-projects vxc, r*(vxg.a), and vxg/r onto harmonics%slm once per (atom, spin) via DGEMM,
757 : !> skips shell pairs with lmin12 > lmax_expansion, and mirrors off-diagonal primitive pairs.
758 : ! **************************************************************************************************
759 33027 : SUBROUTINE gaVxcgb_GC(vxc_h, vxc_s, vxg_h, vxg_s, int_hh, int_ss, &
760 : grid_atom, basis_1c, harmonics, nspins)
761 :
762 : REAL(dp), DIMENSION(:, :, :), POINTER :: vxc_h, vxc_s
763 : REAL(dp), DIMENSION(:, :, :, :), POINTER :: vxg_h, vxg_s
764 : TYPE(rho_atom_coeff), DIMENSION(:), POINTER :: int_hh, int_ss
765 : TYPE(grid_atom_type), POINTER :: grid_atom
766 : TYPE(gto_basis_set_type), POINTER :: basis_1c
767 : TYPE(harmonics_atom_type), POINTER :: harmonics
768 : INTEGER, INTENT(IN) :: nspins
769 :
770 : CHARACTER(len=*), PARAMETER :: routineN = 'gaVxcgb_GC'
771 :
772 : INTEGER :: dmax_iso_not0, dmax_iso_not0_local, handle, ia, ic, icg, ipgf1, ipgf2, ir, iset1, &
773 : iset2, iso, iso1, iso1_lo, iso2, iso2_lo, ispin, l, ld_rad, lmax12, lmax_expansion, &
774 : lmin12, m1, m2, max_iso_not0, max_iso_not0_local, max_s_harm, maxl, maxso, n1, n2, na, &
775 : ngau1, ngau2, nl, nr, nset
776 : INTEGER, ALLOCATABLE, DIMENSION(:) :: cg_n_list, dcg_n_list
777 : INTEGER, ALLOCATABLE, DIMENSION(:, :, :) :: cg_list, dcg_list
778 33027 : INTEGER, DIMENSION(:), POINTER :: lmax, lmin, npgf
779 : REAL(dp) :: a1, a2, a3, cg_val, rad_ir, urad, &
780 : zet12_m2
781 33027 : REAL(dp), ALLOCATABLE, DIMENSION(:) :: g1, qv_h, qv_s
782 33027 : REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: gg, matso_h, matso_s
783 33027 : REAL(dp), ALLOCATABLE, DIMENSION(:, :, :) :: rad_vc, rad_vg, vc_grid, vc_slm, &
784 33027 : vg_grid, vg_slm
785 33027 : REAL(dp), DIMENSION(:, :), POINTER :: zet
786 : REAL(dp), DIMENSION(:, :, :), POINTER :: my_CG
787 : REAL(dp), DIMENSION(:, :, :, :), POINTER :: my_CG_dxyz
788 :
789 33027 : CALL timeset(routineN, handle)
790 :
791 33027 : NULLIFY (lmin, lmax, npgf, zet, my_CG, my_CG_dxyz)
792 :
793 : CALL get_gto_basis_set(gto_basis_set=basis_1c, lmax=lmax, lmin=lmin, &
794 : maxso=maxso, maxl=maxl, npgf=npgf, &
795 33027 : nset=nset, zet=zet)
796 :
797 33027 : nr = grid_atom%nr
798 33027 : na = grid_atom%ng_sphere
799 33027 : my_CG => harmonics%my_CG
800 33027 : my_CG_dxyz => harmonics%my_CG_dxyz
801 33027 : max_iso_not0 = harmonics%max_iso_not0
802 33027 : dmax_iso_not0 = harmonics%dmax_iso_not0
803 33027 : CPASSERT(max_iso_not0 > 0)
804 33027 : CPASSERT(IS_CONTIGUOUS(harmonics%slm))
805 33027 : lmax_expansion = indso(1, max_iso_not0)
806 33027 : max_s_harm = harmonics%max_s_harm
807 33027 : ld_rad = 2*maxl + 1
808 :
809 297243 : ALLOCATE (g1(nr), gg(nr, 0:2*maxl), qv_h(0:2*maxl), qv_s(0:2*maxl))
810 396324 : ALLOCATE (vc_grid(na, nr, 4), vc_slm(nr, 4, max_iso_not0), rad_vc(0:2*maxl, 4, max_iso_not0))
811 387990 : ALLOCATE (vg_grid(na, nr, 6), vg_slm(nr, 6, dmax_iso_not0), rad_vg(0:2*maxl, 6, dmax_iso_not0))
812 : ALLOCATE (cg_list(2, nsoset(maxl)**2, max_s_harm), cg_n_list(max_s_harm), &
813 297243 : dcg_list(2, nsoset(maxl)**2, max_s_harm), dcg_n_list(max_s_harm))
814 :
815 : ALLOCATE (matso_h(nsoset(maxl), nsoset(maxl)), &
816 198162 : matso_s(nsoset(maxl), nsoset(maxl)))
817 :
818 33027 : gg = 0.0_dp
819 33027 : qv_h = 0.0_dp
820 33027 : qv_s = 0.0_dp
821 33027 : rad_vc = 0.0_dp
822 33027 : rad_vg = 0.0_dp
823 :
824 69963 : DO ispin = 1, nspins
825 1915496 : DO ir = 1, nr
826 1878560 : rad_ir = grid_atom%rad(ir)
827 1878560 : urad = grid_atom%oorad2l(ir, 1)
828 99644376 : DO ia = 1, na
829 97728880 : a1 = harmonics%a(1, ia)
830 97728880 : a2 = harmonics%a(2, ia)
831 97728880 : a3 = harmonics%a(3, ia)
832 97728880 : vc_grid(ia, ir, 1) = vxc_h(ia, ir, ispin)
833 : vc_grid(ia, ir, 2) = rad_ir*(vxg_h(1, ia, ir, ispin)*a1 + &
834 : vxg_h(2, ia, ir, ispin)*a2 + &
835 97728880 : vxg_h(3, ia, ir, ispin)*a3)
836 97728880 : vc_grid(ia, ir, 3) = vxc_s(ia, ir, ispin)
837 : vc_grid(ia, ir, 4) = rad_ir*(vxg_s(1, ia, ir, ispin)*a1 + &
838 : vxg_s(2, ia, ir, ispin)*a2 + &
839 97728880 : vxg_s(3, ia, ir, ispin)*a3)
840 390915520 : vg_grid(ia, ir, 1:3) = vxg_h(1:3, ia, ir, ispin)*urad
841 392794080 : vg_grid(ia, ir, 4:6) = vxg_s(1:3, ia, ir, ispin)*urad
842 : END DO
843 : END DO
844 : CALL dgemm('T', 'N', 4*nr, max_iso_not0, na, 1.0_dp, vc_grid(1, 1, 1), na, &
845 36936 : harmonics%slm, SIZE(harmonics%slm, 1), 0.0_dp, vc_slm(1, 1, 1), 4*nr)
846 36936 : IF (dmax_iso_not0 > 0) THEN
847 : CALL dgemm('T', 'N', 6*nr, dmax_iso_not0, na, 1.0_dp, vg_grid(1, 1, 1), na, &
848 31879 : harmonics%slm, SIZE(harmonics%slm, 1), 0.0_dp, vg_slm(1, 1, 1), 6*nr)
849 : END IF
850 :
851 164598 : DO iset1 = 1, nset
852 94635 : m1 = (iset1 - 1)*maxso
853 94635 : n1 = nsoset(lmax(iset1))
854 94635 : iso1_lo = nsoset(lmin(iset1) - 1) + 1
855 343019 : DO iset2 = iset1, nset
856 211448 : lmin12 = lmin(iset1) + lmin(iset2)
857 211448 : IF (lmin12 > lmax_expansion) CYCLE
858 : CALL get_none0_cg_list(my_CG, lmin(iset1), lmax(iset1), lmin(iset2), lmax(iset2), &
859 211432 : max_s_harm, lmax_expansion, cg_list, cg_n_list, max_iso_not0_local)
860 211432 : CPASSERT(max_iso_not0_local <= max_iso_not0)
861 : CALL get_none0_cg_list(my_CG_dxyz, lmin(iset1), lmax(iset1), lmin(iset2), lmax(iset2), &
862 211432 : max_s_harm, lmax_expansion, dcg_list, dcg_n_list, dmax_iso_not0_local)
863 211432 : CPASSERT(dmax_iso_not0_local <= dmax_iso_not0)
864 211432 : IF (max_iso_not0_local <= 0 .AND. dmax_iso_not0_local <= 0) CYCLE
865 :
866 211432 : m2 = (iset2 - 1)*maxso
867 211432 : n2 = nsoset(lmax(iset2))
868 211432 : iso2_lo = nsoset(lmin(iset2) - 1) + 1
869 211432 : lmax12 = MIN(lmax(iset1) + lmax(iset2), lmax_expansion)
870 211432 : nl = lmax12 - lmin12 + 1
871 1303781 : DO ipgf1 = 1, npgf(iset1)
872 574850 : ngau1 = n1*(ipgf1 - 1) + m1
873 30203860 : g1(1:nr) = EXP(-zet(ipgf1, iset1)*grid_atom%rad2(1:nr))
874 2217381 : DO ipgf2 = MERGE(ipgf1, 1, iset1 == iset2), npgf(iset2)
875 1095580 : ngau2 = n2*(ipgf2 - 1) + m2
876 1095580 : zet12_m2 = -2.0_dp*(zet(ipgf1, iset1) + zet(ipgf2, iset2))
877 57524170 : gg(1:nr, lmin12) = g1(1:nr)*EXP(-zet(ipgf2, iset2)*grid_atom%rad2(1:nr))
878 22601100 : IF (lmin12 > 0) gg(1:nr, lmin12) = grid_atom%rad2l(1:nr, lmin12)*gg(1:nr, lmin12)
879 1693520 : DO l = lmin12 + 1, lmax12
880 32901920 : gg(1:nr, l) = grid_atom%rad(1:nr)*gg(1:nr, l - 1)
881 : END DO
882 1095580 : IF (max_iso_not0_local > 0) THEN
883 : CALL dgemm('T', 'N', nl, 4*max_iso_not0_local, nr, 1.0_dp, &
884 : gg(1, lmin12), nr, vc_slm(1, 1, 1), nr, 0.0_dp, &
885 1095580 : rad_vc(lmin12, 1, 1), ld_rad)
886 : END IF
887 1095580 : IF (dmax_iso_not0_local > 0) THEN
888 : CALL dgemm('T', 'N', nl, 6*dmax_iso_not0_local, nr, 1.0_dp, &
889 : gg(1, lmin12), nr, vg_slm(1, 1, 1), nr, 0.0_dp, &
890 713169 : rad_vg(lmin12, 1, 1), ld_rad)
891 : END IF
892 :
893 13345771 : matso_h(iso1_lo:n1, iso2_lo:n2) = 0.0_dp
894 13345771 : matso_s(iso1_lo:n1, iso2_lo:n2) = 0.0_dp
895 7990075 : DO iso = 1, max_iso_not0_local
896 20405723 : DO l = lmin12, lmax12
897 13511228 : qv_h(l) = rad_vc(l, 1, iso) + zet12_m2*rad_vc(l, 2, iso)
898 20405723 : qv_s(l) = rad_vc(l, 3, iso) + zet12_m2*rad_vc(l, 4, iso)
899 : END DO
900 22862869 : DO icg = 1, cg_n_list(iso)
901 14872794 : iso1 = cg_list(1, icg, iso)
902 14872794 : iso2 = cg_list(2, icg, iso)
903 14872794 : l = indso(1, iso1) + indso(1, iso2)
904 14872794 : cg_val = my_CG(iso1, iso2, iso)
905 14872794 : matso_h(iso1, iso2) = matso_h(iso1, iso2) + qv_h(l)*cg_val
906 21767289 : matso_s(iso1, iso2) = matso_s(iso1, iso2) + qv_s(l)*cg_val
907 : END DO
908 : END DO
909 4262881 : DO iso = 1, dmax_iso_not0_local
910 28323456 : DO icg = 1, dcg_n_list(iso)
911 24060575 : iso1 = dcg_list(1, icg, iso)
912 24060575 : iso2 = dcg_list(2, icg, iso)
913 24060575 : l = indso(1, iso1) + indso(1, iso2)
914 : matso_h(iso1, iso2) = matso_h(iso1, iso2) + &
915 : rad_vg(l, 1, iso)*my_CG_dxyz(1, iso1, iso2, iso) + &
916 : rad_vg(l, 2, iso)*my_CG_dxyz(2, iso1, iso2, iso) + &
917 24060575 : rad_vg(l, 3, iso)*my_CG_dxyz(3, iso1, iso2, iso)
918 : matso_s(iso1, iso2) = matso_s(iso1, iso2) + &
919 : rad_vg(l, 4, iso)*my_CG_dxyz(1, iso1, iso2, iso) + &
920 : rad_vg(l, 5, iso)*my_CG_dxyz(2, iso1, iso2, iso) + &
921 27227876 : rad_vg(l, 6, iso)*my_CG_dxyz(3, iso1, iso2, iso)
922 : END DO
923 : END DO
924 :
925 : ! Write in the global matrix
926 4339950 : DO ic = iso2_lo, n2
927 3244370 : iso2 = ngau2 + ic
928 13345771 : DO ir = iso1_lo, n1
929 9005821 : iso1 = ngau1 + ir
930 9005821 : int_hh(ispin)%r_coef(iso1, iso2) = int_hh(ispin)%r_coef(iso1, iso2) + matso_h(ir, ic)
931 12250191 : int_ss(ispin)%r_coef(iso1, iso2) = int_ss(ispin)%r_coef(iso1, iso2) + matso_s(ir, ic)
932 : END DO
933 : END DO
934 1670430 : IF (iset1 /= iset2 .OR. ipgf1 /= ipgf2) THEN
935 2621568 : DO ir = iso1_lo, n1
936 1765335 : iso1 = ngau1 + ir
937 9355280 : DO ic = iso2_lo, n2
938 6733712 : iso2 = ngau2 + ic
939 6733712 : int_hh(ispin)%r_coef(iso2, iso1) = int_hh(ispin)%r_coef(iso2, iso1) + matso_h(ir, ic)
940 8499047 : int_ss(ispin)%r_coef(iso2, iso1) = int_ss(ispin)%r_coef(iso2, iso1) + matso_s(ir, ic)
941 : END DO
942 : END DO
943 : END IF
944 : END DO ! ipgf2
945 : END DO ! ipgf1
946 : END DO ! iset2
947 : END DO ! iset1
948 : END DO ! ispin
949 :
950 33027 : DEALLOCATE (g1, gg, qv_h, qv_s, vc_grid, vc_slm, vg_grid, vg_slm, rad_vc, rad_vg)
951 33027 : DEALLOCATE (matso_h, matso_s, cg_list, cg_n_list, dcg_list, dcg_n_list)
952 :
953 33027 : CALL timestop(handle)
954 :
955 33027 : END SUBROUTINE gaVxcgb_GC
956 :
957 : ! **************************************************************************************************
958 : !> \brief Integrates 0.5 * grad_ga .dot. (V_tau * grad_gb) on the atomic grid for meta-GGA
959 : !> \param vtau_h the hard tau potential
960 : !> \param vtau_s the soft tau potential
961 : !> \param int_hh hard one-center matrix contribution
962 : !> \param int_ss soft one-center matrix contribution
963 : !> \param tau_cache precomputed compact one-center gradient basis
964 : !> \param nspins number of spin channels
965 : !> \note This is a rewrite to correct meta-GGA GAPW bug. This is more brute force than the original
966 : !> but makes sure that no corner is cut in terms of accuracy (A. Bussy)
967 : ! **************************************************************************************************
968 1265 : SUBROUTINE dgaVtaudgb(vtau_h, vtau_s, int_hh, int_ss, tau_cache, nspins)
969 :
970 : REAL(dp), DIMENSION(:, :, :), POINTER :: vtau_h, vtau_s
971 : TYPE(rho_atom_coeff), DIMENSION(:), POINTER :: int_hh, int_ss
972 : TYPE(tau_basis_cache_type), INTENT(IN) :: tau_cache
973 : INTEGER, INTENT(IN) :: nspins
974 :
975 : CHARACTER(len=*), PARAMETER :: routineN = 'dgaVtaudgb'
976 :
977 : INTEGER :: dir, handle, ia, ibas, igrid, iold, ir, &
978 : ispin, jbas, jold, max_old_basis, na, &
979 : nbas, ngrid, nr
980 1265 : REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: int_h, int_s, weighted_grad
981 :
982 1265 : CALL timeset(routineN, handle)
983 :
984 1265 : CPASSERT(ALLOCATED(tau_cache%grad))
985 1265 : CPASSERT(ASSOCIATED(tau_cache%n2oindex))
986 :
987 1265 : nr = tau_cache%nr
988 1265 : na = tau_cache%na
989 1265 : nbas = tau_cache%nsatbas
990 1265 : ngrid = na*nr
991 72410 : max_old_basis = MAXVAL(tau_cache%n2oindex)
992 11385 : ALLOCATE (int_h(nbas, nbas), int_s(nbas, nbas), weighted_grad(ngrid, nbas))
993 :
994 2610 : DO ispin = 1, nspins
995 1345 : CPASSERT(SIZE(int_hh(ispin)%r_coef, 1) >= max_old_basis)
996 1345 : CPASSERT(SIZE(int_hh(ispin)%r_coef, 2) >= max_old_basis)
997 1345 : CPASSERT(SIZE(int_ss(ispin)%r_coef, 1) >= max_old_basis)
998 1345 : CPASSERT(SIZE(int_ss(ispin)%r_coef, 2) >= max_old_basis)
999 1345 : int_h = 0.0_dp
1000 1345 : int_s = 0.0_dp
1001 5380 : DO dir = 1, 3
1002 : !$OMP PARALLEL DO DEFAULT(NONE) COLLAPSE(3) SCHEDULE(STATIC) &
1003 : !$OMP SHARED(dir, ispin, na, nbas, nr, tau_cache, vtau_h, weighted_grad) &
1004 4035 : !$OMP PRIVATE(ia, ibas, igrid, ir)
1005 : DO ibas = 1, nbas
1006 : DO ir = 1, nr
1007 : DO ia = 1, na
1008 : igrid = ia + (ir - 1)*na
1009 : weighted_grad(igrid, ibas) = vtau_h(ia, ir, ispin)* &
1010 : tau_cache%grad(igrid, ibas, dir)
1011 : END DO
1012 : END DO
1013 : END DO
1014 : !$OMP END PARALLEL DO
1015 : CALL dgemm('T', 'N', nbas, nbas, ngrid, 0.5_dp, tau_cache%grad(:, :, dir), &
1016 4035 : ngrid, weighted_grad, ngrid, 1.0_dp, int_h, nbas)
1017 :
1018 : !$OMP PARALLEL DO DEFAULT(NONE) COLLAPSE(3) SCHEDULE(STATIC) &
1019 : !$OMP SHARED(dir, ispin, na, nbas, nr, tau_cache, vtau_s, weighted_grad) &
1020 4035 : !$OMP PRIVATE(ia, ibas, igrid, ir)
1021 : DO ibas = 1, nbas
1022 : DO ir = 1, nr
1023 : DO ia = 1, na
1024 : igrid = ia + (ir - 1)*na
1025 : weighted_grad(igrid, ibas) = vtau_s(ia, ir, ispin)* &
1026 : tau_cache%grad(igrid, ibas, dir)
1027 : END DO
1028 : END DO
1029 : END DO
1030 : !$OMP END PARALLEL DO
1031 : CALL dgemm('T', 'N', nbas, nbas, ngrid, 0.5_dp, tau_cache%grad(:, :, dir), &
1032 5380 : ngrid, weighted_grad, ngrid, 1.0_dp, int_s, nbas)
1033 : END DO
1034 :
1035 : !$OMP PARALLEL DO DEFAULT(NONE) COLLAPSE(2) SCHEDULE(STATIC) &
1036 : !$OMP SHARED(int_h, int_hh, int_s, int_ss, ispin, nbas, tau_cache) &
1037 2610 : !$OMP PRIVATE(ibas, iold, jbas, jold)
1038 : DO jbas = 1, nbas
1039 : DO ibas = 1, nbas
1040 : jold = tau_cache%n2oindex(jbas)
1041 : iold = tau_cache%n2oindex(ibas)
1042 : int_hh(ispin)%r_coef(iold, jold) = int_hh(ispin)%r_coef(iold, jold) + &
1043 : int_h(ibas, jbas)
1044 : int_ss(ispin)%r_coef(iold, jold) = int_ss(ispin)%r_coef(iold, jold) + &
1045 : int_s(ibas, jbas)
1046 : END DO
1047 : END DO
1048 : !$OMP END PARALLEL DO
1049 : END DO
1050 :
1051 1265 : DEALLOCATE (int_h, int_s, weighted_grad)
1052 :
1053 1265 : CALL timestop(handle)
1054 :
1055 2530 : END SUBROUTINE dgaVtaudgb
1056 :
1057 : ! **************************************************************************************************
1058 : !> \brief Calculates the radial weight function for accurate XC integration
1059 : !> \param fun The weight function
1060 : !> \param r2 Radial values of the grid (squared)
1061 : !> \param order Polynomial order (2n)
1062 : !> \param alpha Gaussian exponent
1063 : ! **************************************************************************************************
1064 536 : SUBROUTINE calc_weight_function(fun, r2, order, alpha)
1065 :
1066 : REAL(dp), DIMENSION(:), INTENT(INOUT) :: fun
1067 : REAL(dp), DIMENSION(:), INTENT(IN) :: r2
1068 : INTEGER, INTENT(IN) :: order
1069 : REAL(dp), INTENT(IN) :: alpha
1070 :
1071 : INTEGER :: i
1072 : REAL(dp) :: pval
1073 :
1074 536 : CPASSERT(SIZE(fun) == SIZE(r2))
1075 :
1076 27156 : fun(:) = 1.0_dp
1077 540 : DO i = 1, order
1078 4 : pval = alpha**i/fac(i)
1079 740 : fun(:) = fun(:) + pval*r2**i
1080 : END DO
1081 27156 : fun(:) = fun(:)*EXP(-alpha*r2(:))
1082 :
1083 536 : END SUBROUTINE calc_weight_function
1084 :
1085 : ! **************************************************************************************************
1086 :
1087 0 : END MODULE qs_vxc_atom_utils
|