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