(git:31876b5)
Loading...
Searching...
No Matches
accint_weights_forces.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
8! **************************************************************************************************
9!> \brief
10!> \author JGH (01.2026)
11! **************************************************************************************************
16 USE cell_types, ONLY: cell_type,&
17 pbc
21 USE input_constants, ONLY: sic_none,&
25 USE kinds, ONLY: dp
28 USE pw_env_types, ONLY: pw_env_get,&
30 USE pw_grids, ONLY: pw_grid_compare
31 USE pw_methods, ONLY: pw_axpy,&
33 pw_scale,&
36 USE pw_pool_types, ONLY: pw_pool_p_type,&
38 USE pw_types, ONLY: pw_c1d_gs_type,&
43 USE qs_fxc, ONLY: qs_fxc_analytic
44 USE qs_ks_types, ONLY: get_ks_env,&
46 USE qs_rho_types, ONLY: qs_rho_create,&
54 USE virial_types, ONLY: virial_type
55 USE xc, ONLY: xc_exc_pw_create,&
57#include "./base/base_uses.f90"
58
59 IMPLICIT NONE
60
61 PRIVATE
62
63 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .false.
64
65 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'accint_weights_forces'
66
67 PUBLIC :: accint_weight_force
68
69CONTAINS
70
71! **************************************************************************************************
72!> \brief ...
73!> \param qs_env ...
74!> \param rho ...
75!> \param rho1 ...
76!> \param order ...
77!> \param xc_section ...
78!> \param triplet ...
79!> \param force_scale ...
80! **************************************************************************************************
81 SUBROUTINE accint_weight_force(qs_env, rho, rho1, order, xc_section, triplet, force_scale)
82 TYPE(qs_environment_type), POINTER :: qs_env
83 TYPE(qs_rho_type), POINTER :: rho, rho1
84 INTEGER, INTENT(IN) :: order
85 TYPE(section_vals_type), POINTER :: xc_section
86 LOGICAL, INTENT(IN), OPTIONAL :: triplet
87 REAL(kind=dp), INTENT(IN), OPTIONAL :: force_scale
88
89 CHARACTER(len=*), PARAMETER :: routinen = 'accint_weight_force'
90
91 INTEGER :: atom_a, handle, iatom, ikind, natom, &
92 natom_of_kind, nkind, output_unit
93 INTEGER, DIMENSION(:), POINTER :: atom_list
94 LOGICAL :: lr_triplet, native_grid_diagnostics, &
95 native_skala_grid, uf_grid, use_virial
96 REAL(kind=dp) :: my_force_scale
97 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: calpha, cvalue
98 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: aforce
99 REAL(kind=dp), DIMENSION(3, 3) :: avirial
100 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
101 TYPE(dft_control_type), POINTER :: dft_control
102 TYPE(pw_env_type), POINTER :: pw_env
103 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool, xc_pw_pool
104 TYPE(pw_r3d_rs_type) :: e_force_rspace, e_rspace
105 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
106 TYPE(qs_ks_env_type), POINTER :: ks_env
107 TYPE(virial_type), POINTER :: virial
108
109 CALL timeset(routinen, handle)
110
111 CALL get_qs_env(qs_env, dft_control=dft_control)
112
113 IF (dft_control%qs_control%gapw_control%accurate_xcint) THEN
114
115 CALL get_qs_env(qs_env=qs_env, force=force, virial=virial)
116 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
117
118 CALL get_qs_env(qs_env, natom=natom, nkind=nkind)
119 ALLOCATE (aforce(3, natom))
120 ALLOCATE (calpha(nkind), cvalue(nkind))
121 cvalue = 1.0_dp
122 calpha(1:nkind) = dft_control%qs_control%gapw_control%aw(1:nkind)
123
124 CALL get_qs_env(qs_env, ks_env=ks_env, pw_env=pw_env)
125 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, xc_pw_pool=xc_pw_pool)
126 uf_grid = .NOT. pw_grid_compare(auxbas_pw_pool%pw_grid, xc_pw_pool%pw_grid)
127 IF (uf_grid) THEN
128 CALL xc_pw_pool%create_pw(e_rspace)
129 ELSE
130 CALL auxbas_pw_pool%create_pw(e_rspace)
131 END IF
132
133 lr_triplet = .false.
134 IF (PRESENT(triplet)) lr_triplet = triplet
135 my_force_scale = 1.0_dp
136 IF (PRESENT(force_scale)) my_force_scale = force_scale
137
138 CALL xc_density(ks_env, rho, rho1, order, xc_section, lr_triplet, e_rspace)
139
140 IF (uf_grid) THEN
141 CALL auxbas_pw_pool%create_pw(e_force_rspace)
142 block
143 TYPE(pw_c1d_gs_type) :: e_g_aux, e_g_xc
144 CALL xc_pw_pool%create_pw(e_g_xc)
145 CALL auxbas_pw_pool%create_pw(e_g_aux)
146 CALL pw_transfer(e_rspace, e_g_xc)
147 CALL pw_transfer(e_g_xc, e_g_aux)
148 CALL pw_transfer(e_g_aux, e_force_rspace)
149 CALL auxbas_pw_pool%give_back_pw(e_g_aux)
150 CALL xc_pw_pool%give_back_pw(e_g_xc)
151 END block
152 CALL pw_scale(e_force_rspace, e_force_rspace%pw_grid%dvol)
153 CALL gauss_grid_force(e_force_rspace, qs_env, calpha, cvalue, aforce, avirial)
154 CALL auxbas_pw_pool%give_back_pw(e_force_rspace)
155 ELSE
156 CALL pw_scale(e_rspace, e_rspace%pw_grid%dvol)
157 CALL gauss_grid_force(e_rspace, qs_env, calpha, cvalue, aforce, avirial)
158 END IF
159
160 IF (uf_grid) THEN
161 CALL xc_pw_pool%give_back_pw(e_rspace)
162 ELSE
163 CALL auxbas_pw_pool%give_back_pw(e_rspace)
164 END IF
165
166 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
167 native_skala_grid = xc_section_uses_native_skala_grid(xc_section)
168 native_grid_diagnostics = .false.
169 IF (native_skala_grid) THEN
170 CALL section_vals_val_get(xc_section, "XC_FUNCTIONAL%GAUXC%NATIVE_GRID_DIAGNOSTICS", &
171 l_val=native_grid_diagnostics)
172 END IF
173 DO ikind = 1, nkind
174 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom_of_kind, atom_list=atom_list)
175 DO iatom = 1, natom_of_kind
176 atom_a = atom_list(iatom)
177 IF (native_grid_diagnostics) THEN
178 output_unit = cp_logger_get_default_io_unit()
179 IF (output_unit > 0) THEN
180 WRITE (unit=output_unit, fmt="(T2,A,1X,I0,3(1X,ES20.12))") &
181 "SKALA_GPW| Accurate-XCINT atom force", atom_a, my_force_scale*aforce(:, atom_a)
182 END IF
183 END IF
184 force(ikind)%rho_elec(1:3, iatom) = &
185 force(ikind)%rho_elec(1:3, iatom) + my_force_scale*aforce(1:3, atom_a)
186 END DO
187 END DO
188 IF (use_virial) THEN
189 virial%pv_exc = virial%pv_exc + my_force_scale*avirial
190 virial%pv_virial = virial%pv_virial + my_force_scale*avirial
191 END IF
192
193 DEALLOCATE (aforce, calpha, cvalue)
194
195 END IF
196
197 CALL timestop(handle)
198
199 END SUBROUTINE accint_weight_force
200
201! **************************************************************************************************
202!> \brief computes the forces/virial due to atomic centered Gaussian functions
203!> \param e_rspace Energy density
204!> \param qs_env ...
205!> \param calpha ...
206!> \param cvalue ...
207!> \param aforce ...
208!> \param avirial ...
209! **************************************************************************************************
210 SUBROUTINE gauss_grid_force(e_rspace, qs_env, calpha, cvalue, aforce, avirial)
211 TYPE(pw_r3d_rs_type), INTENT(IN) :: e_rspace
212 TYPE(qs_environment_type), POINTER :: qs_env
213 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: calpha, cvalue
214 REAL(kind=dp), DIMENSION(:, :), INTENT(OUT) :: aforce
215 REAL(kind=dp), DIMENSION(3, 3), INTENT(OUT) :: avirial
216
217 CHARACTER(len=*), PARAMETER :: routinen = 'gauss_grid_force'
218
219 INTEGER :: atom_a, handle, iatom, igrid, ikind, j, &
220 natom_of_kind, npme
221 INTEGER, DIMENSION(:), POINTER :: atom_list, cores
222 LOGICAL :: use_virial
223 REAL(kind=dp) :: alpha, eps_rho_rspace, radius
224 REAL(kind=dp), DIMENSION(3) :: force_a, force_b, ra
225 REAL(kind=dp), DIMENSION(3, 3) :: my_virial_a, my_virial_b
226 REAL(kind=dp), DIMENSION(:, :), POINTER :: hab, pab
227 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
228 TYPE(cell_type), POINTER :: cell
229 TYPE(dft_control_type), POINTER :: dft_control
230 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
231 TYPE(pw_env_type), POINTER :: pw_env
232 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
233 TYPE(realspace_grid_type), DIMENSION(:), POINTER :: rs_grids
234 TYPE(realspace_grid_type), POINTER :: rs_v
235
236 CALL timeset(routinen, handle)
237
238 ALLOCATE (cores(1))
239 ALLOCATE (hab(1, 1))
240 ALLOCATE (pab(1, 1))
241
242 NULLIFY (pw_pools, rs_grids, rs_v)
243
244 CALL get_qs_env(qs_env, pw_env=pw_env)
245 CALL pw_env_get(pw_env, pw_pools=pw_pools, rs_grids=rs_grids)
246 DO igrid = 1, SIZE(pw_pools)
247 IF (pw_grid_compare(e_rspace%pw_grid, pw_pools(igrid)%pool%pw_grid)) THEN
248 rs_v => rs_grids(igrid)
249 EXIT
250 END IF
251 END DO
252 IF (.NOT. ASSOCIATED(rs_v)) THEN
253 cpabort("No realspace grid for Accurate-XCINT weight force")
254 END IF
255
256 CALL transfer_pw2rs(rs_v, e_rspace)
257
258 CALL get_qs_env(qs_env, &
259 atomic_kind_set=atomic_kind_set, &
260 cell=cell, &
261 dft_control=dft_control, &
262 particle_set=particle_set)
263
264 use_virial = .true.
265 avirial = 0.0_dp
266 aforce = 0.0_dp
267
268 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
269
270 DO ikind = 1, SIZE(atomic_kind_set)
271
272 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom_of_kind, atom_list=atom_list)
273
274 alpha = calpha(ikind)
275 pab(1, 1) = -cvalue(ikind)
276 IF (alpha == 0.0_dp .OR. pab(1, 1) == 0.0_dp) cycle
277
278 CALL reallocate(cores, 1, natom_of_kind)
279 npme = 0
280 cores = 0
281
282 DO iatom = 1, natom_of_kind
283 atom_a = atom_list(iatom)
284 ra(:) = pbc(particle_set(atom_a)%r, cell)
285 IF (rs_v%desc%parallel .AND. .NOT. rs_v%desc%distributed) THEN
286 ! replicated realspace grid, split the atoms up between procs
287 IF (modulo(iatom, rs_v%desc%group_size) == rs_v%desc%my_pos) THEN
288 npme = npme + 1
289 cores(npme) = iatom
290 END IF
291 ELSE
292 npme = npme + 1
293 cores(npme) = iatom
294 END IF
295 END DO
296
297 DO j = 1, npme
298
299 iatom = cores(j)
300 atom_a = atom_list(iatom)
301 ra(:) = pbc(particle_set(atom_a)%r, cell)
302 hab(1, 1) = 0.0_dp
303 force_a(:) = 0.0_dp
304 force_b(:) = 0.0_dp
305 my_virial_a = 0.0_dp
306 my_virial_b = 0.0_dp
307
308 radius = exp_radius_very_extended(la_min=0, la_max=0, lb_min=0, lb_max=0, &
309 ra=ra, rb=ra, rp=ra, &
310 zetp=alpha, eps=eps_rho_rspace, &
311 pab=pab, o1=0, o2=0, &
312 prefactor=1.0_dp, cutoff=1.0_dp)
313
314 CALL integrate_pgf_product(0, alpha, 0, &
315 0, 0.0_dp, 0, ra, [0.0_dp, 0.0_dp, 0.0_dp], &
316 rs_v, hab, pab=pab, o1=0, o2=0, &
317 radius=radius, &
318 calculate_forces=.true., force_a=force_a, &
319 force_b=force_b, use_virial=use_virial, my_virial_a=my_virial_a, &
320 my_virial_b=my_virial_b, use_subpatch=.true., subpatch_pattern=0)
321
322 aforce(1:3, atom_a) = aforce(1:3, atom_a) + force_a(1:3)
323 avirial = avirial + my_virial_a
324
325 END DO
326
327 END DO
328
329 DEALLOCATE (hab, pab, cores)
330
331 CALL timestop(handle)
332
333 END SUBROUTINE gauss_grid_force
334
335! **************************************************************************************************
336!> \brief calculates the XC density:
337!> order=0: exc will contain the xc energy density E_xc(r)
338!> order=1: exc will contain V_xc(r) * rho1(r)
339!> order=2: exc will contain F_xc(r) * rho1(r) * rho1(r)
340!> \param ks_env to get all the needed things
341!> \param rho_struct density
342!> \param rho1_struct response density
343!> \param order requested derivative order
344!> \param xc_section ...
345!> \param triplet ...
346!> \param exc ...
347!> \author JGH
348! **************************************************************************************************
349 SUBROUTINE xc_density(ks_env, rho_struct, rho1_struct, order, xc_section, triplet, exc)
350
351 TYPE(qs_ks_env_type), POINTER :: ks_env
352 TYPE(qs_rho_type), POINTER :: rho_struct, rho1_struct
353 INTEGER, INTENT(IN) :: order
354 TYPE(section_vals_type), POINTER :: xc_section
355 LOGICAL, INTENT(IN) :: triplet
356 TYPE(pw_r3d_rs_type) :: exc
357
358 CHARACTER(len=*), PARAMETER :: routinen = 'xc_density'
359
360 INTEGER :: handle, ispin, myfun, nspins
361 LOGICAL :: native_skala_grid, rho1_g_valid, rho1_tau_g_valid, rho1_tau_valid, rho_g_valid, &
362 rho_tau_g_valid, rho_tau_valid, uf_grid
363 REAL(kind=dp) :: excint, factor
364 REAL(kind=dp), DIMENSION(3, 3) :: vdum
365 TYPE(cell_type), POINTER :: cell
366 TYPE(dft_control_type), POINTER :: dft_control
367 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
368 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho1_g, rho1_g_base, rho_g, rho_g_base, &
369 tau1_g, tau1_g_base, tau_g, tau_g_base
370 TYPE(pw_c1d_gs_type), POINTER :: rho_nlcc_g, rho_nlcc_g_use, rho_nlcc_g_xc
371 TYPE(pw_env_type), POINTER :: pw_env
372 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool, xc_pw_pool
373 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho1_r, rho1_r_base, rho_r, rho_r_base, &
374 tau1_r, tau1_r_base, tau_r, &
375 tau_r_base, vxc_rho, vxc_tau
376 TYPE(pw_r3d_rs_type), POINTER :: rho_nlcc, rho_nlcc_use, rho_nlcc_xc, &
377 weights
378 TYPE(qs_rho_type), POINTER :: rho_fxc
379
380 CALL timeset(routinen, handle)
381
382 ! we always get true exc (not integration weighted)
383 NULLIFY (rho1_g, rho1_g_base, rho1_r, rho1_r_base, rho_fxc, tau1_g, tau1_g_base)
384 NULLIFY (rho_g, rho_g_base, rho_r, rho_r_base, tau_g, tau_g_base, tau_r, tau_r_base, &
385 tau1_r, tau1_r_base)
386 NULLIFY (particle_set, rho_nlcc_use, rho_nlcc_xc, rho_nlcc_g_use, rho_nlcc_g_xc, weights)
387
388 CALL get_ks_env(ks_env, &
389 dft_control=dft_control, &
390 pw_env=pw_env, &
391 cell=cell, &
392 particle_set=particle_set, &
393 rho_nlcc=rho_nlcc, &
394 rho_nlcc_g=rho_nlcc_g)
395
396 CALL qs_rho_get(rho_struct, rho_r=rho_r_base, rho_g=rho_g_base, tau_r=tau_r_base, &
397 tau_g=tau_g_base, rho_g_valid=rho_g_valid, tau_g_valid=rho_tau_g_valid, &
398 tau_r_valid=rho_tau_valid)
399 rho_r => rho_r_base
400 rho_g => rho_g_base
401 tau_r => tau_r_base
402 tau_g => tau_g_base
403
404 nspins = dft_control%nspins
405
406 CALL section_vals_val_get(xc_section, "XC_FUNCTIONAL%_SECTION_PARAMETERS_", i_val=myfun)
407 native_skala_grid = xc_section_uses_native_skala_grid(xc_section)
408
409 CALL pw_env_get(pw_env, xc_pw_pool=xc_pw_pool, auxbas_pw_pool=auxbas_pw_pool)
410 uf_grid = .NOT. pw_grid_compare(auxbas_pw_pool%pw_grid, xc_pw_pool%pw_grid)
411 IF (uf_grid) THEN
412 NULLIFY (rho_r, rho_g, tau_r, tau_g)
413 IF (rho_g_valid) THEN
414 CALL create_density_on_pool(xc_pw_pool, rho_g_base, rho_r, rho_g)
415 ELSEIF (ASSOCIATED(rho_r_base)) THEN
416 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, rho_r_base, rho_r, rho_g)
417 ELSE
418 cpabort("Fine Grid in xc_density requires rho_r or rho_g")
419 END IF
420 IF (rho_tau_valid) THEN
421 IF (rho_tau_g_valid) THEN
422 CALL create_density_on_pool(xc_pw_pool, tau_g_base, tau_r, tau_g)
423 ELSEIF (ASSOCIATED(tau_r_base)) THEN
424 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, tau_r_base, tau_r, tau_g)
425 ELSE
426 cpabort("Fine Grid in xc_density requires tau_r or tau_g")
427 END IF
428 END IF
429 IF (ASSOCIATED(rho_nlcc)) THEN
430 ALLOCATE (rho_nlcc_g_xc, rho_nlcc_xc)
431 CALL xc_pw_pool%create_pw(rho_nlcc_g_xc)
432 CALL xc_pw_pool%create_pw(rho_nlcc_xc)
433 CALL pw_transfer(rho_nlcc_g, rho_nlcc_g_xc)
434 CALL pw_transfer(rho_nlcc_g_xc, rho_nlcc_xc)
435 rho_nlcc_use => rho_nlcc_xc
436 rho_nlcc_g_use => rho_nlcc_g_xc
437 END IF
438 END IF
439 IF (.NOT. ASSOCIATED(rho_nlcc_use)) THEN
440 rho_nlcc_use => rho_nlcc
441 rho_nlcc_g_use => rho_nlcc_g
442 END IF
443
444 CALL pw_zero(exc)
445
446 IF (myfun /= xc_none) THEN
447
448 cpassert(ASSOCIATED(rho_struct))
449 cpassert(dft_control%sic_method_id == sic_none)
450
451 ! add the nlcc densities
452 IF (ASSOCIATED(rho_nlcc_use) .AND. order <= 1) THEN
453 factor = 1.0_dp
454 DO ispin = 1, nspins
455 CALL pw_axpy(rho_nlcc_use, rho_r(ispin), factor)
456 CALL pw_axpy(rho_nlcc_g_use, rho_g(ispin), factor)
457 END DO
458 END IF
459
460 NULLIFY (vxc_rho, vxc_tau)
461 SELECT CASE (order)
462 CASE (0)
463 IF (native_skala_grid) THEN
464 CALL skala_gpw_exc_density(exc, rho_r, rho_g, tau_r, xc_section, weights, &
465 xc_pw_pool, particle_set, cell)
466 ELSE
467 ! we could reduce to energy only here
468 CALL xc_exc_pw_create(rho_r, rho_g, tau_r, xc_section, weights, xc_pw_pool, exc)
469 END IF
470 CASE (1)
471 IF (native_skala_grid) THEN
472 CALL cp_abort(__location__, &
473 "Native SKALA GAPW accurate-XCINT response forces are not implemented.")
474 END IF
475 CALL qs_rho_get(rho1_struct, rho_r=rho1_r_base, rho_g=rho1_g_base, tau_r=tau1_r_base, &
476 tau_g=tau1_g_base, rho_g_valid=rho1_g_valid, &
477 tau_g_valid=rho1_tau_g_valid, tau_r_valid=rho1_tau_valid)
478 rho1_r => rho1_r_base
479 tau1_g => tau1_g_base
480 tau1_r => tau1_r_base
481 IF (uf_grid) THEN
482 NULLIFY (rho1_r, rho1_g, tau1_r, tau1_g)
483 IF (rho1_g_valid) THEN
484 CALL create_density_on_pool(xc_pw_pool, rho1_g_base, rho1_r, rho1_g)
485 ELSEIF (ASSOCIATED(rho1_r_base)) THEN
486 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, rho1_r_base, rho1_r, rho1_g)
487 ELSE
488 cpabort("Fine Grid in xc_density requires rho1_r or rho1_g")
489 END IF
490 IF (rho1_tau_valid) THEN
491 IF (rho1_tau_g_valid) THEN
492 CALL create_density_on_pool(xc_pw_pool, tau1_g_base, tau1_r, tau1_g)
493 ELSEIF (ASSOCIATED(tau1_r_base)) THEN
494 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, tau1_r_base, tau1_r, tau1_g)
495 ELSE
496 cpabort("Fine Grid in xc_density requires tau1_r or tau1_g")
497 END IF
498 END IF
499 END IF
500 CALL xc_vxc_pw_create(vxc_rho=vxc_rho, vxc_tau=vxc_tau, rho_r=rho_r, &
501 rho_g=rho_g, tau=tau_r, exc=excint, &
502 xc_section=xc_section, &
503 weights=weights, pw_pool=xc_pw_pool, &
504 compute_virial=.false., &
505 virial_xc=vdum)
506 CASE (2)
507 IF (native_skala_grid) THEN
508 CALL cp_abort(__location__, &
509 "Native SKALA GAPW accurate-XCINT response forces are not implemented.")
510 END IF
511 CALL qs_rho_get(rho1_struct, rho_r=rho1_r_base, rho_g=rho1_g_base, tau_r=tau1_r_base, &
512 tau_g=tau1_g_base, rho_g_valid=rho1_g_valid, &
513 tau_g_valid=rho1_tau_g_valid, tau_r_valid=rho1_tau_valid)
514 rho1_r => rho1_r_base
515 tau1_g => tau1_g_base
516 tau1_r => tau1_r_base
517 IF (uf_grid) THEN
518 NULLIFY (rho1_r, rho1_g, tau1_r, tau1_g)
519 IF (rho1_g_valid) THEN
520 CALL create_density_on_pool(xc_pw_pool, rho1_g_base, rho1_r, rho1_g)
521 ELSEIF (ASSOCIATED(rho1_r_base)) THEN
522 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, rho1_r_base, rho1_r, rho1_g)
523 ELSE
524 cpabort("Fine Grid in xc_density requires rho1_r or rho1_g")
525 END IF
526 IF (rho1_tau_valid) THEN
527 IF (rho1_tau_g_valid) THEN
528 CALL create_density_on_pool(xc_pw_pool, tau1_g_base, tau1_r, tau1_g)
529 ELSEIF (ASSOCIATED(tau1_r_base)) THEN
530 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, tau1_r_base, tau1_r, tau1_g)
531 ELSE
532 cpabort("Fine Grid in xc_density requires tau1_r or tau1_g")
533 END IF
534 END IF
535 ALLOCATE (rho_fxc)
536 CALL qs_rho_create(rho_fxc)
537 IF (rho_tau_valid) THEN
538 CALL qs_rho_set(rho_fxc, rho_r=rho_r, rho_g=rho_g, tau_r=tau_r, &
539 rho_r_valid=.true., rho_g_valid=.true., tau_r_valid=.true.)
540 ELSE
541 CALL qs_rho_set(rho_fxc, rho_r=rho_r, rho_g=rho_g, &
542 rho_r_valid=.true., rho_g_valid=.true.)
543 END IF
544 ELSE
545 rho_fxc => rho_struct
546 END IF
547 CALL qs_fxc_analytic(rho_fxc, rho1_r, tau1_r, xc_section, weights, xc_pw_pool, &
548 triplet, vxc_rho, vxc_tau)
549 IF (uf_grid) DEALLOCATE (rho_fxc)
550 CASE DEFAULT
551 cpabort("Derivative order not available in xc_density")
552 END SELECT
553
554 ! remove the nlcc densities (keep stuff in original state)
555 IF (ASSOCIATED(rho_nlcc_use) .AND. order <= 1) THEN
556 factor = -1.0_dp
557 DO ispin = 1, dft_control%nspins
558 CALL pw_axpy(rho_nlcc_use, rho_r(ispin), factor)
559 CALL pw_axpy(rho_nlcc_g_use, rho_g(ispin), factor)
560 END DO
561 END IF
562 !
563 SELECT CASE (order)
564 CASE (0)
565 !
566 CASE (1, 2)
567 CALL pw_zero(exc)
568 IF (ASSOCIATED(vxc_rho)) THEN
569 DO ispin = 1, nspins
570 CALL pw_multiply_with(vxc_rho(ispin), rho1_r(ispin))
571 CALL pw_axpy(vxc_rho(ispin), exc, 1.0_dp)
572 CALL vxc_rho(ispin)%release()
573 END DO
574 DEALLOCATE (vxc_rho)
575 END IF
576 IF (ASSOCIATED(vxc_tau)) THEN
577 IF (.NOT. ASSOCIATED(tau1_r)) &
578 cpabort("Tau response density required for mGGA xc_density")
579 DO ispin = 1, nspins
580 CALL pw_multiply_with(vxc_tau(ispin), tau1_r(ispin))
581 CALL pw_axpy(vxc_tau(ispin), exc, 1.0_dp)
582 CALL vxc_tau(ispin)%release()
583 END DO
584 DEALLOCATE (vxc_tau)
585 END IF
586 CASE DEFAULT
587 cpabort("Derivative order not available in xc_density")
588 END SELECT
589
590 IF (order == 2) THEN
591 CALL pw_scale(exc, 0.5_dp)
592 END IF
593
594 END IF
595
596 IF (uf_grid) THEN
597 CALL give_back_density_on_pool(xc_pw_pool, rho_r, rho_g)
598 IF (ASSOCIATED(tau_r)) CALL give_back_density_on_pool(xc_pw_pool, tau_r, tau_g)
599 IF (ASSOCIATED(rho1_r)) CALL give_back_density_on_pool(xc_pw_pool, rho1_r, rho1_g)
600 IF (ASSOCIATED(tau1_r)) CALL give_back_density_on_pool(xc_pw_pool, tau1_r, tau1_g)
601 IF (ASSOCIATED(rho_nlcc_xc)) THEN
602 CALL xc_pw_pool%give_back_pw(rho_nlcc_xc)
603 DEALLOCATE (rho_nlcc_xc)
604 END IF
605 IF (ASSOCIATED(rho_nlcc_g_xc)) THEN
606 CALL xc_pw_pool%give_back_pw(rho_nlcc_g_xc)
607 DEALLOCATE (rho_nlcc_g_xc)
608 END IF
609 END IF
610
611 CALL timestop(handle)
612
613 END SUBROUTINE xc_density
614
615! **************************************************************************************************
616!> \brief transfers a g-space density to a given PW pool and creates its r-space representation
617!> \param pw_pool ...
618!> \param rho_g_in ...
619!> \param rho_r_out ...
620!> \param rho_g_out ...
621! **************************************************************************************************
622 SUBROUTINE create_density_on_pool(pw_pool, rho_g_in, rho_r_out, rho_g_out)
623 TYPE(pw_pool_type), POINTER :: pw_pool
624 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g_in
625 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r_out
626 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g_out
627
628 INTEGER :: ispin, nspins
629
630 cpassert(ASSOCIATED(pw_pool))
631 cpassert(ASSOCIATED(rho_g_in))
632
633 nspins = SIZE(rho_g_in)
634 ALLOCATE (rho_r_out(nspins), rho_g_out(nspins))
635 DO ispin = 1, nspins
636 CALL pw_pool%create_pw(rho_g_out(ispin))
637 CALL pw_pool%create_pw(rho_r_out(ispin))
638 CALL pw_transfer(rho_g_in(ispin), rho_g_out(ispin))
639 CALL pw_transfer(rho_g_out(ispin), rho_r_out(ispin))
640 END DO
641
642 END SUBROUTINE create_density_on_pool
643
644! **************************************************************************************************
645!> \brief transfers an r-space density to a given PW pool and creates its g-space representation
646!> \param source_pw_pool ...
647!> \param target_pw_pool ...
648!> \param rho_r_in ...
649!> \param rho_r_out ...
650!> \param rho_g_out ...
651! **************************************************************************************************
652 SUBROUTINE create_density_on_pool_from_r(source_pw_pool, target_pw_pool, rho_r_in, rho_r_out, rho_g_out)
653 TYPE(pw_pool_type), POINTER :: source_pw_pool, target_pw_pool
654 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r_in, rho_r_out
655 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g_out
656
657 INTEGER :: ispin, nspins
658 TYPE(pw_c1d_gs_type) :: rho_g_in
659
660 cpassert(ASSOCIATED(source_pw_pool))
661 cpassert(ASSOCIATED(target_pw_pool))
662 cpassert(ASSOCIATED(rho_r_in))
663
664 nspins = SIZE(rho_r_in)
665 ALLOCATE (rho_r_out(nspins), rho_g_out(nspins))
666 DO ispin = 1, nspins
667 CALL source_pw_pool%create_pw(rho_g_in)
668 CALL target_pw_pool%create_pw(rho_g_out(ispin))
669 CALL target_pw_pool%create_pw(rho_r_out(ispin))
670 CALL pw_transfer(rho_r_in(ispin), rho_g_in)
671 CALL pw_transfer(rho_g_in, rho_g_out(ispin))
672 CALL pw_transfer(rho_g_out(ispin), rho_r_out(ispin))
673 CALL source_pw_pool%give_back_pw(rho_g_in)
674 END DO
675
676 END SUBROUTINE create_density_on_pool_from_r
677
678! **************************************************************************************************
679!> \brief returns temporary density arrays to the given PW pool
680!> \param pw_pool ...
681!> \param rho_r ...
682!> \param rho_g ...
683! **************************************************************************************************
684 SUBROUTINE give_back_density_on_pool(pw_pool, rho_r, rho_g)
685 TYPE(pw_pool_type), POINTER :: pw_pool
686 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
687 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
688
689 INTEGER :: ispin
690
691 cpassert(ASSOCIATED(pw_pool))
692
693 IF (ASSOCIATED(rho_r)) THEN
694 DO ispin = 1, SIZE(rho_r)
695 CALL pw_pool%give_back_pw(rho_r(ispin))
696 END DO
697 DEALLOCATE (rho_r)
698 END IF
699 IF (ASSOCIATED(rho_g)) THEN
700 DO ispin = 1, SIZE(rho_g)
701 CALL pw_pool%give_back_pw(rho_g(ispin))
702 END DO
703 DEALLOCATE (rho_g)
704 END IF
705
706 END SUBROUTINE give_back_density_on_pool
707
708END MODULE accint_weights_forces
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
subroutine, public accint_weight_force(qs_env, rho, rho1, order, xc_section, triplet, force_scale)
...
All kind of helpful little routines.
Definition ao_util.F:14
real(kind=dp) function, public exp_radius_very_extended(la_min, la_max, lb_min, lb_max, pab, o1, o2, ra, rb, rp, zetp, eps, prefactor, cutoff, epsabs)
computes the radius of the Gaussian outside of which it is smaller than eps
Definition ao_util.F:209
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.
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...
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
Fortran API for the grid package, which is written in C.
Definition grid_api.F:12
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:276
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public sic_none
integer, parameter, public xc_none
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Utility routines for the memory handling.
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
This module defines the grid data type and some basic operations on it.
Definition pw_grids.F:36
logical function, public pw_grid_compare(grida, gridb)
Check if two pw_grids are equal.
Definition pw_grids.F:148
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, 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, 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)
Get the QUICKSTEP environment.
https://en.wikipedia.org/wiki/Finite_difference_coefficient
Definition qs_fxc.F:27
subroutine, public qs_fxc_analytic(rho0, rho1_r, tau1_r, xc_section, weights, auxbas_pw_pool, is_triplet, v_xc, v_xc_tau, spinflip)
...
Definition qs_fxc.F:96
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, rho, rho_xc, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, kpoints, do_kpoints, atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, particle_set, energy, force, local_particles, local_molecules, molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, nelectron_total, nelectron_spin)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_set(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
subroutine, public qs_rho_create(rho)
Allocates a new instance of rho.
subroutine, public transfer_pw2rs(rs, pw)
...
Experimental CP2K-native GPW real-space-grid path for SKALA TorchScript models.
subroutine, public skala_gpw_exc_density(exc_r, rho_r, rho_g, tau, xc_section, weights, pw_pool, particle_set, cell)
Evaluate the native SKALA XC energy density on the CP2K PW grid.
logical function, public xc_section_uses_native_skala_grid(xc_section)
Return true if the GAUXC subsection requests the CP2K-native GPW grid path.
Exchange and Correlation functional calculations.
Definition xc.F:17
subroutine, public xc_vxc_pw_create(vxc_rho, vxc_tau, exc, rho_r, rho_g, tau, xc_section, weights, pw_pool, compute_virial, virial_xc, exc_r)
Exchange and Correlation functional calculations.
Definition xc.F:474
subroutine, public xc_exc_pw_create(rho_r, rho_g, tau, xc_section, weights, pw_pool, exc)
calculates just the exchange and correlation energy density
Definition xc.F:857
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
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 ...
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.