(git:0a7030e)
Loading...
Searching...
No Matches
qs_harris_types.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 Types needed for a for a Harris model calculation
10!> \par History
11!> 2024.07 created
12!> \author JGH
13! **************************************************************************************************
20 USE kinds, ONLY: default_string_length,&
21 dp
22 USE pw_types, ONLY: pw_r3d_rs_type
23 USE qs_kind_types, ONLY: get_qs_kind,&
25#include "./base/base_uses.f90"
26
27 IMPLICIT NONE
28
29 PRIVATE
30
31 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_harris_types'
32
33! *****************************************************************************
34 TYPE rho_vec_type
35 REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: rvecs
36 END TYPE rho_vec_type
37
39 CHARACTER(LEN=default_string_length) :: basis_type = "NDef"
40 TYPE(rho_vec_type), ALLOCATABLE, DIMENSION(:, :) :: rhovec
41 TYPE(rho_vec_type), ALLOCATABLE, DIMENSION(:, :) :: intvec
42 INTEGER :: nspin = 0
43 INTEGER :: nbas = 0
44 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: basptr
45 LOGICAL :: frozen = .false.
46 END TYPE harris_rhoin_type
47
49 REAL(kind=dp) :: eharris = 0.0_dp
50 REAL(kind=dp) :: eband = 0.0_dp
51 REAL(kind=dp) :: exc_correction = 0.0_dp
52 REAL(kind=dp) :: eh_correction = 0.0_dp
53 REAL(kind=dp) :: ewald_correction = 0.0_dp
54 REAL(kind=dp) :: dispersion = 0.0_dp
55 REAL(kind=dp) :: trial_dm = 0.0_dp
56 REAL(kind=dp) :: direct_harris = 0.0_dp
57 REAL(kind=dp) :: direct_difference = 0.0_dp
58 END TYPE harris_energy_type
59
60! *****************************************************************************
61!> \brief Contains information on the Harris method
62!> \par History
63!> 07.2024 created
64!> \author JGH
65! *****************************************************************************
67 INTEGER :: energy_functional = 0
68 INTEGER :: density_source = 0
69 INTEGER :: orbital_basis = 0
70 CHARACTER(LEN=default_string_length) :: density_filename = ""
71 INTEGER :: fit_max_iter = 50
72 INTEGER :: fit_max_backtrack = 20
73 INTEGER :: fit_method = 0
74 REAL(kind=dp) :: fit_eps = 1.0e-3_dp
75 REAL(kind=dp) :: fit_step_size = 1.0_dp
76 REAL(kind=dp) :: fit_temperature = 0.0_dp
77 REAL(kind=dp) :: fit_relative_entropy_weight = 1.0e-3_dp
78 LOGICAL :: density_fit_ready = .false.
79 LOGICAL :: density_target_ready = .false.
80 LOGICAL :: direct_density_matrix_energy = .false.
81 !
82 TYPE(harris_energy_type) :: energy
83 !
84 TYPE(harris_rhoin_type) :: rhoin
85 !
86 TYPE(pw_r3d_rs_type) :: vh_rspace = pw_r3d_rs_type()
87 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: vxc_rspace => null()
88 TYPE(pw_r3d_rs_type) :: density_fit_rspace = pw_r3d_rs_type()
89 TYPE(pw_r3d_rs_type) :: density_target_rspace = pw_r3d_rs_type()
90
91 !
92 LOGICAL :: debug_forces = .false.
93 LOGICAL :: debug_stress = .false.
94 END TYPE harris_type
95! **************************************************************************************************
96
99
100! **************************************************************************************************
101
102CONTAINS
103
104! **************************************************************************************************
105
106! **************************************************************************************************
107!> \brief ...
108!> \param iounit ...
109!> \param energy ...
110! **************************************************************************************************
111 SUBROUTINE harris_print_energy(iounit, energy)
112 INTEGER, INTENT(IN) :: iounit
113 TYPE(harris_energy_type) :: energy
114
115 IF (iounit > 0) THEN
116 WRITE (unit=iounit, fmt="(/,(T2,A))") "HARRIS MODEL ENERGY INFORMATION"
117 WRITE (unit=iounit, fmt="((T3,A,T56,F25.14))") &
118 "Harris model energy: ", energy%eharris, &
119 "Band energy: ", energy%eband, &
120 "Hartree correction energy: ", energy%eh_correction, &
121 "XC correction energy: ", energy%exc_correction, &
122 "Ewald sum correction energy: ", energy%ewald_correction, &
123 "Dispersion energy (pair potential): ", energy%dispersion
124 END IF
125
126 END SUBROUTINE harris_print_energy
127
128! **************************************************************************************************
129!> \brief Prints the two direct fitted-density-matrix energy evaluations.
130!> \param iounit Output unit
131!> \param energy Harris energy data
132! **************************************************************************************************
133 SUBROUTINE harris_print_direct_energy(iounit, energy)
134 INTEGER, INTENT(IN) :: iounit
135 TYPE(harris_energy_type), INTENT(IN) :: energy
136
137 IF (iounit > 0) THEN
138 WRITE (unit=iounit, fmt="(/,(T2,A))") "HARRIS DIRECT DENSITY MATRIX ENERGY INFORMATION"
139 WRITE (unit=iounit, fmt="((T3,A,T56,F25.14))") &
140 "Consistent trial-DM energy: ", energy%trial_dm, &
141 "Harris-like fitted-DM/cube energy: ", energy%direct_harris, &
142 "Trial-DM minus Harris-like energy: ", energy%direct_difference
143 END IF
144
145 END SUBROUTINE harris_print_direct_energy
146
147! **************************************************************************************************
148!> \brief ...
149!> \param rhoin ...
150!> \param basis_type ...
151!> \param qs_kind_set ...
152!> \param atomic_kind_set ...
153!> \param local_particles ...
154!> \param nspin ...
155! **************************************************************************************************
156 SUBROUTINE harris_rhoin_init(rhoin, basis_type, qs_kind_set, atomic_kind_set, &
157 local_particles, nspin)
158 TYPE(harris_rhoin_type) :: rhoin
159 CHARACTER(LEN=*) :: basis_type
160 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
161 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
162 TYPE(distribution_1d_type), POINTER :: local_particles
163 INTEGER, INTENT(IN) :: nspin
164
165 INTEGER :: iatom, ikind, iptr, ispin, natom, nkind, &
166 nparticle_local, nsgf
167 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, kind_of, nbasf
168 TYPE(gto_basis_set_type), POINTER :: basis_set
169 TYPE(qs_kind_type), POINTER :: qs_kind
170
171 CALL harris_rhoin_release(rhoin)
172
173 rhoin%basis_type = basis_type
174 rhoin%nspin = nspin
175
176 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
177 atom_of_kind=atom_of_kind, kind_of=kind_of)
178 natom = SIZE(atom_of_kind)
179 nkind = SIZE(qs_kind_set)
180
181 ALLOCATE (nbasf(nkind))
182 DO ikind = 1, nkind
183 qs_kind => qs_kind_set(ikind)
184 CALL get_qs_kind(qs_kind, basis_set=basis_set, basis_type=basis_type)
185 CALL get_gto_basis_set(basis_set, nsgf=nsgf)
186 nbasf(ikind) = nsgf
187 END DO
188
189 ALLOCATE (rhoin%basptr(natom, 2))
190 iptr = 1
191 DO iatom = 1, natom
192 ikind = kind_of(iatom)
193 rhoin%basptr(iatom, 1) = iptr
194 iptr = iptr + nbasf(ikind)
195 rhoin%basptr(iatom, 2) = iptr - 1
196 END DO
197 rhoin%nbas = iptr - 1
198
199 ALLOCATE (rhoin%rhovec(nkind, nspin))
200 DO ispin = 1, nspin
201 DO ikind = 1, nkind
202 nsgf = nbasf(ikind)
203 nparticle_local = local_particles%n_el(ikind)
204 ALLOCATE (rhoin%rhovec(ikind, ispin)%rvecs(nsgf, nparticle_local))
205 END DO
206 END DO
207
208 ALLOCATE (rhoin%intvec(nkind, nspin))
209 DO ispin = 1, nspin
210 DO ikind = 1, nkind
211 nsgf = nbasf(ikind)
212 nparticle_local = local_particles%n_el(ikind)
213 ALLOCATE (rhoin%intvec(ikind, ispin)%rvecs(nsgf, nparticle_local))
214 END DO
215 END DO
216
217 DEALLOCATE (nbasf)
218
219 END SUBROUTINE harris_rhoin_init
220
221! **************************************************************************************************
222!> \brief ...
223!> \param harris_env ...
224! **************************************************************************************************
225 SUBROUTINE harris_env_release(harris_env)
226 TYPE(harris_type), POINTER :: harris_env
227
228 INTEGER :: iab
229
230 IF (ASSOCIATED(harris_env)) THEN
231 !
232 CALL harris_rhoin_release(harris_env%rhoin)
233 !
234 IF (ASSOCIATED(harris_env%vh_rspace%pw_grid)) THEN
235 CALL harris_env%vh_rspace%release()
236 END IF
237 IF (ASSOCIATED(harris_env%density_fit_rspace%pw_grid)) THEN
238 CALL harris_env%density_fit_rspace%release()
239 END IF
240 IF (ASSOCIATED(harris_env%density_target_rspace%pw_grid)) THEN
241 CALL harris_env%density_target_rspace%release()
242 END IF
243 IF (ASSOCIATED(harris_env%vxc_rspace)) THEN
244 DO iab = 1, SIZE(harris_env%vxc_rspace)
245 CALL harris_env%vxc_rspace(iab)%release()
246 END DO
247 DEALLOCATE (harris_env%vxc_rspace)
248 END IF
249 !
250 DEALLOCATE (harris_env)
251 END IF
252
253 NULLIFY (harris_env)
254
255 END SUBROUTINE harris_env_release
256
257! **************************************************************************************************
258!> \brief ...
259!> \param rhoin ...
260! **************************************************************************************************
261 SUBROUTINE harris_rhoin_release(rhoin)
262 TYPE(harris_rhoin_type) :: rhoin
263
264 INTEGER :: i, j
265
266 IF (ALLOCATED(rhoin%rhovec)) THEN
267 DO i = 1, SIZE(rhoin%rhovec, 2)
268 DO j = 1, SIZE(rhoin%rhovec, 1)
269 IF (ALLOCATED(rhoin%rhovec(j, i)%rvecs)) THEN
270 DEALLOCATE (rhoin%rhovec(j, i)%rvecs)
271 END IF
272 END DO
273 END DO
274 DEALLOCATE (rhoin%rhovec)
275 END IF
276 IF (ALLOCATED(rhoin%intvec)) THEN
277 DO i = 1, SIZE(rhoin%intvec, 2)
278 DO j = 1, SIZE(rhoin%intvec, 1)
279 IF (ALLOCATED(rhoin%intvec(j, i)%rvecs)) THEN
280 DEALLOCATE (rhoin%intvec(j, i)%rvecs)
281 END IF
282 END DO
283 END DO
284 DEALLOCATE (rhoin%intvec)
285 END IF
286 IF (ALLOCATED(rhoin%basptr)) THEN
287 DEALLOCATE (rhoin%basptr)
288 END IF
289 rhoin%basis_type = "NDef"
290 rhoin%nspin = 0
291 rhoin%nbas = 0
292 rhoin%frozen = .false.
293
294 END SUBROUTINE harris_rhoin_release
295
296END MODULE qs_harris_types
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum, ccon)
...
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
Types needed for a for a Harris model calculation.
subroutine, public harris_env_release(harris_env)
...
subroutine, public harris_rhoin_init(rhoin, basis_type, qs_kind_set, atomic_kind_set, local_particles, nspin)
...
subroutine, public harris_print_direct_energy(iounit, energy)
Prints the two direct fitted-density-matrix energy evaluations.
subroutine, public harris_print_energy(iounit, energy)
...
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
Provides all information about an atomic kind.
structure to store local (to a processor) ordered lists of integers.
Contains information on the Harris method.
Provides all information about a quickstep kind.