(git:2bb242e)
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-2026 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,&
49 USE qs_kind_types, ONLY: get_qs_kind,&
53 USE qs_rho0_types, ONLY: get_rho0_mpole,&
66 USE util, ONLY: get_limit
67 USE virial_types, ONLY: virial_type
68#include "./base/base_uses.f90"
69
70 IMPLICIT NONE
71
72 PRIVATE
73
74 ! Global parameters (only in this module)
75
76 CHARACTER(LEN=*), PARAMETER, PRIVATE :: moduleN = 'qs_rho0_ggrid'
77
78 ! Public subroutines
79
81
82CONTAINS
83
84! **************************************************************************************************
85!> \brief ...
86!> \param qs_env ...
87!> \param rho0 ...
88!> \param tot_rs_int ...
89!> \param my_pools ...
90!> \param my_rs_grids ...
91!> \param my_rs_descs ...
92! **************************************************************************************************
93 SUBROUTINE put_rho0_on_grid(qs_env, rho0, tot_rs_int, my_pools, my_rs_grids, my_rs_descs)
94
95 TYPE(qs_environment_type), POINTER :: qs_env
96 TYPE(rho0_mpole_type), POINTER :: rho0
97 REAL(kind=dp), INTENT(OUT) :: tot_rs_int
98 TYPE(pw_pool_p_type), DIMENSION(:), OPTIONAL, &
99 POINTER :: my_pools
100 TYPE(realspace_grid_type), DIMENSION(:), &
101 OPTIONAL, POINTER :: my_rs_grids
102 TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
103 OPTIONAL, POINTER :: my_rs_descs
104
105 CHARACTER(LEN=*), PARAMETER :: routinen = 'put_rho0_on_grid'
106
107 INTEGER :: auxbas_grid, handle, iat, iatom, igrid, &
108 ikind, ithread, j, l0_ikind, lmax0, &
109 nat, nch_ik, nch_max, npme
110 INTEGER, DIMENSION(:), POINTER :: atom_list, cores
111 LOGICAL :: paw_atom
112 REAL(kind=dp) :: eps_rho_rspace, rpgf0, zet0
113 REAL(kind=dp), DIMENSION(3) :: ra
114 REAL(kind=dp), DIMENSION(:), POINTER :: qlm_c
115 REAL(kind=dp), DIMENSION(:, :), POINTER :: pab
116 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
117 TYPE(cell_type), POINTER :: cell
118 TYPE(dft_control_type), POINTER :: dft_control
119 TYPE(mp_para_env_type), POINTER :: para_env
120 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
121 TYPE(pw_c1d_gs_type) :: coeff_gspace
122 TYPE(pw_c1d_gs_type), POINTER :: rho0_s_gs
123 TYPE(pw_env_type), POINTER :: pw_env
124 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
125 TYPE(pw_pool_type), POINTER :: pw_pool
126 TYPE(pw_r3d_rs_type) :: coeff_rspace
127 TYPE(pw_r3d_rs_type), POINTER :: rho0_s_rs
128 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
129 TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
130 POINTER :: descs
131 TYPE(realspace_grid_desc_type), POINTER :: desc
132 TYPE(realspace_grid_type), DIMENSION(:), POINTER :: grids
133 TYPE(realspace_grid_type), POINTER :: rs_grid
134
135 CALL timeset(routinen, handle)
136
137 NULLIFY (atomic_kind_set, qs_kind_set, cores, pab, qlm_c)
138
139 NULLIFY (dft_control, pw_env, particle_set, para_env, cell, rho0_s_gs, rho0_s_rs)
140 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, &
141 particle_set=particle_set, &
142 atomic_kind_set=atomic_kind_set, &
143 qs_kind_set=qs_kind_set, &
144 para_env=para_env, &
145 pw_env=pw_env, cell=cell)
146 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
147
148 NULLIFY (descs, pw_pools)
149 CALL pw_env_get(pw_env=pw_env, rs_descs=descs, rs_grids=grids, pw_pools=pw_pools)
150 auxbas_grid = pw_env%auxbas_grid
151
152 NULLIFY (rho0_s_gs, rho0_s_rs)
153 CALL get_rho0_mpole(rho0_mpole=rho0, lmax_0=lmax0, &
154 zet0_h=zet0, igrid_zet0_s=igrid, &
155 rho0_s_gs=rho0_s_gs, &
156 rho0_s_rs=rho0_s_rs)
157
158 ! *** set up the rs grid at level igrid
159 NULLIFY (rs_grid, desc, pw_pool)
160 ! IF present, overwrite qs grid for new pool
161 IF (PRESENT(my_pools)) THEN
162 desc => my_rs_descs(igrid)%rs_desc
163 rs_grid => my_rs_grids(igrid)
164 pw_pool => my_pools(igrid)%pool
165 ELSE
166 desc => descs(igrid)%rs_desc
167 rs_grid => grids(igrid)
168 pw_pool => pw_pools(igrid)%pool
169 END IF
170
171 cpassert(ASSOCIATED(desc))
172 cpassert(ASSOCIATED(pw_pool))
173
174 IF (igrid /= auxbas_grid) THEN
175 CALL pw_pool%create_pw(coeff_rspace)
176 CALL pw_pool%create_pw(coeff_gspace)
177 END IF
178 CALL rs_grid_zero(rs_grid)
179
180 nch_max = ncoset(lmax0)
181
182 ALLOCATE (pab(nch_max, 1))
183
184 DO ikind = 1, SIZE(atomic_kind_set)
185 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom_list, natom=nat)
186 CALL get_qs_kind(qs_kind_set(ikind), paw_atom=paw_atom)
187
188 IF (.NOT. paw_atom .AND. dft_control%qs_control%gapw_control%nopaw_as_gpw) cycle
189
190 CALL get_rho0_mpole(rho0_mpole=rho0, ikind=ikind, l0_ikind=l0_ikind, &
191 rpgf0_s=rpgf0)
192
193 nch_ik = ncoset(l0_ikind)
194 pab = 0.0_dp
195
196 CALL reallocate(cores, 1, nat)
197 npme = 0
198 cores = 0
199
200 DO iat = 1, nat
201 iatom = atom_list(iat)
202 ra(:) = pbc(particle_set(iatom)%r, cell)
203 IF (rs_grid%desc%parallel .AND. .NOT. rs_grid%desc%distributed) THEN
204 ! replicated realspace grid, split the atoms up between procs
205 IF (modulo(iatom, rs_grid%desc%group_size) == rs_grid%desc%my_pos) THEN
206 npme = npme + 1
207 cores(npme) = iat
208 END IF
209 ELSE
210 npme = npme + 1
211 cores(npme) = iat
212 END IF
213
214 END DO
215
216 ithread = 0
217 DO j = 1, npme
218
219 iat = cores(j)
220 iatom = atom_list(iat)
221
222 CALL get_rho0_mpole(rho0_mpole=rho0, iat=iatom, qlm_car=qlm_c)
223
224 pab(1:nch_ik, 1) = qlm_c(1:nch_ik)
225
226 ra(:) = pbc(particle_set(iatom)%r, cell)
227
229 l0_ikind, zet0, 0, 0, 0.0_dp, 0, &
230 ra, [0.0_dp, 0.0_dp, 0.0_dp], 1.0_dp, pab, 0, 0, &
231 rs_grid, ga_gb_function=grid_func_ab, radius=rpgf0, &
232 use_subpatch=.true., subpatch_pattern=0)
233
234 END DO ! j
235
236 END DO ! ikind
237
238 IF (ASSOCIATED(cores)) THEN
239 DEALLOCATE (cores)
240 END IF
241
242 DEALLOCATE (pab)
243
244 IF (igrid /= auxbas_grid) THEN
245 CALL transfer_rs2pw(rs_grid, coeff_rspace)
246 CALL pw_zero(rho0_s_gs)
247 CALL pw_transfer(coeff_rspace, coeff_gspace)
248 CALL pw_axpy(coeff_gspace, rho0_s_gs)
249
250 tot_rs_int = pw_integrate_function(coeff_rspace, isign=-1)
251
252 CALL pw_pool%give_back_pw(coeff_rspace)
253 CALL pw_pool%give_back_pw(coeff_gspace)
254 ELSE
255 IF (ASSOCIATED(rs_grid%desc%pw, rho0_s_rs%pw_grid)) THEN
256 CALL transfer_rs2pw(rs_grid, rho0_s_rs)
257 tot_rs_int = pw_integrate_function(rho0_s_rs, isign=-1)
258 ELSE
259 ! Custom pools may use a distinct grid descriptor at the same level.
260 CALL pw_pool%create_pw(coeff_rspace)
261 CALL transfer_rs2pw(rs_grid, coeff_rspace)
262 tot_rs_int = pw_integrate_function(coeff_rspace, isign=-1)
263 CALL pw_transfer(coeff_rspace, rho0_s_rs)
264 CALL pw_pool%give_back_pw(coeff_rspace)
265 END IF
266
267 CALL pw_zero(rho0_s_gs)
268 CALL pw_transfer(rho0_s_rs, rho0_s_gs)
269 END IF
270 CALL timestop(handle)
271
272 END SUBROUTINE put_rho0_on_grid
273
274! **************************************************************************************************
275!> \brief ...
276!> \param pw_env ...
277!> \param rho0_mpole ...
278! **************************************************************************************************
279 SUBROUTINE rho0_s_grid_create(pw_env, rho0_mpole)
280
281 TYPE(pw_env_type), POINTER :: pw_env
282 TYPE(rho0_mpole_type), POINTER :: rho0_mpole
283
284 CHARACTER(LEN=*), PARAMETER :: routinen = 'rho0_s_grid_create'
285
286 INTEGER :: handle
287 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
288
289 CALL timeset(routinen, handle)
290
291 cpassert(ASSOCIATED(pw_env))
292
293 NULLIFY (auxbas_pw_pool)
294 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
295 cpassert(ASSOCIATED(auxbas_pw_pool))
296
297 ! reallocate rho0 on the global grid in real and reciprocal space
298 cpassert(ASSOCIATED(rho0_mpole))
299
300 ! rho0 density in real space
301 IF (ASSOCIATED(rho0_mpole%rho0_s_rs)) THEN
302 CALL rho0_mpole%rho0_s_rs%release()
303 ELSE
304 ALLOCATE (rho0_mpole%rho0_s_rs)
305 END IF
306 CALL auxbas_pw_pool%create_pw(rho0_mpole%rho0_s_rs)
307
308 ! rho0 density in reciprocal space
309 IF (ASSOCIATED(rho0_mpole%rho0_s_gs)) THEN
310 CALL rho0_mpole%rho0_s_gs%release()
311 ELSE
312 ALLOCATE (rho0_mpole%rho0_s_gs)
313 END IF
314 CALL auxbas_pw_pool%create_pw(rho0_mpole%rho0_s_gs)
315
316 ! Find the grid level suitable for rho0_soft
317 rho0_mpole%igrid_zet0_s = gaussian_gridlevel(pw_env%gridlevel_info, 2.0_dp*rho0_mpole%zet0_h)
318
319 CALL timestop(handle)
320
321 IF (rho0_mpole%do_cneo) THEN
322 CALL rhoz_cneo_s_grid_create(pw_env, rho0_mpole)
323 END IF
324
325 END SUBROUTINE rho0_s_grid_create
326
327! **************************************************************************************************
328!> \brief ...
329!> \param qs_env ...
330!> \param v_rspace ...
331!> \param para_env ...
332!> \param calculate_forces ...
333!> \param local_rho_set ...
334!> \param local_rho_set_2nd ...
335!> \param atener ...
336!> \param kforce ...
337!> \param my_pools ...
338!> \param my_rs_descs ...
339! **************************************************************************************************
340 SUBROUTINE integrate_vhg0_rspace(qs_env, v_rspace, para_env, calculate_forces, local_rho_set, &
341 local_rho_set_2nd, atener, kforce, my_pools, my_rs_descs)
342
343 TYPE(qs_environment_type), POINTER :: qs_env
344 TYPE(pw_r3d_rs_type), INTENT(IN) :: v_rspace
345 TYPE(mp_para_env_type), POINTER :: para_env
346 LOGICAL, INTENT(IN) :: calculate_forces
347 TYPE(local_rho_type), OPTIONAL, POINTER :: local_rho_set, local_rho_set_2nd
348 REAL(kind=dp), DIMENSION(:), OPTIONAL :: atener
349 REAL(kind=dp), INTENT(IN), OPTIONAL :: kforce
350 TYPE(pw_pool_p_type), DIMENSION(:), OPTIONAL, &
351 POINTER :: my_pools
352 TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
353 OPTIONAL, POINTER :: my_rs_descs
354
355 CHARACTER(LEN=*), PARAMETER :: routinen = 'integrate_vhg0_rspace'
356
357 INTEGER :: auxbas_grid, bo(2), handle, i, iat, iatom, ic, ico, igrid, ii, ikind, is, iso, &
358 ispin, j, l0_ikind, lmax0, lshell, lx, ly, lz, maxso, maxso_nuc, mepos, n_iso, n_iso_nuc, &
359 nat, nch_max, nset, nset_nuc, nso_ik, nsotot, nsotot_nuc, nspins, num_pe
360 INTEGER, DIMENSION(:), POINTER :: atom_list
361 LOGICAL :: direct_transfer, grid_distributed, &
362 paw_atom, use_virial
363 REAL(kind=dp) :: eps_rho_rspace, force_tmp(3), fscale, &
364 ra(3), rpgf0, zet0
365 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: hab_sph_all
366 REAL(kind=dp), DIMENSION(3, 3) :: my_virial_a, my_virial_b
367 REAL(kind=dp), DIMENSION(:), POINTER :: hab_sph, norm_l, qlm
368 REAL(kind=dp), DIMENSION(:, :), POINTER :: hab, hdab_sph, intloc, intloc_nuc, pab
369 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: a_hdab_sph, hdab, qlm_gg
370 REAL(kind=dp), DIMENSION(:, :, :, :), POINTER :: a_hdab
371 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
372 TYPE(cell_type), POINTER :: cell
373 TYPE(cneo_potential_type), POINTER :: cneo_potential
374 TYPE(dft_control_type), POINTER :: dft_control
375 TYPE(gto_basis_set_type), POINTER :: basis_1c_set, nuc_basis_set
376 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
377 TYPE(pw_c1d_gs_type) :: coeff_gaux, coeff_gspace
378 TYPE(pw_env_type), POINTER :: pw_env
379 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
380 TYPE(pw_pool_type), POINTER :: pw_aux, pw_pool
381 TYPE(pw_r3d_rs_type) :: coeff_rspace
382 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
383 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
384 TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
385 POINTER :: rs_descs
386 TYPE(realspace_grid_desc_type), POINTER :: rs_desc
387 TYPE(realspace_grid_type) :: rs_v
388 TYPE(rho0_mpole_type), POINTER :: rho0_mpole
389 TYPE(rho_atom_coeff), DIMENSION(:), POINTER :: int_local_h, int_local_s
390 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
391 TYPE(rho_atom_type), POINTER :: rho_atom
392 TYPE(rhoz_cneo_type), DIMENSION(:), POINTER :: rhoz_cneo_set
393 TYPE(rhoz_cneo_type), POINTER :: rhoz_cneo
394 TYPE(virial_type), POINTER :: virial
395
396 CALL timeset(routinen, handle)
397
398 ! In case of the external density computed forces probably also
399 ! need to be stored outside qs_env. We can then remove the
400 ! attribute 'OPTIONAL' from the argument 'local_rho_set'.
401
402 ! CPASSERT(.NOT. (calculate_forces .AND. PRESENT(local_rho_set)))
403! IF (calculate_forces .AND. PRESENT(local_rho_set)) THEN
404! CPWARN("Forces and External Density!")
405! END IF
406
407 NULLIFY (atomic_kind_set, qs_kind_set, dft_control, particle_set)
408 NULLIFY (cell, force, pw_env, rho0_mpole, rho_atom_set, rhoz_cneo_set)
409
410 CALL get_qs_env(qs_env=qs_env, &
411 atomic_kind_set=atomic_kind_set, &
412 qs_kind_set=qs_kind_set, &
413 cell=cell, &
414 dft_control=dft_control, &
415 force=force, pw_env=pw_env, &
416 rho0_mpole=rho0_mpole, &
417 rho_atom_set=rho_atom_set, &
418 rhoz_cneo_set=rhoz_cneo_set, &
419 particle_set=particle_set, &
420 virial=virial)
421
422 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
423
424 nspins = dft_control%nspins
425
426 ! The aim of the following code was to return immediately if the subroutine
427 ! was called for triplet excited states in spin-restricted case. This check
428 ! is also performed before invocation of this subroutine. It should be save
429 ! to remove the optional argument 'do_triplet' from the subroutine interface.
430 !my_tddft = PRESENT(local_rho_set)
431 !IF (my_tddft) THEN
432 ! IF (PRESENT(do_triplet)) THEN
433 ! IF (nspins == 1 .AND. do_triplet) RETURN
434 ! ELSE
435 ! IF (nspins == 1 .AND. dft_control%tddfpt_control%res_etype /= tddfpt_singlet) RETURN
436 ! END IF
437 !END IF
438
439 IF (PRESENT(local_rho_set)) THEN
440 CALL get_local_rho(local_rho_set, rho0_mpole=rho0_mpole, rho_atom_set=rho_atom_set, &
441 rhoz_cneo_set=rhoz_cneo_set)
442 END IF
443 ! Q from rho0_mpole of local_rho_set
444 ! for TDDFT forces we need mixed potential / integral space
445 ! potential stored on local_rho_set_2nd
446 IF (PRESENT(local_rho_set_2nd)) THEN
447 CALL get_local_rho(local_rho_set_2nd, rho_atom_set=rho_atom_set)
448 END IF
449 CALL get_rho0_mpole(rho0_mpole=rho0_mpole, lmax_0=lmax0, &
450 zet0_h=zet0, igrid_zet0_s=igrid, &
451 norm_g0l_h=norm_l)
452
453 ! Setup of the potential on the multigrids
454 NULLIFY (rs_descs, pw_pools)
455 cpassert(ASSOCIATED(pw_env))
456 CALL pw_env_get(pw_env, rs_descs=rs_descs, pw_pools=pw_pools)
457
458 ! Assign from pw_env
459 auxbas_grid = pw_env%auxbas_grid
460
461 ! IF present, overwrite qs grid for new pool
462 ! Get the potential on the right grid
463 IF (PRESENT(my_pools)) THEN
464 rs_desc => my_rs_descs(igrid)%rs_desc
465 pw_pool => my_pools(igrid)%pool
466 ELSE
467 rs_desc => rs_descs(igrid)%rs_desc
468 pw_pool => pw_pools(igrid)%pool
469 END IF
470
471 direct_transfer = igrid == auxbas_grid .AND. .NOT. pw_pool%pw_grid%spherical .AND. &
472 ASSOCIATED(rs_desc%pw, v_rspace%pw_grid)
473 IF (.NOT. direct_transfer) THEN
474 CALL pw_pool%create_pw(coeff_rspace)
475 IF (igrid /= auxbas_grid .OR. pw_pool%pw_grid%spherical) THEN
476 CALL pw_pool%create_pw(coeff_gspace)
477 IF (igrid /= auxbas_grid) THEN
478 pw_aux => pw_pools(auxbas_grid)%pool
479 CALL pw_aux%create_pw(coeff_gaux)
480 CALL pw_transfer(v_rspace, coeff_gaux)
481 CALL pw_copy(coeff_gaux, coeff_gspace)
482 CALL pw_aux%give_back_pw(coeff_gaux)
483 ELSE
484 ! Preserve the reciprocal-space projection on spherical grids.
485 CALL pw_transfer(v_rspace, coeff_gspace)
486 END IF
487 CALL pw_transfer(coeff_gspace, coeff_rspace)
488 CALL pw_pool%give_back_pw(coeff_gspace)
489 IF (igrid /= auxbas_grid) THEN
490 fscale = coeff_rspace%pw_grid%dvol/pw_aux%pw_grid%dvol
491 CALL pw_scale(coeff_rspace, fscale)
492 END IF
493 ELSE
494 CALL pw_copy(v_rspace, coeff_rspace)
495 END IF
496 END IF
497
498 ! Setup the rs grid at level igrid
499 CALL rs_grid_create(rs_v, rs_desc)
500 CALL rs_grid_zero(rs_v)
501 IF (direct_transfer) THEN
502 ! The potential is already on the target grid; no PW copy is needed.
503 CALL transfer_pw2rs(rs_v, v_rspace)
504 ELSE
505 CALL transfer_pw2rs(rs_v, coeff_rspace)
506 CALL pw_pool%give_back_pw(coeff_rspace)
507 END IF
508
509 ! Now the potential is on the right grid => integration
510
511 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
512
513 ! Allocate work storage
514
515 NULLIFY (hab, hab_sph, hdab, hdab_sph, pab, a_hdab, a_hdab_sph)
516 nch_max = ncoset(lmax0)
517 CALL reallocate(hab, 1, nch_max, 1, 1)
518 CALL reallocate(hab_sph, 1, nch_max)
519 CALL reallocate(hdab, 1, 3, 1, nch_max, 1, 1)
520 CALL reallocate(hdab_sph, 1, 3, 1, nch_max)
521 CALL reallocate(a_hdab, 1, 3, 1, 3, 1, nch_max, 1, 1)
522 CALL reallocate(a_hdab_sph, 1, 3, 1, 3, 1, nch_max)
523 CALL reallocate(pab, 1, nch_max, 1, 1)
524
525 grid_distributed = rs_v%desc%distributed
526
527 fscale = 1.0_dp
528 IF (PRESENT(kforce)) THEN
529 fscale = kforce
530 END IF
531
532 DO ikind = 1, SIZE(atomic_kind_set, 1)
533 NULLIFY (basis_1c_set, atom_list, cneo_potential)
534 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom_list, natom=nat)
535 CALL get_qs_kind(qs_kind_set(ikind), &
536 basis_set=basis_1c_set, basis_type="GAPW_1C", &
537 paw_atom=paw_atom, &
538 cneo_potential=cneo_potential)
539
540 IF (.NOT. paw_atom) cycle
541
542 NULLIFY (qlm_gg)
543 CALL get_rho0_mpole(rho0_mpole=rho0_mpole, ikind=ikind, &
544 l0_ikind=l0_ikind, qlm_gg=qlm_gg, & ! Qs different
545 rpgf0_s=rpgf0)
546
547 CALL get_gto_basis_set(gto_basis_set=basis_1c_set, &
548 maxso=maxso, nset=nset)
549
550 nsotot = maxso*nset
551 ALLOCATE (intloc(nsotot, nsotot))
552
553 ! Initialize the local KS integrals
554
555 pab = 1.0_dp
556 nso_ik = nsoset(l0_ikind)
557 ALLOCATE (hab_sph_all(nso_ik, nat))
558 hab_sph_all = 0.0_dp
559
560 NULLIFY (intloc_nuc)
561 nsotot_nuc = 0
562 IF (ASSOCIATED(cneo_potential)) THEN
563 NULLIFY (nuc_basis_set)
564 CALL get_qs_kind(qs_kind_set(ikind), &
565 basis_set=nuc_basis_set, &
566 basis_type="NUC")
567
568 CALL get_gto_basis_set(gto_basis_set=nuc_basis_set, &
569 maxso=maxso_nuc, nset=nset_nuc)
570 nsotot_nuc = maxso_nuc*nset_nuc
571 ALLOCATE (intloc_nuc(nsotot_nuc, nsotot_nuc))
572 END IF
573
574 num_pe = para_env%num_pe
575 mepos = para_env%mepos
576 DO j = 0, num_pe - 1
577 bo = get_limit(nat, num_pe, j)
578 IF (.NOT. grid_distributed .AND. j /= mepos) cycle
579
580 DO iat = bo(1), bo(2)
581 iatom = atom_list(iat)
582 ra(:) = pbc(particle_set(iatom)%r, cell)
583
584 NULLIFY (qlm)
585 CALL get_rho0_mpole(rho0_mpole=rho0_mpole, iat=iatom, qlm_tot=qlm)
586
587 hab = 0.0_dp
588 hdab = 0.0_dp
589 IF (use_virial) THEN
590 my_virial_a = 0.0_dp
591 my_virial_b = 0.0_dp
592 a_hdab = 0.0_dp
593 END IF
594
596 l0_ikind, zet0, 0, 0, 0.0_dp, 0, &
597 ra, [0.0_dp, 0.0_dp, 0.0_dp], rs_v, &
598 hab, pab, o1=0, o2=0, &
599 radius=rpgf0, &
600 calculate_forces=calculate_forces, &
601 use_virial=use_virial, my_virial_a=my_virial_a, my_virial_b=my_virial_b, &
602 hdab=hdab, a_hdab=a_hdab, use_subpatch=.true., subpatch_pattern=0)
603
604 ! Convert from cartesian to spherical
605 DO lshell = 0, l0_ikind
606 DO is = 1, nso(lshell)
607 iso = is + nsoset(lshell - 1)
608 hab_sph(iso) = 0.0_dp
609 hdab_sph(1:3, iso) = 0.0_dp
610 a_hdab_sph(1:3, 1:3, iso) = 0.0_dp
611 DO ic = 1, nco(lshell)
612 ico = ic + ncoset(lshell - 1)
613 lx = indco(1, ico)
614 ly = indco(2, ico)
615 lz = indco(3, ico)
616 hab_sph(iso) = hab_sph(iso) + &
617 norm_l(lshell)* &
618 orbtramat(lshell)%slm(is, ic)* &
619 hab(ico, 1)
620 IF (calculate_forces) THEN
621 hdab_sph(1:3, iso) = hdab_sph(1:3, iso) + &
622 norm_l(lshell)* &
623 orbtramat(lshell)%slm(is, ic)* &
624 hdab(1:3, ico, 1)
625 END IF
626 IF (use_virial) THEN
627 DO ii = 1, 3
628 DO i = 1, 3
629 a_hdab_sph(i, ii, iso) = a_hdab_sph(i, ii, iso) + &
630 norm_l(lshell)* &
631 orbtramat(lshell)%slm(is, ic)* &
632 a_hdab(i, ii, ico, 1)
633 END DO
634 END DO
635 END IF
636
637 END DO ! ic
638 END DO ! is
639 END DO ! lshell
640
641 hab_sph_all(1:nso_ik, iat) = hab_sph(1:nso_ik)
642
643 IF (PRESENT(atener)) THEN
644 DO iso = 1, nsoset(l0_ikind)
645 atener(iatom) = atener(iatom) + 0.5_dp*qlm(iso)*hab_sph(iso)
646 END DO
647 END IF
648
649 IF (calculate_forces) THEN
650 force_tmp(1:3) = 0.0_dp
651 DO iso = 1, nsoset(l0_ikind)
652 force_tmp(1) = force_tmp(1) + qlm(iso)*hdab_sph(1, iso) ! Q here is from local_rho_set
653 force_tmp(2) = force_tmp(2) + qlm(iso)*hdab_sph(2, iso)
654 force_tmp(3) = force_tmp(3) + qlm(iso)*hdab_sph(3, iso)
655 END DO
656 force(ikind)%g0s_Vh_elec(1:3, iat) = force(ikind)%g0s_Vh_elec(1:3, iat) + fscale*force_tmp(1:3)
657 END IF
658 IF (use_virial) THEN
659 my_virial_a = 0.0_dp
660 DO iso = 1, nsoset(l0_ikind)
661 DO ii = 1, 3
662 DO i = 1, 3
663 ! Q from local_rho_set
664 virial%pv_gapw(i, ii) = virial%pv_gapw(i, ii) + fscale*qlm(iso)*a_hdab_sph(i, ii, iso)
665 virial%pv_virial(i, ii) = virial%pv_virial(i, ii) + fscale*qlm(iso)*a_hdab_sph(i, ii, iso)
666 END DO
667 END DO
668 END DO
669 END IF
670
671 END DO
672 END DO
673
674 IF (grid_distributed .AND. nat > 0) THEN
675 ! Sum multipole potential coefficients over all processors once per kind
676 CALL para_env%sum(hab_sph_all)
677 END IF
678
679 ! Qlm_gg is zero outside Gaunt selection rules (calculate_mpole_gau), so dense DGEMV is exact.
680 bo = get_limit(nat, num_pe, mepos)
681 n_iso = min(nso_ik, SIZE(qlm_gg, 3))
682 cpassert(nsotot > 0)
683 cpassert(n_iso > 0)
684 cpassert(is_contiguous(qlm_gg))
685 cpassert(SIZE(qlm_gg, 1) == nsotot)
686 cpassert(SIZE(qlm_gg, 2) == nsotot)
687 DO iat = bo(1), bo(2)
688 iatom = atom_list(iat)
689 CALL dgemv('N', nsotot*nsotot, n_iso, 1.0_dp, &
690 qlm_gg(1, 1, 1), nsotot*nsotot, &
691 hab_sph_all(1, iat), 1, 0.0_dp, intloc(1, 1), 1)
692
693 rho_atom => rho_atom_set(iatom)
694 CALL get_rho_atom(rho_atom=rho_atom, ga_vlocal_gb_h=int_local_h, ga_vlocal_gb_s=int_local_s)
695 DO ispin = 1, nspins
696 int_local_h(ispin)%r_coef = int_local_h(ispin)%r_coef + intloc
697 int_local_s(ispin)%r_coef = int_local_s(ispin)%r_coef + intloc
698 END DO
699
700 IF (ASSOCIATED(cneo_potential)) THEN
701 n_iso_nuc = min(nso_ik, SIZE(cneo_potential%Qlm_gg, 3))
702 cpassert(nsotot_nuc > 0)
703 cpassert(n_iso_nuc > 0)
704 cpassert(is_contiguous(cneo_potential%Qlm_gg))
705 cpassert(SIZE(cneo_potential%Qlm_gg, 1) == nsotot_nuc)
706 cpassert(SIZE(cneo_potential%Qlm_gg, 2) == nsotot_nuc)
707 CALL dgemv('N', nsotot_nuc*nsotot_nuc, n_iso_nuc, -cneo_potential%zeff, &
708 cneo_potential%Qlm_gg(1, 1, 1), nsotot_nuc*nsotot_nuc, &
709 hab_sph_all(1, iat), 1, 0.0_dp, intloc_nuc(1, 1), 1)
710 rhoz_cneo => rhoz_cneo_set(iatom)
711 rhoz_cneo%ga_Vlocal_gb_h = rhoz_cneo%ga_Vlocal_gb_h + intloc_nuc
712 rhoz_cneo%ga_Vlocal_gb_s = rhoz_cneo%ga_Vlocal_gb_s + intloc_nuc
713 END IF
714 END DO
715
716 DEALLOCATE (hab_sph_all, intloc)
717 IF (ASSOCIATED(intloc_nuc)) DEALLOCATE (intloc_nuc)
718
719 END DO ! ikind
720
721 CALL rs_grid_release(rs_v)
722
723 DEALLOCATE (hab, hdab, hab_sph, hdab_sph, pab, a_hdab, a_hdab_sph)
724
725 CALL timestop(handle)
726
727 IF (rho0_mpole%do_cneo) THEN
728 IF (PRESENT(kforce)) THEN
729 CALL integrate_vhgg_rspace(qs_env, v_rspace, para_env, calculate_forces, &
730 rhoz_cneo_set, kforce)
731 ELSE
732 CALL integrate_vhgg_rspace(qs_env, v_rspace, para_env, calculate_forces, &
733 rhoz_cneo_set)
734 END IF
735 END IF
736
737 END SUBROUTINE integrate_vhg0_rspace
738
739END MODULE qs_rho0_ggrid
static int modulo(int a, int m)
Equivalent of Fortran's MODULO which always returns a positive number. https://gcc....
Definition fft_utils.h:60
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, ccon)
...
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:27
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:274
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:116
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 ...
CNEO soft nuclear densities on the global grid (see J. Chem. Theory Comput. 2025, 21,...
subroutine, public integrate_vhgg_rspace(qs_env, v_rspace, para_env, calculate_forces, rhoz_cneo_set, kforce)
...
subroutine, public rhoz_cneo_s_grid_create(pw_env, rho0_mpole)
...
Types used by CNEO-DFT (see J. Chem. Theory Comput. 2025, 21, 16, 7865–7877).
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, mimic, 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, sab_cneo, 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, matrix_vhxc, 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, xcint_weights, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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, do_rixs, tb_tblite, matrix_metric, matrix_metric_kp)
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, cneo_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, hund_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, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, 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, rhoz_cneo_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, rhoz_cneo_s_rs, rhoz_cneo_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:60
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.