(git:8dea62c)
Loading...
Searching...
No Matches
ec_env_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 Energy Correction
10!> \par History
11!> 2019.09 created
12!> \author JGH
13! **************************************************************************************************
15 USE cp_dbcsr_api, ONLY: dbcsr_p_type
17 USE cp_fm_types, ONLY: cp_fm_release,&
21 USE hfx_types, ONLY: hfx_release,&
25 USE kinds, ONLY: dp
26 USE kpoint_types, ONLY: kpoint_release,&
28 USE pw_types, ONLY: pw_r3d_rs_type
39 USE qs_p_env_types, ONLY: p_env_release,&
46#include "./base/base_uses.f90"
47
48 IMPLICIT NONE
49
50 PRIVATE
51
52 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ec_env_types'
53
56
57! *****************************************************************************
58!> \brief Contains information on the energy correction functional for KG
59!> \par History
60!> 03.2014 created
61!> \author JGH
62! *****************************************************************************
64 CHARACTER(len=20) :: ec_name = ""
65 INTEGER :: energy_functional = 0
66 INTEGER :: ks_solver = 0
67 INTEGER :: factorization = 0
68 INTEGER :: ec_initial_guess = 0
69 REAL(kind=dp) :: eps_default = 0.0_dp
70 LOGICAL :: do_ec_admm = .false.
71 LOGICAL :: do_ec_hfx = .false.
72 LOGICAL :: should_update = .false.
73 LOGICAL :: use_ls_solver = .false.
74 LOGICAL :: reuse_hfx = .false.
75 LOGICAL :: basis_inconsistent = .false.
76 !
77 LOGICAL :: write_harris_wfn = .false.
78 ! debug
79 LOGICAL :: debug_forces = .false.
80 LOGICAL :: debug_stress = .false.
81 LOGICAL :: debug_external = .false.
82 REAL(kind=dp) :: orbrot_index = 0.0_dp
83 REAL(kind=dp) :: phase_index = 0.0_dp
84 ! basis set
85 CHARACTER(len=20) :: basis = ""
86 LOGICAL :: mao = .false.
87 ! Skip EC calculation if ground-state didnt converge
88 LOGICAL :: do_skip = .false., skip_ec = .false.
89 ! MAO basis
90 INTEGER :: mao_max_iter = 0
91 REAL(kind=dp) :: mao_eps_grad = 0.0_dp
92 REAL(kind=dp) :: mao_eps1 = 0.0_dp
93 INTEGER :: mao_iolevel = 0
94 !
95 TYPE(smear_type) :: smear
96 ! energy components
97 REAL(kind=dp) :: etotal = 0.0_dp, old_etotal = 0.0_dp
98 REAL(kind=dp) :: eband = 0.0_dp, ecore = 0.0_dp, exc = 0.0_dp, &
99 ehartree = 0.0_dp, vhxc = 0.0_dp
100 REAL(kind=dp) :: edispersion = 0.0_dp, efield_elec = 0.0_dp, &
101 efield_nuclear = 0.0_dp, ex = 0.0_dp, exc_aux_fit = 0.0_dp
102 REAL(kind=dp) :: exc1 = 0.0_dp, exc1_aux_fit = 0.0_dp, ehartree_1c = 0.0_dp
103 REAL(kind=dp) :: ekts = 0.0_dp
104 ! forces
105 TYPE(qs_force_type), DIMENSION(:), POINTER :: force => null()
106 ! full neighbor lists and corresponding task list
108 DIMENSION(:), POINTER :: sab_orb => null(), sac_ppl => null(), &
109 sac_ae => null(), sap_ppnl => null(), &
110 sab_kp => null(), sab_kp_nosym => null(), &
111 sap_oce => null()
112 TYPE(task_list_type), POINTER :: task_list => null()
113 TYPE(task_list_type), POINTER :: task_list_soft => null()
114 ! the XC function to be used for the correction, dispersion info
115 TYPE(section_vals_type), POINTER :: xc_section => null()
116 TYPE(qs_dispersion_type), POINTER :: dispersion_env => null()
117 ! kpoint information
118 LOGICAL :: do_kpoints = .false.
119 TYPE(kpoint_type), POINTER :: kpoints => null()
120 ! matrices in complete basis
121 ! KS: Kohn-Sham; H: Core; S: overlap; T: kinetic energy;
122 ! P: Harris density, W: Harris energy weighted density
123 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks => null(), &
124 matrix_h => null(), &
125 matrix_s => null(), &
126 matrix_t => null(), &
127 matrix_p => null(), &
128 matrix_w => null()
129 ! GAPW
130 TYPE(local_rho_type), POINTER :: local_rho_set => null()
131 TYPE(local_rho_type), POINTER :: local_rho_set_admm => null()
132 TYPE(oce_matrix_type), POINTER :: oce => null()
133 ! reduce basis
134 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mao_coef => null()
135 ! external energy calclulation
136 TYPE(cp_fm_type), DIMENSION(:), POINTER :: mo_occ => null()
137 TYPE(cp_fm_type), DIMENSION(:), POINTER :: cpmos => null()
138 ! CP equations
139 TYPE(qs_p_env_type), POINTER :: p_env => null()
140 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hz => null(), matrix_wz => null(), &
141 matrix_z => null(), z_admm => null()
142 ! Harris (rhoout), and response density (rhoz) on grid
143 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rhoout_r => null(), &
144 rhoz_r => null()
145 ! potentials from input density
146 TYPE(pw_r3d_rs_type) :: vh_rspace = pw_r3d_rs_type()
147 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: vxc_rspace => null(), &
148 vtau_rspace => null(), &
149 vadmm_rspace => null(), &
150 vadmm_tau_rspace => null()
151 ! efield
152 TYPE(efield_berry_type), POINTER :: efield => null()
153 ! LS matrices and types
154 TYPE(ls_scf_env_type), POINTER :: ls_env => null()
155 ! Environment for Hartree-Fock exchange
156 TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data => null()
157 ! ADMM XC environments
158 TYPE(section_vals_type), POINTER :: xc_section_primary => null(), &
159 xc_section_aux => null()
160 ! External
161 CHARACTER(len=40) :: exresp_fn = ""
162 CHARACTER(len=40) :: exresperr_fn = ""
163 CHARACTER(len=40) :: exresult_fn = ""
164 LOGICAL :: do_error = .false.
165 CHARACTER(len=1) :: error_method = "E"
166 REAL(kind=dp) :: error_cutoff = 0.0_dp
167 INTEGER :: error_subspace = 0
168 REAL(kind=dp), DIMENSION(3, 3) :: rpv = 0.0_dp
169 REAL(kind=dp), DIMENSION(:, :), POINTER :: rf => null()
170 TYPE(cp_fm_type), DIMENSION(:), POINTER :: cpref => null()
172
173CONTAINS
174
175! **************************************************************************************************
176!> \brief ...
177!> \param ec_env ...
178! **************************************************************************************************
179 SUBROUTINE ec_env_release(ec_env)
180 TYPE(energy_correction_type), POINTER :: ec_env
181
182 CHARACTER(LEN=*), PARAMETER :: routinen = 'ec_env_release'
183
184 INTEGER :: handle
185
186 CALL timeset(routinen, handle)
187
188 IF (ASSOCIATED(ec_env)) THEN
189 ! neighbor lists
190 CALL release_neighbor_list_sets(ec_env%sab_orb)
191 CALL release_neighbor_list_sets(ec_env%sac_ppl)
192 CALL release_neighbor_list_sets(ec_env%sac_ae)
193 CALL release_neighbor_list_sets(ec_env%sap_ppnl)
194 CALL release_neighbor_list_sets(ec_env%sab_kp)
195 CALL release_neighbor_list_sets(ec_env%sab_kp_nosym)
196 CALL release_neighbor_list_sets(ec_env%sap_oce)
197 ! forces
198 IF (ASSOCIATED(ec_env%force)) CALL deallocate_qs_force(ec_env%force)
199 ! operator matrices
200 IF (ASSOCIATED(ec_env%matrix_ks)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
201 IF (ASSOCIATED(ec_env%matrix_h)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_h)
202 IF (ASSOCIATED(ec_env%matrix_s)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_s)
203 IF (ASSOCIATED(ec_env%matrix_t)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_t)
204 IF (ASSOCIATED(ec_env%matrix_p)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_p)
205 IF (ASSOCIATED(ec_env%matrix_w)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_w)
206 ! GAPW
207 IF (ASSOCIATED(ec_env%oce)) CALL deallocate_oce_set(ec_env%oce)
208 ! task lists for collocate/integrate
209 IF (ASSOCIATED(ec_env%task_list)) THEN
210 CALL deallocate_task_list(ec_env%task_list)
211 END IF
212 IF (ASSOCIATED(ec_env%task_list_soft)) THEN
213 CALL deallocate_task_list(ec_env%task_list_soft)
214 END IF
215 ! reduced basis
216 IF (ASSOCIATED(ec_env%mao_coef)) CALL dbcsr_deallocate_matrix_set(ec_env%mao_coef)
217 ! dispersion environment
218 IF (ASSOCIATED(ec_env%dispersion_env)) THEN
219 CALL qs_dispersion_release(ec_env%dispersion_env)
220 END IF
221
222 CALL ec_env_matrix_release(ec_env)
223
224 ! kpoints
225 CALL kpoint_release(ec_env%kpoints)
226
227 IF (ASSOCIATED(ec_env%p_env)) THEN
228 CALL p_env_release(ec_env%p_env)
229 DEALLOCATE (ec_env%p_env)
230 END IF
231 ! potential
232 CALL ec_env_potential_release(ec_env)
233 !
234 CALL efield_berry_release(ec_env%efield)
235
236 IF (ASSOCIATED(ec_env%ls_env)) THEN
237 CALL ls_scf_release(ec_env%ls_env)
238 END IF
239
240 IF (.NOT. ec_env%reuse_hfx) THEN
241 IF (ASSOCIATED(ec_env%x_data)) CALL hfx_release(ec_env%x_data)
242 END IF
243
244 IF (ASSOCIATED(ec_env%xc_section_aux)) CALL section_vals_release(ec_env%xc_section_aux)
245 IF (ASSOCIATED(ec_env%xc_section_primary)) CALL section_vals_release(ec_env%xc_section_primary)
246
247 CALL cp_fm_release(ec_env%mo_occ)
248 CALL cp_fm_release(ec_env%cpmos)
249 CALL cp_fm_release(ec_env%cpref)
250
251 IF (ASSOCIATED(ec_env%rf)) THEN
252 DEALLOCATE (ec_env%rf)
253 END IF
254
255 DEALLOCATE (ec_env)
256
257 END IF
258
259 NULLIFY (ec_env)
260
261 CALL timestop(handle)
262
263 END SUBROUTINE ec_env_release
264
265! **************************************************************************************************
266!> \brief ...
267!> \param ec_env ...
268! **************************************************************************************************
269 SUBROUTINE ec_env_matrix_release(ec_env)
270 TYPE(energy_correction_type), POINTER :: ec_env
271
272 IF (ASSOCIATED(ec_env)) THEN
273 IF (ASSOCIATED(ec_env%matrix_hz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_hz)
274 NULLIFY (ec_env%matrix_hz)
275 IF (ASSOCIATED(ec_env%matrix_wz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_wz)
276 NULLIFY (ec_env%matrix_wz)
277 IF (ASSOCIATED(ec_env%matrix_z)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_z)
278 NULLIFY (ec_env%matrix_z)
279 IF (ASSOCIATED(ec_env%z_admm)) CALL dbcsr_deallocate_matrix_set(ec_env%z_admm)
280 NULLIFY (ec_env%z_admm)
281 END IF
282
283 END SUBROUTINE ec_env_matrix_release
284
285! **************************************************************************************************
286!> \brief ...
287!> \param ec_env ...
288! **************************************************************************************************
289 SUBROUTINE ec_env_potential_release(ec_env)
290 TYPE(energy_correction_type), POINTER :: ec_env
291
292 INTEGER :: iab
293
294 IF (ASSOCIATED(ec_env)) THEN
295 IF (ASSOCIATED(ec_env%vh_rspace%pw_grid)) THEN
296 CALL ec_env%vh_rspace%release()
297 END IF
298 IF (ASSOCIATED(ec_env%vxc_rspace)) THEN
299 DO iab = 1, SIZE(ec_env%vxc_rspace)
300 CALL ec_env%vxc_rspace(iab)%release()
301 END DO
302 DEALLOCATE (ec_env%vxc_rspace)
303 NULLIFY (ec_env%vxc_rspace)
304 END IF
305 IF (ASSOCIATED(ec_env%vtau_rspace)) THEN
306 DO iab = 1, SIZE(ec_env%vtau_rspace)
307 CALL ec_env%vtau_rspace(iab)%release()
308 END DO
309 DEALLOCATE (ec_env%vtau_rspace)
310 NULLIFY (ec_env%vtau_rspace)
311 END IF
312 IF (ASSOCIATED(ec_env%vadmm_rspace)) THEN
313 DO iab = 1, SIZE(ec_env%vadmm_rspace)
314 CALL ec_env%vadmm_rspace(iab)%release()
315 END DO
316 DEALLOCATE (ec_env%vadmm_rspace)
317 NULLIFY (ec_env%vadmm_rspace)
318 END IF
319 IF (ASSOCIATED(ec_env%vadmm_tau_rspace)) THEN
320 DO iab = 1, SIZE(ec_env%vadmm_tau_rspace)
321 CALL ec_env%vadmm_tau_rspace(iab)%release()
322 END DO
323 DEALLOCATE (ec_env%vadmm_tau_rspace)
324 NULLIFY (ec_env%vadmm_tau_rspace)
325 END IF
326 IF (ASSOCIATED(ec_env%local_rho_set)) THEN
327 CALL local_rho_set_release(ec_env%local_rho_set)
328 NULLIFY (ec_env%local_rho_set)
329 END IF
330 IF (ASSOCIATED(ec_env%local_rho_set_admm)) THEN
331 CALL local_rho_set_release(ec_env%local_rho_set_admm)
332 NULLIFY (ec_env%local_rho_set_admm)
333 END IF
334 END IF
335
336 END SUBROUTINE ec_env_potential_release
337
338END MODULE ec_env_types
DBCSR operations in CP2K.
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
Types needed for a linear scaling quickstep SCF run based on the density matrix.
subroutine, public ls_scf_release(ls_scf_env)
release the LS type.
Types needed for a for a Energy Correction.
subroutine, public ec_env_potential_release(ec_env)
...
subroutine, public ec_env_matrix_release(ec_env)
...
subroutine, public ec_env_release(ec_env)
...
Types and set/get functions for HFX.
Definition hfx_types.F:15
subroutine, public hfx_release(x_data)
This routine deallocates all data structures
Definition hfx_types.F:1960
objects that represent the structure of input sections and the data contained in an input section
recursive subroutine, public section_vals_release(section_vals)
releases the given object
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_release(kpoint)
Release a kpoint environment, deallocate all data.
Definition of disperson types for DFT calculations.
subroutine, public qs_dispersion_release(dispersion_env)
...
subroutine, public deallocate_qs_force(qs_force)
Deallocate a Quickstep force data structure.
subroutine, public local_rho_set_release(local_rho_set)
...
Define the neighbor list data types and the corresponding functionality.
subroutine, public release_neighbor_list_sets(nlists)
releases an array of neighbor_list_sets
subroutine, public deallocate_oce_set(oce_set)
Deallocate the matrix set of oce coefficients.
basis types for the calculation of the perturbation of density theory.
subroutine, public p_env_release(p_env)
relases the given p_env (see doc/ReferenceCounting.html)
type for berry phase efield matrices. At the moment only used for cosmat and sinmat
subroutine, public efield_berry_release(efield)
...
parameters that control an scf iteration
types for task lists
subroutine, public deallocate_task_list(task_list)
deallocates the components and the object itself
represent a full matrix
Contains information on the energy correction functional for KG.
stores some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:511
Contains information about kpoints.
Represent a qs system that is perturbed. Can calculate the linear operator and the rhs of the system ...
contains the parameters needed by a scf run