(git:374b731)
Loading...
Searching...
No Matches
xc_adiabatic_utils.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief
10!>
11!>
12!> \par History
13!> refactoring 03-2011 [MI]
14!> \author MI
15! **************************************************************************************************
17
19 USE dbcsr_api, ONLY: dbcsr_p_type
22 USE hfx_types, ONLY: hfx_type
29 USE kinds, ONLY: dp
31 USE pw_types, ONLY: pw_r3d_rs_type
36 USE qs_rho_types, ONLY: qs_rho_get,&
38 USE qs_vxc, ONLY: qs_vxc_create
41#include "./base/base_uses.f90"
42
43 IMPLICIT NONE
44
45 PRIVATE
46
47 ! *** Public subroutines ***
48 PUBLIC :: rescale_xc_potential
49
50 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xc_adiabatic_utils'
51
52CONTAINS
53
54! **************************************************************************************************
55!> \brief
56!>
57!> \param qs_env ...
58!> \param ks_matrix ...
59!> \param rho ...
60!> \param energy ...
61!> \param v_rspace_new ...
62!> \param v_tau_rspace ...
63!> \param hf_energy ...
64!> \param just_energy ...
65!> \param calculate_forces ...
66!> \param use_virial ...
67! **************************************************************************************************
68 SUBROUTINE rescale_xc_potential(qs_env, ks_matrix, rho, energy, v_rspace_new, v_tau_rspace, &
69 hf_energy, just_energy, calculate_forces, use_virial)
70
71 TYPE(qs_environment_type), POINTER :: qs_env
72 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix
73 TYPE(qs_rho_type), POINTER :: rho
74 TYPE(qs_energy_type), POINTER :: energy
75 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_rspace_new, v_tau_rspace
76 REAL(dp), DIMENSION(:) :: hf_energy
77 LOGICAL, INTENT(in) :: just_energy, calculate_forces, use_virial
78
79 CHARACTER(LEN=*), PARAMETER :: routinen = 'rescale_xc_potential'
80
81 INTEGER :: adiabatic_functional, adiabatic_model, &
82 handle, n_rep_hf, nimages
83 LOGICAL :: do_adiabatic_rescaling, do_hfx, gapw, &
84 gapw_xc
85 REAL(dp) :: adiabatic_lambda, adiabatic_omega, &
86 scale_ddfa, scale_ddw0, scale_dex1, &
87 scale_dex2, total_energy_xc
88 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao_resp
89 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: rho_ao
90 TYPE(dft_control_type), POINTER :: dft_control
91 TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data
92 TYPE(mp_para_env_type), POINTER :: para_env
93 TYPE(qs_ks_env_type), POINTER :: ks_env
94 TYPE(qs_rho_type), POINTER :: rho_xc
95 TYPE(section_vals_type), POINTER :: adiabatic_rescaling_section, &
96 hfx_sections, input, xc_section
97
98 CALL timeset(routinen, handle)
99 NULLIFY (para_env, dft_control, adiabatic_rescaling_section, hfx_sections, &
100 input, xc_section, rho_xc, ks_env, rho_ao, rho_ao_resp, x_data)
101
102 CALL get_qs_env(qs_env, &
103 dft_control=dft_control, &
104 para_env=para_env, &
105 input=input, &
106 rho_xc=rho_xc, &
107 ks_env=ks_env, &
108 x_data=x_data)
109
110 IF (x_data(1, 1)%do_hfx_ri) cpabort("RI-HFX not compatible with this kinf of functionals")
111 nimages = dft_control%nimages
112 cpassert(nimages == 1)
113
114 CALL qs_rho_get(rho, rho_ao_kp=rho_ao)
115
116 adiabatic_rescaling_section => section_vals_get_subs_vals(input, "DFT%XC%ADIABATIC_RESCALING")
117 CALL section_vals_get(adiabatic_rescaling_section, explicit=do_adiabatic_rescaling)
118 hfx_sections => section_vals_get_subs_vals(input, "DFT%XC%HF")
119 CALL section_vals_get(hfx_sections, explicit=do_hfx)
120 CALL section_vals_get(hfx_sections, n_repetition=n_rep_hf)
121
122 gapw = dft_control%qs_control%gapw
123 gapw_xc = dft_control%qs_control%gapw_xc
124
125 CALL section_vals_val_get(adiabatic_rescaling_section, "FUNCTIONAL_TYPE", &
126 i_val=adiabatic_functional)
127 CALL section_vals_val_get(adiabatic_rescaling_section, "FUNCTIONAL_MODEL", &
128 i_val=adiabatic_model)
129 CALL section_vals_val_get(adiabatic_rescaling_section, "LAMBDA", &
130 r_val=adiabatic_lambda)
131 CALL section_vals_val_get(adiabatic_rescaling_section, "OMEGA", &
132 r_val=adiabatic_omega)
133 SELECT CASE (adiabatic_functional)
135 SELECT CASE (adiabatic_model)
137 IF (n_rep_hf /= 2) &
138 CALL cp_abort(__location__, &
139 "For this kind of adiababatic hybrid functional 2 HF sections have to be provided. "// &
140 "Please check your input file.")
141 CALL rescale_mcy3_pade(qs_env, hf_energy, energy, adiabatic_lambda, &
142 adiabatic_omega, scale_dex1, scale_ddw0, scale_ddfa, &
143 scale_dex2, total_energy_xc)
144
145 !! Scale and add Fock matrix to KS matrix
146 IF (do_hfx) THEN
147 CALL scale_and_add_fock_to_ks_matrix(para_env, qs_env, ks_matrix, 1, &
148 scale_dex1)
149 CALL scale_and_add_fock_to_ks_matrix(para_env, qs_env, ks_matrix, 2, &
150 scale_dex2)
151 END IF
152 IF (calculate_forces) THEN
153 cpassert(.NOT. use_virial)
154 !! we also have to scale the forces!!!!
155 CALL derivatives_four_center(qs_env, rho_ao, rho_ao_resp, hfx_sections, &
156 para_env, 1, use_virial, &
157 adiabatic_rescale_factor=scale_dex1)
158 CALL derivatives_four_center(qs_env, rho_ao, rho_ao_resp, hfx_sections, &
159 para_env, 2, use_virial, &
160 adiabatic_rescale_factor=scale_dex2)
161 END IF
162
163 ! Calculate vxc and rescale it
164 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
165 IF (gapw_xc) THEN
166 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_xc, xc_section=xc_section, &
167 vxc_rho=v_rspace_new, vxc_tau=v_tau_rspace, exc=energy%exc, &
168 just_energy=just_energy, adiabatic_rescale_factor=scale_ddfa)
169 ELSE
170 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=xc_section, &
171 vxc_rho=v_rspace_new, vxc_tau=v_tau_rspace, exc=energy%exc, &
172 just_energy=just_energy, adiabatic_rescale_factor=scale_ddfa)
173 END IF
174
175 ! Calculate vxc and rescale it
176 IF (gapw .OR. gapw_xc) THEN
177 CALL calculate_vxc_atom(qs_env, just_energy, energy%exc1, adiabatic_rescale_factor=scale_ddfa)
178 END IF
179 !! Hack for the total energy expression
180 energy%ex = 0.0_dp
181 energy%exc1 = 0.0_dp
182 energy%exc = total_energy_xc
183
184 END SELECT
185 END SELECT
186 CALL timestop(handle)
187
188 END SUBROUTINE rescale_xc_potential
189
190END MODULE xc_adiabatic_utils
191
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
Routines for data exchange between MPI processes.
subroutine, public scale_and_add_fock_to_ks_matrix(para_env, qs_env, ks_matrix, irep, scaling_factor)
Distributes the local full Kohn-Sham matrix to all CPUS. Is called in case of adiabatic rescaling....
Routines to calculate derivatives with respect to basis function origin.
subroutine, public derivatives_four_center(qs_env, rho_ao, rho_ao_resp, hfx_section, para_env, irep, use_virial, adiabatic_rescale_factor, resp_only, external_x_data)
computes four center derivatives for a full basis set and updates the forcesfock_4c arrays....
Types and set/get functions for HFX.
Definition hfx_types.F:15
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_adiabatic_hybrid_mcy3
integer, parameter, public do_adiabatic_model_pade
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
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
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
Interface to the message passing library MPI.
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, 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_nonbond, sab_almo, sab_kp, sab_kp_nosym, 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, 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, ecoul_1c, rho0_s_rs, rho0_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, 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, rhs)
Get the QUICKSTEP environment.
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...
routines that build the integrals of the Vxc potential calculated for the atomic density in the basis...
Definition qs_vxc_atom.F:12
subroutine, public calculate_vxc_atom(qs_env, energy_only, exc1, gradient_atom_set, adiabatic_rescale_factor, kind_set_external, rho_atom_set_external, xc_section_external)
...
Definition qs_vxc_atom.F:87
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...
Definition qs_vxc.F:98
Contains some functions used in the context of adiabatic hybrid functionals.
subroutine, public rescale_mcy3_pade(qs_env, hf_energy, energy, adiabatic_lambda, adiabatic_omega, scale_dex1, scale_ddw0, scale_ddfa, scale_dex2, total_energy_xc)
Calculates rescaling factors for XC potentials and energy expression
subroutine, public rescale_xc_potential(qs_env, ks_matrix, rho, energy, v_rspace_new, v_tau_rspace, hf_energy, just_energy, calculate_forces, use_virial)
stores some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:509
stores all the informations relevant to an mpi environment
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.