Line data Source code
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 Types needed for a for a Energy Correction
10 : !> \par History
11 : !> 2019.09 created
12 : !> \author JGH
13 : ! **************************************************************************************************
14 : MODULE ec_env_types
15 : USE cp_dbcsr_api, ONLY: dbcsr_p_type
16 : USE cp_dbcsr_operations, ONLY: dbcsr_deallocate_matrix_set
17 : USE dm_ls_scf_types, ONLY: ls_scf_env_type,&
18 : ls_scf_release
19 : USE hfx_types, ONLY: hfx_release,&
20 : hfx_type
21 : USE input_section_types, ONLY: section_vals_release,&
22 : section_vals_type
23 : USE kinds, ONLY: dp
24 : USE pw_types, ONLY: pw_r3d_rs_type
25 : USE qs_dispersion_types, ONLY: qs_dispersion_release,&
26 : qs_dispersion_type
27 : USE qs_force_types, ONLY: deallocate_qs_force,&
28 : qs_force_type
29 : USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type,&
30 : release_neighbor_list_sets
31 : USE qs_p_env_types, ONLY: p_env_release,&
32 : qs_p_env_type
33 : USE qs_period_efield_types, ONLY: efield_berry_release,&
34 : efield_berry_type
35 : USE task_list_types, ONLY: deallocate_task_list,&
36 : task_list_type
37 : #include "./base/base_uses.f90"
38 :
39 : IMPLICIT NONE
40 :
41 : PRIVATE
42 :
43 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ec_env_types'
44 :
45 : PUBLIC :: energy_correction_type, ec_env_release
46 :
47 : ! *****************************************************************************
48 : !> \brief Contains information on the energy correction functional for KG
49 : !> \par History
50 : !> 03.2014 created
51 : !> \author JGH
52 : ! *****************************************************************************
53 : TYPE energy_correction_type
54 : CHARACTER(len=20) :: ec_name = ""
55 : INTEGER :: energy_functional = 0
56 : INTEGER :: ks_solver = 0
57 : INTEGER :: factorization = 0
58 : INTEGER :: ec_initial_guess = 0
59 : REAL(KIND=dp) :: eps_default = 0.0_dp
60 : LOGICAL :: do_ec_admm = .FALSE.
61 : LOGICAL :: do_ec_hfx = .FALSE.
62 : LOGICAL :: should_update = .FALSE.
63 : LOGICAL :: use_ls_solver = .FALSE.
64 : LOGICAL :: reuse_hfx = .FALSE.
65 : LOGICAL :: basis_inconsistent = .FALSE.
66 : ! debug
67 : LOGICAL :: debug_forces = .FALSE.
68 : LOGICAL :: debug_stress = .FALSE.
69 : ! basis set
70 : CHARACTER(len=20) :: basis = ""
71 : LOGICAL :: mao = .FALSE.
72 : ! Skip EC calculation if ground-state didnt converge
73 : LOGICAL :: do_skip = .FALSE., skip_ec = .FALSE.
74 : INTEGER :: mao_max_iter = 0
75 : REAL(KIND=dp) :: mao_eps_grad = 0.0_dp
76 : REAL(KIND=dp) :: mao_eps1 = 0.0_dp
77 : INTEGER :: mao_iolevel = 0
78 : ! energy components
79 : REAL(KIND=dp) :: etotal = 0.0_dp, old_etotal = 0.0_dp
80 : REAL(KIND=dp) :: eband = 0.0_dp, ecore = 0.0_dp, exc = 0.0_dp, &
81 : ehartree = 0.0_dp, vhxc = 0.0_dp
82 : REAL(KIND=dp) :: edispersion = 0.0_dp, efield_elec = 0.0_dp, &
83 : efield_nuclear = 0.0_dp, ex = 0.0_dp, exc_aux_fit = 0.0_dp
84 : ! forces
85 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force => Null()
86 : ! full neighbor lists and corresponding task list
87 : TYPE(neighbor_list_set_p_type), &
88 : DIMENSION(:), POINTER :: sab_orb => Null(), sac_ppl => Null(), sap_ppnl => Null()
89 : TYPE(task_list_type), POINTER :: task_list => Null()
90 : ! the XC function to be used for the correction, dispersion info
91 : TYPE(section_vals_type), POINTER :: xc_section => Null()
92 : TYPE(qs_dispersion_type), POINTER :: dispersion_env => Null()
93 : ! matrices in complete basis
94 : ! KS: Kohn-Sham; H: Core; S: overlap; T: kinetic energy;
95 : ! P: Harris density, W: Harris energy weighted density
96 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks => Null(), &
97 : matrix_h => Null(), &
98 : matrix_s => Null(), &
99 : matrix_t => Null(), &
100 : matrix_p => Null(), &
101 : matrix_w => Null()
102 : ! reduce basis
103 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mao_coef => Null()
104 : ! CP equations
105 : TYPE(qs_p_env_type), POINTER :: p_env => Null()
106 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hz => Null(), matrix_wz => Null(), &
107 : matrix_z => Null(), z_admm => Null()
108 : ! Harris (rhoout), and response density (rhoz) on grid
109 : TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rhoout_r => Null(), rhoz_r => Null()
110 : ! potentials from input density
111 : TYPE(pw_r3d_rs_type) :: vh_rspace = pw_r3d_rs_type()
112 : TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: vxc_rspace => Null(), vtau_rspace => Null(), vadmm_rspace => Null()
113 : ! efield
114 : TYPE(efield_berry_type), POINTER :: efield => NULL()
115 : ! LS matrices and types
116 : TYPE(ls_scf_env_type), POINTER :: ls_env => Null()
117 : ! Environment for Hartree-Fock exchange
118 : TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data => Null()
119 : ! ADMM XC environments
120 : TYPE(section_vals_type), POINTER :: xc_section_primary => Null(), &
121 : xc_section_aux => Null()
122 : END TYPE energy_correction_type
123 :
124 : CONTAINS
125 :
126 : ! **************************************************************************************************
127 : !> \brief ...
128 : !> \param ec_env ...
129 : ! **************************************************************************************************
130 6586 : SUBROUTINE ec_env_release(ec_env)
131 : TYPE(energy_correction_type), POINTER :: ec_env
132 :
133 : CHARACTER(LEN=*), PARAMETER :: routineN = 'ec_env_release'
134 :
135 : INTEGER :: handle, iab
136 :
137 6586 : CALL timeset(routineN, handle)
138 :
139 6586 : IF (ASSOCIATED(ec_env)) THEN
140 : ! neighbor lists
141 6586 : CALL release_neighbor_list_sets(ec_env%sab_orb)
142 6586 : CALL release_neighbor_list_sets(ec_env%sac_ppl)
143 6586 : CALL release_neighbor_list_sets(ec_env%sap_ppnl)
144 : ! forces
145 6586 : IF (ASSOCIATED(ec_env%force)) CALL deallocate_qs_force(ec_env%force)
146 : ! operator matrices
147 6586 : IF (ASSOCIATED(ec_env%matrix_ks)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_ks)
148 6586 : IF (ASSOCIATED(ec_env%matrix_h)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_h)
149 6586 : IF (ASSOCIATED(ec_env%matrix_s)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_s)
150 6586 : IF (ASSOCIATED(ec_env%matrix_t)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_t)
151 6586 : IF (ASSOCIATED(ec_env%matrix_p)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_p)
152 6586 : IF (ASSOCIATED(ec_env%matrix_w)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_w)
153 6586 : IF (ASSOCIATED(ec_env%task_list)) THEN
154 232 : CALL deallocate_task_list(ec_env%task_list)
155 : END IF
156 : ! reduced basis
157 6586 : IF (ASSOCIATED(ec_env%mao_coef)) CALL dbcsr_deallocate_matrix_set(ec_env%mao_coef)
158 : ! dispersion environment
159 6586 : IF (ASSOCIATED(ec_env%dispersion_env)) THEN
160 232 : CALL qs_dispersion_release(ec_env%dispersion_env)
161 : END IF
162 :
163 6586 : IF (ASSOCIATED(ec_env%matrix_hz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_hz)
164 6586 : IF (ASSOCIATED(ec_env%matrix_wz)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_wz)
165 6586 : IF (ASSOCIATED(ec_env%matrix_z)) CALL dbcsr_deallocate_matrix_set(ec_env%matrix_z)
166 6586 : IF (ASSOCIATED(ec_env%z_admm)) CALL dbcsr_deallocate_matrix_set(ec_env%z_admm)
167 6586 : NULLIFY (ec_env%matrix_z, ec_env%matrix_hz, ec_env%matrix_wz)
168 6586 : NULLIFY (ec_env%z_admm)
169 :
170 6586 : IF (ASSOCIATED(ec_env%p_env)) THEN
171 212 : CALL p_env_release(ec_env%p_env)
172 212 : DEALLOCATE (ec_env%p_env)
173 : END IF
174 : ! potential
175 6586 : IF (ASSOCIATED(ec_env%vh_rspace%pw_grid)) THEN
176 232 : CALL ec_env%vh_rspace%release()
177 : END IF
178 6586 : IF (ASSOCIATED(ec_env%vxc_rspace)) THEN
179 464 : DO iab = 1, SIZE(ec_env%vxc_rspace)
180 464 : CALL ec_env%vxc_rspace(iab)%release()
181 : END DO
182 232 : DEALLOCATE (ec_env%vxc_rspace)
183 : END IF
184 6586 : IF (ASSOCIATED(ec_env%vtau_rspace)) THEN
185 32 : DO iab = 1, SIZE(ec_env%vtau_rspace)
186 32 : CALL ec_env%vtau_rspace(iab)%release()
187 : END DO
188 16 : DEALLOCATE (ec_env%vtau_rspace)
189 : END IF
190 6586 : IF (ASSOCIATED(ec_env%vadmm_rspace)) THEN
191 48 : DO iab = 1, SIZE(ec_env%vadmm_rspace)
192 48 : CALL ec_env%vadmm_rspace(iab)%release()
193 : END DO
194 24 : DEALLOCATE (ec_env%vadmm_rspace)
195 : END IF
196 6586 : CALL efield_berry_release(ec_env%efield)
197 :
198 6586 : IF (ASSOCIATED(ec_env%ls_env)) THEN
199 22 : CALL ls_scf_release(ec_env%ls_env)
200 : END IF
201 :
202 6586 : IF (.NOT. ec_env%reuse_hfx) THEN
203 6576 : IF (ASSOCIATED(ec_env%x_data)) CALL hfx_release(ec_env%x_data)
204 : END IF
205 :
206 6586 : IF (ASSOCIATED(ec_env%xc_section_aux)) CALL section_vals_release(ec_env%xc_section_aux)
207 6586 : IF (ASSOCIATED(ec_env%xc_section_primary)) CALL section_vals_release(ec_env%xc_section_primary)
208 :
209 6586 : DEALLOCATE (ec_env)
210 :
211 : END IF
212 :
213 6586 : NULLIFY (ec_env)
214 :
215 6586 : CALL timestop(handle)
216 :
217 6586 : END SUBROUTINE ec_env_release
218 :
219 0 : END MODULE ec_env_types
|