(git:30099c3)
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 pw_types, ONLY: pw_r3d_rs_type
37 USE qs_p_env_types, ONLY: p_env_release,&
43#include "./base/base_uses.f90"
44
45 IMPLICIT NONE
46
47 PRIVATE
48
49 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ec_env_types'
50
53
54! *****************************************************************************
55!> \brief Contains information on the energy correction functional for KG
56!> \par History
57!> 03.2014 created
58!> \author JGH
59! *****************************************************************************
61 CHARACTER(len=20) :: ec_name = ""
62 INTEGER :: energy_functional = 0
63 INTEGER :: ks_solver = 0
64 INTEGER :: factorization = 0
65 INTEGER :: ec_initial_guess = 0
66 REAL(kind=dp) :: eps_default = 0.0_dp
67 LOGICAL :: do_ec_admm = .false.
68 LOGICAL :: do_ec_hfx = .false.
69 LOGICAL :: should_update = .false.
70 LOGICAL :: use_ls_solver = .false.
71 LOGICAL :: reuse_hfx = .false.
72 LOGICAL :: basis_inconsistent = .false.
73 ! debug
74 LOGICAL :: debug_forces = .false.
75 LOGICAL :: debug_stress = .false.
76 LOGICAL :: debug_external = .false.
77 REAL(kind=dp) :: orbrot_index = 0.0_dp
78 REAL(kind=dp) :: phase_index = 0.0_dp
79 ! basis set
80 CHARACTER(len=20) :: basis = ""
81 LOGICAL :: mao = .false.
82 ! Skip EC calculation if ground-state didnt converge
83 LOGICAL :: do_skip = .false., skip_ec = .false.
84 INTEGER :: mao_max_iter = 0
85 REAL(kind=dp) :: mao_eps_grad = 0.0_dp
86 REAL(kind=dp) :: mao_eps1 = 0.0_dp
87 INTEGER :: mao_iolevel = 0
88 ! energy components
89 REAL(kind=dp) :: etotal = 0.0_dp, old_etotal = 0.0_dp
90 REAL(kind=dp) :: eband = 0.0_dp, ecore = 0.0_dp, exc = 0.0_dp, &
91 ehartree = 0.0_dp, vhxc = 0.0_dp
92 REAL(kind=dp) :: edispersion = 0.0_dp, efield_elec = 0.0_dp, &
93 efield_nuclear = 0.0_dp, ex = 0.0_dp, exc_aux_fit = 0.0_dp
94 REAL(kind=dp) :: exc1 = 0.0_dp, exc1_aux_fit = 0.0_dp, ehartree_1c = 0.0_dp
95 ! forces
96 TYPE(qs_force_type), DIMENSION(:), POINTER :: force => null()
97 ! full neighbor lists and corresponding task list
99 DIMENSION(:), POINTER :: sab_orb => null(), sac_ppl => null(), &
100 sac_ae => null(), sap_ppnl => null(), &
101 sap_oce => null()
102 TYPE(task_list_type), POINTER :: task_list => null()
103 TYPE(task_list_type), POINTER :: task_list_soft => null()
104 ! the XC function to be used for the correction, dispersion info
105 TYPE(section_vals_type), POINTER :: xc_section => null()
106 TYPE(qs_dispersion_type), POINTER :: dispersion_env => null()
107 ! matrices in complete basis
108 ! KS: Kohn-Sham; H: Core; S: overlap; T: kinetic energy;
109 ! P: Harris density, W: Harris energy weighted density
110 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks => null(), &
111 matrix_h => null(), &
112 matrix_s => null(), &
113 matrix_t => null(), &
114 matrix_p => null(), &
115 matrix_w => null()
116 ! GAPW
117 TYPE(local_rho_type), POINTER :: local_rho_set => null()
118 TYPE(local_rho_type), POINTER :: local_rho_set_admm => null()
119 TYPE(oce_matrix_type), POINTER :: oce => null()
120 ! reduce basis
121 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mao_coef => null()
122 ! external energy calclulation
123 TYPE(cp_fm_type), DIMENSION(:), POINTER :: mo_occ => null()
124 TYPE(cp_fm_type), DIMENSION(:), POINTER :: cpmos => null()
125 ! CP equations
126 TYPE(qs_p_env_type), POINTER :: p_env => null()
127 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hz => null(), matrix_wz => null(), &
128 matrix_z => null(), z_admm => null()
129 ! Harris (rhoout), and response density (rhoz) on grid
130 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rhoout_r => null(), &
131 rhoz_r => null()
132 ! potentials from input density
133 TYPE(pw_r3d_rs_type) :: vh_rspace = pw_r3d_rs_type()
134 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: vxc_rspace => null(), &
135 vtau_rspace => null(), &
136 vadmm_rspace => null()
137 ! efield
138 TYPE(efield_berry_type), POINTER :: efield => null()
139 ! LS matrices and types
140 TYPE(ls_scf_env_type), POINTER :: ls_env => null()
141 ! Environment for Hartree-Fock exchange
142 TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data => null()
143 ! ADMM XC environments
144 TYPE(section_vals_type), POINTER :: xc_section_primary => null(), &
145 xc_section_aux => null()
146 ! External
147 CHARACTER(len=40) :: exresp_fn = ""
148 CHARACTER(len=40) :: exresperr_fn = ""
149 CHARACTER(len=40) :: exresult_fn = ""
150 LOGICAL :: do_error = .false.
151 CHARACTER(len=1) :: error_method = "E"
152 REAL(kind=dp) :: error_cutoff = 0.0_dp
153 INTEGER :: error_subspace = 0
154 REAL(kind=dp), DIMENSION(3, 3) :: rpv = 0.0_dp
155 REAL(kind=dp), DIMENSION(:, :), POINTER :: rf => null()
156 TYPE(cp_fm_type), DIMENSION(:), POINTER :: cpref => null()
158
159CONTAINS
160
161! **************************************************************************************************
162!> \brief ...
163!> \param ec_env ...
164! **************************************************************************************************
165 SUBROUTINE ec_env_release(ec_env)
166 TYPE(energy_correction_type), POINTER :: ec_env
167
168 CHARACTER(LEN=*), PARAMETER :: routinen = 'ec_env_release'
169
170 INTEGER :: handle
171
172 CALL timeset(routinen, handle)
173
174 IF (ASSOCIATED(ec_env)) THEN
175 ! neighbor lists
176 CALL release_neighbor_list_sets(ec_env%sab_orb)
177 CALL release_neighbor_list_sets(ec_env%sac_ppl)
178 CALL release_neighbor_list_sets(ec_env%sac_ae)
179 CALL release_neighbor_list_sets(ec_env%sap_ppnl)
180 CALL release_neighbor_list_sets(ec_env%sap_oce)
181 ! forces
182 IF (ASSOCIATED(ec_env%force)) CALL deallocate_qs_force(ec_env%force)
183 ! operator matrices
184 IF (ASSOCIATED(ec_env%matrix_ks)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
185 IF (ASSOCIATED(ec_env%matrix_h)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_h)
186 IF (ASSOCIATED(ec_env%matrix_s)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_s)
187 IF (ASSOCIATED(ec_env%matrix_t)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_t)
188 IF (ASSOCIATED(ec_env%matrix_p)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_p)
189 IF (ASSOCIATED(ec_env%matrix_w)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_w)
190 ! GAPW
191 IF (ASSOCIATED(ec_env%oce)) CALL deallocate_oce_set(ec_env%oce)
192 ! task lists for collocate/integrate
193 IF (ASSOCIATED(ec_env%task_list)) THEN
194 CALL deallocate_task_list(ec_env%task_list)
195 END IF
196 IF (ASSOCIATED(ec_env%task_list_soft)) THEN
197 CALL deallocate_task_list(ec_env%task_list_soft)
198 END IF
199 ! reduced basis
200 IF (ASSOCIATED(ec_env%mao_coef)) CALL dbcsr_deallocate_matrix_set(ec_env%mao_coef)
201 ! dispersion environment
202 IF (ASSOCIATED(ec_env%dispersion_env)) THEN
203 CALL qs_dispersion_release(ec_env%dispersion_env)
204 END IF
205
206 CALL ec_env_matrix_release(ec_env)
207
208 IF (ASSOCIATED(ec_env%p_env)) THEN
209 CALL p_env_release(ec_env%p_env)
210 DEALLOCATE (ec_env%p_env)
211 END IF
212 ! potential
213 CALL ec_env_potential_release(ec_env)
214 !
215 CALL efield_berry_release(ec_env%efield)
216
217 IF (ASSOCIATED(ec_env%ls_env)) THEN
218 CALL ls_scf_release(ec_env%ls_env)
219 END IF
220
221 IF (.NOT. ec_env%reuse_hfx) THEN
222 IF (ASSOCIATED(ec_env%x_data)) CALL hfx_release(ec_env%x_data)
223 END IF
224
225 IF (ASSOCIATED(ec_env%xc_section_aux)) CALL section_vals_release(ec_env%xc_section_aux)
226 IF (ASSOCIATED(ec_env%xc_section_primary)) CALL section_vals_release(ec_env%xc_section_primary)
227
228 CALL cp_fm_release(ec_env%mo_occ)
229 CALL cp_fm_release(ec_env%cpmos)
230 CALL cp_fm_release(ec_env%cpref)
231
232 IF (ASSOCIATED(ec_env%rf)) THEN
233 DEALLOCATE (ec_env%rf)
234 END IF
235
236 DEALLOCATE (ec_env)
237
238 END IF
239
240 NULLIFY (ec_env)
241
242 CALL timestop(handle)
243
244 END SUBROUTINE ec_env_release
245
246! **************************************************************************************************
247!> \brief ...
248!> \param ec_env ...
249! **************************************************************************************************
250 SUBROUTINE ec_env_matrix_release(ec_env)
251 TYPE(energy_correction_type), POINTER :: ec_env
252
253 IF (ASSOCIATED(ec_env)) THEN
254 IF (ASSOCIATED(ec_env%matrix_hz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_hz)
255 NULLIFY (ec_env%matrix_hz)
256 IF (ASSOCIATED(ec_env%matrix_wz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_wz)
257 NULLIFY (ec_env%matrix_wz)
258 IF (ASSOCIATED(ec_env%matrix_z)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_z)
259 NULLIFY (ec_env%matrix_z)
260 IF (ASSOCIATED(ec_env%z_admm)) CALL dbcsr_deallocate_matrix_set(ec_env%z_admm)
261 NULLIFY (ec_env%z_admm)
262 END IF
263
264 END SUBROUTINE ec_env_matrix_release
265
266! **************************************************************************************************
267!> \brief ...
268!> \param ec_env ...
269! **************************************************************************************************
270 SUBROUTINE ec_env_potential_release(ec_env)
271 TYPE(energy_correction_type), POINTER :: ec_env
272
273 INTEGER :: iab
274
275 IF (ASSOCIATED(ec_env)) THEN
276 IF (ASSOCIATED(ec_env%vh_rspace%pw_grid)) THEN
277 CALL ec_env%vh_rspace%release()
278 END IF
279 IF (ASSOCIATED(ec_env%vxc_rspace)) THEN
280 DO iab = 1, SIZE(ec_env%vxc_rspace)
281 CALL ec_env%vxc_rspace(iab)%release()
282 END DO
283 DEALLOCATE (ec_env%vxc_rspace)
284 NULLIFY (ec_env%vxc_rspace)
285 END IF
286 IF (ASSOCIATED(ec_env%vtau_rspace)) THEN
287 DO iab = 1, SIZE(ec_env%vtau_rspace)
288 CALL ec_env%vtau_rspace(iab)%release()
289 END DO
290 DEALLOCATE (ec_env%vtau_rspace)
291 NULLIFY (ec_env%vtau_rspace)
292 END IF
293 IF (ASSOCIATED(ec_env%vadmm_rspace)) THEN
294 DO iab = 1, SIZE(ec_env%vadmm_rspace)
295 CALL ec_env%vadmm_rspace(iab)%release()
296 END DO
297 DEALLOCATE (ec_env%vadmm_rspace)
298 NULLIFY (ec_env%vadmm_rspace)
299 END IF
300 IF (ASSOCIATED(ec_env%local_rho_set)) THEN
301 CALL local_rho_set_release(ec_env%local_rho_set)
302 NULLIFY (ec_env%local_rho_set)
303 END IF
304 IF (ASSOCIATED(ec_env%local_rho_set_admm)) THEN
305 CALL local_rho_set_release(ec_env%local_rho_set_admm)
306 NULLIFY (ec_env%local_rho_set_admm)
307 END IF
308 END IF
309
310 END SUBROUTINE ec_env_potential_release
311
312END 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:1910
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
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)
...
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:510
Represent a qs system that is perturbed. Can calculate the linear operator and the rhs of the system ...