LCOV - code coverage report
Current view: top level - src - dm_ls_scf_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:2fce0f8) Lines: 30 31 96.8 %
Date: 2024-12-21 06:28:57 Functions: 1 10 10.0 %

          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 Types needed for a linear scaling quickstep SCF run based on the density
      10             : !>        matrix
      11             : !> \par History
      12             : !>       2010.10 created [Joost VandeVondele]
      13             : !> \author Joost VandeVondele
      14             : ! **************************************************************************************************
      15             : MODULE dm_ls_scf_types
      16             :    USE cp_dbcsr_api,                    ONLY: dbcsr_release,&
      17             :                                               dbcsr_type
      18             :    USE input_constants,                 ONLY: ls_cluster_atomic,&
      19             :                                               ls_cluster_molecular
      20             :    USE input_section_types,             ONLY: section_vals_release,&
      21             :                                               section_vals_type
      22             :    USE kinds,                           ONLY: dp
      23             :    USE message_passing,                 ONLY: mp_para_env_release,&
      24             :                                               mp_para_env_type
      25             :    USE pao_types,                       ONLY: pao_env_type,&
      26             :                                               pao_finalize
      27             :    USE pexsi_types,                     ONLY: lib_pexsi_env,&
      28             :                                               lib_pexsi_finalize
      29             :    USE qs_density_mixing_types,         ONLY: mixing_storage_release,&
      30             :                                               mixing_storage_type
      31             : #include "./base/base_uses.f90"
      32             : 
      33             :    IMPLICIT NONE
      34             : 
      35             :    PRIVATE
      36             : 
      37             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'dm_ls_scf_types'
      38             : 
      39             :    PUBLIC :: ls_scf_env_type, ls_mstruct_type, ls_cluster_atomic, ls_cluster_molecular, &
      40             :              ls_scf_curvy_type
      41             : 
      42             :    TYPE ls_mstruct_type
      43             :       INTEGER :: cluster_type = -1
      44             :       LOGICAL :: do_pao = .FALSE.
      45             :       INTEGER, DIMENSION(:), ALLOCATABLE :: atom_to_molecule
      46             :       TYPE(dbcsr_type)                :: matrix_A = dbcsr_type()
      47             :       TYPE(dbcsr_type)                :: matrix_B = dbcsr_type()
      48             :    END TYPE
      49             : 
      50             :    TYPE ls_mat_history_type
      51             :       INTEGER :: istore = 0, nstore = 0
      52             :       TYPE(dbcsr_type), DIMENSION(:, :), ALLOCATABLE :: matrix
      53             :    END TYPE
      54             : 
      55             :    TYPE ls_scf_curvy_type
      56             :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_dp
      57             :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_p
      58             :       TYPE(dbcsr_type), DIMENSION(:, :), ALLOCATABLE :: matrix_psave
      59             :       TYPE(dbcsr_type), DIMENSION(:, :), ALLOCATABLE :: matrix_BCH
      60             :       REAL(KIND=dp), DIMENSION(2)                      :: step_size = 0.0_dp
      61             :       REAL(KIND=dp), DIMENSION(2)                      :: shift = 0.0_dp
      62             :       REAL(KIND=dp), DIMENSION(2)                      :: cg_denom = 0.0_dp
      63             :       REAL(KIND=dp), DIMENSION(2)                      :: cg_numer = 0.0_dp
      64             :       REAL(KIND=dp), DIMENSION(6)                      :: energies = 0.0_dp
      65             :       INTEGER                                          :: line_search_step = 0
      66             :       INTEGER, DIMENSION(2)                            :: BCH_saved = 0
      67             :       LOGICAL                                          :: double_step_size = .FALSE.
      68             :       LOGICAL, DIMENSION(2)                            :: fix_shift = .FALSE.
      69             : 
      70             :       INTEGER                                          :: line_search_type = 0
      71             :       INTEGER                                          :: n_bch_hist = 0
      72             :       REAL(KIND=dp)                                    :: scale_filter = 0.0_dp
      73             :       REAL(KIND=dp)                                    :: filter_factor = 0.0_dp
      74             :       REAL(KIND=dp)                                    :: min_shift = 0.0_dp
      75             :       REAL(KIND=dp)                                    :: min_filter = 0.0_dp
      76             :    END TYPE
      77             : 
      78             :    TYPE chebyshev_type
      79             :       LOGICAL :: compute_chebyshev = .FALSE.
      80             :       INTEGER :: n_chebyshev = 0
      81             :       INTEGER :: n_gridpoint_dos = 0
      82             :       REAL(KIND=dp), DIMENSION(:), POINTER :: min_energy => NULL()
      83             :       REAL(KIND=dp), DIMENSION(:), POINTER :: max_energy => NULL()
      84             :       TYPE(section_vals_type), POINTER :: print_key_dos => NULL()
      85             :       TYPE(section_vals_type), POINTER :: print_key_cube => NULL()
      86             :    END TYPE
      87             : 
      88             :    TYPE ls_scf_env_type
      89             :       INTEGER               :: nspins = 0, natoms = 0
      90             :       INTEGER               :: nelectron_total = 0
      91             :       INTEGER, DIMENSION(2) :: nelectron_spin = 0
      92             :       REAL(KIND=dp), DIMENSION(2) ::  mu_spin = 0.0_dp
      93             :       REAL(KIND=dp), DIMENSION(2) ::  homo_spin = 0.0_dp
      94             :       REAL(KIND=dp), DIMENSION(2) ::  lumo_spin = 0.0_dp
      95             : 
      96             : #if defined(FTN_NO_DEFAULT_INIT)
      97             :       TYPE(ls_mat_history_type) :: scf_history = ls_mat_history_type(matrix=null())
      98             : #else
      99             :       TYPE(ls_mat_history_type) :: scf_history = ls_mat_history_type()
     100             : #endif
     101             :       INTEGER :: extrapolation_order = -1
     102             : 
     103             :       LOGICAL :: has_unit_metric = .FALSE.
     104             : 
     105             :       LOGICAL :: curvy_steps = .FALSE.
     106             :       INTEGER :: s_preconditioner_type = 0
     107             :       INTEGER :: s_inversion_type = 0
     108             :       INTEGER :: purification_method = 0
     109             :       INTEGER :: sign_method = 0
     110             :       INTEGER :: sign_order = 0
     111             :       LOGICAL :: sign_symmetric = .FALSE.
     112             :       INTEGER :: submatrix_sign_method = -1
     113             :       INTEGER :: s_sqrt_method = 0
     114             :       INTEGER :: s_sqrt_order = 0
     115             : 
     116             :       LOGICAL               :: needs_s_inv = .FALSE., has_s_preconditioner = .FALSE., fixed_mu = .FALSE., &
     117             :                                dynamic_threshold = .FALSE., check_s_inv = .FALSE.
     118             :       LOGICAL               :: restart_read = .FALSE., restart_write = .FALSE., non_monotonic = .FALSE.
     119             :       REAL(KIND=dp)         :: eps_filter = 0.0_dp, eps_scf = 0.0_dp
     120             : 
     121             :       REAL(KIND=dp)         :: eps_lanczos = 0.0_dp
     122             :       INTEGER               :: max_iter_lanczos = 0
     123             : 
     124             :       REAL(KIND=dp)         :: mixing_fraction = 0.0_dp
     125             :       INTEGER               :: max_scf = 0
     126             :       LOGICAL               :: ls_diis = .FALSE.
     127             :       INTEGER               :: iter_ini_diis = 0
     128             :       INTEGER               :: nmixing = 0, max_diis = 0
     129             :       REAL(KIND=dp)         :: eps_diis = 0.0_dp
     130             :       REAL(KIND=dp)         :: energy_init = 0.0_dp
     131             : 
     132             :       TYPE(dbcsr_type)   :: matrix_s_inv = dbcsr_type()
     133             :       TYPE(dbcsr_type)   :: matrix_s = dbcsr_type()
     134             :       TYPE(dbcsr_type)   :: matrix_bs_sqrt = dbcsr_type(), matrix_bs_sqrt_inv = dbcsr_type()
     135             :       TYPE(dbcsr_type)   :: matrix_s_sqrt = dbcsr_type(), matrix_s_sqrt_inv = dbcsr_type()
     136             :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_ks
     137             :       TYPE(dbcsr_type), DIMENSION(:), ALLOCATABLE :: matrix_p
     138             : 
     139             :       LOGICAL  :: report_all_sparsities = .FALSE., perform_mu_scan = .FALSE., use_s_sqrt = .FALSE.
     140             : 
     141             : #if defined(FTN_NO_DEFAULT_INIT)
     142             :       TYPE(ls_mstruct_type) :: ls_mstruct = ls_mstruct_type(atom_to_molecule=NULL())
     143             :       TYPE(ls_scf_curvy_type) :: curvy_data = ls_scf_curvy_type(matrix_dp=null(), matrix_p=null(), &
     144             :                                                                 matrix_psave=null(), matrix_bch=null())
     145             : #else
     146             :       TYPE(ls_mstruct_type) :: ls_mstruct = ls_mstruct_type()
     147             :       TYPE(ls_scf_curvy_type) :: curvy_data = ls_scf_curvy_type()
     148             : #endif
     149             : 
     150             :       TYPE(chebyshev_type) :: chebyshev = chebyshev_type()
     151             : 
     152             :       LOGICAL :: do_rho_mixing = .FALSE.
     153             :       INTEGER :: density_mixing_method = 0
     154             :       TYPE(mixing_storage_type), POINTER :: mixing_store => NULL()
     155             : 
     156             :       LOGICAL :: do_transport = .FALSE.
     157             :       LOGICAL :: do_pexsi = .FALSE.
     158             : 
     159             :       LOGICAL :: calculate_forces = .FALSE.
     160             : 
     161             : #if defined(__LIBPEXSI)
     162             :       TYPE(lib_pexsi_env) :: pexsi
     163             : #else
     164             :       TYPE(lib_pexsi_env) :: pexsi = lib_pexsi_env()
     165             : #endif
     166             : 
     167             :       TYPE(mp_para_env_type), POINTER :: para_env => NULL()
     168             :       LOGICAL                 :: do_pao = .FALSE.
     169             :       TYPE(pao_env_type)      :: pao_env
     170             :    END TYPE ls_scf_env_type
     171             : 
     172             :    PUBLIC :: ls_scf_release
     173             : 
     174             : CONTAINS
     175             : 
     176             : ! **************************************************************************************************
     177             : !> \brief release the LS type.
     178             : !> \param ls_scf_env ...
     179             : !> \par History
     180             : !>       2012.11 created [Joost VandeVondele]
     181             : !> \author Joost VandeVondele
     182             : ! **************************************************************************************************
     183         364 :    SUBROUTINE ls_scf_release(ls_scf_env)
     184             :       TYPE(ls_scf_env_type), POINTER                     :: ls_scf_env
     185             : 
     186             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'ls_scf_release'
     187             : 
     188             :       INTEGER                                            :: handle, ispin, istore
     189             : 
     190         364 :       CALL timeset(routineN, handle)
     191             : 
     192         364 :       CALL mp_para_env_release(ls_scf_env%para_env)
     193             : 
     194         364 :       DEALLOCATE (ls_scf_env%ls_mstruct%atom_to_molecule)
     195             : 
     196             :       ! set up the buffer for the history of matrices
     197         784 :       DO istore = 1, MIN(ls_scf_env%scf_history%istore, ls_scf_env%scf_history%nstore)
     198        1224 :          DO ispin = 1, SIZE(ls_scf_env%scf_history%matrix, 1)
     199         860 :             CALL dbcsr_release(ls_scf_env%scf_history%matrix(ispin, istore))
     200             :          END DO
     201             :       END DO
     202         364 :       DEALLOCATE (ls_scf_env%scf_history%matrix)
     203             : 
     204         364 :       IF (ALLOCATED(ls_scf_env%matrix_p)) THEN
     205         742 :          DO ispin = 1, SIZE(ls_scf_env%matrix_p)
     206         742 :             CALL dbcsr_release(ls_scf_env%matrix_p(ispin))
     207             :          END DO
     208         364 :          DEALLOCATE (ls_scf_env%matrix_p)
     209             :       END IF
     210             : 
     211         364 :       IF (ASSOCIATED(ls_scf_env%chebyshev%print_key_dos)) &
     212           6 :          CALL section_vals_release(ls_scf_env%chebyshev%print_key_dos)
     213         364 :       IF (ASSOCIATED(ls_scf_env%chebyshev%print_key_cube)) &
     214           6 :          CALL section_vals_release(ls_scf_env%chebyshev%print_key_cube)
     215         364 :       IF (ASSOCIATED(ls_scf_env%chebyshev%min_energy)) THEN
     216           2 :          DEALLOCATE (ls_scf_env%chebyshev%min_energy)
     217             :       END IF
     218         364 :       IF (ASSOCIATED(ls_scf_env%chebyshev%max_energy)) THEN
     219           2 :          DEALLOCATE (ls_scf_env%chebyshev%max_energy)
     220             :       END IF
     221             : 
     222         364 :       IF (ASSOCIATED(ls_scf_env%mixing_store)) THEN
     223         342 :          CALL mixing_storage_release(ls_scf_env%mixing_store)
     224         342 :          DEALLOCATE (ls_scf_env%mixing_store)
     225             :       END IF
     226             : 
     227         364 :       IF (ls_scf_env%do_pexsi) THEN
     228           8 :          CALL lib_pexsi_finalize(ls_scf_env%pexsi)
     229             :       END IF
     230             : 
     231         364 :       IF (ls_scf_env%do_pao) &
     232          96 :          CALL pao_finalize(ls_scf_env%pao_env)
     233             : 
     234         364 :       DEALLOCATE (ls_scf_env)
     235             : 
     236         364 :       CALL timestop(handle)
     237             : 
     238         364 :    END SUBROUTINE ls_scf_release
     239             : 
     240           0 : END MODULE dm_ls_scf_types

Generated by: LCOV version 1.15