58#include "./base/base_uses.f90"
67 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_fxc'
84 SUBROUTINE qs_fxc_analytic(rho0, rho1_r, tau1_r, xc_section, auxbas_pw_pool, is_triplet, v_xc, v_xc_tau)
90 LOGICAL,
INTENT(IN) :: is_triplet
93 CHARACTER(len=*),
PARAMETER :: routinen =
'qs_fxc_analytic'
95 INTEGER :: handle, nspins
96 INTEGER,
DIMENSION(2, 3) :: bo
106 CALL timeset(routinen, handle)
108 cpassert(.NOT.
ASSOCIATED(v_xc))
109 cpassert(.NOT.
ASSOCIATED(v_xc_tau))
111 CALL qs_rho_get(rho0, rho_r=rho0_r, rho_g=rho0_g, tau_r=tau0_r)
112 nspins =
SIZE(rho0_r)
116 IF (is_triplet .AND. nspins == 1)
fac = -1.0_dp
119 bo = rho1_r(1)%pw_grid%bounds_local
123 CALL xc_prep_2nd_deriv(deriv_set, rho0_set, rho0_r, auxbas_pw_pool, xc_section=xc_section, tau_r=tau0_r)
124 CALL xc_calc_2nd_deriv(v_xc, v_xc_tau, deriv_set, rho0_set, rho1_r, rho1_g, tau1_r, &
125 auxbas_pw_pool, xc_section=xc_section, gapw=.false., do_triplet=is_triplet)
129 CALL timestop(handle)
144 SUBROUTINE qs_fxc_fdiff(ks_env, rho0_struct, rho1_struct, xc_section, accuracy, is_triplet, &
148 TYPE(
qs_rho_type),
POINTER :: rho0_struct, rho1_struct
150 INTEGER,
INTENT(IN) :: accuracy
151 LOGICAL,
INTENT(IN) :: is_triplet
154 CHARACTER(len=*),
PARAMETER :: routinen =
'qs_fxc_fdiff'
155 REAL(kind=
dp),
PARAMETER :: epsrho = 5.e-4_dp
157 INTEGER :: handle, ispin, istep, nspins, nstep
158 REAL(kind=
dp) :: alpha, beta, exc, oeps1
159 REAL(kind=
dp),
DIMENSION(-4:4) :: ak
163 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: v_tau_rspace, vxc00
166 CALL timeset(routinen, handle)
168 cpassert(.NOT.
ASSOCIATED(fxc_rho))
169 cpassert(.NOT.
ASSOCIATED(fxc_tau))
170 cpassert(
ASSOCIATED(rho0_struct))
171 cpassert(
ASSOCIATED(rho1_struct))
174 SELECT CASE (accuracy)
177 ak(-2:2) = (/1.0_dp, -8.0_dp, 0.0_dp, 8.0_dp, -1.0_dp/)/12.0_dp
180 ak(-3:3) = (/-1.0_dp, 9.0_dp, -45.0_dp, 0.0_dp, 45.0_dp, -9.0_dp, 1.0_dp/)/60.0_dp
183 ak(-4:4) = (/1.0_dp, -32.0_dp/3.0_dp, 56.0_dp, -224.0_dp, 0.0_dp, &
184 224.0_dp, -56.0_dp, 32.0_dp/3.0_dp, -1.0_dp/)/280.0_dp
187 CALL get_ks_env(ks_env, dft_control=dft_control, pw_env=pw_env)
188 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
190 nspins = dft_control%nspins
193 DO istep = -nstep, nstep
195 IF (ak(istep) /= 0.0_dp)
THEN
197 beta = real(istep, kind=
dp)*epsrho
201 NULLIFY (vxc00, v_tau_rspace)
203 cpassert(nspins == 1)
205 CALL qs_rho_copy(rho0_struct, rhoin, auxbas_pw_pool, 2)
208 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rhoin, xc_section=xc_section, &
209 vxc_rho=vxc00, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
210 CALL pw_axpy(vxc00(2), vxc00(1), -1.0_dp)
211 IF (
ASSOCIATED(v_tau_rspace))
CALL pw_axpy(v_tau_rspace(2), v_tau_rspace(1), -1.0_dp)
213 CALL qs_rho_copy(rho0_struct, rhoin, auxbas_pw_pool, nspins)
215 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rhoin, xc_section=xc_section, &
216 vxc_rho=vxc00, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
220 IF (.NOT.
ASSOCIATED(fxc_rho))
THEN
221 ALLOCATE (fxc_rho(nspins))
223 CALL auxbas_pw_pool%create_pw(fxc_rho(ispin))
228 CALL pw_axpy(vxc00(ispin), fxc_rho(ispin), ak(istep))
230 DO ispin = 1,
SIZE(vxc00)
231 CALL auxbas_pw_pool%give_back_pw(vxc00(ispin))
234 IF (
ASSOCIATED(v_tau_rspace))
THEN
235 IF (.NOT.
ASSOCIATED(fxc_tau))
THEN
236 ALLOCATE (fxc_tau(nspins))
238 CALL auxbas_pw_pool%create_pw(fxc_tau(ispin))
243 CALL pw_axpy(v_tau_rspace(ispin), fxc_tau(ispin), ak(istep))
245 DO ispin = 1,
SIZE(v_tau_rspace)
246 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
248 DEALLOCATE (v_tau_rspace)
254 oeps1 = 1.0_dp/epsrho
256 CALL pw_scale(fxc_rho(ispin), oeps1)
258 IF (
ASSOCIATED(fxc_tau))
THEN
260 CALL pw_scale(fxc_tau(ispin), oeps1)
264 CALL timestop(handle)
282 SUBROUTINE qs_fgxc_gdiff(ks_env, rho0_struct, rho1_struct, xc_section, accuracy, epsrho, &
283 is_triplet, fxc_rho, fxc_tau, gxc_rho, gxc_tau)
286 TYPE(
qs_rho_type),
POINTER :: rho0_struct, rho1_struct
288 INTEGER,
INTENT(IN) :: accuracy
289 REAL(kind=
dp),
INTENT(IN) :: epsrho
290 LOGICAL,
INTENT(IN) :: is_triplet
291 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: fxc_rho, fxc_tau, gxc_rho, gxc_tau
293 CHARACTER(len=*),
PARAMETER :: routinen =
'qs_fgxc_gdiff'
295 INTEGER :: handle, ispin, istep, nspins, nstep
296 REAL(kind=
dp) :: alpha, beta, exc, oeps1
297 REAL(kind=
dp),
DIMENSION(-4:4) :: ak
301 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: v_tau_rspace, vxc00
304 CALL timeset(routinen, handle)
306 cpassert(.NOT.
ASSOCIATED(fxc_rho))
307 cpassert(.NOT.
ASSOCIATED(fxc_tau))
308 cpassert(.NOT.
ASSOCIATED(gxc_rho))
309 cpassert(.NOT.
ASSOCIATED(gxc_tau))
310 cpassert(
ASSOCIATED(rho0_struct))
311 cpassert(
ASSOCIATED(rho1_struct))
314 SELECT CASE (accuracy)
317 ak(-2:2) = (/1.0_dp, -8.0_dp, 0.0_dp, 8.0_dp, -1.0_dp/)/12.0_dp
320 ak(-3:3) = (/-1.0_dp, 9.0_dp, -45.0_dp, 0.0_dp, 45.0_dp, -9.0_dp, 1.0_dp/)/60.0_dp
323 ak(-4:4) = (/1.0_dp, -32.0_dp/3.0_dp, 56.0_dp, -224.0_dp, 0.0_dp, &
324 224.0_dp, -56.0_dp, 32.0_dp/3.0_dp, -1.0_dp/)/280.0_dp
327 CALL get_ks_env(ks_env, dft_control=dft_control, pw_env=pw_env)
328 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
330 nspins = dft_control%nspins
333 CALL qs_fxc_fdiff(ks_env, rho0_struct, rho1_struct, xc_section, accuracy, is_triplet, &
336 DO istep = -nstep, nstep
338 IF (ak(istep) /= 0.0_dp)
THEN
340 beta = real(istep, kind=
dp)*epsrho
344 NULLIFY (vxc00, v_tau_rspace)
345 CALL qs_rho_copy(rho0_struct, rhoin, auxbas_pw_pool, nspins)
347 CALL qs_fxc_fdiff(ks_env=ks_env, rho0_struct=rhoin, rho1_struct=rho1_struct, &
348 xc_section=xc_section, accuracy=accuracy, is_triplet=is_triplet, &
349 fxc_rho=vxc00, fxc_tau=v_tau_rspace)
352 IF (.NOT.
ASSOCIATED(gxc_rho))
THEN
353 ALLOCATE (gxc_rho(nspins))
355 CALL auxbas_pw_pool%create_pw(gxc_rho(ispin))
360 CALL pw_axpy(vxc00(ispin), gxc_rho(ispin), ak(istep))
362 DO ispin = 1,
SIZE(vxc00)
363 CALL auxbas_pw_pool%give_back_pw(vxc00(ispin))
366 IF (
ASSOCIATED(v_tau_rspace))
THEN
367 IF (.NOT.
ASSOCIATED(gxc_tau))
THEN
368 ALLOCATE (gxc_tau(nspins))
370 CALL auxbas_pw_pool%create_pw(gxc_tau(ispin))
375 CALL pw_axpy(v_tau_rspace(ispin), gxc_tau(ispin), ak(istep))
377 DO ispin = 1,
SIZE(v_tau_rspace)
378 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
380 DEALLOCATE (v_tau_rspace)
386 oeps1 = 1.0_dp/epsrho
388 CALL pw_scale(gxc_rho(ispin), oeps1)
390 IF (
ASSOCIATED(gxc_tau))
THEN
392 CALL pw_scale(gxc_tau(ispin), oeps1)
396 CALL timestop(handle)
413 SUBROUTINE qs_fgxc_create(ks_env, rho0_struct, rho1_struct, xc_section, accuracy, is_triplet, &
414 fxc_rho, fxc_tau, gxc_rho, gxc_tau)
417 TYPE(
qs_rho_type),
POINTER :: rho0_struct, rho1_struct
419 INTEGER,
INTENT(IN) :: accuracy
420 LOGICAL,
INTENT(IN) :: is_triplet
421 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: fxc_rho, fxc_tau, gxc_rho, gxc_tau
423 CHARACTER(len=*),
PARAMETER :: routinen =
'qs_fgxc_create'
424 REAL(kind=
dp),
PARAMETER :: epsrho = 5.e-4_dp
426 INTEGER :: handle, ispin, istep, nspins, nstep
427 REAL(kind=
dp) :: alpha, beta, exc, oeps1, oeps2
428 REAL(kind=
dp),
DIMENSION(-4:4) :: ak, bl
432 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: v_tau_rspace, vxc00
435 CALL timeset(routinen, handle)
437 cpassert(.NOT.
ASSOCIATED(fxc_rho))
438 cpassert(.NOT.
ASSOCIATED(fxc_tau))
439 cpassert(.NOT.
ASSOCIATED(gxc_rho))
440 cpassert(.NOT.
ASSOCIATED(gxc_tau))
441 cpassert(
ASSOCIATED(rho0_struct))
442 cpassert(
ASSOCIATED(rho1_struct))
446 SELECT CASE (accuracy)
449 ak(-2:2) = (/1.0_dp, -8.0_dp, 0.0_dp, 8.0_dp, -1.0_dp/)/12.0_dp
450 bl(-2:2) = (/-1.0_dp, 16.0_dp, -30.0_dp, 16.0_dp, -1.0_dp/)/12.0_dp
453 ak(-3:3) = (/-1.0_dp, 9.0_dp, -45.0_dp, 0.0_dp, 45.0_dp, -9.0_dp, 1.0_dp/)/60.0_dp
454 bl(-3:3) = (/2.0_dp, -27.0_dp, 270.0_dp, -490.0_dp, 270.0_dp, -27.0_dp, 2.0_dp/)/180.0_dp
457 ak(-4:4) = (/1.0_dp, -32.0_dp/3.0_dp, 56.0_dp, -224.0_dp, 0.0_dp, &
458 224.0_dp, -56.0_dp, 32.0_dp/3.0_dp, -1.0_dp/)/280.0_dp
459 bl(-4:4) = (/-1.0_dp, 128.0_dp/9.0_dp, -112.0_dp, 896.0_dp, -14350.0_dp/9.0_dp, &
460 896.0_dp, -112.0_dp, 128.0_dp/9.0_dp, -1.0_dp/)/560.0_dp
463 CALL get_ks_env(ks_env, dft_control=dft_control, pw_env=pw_env)
464 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
466 nspins = dft_control%nspins
469 DO istep = -nstep, nstep
472 beta = real(istep, kind=
dp)*epsrho
476 NULLIFY (vxc00, v_tau_rspace)
478 cpassert(nspins == 1)
480 CALL qs_rho_copy(rho0_struct, rhoin, auxbas_pw_pool, 2)
483 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rhoin, xc_section=xc_section, &
484 vxc_rho=vxc00, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
485 CALL pw_axpy(vxc00(2), vxc00(1), -1.0_dp)
487 CALL qs_rho_copy(rho0_struct, rhoin, auxbas_pw_pool, nspins)
489 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rhoin, xc_section=xc_section, &
490 vxc_rho=vxc00, vxc_tau=v_tau_rspace, exc=exc, just_energy=.false.)
494 IF (.NOT.
ASSOCIATED(fxc_rho))
THEN
495 ALLOCATE (fxc_rho(nspins))
497 CALL auxbas_pw_pool%create_pw(fxc_rho(ispin))
501 IF (.NOT.
ASSOCIATED(gxc_rho))
THEN
502 ALLOCATE (gxc_rho(nspins))
504 CALL auxbas_pw_pool%create_pw(gxc_rho(ispin))
508 cpassert(.NOT.
ASSOCIATED(v_tau_rspace))
510 IF (ak(istep) /= 0.0_dp)
THEN
511 CALL pw_axpy(vxc00(ispin), fxc_rho(ispin), ak(istep))
513 IF (bl(istep) /= 0.0_dp)
THEN
514 CALL pw_axpy(vxc00(ispin), gxc_rho(ispin), bl(istep))
517 DO ispin = 1,
SIZE(vxc00)
518 CALL auxbas_pw_pool%give_back_pw(vxc00(ispin))
524 oeps1 = 1.0_dp/epsrho
525 oeps2 = 1.0_dp/(epsrho**2)
527 CALL pw_scale(fxc_rho(ispin), oeps1)
528 CALL pw_scale(gxc_rho(ispin), oeps2)
531 CALL timestop(handle)
546 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: fxc_rho, fxc_tau, gxc_rho, gxc_tau
553 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
555 IF (
ASSOCIATED(fxc_rho))
THEN
556 DO ispin = 1,
SIZE(fxc_rho)
557 CALL auxbas_pw_pool%give_back_pw(fxc_rho(ispin))
561 IF (
ASSOCIATED(fxc_tau))
THEN
562 DO ispin = 1,
SIZE(fxc_tau)
563 CALL auxbas_pw_pool%give_back_pw(fxc_tau(ispin))
567 IF (
ASSOCIATED(gxc_rho))
THEN
568 DO ispin = 1,
SIZE(gxc_rho)
569 CALL auxbas_pw_pool%give_back_pw(gxc_rho(ispin))
573 IF (
ASSOCIATED(gxc_tau))
THEN
574 DO ispin = 1,
SIZE(gxc_tau)
575 CALL auxbas_pw_pool%give_back_pw(gxc_tau(ispin))
static GRID_HOST_DEVICE double fac(const int i)
Factorial function, e.g. fac(5) = 5! = 120.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
Defines the basic variable types.
integer, parameter, public dp
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
https://en.wikipedia.org/wiki/Finite_difference_coefficient
subroutine, public qs_fgxc_gdiff(ks_env, rho0_struct, rho1_struct, xc_section, accuracy, epsrho, is_triplet, fxc_rho, fxc_tau, gxc_rho, gxc_tau)
...
subroutine, public qs_fgxc_create(ks_env, rho0_struct, rho1_struct, xc_section, accuracy, is_triplet, fxc_rho, fxc_tau, gxc_rho, gxc_tau)
...
subroutine, public qs_fxc_analytic(rho0, rho1_r, tau1_r, xc_section, auxbas_pw_pool, is_triplet, v_xc, v_xc_tau)
...
subroutine, public qs_fgxc_release(ks_env, fxc_rho, fxc_tau, gxc_rho, gxc_tau)
...
subroutine, public qs_fxc_fdiff(ks_env, rho0_struct, rho1_struct, xc_section, accuracy, is_triplet, fxc_rho, fxc_tau)
...
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, 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, 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, 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)
...
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_copy(rho_input, rho_output, auxbas_pw_pool, mspin)
Allocate a density structure and fill it with data from an input structure SIZE(rho_input) == mspin =...
subroutine, public qs_rho_scale_and_add(rhoa, rhob, alpha, beta)
rhoa = alpha*rhoa+beta*rhob
superstucture that hold various representations of the density and keeps track of which ones are vali...
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 qs_rho_release(rho_struct)
releases a rho_struct by decreasing the reference count by one and deallocating if it reaches 0 (to b...
subroutine, public qs_vxc_create(ks_env, rho_struct, xc_section, vxc_rho, vxc_tau, exc, just_energy, edisp, dispersion_env, adiabatic_rescale_factor, pw_env_external)
calculates and allocates the xc potential, already reducing it to the dependence on rho and the one o...
represent a group ofunctional derivatives
subroutine, public xc_dset_release(derivative_set)
releases a derivative set
type(xc_rho_cflags_type) function, public xc_functionals_get_needs(functionals, lsd, calc_potential)
...
subroutine, public xc_rho_set_release(rho_set, pw_pool)
releases the given rho_set
Exchange and Correlation functional calculations.
subroutine, public xc_calc_2nd_deriv(v_xc, v_xc_tau, deriv_set, rho_set, rho1_r, rho1_g, tau1_r, pw_pool, xc_section, gapw, vxg, do_excitations, do_triplet, compute_virial, virial_xc)
Caller routine to calculate the second order potential in the direction of rho1_r.
subroutine, public xc_prep_2nd_deriv(deriv_set, rho_set, rho_r, pw_pool, xc_section, tau_r)
Prepare objects for the calculation of the 2nd derivatives of the density functional....
contained for different pw related things
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.
A derivative set contains the different derivatives of a xc-functional in form of a linked list.
contains a flag for each component of xc_rho_set, so that you can use it to tell which components you...
represent a density, with all the representation and data needed to perform a functional evaluation