LCOV - code coverage report
Current view: top level - src - qs_scf_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4c33f95) Lines: 187 214 87.4 %
Date: 2025-01-30 06:53:08 Functions: 7 11 63.6 %

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

Generated by: LCOV version 1.15