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