(git:d18deda)
Loading...
Searching...
No Matches
qs_rho0_ggrid.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7! **************************************************************************************************
13 USE cell_types, ONLY: cell_type,&
14 pbc
17 USE grid_api, ONLY: grid_func_ab,&
19 USE kinds, ONLY: dp
22 USE orbital_pointers, ONLY: indco,&
23 nco,&
24 ncoset,&
25 nso,&
26 nsoset
29 USE pw_env_types, ONLY: pw_env_get,&
31 USE pw_methods, ONLY: pw_axpy,&
32 pw_copy,&
34 pw_scale,&
37 USE pw_pool_types, ONLY: pw_pool_p_type,&
39 USE pw_types, ONLY: pw_c1d_gs_type,&
47 USE qs_kind_types, ONLY: get_qs_kind,&
51 USE qs_rho0_types, ONLY: get_rho0_mpole,&
64 USE util, ONLY: get_limit
65 USE virial_types, ONLY: virial_type
66#include "./base/base_uses.f90"
67
68 IMPLICIT NONE
69
70 PRIVATE
71
72 ! Global parameters (only in this module)
73
74 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_rho0_ggrid'
75
76 ! Public subroutines
77
79
80CONTAINS
81
82! **************************************************************************************************
83!> \brief ...
84!> \param qs_env ...
85!> \param rho0 ...
86!> \param tot_rs_int ...
87!> \param my_pools ...
88!> \param my_rs_grids ...
89!> \param my_rs_descs ...
90! **************************************************************************************************
91 SUBROUTINE put_rho0_on_grid(qs_env, rho0, tot_rs_int, my_pools, my_rs_grids, my_rs_descs)
92
93 TYPE(qs_environment_type), POINTER :: qs_env
94 TYPE(rho0_mpole_type), POINTER :: rho0
95 REAL(kind=dp), INTENT(OUT) :: tot_rs_int
96 TYPE(pw_pool_p_type), DIMENSION(:), OPTIONAL, &
97 POINTER :: my_pools
98 TYPE(realspace_grid_type), DIMENSION(:), &
99 OPTIONAL, POINTER :: my_rs_grids
100 TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
101 OPTIONAL, POINTER :: my_rs_descs
102
103 CHARACTER(LEN=*), PARAMETER :: routinen = 'put_rho0_on_grid'
104
105 INTEGER :: auxbas_grid, handle, iat, iatom, igrid, &
106 ikind, ithread, j, l0_ikind, lmax0, &
107 nat, nch_ik, nch_max, npme
108 INTEGER, DIMENSION(:), POINTER :: atom_list, cores
109 LOGICAL :: paw_atom
110 REAL(kind=dp) :: eps_rho_rspace, rpgf0, zet0
111 REAL(kind=dp), DIMENSION(3) :: ra
112 REAL(kind=dp), DIMENSION(:), POINTER :: qlm_c
113 REAL(kind=dp), DIMENSION(:, :), POINTER :: pab
114 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
115 TYPE(cell_type), POINTER :: cell
116 TYPE(dft_control_type), POINTER :: dft_control
117 TYPE(mp_para_env_type), POINTER :: para_env
118 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
119 TYPE(pw_c1d_gs_type) :: coeff_gspace
120 TYPE(pw_c1d_gs_type), POINTER :: rho0_s_gs
121 TYPE(pw_env_type), POINTER :: pw_env
122 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
123 TYPE(pw_pool_type), POINTER :: pw_pool
124 TYPE(pw_r3d_rs_type) :: coeff_rspace, rho0_r_tmp
125 TYPE(pw_r3d_rs_type), POINTER :: rho0_s_rs
126 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
127 TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
128 POINTER :: descs
129 TYPE(realspace_grid_desc_type), POINTER :: desc
130 TYPE(realspace_grid_type), DIMENSION(:), POINTER :: grids
131 TYPE(realspace_grid_type), POINTER :: rs_grid
132
133 CALL timeset(routinen, handle)
134
135 NULLIFY (atomic_kind_set, qs_kind_set, cores, pab, qlm_c)
136
137 NULLIFY (dft_control, pw_env, particle_set, para_env, cell, rho0_s_gs, rho0_s_rs)
138 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, &
139 particle_set=particle_set, &
140 atomic_kind_set=atomic_kind_set, &
141 qs_kind_set=qs_kind_set, &
142 para_env=para_env, &
143 pw_env=pw_env, cell=cell)
144 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
145
146 NULLIFY (descs, pw_pools)
147 CALL pw_env_get(pw_env=pw_env, rs_descs=descs, rs_grids=grids, pw_pools=pw_pools)
148 auxbas_grid = pw_env%auxbas_grid
149
150 NULLIFY (rho0_s_gs, rho0_s_rs)
151 CALL get_rho0_mpole(rho0_mpole=rho0, lmax_0=lmax0, &
152 zet0_h=zet0, igrid_zet0_s=igrid, &
153 rho0_s_gs=rho0_s_gs, &
154 rho0_s_rs=rho0_s_rs)
155
156 ! *** set up the rs grid at level igrid
157 NULLIFY (rs_grid, desc, pw_pool)
158 ! IF present, overwrite qs grid for new pool
159 IF (PRESENT(my_pools)) THEN
160 desc => my_rs_descs(igrid)%rs_desc
161 rs_grid => my_rs_grids(igrid)
162 pw_pool => my_pools(igrid)%pool
163 ELSE
164 desc => descs(igrid)%rs_desc
165 rs_grid => grids(igrid)
166 pw_pool => pw_pools(igrid)%pool
167 END IF
168
169 cpassert(ASSOCIATED(desc))
170 cpassert(ASSOCIATED(pw_pool))
171
172 IF (igrid /= auxbas_grid) THEN
173 CALL pw_pool%create_pw(coeff_rspace)
174 CALL pw_pool%create_pw(coeff_gspace)
175 END IF
176 CALL rs_grid_zero(rs_grid)
177
178 nch_max = ncoset(lmax0)
179
180 ALLOCATE (pab(nch_max, 1))
181
182 DO ikind = 1, SIZE(atomic_kind_set)
183 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom_list, natom=nat)
184 CALL get_qs_kind(qs_kind_set(ikind), paw_atom=paw_atom)
185
186 IF (.NOT. paw_atom .AND. dft_control%qs_control%gapw_control%nopaw_as_gpw) cycle
187
188 CALL get_rho0_mpole(rho0_mpole=rho0, ikind=ikind, l0_ikind=l0_ikind, &
189 rpgf0_s=rpgf0)
190
191 nch_ik = ncoset(l0_ikind)
192 pab = 0.0_dp
193
194 CALL reallocate(cores, 1, nat)
195 npme = 0
196 cores = 0
197
198 DO iat = 1, nat
199 iatom = atom_list(iat)
200 ra(:) = pbc(particle_set(iatom)%r, cell)
201 IF (rs_grid%desc%parallel .AND. .NOT. rs_grid%desc%distributed) THEN
202 ! replicated realspace grid, split the atoms up between procs
203 IF (modulo(nat, rs_grid%desc%group_size) == rs_grid%desc%my_pos) THEN
204 npme = npme + 1
205 cores(npme) = iat
206 END IF
207 ELSE
208 npme = npme + 1
209 cores(npme) = iat
210 END IF
211
212 END DO
213
214 ithread = 0
215 DO j = 1, npme
216
217 iat = cores(j)
218 iatom = atom_list(iat)
219
220 CALL get_rho0_mpole(rho0_mpole=rho0, iat=iatom, qlm_car=qlm_c)
221
222 pab(1:nch_ik, 1) = qlm_c(1:nch_ik)
223
224 ra(:) = pbc(particle_set(iatom)%r, cell)
225
227 l0_ikind, zet0, 0, 0, 0.0_dp, 0, &
228 ra, (/0.0_dp, 0.0_dp, 0.0_dp/), 1.0_dp, pab, 0, 0, &
229 rs_grid, ga_gb_function=grid_func_ab, radius=rpgf0, &
230 use_subpatch=.true., subpatch_pattern=0)
231
232 END DO ! j
233
234 END DO ! ikind
235
236 IF (ASSOCIATED(cores)) THEN
237 DEALLOCATE (cores)
238 END IF
239
240 DEALLOCATE (pab)
241
242 IF (igrid /= auxbas_grid) THEN
243 CALL transfer_rs2pw(rs_grid, coeff_rspace)
244 CALL pw_zero(rho0_s_gs)
245 CALL pw_transfer(coeff_rspace, coeff_gspace)
246 CALL pw_axpy(coeff_gspace, rho0_s_gs)
247
248 tot_rs_int = pw_integrate_function(coeff_rspace, isign=-1)
249
250 CALL pw_pool%give_back_pw(coeff_rspace)
251 CALL pw_pool%give_back_pw(coeff_gspace)
252 ELSE
253
254 CALL pw_pool%create_pw(rho0_r_tmp)
255
256 CALL transfer_rs2pw(rs_grid, rho0_r_tmp)
257
258 tot_rs_int = pw_integrate_function(rho0_r_tmp, isign=-1)
259
260 CALL pw_transfer(rho0_r_tmp, rho0_s_rs)
261 CALL pw_pool%give_back_pw(rho0_r_tmp)
262
263 CALL pw_zero(rho0_s_gs)
264 CALL pw_transfer(rho0_s_rs, rho0_s_gs)
265 END IF
266 CALL timestop(handle)
267
268 END SUBROUTINE put_rho0_on_grid
269
270! **************************************************************************************************
271!> \brief ...
272!> \param pw_env ...
273!> \param rho0_mpole ...
274! **************************************************************************************************
275 SUBROUTINE rho0_s_grid_create(pw_env, rho0_mpole)
276
277 TYPE(pw_env_type), POINTER :: pw_env
278 TYPE(rho0_mpole_type), POINTER :: rho0_mpole
279
280 CHARACTER(len=*), PARAMETER :: routinen = 'rho0_s_grid_create'
281
282 INTEGER :: handle
283 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
284
285 CALL timeset(routinen, handle)
286
287 cpassert(ASSOCIATED(pw_env))
288
289 NULLIFY (auxbas_pw_pool)
290 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
291 cpassert(ASSOCIATED(auxbas_pw_pool))
292
293 ! reallocate rho0 on the global grid in real and reciprocal space
294 cpassert(ASSOCIATED(rho0_mpole))
295
296 ! rho0 density in real space
297 IF (ASSOCIATED(rho0_mpole%rho0_s_rs)) THEN
298 CALL rho0_mpole%rho0_s_rs%release()
299 ELSE
300 ALLOCATE (rho0_mpole%rho0_s_rs)
301 END IF
302 CALL auxbas_pw_pool%create_pw(rho0_mpole%rho0_s_rs)
303
304 ! rho0 density in reciprocal space
305 IF (ASSOCIATED(rho0_mpole%rho0_s_gs)) THEN
306 CALL rho0_mpole%rho0_s_gs%release()
307 ELSE
308 ALLOCATE (rho0_mpole%rho0_s_gs)
309 END IF
310 CALL auxbas_pw_pool%create_pw(rho0_mpole%rho0_s_gs)
311
312 ! Find the grid level suitable for rho0_soft
313 rho0_mpole%igrid_zet0_s = gaussian_gridlevel(pw_env%gridlevel_info, 2.0_dp*rho0_mpole%zet0_h)
314
315 CALL timestop(handle)
316
317 END SUBROUTINE rho0_s_grid_create
318
319! **************************************************************************************************
320!> \brief ...
321!> \param qs_env ...
322!> \param v_rspace ...
323!> \param para_env ...
324!> \param calculate_forces ...
325!> \param local_rho_set ...
326!> \param local_rho_set_2nd ...
327!> \param atener ...
328!> \param kforce ...
329!> \param my_pools ...
330!> \param my_rs_descs ...
331! **************************************************************************************************
332 SUBROUTINE integrate_vhg0_rspace(qs_env, v_rspace, para_env, calculate_forces, local_rho_set, &
333 local_rho_set_2nd, atener, kforce, my_pools, my_rs_descs)
334
335 TYPE(qs_environment_type), POINTER :: qs_env
336 TYPE(pw_r3d_rs_type), INTENT(IN) :: v_rspace
337 TYPE(mp_para_env_type), POINTER :: para_env
338 LOGICAL, INTENT(IN) :: calculate_forces
339 TYPE(local_rho_type), OPTIONAL, POINTER :: local_rho_set, local_rho_set_2nd
340 REAL(kind=dp), DIMENSION(:), OPTIONAL :: atener
341 REAL(kind=dp), INTENT(IN), OPTIONAL :: kforce
342 TYPE(pw_pool_p_type), DIMENSION(:), OPTIONAL, &
343 POINTER :: my_pools
344 TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
345 OPTIONAL, POINTER :: my_rs_descs
346
347 CHARACTER(LEN=*), PARAMETER :: routinen = 'integrate_vhg0_rspace'
348
349 INTEGER :: auxbas_grid, bo(2), handle, i, iat, iatom, ic, icg, ico, ig1, ig2, igrid, ii, &
350 ikind, ipgf1, ipgf2, is, iset1, iset2, iso, iso1, iso2, ispin, j, l0_ikind, llmax, lmax0, &
351 lshell, lx, ly, lz, m1, m2, max_iso_not0_local, max_s_harm, maxl, maxso, mepos, n1, n2, &
352 nat, nch_ik, nch_max, ncurr, nset, nsotot, nspins, num_pe
353 INTEGER, ALLOCATABLE, DIMENSION(:) :: cg_n_list
354 INTEGER, ALLOCATABLE, DIMENSION(:, :, :) :: cg_list
355 INTEGER, DIMENSION(:), POINTER :: atom_list, lmax, lmin, npgf
356 LOGICAL :: grid_distributed, paw_atom, use_virial
357 REAL(kind=dp) :: eps_rho_rspace, force_tmp(3), fscale, &
358 ra(3), rpgf0, zet0
359 REAL(kind=dp), DIMENSION(3, 3) :: my_virial_a, my_virial_b
360 REAL(kind=dp), DIMENSION(:), POINTER :: hab_sph, norm_l, qlm
361 REAL(kind=dp), DIMENSION(:, :), POINTER :: hab, hdab_sph, intloc, pab
362 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: a_hdab_sph, hdab, qlm_gg
363 REAL(kind=dp), DIMENSION(:, :, :, :), POINTER :: a_hdab
364 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
365 TYPE(cell_type), POINTER :: cell
366 TYPE(dft_control_type), POINTER :: dft_control
367 TYPE(gto_basis_set_type), POINTER :: basis_1c_set
368 TYPE(harmonics_atom_type), POINTER :: harmonics
369 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
370 TYPE(pw_c1d_gs_type) :: coeff_gaux, coeff_gspace
371 TYPE(pw_env_type), POINTER :: pw_env
372 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
373 TYPE(pw_pool_type), POINTER :: pw_aux, pw_pool
374 TYPE(pw_r3d_rs_type) :: coeff_raux, coeff_rspace
375 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
376 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
377 TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
378 POINTER :: rs_descs
379 TYPE(realspace_grid_desc_type), POINTER :: rs_desc
380 TYPE(realspace_grid_type) :: rs_v
381 TYPE(rho0_mpole_type), POINTER :: rho0_mpole
382 TYPE(rho_atom_coeff), DIMENSION(:), POINTER :: int_local_h, int_local_s
383 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
384 TYPE(rho_atom_type), POINTER :: rho_atom
385 TYPE(virial_type), POINTER :: virial
386
387 CALL timeset(routinen, handle)
388
389 ! In case of the external density computed forces probably also
390 ! need to be stored outside qs_env. We can then remove the
391 ! attribute 'OPTIONAL' from the argument 'local_rho_set'.
392
393 ! CPASSERT(.NOT. (calculate_forces .AND. PRESENT(local_rho_set)))
394! IF (calculate_forces .AND. PRESENT(local_rho_set)) THEN
395! CPWARN("Forces and External Density!")
396! END IF
397
398 NULLIFY (atomic_kind_set, qs_kind_set, dft_control, particle_set)
399 NULLIFY (cell, force, pw_env, rho0_mpole, rho_atom_set)
400
401 CALL get_qs_env(qs_env=qs_env, &
402 atomic_kind_set=atomic_kind_set, &
403 qs_kind_set=qs_kind_set, &
404 cell=cell, &
405 dft_control=dft_control, &
406 force=force, pw_env=pw_env, &
407 rho0_mpole=rho0_mpole, &
408 rho_atom_set=rho_atom_set, &
409 particle_set=particle_set, &
410 virial=virial)
411
412 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
413
414 nspins = dft_control%nspins
415
416 ! The aim of the following code was to return immediately if the subroutine
417 ! was called for triplet excited states in spin-restricted case. This check
418 ! is also performed before invocation of this subroutine. It should be save
419 ! to remove the optional argument 'do_triplet' from the subroutine interface.
420 !my_tddft = PRESENT(local_rho_set)
421 !IF (my_tddft) THEN
422 ! IF (PRESENT(do_triplet)) THEN
423 ! IF (nspins == 1 .AND. do_triplet) RETURN
424 ! ELSE
425 ! IF (nspins == 1 .AND. dft_control%tddfpt_control%res_etype /= tddfpt_singlet) RETURN
426 ! END IF
427 !END IF
428
429 IF (PRESENT(local_rho_set)) &
430 CALL get_local_rho(local_rho_set, rho0_mpole=rho0_mpole, rho_atom_set=rho_atom_set)
431 ! Q from rho0_mpole of local_rho_set
432 ! for TDDFT forces we need mixed potential / integral space
433 ! potential stored on local_rho_set_2nd
434 IF (PRESENT(local_rho_set_2nd)) THEN
435 CALL get_local_rho(local_rho_set_2nd, rho_atom_set=rho_atom_set)
436 END IF
437 CALL get_rho0_mpole(rho0_mpole=rho0_mpole, lmax_0=lmax0, &
438 zet0_h=zet0, igrid_zet0_s=igrid, &
439 norm_g0l_h=norm_l)
440
441 ! Setup of the potential on the multigrids
442 NULLIFY (rs_descs, pw_pools)
443 cpassert(ASSOCIATED(pw_env))
444 CALL pw_env_get(pw_env, rs_descs=rs_descs, pw_pools=pw_pools)
445
446 ! Assign from pw_env
447 auxbas_grid = pw_env%auxbas_grid
448
449 ! IF present, overwrite qs grid for new pool
450 ! Get the potential on the right grid
451 IF (PRESENT(my_pools)) THEN
452 rs_desc => my_rs_descs(igrid)%rs_desc
453 pw_pool => my_pools(igrid)%pool
454 ELSE
455 rs_desc => rs_descs(igrid)%rs_desc
456 pw_pool => pw_pools(igrid)%pool
457 END IF
458
459 CALL pw_pool%create_pw(coeff_gspace)
460 CALL pw_pool%create_pw(coeff_rspace)
461
462 IF (igrid /= auxbas_grid) THEN
463 pw_aux => pw_pools(auxbas_grid)%pool
464 CALL pw_aux%create_pw(coeff_gaux)
465 CALL pw_transfer(v_rspace, coeff_gaux)
466 CALL pw_copy(coeff_gaux, coeff_gspace)
467 CALL pw_transfer(coeff_gspace, coeff_rspace)
468 CALL pw_aux%give_back_pw(coeff_gaux)
469 CALL pw_aux%create_pw(coeff_raux)
470 fscale = coeff_rspace%pw_grid%dvol/coeff_raux%pw_grid%dvol
471 CALL pw_scale(coeff_rspace, fscale)
472 CALL pw_aux%give_back_pw(coeff_raux)
473 ELSE
474
475 IF (coeff_gspace%pw_grid%spherical) THEN
476 CALL pw_transfer(v_rspace, coeff_gspace)
477 CALL pw_transfer(coeff_gspace, coeff_rspace)
478 ELSE
479 CALL pw_copy(v_rspace, coeff_rspace)
480 END IF
481 END IF
482 CALL pw_pool%give_back_pw(coeff_gspace)
483
484 ! Setup the rs grid at level igrid
485 CALL rs_grid_create(rs_v, rs_desc)
486 CALL rs_grid_zero(rs_v)
487 CALL transfer_pw2rs(rs_v, coeff_rspace)
488
489 CALL pw_pool%give_back_pw(coeff_rspace)
490
491 ! Now the potential is on the right grid => integration
492
493 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
494
495 ! Allocate work storage
496
497 NULLIFY (hab, hab_sph, hdab, hdab_sph, pab, a_hdab, a_hdab_sph)
498 nch_max = ncoset(lmax0)
499 CALL reallocate(hab, 1, nch_max, 1, 1)
500 CALL reallocate(hab_sph, 1, nch_max)
501 CALL reallocate(hdab, 1, 3, 1, nch_max, 1, 1)
502 CALL reallocate(hdab_sph, 1, 3, 1, nch_max)
503 CALL reallocate(a_hdab, 1, 3, 1, 3, 1, nch_max, 1, 1)
504 CALL reallocate(a_hdab_sph, 1, 3, 1, 3, 1, nch_max)
505 CALL reallocate(pab, 1, nch_max, 1, 1)
506
507 ncurr = -1
508
509 grid_distributed = rs_v%desc%distributed
510
511 fscale = 1.0_dp
512 IF (PRESENT(kforce)) THEN
513 fscale = kforce
514 END IF
515
516 DO ikind = 1, SIZE(atomic_kind_set, 1)
517 NULLIFY (basis_1c_set, atom_list, harmonics)
518 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom_list, natom=nat)
519 CALL get_qs_kind(qs_kind_set(ikind), &
520 basis_set=basis_1c_set, basis_type="GAPW_1C", &
521 paw_atom=paw_atom, &
522 harmonics=harmonics)
523
524 IF (.NOT. paw_atom) cycle
525
526 NULLIFY (qlm_gg, lmax, npgf)
527 CALL get_rho0_mpole(rho0_mpole=rho0_mpole, ikind=ikind, &
528 l0_ikind=l0_ikind, qlm_gg=qlm_gg, & ! Qs different
529 rpgf0_s=rpgf0)
530
531 CALL get_gto_basis_set(gto_basis_set=basis_1c_set, &
532 lmax=lmax, lmin=lmin, &
533 maxso=maxso, maxl=maxl, &
534 nset=nset, npgf=npgf)
535
536 nsotot = maxso*nset
537 ALLOCATE (intloc(nsotot, nsotot))
538
539 ! Initialize the local KS integrals
540
541 nch_ik = ncoset(l0_ikind)
542 pab = 1.0_dp
543 max_s_harm = harmonics%max_s_harm
544 llmax = harmonics%llmax
545
546 ALLOCATE (cg_list(2, nsoset(maxl)**2, max_s_harm), cg_n_list(max_s_harm))
547
548 num_pe = para_env%num_pe
549 mepos = para_env%mepos
550 DO j = 0, num_pe - 1
551 bo = get_limit(nat, num_pe, j)
552 IF (.NOT. grid_distributed .AND. j /= mepos) cycle
553
554 DO iat = bo(1), bo(2)
555 iatom = atom_list(iat)
556 ra(:) = pbc(particle_set(iatom)%r, cell)
557
558 NULLIFY (qlm)
559 CALL get_rho0_mpole(rho0_mpole=rho0_mpole, iat=iatom, qlm_tot=qlm)
560
561 hab = 0.0_dp
562 hdab = 0.0_dp
563 intloc = 0._dp
564 IF (use_virial) THEN
565 my_virial_a = 0.0_dp
566 my_virial_b = 0.0_dp
567 a_hdab = 0.0_dp
568 END IF
569
571 l0_ikind, zet0, 0, 0, 0.0_dp, 0, &
572 ra, (/0.0_dp, 0.0_dp, 0.0_dp/), rs_v, &
573 hab, pab, o1=0, o2=0, &
574 radius=rpgf0, &
575 calculate_forces=calculate_forces, &
576 use_virial=use_virial, my_virial_a=my_virial_a, my_virial_b=my_virial_b, &
577 hdab=hdab, a_hdab=a_hdab, use_subpatch=.true., subpatch_pattern=0)
578
579 ! Convert from cartesian to spherical
580 DO lshell = 0, l0_ikind
581 DO is = 1, nso(lshell)
582 iso = is + nsoset(lshell - 1)
583 hab_sph(iso) = 0.0_dp
584 hdab_sph(1:3, iso) = 0.0_dp
585 a_hdab_sph(1:3, 1:3, iso) = 0.0_dp
586 DO ic = 1, nco(lshell)
587 ico = ic + ncoset(lshell - 1)
588 lx = indco(1, ico)
589 ly = indco(2, ico)
590 lz = indco(3, ico)
591 hab_sph(iso) = hab_sph(iso) + &
592 norm_l(lshell)* &
593 orbtramat(lshell)%slm(is, ic)* &
594 hab(ico, 1)
595 IF (calculate_forces) THEN
596 hdab_sph(1:3, iso) = hdab_sph(1:3, iso) + &
597 norm_l(lshell)* &
598 orbtramat(lshell)%slm(is, ic)* &
599 hdab(1:3, ico, 1)
600 END IF
601 IF (use_virial) THEN
602 DO ii = 1, 3
603 DO i = 1, 3
604 a_hdab_sph(i, ii, iso) = a_hdab_sph(i, ii, iso) + &
605 norm_l(lshell)* &
606 orbtramat(lshell)%slm(is, ic)* &
607 a_hdab(i, ii, ico, 1)
608 END DO
609 END DO
610 END IF
611
612 END DO ! ic
613 END DO ! is
614 END DO ! lshell
615
616 m1 = 0
617 DO iset1 = 1, nset
618
619 m2 = 0
620 DO iset2 = 1, nset
621 CALL get_none0_cg_list(harmonics%my_CG, lmin(iset1), lmax(iset1), lmin(iset2), lmax(iset2), &
622 max_s_harm, llmax, cg_list, cg_n_list, max_iso_not0_local)
623 n1 = nsoset(lmax(iset1))
624 DO ipgf1 = 1, npgf(iset1)
625 n2 = nsoset(lmax(iset2))
626 DO ipgf2 = 1, npgf(iset2)
627
628 DO iso = 1, min(nsoset(l0_ikind), max_iso_not0_local)
629 DO icg = 1, cg_n_list(iso)
630 iso1 = cg_list(1, icg, iso)
631 iso2 = cg_list(2, icg, iso)
632
633 ig1 = iso1 + n1*(ipgf1 - 1) + m1
634 ig2 = iso2 + n2*(ipgf2 - 1) + m2
635
636 intloc(ig1, ig2) = intloc(ig1, ig2) + qlm_gg(ig1, ig2, iso)*hab_sph(iso) ! potential times Q
637
638 END DO ! icg
639 END DO ! iso
640
641 END DO ! ipgf2
642 END DO ! ipgf1
643 m2 = m2 + maxso
644 END DO ! iset2
645 m1 = m1 + maxso
646 END DO ! iset1
647
648 IF (grid_distributed) THEN
649 ! Sum result over all processors
650 CALL para_env%sum(intloc)
651 END IF
652
653 IF (j == mepos) THEN
654 rho_atom => rho_atom_set(iatom)
655 CALL get_rho_atom(rho_atom=rho_atom, ga_vlocal_gb_h=int_local_h, ga_vlocal_gb_s=int_local_s)
656 DO ispin = 1, nspins
657 int_local_h(ispin)%r_coef = int_local_h(ispin)%r_coef + intloc
658 int_local_s(ispin)%r_coef = int_local_s(ispin)%r_coef + intloc
659 END DO
660 END IF
661
662 IF (PRESENT(atener)) THEN
663 DO iso = 1, nsoset(l0_ikind)
664 atener(iatom) = atener(iatom) + 0.5_dp*qlm(iso)*hab_sph(iso)
665 END DO
666 END IF
667
668 IF (calculate_forces) THEN
669 force_tmp(1:3) = 0.0_dp
670 DO iso = 1, nsoset(l0_ikind)
671 force_tmp(1) = force_tmp(1) + qlm(iso)*hdab_sph(1, iso) ! Q here is from local_rho_set
672 force_tmp(2) = force_tmp(2) + qlm(iso)*hdab_sph(2, iso)
673 force_tmp(3) = force_tmp(3) + qlm(iso)*hdab_sph(3, iso)
674 END DO
675 force(ikind)%g0s_Vh_elec(1:3, iat) = force(ikind)%g0s_Vh_elec(1:3, iat) + fscale*force_tmp(1:3)
676 END IF
677 IF (use_virial) THEN
678 my_virial_a = 0.0_dp
679 DO iso = 1, nsoset(l0_ikind)
680 DO ii = 1, 3
681 DO i = 1, 3
682 ! Q from local_rho_set
683 virial%pv_gapw(i, ii) = virial%pv_gapw(i, ii) + fscale*qlm(iso)*a_hdab_sph(i, ii, iso)
684 virial%pv_virial(i, ii) = virial%pv_virial(i, ii) + fscale*qlm(iso)*a_hdab_sph(i, ii, iso)
685 END DO
686 END DO
687 END DO
688 END IF
689
690 END DO
691 END DO
692
693 DEALLOCATE (intloc)
694 DEALLOCATE (cg_list, cg_n_list)
695
696 END DO ! ikind
697
698 CALL rs_grid_release(rs_v)
699
700 DEALLOCATE (hab, hdab, hab_sph, hdab_sph, pab, a_hdab, a_hdab_sph)
701
702 CALL timestop(handle)
703
704 END SUBROUTINE integrate_vhg0_rspace
705
706END MODULE qs_rho0_ggrid
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum)
...
Handles all functions related to the CELL.
Definition cell_types.F:15
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
integer function, public gaussian_gridlevel(gridlevel_info, exponent)
...
Fortran API for the grid package, which is written in C.
Definition grid_api.F:12
integer, parameter, public grid_func_ab
Definition grid_api.F:29
subroutine, public integrate_pgf_product(la_max, zeta, la_min, lb_max, zetb, lb_min, ra, rab, rsgrid, hab, pab, o1, o2, radius, calculate_forces, force_a, force_b, compute_tau, use_virial, my_virial_a, my_virial_b, hdab, hadb, a_hdab, use_subpatch, subpatch_pattern)
low level function to compute matrix elements of primitive gaussian functions
Definition grid_api.F:279
subroutine, public collocate_pgf_product(la_max, zeta, la_min, lb_max, zetb, lb_min, ra, rab, scale, pab, o1, o2, rsgrid, ga_gb_function, radius, use_subpatch, subpatch_pattern)
low level collocation of primitive gaussian functions
Definition grid_api.F:119
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Utility routines for the memory handling.
Interface to the message passing library MPI.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public nco
integer, dimension(:), allocatable, public nsoset
integer, dimension(:), allocatable, public ncoset
integer, dimension(:, :), allocatable, public indco
integer, dimension(:), allocatable, public nso
Calculation of the spherical harmonics and the corresponding orbital transformation matrices.
type(orbtramat_type), dimension(:), pointer, public orbtramat
Define the data structure for the particle information.
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_local_rho(local_rho_set, rho_atom_set, rho0_atom_set, rho0_mpole, rhoz_set)
...
subroutine, public put_rho0_on_grid(qs_env, rho0, tot_rs_int, my_pools, my_rs_grids, my_rs_descs)
...
subroutine, public rho0_s_grid_create(pw_env, rho0_mpole)
...
subroutine, public integrate_vhg0_rspace(qs_env, v_rspace, para_env, calculate_forces, local_rho_set, local_rho_set_2nd, atener, kforce, my_pools, my_rs_descs)
...
subroutine, public get_rho0_mpole(rho0_mpole, g0_h, vg0_h, iat, ikind, lmax_0, l0_ikind, mp_gau_ikind, mp_rho, norm_g0l_h, qlm_gg, qlm_car, qlm_tot, zet0_h, igrid_zet0_s, rpgf0_h, rpgf0_s, max_rpgf0_s, rho0_s_rs, rho0_s_gs)
...
subroutine, public get_rho_atom(rho_atom, cpc_h, cpc_s, rho_rad_h, rho_rad_s, drho_rad_h, drho_rad_s, vrho_rad_h, vrho_rad_s, rho_rad_h_d, rho_rad_s_d, ga_vlocal_gb_h, ga_vlocal_gb_s, int_scr_h, int_scr_s)
...
subroutine, public rs_grid_create(rs, desc)
...
subroutine, public transfer_pw2rs(rs, pw)
...
subroutine, public transfer_rs2pw(rs, pw)
...
subroutine, public rs_grid_release(rs_grid)
releases the given rs grid (see doc/ReferenceCounting.html)
subroutine, public rs_grid_zero(rs)
Initialize grid to zero.
All kind of helpful little routines.
Definition util.F:14
pure integer function, dimension(2), public get_limit(m, n, me)
divide m entries into n parts, return size of part me
Definition util.F:333
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
stores all the informations relevant to an mpi environment
contained for different pw related things
to create arrays of pools
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.