LCOV - code coverage report
Current view: top level - src - exstates_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4dc10b3) Lines: 70 75 93.3 %
Date: 2024-11-21 06:45:46 Functions: 4 6 66.7 %

          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 for excited states potential energies
      10             : !> \par History
      11             : !>       2020.01 created
      12             : !> \author JGH
      13             : ! **************************************************************************************************
      14             : MODULE exstates_types
      15             :    USE cp_dbcsr_api,                    ONLY: dbcsr_p_type
      16             :    USE cp_dbcsr_operations,             ONLY: dbcsr_deallocate_matrix_set
      17             :    USE cp_fm_types,                     ONLY: cp_fm_release,&
      18             :                                               cp_fm_type
      19             :    USE input_constants,                 ONLY: xc_kernel_method_best
      20             :    USE input_section_types,             ONLY: section_vals_type,&
      21             :                                               section_vals_val_get
      22             :    USE kinds,                           ONLY: dp
      23             :    USE pw_types,                        ONLY: pw_r3d_rs_type
      24             :    USE qs_local_rho_types,              ONLY: local_rho_set_release,&
      25             :                                               local_rho_type
      26             : #include "./base/base_uses.f90"
      27             : 
      28             :    IMPLICIT NONE
      29             : 
      30             :    PRIVATE
      31             : 
      32             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'exstates_types'
      33             : 
      34             :    PUBLIC :: excited_energy_type, exstate_release, exstate_create
      35             :    PUBLIC :: exstate_matrix_release, exstate_potential_release
      36             :    PUBLIC :: wfn_history_type
      37             : 
      38             : ! *****************************************************************************
      39             : 
      40             :    TYPE wfn_history_type
      41             :       INTEGER                                            :: state = -1
      42             :       REAL(KIND=dp)                                      :: evalue = 0.0_dp
      43             :       TYPE(cp_fm_type), POINTER, DIMENSION(:)            :: evect => NULL()
      44             :       TYPE(cp_fm_type), POINTER, DIMENSION(:)            :: cpmos => NULL()
      45             :       REAL(KIND=dp)                                      :: xsval = 0.0_dp, gsval = 0.0_dp, gsmin = 0.0_dp
      46             :    END TYPE wfn_history_type
      47             : 
      48             : ! *****************************************************************************
      49             : !> \brief Contains information on the excited states energy
      50             : !> \par History
      51             : !>       01.2020 created
      52             : !> \author JGH
      53             : ! *****************************************************************************
      54             :    TYPE excited_energy_type
      55             :       INTEGER                                            :: state = -1
      56             :       REAL(KIND=dp)                                      :: evalue = 0.0_dp
      57             :       INTEGER                                            :: xc_kernel_method = -1
      58             :       REAL(KIND=dp)                                      :: eps_delta_rho = 1.E-02_dp
      59             :       INTEGER                                            :: diff_order = -1
      60             :       LOGICAL                                            :: debug_forces = .FALSE.
      61             :       TYPE(cp_fm_type), POINTER, DIMENSION(:)            :: evect => NULL()
      62             :       TYPE(cp_fm_type), POINTER, DIMENSION(:)            :: cpmos => NULL()
      63             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: matrix_pe => NULL()
      64             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: matrix_hz => NULL()
      65             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: matrix_pe_admm => NULL()
      66             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: matrix_px1 => NULL()
      67             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: matrix_px1_admm => NULL()
      68             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: matrix_px1_asymm => NULL()
      69             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: matrix_px1_admm_asymm => NULL()
      70             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: matrix_wx1 => NULL()
      71             :       TYPE(pw_r3d_rs_type)                               :: vh_rspace = pw_r3d_rs_type()
      72             :       TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER        :: vxc_rspace => NULL()
      73             :       TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER        :: vtau_rspace => NULL()
      74             :       TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER        :: vadmm_rspace => NULL()
      75             :       TYPE(local_rho_type), POINTER                      :: local_rho_set => NULL()
      76             :       TYPE(local_rho_type), POINTER                      :: local_rho_set_admm => NULL()
      77             :       TYPE(wfn_history_type)                             :: wfn_history = wfn_history_type()
      78             :    END TYPE excited_energy_type
      79             : 
      80             : CONTAINS
      81             : 
      82             : ! **************************************************************************************************
      83             : !> \brief ...
      84             : !> \param ex_env ...
      85             : ! **************************************************************************************************
      86        6686 :    SUBROUTINE exstate_release(ex_env)
      87             :       TYPE(excited_energy_type), POINTER                 :: ex_env
      88             : 
      89        6686 :       IF (ASSOCIATED(ex_env)) THEN
      90             : 
      91        6686 :          CALL cp_fm_release(ex_env%evect)
      92        6686 :          CALL cp_fm_release(ex_env%cpmos)
      93             :          !
      94        6686 :          CALL exstate_matrix_release(ex_env)
      95             :          !
      96        6686 :          CALL exstate_potential_release(ex_env)
      97             :          !
      98        6686 :          CALL cp_fm_release(ex_env%wfn_history%evect)
      99        6686 :          CALL cp_fm_release(ex_env%wfn_history%cpmos)
     100             : 
     101        6686 :          DEALLOCATE (ex_env)
     102             : 
     103             :       END IF
     104             : 
     105        6686 :    END SUBROUTINE exstate_release
     106             : 
     107             : ! **************************************************************************************************
     108             : !> \brief ...
     109             : !> \param ex_env ...
     110             : ! **************************************************************************************************
     111        6686 :    SUBROUTINE exstate_matrix_release(ex_env)
     112             :       TYPE(excited_energy_type), POINTER                 :: ex_env
     113             : 
     114        6686 :       IF (ASSOCIATED(ex_env)) THEN
     115        6686 :          IF (ASSOCIATED(ex_env%matrix_pe)) CALL dbcsr_deallocate_matrix_set(ex_env%matrix_pe)
     116        6686 :          NULLIFY (ex_env%matrix_pe)
     117        6686 :          IF (ASSOCIATED(ex_env%matrix_hz)) CALL dbcsr_deallocate_matrix_set(ex_env%matrix_hz)
     118        6686 :          NULLIFY (ex_env%matrix_hz)
     119        6686 :          IF (ASSOCIATED(ex_env%matrix_pe_admm)) CALL dbcsr_deallocate_matrix_set(ex_env%matrix_pe_admm)
     120        6686 :          NULLIFY (ex_env%matrix_pe_admm)
     121        6686 :          IF (ASSOCIATED(ex_env%matrix_px1)) CALL dbcsr_deallocate_matrix_set(ex_env%matrix_px1)
     122        6686 :          NULLIFY (ex_env%matrix_px1)
     123        6686 :          IF (ASSOCIATED(ex_env%matrix_px1_admm)) CALL dbcsr_deallocate_matrix_set(ex_env%matrix_px1_admm)
     124        6686 :          NULLIFY (ex_env%matrix_px1_admm)
     125        6686 :          IF (ASSOCIATED(ex_env%matrix_px1_asymm)) CALL dbcsr_deallocate_matrix_set(ex_env%matrix_px1_asymm)
     126        6686 :          NULLIFY (ex_env%matrix_px1_asymm)
     127        6686 :          IF (ASSOCIATED(ex_env%matrix_px1_admm_asymm)) CALL dbcsr_deallocate_matrix_set(ex_env%matrix_px1_admm_asymm)
     128        6686 :          NULLIFY (ex_env%matrix_px1_admm_asymm)
     129        6686 :          IF (ASSOCIATED(ex_env%matrix_wx1)) CALL dbcsr_deallocate_matrix_set(ex_env%matrix_wx1)
     130        6686 :          NULLIFY (ex_env%matrix_wx1)
     131             :       END IF
     132             : 
     133        6686 :    END SUBROUTINE exstate_matrix_release
     134             : 
     135             : ! **************************************************************************************************
     136             : !> \brief ...
     137             : !> \param ex_env ...
     138             : ! **************************************************************************************************
     139        7236 :    SUBROUTINE exstate_potential_release(ex_env)
     140             :       TYPE(excited_energy_type), POINTER                 :: ex_env
     141             : 
     142             :       INTEGER                                            :: iab
     143             : 
     144        7236 :       IF (ASSOCIATED(ex_env)) THEN
     145        7236 :          IF (ASSOCIATED(ex_env%vh_rspace%pw_grid)) THEN
     146         550 :             CALL ex_env%vh_rspace%release()
     147             :          END IF
     148        7236 :          IF (ASSOCIATED(ex_env%vxc_rspace)) THEN
     149        1196 :             DO iab = 1, SIZE(ex_env%vxc_rspace)
     150        1196 :                CALL ex_env%vxc_rspace(iab)%release()
     151             :             END DO
     152         550 :             DEALLOCATE (ex_env%vxc_rspace)
     153         550 :             NULLIFY (ex_env%vxc_rspace)
     154             :          END IF
     155        7236 :          IF (ASSOCIATED(ex_env%vtau_rspace)) THEN
     156           0 :             DO iab = 1, SIZE(ex_env%vtau_rspace)
     157           0 :                CALL ex_env%vtau_rspace(iab)%release()
     158             :             END DO
     159           0 :             DEALLOCATE (ex_env%vtau_rspace)
     160           0 :             NULLIFY (ex_env%vtau_rspace)
     161             :          END IF
     162        7236 :          IF (ASSOCIATED(ex_env%vadmm_rspace)) THEN
     163         164 :             DO iab = 1, SIZE(ex_env%vadmm_rspace)
     164         164 :                CALL ex_env%vadmm_rspace(iab)%release()
     165             :             END DO
     166          78 :             DEALLOCATE (ex_env%vadmm_rspace)
     167          78 :             NULLIFY (ex_env%vadmm_rspace)
     168             :          END IF
     169        7236 :          IF (ASSOCIATED(ex_env%local_rho_set)) THEN
     170          76 :             CALL local_rho_set_release(ex_env%local_rho_set)
     171          76 :             NULLIFY (ex_env%local_rho_set)
     172             :          END IF
     173        7236 :          IF (ASSOCIATED(ex_env%local_rho_set_admm)) THEN
     174          10 :             CALL local_rho_set_release(ex_env%local_rho_set_admm)
     175          10 :             NULLIFY (ex_env%local_rho_set_admm)
     176             :          END IF
     177             :       END IF
     178             : 
     179        7236 :    END SUBROUTINE exstate_potential_release
     180             : 
     181             : ! **************************************************************************************************
     182             : !> \brief Allocates and intitializes exstate_env
     183             : !> \param ex_env the object to create
     184             : !> \param excited_state ...
     185             : !> \param dft_section ...
     186             : !> \par History
     187             : !>       2020.01 created
     188             : !> \author JGH
     189             : ! **************************************************************************************************
     190        6686 :    SUBROUTINE exstate_create(ex_env, excited_state, dft_section)
     191             :       TYPE(excited_energy_type), POINTER                 :: ex_env
     192             :       LOGICAL, INTENT(IN)                                :: excited_state
     193             :       TYPE(section_vals_type), POINTER                   :: dft_section
     194             : 
     195        6686 :       CPASSERT(.NOT. ASSOCIATED(ex_env))
     196        6686 :       ALLOCATE (ex_env)
     197             :       ex_env%evalue = 0.0_dp
     198             :       NULLIFY (ex_env%evect)
     199        6686 :       IF (excited_state) THEN
     200         342 :          CALL section_vals_val_get(dft_section, "EXCITED_STATES%STATE", i_val=ex_env%state)
     201             :          CALL section_vals_val_get(dft_section, "EXCITED_STATES%XC_KERNEL_METHOD", &
     202         342 :                                    i_val=ex_env%xc_kernel_method)
     203             :          CALL section_vals_val_get(dft_section, "EXCITED_STATES%DEBUG_FORCES", &
     204         342 :                                    l_val=ex_env%debug_forces)
     205             :          CALL section_vals_val_get(dft_section, "EXCITED_STATES%EPS_DELTA_RHO", &
     206         342 :                                    r_val=ex_env%eps_delta_rho)
     207             :          CALL section_vals_val_get(dft_section, "EXCITED_STATES%DIFF_ORDER", &
     208         342 :                                    i_val=ex_env%diff_order)
     209             :       ELSE
     210        6344 :          ex_env%state = 0
     211        6344 :          ex_env%xc_kernel_method = xc_kernel_method_best
     212             :       END IF
     213        6686 :       ex_env%wfn_history%evalue = 0.0_dp
     214        6686 :       ex_env%wfn_history%state = ex_env%state
     215        6686 :       ex_env%wfn_history%xsval = 1.0_dp
     216        6686 :       ex_env%wfn_history%gsval = 1.0_dp
     217        6686 :       ex_env%wfn_history%gsmin = 1.0_dp
     218        6686 :       NULLIFY (ex_env%wfn_history%cpmos)
     219        6686 :       NULLIFY (ex_env%wfn_history%evect)
     220             : 
     221        6686 :    END SUBROUTINE exstate_create
     222             : 
     223           0 : END MODULE exstates_types

Generated by: LCOV version 1.15