(git:97501a3)
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-2025 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
33 USE qs_p_env_types, ONLY: p_env_release,&
39#include "./base/base_uses.f90"
40
41 IMPLICIT NONE
42
43 PRIVATE
44
45 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ec_env_types'
46
48
49! *****************************************************************************
50!> \brief Contains information on the energy correction functional for KG
51!> \par History
52!> 03.2014 created
53!> \author JGH
54! *****************************************************************************
56 CHARACTER(len=20) :: ec_name = ""
57 INTEGER :: energy_functional = 0
58 INTEGER :: ks_solver = 0
59 INTEGER :: factorization = 0
60 INTEGER :: ec_initial_guess = 0
61 REAL(kind=dp) :: eps_default = 0.0_dp
62 LOGICAL :: do_ec_admm = .false.
63 LOGICAL :: do_ec_hfx = .false.
64 LOGICAL :: should_update = .false.
65 LOGICAL :: use_ls_solver = .false.
66 LOGICAL :: reuse_hfx = .false.
67 LOGICAL :: basis_inconsistent = .false.
68 ! debug
69 LOGICAL :: debug_forces = .false.
70 LOGICAL :: debug_stress = .false.
71 LOGICAL :: debug_external = .false.
72 ! basis set
73 CHARACTER(len=20) :: basis = ""
74 LOGICAL :: mao = .false.
75 ! Skip EC calculation if ground-state didnt converge
76 LOGICAL :: do_skip = .false., skip_ec = .false.
77 INTEGER :: mao_max_iter = 0
78 REAL(kind=dp) :: mao_eps_grad = 0.0_dp
79 REAL(kind=dp) :: mao_eps1 = 0.0_dp
80 INTEGER :: mao_iolevel = 0
81 ! energy components
82 REAL(kind=dp) :: etotal = 0.0_dp, old_etotal = 0.0_dp
83 REAL(kind=dp) :: eband = 0.0_dp, ecore = 0.0_dp, exc = 0.0_dp, &
84 ehartree = 0.0_dp, vhxc = 0.0_dp
85 REAL(kind=dp) :: edispersion = 0.0_dp, efield_elec = 0.0_dp, &
86 efield_nuclear = 0.0_dp, ex = 0.0_dp, exc_aux_fit = 0.0_dp
87 ! forces
88 TYPE(qs_force_type), DIMENSION(:), POINTER :: force => null()
89 ! full neighbor lists and corresponding task list
91 DIMENSION(:), POINTER :: sab_orb => null(), sac_ppl => null(), &
92 sac_ae => null(), sap_ppnl => null()
93 TYPE(task_list_type), POINTER :: task_list => null()
94 ! the XC function to be used for the correction, dispersion info
95 TYPE(section_vals_type), POINTER :: xc_section => null()
96 TYPE(qs_dispersion_type), POINTER :: dispersion_env => null()
97 ! matrices in complete basis
98 ! KS: Kohn-Sham; H: Core; S: overlap; T: kinetic energy;
99 ! P: Harris density, W: Harris energy weighted density
100 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks => null(), &
101 matrix_h => null(), &
102 matrix_s => null(), &
103 matrix_t => null(), &
104 matrix_p => null(), &
105 matrix_w => null()
106 ! reduce basis
107 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mao_coef => null()
108 ! external energy calclulation
109 TYPE(cp_fm_type), DIMENSION(:), POINTER :: mo_occ => null()
110 TYPE(cp_fm_type), DIMENSION(:), POINTER :: cpmos => null()
111 ! CP equations
112 TYPE(qs_p_env_type), POINTER :: p_env => null()
113 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hz => null(), matrix_wz => null(), &
114 matrix_z => null(), z_admm => null()
115 ! Harris (rhoout), and response density (rhoz) on grid
116 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rhoout_r => null(), &
117 rhoz_r => null()
118 ! potentials from input density
119 TYPE(pw_r3d_rs_type) :: vh_rspace = pw_r3d_rs_type()
120 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: vxc_rspace => null(), &
121 vtau_rspace => null(), &
122 vadmm_rspace => null()
123 ! efield
124 TYPE(efield_berry_type), POINTER :: efield => null()
125 ! LS matrices and types
126 TYPE(ls_scf_env_type), POINTER :: ls_env => null()
127 ! Environment for Hartree-Fock exchange
128 TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data => null()
129 ! ADMM XC environments
130 TYPE(section_vals_type), POINTER :: xc_section_primary => null(), &
131 xc_section_aux => null()
132 ! External
133 CHARACTER(len=40) :: exresp_fn = ""
134 CHARACTER(len=40) :: exresult_fn = ""
135 LOGICAL :: do_error = .false.
136 REAL(kind=dp), DIMENSION(3, 3) :: rpv = 0.0_dp
137 REAL(kind=dp), DIMENSION(:, :), POINTER :: rf => null()
139
140CONTAINS
141
142! **************************************************************************************************
143!> \brief ...
144!> \param ec_env ...
145! **************************************************************************************************
146 SUBROUTINE ec_env_release(ec_env)
147 TYPE(energy_correction_type), POINTER :: ec_env
148
149 CHARACTER(LEN=*), PARAMETER :: routinen = 'ec_env_release'
150
151 INTEGER :: handle, iab
152
153 CALL timeset(routinen, handle)
154
155 IF (ASSOCIATED(ec_env)) THEN
156 ! neighbor lists
157 CALL release_neighbor_list_sets(ec_env%sab_orb)
158 CALL release_neighbor_list_sets(ec_env%sac_ppl)
159 CALL release_neighbor_list_sets(ec_env%sac_ae)
160 CALL release_neighbor_list_sets(ec_env%sap_ppnl)
161 ! forces
162 IF (ASSOCIATED(ec_env%force)) CALL deallocate_qs_force(ec_env%force)
163 ! operator matrices
164 IF (ASSOCIATED(ec_env%matrix_ks)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
165 IF (ASSOCIATED(ec_env%matrix_h)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_h)
166 IF (ASSOCIATED(ec_env%matrix_s)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_s)
167 IF (ASSOCIATED(ec_env%matrix_t)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_t)
168 IF (ASSOCIATED(ec_env%matrix_p)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_p)
169 IF (ASSOCIATED(ec_env%matrix_w)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_w)
170 IF (ASSOCIATED(ec_env%task_list)) THEN
171 CALL deallocate_task_list(ec_env%task_list)
172 END IF
173 ! reduced basis
174 IF (ASSOCIATED(ec_env%mao_coef)) CALL dbcsr_deallocate_matrix_set(ec_env%mao_coef)
175 ! dispersion environment
176 IF (ASSOCIATED(ec_env%dispersion_env)) THEN
177 CALL qs_dispersion_release(ec_env%dispersion_env)
178 END IF
179
180 IF (ASSOCIATED(ec_env%matrix_hz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_hz)
181 IF (ASSOCIATED(ec_env%matrix_wz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_wz)
182 IF (ASSOCIATED(ec_env%matrix_z)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_z)
183 IF (ASSOCIATED(ec_env%z_admm)) CALL dbcsr_deallocate_matrix_set(ec_env%z_admm)
184 NULLIFY (ec_env%matrix_z, ec_env%matrix_hz, ec_env%matrix_wz)
185 NULLIFY (ec_env%z_admm)
186
187 IF (ASSOCIATED(ec_env%p_env)) THEN
188 CALL p_env_release(ec_env%p_env)
189 DEALLOCATE (ec_env%p_env)
190 END IF
191 ! potential
192 IF (ASSOCIATED(ec_env%vh_rspace%pw_grid)) THEN
193 CALL ec_env%vh_rspace%release()
194 END IF
195 IF (ASSOCIATED(ec_env%vxc_rspace)) THEN
196 DO iab = 1, SIZE(ec_env%vxc_rspace)
197 CALL ec_env%vxc_rspace(iab)%release()
198 END DO
199 DEALLOCATE (ec_env%vxc_rspace)
200 END IF
201 IF (ASSOCIATED(ec_env%vtau_rspace)) THEN
202 DO iab = 1, SIZE(ec_env%vtau_rspace)
203 CALL ec_env%vtau_rspace(iab)%release()
204 END DO
205 DEALLOCATE (ec_env%vtau_rspace)
206 END IF
207 IF (ASSOCIATED(ec_env%vadmm_rspace)) THEN
208 DO iab = 1, SIZE(ec_env%vadmm_rspace)
209 CALL ec_env%vadmm_rspace(iab)%release()
210 END DO
211 DEALLOCATE (ec_env%vadmm_rspace)
212 END IF
213 CALL efield_berry_release(ec_env%efield)
214
215 IF (ASSOCIATED(ec_env%ls_env)) THEN
216 CALL ls_scf_release(ec_env%ls_env)
217 END IF
218
219 IF (.NOT. ec_env%reuse_hfx) THEN
220 IF (ASSOCIATED(ec_env%x_data)) CALL hfx_release(ec_env%x_data)
221 END IF
222
223 IF (ASSOCIATED(ec_env%xc_section_aux)) CALL section_vals_release(ec_env%xc_section_aux)
224 IF (ASSOCIATED(ec_env%xc_section_primary)) CALL section_vals_release(ec_env%xc_section_primary)
225
226 CALL cp_fm_release(ec_env%mo_occ)
227 CALL cp_fm_release(ec_env%cpmos)
228
229 IF (ASSOCIATED(ec_env%rf)) THEN
230 DEALLOCATE (ec_env%rf)
231 END IF
232
233 DEALLOCATE (ec_env)
234
235 END IF
236
237 NULLIFY (ec_env)
238
239 CALL timestop(handle)
240
241 END SUBROUTINE ec_env_release
242
243END 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_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.
Define the neighbor list data types and the corresponding functionality.
subroutine, public release_neighbor_list_sets(nlists)
releases an array of neighbor_list_sets
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 ...