(git:3d5d2e5)
Loading...
Searching...
No Matches
qs_scf_types.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 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! **************************************************************************************************
20 USE cp_fm_types, ONLY: cp_fm_release,&
25 USE kinds, ONLY: dp
43 USE qs_ot_types, ONLY: qs_ot_destroy,&
47#include "./base/base_uses.f90"
48
49 IMPLICIT NONE
50 PRIVATE
51
52 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
53
54 CHARACTER(LEN=*), PARAMETER, PRIVATE :: moduleN = 'qs_scf_types'
55
56 INTEGER, PARAMETER, PUBLIC :: general_diag_method_nr = 1, &
61 ot_method_nr = 10, &
64
65 PUBLIC :: qs_scf_env_type
71
72! **************************************************************************************************
73!> \brief wrapper for temporary and cached objects used in the scf iteration
74!> \par History
75!> 02.2003 created [fawzi]
76!> \author fawzi
77! **************************************************************************************************
78!> \brief Parsed Krylov solver settings of the SCF section. One fully
79!> initialized object exists for every run that selects the
80!> block-Krylov diagonalization. The Gamma and the k-point
81!> drivers read it alike
82! **************************************************************************************************
84 INTEGER :: nkrylov = -1, nblock = -1, max_iter = -1
85 LOGICAL :: always_check_conv = .false.
86 REAL(dp) :: eps_std_diag = -1.0_dp, eps_conv = -1.0_dp, eps_adapt = -1.0_dp
88
89!> \brief Workspace and convergence statistics of the real-Lanczos
90!> Gamma refinement. The k-point drivers never allocate this
91!> type: their complex kernel takes a caller-owned workspace
92! **************************************************************************************************
94 ! the parsed settings of the run, shared with the SCF environment
95 TYPE(krylov_settings_type), POINTER :: settings => null()
96 INTEGER :: nmo_conv = -1, nmo_nc = -1
97 REAL(dp) :: max_res_norm = -1.0_dp, min_res_norm = -1.0_dp
98 REAL(dp), DIMENSION(:), POINTER :: c_eval => null(), t_eval => null()
99 TYPE(cp_fm_type), DIMENSION(:), POINTER :: v_mat => null(), mo_conv => null(), mo_refine => null()
100 TYPE(cp_fm_type), POINTER :: tmp_mat => null()
101 !NOTE: the following matrices are small and could be used as standard array rather than distributed fm
102 TYPE(cp_fm_type), POINTER :: block1_mat => null(), block2_mat => null(), block3_mat => null(), &
103 block4_mat => null(), block5_mat => null()
104 TYPE(cp_fm_type), DIMENSION(:), POINTER :: c_vec => null(), chc_mat => null()
105 END TYPE krylov_workspace_type
106
108 INTEGER :: max_iter = -1, mixing_method = -1
109 REAL(dp) :: eps_diag_sub = -1.0_dp, eps_ene = -1.0_dp, eps_adapt = -1.0_dp
110 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: p_matrix_store => null()
111 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: p_matrix_mix => null()
112 TYPE(cp_fm_type), DIMENSION(:), POINTER :: chc_mat => null(), c_vec => null(), c0 => null()
113 TYPE(mixing_storage_type), POINTER :: mixing_store => null()
114 END TYPE subspace_env_type
115
116 TYPE floating_basis_type
117 REAL(kind=dp), DIMENSION(:, :), POINTER :: gradient => null()
118 END TYPE floating_basis_type
119! **************************************************************************************************
122 INTEGER :: iter_count = -1
123 INTEGER :: cholesky_method = -1, nelectron = -1, method = -1, mixing_method = -1, nskip_mixing = -1
124 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
125 ! ADIIS diagnostics: accepted-step norm and raw-map delta.
126 REAL(kind=dp) :: step_norm = -1.0_dp, raw_map_delta = -1.0_dp
127 ! Occupied-space regularization used only to generate ADIIS candidates.
128 REAL(kind=dp) :: adiis_shift = 0.0_dp
129 CHARACTER(LEN=15) :: iter_method = ""
130 COMPLEX(KIND=dp), DIMENSION(:, :, :), POINTER :: cc_buffer => null()
131 LOGICAL :: print_iter_line = .false., skip_mixing = .false., skip_diis = .false., needs_ortho = .false., &
132 adiis_check_next = .false., adiis_validated = .false., &
133 raw_map_delta_valid = .false.
134 TYPE(mixing_storage_type), POINTER :: mixing_store => null()
135 TYPE(cp_fm_type), DIMENSION(:), POINTER :: scf_work1 => null(), scf_work1_red => null()
136 ! Gamma copy plans: overlap at index 0, KS matrices at the spin indices.
137 TYPE(dbcsr_fm_copy_plan_type), ALLOCATABLE :: fm_copy_plan(:)
138 TYPE(cp_fm_type), POINTER :: scf_work2 => null(), ortho => null(), ortho_m1 => null(), &
139 s_half => null(), s_minus_one => null(), &
140 scf_work2_red => null(), ortho_red => null(), ortho_m1_red => null()
141 TYPE(krylov_settings_type), POINTER :: krylov_settings => null()
142 TYPE(krylov_workspace_type), POINTER :: krylov_space => null()
143 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: p_delta => null(), p_mix_new => null()
144 TYPE(dbcsr_type), POINTER :: ortho_dbcsr => null(), buf1_dbcsr => null(), buf2_dbcsr => null()
145 TYPE(preconditioner_p_type), DIMENSION(:), POINTER :: ot_preconditioner => null()
146 TYPE(qs_ot_type), POINTER, DIMENSION(:) :: qs_ot_env => null()
147 ! K-point operator routing and overlap are valid for one inner SCF loop.
148 TYPE(kpoint_operator_context_type), ALLOCATABLE :: ot_operator_ctx
149 LOGICAL :: ot_ks_valid = .false.
150 TYPE(qs_diis_buffer_type), POINTER :: scf_diis_buffer => null()
151 TYPE(qs_scf_subspace_buffer_type), POINTER :: scf_subspace_buffer => null()
152 TYPE(subspace_env_type), POINTER :: subspace_env => null()
153 TYPE(davidson_type), POINTER, DIMENSION(:) :: block_davidson_env => null()
154 TYPE(fb_env_obj) :: filter_matrix_env = fb_env_obj()
155 TYPE(floating_basis_type) :: floating_basis = floating_basis_type()
156 !> reference molecular orbitals for the maximum overlap method
157 TYPE(cp_fm_type), DIMENSION(:), POINTER :: mom_ref_mo_coeff => null()
158 !> MOM-related work matrices
159 TYPE(cp_fm_type), DIMENSION(:), POINTER :: mom_overlap => null(), mom_s_mo_coeff => null()
160 END TYPE qs_scf_env_type
161
162CONTAINS
163
164! **************************************************************************************************
165!> \brief Drop k-point OT operator caches before their pools or layout can change.
166!> \param scf_env SCF environment owning the operator context
167! **************************************************************************************************
169 TYPE(qs_scf_env_type), INTENT(INOUT) :: scf_env
170
171 IF (ALLOCATED(scf_env%ot_operator_ctx)) THEN
172 CALL kpoint_operator_context_release(scf_env%ot_operator_ctx)
173 DEALLOCATE (scf_env%ot_operator_ctx)
174 END IF
175 scf_env%ot_ks_valid = .false.
176 END SUBROUTINE scf_env_release_ot_operators
177
178! **************************************************************************************************
179!> \brief allocates and initialize an scf_env
180!> \param scf_env the scf env to initialize
181!> \par History
182!> 02.2003 created [fawzi]
183!> \author fawzi
184! **************************************************************************************************
185 SUBROUTINE scf_env_create(scf_env)
186 TYPE(qs_scf_env_type), INTENT(OUT) :: scf_env
187
188 CHARACTER(LEN=*), PARAMETER :: routinen = 'scf_env_create'
189
190 INTEGER :: handle
191
192 CALL timeset(routinen, handle)
193
194 scf_env%iter_count = 0
195 scf_env%nelectron = 0
196 scf_env%iter_param = 0.0_dp
197 scf_env%iter_delta = 0.0_dp
198 scf_env%step_norm = 0.0_dp
199 scf_env%raw_map_delta = 0.0_dp
200 scf_env%iter_method = ""
201 scf_env%print_iter_line = .true.
202 scf_env%skip_mixing = .false.
203 scf_env%skip_diis = .false.
204 scf_env%needs_ortho = .false.
205 scf_env%adiis_check_next = .false.
206 scf_env%adiis_validated = .false.
207 scf_env%raw_map_delta_valid = .false.
208 scf_env%adiis_shift = 0.0_dp
209 scf_env%method = -1
210 scf_env%mixing_method = -1
211 scf_env%p_mix_alpha = 1.0_dp
212 scf_env%cholesky_method = -1
213 scf_env%outer_scf%iter_count = 0
214 scf_env%sum_zeff_corr = 0.0_dp
215 NULLIFY (scf_env%outer_scf%variables)
216 NULLIFY (scf_env%outer_scf%gradient)
217 NULLIFY (scf_env%outer_scf%energy)
218 NULLIFY (scf_env%outer_scf%count)
219 NULLIFY (scf_env%outer_scf%inv_jacobian)
220 scf_env%outer_scf%deallocate_jacobian = .true.
221 NULLIFY (scf_env%scf_work1)
222 NULLIFY (scf_env%scf_work2)
223 NULLIFY (scf_env%scf_work1_red)
224 NULLIFY (scf_env%scf_work2_red)
225 NULLIFY (scf_env%ortho)
226 NULLIFY (scf_env%ortho_red)
227 NULLIFY (scf_env%ortho_dbcsr)
228 NULLIFY (scf_env%ortho_m1)
229 NULLIFY (scf_env%ortho_m1_red)
230 NULLIFY (scf_env%p_mix_new)
231 NULLIFY (scf_env%ot_preconditioner)
232 NULLIFY (scf_env%qs_ot_env)
233 NULLIFY (scf_env%scf_diis_buffer)
234 NULLIFY (scf_env%scf_subspace_buffer)
235 NULLIFY (scf_env%buf1_dbcsr)
236 NULLIFY (scf_env%buf2_dbcsr)
237 NULLIFY (scf_env%s_half)
238 NULLIFY (scf_env%p_delta)
239 NULLIFY (scf_env%s_minus_one)
240 NULLIFY (scf_env%cc_buffer)
241 NULLIFY (scf_env%mixing_store)
242 NULLIFY (scf_env%krylov_space)
243 NULLIFY (scf_env%subspace_env)
244 NULLIFY (scf_env%block_davidson_env)
245 NULLIFY (scf_env%floating_basis%gradient)
246 CALL fb_env_nullify(scf_env%filter_matrix_env)
247 NULLIFY (scf_env%mom_ref_mo_coeff)
248 NULLIFY (scf_env%mom_overlap)
249 NULLIFY (scf_env%mom_s_mo_coeff)
250
251 CALL timestop(handle)
252
253 END SUBROUTINE scf_env_create
254
255! **************************************************************************************************
256!> \brief function to be called to inform the scf_env about changes
257!> \param scf_env the scf env to inform
258!> \par History
259!> 03.2003 created [fawzi]
260!> \author fawzi
261! **************************************************************************************************
262 SUBROUTINE scf_env_did_change(scf_env)
263 TYPE(qs_scf_env_type), INTENT(INOUT) :: scf_env
264
265 CHARACTER(LEN=*), PARAMETER :: routinen = 'scf_env_did_change'
266
267 INTEGER :: handle
268
269 CALL timeset(routinen, handle)
270
271 CALL scf_env_release_ot_operators(scf_env)
272 IF (ALLOCATED(scf_env%fm_copy_plan)) DEALLOCATE (scf_env%fm_copy_plan)
273 IF (ASSOCIATED(scf_env%p_mix_new)) THEN
274 CALL dbcsr_deallocate_matrix_set(scf_env%p_mix_new)
275 END IF
276 IF (ASSOCIATED(scf_env%p_delta)) THEN
277 CALL dbcsr_deallocate_matrix_set(scf_env%p_delta)
278 END IF
279 IF (ASSOCIATED(scf_env%scf_subspace_buffer)) THEN
280 CALL qs_scf_subspace_buffer_release(scf_env%scf_subspace_buffer)
281 DEALLOCATE (scf_env%scf_subspace_buffer)
282 END IF
283 CALL cp_fm_release(scf_env%mom_ref_mo_coeff)
284
285 CALL timestop(handle)
286
287 END SUBROUTINE scf_env_did_change
288
289! **************************************************************************************************
290!> \brief releases an scf_env (see doc/ReferenceCounting.html)
291!> \param scf_env the environment to release
292!> \par History
293!> 02.2003 created [fawzi]
294!> \author fawzi
295! **************************************************************************************************
296 SUBROUTINE scf_env_release(scf_env)
297
298 TYPE(qs_scf_env_type), INTENT(INOUT) :: scf_env
299
300 CHARACTER(LEN=*), PARAMETER :: routinen = 'scf_env_release'
301
302 INTEGER :: handle, i
303
304 CALL timeset(routinen, handle)
305
306 CALL scf_env_release_ot_operators(scf_env)
307 IF (ALLOCATED(scf_env%fm_copy_plan)) DEALLOCATE (scf_env%fm_copy_plan)
308 CALL cp_fm_release(scf_env%scf_work1)
309 IF (ASSOCIATED(scf_env%scf_work1_red)) THEN
310 CALL cp_fm_release(scf_env%scf_work1_red)
311 DEALLOCATE (scf_env%scf_work1_red)
312 NULLIFY (scf_env%scf_work1_red)
313 END IF
314 IF (ASSOCIATED(scf_env%scf_work2)) THEN
315 CALL cp_fm_release(scf_env%scf_work2)
316 DEALLOCATE (scf_env%scf_work2)
317 NULLIFY (scf_env%scf_work2)
318 END IF
319 IF (ASSOCIATED(scf_env%scf_work2_red)) THEN
320 CALL cp_fm_release(scf_env%scf_work2_red)
321 DEALLOCATE (scf_env%scf_work2_red)
322 NULLIFY (scf_env%scf_work2_red)
323 END IF
324 IF (ASSOCIATED(scf_env%ortho)) THEN
325 CALL cp_fm_release(scf_env%ortho)
326 DEALLOCATE (scf_env%ortho)
327 NULLIFY (scf_env%ortho)
328 END IF
329 IF (ASSOCIATED(scf_env%ortho_red)) THEN
330 CALL cp_fm_release(scf_env%ortho_red)
331 DEALLOCATE (scf_env%ortho_red)
332 NULLIFY (scf_env%ortho_red)
333 END IF
334 IF (ASSOCIATED(scf_env%ortho_m1)) THEN
335 CALL cp_fm_release(scf_env%ortho_m1)
336 DEALLOCATE (scf_env%ortho_m1)
337 NULLIFY (scf_env%ortho_m1)
338 END IF
339 IF (ASSOCIATED(scf_env%ortho_m1_red)) THEN
340 CALL cp_fm_release(scf_env%ortho_m1_red)
341 DEALLOCATE (scf_env%ortho_m1_red)
342 NULLIFY (scf_env%ortho_m1_red)
343 END IF
344 IF (ASSOCIATED(scf_env%ortho_dbcsr)) THEN
345 ! we should not end up here, and give back using the pools
346 CALL dbcsr_deallocate_matrix(scf_env%ortho_dbcsr)
347 END IF
348 IF (ASSOCIATED(scf_env%buf1_dbcsr)) THEN
349 ! we should not end up here, and give back using the pools
350 CALL dbcsr_deallocate_matrix(scf_env%buf1_dbcsr)
351 END IF
352 IF (ASSOCIATED(scf_env%buf2_dbcsr)) THEN
353 ! we should not end up here, and give back using the pools
354 CALL dbcsr_deallocate_matrix(scf_env%buf2_dbcsr)
355 END IF
356 IF (ASSOCIATED(scf_env%s_half)) THEN
357 CALL cp_fm_release(scf_env%s_half)
358 DEALLOCATE (scf_env%s_half)
359 END IF
360 IF (ASSOCIATED(scf_env%s_minus_one)) THEN
361 CALL cp_fm_release(scf_env%s_minus_one)
362 DEALLOCATE (scf_env%s_minus_one)
363 END IF
364 IF (ASSOCIATED(scf_env%p_mix_new)) THEN
365 ! we should not end up here, and give back using the pools
366 CALL dbcsr_deallocate_matrix_set(scf_env%p_mix_new)
367 END IF
368 IF (ASSOCIATED(scf_env%p_delta)) THEN
369 ! we should not end up here, and give back using the pools
370 CALL dbcsr_deallocate_matrix_set(scf_env%p_delta)
371 END IF
372 IF (ASSOCIATED(scf_env%ot_preconditioner)) THEN
373 DO i = 1, SIZE(scf_env%ot_preconditioner)
374 IF (ASSOCIATED(scf_env%ot_preconditioner(i)%preconditioner)) THEN
375 CALL destroy_preconditioner(scf_env%ot_preconditioner(i)%preconditioner)
376 DEALLOCATE (scf_env%ot_preconditioner(i)%preconditioner)
377 END IF
378 END DO
379 DEALLOCATE (scf_env%ot_preconditioner)
380 END IF
381 IF (ASSOCIATED(scf_env%qs_ot_env)) THEN
382 DO i = 1, SIZE(scf_env%qs_ot_env)
383 CALL qs_ot_destroy(scf_env%qs_ot_env(i))
384 END DO
385 DEALLOCATE (scf_env%qs_ot_env)
386 END IF
387 IF (ASSOCIATED(scf_env%scf_diis_buffer)) THEN
388 CALL qs_diis_b_release(scf_env%scf_diis_buffer)
389 DEALLOCATE (scf_env%scf_diis_buffer)
390 END IF
391 IF (ASSOCIATED(scf_env%scf_subspace_buffer)) THEN
392 CALL qs_scf_subspace_buffer_release(scf_env%scf_subspace_buffer)
393 DEALLOCATE (scf_env%scf_subspace_buffer)
394 END IF
395 IF (ASSOCIATED(scf_env%outer_scf%variables)) THEN
396 DEALLOCATE (scf_env%outer_scf%variables)
397 END IF
398 IF (ASSOCIATED(scf_env%outer_scf%count)) THEN
399 DEALLOCATE (scf_env%outer_scf%count)
400 END IF
401 IF (ASSOCIATED(scf_env%outer_scf%gradient)) THEN
402 DEALLOCATE (scf_env%outer_scf%gradient)
403 END IF
404 IF (ASSOCIATED(scf_env%outer_scf%inv_jacobian)) THEN
405 DEALLOCATE (scf_env%outer_scf%inv_jacobian)
406 END IF
407 IF (ASSOCIATED(scf_env%outer_scf%energy)) THEN
408 DEALLOCATE (scf_env%outer_scf%energy)
409 END IF
410 IF (ASSOCIATED(scf_env%cc_buffer)) THEN
411 DEALLOCATE (scf_env%cc_buffer)
412 END IF
413 IF (ASSOCIATED(scf_env%mixing_store)) THEN
414 CALL mixing_storage_release(scf_env%mixing_store)
415 DEALLOCATE (scf_env%mixing_store)
416 END IF
417 IF (ASSOCIATED(scf_env%krylov_space)) THEN
418 CALL krylov_workspace_release(scf_env%krylov_space)
419 END IF
420 IF (ASSOCIATED(scf_env%krylov_settings)) THEN
421 DEALLOCATE (scf_env%krylov_settings)
422 END IF
423 IF (ASSOCIATED(scf_env%subspace_env)) THEN
424 CALL diag_subspace_env_release(scf_env%subspace_env)
425 END IF
426 IF (ASSOCIATED(scf_env%block_davidson_env)) THEN
427 CALL block_davidson_release(scf_env%block_davidson_env)
428 END IF
429 IF (fb_env_has_data(scf_env%filter_matrix_env)) THEN
430 CALL fb_env_release(scf_env%filter_matrix_env)
431 END IF
432 IF (ASSOCIATED(scf_env%floating_basis%gradient)) THEN
433 DEALLOCATE (scf_env%floating_basis%gradient)
434 END IF
435 CALL cp_fm_release(scf_env%mom_ref_mo_coeff)
436 CALL cp_fm_release(scf_env%mom_overlap)
437 CALL cp_fm_release(scf_env%mom_s_mo_coeff)
438
439 CALL timestop(handle)
440
441 END SUBROUTINE scf_env_release
442
443! **************************************************************************************************
444!> \brief creates the Krylov solver settings
445!> \param krylov_settings returned settings object
446!> \param scf_section ...
447! **************************************************************************************************
448 SUBROUTINE krylov_settings_create(krylov_settings, scf_section)
449
450 TYPE(krylov_settings_type), POINTER :: krylov_settings
451 TYPE(section_vals_type), POINTER :: scf_section
452
453 cpassert(.NOT. ASSOCIATED(krylov_settings))
454 ALLOCATE (krylov_settings)
455
456 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%MAX_ITER", &
457 i_val=krylov_settings%max_iter)
458 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%NKRYLOV", &
459 i_val=krylov_settings%nkrylov)
460 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%NBLOCK", &
461 i_val=krylov_settings%nblock)
462 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%EPS_KRYLOV", &
463 r_val=krylov_settings%eps_conv)
464 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%EPS_STD_DIAG", &
465 r_val=krylov_settings%eps_std_diag)
466 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%EPS_ADAPT", &
467 r_val=krylov_settings%eps_adapt)
468 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%KRYLOV%CHECK_MOS_CONV", &
469 l_val=krylov_settings%always_check_conv)
470
471 END SUBROUTINE krylov_settings_create
472
473! **************************************************************************************************
474!> \brief releases the real-Lanczos workspace
475!> \param krylov_space ...
476!> \par History
477!> 05.2009 created [MI]
478!> \author [MI]
479! **************************************************************************************************
480 SUBROUTINE krylov_workspace_release(krylov_space)
481 TYPE(krylov_workspace_type), POINTER :: krylov_space
482
483 IF (ASSOCIATED(krylov_space)) THEN
484
485 IF (ASSOCIATED(krylov_space%c_eval)) THEN
486 DEALLOCATE (krylov_space%c_eval)
487 NULLIFY (krylov_space%c_eval)
488 END IF
489 IF (ASSOCIATED(krylov_space%t_eval)) THEN
490 DEALLOCATE (krylov_space%t_eval)
491 NULLIFY (krylov_space%t_eval)
492 END IF
493
494 IF (ASSOCIATED(krylov_space%v_mat)) THEN
495 CALL cp_fm_release(krylov_space%v_mat)
496 END IF
497 IF (ASSOCIATED(krylov_space%mo_conv)) THEN
498 CALL cp_fm_release(krylov_space%mo_conv)
499 END IF
500 IF (ASSOCIATED(krylov_space%mo_refine)) THEN
501 CALL cp_fm_release(krylov_space%mo_refine)
502 END IF
503 IF (ASSOCIATED(krylov_space%chc_mat)) THEN
504 CALL cp_fm_release(krylov_space%chc_mat)
505 END IF
506 IF (ASSOCIATED(krylov_space%c_vec)) THEN
507 CALL cp_fm_release(krylov_space%c_vec)
508 END IF
509
510 IF (ASSOCIATED(krylov_space%tmp_mat)) THEN
511 CALL cp_fm_release(krylov_space%tmp_mat)
512 DEALLOCATE (krylov_space%tmp_mat)
513 END IF
514 IF (ASSOCIATED(krylov_space%block1_mat)) THEN
515 CALL cp_fm_release(krylov_space%block1_mat)
516 DEALLOCATE (krylov_space%block1_mat)
517 END IF
518 IF (ASSOCIATED(krylov_space%block2_mat)) THEN
519 CALL cp_fm_release(krylov_space%block2_mat)
520 DEALLOCATE (krylov_space%block2_mat)
521 END IF
522 IF (ASSOCIATED(krylov_space%block3_mat)) THEN
523 CALL cp_fm_release(krylov_space%block3_mat)
524 DEALLOCATE (krylov_space%block3_mat)
525 END IF
526 IF (ASSOCIATED(krylov_space%block4_mat)) THEN
527 CALL cp_fm_release(krylov_space%block4_mat)
528 DEALLOCATE (krylov_space%block4_mat)
529 END IF
530 IF (ASSOCIATED(krylov_space%block5_mat)) THEN
531 CALL cp_fm_release(krylov_space%block5_mat)
532 DEALLOCATE (krylov_space%block5_mat)
533 END IF
534
535 DEALLOCATE (krylov_space)
536
537 NULLIFY (krylov_space)
538 END IF
539
540 END SUBROUTINE krylov_workspace_release
541
542! **************************************************************************************************
543!> \brief creates subspace-rotation environment
544!> \param subspace_env ...
545!> \param scf_section ...
546!> \param ecut ...
547!> \par History
548!> 09.2009 created [MI]
549!> \author [MI]
550! **************************************************************************************************
551 SUBROUTINE diag_subspace_env_create(subspace_env, scf_section, ecut)
552
553 TYPE(subspace_env_type), POINTER :: subspace_env
554 TYPE(section_vals_type), POINTER :: scf_section
555 REAL(dp), INTENT(IN) :: ecut
556
557 LOGICAL :: do_mixing
558 TYPE(section_vals_type), POINTER :: mixing_section
559
560 cpassert(.NOT. ASSOCIATED(subspace_env))
561 ALLOCATE (subspace_env)
562
563 NULLIFY (subspace_env%p_matrix_store)
564 NULLIFY (subspace_env%p_matrix_mix)
565 NULLIFY (subspace_env%chc_mat)
566 NULLIFY (subspace_env%c_vec)
567 NULLIFY (subspace_env%c0)
568 NULLIFY (subspace_env%mixing_store)
569 NULLIFY (mixing_section)
570
571 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%MAX_ITER", &
572 i_val=subspace_env%max_iter)
573 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%EPS_ENE", &
574 r_val=subspace_env%eps_ene)
575 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%EPS_SKIP_SUB_DIAG", &
576 r_val=subspace_env%eps_diag_sub)
577 CALL section_vals_val_get(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%EPS_ADAPT_SCF", &
578 r_val=subspace_env%eps_adapt)
579 subspace_env%mixing_method = 0
580 do_mixing = .false.
581 mixing_section => section_vals_get_subs_vals(scf_section, "DIAGONALIZATION%DIAG_SUB_SCF%MIXING")
582 CALL section_vals_val_get(mixing_section, "_SECTION_PARAMETERS_", &
583 l_val=do_mixing)
584 IF (do_mixing) THEN
585 CALL section_vals_val_get(mixing_section, "METHOD", &
586 i_val=subspace_env%mixing_method)
587 IF (subspace_env%mixing_method >= direct_mixing_nr) THEN
588 ALLOCATE (subspace_env%mixing_store)
589 CALL mixing_storage_create(subspace_env%mixing_store, mixing_section, &
590 subspace_env%mixing_method, ecut=ecut)
591 END IF
592 END IF
593
594 END SUBROUTINE diag_subspace_env_create
595
596! **************************************************************************************************
597!> \brief releases subspace-rotation environment
598!> \param subspace_env ...
599!> \par History
600!> 09.2009 created [MI]
601!> \author [MI]
602! **************************************************************************************************
603 SUBROUTINE diag_subspace_env_release(subspace_env)
604 TYPE(subspace_env_type), POINTER :: subspace_env
605
606 IF (ASSOCIATED(subspace_env)) THEN
607
608 IF (ASSOCIATED(subspace_env%p_matrix_store)) THEN
609
610 cpassert(.true.)
611 CALL dbcsr_deallocate_matrix_set(subspace_env%p_matrix_store)
612 END IF
613 CALL cp_fm_release(subspace_env%chc_mat)
614 CALL cp_fm_release(subspace_env%c_vec)
615 CALL cp_fm_release(subspace_env%c0)
616
617 IF (ASSOCIATED(subspace_env%mixing_store)) THEN
618 CALL mixing_storage_release(subspace_env%mixing_store)
619 DEALLOCATE (subspace_env%mixing_store)
620 END IF
621
622 DEALLOCATE (subspace_env)
623 END IF
624
625 END SUBROUTINE diag_subspace_env_release
626
627END MODULE qs_scf_types
subroutine, public dbcsr_deallocate_matrix(matrix)
...
DBCSR operations in CP2K.
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
parameters that control the outer loop of an SCF iteration
types of preconditioners
subroutine, public destroy_preconditioner(preconditioner_env)
...
module that contains the algorithms to perform an iterative diagonalization by the block-Davidson app...
subroutine, public block_davidson_release(bdav_env)
...
module that contains the definitions of the scf types
subroutine, public mixing_storage_release(mixing_store)
releases a mixing_storage
integer, parameter, public direct_mixing_nr
subroutine, public mixing_storage_create(mixing_store, mixing_section, mixing_method, ecut)
creates a mixing_storage
buffer for the diis of the scf
subroutine, public qs_diis_b_release(diis_buffer)
releases the given diis buffer (see doc/ReferenceCounting.html)
logical function, public fb_env_has_data(fb_env)
Checks if a fb_env object is associated with an actual data content or not.
subroutine, public fb_env_release(fb_env)
releases a given fb_env
subroutine, public fb_env_nullify(fb_env)
nullifies a fb_env object, note that this does not release the original object. This procedure is use...
Assembly of real and complex k-point operators from real-space DBCSR matrices. SCF slots and spin row...
subroutine, public kpoint_operator_context_release(ctx)
Release the context together with every buffer it created. Call once, at the end of the fixed-layout ...
orbital transformations
Definition qs_ot_types.F:15
subroutine, public qs_ot_destroy(qs_ot_env)
deallocates data
Data types for the ADIIS SCF subspace accelerator.
subroutine, public qs_scf_subspace_buffer_release(buffer)
Release all matrices and scalar storage owned by a subspace buffer.
module that contains the definitions of the scf types
subroutine, public krylov_workspace_release(krylov_space)
releases the real-Lanczos workspace
subroutine, public scf_env_did_change(scf_env)
function to be called to inform the scf_env about changes
integer, parameter, public ot_diag_method_nr
subroutine, public diag_subspace_env_create(subspace_env, scf_section, ecut)
creates subspace-rotation environment
integer, parameter, public filter_matrix_diag_method_nr
integer, parameter, public block_davidson_diag_method_nr
subroutine, public scf_env_release_ot_operators(scf_env)
Drop k-point OT operator caches before their pools or layout can change.
integer, parameter, public smeagol_method_nr
subroutine, public krylov_settings_create(krylov_settings, scf_section)
creates the Krylov solver settings
integer, parameter, public ot_method_nr
subroutine, public scf_env_create(scf_env)
allocates and initialize an scf_env
integer, parameter, public special_diag_method_nr
integer, parameter, public block_krylov_diag_method_nr
subroutine, public scf_env_release(scf_env)
releases an scf_env (see doc/ReferenceCounting.html)
integer, parameter, public general_diag_method_nr
represent a full matrix
keeps a buffer with the previous values of s,p,k
the object container which allows for the creation of an array of pointers to fb_env
Caller-owned assembly context for a fixed geometry and parallel layout. OT retains it for one inner S...
History buffer holding strictly paired P and F[P] SCF states.
wrapper for temporary and cached objects used in the scf iteration
Workspace and convergence statistics of the real-Lanczos Gamma refinement. The k-point drivers never ...