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 module that contains the definitions of the scf types
10 : !> \par History
11 : !> 02.2003 created [fawzi]
12 : !> \author fawzi
13 : ! **************************************************************************************************
14 : MODULE qs_scf_types
15 : USE cp_dbcsr_api, ONLY: dbcsr_deallocate_matrix,&
16 : dbcsr_p_type,&
17 : dbcsr_type
18 : USE cp_dbcsr_operations, ONLY: dbcsr_deallocate_matrix_set
19 : USE cp_fm_types, ONLY: cp_fm_release,&
20 : cp_fm_type
21 : USE input_section_types, ONLY: section_vals_get_subs_vals,&
22 : section_vals_type,&
23 : section_vals_val_get
24 : USE kinds, ONLY: dp
25 : USE outer_scf_control_types, ONLY: qs_outer_scf_type
26 : USE preconditioner_types, ONLY: destroy_preconditioner,&
27 : preconditioner_p_type
28 : USE qs_block_davidson_types, ONLY: block_davidson_release,&
29 : davidson_type
30 : USE qs_density_mixing_types, ONLY: direct_mixing_nr,&
31 : mixing_storage_create,&
32 : mixing_storage_release,&
33 : mixing_storage_type
34 : USE qs_diis_types, ONLY: qs_diis_b_release,&
35 : qs_diis_buffer_type
36 : USE qs_fb_env_types, ONLY: fb_env_has_data,&
37 : fb_env_nullify,&
38 : fb_env_obj,&
39 : fb_env_release
40 : USE qs_ot_types, ONLY: qs_ot_destroy,&
41 : qs_ot_type
42 : #include "./base/base_uses.f90"
43 :
44 : IMPLICIT NONE
45 : PRIVATE
46 :
47 : LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
48 :
49 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_scf_types'
50 :
51 : INTEGER, PARAMETER, PUBLIC :: general_diag_method_nr = 1, &
52 : special_diag_method_nr = 2, &
53 : ot_diag_method_nr = 3, &
54 : block_krylov_diag_method_nr = 4, &
55 : block_davidson_diag_method_nr = 5, &
56 : ot_method_nr = 10, &
57 : filter_matrix_diag_method_nr = 20, &
58 : smeagol_method_nr = 41
59 :
60 : PUBLIC :: qs_scf_env_type
61 : PUBLIC :: scf_env_release, scf_env_create, scf_env_did_change
62 : PUBLIC :: krylov_space_type, krylov_space_create, subspace_env_type
63 : PUBLIC :: diag_subspace_env_create
64 :
65 : ! **************************************************************************************************
66 : !> \brief wrapper for temporary and cached objects used in the scf iteration
67 : !> \par History
68 : !> 02.2003 created [fawzi]
69 : !> \author fawzi
70 : ! **************************************************************************************************
71 : TYPE krylov_space_type
72 : INTEGER :: nkrylov = -1, nblock = -1, nmo_conv = -1, nmo_nc = -1, max_iter = -1
73 : LOGICAL :: always_check_conv = .FALSE.
74 : REAL(dp) :: eps_std_diag = -1.0_dp, eps_conv = -1.0_dp, eps_adapt = -1.0_dp, max_res_norm = -1.0_dp, min_res_norm = -1.0_dp
75 : REAL(dp), DIMENSION(:), POINTER :: c_eval => NULL(), t_eval => NULL()
76 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: v_mat => NULL(), mo_conv => NULL(), mo_refine => NULL()
77 : TYPE(cp_fm_type), POINTER :: tmp_mat => NULL()
78 : !NOTE: the following matrices are small and could be used as standard array rather than distributed fm
79 : TYPE(cp_fm_type), POINTER :: block1_mat => NULL(), block2_mat => NULL(), block3_mat => NULL(), &
80 : block4_mat => NULL(), block5_mat => NULL()
81 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: c_vec => NULL(), chc_mat => NULL()
82 : END TYPE krylov_space_type
83 :
84 : TYPE subspace_env_type
85 : INTEGER :: max_iter = -1, mixing_method = -1
86 : REAL(dp) :: eps_diag_sub = -1.0_dp, eps_ene = -1.0_dp, eps_adapt = -1.0_dp
87 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: p_matrix_store => NULL()
88 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: p_matrix_mix => NULL()
89 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: chc_mat => NULL(), c_vec => NULL(), c0 => NULL()
90 : TYPE(mixing_storage_type), POINTER :: mixing_store => NULL()
91 : END TYPE subspace_env_type
92 :
93 : TYPE floating_basis_type
94 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: gradient => NULL()
95 : END TYPE floating_basis_type
96 : ! **************************************************************************************************
97 : TYPE qs_scf_env_type
98 : TYPE(qs_outer_scf_type) :: outer_scf = qs_outer_scf_type()
99 : INTEGER :: iter_count = -1
100 : INTEGER :: cholesky_method = -1, nelectron = -1, method = -1, mixing_method = -1, nskip_mixing = -1
101 : REAL(KIND=dp) :: iter_param = -1.0_dp, iter_delta = -1.0_dp, p_mix_alpha = -1.0_dp, sum_zeff_corr = -1.0_dp
102 : CHARACTER(len=15) :: iter_method = ""
103 : COMPLEX(KIND=dp), DIMENSION(:, :, :), POINTER :: cc_buffer => NULL()
104 : LOGICAL :: print_iter_line = .FALSE., skip_mixing = .FALSE., skip_diis = .FALSE., needs_ortho = .FALSE.
105 : TYPE(mixing_storage_type), POINTER :: mixing_store => NULL()
106 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: scf_work1 => NULL()
107 : TYPE(cp_fm_type), POINTER :: scf_work2 => NULL(), ortho => NULL(), ortho_m1 => NULL(), &
108 : s_half => NULL(), s_minus_one => NULL()
109 : TYPE(krylov_space_type), POINTER :: krylov_space => NULL()
110 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: p_delta => NULL(), p_mix_new => NULL()
111 : TYPE(dbcsr_type), POINTER :: ortho_dbcsr => NULL(), buf1_dbcsr => NULL(), buf2_dbcsr => NULL()
112 : TYPE(preconditioner_p_type), DIMENSION(:), POINTER :: ot_preconditioner => NULL()
113 : TYPE(qs_ot_type), POINTER, DIMENSION(:) :: qs_ot_env => NULL()
114 : TYPE(qs_diis_buffer_type), POINTER :: scf_diis_buffer => NULL()
115 : TYPE(subspace_env_type), POINTER :: subspace_env => NULL()
116 : TYPE(davidson_type), POINTER, DIMENSION(:) :: block_davidson_env => NULL()
117 : TYPE(fb_env_obj) :: filter_matrix_env = fb_env_obj()
118 : TYPE(floating_basis_type) :: floating_basis = floating_basis_type()
119 : !> reference molecular orbitals for the maximum overlap method
120 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: mom_ref_mo_coeff => NULL()
121 : !> MOM-related work matrices
122 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: mom_overlap => NULL(), mom_s_mo_coeff => NULL()
123 : END TYPE qs_scf_env_type
124 :
125 : CONTAINS
126 :
127 : ! **************************************************************************************************
128 : !> \brief allocates and initialize an scf_env
129 : !> \param scf_env the scf env to initialize
130 : !> \par History
131 : !> 02.2003 created [fawzi]
132 : !> \author fawzi
133 : ! **************************************************************************************************
134 5691 : SUBROUTINE scf_env_create(scf_env)
135 : TYPE(qs_scf_env_type), INTENT(OUT) :: scf_env
136 :
137 : CHARACTER(len=*), PARAMETER :: routineN = 'scf_env_create'
138 :
139 : INTEGER :: handle
140 :
141 5691 : CALL timeset(routineN, handle)
142 :
143 5691 : scf_env%iter_count = 0
144 5691 : scf_env%nelectron = 0
145 5691 : scf_env%iter_param = 0.0_dp
146 5691 : scf_env%iter_delta = 0.0_dp
147 5691 : scf_env%iter_method = ""
148 5691 : scf_env%print_iter_line = .TRUE.
149 5691 : scf_env%skip_mixing = .FALSE.
150 5691 : scf_env%skip_diis = .FALSE.
151 5691 : scf_env%needs_ortho = .FALSE.
152 5691 : scf_env%method = -1
153 5691 : scf_env%mixing_method = -1
154 5691 : scf_env%p_mix_alpha = 1.0_dp
155 5691 : scf_env%cholesky_method = -1
156 5691 : scf_env%outer_scf%iter_count = 0
157 5691 : scf_env%sum_zeff_corr = 0.0_dp
158 5691 : NULLIFY (scf_env%outer_scf%variables)
159 5691 : NULLIFY (scf_env%outer_scf%gradient)
160 5691 : NULLIFY (scf_env%outer_scf%energy)
161 5691 : NULLIFY (scf_env%outer_scf%count)
162 5691 : NULLIFY (scf_env%outer_scf%inv_jacobian)
163 5691 : scf_env%outer_scf%deallocate_jacobian = .TRUE.
164 5691 : NULLIFY (scf_env%scf_work1)
165 5691 : NULLIFY (scf_env%scf_work2)
166 5691 : NULLIFY (scf_env%ortho)
167 5691 : NULLIFY (scf_env%ortho_dbcsr)
168 5691 : NULLIFY (scf_env%ortho_m1)
169 5691 : NULLIFY (scf_env%p_mix_new)
170 5691 : NULLIFY (scf_env%ot_preconditioner)
171 5691 : NULLIFY (scf_env%qs_ot_env)
172 5691 : NULLIFY (scf_env%scf_diis_buffer)
173 5691 : NULLIFY (scf_env%buf1_dbcsr)
174 5691 : NULLIFY (scf_env%buf2_dbcsr)
175 5691 : NULLIFY (scf_env%s_half)
176 5691 : NULLIFY (scf_env%p_delta)
177 5691 : NULLIFY (scf_env%s_minus_one)
178 5691 : NULLIFY (scf_env%cc_buffer)
179 5691 : NULLIFY (scf_env%mixing_store)
180 5691 : NULLIFY (scf_env%krylov_space)
181 5691 : NULLIFY (scf_env%subspace_env)
182 5691 : NULLIFY (scf_env%block_davidson_env)
183 5691 : NULLIFY (scf_env%floating_basis%gradient)
184 5691 : CALL fb_env_nullify(scf_env%filter_matrix_env)
185 5691 : NULLIFY (scf_env%mom_ref_mo_coeff)
186 5691 : NULLIFY (scf_env%mom_overlap)
187 5691 : NULLIFY (scf_env%mom_s_mo_coeff)
188 :
189 5691 : CALL timestop(handle)
190 :
191 5691 : END SUBROUTINE scf_env_create
192 :
193 : ! **************************************************************************************************
194 : !> \brief function to be called to inform the scf_env about changes
195 : !> \param scf_env the scf env to inform
196 : !> \par History
197 : !> 03.2003 created [fawzi]
198 : !> \author fawzi
199 : ! **************************************************************************************************
200 13322 : SUBROUTINE scf_env_did_change(scf_env)
201 : TYPE(qs_scf_env_type), INTENT(INOUT) :: scf_env
202 :
203 : CHARACTER(len=*), PARAMETER :: routineN = 'scf_env_did_change'
204 :
205 : INTEGER :: handle
206 :
207 13322 : CALL timeset(routineN, handle)
208 :
209 13322 : IF (ASSOCIATED(scf_env%p_mix_new)) THEN
210 1230 : CALL dbcsr_deallocate_matrix_set(scf_env%p_mix_new)
211 : END IF
212 13322 : IF (ASSOCIATED(scf_env%p_delta)) THEN
213 0 : CALL dbcsr_deallocate_matrix_set(scf_env%p_delta)
214 : END IF
215 13322 : CALL cp_fm_release(scf_env%mom_ref_mo_coeff)
216 :
217 13322 : CALL timestop(handle)
218 :
219 13322 : END SUBROUTINE scf_env_did_change
220 :
221 : ! **************************************************************************************************
222 : !> \brief releases an scf_env (see doc/ReferenceCounting.html)
223 : !> \param scf_env the environment to release
224 : !> \par History
225 : !> 02.2003 created [fawzi]
226 : !> \author fawzi
227 : ! **************************************************************************************************
228 5691 : SUBROUTINE scf_env_release(scf_env)
229 :
230 : TYPE(qs_scf_env_type), INTENT(INOUT) :: scf_env
231 :
232 : CHARACTER(len=*), PARAMETER :: routineN = 'scf_env_release'
233 :
234 : INTEGER :: handle, i
235 :
236 5691 : CALL timeset(routineN, handle)
237 :
238 5691 : CALL cp_fm_release(scf_env%scf_work1)
239 5691 : IF (ASSOCIATED(scf_env%scf_work2)) THEN
240 94 : CALL cp_fm_release(scf_env%scf_work2)
241 94 : DEALLOCATE (scf_env%scf_work2)
242 : END IF
243 5691 : IF (ASSOCIATED(scf_env%ortho)) THEN
244 94 : CALL cp_fm_release(scf_env%ortho)
245 94 : DEALLOCATE (scf_env%ortho)
246 : END IF
247 5691 : IF (ASSOCIATED(scf_env%ortho_m1)) THEN
248 0 : CALL cp_fm_release(scf_env%ortho_m1)
249 0 : DEALLOCATE (scf_env%ortho_m1)
250 : END IF
251 5691 : IF (ASSOCIATED(scf_env%ortho_dbcsr)) THEN
252 : ! we should not end up here, and give back using the pools
253 : CPASSERT(.TRUE.)
254 0 : CALL dbcsr_deallocate_matrix(scf_env%ortho_dbcsr)
255 : END IF
256 5691 : IF (ASSOCIATED(scf_env%buf1_dbcsr)) THEN
257 : ! we should not end up here, and give back using the pools
258 : CPASSERT(.TRUE.)
259 0 : CALL dbcsr_deallocate_matrix(scf_env%buf1_dbcsr)
260 : END IF
261 5691 : IF (ASSOCIATED(scf_env%buf2_dbcsr)) THEN
262 : ! we should not end up here, and give back using the pools
263 : CPASSERT(.TRUE.)
264 0 : CALL dbcsr_deallocate_matrix(scf_env%buf2_dbcsr)
265 : END IF
266 5691 : IF (ASSOCIATED(scf_env%s_half)) THEN
267 8 : CALL cp_fm_release(scf_env%s_half)
268 8 : DEALLOCATE (scf_env%s_half)
269 : END IF
270 5691 : IF (ASSOCIATED(scf_env%s_minus_one)) THEN
271 0 : CALL cp_fm_release(scf_env%s_minus_one)
272 0 : DEALLOCATE (scf_env%s_minus_one)
273 : END IF
274 5691 : IF (ASSOCIATED(scf_env%p_mix_new)) THEN
275 : ! we should not end up here, and give back using the pools
276 : CPASSERT(.TRUE.)
277 92 : CALL dbcsr_deallocate_matrix_set(scf_env%p_mix_new)
278 : END IF
279 5691 : IF (ASSOCIATED(scf_env%p_delta)) THEN
280 : ! we should not end up here, and give back using the pools
281 : CPASSERT(.TRUE.)
282 0 : CALL dbcsr_deallocate_matrix_set(scf_env%p_delta)
283 : END IF
284 5691 : IF (ASSOCIATED(scf_env%ot_preconditioner)) THEN
285 4389 : DO i = 1, SIZE(scf_env%ot_preconditioner)
286 2420 : CALL destroy_preconditioner(scf_env%ot_preconditioner(i)%preconditioner)
287 4389 : DEALLOCATE (scf_env%ot_preconditioner(i)%preconditioner)
288 : END DO
289 1969 : DEALLOCATE (scf_env%ot_preconditioner)
290 : END IF
291 5691 : IF (ASSOCIATED(scf_env%qs_ot_env)) THEN
292 0 : DO i = 1, SIZE(scf_env%qs_ot_env)
293 0 : CALL qs_ot_destroy(scf_env%qs_ot_env(i))
294 : END DO
295 0 : DEALLOCATE (scf_env%qs_ot_env)
296 : END IF
297 5691 : IF (ASSOCIATED(scf_env%scf_diis_buffer)) THEN
298 3260 : CALL qs_diis_b_release(scf_env%scf_diis_buffer)
299 3260 : DEALLOCATE (scf_env%scf_diis_buffer)
300 : END IF
301 5691 : IF (ASSOCIATED(scf_env%outer_scf%variables)) THEN
302 0 : DEALLOCATE (scf_env%outer_scf%variables)
303 : END IF
304 5691 : IF (ASSOCIATED(scf_env%outer_scf%count)) THEN
305 0 : DEALLOCATE (scf_env%outer_scf%count)
306 : END IF
307 5691 : IF (ASSOCIATED(scf_env%outer_scf%gradient)) THEN
308 0 : DEALLOCATE (scf_env%outer_scf%gradient)
309 : END IF
310 5691 : IF (ASSOCIATED(scf_env%outer_scf%inv_jacobian)) THEN
311 6 : DEALLOCATE (scf_env%outer_scf%inv_jacobian)
312 : END IF
313 5691 : IF (ASSOCIATED(scf_env%outer_scf%energy)) THEN
314 0 : DEALLOCATE (scf_env%outer_scf%energy)
315 : END IF
316 5691 : IF (ASSOCIATED(scf_env%cc_buffer)) THEN
317 0 : DEALLOCATE (scf_env%cc_buffer)
318 : END IF
319 5691 : IF (ASSOCIATED(scf_env%mixing_store)) THEN
320 5573 : CALL mixing_storage_release(scf_env%mixing_store)
321 5573 : DEALLOCATE (scf_env%mixing_store)
322 : END IF
323 5691 : IF (ASSOCIATED(scf_env%krylov_space)) THEN
324 4 : CALL krylov_space_release(scf_env%krylov_space)
325 : END IF
326 5691 : IF (ASSOCIATED(scf_env%subspace_env)) THEN
327 2 : CALL diag_subspace_env_release(scf_env%subspace_env)
328 : END IF
329 5691 : IF (ASSOCIATED(scf_env%block_davidson_env)) THEN
330 12 : CALL block_davidson_release(scf_env%block_davidson_env)
331 : END IF
332 5691 : IF (fb_env_has_data(scf_env%filter_matrix_env)) THEN
333 10 : CALL fb_env_release(scf_env%filter_matrix_env)
334 : END IF
335 5691 : IF (ASSOCIATED(scf_env%floating_basis%gradient)) THEN
336 0 : DEALLOCATE (scf_env%floating_basis%gradient)
337 : END IF
338 5691 : CALL cp_fm_release(scf_env%mom_ref_mo_coeff)
339 5691 : CALL cp_fm_release(scf_env%mom_overlap)
340 5691 : CALL cp_fm_release(scf_env%mom_s_mo_coeff)
341 :
342 5691 : CALL timestop(handle)
343 :
344 5691 : END SUBROUTINE scf_env_release
345 :
346 : ! **************************************************************************************************
347 : !> \brief creates krylov space
348 : !> \param krylov_space ...
349 : !> \param scf_section ...
350 : !> \par History
351 : !> 05.2009 created [MI]
352 : !> \author [MI]
353 : ! **************************************************************************************************
354 4 : SUBROUTINE krylov_space_create(krylov_space, scf_section)
355 :
356 : TYPE(krylov_space_type), POINTER :: krylov_space
357 : TYPE(section_vals_type), POINTER :: scf_section
358 :
359 4 : CPASSERT(.NOT. ASSOCIATED(krylov_space))
360 4 : ALLOCATE (krylov_space)
361 :
362 : NULLIFY (krylov_space%c_eval, krylov_space%t_eval)
363 : NULLIFY (krylov_space%v_mat)
364 : NULLIFY (krylov_space%mo_conv, krylov_space%mo_refine)
365 : NULLIFY (krylov_space%chc_mat, krylov_space%c_vec)
366 : NULLIFY (krylov_space%tmp_mat)
367 : NULLIFY (krylov_space%block1_mat, krylov_space%block2_mat)
368 : NULLIFY (krylov_space%block3_mat, krylov_space%block4_mat, krylov_space%block5_mat)
369 :
370 : CALL section_vals_val_get(scf_section, "DIAGONALIZATION%MAX_ITER", &
371 4 : i_val=krylov_space%max_iter)
372 : CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%NKRYLOV", &
373 4 : i_val=krylov_space%nkrylov)
374 : CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%NBLOCK", &
375 4 : i_val=krylov_space%nblock)
376 : CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%EPS_KRYLOV", &
377 4 : r_val=krylov_space%eps_conv)
378 : CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%EPS_STD_DIAG", &
379 4 : r_val=krylov_space%eps_std_diag)
380 : CALL section_vals_val_get(scf_section, "DIAGONALIZATION%EPS_ADAPT", &
381 4 : r_val=krylov_space%eps_adapt)
382 : CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%CHECK_MOS_CONV", &
383 4 : l_val=krylov_space%always_check_conv)
384 :
385 4 : END SUBROUTINE krylov_space_create
386 :
387 : ! **************************************************************************************************
388 : !> \brief releases krylov space
389 : !> \param krylov_space ...
390 : !> \par History
391 : !> 05.2009 created [MI]
392 : !> \author [MI]
393 : ! **************************************************************************************************
394 4 : SUBROUTINE krylov_space_release(krylov_space)
395 : TYPE(krylov_space_type), POINTER :: krylov_space
396 :
397 4 : IF (ASSOCIATED(krylov_space)) THEN
398 :
399 4 : DEALLOCATE (krylov_space%c_eval)
400 4 : DEALLOCATE (krylov_space%t_eval)
401 :
402 4 : CALL cp_fm_release(krylov_space%v_mat)
403 4 : CALL cp_fm_release(krylov_space%mo_conv)
404 4 : CALL cp_fm_release(krylov_space%mo_refine)
405 4 : CALL cp_fm_release(krylov_space%chc_mat)
406 4 : CALL cp_fm_release(krylov_space%c_vec)
407 :
408 4 : IF (ASSOCIATED(krylov_space%tmp_mat)) THEN
409 4 : CALL cp_fm_release(krylov_space%tmp_mat)
410 4 : DEALLOCATE (krylov_space%tmp_mat)
411 : END IF
412 4 : IF (ASSOCIATED(krylov_space%block1_mat)) THEN
413 4 : CALL cp_fm_release(krylov_space%block1_mat)
414 4 : DEALLOCATE (krylov_space%block1_mat)
415 : END IF
416 4 : IF (ASSOCIATED(krylov_space%block2_mat)) THEN
417 4 : CALL cp_fm_release(krylov_space%block2_mat)
418 4 : DEALLOCATE (krylov_space%block2_mat)
419 : END IF
420 4 : IF (ASSOCIATED(krylov_space%block3_mat)) THEN
421 4 : CALL cp_fm_release(krylov_space%block3_mat)
422 4 : DEALLOCATE (krylov_space%block3_mat)
423 : END IF
424 4 : IF (ASSOCIATED(krylov_space%block4_mat)) THEN
425 4 : CALL cp_fm_release(krylov_space%block4_mat)
426 4 : DEALLOCATE (krylov_space%block4_mat)
427 : END IF
428 4 : IF (ASSOCIATED(krylov_space%block5_mat)) THEN
429 4 : CALL cp_fm_release(krylov_space%block5_mat)
430 4 : DEALLOCATE (krylov_space%block5_mat)
431 : END IF
432 :
433 4 : DEALLOCATE (krylov_space)
434 :
435 : NULLIFY (krylov_space)
436 : END IF
437 :
438 4 : END SUBROUTINE krylov_space_release
439 :
440 : ! **************************************************************************************************
441 : !> \brief creates subspace-rotation environment
442 : !> \param subspace_env ...
443 : !> \param scf_section ...
444 : !> \param ecut ...
445 : !> \par History
446 : !> 09.2009 created [MI]
447 : !> \author [MI]
448 : ! **************************************************************************************************
449 4 : SUBROUTINE diag_subspace_env_create(subspace_env, scf_section, ecut)
450 :
451 : TYPE(subspace_env_type), POINTER :: subspace_env
452 : TYPE(section_vals_type), POINTER :: scf_section
453 : REAL(dp), INTENT(IN) :: ecut
454 :
455 : LOGICAL :: do_mixing
456 : TYPE(section_vals_type), POINTER :: mixing_section
457 :
458 2 : CPASSERT(.NOT. ASSOCIATED(subspace_env))
459 2 : ALLOCATE (subspace_env)
460 :
461 : NULLIFY (subspace_env%p_matrix_store)
462 : NULLIFY (subspace_env%p_matrix_mix)
463 : NULLIFY (subspace_env%chc_mat)
464 : NULLIFY (subspace_env%c_vec)
465 : NULLIFY (subspace_env%c0)
466 : NULLIFY (subspace_env%mixing_store)
467 2 : NULLIFY (mixing_section)
468 :
469 : CALL section_vals_val_get(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%MAX_ITER", &
470 2 : i_val=subspace_env%max_iter)
471 : CALL section_vals_val_get(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%EPS_ENE", &
472 2 : r_val=subspace_env%eps_ene)
473 : CALL section_vals_val_get(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%EPS_SKIP_SUB_DIAG", &
474 2 : r_val=subspace_env%eps_diag_sub)
475 : CALL section_vals_val_get(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%EPS_ADAPT_SCF", &
476 2 : r_val=subspace_env%eps_adapt)
477 2 : subspace_env%mixing_method = 0
478 : do_mixing = .FALSE.
479 2 : mixing_section => section_vals_get_subs_vals(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%MIXING")
480 : CALL section_vals_val_get(mixing_section, "_SECTION_PARAMETERS_", &
481 2 : l_val=do_mixing)
482 2 : IF (do_mixing) THEN
483 : CALL section_vals_val_get(mixing_section, "METHOD", &
484 2 : i_val=subspace_env%mixing_method)
485 2 : IF (subspace_env%mixing_method >= direct_mixing_nr) THEN
486 8 : ALLOCATE (subspace_env%mixing_store)
487 : CALL mixing_storage_create(subspace_env%mixing_store, mixing_section, &
488 2 : subspace_env%mixing_method, ecut=ecut)
489 : END IF
490 : END IF
491 :
492 2 : END SUBROUTINE diag_subspace_env_create
493 :
494 : ! **************************************************************************************************
495 : !> \brief releases subspace-rotation environment
496 : !> \param subspace_env ...
497 : !> \par History
498 : !> 09.2009 created [MI]
499 : !> \author [MI]
500 : ! **************************************************************************************************
501 2 : SUBROUTINE diag_subspace_env_release(subspace_env)
502 : TYPE(subspace_env_type), POINTER :: subspace_env
503 :
504 2 : IF (ASSOCIATED(subspace_env)) THEN
505 :
506 2 : IF (ASSOCIATED(subspace_env%p_matrix_store)) THEN
507 :
508 : CPASSERT(.TRUE.)
509 2 : CALL dbcsr_deallocate_matrix_set(subspace_env%p_matrix_store)
510 : END IF
511 2 : CALL cp_fm_release(subspace_env%chc_mat)
512 2 : CALL cp_fm_release(subspace_env%c_vec)
513 2 : CALL cp_fm_release(subspace_env%c0)
514 :
515 2 : IF (ASSOCIATED(subspace_env%mixing_store)) THEN
516 2 : CALL mixing_storage_release(subspace_env%mixing_store)
517 2 : DEALLOCATE (subspace_env%mixing_store)
518 : END IF
519 :
520 2 : DEALLOCATE (subspace_env)
521 : END IF
522 :
523 2 : END SUBROUTINE diag_subspace_env_release
524 :
525 0 : END MODULE qs_scf_types
|