(git:5e7fe52)
Loading...
Searching...
No Matches
qs_kernel_methods.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
13 USE kinds, ONLY: dp
14 USE pw_env_types, ONLY: pw_env_get,&
16 USE pw_methods, ONLY: pw_axpy,&
19 USE pw_types, ONLY: pw_c1d_gs_type,&
23 USE qs_fxc, ONLY: qs_fxc_prep
27 USE qs_rho_types, ONLY: qs_rho_create,&
32#include "./base/base_uses.f90"
33
34 IMPLICIT NONE
35
36 PRIVATE
37
38 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_kernel_methods'
39
40 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .false.
41
43
44CONTAINS
45
46! **************************************************************************************************
47!> \brief Create kernel environment.
48!> \param kernel_env kernel environment (allocated and initialised on exit)
49!> \param xc_section input section which defines an exchange-correlation functional
50!> \param is_rks_triplets indicates that the triplet excited states calculation using
51!> spin-unpolarised molecular orbitals has been requested
52!> \param rho_struct_sub ground state charge density, if not associated on input, it will be associated on output
53!> \param sub_env parallel group environment
54!> \param qs_env ...
55!> \par History
56!> * 02.2017 created [Sergey Chulkov]
57!> * 06.2018 the charge density needs to be provided via a dummy argument [Sergey Chulkov]
58! **************************************************************************************************
59 SUBROUTINE create_kernel_env(kernel_env, xc_section, is_rks_triplets, rho_struct_sub, &
60 sub_env, qs_env)
61 TYPE(full_kernel_env_type), INTENT(inout) :: kernel_env
62 TYPE(section_vals_type), INTENT(IN), POINTER :: xc_section
63 LOGICAL, INTENT(in) :: is_rks_triplets
64 TYPE(qs_rho_type), POINTER :: rho_struct_sub
65 TYPE(tddfpt_subgroup_env_type), INTENT(in) :: sub_env
66 TYPE(qs_environment_type), INTENT(in), POINTER :: qs_env
67
68 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_kernel_env'
69
70 INTEGER :: handle, nspins
71 TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
72 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
73 POINTER :: sab_orb
74 TYPE(pw_env_type), POINTER :: pw_env
75 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
76 TYPE(pw_r3d_rs_type), POINTER :: rho_nlcc, weights
77
78 CALL timeset(routinen, handle)
79
80 pw_env => sub_env%pw_env
81 dbcsr_dist => sub_env%dbcsr_dist
82 sab_orb => sub_env%sab_orb
83
84 nspins = SIZE(sub_env%mos_occ)
85
86 NULLIFY (weights, rho_nlcc)
87 weights => sub_env%xcint_weights
88 IF (sub_env%is_split .AND. ASSOCIATED(weights)) THEN
89 cpabort("Split communicators and integration weights")
90 END IF
91 CALL get_qs_env(qs_env, rho_nlcc=rho_nlcc)
92 IF (sub_env%is_split .AND. ASSOCIATED(rho_nlcc)) THEN
93 cpabort("Split communicators and NLCC not implemented")
94 END IF
95
96 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
97 IF (.NOT. ASSOCIATED(kernel_env%rho0_struct)) THEN
98 ALLOCATE (kernel_env%rho0_struct)
99 CALL qs_rho_create(kernel_env%rho0_struct)
100 END IF
101 CALL qs_rho_copy(rho_struct_sub, kernel_env%rho0_struct, auxbas_pw_pool, nspins)
102
103 ! ++ allocate structure for response density
104 kernel_env%xc_section => xc_section
105 ALLOCATE (kernel_env%xc_rho_set)
106 CALL qs_fxc_prep(qs_env, rho_struct_sub, &
107 kernel_env%xc_rho_set, kernel_env%xc_deriv_set, &
108 xc_section, pw_env, is_rks_triplets)
109
110 kernel_env%alpha = 1.0_dp
111 kernel_env%beta = 0.0_dp
112 ! kernel_env%beta is taken into account in spin-restricted case only
113 IF (nspins == 1) THEN
114 IF (is_rks_triplets) THEN
115 ! K_{triplets} = K_{alpha,alpha} - K_{alpha,beta}
116 kernel_env%beta = -1.0_dp
117 ELSE
118 ! alpha beta
119 ! K_{singlets} = K_{alpha,alpha} + K_{alpha,beta} = 2 * K_{alpha,alpha} + 0 * K_{alpha,beta},
120 ! due to the following relation : K_{alpha,alpha,singlets} == K_{alpha,beta,singlets}
121 kernel_env%alpha = 2.0_dp
122 END IF
123 END IF
124
125 ! finite differences
126 kernel_env%deriv2_analytic = section_get_lval(xc_section, "2ND_DERIV_ANALYTICAL")
127 kernel_env%deriv3_analytic = section_get_lval(xc_section, "3RD_DERIV_ANALYTICAL")
128
129 CALL timestop(handle)
130
131 END SUBROUTINE create_kernel_env
132
133! **************************************************************************************************
134!> \brief Create the xc kernel potential for the approximate Fxc kernel model
135!> \param rho_struct ...
136!> \param fxc_rspace ...
137!> \param xc_section ...
138!> \param is_rks_triplets ...
139!> \param sub_env ...
140!> \param qs_env ...
141! **************************************************************************************************
142 SUBROUTINE create_fxc_kernel(rho_struct, fxc_rspace, xc_section, is_rks_triplets, sub_env, qs_env)
143 TYPE(qs_rho_type), POINTER :: rho_struct
144 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: fxc_rspace
145 TYPE(section_vals_type), INTENT(IN), POINTER :: xc_section
146 LOGICAL, INTENT(IN) :: is_rks_triplets
147 TYPE(tddfpt_subgroup_env_type), INTENT(IN) :: sub_env
148 TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
149
150 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_fxc_kernel'
151
152 INTEGER :: handle, ispin, nspins
153 LOGICAL :: rho_g_valid, tau_r_valid
154 REAL(kind=dp) :: factor
155 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
156 TYPE(pw_c1d_gs_type), POINTER :: rho_nlcc_g
157 TYPE(pw_env_type), POINTER :: pw_env
158 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
159 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r, tau_r
160 TYPE(pw_r3d_rs_type), POINTER :: rho_nlcc
161 TYPE(section_vals_type), POINTER :: xc_kernel
162
163 CALL timeset(routinen, handle)
164
165 pw_env => sub_env%pw_env
166 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
167
168 NULLIFY (rho_r, rho_g, tau_r)
169 CALL qs_rho_get(rho_struct, &
170 tau_r_valid=tau_r_valid, &
171 rho_g_valid=rho_g_valid, &
172 rho_r=rho_r, &
173 rho_g=rho_g, &
174 tau_r=tau_r)
175
176 IF (.NOT. tau_r_valid) NULLIFY (tau_r)
177 IF (.NOT. rho_g_valid) NULLIFY (rho_g)
178
179 nspins = SIZE(rho_r)
180
181 NULLIFY (rho_nlcc, rho_nlcc_g)
182 CALL get_qs_env(qs_env, &
183 rho_nlcc=rho_nlcc, &
184 rho_nlcc_g=rho_nlcc_g)
185 ! add the nlcc densities
186 IF (ASSOCIATED(rho_nlcc)) THEN
187 factor = 1.0_dp
188 DO ispin = 1, nspins
189 CALL pw_axpy(rho_nlcc, rho_r(ispin), factor)
190 CALL pw_axpy(rho_nlcc_g, rho_g(ispin), factor)
191 END DO
192 END IF
193
194 DO ispin = 1, SIZE(fxc_rspace)
195 CALL pw_zero(fxc_rspace(ispin))
196 END DO
197
198 xc_kernel => section_vals_get_subs_vals(xc_section, "XC_KERNEL")
199 CALL calc_fxc_kernel(fxc_rspace, rho_r, rho_g, tau_r, &
200 xc_kernel, is_rks_triplets, auxbas_pw_pool)
201
202 ! remove the nlcc densities (keep stuff in original state)
203 IF (ASSOCIATED(rho_nlcc)) THEN
204 factor = -1.0_dp
205 DO ispin = 1, nspins
206 CALL pw_axpy(rho_nlcc, rho_r(ispin), factor)
207 CALL pw_axpy(rho_nlcc_g, rho_g(ispin), factor)
208 END DO
209 END IF
210
211 CALL timestop(handle)
212
213 END SUBROUTINE create_fxc_kernel
214
215END MODULE qs_kernel_methods
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
logical function, public section_get_lval(section_vals, keyword_name)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
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 ...
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.
Setup Routine for Fxc Potentials.
Definition qs_fxc.F:29
subroutine, public qs_fxc_prep(qs_env, rho0_struct, xc_rho_set, xc_deriv_set, xc_section, pw_env_ext, is_triplet)
...
Definition qs_fxc.F:518
subroutine, public create_kernel_env(kernel_env, xc_section, is_rks_triplets, rho_struct_sub, sub_env, qs_env)
Create kernel environment.
subroutine, public create_fxc_kernel(rho_struct, fxc_rspace, xc_section, is_rks_triplets, sub_env, qs_env)
Create the xc kernel potential for the approximate Fxc kernel model.
Define the neighbor list data types and the corresponding functionality.
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_copy(rho_input, rho_output, auxbas_pw_pool, mspin, factor)
Allocate a density structure and fill it with data from an input structure SIZE(rho_input) == mspin =...
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.
Exchange and Correlation kernel functionals.
subroutine, public calc_fxc_kernel(fxc_rspace, rho_r, rho_g, tau_r, xc_kernel, triplet, pw_pool)
Exchange and Correlation kernel functional calculations.
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 ...
Collection of variables required to evaluate adiabatic TDDFPT kernel.
keeps the density in various representations, keeping track of which ones are valid.