(git:98357aa)
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
45 USE qs_ks_types, ONLY: get_ks_env,&
47 USE qs_rho_types, ONLY: qs_rho_create,&
59 USE virial_types, ONLY: virial_type
60 USE xc, ONLY: xc_exc_pw_create,&
64#include "./base/base_uses.f90"
65
66 IMPLICIT NONE
67
68 PRIVATE
69
70 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .false.
71
72 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'accint_weights_forces'
73
74 PUBLIC :: accint_weight_force
75
76CONTAINS
77
78! **************************************************************************************************
79!> \brief ...
80!> \param qs_env ...
81!> \param rho ...
82!> \param rho1 ...
83!> \param order ...
84!> \param xc_section ...
85!> \param triplet ...
86!> \param force_scale ...
87! **************************************************************************************************
88 SUBROUTINE accint_weight_force(qs_env, rho, rho1, order, xc_section, triplet, force_scale)
89 TYPE(qs_environment_type), POINTER :: qs_env
90 TYPE(qs_rho_type), POINTER :: rho, rho1
91 INTEGER, INTENT(IN) :: order
92 TYPE(section_vals_type), POINTER :: xc_section
93 LOGICAL, INTENT(IN), OPTIONAL :: triplet
94 REAL(kind=dp), INTENT(IN), OPTIONAL :: force_scale
95
96 CHARACTER(len=*), PARAMETER :: routinen = 'accint_weight_force'
97
98 INTEGER :: atom_a, handle, iatom, ikind, natom, &
99 natom_of_kind, nkind, output_unit
100 INTEGER, DIMENSION(:), POINTER :: atom_list
101 LOGICAL :: composite_reference, lr_triplet, &
102 native_grid_diagnostics, &
103 native_skala_grid, uf_grid, use_virial
104 REAL(kind=dp) :: my_force_scale
105 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: calpha, cvalue
106 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: aforce
107 REAL(kind=dp), DIMENSION(3, 3) :: avirial
108 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
109 TYPE(dft_control_type), POINTER :: dft_control
110 TYPE(pw_env_type), POINTER :: pw_env
111 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool, xc_pw_pool
112 TYPE(pw_r3d_rs_type) :: e_force_rspace, e_rspace
113 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
114 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
115 TYPE(qs_ks_env_type), POINTER :: ks_env
116 TYPE(virial_type), POINTER :: virial
117
118 CALL timeset(routinen, handle)
119
120 CALL get_qs_env(qs_env, dft_control=dft_control, qs_kind_set=qs_kind_set)
121
122 ! Composite references replace the PW XC quadrature and its Gaussian weight derivative.
123 ! The public selector applies only when a pseudopotential kind actually uses PAW one-center
124 ! data; it must not change all-electron GAPW integration.
125 composite_reference = native_skala_gapw_composite_reference(xc_section) .OR. &
127 IF (.NOT. composite_reference) THEN
128 composite_reference = skala_gapw_representation(xc_section) == &
131 END IF
132 IF (.NOT. composite_reference .AND. xc_section_uses_native_skala_grid(xc_section)) THEN
133 composite_reference = native_skala_uses_atom_composite_grid(xc_section)
134 END IF
135 IF (composite_reference) THEN
136 CALL timestop(handle)
137 RETURN
138 END IF
139
140 IF (dft_control%qs_control%gapw_control%accurate_xcint) THEN
141
142 CALL get_qs_env(qs_env=qs_env, force=force, virial=virial)
143 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
144
145 CALL get_qs_env(qs_env, natom=natom, nkind=nkind)
146 ALLOCATE (aforce(3, natom))
147 ALLOCATE (calpha(nkind), cvalue(nkind))
148 cvalue = 1.0_dp
149 calpha(1:nkind) = dft_control%qs_control%gapw_control%aw(1:nkind)
150
151 CALL get_qs_env(qs_env, ks_env=ks_env, pw_env=pw_env)
152 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, xc_pw_pool=xc_pw_pool)
153 uf_grid = .NOT. pw_grid_compare(auxbas_pw_pool%pw_grid, xc_pw_pool%pw_grid)
154 IF (uf_grid) THEN
155 CALL xc_pw_pool%create_pw(e_rspace)
156 ELSE
157 CALL auxbas_pw_pool%create_pw(e_rspace)
158 END IF
159
160 lr_triplet = .false.
161 IF (PRESENT(triplet)) lr_triplet = triplet
162 my_force_scale = 1.0_dp
163 IF (PRESENT(force_scale)) my_force_scale = force_scale
164
165 CALL xc_density(ks_env, rho, rho1, order, xc_section, lr_triplet, e_rspace)
166
167 IF (uf_grid) THEN
168 CALL auxbas_pw_pool%create_pw(e_force_rspace)
169 block
170 TYPE(pw_c1d_gs_type) :: e_g_aux, e_g_xc
171 CALL xc_pw_pool%create_pw(e_g_xc)
172 CALL auxbas_pw_pool%create_pw(e_g_aux)
173 CALL pw_transfer(e_rspace, e_g_xc)
174 CALL pw_transfer(e_g_xc, e_g_aux)
175 CALL pw_transfer(e_g_aux, e_force_rspace)
176 CALL auxbas_pw_pool%give_back_pw(e_g_aux)
177 CALL xc_pw_pool%give_back_pw(e_g_xc)
178 END block
179 CALL pw_scale(e_force_rspace, e_force_rspace%pw_grid%dvol)
180 CALL gauss_grid_force(e_force_rspace, qs_env, calpha, cvalue, aforce, avirial)
181 CALL auxbas_pw_pool%give_back_pw(e_force_rspace)
182 ELSE
183 CALL pw_scale(e_rspace, e_rspace%pw_grid%dvol)
184 CALL gauss_grid_force(e_rspace, qs_env, calpha, cvalue, aforce, avirial)
185 END IF
186
187 IF (uf_grid) THEN
188 CALL xc_pw_pool%give_back_pw(e_rspace)
189 ELSE
190 CALL auxbas_pw_pool%give_back_pw(e_rspace)
191 END IF
192
193 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set)
194 native_skala_grid = xc_section_uses_native_skala_grid(xc_section)
195 native_grid_diagnostics = .false.
196 IF (native_skala_grid) THEN
197 CALL section_vals_val_get(xc_section, "XC_FUNCTIONAL%GAUXC%NATIVE_GRID_DIAGNOSTICS", &
198 l_val=native_grid_diagnostics)
199 END IF
200 DO ikind = 1, nkind
201 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom_of_kind, atom_list=atom_list)
202 DO iatom = 1, natom_of_kind
203 atom_a = atom_list(iatom)
204 IF (native_grid_diagnostics) THEN
205 output_unit = cp_logger_get_default_io_unit()
206 IF (output_unit > 0) THEN
207 WRITE (unit=output_unit, fmt="(T2,A,1X,I0,3(1X,ES20.12))") &
208 "SKALA_GPW| Accurate-XCINT atom force", atom_a, my_force_scale*aforce(:, atom_a)
209 END IF
210 END IF
211 force(ikind)%rho_elec(1:3, iatom) = &
212 force(ikind)%rho_elec(1:3, iatom) + my_force_scale*aforce(1:3, atom_a)
213 END DO
214 END DO
215 IF (use_virial) THEN
216 virial%pv_exc = virial%pv_exc + my_force_scale*avirial
217 virial%pv_virial = virial%pv_virial + my_force_scale*avirial
218 END IF
219
220 DEALLOCATE (aforce, calpha, cvalue)
221
222 END IF
223
224 CALL timestop(handle)
225
226 END SUBROUTINE accint_weight_force
227
228! **************************************************************************************************
229!> \brief computes the forces/virial due to atomic centered Gaussian functions
230!> \param e_rspace Energy density
231!> \param qs_env ...
232!> \param calpha ...
233!> \param cvalue ...
234!> \param aforce ...
235!> \param avirial ...
236! **************************************************************************************************
237 SUBROUTINE gauss_grid_force(e_rspace, qs_env, calpha, cvalue, aforce, avirial)
238 TYPE(pw_r3d_rs_type), INTENT(IN) :: e_rspace
239 TYPE(qs_environment_type), POINTER :: qs_env
240 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: calpha, cvalue
241 REAL(kind=dp), DIMENSION(:, :), INTENT(OUT) :: aforce
242 REAL(kind=dp), DIMENSION(3, 3), INTENT(OUT) :: avirial
243
244 CHARACTER(len=*), PARAMETER :: routinen = 'gauss_grid_force'
245
246 INTEGER :: atom_a, handle, iatom, igrid, ikind, j, &
247 natom_of_kind, npme
248 INTEGER, DIMENSION(:), POINTER :: atom_list, cores
249 LOGICAL :: use_virial
250 REAL(kind=dp) :: alpha, eps_rho_rspace, radius
251 REAL(kind=dp), DIMENSION(3) :: force_a, force_b, ra
252 REAL(kind=dp), DIMENSION(3, 3) :: my_virial_a, my_virial_b
253 REAL(kind=dp), DIMENSION(:, :), POINTER :: hab, pab
254 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
255 TYPE(cell_type), POINTER :: cell
256 TYPE(dft_control_type), POINTER :: dft_control
257 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
258 TYPE(pw_env_type), POINTER :: pw_env
259 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
260 TYPE(realspace_grid_type), DIMENSION(:), POINTER :: rs_grids
261 TYPE(realspace_grid_type), POINTER :: rs_v
262
263 CALL timeset(routinen, handle)
264
265 ALLOCATE (cores(1))
266 ALLOCATE (hab(1, 1))
267 ALLOCATE (pab(1, 1))
268
269 NULLIFY (pw_pools, rs_grids, rs_v)
270
271 CALL get_qs_env(qs_env, pw_env=pw_env)
272 CALL pw_env_get(pw_env, pw_pools=pw_pools, rs_grids=rs_grids)
273 DO igrid = 1, SIZE(pw_pools)
274 IF (pw_grid_compare(e_rspace%pw_grid, pw_pools(igrid)%pool%pw_grid)) THEN
275 rs_v => rs_grids(igrid)
276 EXIT
277 END IF
278 END DO
279 IF (.NOT. ASSOCIATED(rs_v)) THEN
280 cpabort("No realspace grid for Accurate-XCINT weight force")
281 END IF
282
283 CALL transfer_pw2rs(rs_v, e_rspace)
284
285 CALL get_qs_env(qs_env, &
286 atomic_kind_set=atomic_kind_set, &
287 cell=cell, &
288 dft_control=dft_control, &
289 particle_set=particle_set)
290
291 use_virial = .true.
292 avirial = 0.0_dp
293 aforce = 0.0_dp
294
295 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
296
297 DO ikind = 1, SIZE(atomic_kind_set)
298
299 CALL get_atomic_kind(atomic_kind_set(ikind), natom=natom_of_kind, atom_list=atom_list)
300
301 alpha = calpha(ikind)
302 pab(1, 1) = -cvalue(ikind)
303 IF (alpha == 0.0_dp .OR. pab(1, 1) == 0.0_dp) cycle
304
305 CALL reallocate(cores, 1, natom_of_kind)
306 npme = 0
307 cores = 0
308
309 DO iatom = 1, natom_of_kind
310 atom_a = atom_list(iatom)
311 ra(:) = pbc(particle_set(atom_a)%r, cell)
312 IF (rs_v%desc%parallel .AND. .NOT. rs_v%desc%distributed) THEN
313 ! replicated realspace grid, split the atoms up between procs
314 IF (modulo(iatom, rs_v%desc%group_size) == rs_v%desc%my_pos) THEN
315 npme = npme + 1
316 cores(npme) = iatom
317 END IF
318 ELSE
319 npme = npme + 1
320 cores(npme) = iatom
321 END IF
322 END DO
323
324 DO j = 1, npme
325
326 iatom = cores(j)
327 atom_a = atom_list(iatom)
328 ra(:) = pbc(particle_set(atom_a)%r, cell)
329 hab(1, 1) = 0.0_dp
330 force_a(:) = 0.0_dp
331 force_b(:) = 0.0_dp
332 my_virial_a = 0.0_dp
333 my_virial_b = 0.0_dp
334
335 radius = exp_radius_very_extended(la_min=0, la_max=0, lb_min=0, lb_max=0, &
336 ra=ra, rb=ra, rp=ra, &
337 zetp=alpha, eps=eps_rho_rspace, &
338 pab=pab, o1=0, o2=0, &
339 prefactor=1.0_dp, cutoff=1.0_dp)
340
341 CALL integrate_pgf_product(0, alpha, 0, &
342 0, 0.0_dp, 0, ra, [0.0_dp, 0.0_dp, 0.0_dp], &
343 rs_v, hab, pab=pab, o1=0, o2=0, &
344 radius=radius, &
345 calculate_forces=.true., force_a=force_a, &
346 force_b=force_b, use_virial=use_virial, my_virial_a=my_virial_a, &
347 my_virial_b=my_virial_b, use_subpatch=.true., subpatch_pattern=0)
348
349 aforce(1:3, atom_a) = aforce(1:3, atom_a) + force_a(1:3)
350 avirial = avirial + my_virial_a
351
352 END DO
353
354 END DO
355
356 DEALLOCATE (hab, pab, cores)
357
358 CALL timestop(handle)
359
360 END SUBROUTINE gauss_grid_force
361
362! **************************************************************************************************
363!> \brief calculates the XC density:
364!> order=0: exc will contain the xc energy density E_xc(r)
365!> order=1: exc will contain V_xc(r) * rho1(r)
366!> order=2: exc will contain F_xc(r) * rho1(r) * rho1(r)
367!> \param ks_env to get all the needed things
368!> \param rho_struct density
369!> \param rho1_struct response density
370!> \param order requested derivative order
371!> \param xc_section ...
372!> \param triplet ...
373!> \param exc ...
374!> \author JGH
375! **************************************************************************************************
376 SUBROUTINE xc_density(ks_env, rho_struct, rho1_struct, order, xc_section, triplet, exc)
377
378 TYPE(qs_ks_env_type), POINTER :: ks_env
379 TYPE(qs_rho_type), POINTER :: rho_struct, rho1_struct
380 INTEGER, INTENT(IN) :: order
381 TYPE(section_vals_type), POINTER :: xc_section
382 LOGICAL, INTENT(IN) :: triplet
383 TYPE(pw_r3d_rs_type) :: exc
384
385 CHARACTER(len=*), PARAMETER :: routinen = 'xc_density'
386
387 INTEGER :: handle, ispin, myfun, nspins
388 LOGICAL :: native_skala_grid, rho1_g_valid, rho1_tau_g_valid, rho1_tau_valid, rho_g_valid, &
389 rho_tau_g_valid, rho_tau_valid, uf_grid
390 REAL(kind=dp) :: excint, factor
391 REAL(kind=dp), DIMENSION(3, 3) :: vdum
392 TYPE(cell_type), POINTER :: cell
393 TYPE(dft_control_type), POINTER :: dft_control
394 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
395 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho1_g, rho1_g_base, rho_g, rho_g_base, &
396 tau1_g, tau1_g_base, tau_g, tau_g_base
397 TYPE(pw_c1d_gs_type), POINTER :: rho_nlcc_g, rho_nlcc_g_use, rho_nlcc_g_xc
398 TYPE(pw_env_type), POINTER :: pw_env
399 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool, xc_pw_pool
400 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho1_r, rho1_r_base, rho_r, rho_r_base, &
401 tau1_r, tau1_r_base, tau_r, &
402 tau_r_base, vxc_rho, vxc_tau
403 TYPE(pw_r3d_rs_type), POINTER :: rho_nlcc, rho_nlcc_use, rho_nlcc_xc, &
404 weights
405 TYPE(qs_rho_type), POINTER :: rho_fxc
406
407 CALL timeset(routinen, handle)
408
409 ! we always get true exc (not integration weighted)
410 NULLIFY (rho1_g, rho1_g_base, rho1_r, rho1_r_base, rho_fxc, tau1_g, tau1_g_base)
411 NULLIFY (rho_g, rho_g_base, rho_r, rho_r_base, tau_g, tau_g_base, tau_r, tau_r_base, &
412 tau1_r, tau1_r_base)
413 NULLIFY (particle_set, rho_nlcc_use, rho_nlcc_xc, rho_nlcc_g_use, rho_nlcc_g_xc, weights)
414
415 CALL get_ks_env(ks_env, &
416 dft_control=dft_control, &
417 pw_env=pw_env, &
418 cell=cell, &
419 particle_set=particle_set, &
420 rho_nlcc=rho_nlcc, &
421 rho_nlcc_g=rho_nlcc_g)
422
423 CALL qs_rho_get(rho_struct, rho_r=rho_r_base, rho_g=rho_g_base, tau_r=tau_r_base, &
424 tau_g=tau_g_base, rho_g_valid=rho_g_valid, tau_g_valid=rho_tau_g_valid, &
425 tau_r_valid=rho_tau_valid)
426 rho_r => rho_r_base
427 rho_g => rho_g_base
428 tau_r => tau_r_base
429 tau_g => tau_g_base
430
431 nspins = dft_control%nspins
432
433 CALL section_vals_val_get(xc_section, "XC_FUNCTIONAL%_SECTION_PARAMETERS_", i_val=myfun)
434 native_skala_grid = xc_section_uses_native_skala_grid(xc_section)
435
436 CALL pw_env_get(pw_env, xc_pw_pool=xc_pw_pool, auxbas_pw_pool=auxbas_pw_pool)
437 uf_grid = .NOT. pw_grid_compare(auxbas_pw_pool%pw_grid, xc_pw_pool%pw_grid)
438 IF (uf_grid) THEN
439 NULLIFY (rho_r, rho_g, tau_r, tau_g)
440 IF (rho_g_valid) THEN
441 CALL create_density_on_pool(xc_pw_pool, rho_g_base, rho_r, rho_g)
442 ELSE IF (ASSOCIATED(rho_r_base)) THEN
443 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, rho_r_base, rho_r, rho_g)
444 ELSE
445 cpabort("Fine Grid in xc_density requires rho_r or rho_g")
446 END IF
447 IF (rho_tau_valid) THEN
448 IF (rho_tau_g_valid) THEN
449 CALL create_density_on_pool(xc_pw_pool, tau_g_base, tau_r, tau_g)
450 ELSE IF (ASSOCIATED(tau_r_base)) THEN
451 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, tau_r_base, tau_r, tau_g)
452 ELSE
453 cpabort("Fine Grid in xc_density requires tau_r or tau_g")
454 END IF
455 END IF
456 IF (ASSOCIATED(rho_nlcc)) THEN
457 ALLOCATE (rho_nlcc_g_xc, rho_nlcc_xc)
458 CALL xc_pw_pool%create_pw(rho_nlcc_g_xc)
459 CALL xc_pw_pool%create_pw(rho_nlcc_xc)
460 CALL pw_transfer(rho_nlcc_g, rho_nlcc_g_xc)
461 CALL pw_transfer(rho_nlcc_g_xc, rho_nlcc_xc)
462 rho_nlcc_use => rho_nlcc_xc
463 rho_nlcc_g_use => rho_nlcc_g_xc
464 END IF
465 END IF
466 IF (.NOT. ASSOCIATED(rho_nlcc_use)) THEN
467 rho_nlcc_use => rho_nlcc
468 rho_nlcc_g_use => rho_nlcc_g
469 END IF
470
471 CALL pw_zero(exc)
472
473 IF (myfun /= xc_none) THEN
474
475 cpassert(ASSOCIATED(rho_struct))
476 cpassert(dft_control%sic_method_id == sic_none)
477
478 ! add the nlcc densities
479 IF (ASSOCIATED(rho_nlcc_use) .AND. order <= 1) THEN
480 factor = 1.0_dp
481 DO ispin = 1, nspins
482 CALL pw_axpy(rho_nlcc_use, rho_r(ispin), factor)
483 CALL pw_axpy(rho_nlcc_g_use, rho_g(ispin), factor)
484 END DO
485 END IF
486
487 NULLIFY (vxc_rho, vxc_tau)
488 SELECT CASE (order)
489 CASE (0)
490 IF (native_skala_grid) THEN
491 CALL skala_gpw_weight_derivative(exc, rho_r, rho_g, tau_r, xc_section, weights, &
492 xc_pw_pool, particle_set, cell)
493 ELSE
494 ! we could reduce to energy only here
495 CALL xc_exc_pw_create(rho_r, rho_g, tau_r, xc_section, weights, xc_pw_pool, exc)
496 END IF
497 CASE (1)
498 IF (native_skala_grid) THEN
499 CALL cp_abort(__location__, &
500 "Native SKALA GAPW accurate-XCINT response forces are not implemented.")
501 END IF
502 CALL qs_rho_get(rho1_struct, rho_r=rho1_r_base, rho_g=rho1_g_base, tau_r=tau1_r_base, &
503 tau_g=tau1_g_base, rho_g_valid=rho1_g_valid, &
504 tau_g_valid=rho1_tau_g_valid, tau_r_valid=rho1_tau_valid)
505 rho1_r => rho1_r_base
506 tau1_g => tau1_g_base
507 tau1_r => tau1_r_base
508 IF (uf_grid) THEN
509 NULLIFY (rho1_r, rho1_g, tau1_r, tau1_g)
510 IF (rho1_g_valid) THEN
511 CALL create_density_on_pool(xc_pw_pool, rho1_g_base, rho1_r, rho1_g)
512 ELSE IF (ASSOCIATED(rho1_r_base)) THEN
513 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, rho1_r_base, rho1_r, rho1_g)
514 ELSE
515 cpabort("Fine Grid in xc_density requires rho1_r or rho1_g")
516 END IF
517 IF (rho1_tau_valid) THEN
518 IF (rho1_tau_g_valid) THEN
519 CALL create_density_on_pool(xc_pw_pool, tau1_g_base, tau1_r, tau1_g)
520 ELSE IF (ASSOCIATED(tau1_r_base)) THEN
521 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, tau1_r_base, tau1_r, tau1_g)
522 ELSE
523 cpabort("Fine Grid in xc_density requires tau1_r or tau1_g")
524 END IF
525 END IF
526 END IF
527 CALL xc_vxc_pw_create(vxc_rho=vxc_rho, vxc_tau=vxc_tau, rho_r=rho_r, &
528 rho_g=rho_g, tau=tau_r, exc=excint, &
529 xc_section=xc_section, &
530 weights=weights, pw_pool=xc_pw_pool, &
531 compute_virial=.false., &
532 virial_xc=vdum)
533 CASE (2)
534 IF (native_skala_grid) THEN
535 CALL cp_abort(__location__, &
536 "Native SKALA GAPW accurate-XCINT response forces are not implemented.")
537 END IF
538 CALL qs_rho_get(rho1_struct, rho_r=rho1_r_base, rho_g=rho1_g_base, tau_r=tau1_r_base, &
539 tau_g=tau1_g_base, rho_g_valid=rho1_g_valid, &
540 tau_g_valid=rho1_tau_g_valid, tau_r_valid=rho1_tau_valid)
541 rho1_r => rho1_r_base
542 tau1_g => tau1_g_base
543 tau1_r => tau1_r_base
544 IF (uf_grid) THEN
545 NULLIFY (rho1_r, rho1_g, tau1_r, tau1_g)
546 IF (rho1_g_valid) THEN
547 CALL create_density_on_pool(xc_pw_pool, rho1_g_base, rho1_r, rho1_g)
548 ELSE IF (ASSOCIATED(rho1_r_base)) THEN
549 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, rho1_r_base, rho1_r, rho1_g)
550 ELSE
551 cpabort("Fine Grid in xc_density requires rho1_r or rho1_g")
552 END IF
553 IF (rho1_tau_valid) THEN
554 IF (rho1_tau_g_valid) THEN
555 CALL create_density_on_pool(xc_pw_pool, tau1_g_base, tau1_r, tau1_g)
556 ELSE IF (ASSOCIATED(tau1_r_base)) THEN
557 CALL create_density_on_pool_from_r(auxbas_pw_pool, xc_pw_pool, tau1_r_base, tau1_r, tau1_g)
558 ELSE
559 cpabort("Fine Grid in xc_density requires tau1_r or tau1_g")
560 END IF
561 END IF
562 ALLOCATE (rho_fxc)
563 CALL qs_rho_create(rho_fxc)
564 IF (rho_tau_valid) THEN
565 CALL qs_rho_set(rho_fxc, rho_r=rho_r, rho_g=rho_g, tau_r=tau_r, &
566 rho_r_valid=.true., rho_g_valid=.true., tau_r_valid=.true.)
567 ELSE
568 CALL qs_rho_set(rho_fxc, rho_r=rho_r, rho_g=rho_g, &
569 rho_r_valid=.true., rho_g_valid=.true.)
570 END IF
571 ELSE
572 rho_fxc => rho_struct
573 END IF
574 CALL qs_fxc_analytic(rho_fxc, rho1_r, tau1_r, xc_section, weights, xc_pw_pool, &
575 triplet, vxc_rho, vxc_tau)
576 IF (uf_grid) DEALLOCATE (rho_fxc)
577 CASE DEFAULT
578 cpabort("Derivative order not available in xc_density")
579 END SELECT
580
581 ! remove the nlcc densities (keep stuff in original state)
582 IF (ASSOCIATED(rho_nlcc_use) .AND. order <= 1) THEN
583 factor = -1.0_dp
584 DO ispin = 1, dft_control%nspins
585 CALL pw_axpy(rho_nlcc_use, rho_r(ispin), factor)
586 CALL pw_axpy(rho_nlcc_g_use, rho_g(ispin), factor)
587 END DO
588 END IF
589 !
590 SELECT CASE (order)
591 CASE (0)
592 !
593 CASE (1, 2)
594 CALL pw_zero(exc)
595 IF (ASSOCIATED(vxc_rho)) THEN
596 DO ispin = 1, nspins
597 CALL pw_multiply_with(vxc_rho(ispin), rho1_r(ispin))
598 CALL pw_axpy(vxc_rho(ispin), exc, 1.0_dp)
599 CALL vxc_rho(ispin)%release()
600 END DO
601 DEALLOCATE (vxc_rho)
602 END IF
603 IF (ASSOCIATED(vxc_tau)) THEN
604 IF (.NOT. ASSOCIATED(tau1_r)) THEN
605 cpabort("Tau response density required for mGGA xc_density")
606 END IF
607 DO ispin = 1, nspins
608 CALL pw_multiply_with(vxc_tau(ispin), tau1_r(ispin))
609 CALL pw_axpy(vxc_tau(ispin), exc, 1.0_dp)
610 CALL vxc_tau(ispin)%release()
611 END DO
612 DEALLOCATE (vxc_tau)
613 END IF
614 CASE DEFAULT
615 cpabort("Derivative order not available in xc_density")
616 END SELECT
617
618 IF (order == 2) THEN
619 CALL pw_scale(exc, 0.5_dp)
620 END IF
621
622 END IF
623
624 IF (uf_grid) THEN
625 CALL give_back_density_on_pool(xc_pw_pool, rho_r, rho_g)
626 IF (ASSOCIATED(tau_r)) CALL give_back_density_on_pool(xc_pw_pool, tau_r, tau_g)
627 IF (ASSOCIATED(rho1_r)) CALL give_back_density_on_pool(xc_pw_pool, rho1_r, rho1_g)
628 IF (ASSOCIATED(tau1_r)) CALL give_back_density_on_pool(xc_pw_pool, tau1_r, tau1_g)
629 IF (ASSOCIATED(rho_nlcc_xc)) THEN
630 CALL xc_pw_pool%give_back_pw(rho_nlcc_xc)
631 DEALLOCATE (rho_nlcc_xc)
632 END IF
633 IF (ASSOCIATED(rho_nlcc_g_xc)) THEN
634 CALL xc_pw_pool%give_back_pw(rho_nlcc_g_xc)
635 DEALLOCATE (rho_nlcc_g_xc)
636 END IF
637 END IF
638
639 CALL timestop(handle)
640
641 END SUBROUTINE xc_density
642
643! **************************************************************************************************
644!> \brief transfers a g-space density to a given PW pool and creates its r-space representation
645!> \param pw_pool ...
646!> \param rho_g_in ...
647!> \param rho_r_out ...
648!> \param rho_g_out ...
649! **************************************************************************************************
650 SUBROUTINE create_density_on_pool(pw_pool, rho_g_in, rho_r_out, rho_g_out)
651 TYPE(pw_pool_type), POINTER :: pw_pool
652 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g_in
653 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r_out
654 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g_out
655
656 INTEGER :: ispin, nspins
657
658 cpassert(ASSOCIATED(pw_pool))
659 cpassert(ASSOCIATED(rho_g_in))
660
661 nspins = SIZE(rho_g_in)
662 ALLOCATE (rho_r_out(nspins), rho_g_out(nspins))
663 DO ispin = 1, nspins
664 CALL pw_pool%create_pw(rho_g_out(ispin))
665 CALL pw_pool%create_pw(rho_r_out(ispin))
666 CALL pw_transfer(rho_g_in(ispin), rho_g_out(ispin))
667 CALL pw_transfer(rho_g_out(ispin), rho_r_out(ispin))
668 END DO
669
670 END SUBROUTINE create_density_on_pool
671
672! **************************************************************************************************
673!> \brief transfers an r-space density to a given PW pool and creates its g-space representation
674!> \param source_pw_pool ...
675!> \param target_pw_pool ...
676!> \param rho_r_in ...
677!> \param rho_r_out ...
678!> \param rho_g_out ...
679! **************************************************************************************************
680 SUBROUTINE create_density_on_pool_from_r(source_pw_pool, target_pw_pool, rho_r_in, rho_r_out, rho_g_out)
681 TYPE(pw_pool_type), POINTER :: source_pw_pool, target_pw_pool
682 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r_in, rho_r_out
683 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g_out
684
685 INTEGER :: ispin, nspins
686 TYPE(pw_c1d_gs_type) :: rho_g_in
687
688 cpassert(ASSOCIATED(source_pw_pool))
689 cpassert(ASSOCIATED(target_pw_pool))
690 cpassert(ASSOCIATED(rho_r_in))
691
692 nspins = SIZE(rho_r_in)
693 ALLOCATE (rho_r_out(nspins), rho_g_out(nspins))
694 DO ispin = 1, nspins
695 CALL source_pw_pool%create_pw(rho_g_in)
696 CALL target_pw_pool%create_pw(rho_g_out(ispin))
697 CALL target_pw_pool%create_pw(rho_r_out(ispin))
698 CALL pw_transfer(rho_r_in(ispin), rho_g_in)
699 CALL pw_transfer(rho_g_in, rho_g_out(ispin))
700 CALL pw_transfer(rho_g_out(ispin), rho_r_out(ispin))
701 CALL source_pw_pool%give_back_pw(rho_g_in)
702 END DO
703
704 END SUBROUTINE create_density_on_pool_from_r
705
706! **************************************************************************************************
707!> \brief returns temporary density arrays to the given PW pool
708!> \param pw_pool ...
709!> \param rho_r ...
710!> \param rho_g ...
711! **************************************************************************************************
712 SUBROUTINE give_back_density_on_pool(pw_pool, rho_r, rho_g)
713 TYPE(pw_pool_type), POINTER :: pw_pool
714 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
715 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
716
717 INTEGER :: ispin
718
719 cpassert(ASSOCIATED(pw_pool))
720
721 IF (ASSOCIATED(rho_r)) THEN
722 DO ispin = 1, SIZE(rho_r)
723 CALL pw_pool%give_back_pw(rho_r(ispin))
724 END DO
725 DEALLOCATE (rho_r)
726 END IF
727 IF (ASSOCIATED(rho_g)) THEN
728 DO ispin = 1, SIZE(rho_g)
729 CALL pw_pool%give_back_pw(rho_g(ispin))
730 END DO
731 DEALLOCATE (rho_g)
732 END IF
733
734 END SUBROUTINE give_back_density_on_pool
735
736END 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, 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)
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
Define the quickstep kind type and their sub types.
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_vhxc, 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_weight_derivative(weight_deriv_r, rho_r, rho_g, tau, xc_section, weights, pw_pool, particle_set, cell)
Evaluate the derivative of native SKALA XC energy with respect to CP2K's external real-space integrat...
logical function, public native_skala_uses_atom_composite_grid(xc_section)
Return true when native Skala uses atom-centered grids.
integer function, public skala_gapw_representation(xc_section)
Return the pseudopotential GAPW representation selected for an active model.
logical function, public native_skala_gapw_atom_composite_requested(xc_section)
Return true when the explicit atom-centered composite reference is requested.
logical function, public native_skala_gapw_composite_reference(xc_section)
Return true if native SKALA should use the full GAPW ORB density on one common 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.
logical function, public gauxc_gapw_has_paw_pseudopotentials(qs_kind_set)
Return whether GauXC GAPW mode sees pseudopotential one-center GAPW kinds.
input constants for xc
integer, parameter, public skala_gapw_paw_one_center
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 ...
Provides all information about a quickstep kind.
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.