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
10 : !> \author Jan Wilhelm
11 : !> \date 07.2023
12 : ! **************************************************************************************************
13 : MODULE post_scf_bandstructure_types
14 : USE basis_set_types, ONLY: gto_basis_set_p_type
15 : USE cp_cfm_types, ONLY: cp_cfm_release,&
16 : cp_cfm_type
17 : USE cp_dbcsr_api, ONLY: dbcsr_p_type,&
18 : dbcsr_release
19 : USE cp_dbcsr_operations, ONLY: dbcsr_deallocate_matrix_set
20 : USE cp_fm_types, ONLY: cp_fm_release,&
21 : cp_fm_type
22 : USE dbt_api, ONLY: dbt_destroy,&
23 : dbt_type
24 : USE input_constants, ONLY: small_cell_full_kp
25 : USE kinds, ONLY: default_string_length,&
26 : dp
27 : USE kpoint_types, ONLY: kpoint_release,&
28 : kpoint_type
29 : USE libint_2c_3c, ONLY: libint_potential_type
30 : USE message_passing, ONLY: mp_para_env_release,&
31 : mp_para_env_type
32 : USE qs_tensors_types, ONLY: neighbor_list_3c_type
33 : #include "./base/base_uses.f90"
34 :
35 : IMPLICIT NONE
36 :
37 : PRIVATE
38 :
39 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'post_scf_bandstructure_types'
40 :
41 : PUBLIC :: post_scf_bandstructure_type, band_edges_type, data_3_type, bs_env_release
42 :
43 : ! valence band maximum (VBM), conduction band minimum (CBM), direct band gap (DBG),
44 : ! indirect band gap (IDBG)
45 : TYPE band_edges_type
46 : REAL(KIND=dp) :: VBM = -1.0_dp, &
47 : CBM = -1.0_dp, &
48 : DBG = -1.0_dp, &
49 : IDBG = -1.0_dp
50 : END TYPE band_edges_type
51 :
52 : ! data type for storing 3-index quantities for small-cell, full-k-points GW code
53 : TYPE data_3_type
54 : REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE :: data_3
55 : END TYPE data_3_type
56 :
57 : TYPE post_scf_bandstructure_type
58 :
59 : ! decide which calculations will be done
60 : LOGICAL :: do_gw = .FALSE., &
61 : do_soc = .FALSE., &
62 : do_ldos = .FALSE.
63 :
64 : ! various eigenvalues computed in GW code, some depend on k-points
65 : ! and have therefore three dimensions (band index, k-point, spin)
66 : REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: eigenval_scf_Gamma
67 : REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE :: eigenval_scf, &
68 : eigenval_G0W0, &
69 : eigenval_HF, &
70 : eigenval_scGW0
71 : REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: eigenval_scf_soc, &
72 : eigenval_G0W0_soc
73 : TYPE(band_edges_type), DIMENSION(2) :: band_edges_scf_Gamma
74 : TYPE(band_edges_type) :: band_edges_scf, &
75 : band_edges_G0W0, &
76 : band_edges_HF
77 :
78 : ! parameters that influence the GW flavor
79 : LOGICAL :: do_hedin_shift = .FALSE.
80 :
81 : ! general parameters on molecular orbitals and basis sets
82 : INTEGER :: n_ao = -1, &
83 : n_RI = -1, &
84 : n_spin = -1, &
85 : n_atom = -1, &
86 : max_AO_bf_per_atom = -1
87 : INTEGER, DIMENSION(:), ALLOCATABLE :: i_ao_start_from_atom, &
88 : i_ao_end_from_atom, &
89 : i_RI_start_from_atom, &
90 : i_RI_end_from_atom
91 : INTEGER, DIMENSION(2) :: n_occ = -1, &
92 : n_vir = -1
93 : REAL(KIND=dp) :: spin_degeneracy = -1.0_dp
94 : REAL(KIND=dp), DIMENSION(2) :: e_fermi = -1.0_dp
95 :
96 : ! kpoint mesh for chi, eps, W
97 : INTEGER, DIMENSION(:), POINTER :: nkp_grid_DOS_input => NULL()
98 : INTEGER, DIMENSION(3) :: nkp_grid_chi_eps_W_orig = -1, &
99 : nkp_grid_chi_eps_W_extra = -1
100 : INTEGER :: nkp_chi_eps_W_orig = -1, &
101 : nkp_chi_eps_W_extra = -1, &
102 : nkp_chi_eps_W_orig_plus_extra = -1, &
103 : nkp_chi_eps_W_batch = -1, &
104 : num_chi_eps_W_batches = -1, &
105 : size_lattice_sum_V = -1
106 : TYPE(kpoint_type), POINTER :: kpoints_chi_eps_W => NULL(), &
107 : kpoints_DOS => NULL()
108 : LOGICAL :: approx_kp_extrapol = .FALSE.
109 :
110 : REAL(KIND=dp) :: wkp_orig = -1.0_dp
111 : REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: wkp_s_p, &
112 : wkp_no_extra
113 : INTEGER, DIMENSION(:), ALLOCATABLE :: l_RI
114 : INTEGER :: input_kp_bs_npoints = -1, &
115 : input_kp_bs_n_sp_pts = -1, &
116 : nkp_bs_and_DOS = -1, &
117 : nkp_only_bs = -1, &
118 : nkp_only_DOS = -1
119 : REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: xkp_special
120 :
121 : ! parameters for GW band structure calculation of small unit cell (with multiple unit cell)
122 : INTEGER :: small_cell_full_kp_or_large_cell_Gamma = -1, &
123 : nimages_scf = -1
124 : INTEGER, DIMENSION(3) :: periodic = -1
125 : REAL(KIND=dp), DIMENSION(3, 3) :: hmat = -1.0_dp
126 :
127 : ! imaginary time and imaginary frequency grids
128 : INTEGER :: num_time_freq_points = -1, &
129 : num_freq_points_fit = -1
130 : REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: imag_time_points, &
131 : imag_freq_points, &
132 : imag_freq_points_fit
133 : REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: weights_cos_t_to_w, &
134 : weights_cos_w_to_t, &
135 : weights_sin_t_to_w
136 : INTEGER :: nparam_pade = -1, &
137 : num_points_per_magnitude = -1
138 : REAL(KIND=dp) :: freq_max_fit = -1.0_dp, &
139 : regularization_minimax = -1.0_dp, &
140 : stabilize_exp = -1.0_dp
141 :
142 : ! filter threshold for matrix-tensor operations
143 : REAL(KIND=dp) :: eps_filter = -1.0_dp, &
144 : eps_atom_grid_2d_mat = -1.0_dp
145 :
146 : ! threshold for inverting ao overlap matrix, RI cfm_1d
147 : REAL(KIND=dp) :: eps_eigval_mat_s = -1.0_dp, &
148 : eps_eigval_mat_RI = -1.0_dp, &
149 : input_regularization_RI = -1.0_dp, &
150 : regularization_RI = -1.0_dp
151 :
152 : ! global full cfm_1d used in GW
153 : TYPE(cp_fm_type) :: fm_s_Gamma, &
154 : fm_Gocc, &
155 : fm_Gvir
156 : TYPE(cp_fm_type), DIMENSION(2) :: fm_ks_Gamma, &
157 : fm_V_xc_Gamma, &
158 : fm_mo_coeff_Gamma
159 : TYPE(cp_fm_type), DIMENSION(4) :: fm_work_mo
160 : TYPE(cp_fm_type) :: fm_RI_RI, &
161 : fm_chi_Gamma_freq, &
162 : fm_W_MIC_freq, &
163 : fm_W_MIC_freq_1_extra, &
164 : fm_W_MIC_freq_1_no_extra
165 : TYPE(cp_cfm_type) :: cfm_work_mo, &
166 : cfm_work_mo_2
167 :
168 : ! global dbcsr cfm_1d used in GW
169 : TYPE(dbcsr_p_type) :: mat_ao_ao, &
170 : mat_RI_RI
171 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mat_chi_Gamma_tau => NULL()
172 :
173 : ! local dbcsr cfm_1d used in GW (local in tensor group)
174 : TYPE(dbcsr_p_type) :: mat_ao_ao_tensor, &
175 : mat_RI_RI_tensor
176 :
177 : ! tensors for sparse matrix-tensor operations
178 : TYPE(dbt_type) :: t_G, &
179 : t_chi, &
180 : t_W, &
181 : t_RI_AO__AO, &
182 : t_RI__AO_AO
183 :
184 : ! parameters and data for parallelization
185 : INTEGER :: group_size_tensor = -1, &
186 : tensor_group_color = -1, &
187 : num_tensor_groups = -1
188 : REAL(KIND=dp) :: input_memory_per_proc_GB = -1.0_dp
189 : TYPE(mp_para_env_type), POINTER :: para_env => NULL(), &
190 : para_env_tensor => NULL()
191 : REAL(KIND=dp) :: occupation_3c_int = -1.0_dp, &
192 : max_dist_AO_atoms = -1.0_dp, &
193 : safety_factor_memory = -1.0_dp
194 :
195 : ! parallelization: atom range i and atom range j for tensor group
196 : INTEGER, DIMENSION(2) :: atoms_i = -1, &
197 : atoms_j = -1
198 : INTEGER :: n_atom_i = -1, &
199 : n_intervals_i = -1, &
200 : n_atom_j = -1, &
201 : n_intervals_j = -1, &
202 : n_atom_per_interval_ij = -1, &
203 : n_intervals_inner_loop_atoms = -1, &
204 : n_atom_per_IL_interval = -1
205 : INTEGER, DIMENSION(:, :), ALLOCATABLE :: i_atom_intervals, &
206 : j_atom_intervals, &
207 : inner_loop_atom_intervals, &
208 : atoms_i_t_group, &
209 : atoms_j_t_group
210 : LOGICAL, DIMENSION(:, :), ALLOCATABLE :: skip_Sigma_occ, &
211 : skip_Sigma_vir
212 :
213 : ! check-arrays and names for restarting
214 : LOGICAL, DIMENSION(:), ALLOCATABLE :: read_chi, &
215 : calc_chi
216 : LOGICAL, DIMENSION(:, :), ALLOCATABLE :: Sigma_c_exists
217 : LOGICAL :: all_W_exist = .FALSE., &
218 : Sigma_x_exists = .FALSE.
219 : CHARACTER(LEN=3) :: chi_name = "chi"
220 : CHARACTER(LEN=6) :: W_time_name = "W_time"
221 : CHARACTER(LEN=7) :: Sigma_x_name = "Sigma_x"
222 : CHARACTER(LEN=13) :: Sigma_p_name = "Sigma_pos_tau", &
223 : Sigma_n_name = "Sigma_neg_tau"
224 : CHARACTER(LEN=default_string_length) :: prefix = ""
225 : INTEGER :: unit_nr = -1
226 :
227 : ! parameters and data for basis sets
228 : TYPE(gto_basis_set_p_type), &
229 : DIMENSION(:), ALLOCATABLE :: basis_set_AO, &
230 : basis_set_RI
231 : INTEGER, DIMENSION(:), ALLOCATABLE :: sizes_AO, &
232 : sizes_RI
233 : TYPE(neighbor_list_3c_type) :: nl_3c
234 : TYPE(libint_potential_type) :: ri_metric, &
235 : trunc_coulomb
236 :
237 : ! parameters for SOC calculation
238 : REAL(KIND=dp) :: energy_window_soc = -1.0_dp
239 : ! sizes: mat_V_SOC_xyz: xyz, img
240 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mat_V_SOC_xyz => NULL()
241 : TYPE(cp_fm_type), DIMENSION(3) :: fm_V_SOC_xyz_mo
242 : ! small-cell GW: dimension = number of kpoints; large-cell GW: Gamma-point, dimension = 1
243 : TYPE(cp_cfm_type), DIMENSION(:), ALLOCATABLE :: cfm_SOC_spinor_ao
244 : TYPE(band_edges_type) :: band_edges_scf_SOC, &
245 : band_edges_G0W0_SOC
246 :
247 : ! parameters for DOS and PDOS calculation
248 : REAL(KIND=dp) :: energy_window_DOS = -1.0_dp, &
249 : energy_step_DOS = -1.0_dp, &
250 : broadening_DOS = -1.0_dp
251 :
252 : ! parameters for LDOS calculation (LDOS: local density of states)
253 : INTEGER :: int_ldos_xyz = -1
254 : INTEGER, DIMENSION(:), POINTER :: bin_mesh => NULL()
255 : INTEGER :: n_bins_max_for_printing = -1
256 : REAL(KIND=dp) :: unit_ldos_int_z_inv_Ang2_eV = -1.0_dp
257 :
258 : ! quantities only needed for small cells and k-point sampling in DFT (small_cell_full_kp)
259 : INTEGER :: nkp_scf_desymm = -1, &
260 : nimages_3c = -1, &
261 : nimages_scf_desymm = -1, &
262 : nimages_Delta_R = -1
263 : TYPE(kpoint_type), POINTER :: kpoints_scf_desymm => NULL(), &
264 : kpoints_scf_desymm_2 => NULL()
265 : INTEGER, DIMENSION(3) :: cell_grid_scf_desymm = -1
266 : INTEGER, DIMENSION(:, :), ALLOCATABLE :: index_to_cell_3c, &
267 : index_to_cell_Delta_R
268 : INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index_3c => NULL(), &
269 : cell_to_index_Delta_R => NULL()
270 : REAL(KIND=dp) :: heuristic_filter_factor = -1.0_dp
271 :
272 : ! small_cell_full_kp parallelization
273 : INTEGER :: n_tasks_Delta_R_local = -1
274 : INTEGER, DIMENSION(:), ALLOCATABLE :: task_Delta_R
275 : INTEGER, DIMENSION(:, :), ALLOCATABLE :: nblocks_3c
276 :
277 : ! cfm for k-dep overl mat S_µν(k), KS mat h_µν(k,spin) and mo coeff C_μn(k,spin) from SCF
278 : TYPE(cp_cfm_type), DIMENSION(:), ALLOCATABLE :: cfm_s_kp
279 : TYPE(cp_cfm_type), DIMENSION(:, :), ALLOCATABLE :: cfm_mo_coeff_kp, &
280 : cfm_ks_kp
281 : TYPE(cp_fm_type), DIMENSION(:), ALLOCATABLE :: fm_G_S, &
282 : fm_Sigma_x_R
283 : TYPE(cp_fm_type), DIMENSION(:, :), ALLOCATABLE :: fm_V_xc_R, &
284 : fm_chi_R_t, &
285 : fm_MWM_R_t
286 : TYPE(cp_fm_type), DIMENSION(:, :, :), ALLOCATABLE :: fm_Sigma_c_R_neg_tau, &
287 : fm_Sigma_c_R_pos_tau
288 : REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE :: v_xc_n
289 : TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_3c_int
290 :
291 : END TYPE post_scf_bandstructure_type
292 :
293 : CONTAINS
294 :
295 : ! **************************************************************************************************
296 : !> \brief ...
297 : !> \param bs_env ...
298 : ! **************************************************************************************************
299 22 : SUBROUTINE bs_env_release(bs_env)
300 : TYPE(post_scf_bandstructure_type), POINTER :: bs_env
301 :
302 : CHARACTER(LEN=*), PARAMETER :: routineN = 'bs_env_release'
303 :
304 : INTEGER :: handle
305 :
306 22 : CALL timeset(routineN, handle)
307 :
308 22 : CPASSERT(ASSOCIATED(bs_env))
309 :
310 22 : CALL safe_kpoints_release(bs_env%kpoints_chi_eps_W)
311 22 : CALL safe_kpoints_release(bs_env%kpoints_DOS)
312 22 : CALL safe_kpoints_release(bs_env%kpoints_scf_desymm)
313 22 : CALL safe_kpoints_release(bs_env%kpoints_scf_desymm_2)
314 :
315 22 : IF (ALLOCATED(bs_env%wkp_s_p)) DEALLOCATE (bs_env%wkp_s_p)
316 22 : IF (ALLOCATED(bs_env%wkp_no_extra)) DEALLOCATE (bs_env%wkp_no_extra)
317 22 : IF (ALLOCATED(bs_env%l_RI)) DEALLOCATE (bs_env%l_RI)
318 22 : IF (ALLOCATED(bs_env%xkp_special)) DEALLOCATE (bs_env%xkp_special)
319 22 : IF (ALLOCATED(bs_env%imag_time_points)) DEALLOCATE (bs_env%imag_time_points)
320 22 : IF (ALLOCATED(bs_env%imag_freq_points)) DEALLOCATE (bs_env%imag_freq_points)
321 22 : IF (ALLOCATED(bs_env%eigenval_scf_Gamma)) DEALLOCATE (bs_env%eigenval_scf_Gamma)
322 22 : IF (ALLOCATED(bs_env%eigenval_scf)) DEALLOCATE (bs_env%eigenval_scf)
323 22 : IF (ALLOCATED(bs_env%eigenval_G0W0)) DEALLOCATE (bs_env%eigenval_G0W0)
324 22 : IF (ALLOCATED(bs_env%eigenval_HF)) DEALLOCATE (bs_env%eigenval_HF)
325 22 : IF (ALLOCATED(bs_env%eigenval_scGW0)) DEALLOCATE (bs_env%eigenval_scGW0)
326 22 : IF (ALLOCATED(bs_env%eigenval_scf_soc)) DEALLOCATE (bs_env%eigenval_scf_soc)
327 22 : IF (ALLOCATED(bs_env%eigenval_G0W0_soc)) DEALLOCATE (bs_env%eigenval_G0W0_soc)
328 22 : IF (ALLOCATED(bs_env%i_ao_start_from_atom)) DEALLOCATE (bs_env%i_ao_start_from_atom)
329 22 : IF (ALLOCATED(bs_env%i_ao_end_from_atom)) DEALLOCATE (bs_env%i_ao_end_from_atom)
330 22 : IF (ALLOCATED(bs_env%i_RI_start_from_atom)) DEALLOCATE (bs_env%i_RI_start_from_atom)
331 22 : IF (ALLOCATED(bs_env%i_RI_end_from_atom)) DEALLOCATE (bs_env%i_RI_end_from_atom)
332 22 : IF (ALLOCATED(bs_env%i_atom_intervals)) DEALLOCATE (bs_env%i_atom_intervals)
333 22 : IF (ALLOCATED(bs_env%j_atom_intervals)) DEALLOCATE (bs_env%j_atom_intervals)
334 22 : IF (ALLOCATED(bs_env%atoms_i_t_group)) DEALLOCATE (bs_env%atoms_i_t_group)
335 22 : IF (ALLOCATED(bs_env%atoms_j_t_group)) DEALLOCATE (bs_env%atoms_j_t_group)
336 22 : IF (ALLOCATED(bs_env%skip_Sigma_occ)) DEALLOCATE (bs_env%skip_Sigma_occ)
337 22 : IF (ALLOCATED(bs_env%skip_Sigma_vir)) DEALLOCATE (bs_env%skip_Sigma_vir)
338 22 : IF (ALLOCATED(bs_env%read_chi)) DEALLOCATE (bs_env%read_chi)
339 22 : IF (ALLOCATED(bs_env%calc_chi)) DEALLOCATE (bs_env%calc_chi)
340 22 : IF (ALLOCATED(bs_env%Sigma_c_exists)) DEALLOCATE (bs_env%Sigma_c_exists)
341 22 : IF (ALLOCATED(bs_env%sizes_AO)) DEALLOCATE (bs_env%sizes_AO)
342 22 : IF (ALLOCATED(bs_env%sizes_RI)) DEALLOCATE (bs_env%sizes_RI)
343 22 : IF (ALLOCATED(bs_env%index_to_cell_3c)) DEALLOCATE (bs_env%index_to_cell_3c)
344 22 : IF (ALLOCATED(bs_env%index_to_cell_Delta_R)) DEALLOCATE (bs_env%index_to_cell_Delta_R)
345 22 : IF (ASSOCIATED(bs_env%cell_to_index_3c)) DEALLOCATE (bs_env%cell_to_index_3c)
346 22 : IF (ASSOCIATED(bs_env%cell_to_index_Delta_R)) DEALLOCATE (bs_env%cell_to_index_Delta_R)
347 22 : IF (ALLOCATED(bs_env%task_Delta_R)) DEALLOCATE (bs_env%task_Delta_R)
348 22 : IF (ALLOCATED(bs_env%nblocks_3c)) DEALLOCATE (bs_env%nblocks_3c)
349 :
350 22 : CALL cp_fm_release(bs_env%fm_s_Gamma)
351 22 : CALL cp_fm_release(bs_env%fm_ks_Gamma(1))
352 22 : CALL cp_fm_release(bs_env%fm_ks_Gamma(2))
353 22 : CALL cp_fm_release(bs_env%fm_V_xc_Gamma(1))
354 22 : CALL cp_fm_release(bs_env%fm_V_xc_Gamma(2))
355 22 : CALL cp_fm_release(bs_env%fm_mo_coeff_Gamma(1))
356 22 : CALL cp_fm_release(bs_env%fm_mo_coeff_Gamma(2))
357 22 : CALL cp_fm_release(bs_env%fm_Gocc)
358 22 : CALL cp_fm_release(bs_env%fm_Gvir)
359 22 : CALL cp_fm_release(bs_env%fm_work_mo(1))
360 22 : CALL cp_fm_release(bs_env%fm_work_mo(2))
361 22 : CALL cp_fm_release(bs_env%fm_work_mo(3))
362 22 : CALL cp_fm_release(bs_env%fm_work_mo(4))
363 22 : CALL cp_fm_release(bs_env%fm_RI_RI)
364 22 : CALL cp_fm_release(bs_env%fm_chi_Gamma_freq)
365 22 : CALL cp_fm_release(bs_env%fm_W_MIC_freq)
366 22 : CALL cp_fm_release(bs_env%fm_W_MIC_freq_1_extra)
367 22 : CALL cp_fm_release(bs_env%fm_W_MIC_freq_1_no_extra)
368 22 : CALL cp_cfm_release(bs_env%cfm_work_mo)
369 22 : CALL cp_cfm_release(bs_env%cfm_work_mo_2)
370 :
371 22 : CALL safe_fm_destroy_1d(bs_env%fm_G_S)
372 22 : CALL safe_fm_destroy_1d(bs_env%fm_Sigma_x_R)
373 22 : CALL safe_fm_destroy_2d(bs_env%fm_V_xc_R)
374 22 : CALL safe_fm_destroy_2d(bs_env%fm_chi_R_t)
375 22 : CALL safe_fm_destroy_2d(bs_env%fm_MWM_R_t)
376 22 : CALL safe_fm_destroy_3d(bs_env%fm_Sigma_c_R_neg_tau)
377 22 : CALL safe_fm_destroy_3d(bs_env%fm_Sigma_c_R_pos_tau)
378 :
379 22 : CALL t_destroy_2d(bs_env%t_3c_int)
380 :
381 22 : CALL release_dbcsr_p_type(bs_env%mat_ao_ao)
382 22 : CALL release_dbcsr_p_type(bs_env%mat_RI_RI)
383 22 : CALL safe_dbcsr_deallocate_matrix_set_1d(bs_env%mat_chi_Gamma_tau)
384 :
385 22 : CALL release_dbcsr_p_type(bs_env%mat_ao_ao_tensor)
386 22 : CALL release_dbcsr_p_type(bs_env%mat_RI_RI_tensor)
387 :
388 22 : CALL safe_cfm_destroy_1d(bs_env%cfm_s_kp)
389 22 : CALL safe_cfm_destroy_2d(bs_env%cfm_ks_kp)
390 22 : CALL safe_cfm_destroy_2d(bs_env%cfm_mo_coeff_kp)
391 :
392 22 : CALL mp_para_env_release(bs_env%para_env)
393 22 : IF (ASSOCIATED(bs_env%para_env_tensor)) CALL mp_para_env_release(bs_env%para_env_tensor)
394 :
395 22 : CALL safe_dbt_destroy(bs_env%t_G)
396 22 : CALL safe_dbt_destroy(bs_env%t_chi)
397 22 : CALL safe_dbt_destroy(bs_env%t_W)
398 22 : CALL safe_dbt_destroy(bs_env%t_RI_AO__AO)
399 22 : CALL safe_dbt_destroy(bs_env%t_RI__AO_AO)
400 :
401 22 : IF (ALLOCATED(bs_env%basis_set_AO)) DEALLOCATE (bs_env%basis_set_AO)
402 22 : IF (ALLOCATED(bs_env%basis_set_RI)) DEALLOCATE (bs_env%basis_set_RI)
403 :
404 : ! SOC cfm_1d and arrays
405 22 : CALL safe_dbcsr_deallocate_matrix_set_2d(bs_env%mat_V_SOC_xyz)
406 22 : CALL cp_fm_release(bs_env%fm_V_SOC_xyz_mo(1))
407 22 : CALL cp_fm_release(bs_env%fm_V_SOC_xyz_mo(2))
408 22 : CALL cp_fm_release(bs_env%fm_V_SOC_xyz_mo(3))
409 22 : CALL safe_cfm_destroy_1d(bs_env%cfm_SOC_spinor_ao)
410 :
411 22 : DEALLOCATE (bs_env)
412 :
413 22 : CALL timestop(handle)
414 :
415 22 : END SUBROUTINE bs_env_release
416 :
417 : ! **************************************************************************************************
418 : !> \brief ...
419 : !> \param kpoints ...
420 : ! **************************************************************************************************
421 88 : SUBROUTINE safe_kpoints_release(kpoints)
422 : TYPE(kpoint_type), POINTER :: kpoints
423 :
424 88 : IF (ASSOCIATED(kpoints)) CALL kpoint_release(kpoints)
425 :
426 88 : END SUBROUTINE safe_kpoints_release
427 :
428 : ! **************************************************************************************************
429 : !> \brief ...
430 : !> \param dbcsr_p_type_matrix ...
431 : ! **************************************************************************************************
432 88 : SUBROUTINE release_dbcsr_p_type(dbcsr_p_type_matrix)
433 : TYPE(dbcsr_p_type) :: dbcsr_p_type_matrix
434 :
435 88 : IF (ASSOCIATED(dbcsr_p_type_matrix%matrix)) THEN
436 88 : CALL dbcsr_release(dbcsr_p_type_matrix%matrix)
437 88 : DEALLOCATE (dbcsr_p_type_matrix%matrix)
438 : END IF
439 :
440 88 : END SUBROUTINE release_dbcsr_p_type
441 :
442 : ! **************************************************************************************************
443 : !> \brief ...
444 : !> \param t ...
445 : ! **************************************************************************************************
446 110 : SUBROUTINE safe_dbt_destroy(t)
447 : TYPE(dbt_type) :: t
448 :
449 110 : IF (ASSOCIATED(t%matrix_rep)) CALL dbt_destroy(t)
450 :
451 110 : END SUBROUTINE safe_dbt_destroy
452 :
453 : ! **************************************************************************************************
454 : !> \brief ...
455 : !> \param dbcsr_array ...
456 : ! **************************************************************************************************
457 22 : SUBROUTINE safe_dbcsr_deallocate_matrix_set_1d(dbcsr_array)
458 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: dbcsr_array
459 :
460 22 : IF (ASSOCIATED(dbcsr_array)) CALL dbcsr_deallocate_matrix_set(dbcsr_array)
461 :
462 22 : END SUBROUTINE safe_dbcsr_deallocate_matrix_set_1d
463 :
464 : ! **************************************************************************************************
465 : !> \brief ...
466 : !> \param dbcsr_array ...
467 : ! **************************************************************************************************
468 22 : SUBROUTINE safe_dbcsr_deallocate_matrix_set_2d(dbcsr_array)
469 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: dbcsr_array
470 :
471 22 : IF (ASSOCIATED(dbcsr_array)) CALL dbcsr_deallocate_matrix_set(dbcsr_array)
472 :
473 22 : END SUBROUTINE safe_dbcsr_deallocate_matrix_set_2d
474 :
475 : ! **************************************************************************************************
476 : !> \brief ...
477 : !> \param fm_1d ...
478 : ! **************************************************************************************************
479 44 : SUBROUTINE safe_fm_destroy_1d(fm_1d)
480 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_1d
481 :
482 : INTEGER :: i
483 :
484 44 : IF (ALLOCATED(fm_1d)) THEN
485 120 : DO i = 1, SIZE(fm_1d, 1)
486 120 : CALL cp_fm_release(fm_1d(i))
487 : END DO
488 12 : DEALLOCATE (fm_1d)
489 : END IF
490 :
491 44 : END SUBROUTINE safe_fm_destroy_1d
492 :
493 : ! **************************************************************************************************
494 : !> \brief ...
495 : !> \param fm_2d ...
496 : ! **************************************************************************************************
497 66 : SUBROUTINE safe_fm_destroy_2d(fm_2d)
498 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_2d
499 :
500 : INTEGER :: i, j
501 :
502 66 : IF (ALLOCATED(fm_2d)) THEN
503 272 : DO i = 1, SIZE(fm_2d, 1)
504 1354 : DO j = 1, SIZE(fm_2d, 2)
505 1336 : CALL cp_fm_release(fm_2d(i, j))
506 : END DO
507 : END DO
508 18 : DEALLOCATE (fm_2d)
509 : END IF
510 :
511 66 : END SUBROUTINE safe_fm_destroy_2d
512 :
513 : ! **************************************************************************************************
514 : !> \brief ...
515 : !> \param fm_3d ...
516 : ! **************************************************************************************************
517 44 : SUBROUTINE safe_fm_destroy_3d(fm_3d)
518 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :, :) :: fm_3d
519 :
520 : INTEGER :: i, j, k
521 :
522 44 : IF (ALLOCATED(fm_3d)) THEN
523 120 : DO i = 1, SIZE(fm_3d, 1)
524 1056 : DO j = 1, SIZE(fm_3d, 2)
525 1980 : DO k = 1, SIZE(fm_3d, 3)
526 1872 : CALL cp_fm_release(fm_3d(i, j, k))
527 : END DO
528 : END DO
529 : END DO
530 12 : DEALLOCATE (fm_3d)
531 : END IF
532 :
533 44 : END SUBROUTINE safe_fm_destroy_3d
534 :
535 : ! **************************************************************************************************
536 : !> \brief ...
537 : !> \param cfm_1d ...
538 : ! **************************************************************************************************
539 44 : SUBROUTINE safe_cfm_destroy_1d(cfm_1d)
540 : TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:) :: cfm_1d
541 :
542 : INTEGER :: i
543 :
544 44 : IF (ALLOCATED(cfm_1d)) THEN
545 476 : DO i = 1, SIZE(cfm_1d, 1)
546 476 : CALL cp_cfm_release(cfm_1d(i))
547 : END DO
548 24 : DEALLOCATE (cfm_1d)
549 : END IF
550 :
551 44 : END SUBROUTINE safe_cfm_destroy_1d
552 :
553 : ! **************************************************************************************************
554 : !> \brief ...
555 : !> \param cfm_2d ...
556 : ! **************************************************************************************************
557 44 : SUBROUTINE safe_cfm_destroy_2d(cfm_2d)
558 : TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:, :) :: cfm_2d
559 :
560 : INTEGER :: i, j
561 :
562 44 : IF (ALLOCATED(cfm_2d)) THEN
563 452 : DO i = 1, SIZE(cfm_2d, 1)
564 892 : DO j = 1, SIZE(cfm_2d, 2)
565 880 : CALL cp_cfm_release(cfm_2d(i, j))
566 : END DO
567 : END DO
568 12 : DEALLOCATE (cfm_2d)
569 : END IF
570 :
571 44 : END SUBROUTINE safe_cfm_destroy_2d
572 :
573 : ! **************************************************************************************************
574 : !> \brief ...
575 : !> \param t_2d ...
576 : ! **************************************************************************************************
577 22 : SUBROUTINE t_destroy_2d(t_2d)
578 : TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_2d
579 :
580 : INTEGER :: i, j
581 :
582 22 : IF (ALLOCATED(t_2d)) THEN
583 50 : DO i = 1, SIZE(t_2d, 1)
584 438 : DO j = 1, SIZE(t_2d, 2)
585 432 : CALL dbt_destroy(t_2d(i, j))
586 : END DO
587 : END DO
588 394 : DEALLOCATE (t_2d)
589 : END IF
590 :
591 22 : END SUBROUTINE t_destroy_2d
592 :
593 0 : END MODULE post_scf_bandstructure_types
|