LCOV - code coverage report
Current view: top level - src - qs_tddfpt2_fhxc.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:936074a) Lines: 95.2 % 166 158
Test Date: 2025-12-04 06:27:48 Functions: 100.0 % 2 2

            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              : MODULE qs_tddfpt2_fhxc
       9              :    USE admm_types,                      ONLY: admm_type
      10              :    USE cp_control_types,                ONLY: dft_control_type,&
      11              :                                               stda_control_type
      12              :    USE cp_dbcsr_api,                    ONLY: &
      13              :         dbcsr_add, dbcsr_copy, dbcsr_create, dbcsr_deallocate_matrix, dbcsr_get_info, &
      14              :         dbcsr_p_type, dbcsr_release, dbcsr_set, dbcsr_type, dbcsr_type_symmetric
      15              :    USE cp_dbcsr_cp2k_link,              ONLY: cp_dbcsr_alloc_block_from_nbl
      16              :    USE cp_dbcsr_operations,             ONLY: copy_fm_to_dbcsr,&
      17              :                                               cp_dbcsr_plus_fm_fm_t,&
      18              :                                               cp_dbcsr_sm_fm_multiply
      19              :    USE cp_fm_types,                     ONLY: cp_fm_create,&
      20              :                                               cp_fm_get_info,&
      21              :                                               cp_fm_release,&
      22              :                                               cp_fm_type
      23              :    USE input_constants,                 ONLY: do_admm_aux_exch_func_none,&
      24              :                                               no_sf_tddfpt,&
      25              :                                               tddfpt_sf_col,&
      26              :                                               tddfpt_sf_noncol
      27              :    USE kinds,                           ONLY: default_string_length,&
      28              :                                               dp
      29              :    USE lri_environment_types,           ONLY: lri_kind_type
      30              :    USE message_passing,                 ONLY: mp_para_env_type
      31              :    USE parallel_gemm_api,               ONLY: parallel_gemm
      32              :    USE pw_env_types,                    ONLY: pw_env_get
      33              :    USE pw_methods,                      ONLY: pw_axpy,&
      34              :                                               pw_scale,&
      35              :                                               pw_zero
      36              :    USE pw_pool_types,                   ONLY: pw_pool_type
      37              :    USE pw_types,                        ONLY: pw_c1d_gs_type,&
      38              :                                               pw_r3d_rs_type
      39              :    USE qs_environment_types,            ONLY: get_qs_env,&
      40              :                                               qs_environment_type
      41              :    USE qs_gapw_densities,               ONLY: prepare_gapw_den
      42              :    USE qs_integrate_potential,          ONLY: integrate_v_rspace,&
      43              :                                               integrate_v_rspace_one_center
      44              :    USE qs_kernel_types,                 ONLY: full_kernel_env_type
      45              :    USE qs_ks_atom,                      ONLY: update_ks_atom
      46              :    USE qs_rho_atom_types,               ONLY: rho_atom_type
      47              :    USE qs_rho_methods,                  ONLY: qs_rho_update_rho,&
      48              :                                               qs_rho_update_tddfpt
      49              :    USE qs_rho_types,                    ONLY: qs_rho_get
      50              :    USE qs_tddfpt2_densities,            ONLY: tddfpt_construct_aux_fit_density
      51              :    USE qs_tddfpt2_lri_utils,            ONLY: tddfpt2_lri_Amat
      52              :    USE qs_tddfpt2_operators,            ONLY: tddfpt_apply_coulomb,&
      53              :                                               tddfpt_apply_xc,&
      54              :                                               tddfpt_apply_xc_potential
      55              :    USE qs_tddfpt2_stda_types,           ONLY: stda_env_type
      56              :    USE qs_tddfpt2_stda_utils,           ONLY: stda_calculate_kernel
      57              :    USE qs_tddfpt2_subgroups,            ONLY: tddfpt_subgroup_env_type
      58              :    USE qs_tddfpt2_types,                ONLY: tddfpt_work_matrices
      59              :    USE qs_vxc_atom,                     ONLY: calculate_xc_2nd_deriv_atom
      60              :    USE task_list_types,                 ONLY: task_list_type
      61              : #include "./base/base_uses.f90"
      62              : 
      63              :    IMPLICIT NONE
      64              : 
      65              :    PRIVATE
      66              : 
      67              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_tddfpt2_fhxc'
      68              : 
      69              :    INTEGER, PARAMETER, PRIVATE          :: maxspins = 2
      70              : 
      71              :    PUBLIC :: fhxc_kernel, stda_kernel
      72              : 
      73              : ! **************************************************************************************************
      74              : 
      75              : CONTAINS
      76              : 
      77              : ! **************************************************************************************************
      78              : !> \brief Compute action matrix-vector products with the FHxc Kernel
      79              : !> \param Aop_evects            action of TDDFPT operator on trial vectors (modified on exit)
      80              : !> \param evects                TDDFPT trial vectors
      81              : !> \param is_rks_triplets       indicates that a triplet excited states calculation using
      82              : !>                              spin-unpolarised molecular orbitals has been requested
      83              : !> \param do_hfx                flag that activates computation of exact-exchange terms
      84              : !> \param do_admm ...
      85              : !> \param qs_env                Quickstep environment
      86              : !> \param kernel_env            kernel environment
      87              : !> \param kernel_env_admm_aux   kernel environment for ADMM correction
      88              : !> \param sub_env               parallel (sub)group environment
      89              : !> \param work_matrices         collection of work matrices (modified on exit)
      90              : !> \param admm_symm             use symmetric definition of ADMM kernel correction
      91              : !> \param admm_xc_correction    use ADMM XC kernel correction
      92              : !> \param do_lrigpw ...
      93              : !> \param tddfpt_mgrid ...
      94              : !> \par History
      95              : !>    * 06.2016 created [Sergey Chulkov]
      96              : !>    * 03.2017 refactored [Sergey Chulkov]
      97              : !>    * 04.2019 refactored [JHU]
      98              : ! **************************************************************************************************
      99         3074 :    SUBROUTINE fhxc_kernel(Aop_evects, evects, is_rks_triplets, &
     100              :                           do_hfx, do_admm, qs_env, kernel_env, kernel_env_admm_aux, &
     101              :                           sub_env, work_matrices, admm_symm, admm_xc_correction, do_lrigpw, &
     102              :                           tddfpt_mgrid)
     103              :       TYPE(cp_fm_type), DIMENSION(:, :), INTENT(INOUT)   :: Aop_evects
     104              :       TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN)      :: evects
     105              :       LOGICAL, INTENT(in)                                :: is_rks_triplets, do_hfx, do_admm
     106              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     107              :       TYPE(full_kernel_env_type), POINTER                :: kernel_env, kernel_env_admm_aux
     108              :       TYPE(tddfpt_subgroup_env_type), INTENT(in)         :: sub_env
     109              :       TYPE(tddfpt_work_matrices), INTENT(inout)          :: work_matrices
     110              :       LOGICAL, INTENT(in)                                :: admm_symm, admm_xc_correction, &
     111              :                                                             do_lrigpw, tddfpt_mgrid
     112              : 
     113              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'fhxc_kernel'
     114              : 
     115              :       CHARACTER(LEN=default_string_length)               :: basis_type
     116              :       INTEGER                                            :: handle, ikind, ispin, ivect, nao, &
     117              :                                                             nao_aux, nkind, nspins, nvects, &
     118              :                                                             spinflip
     119         3074 :       INTEGER, DIMENSION(:), POINTER                     :: blk_sizes
     120              :       INTEGER, DIMENSION(maxspins)                       :: nactive
     121              :       LOGICAL                                            :: do_noncol, gapw, gapw_xc
     122              :       TYPE(admm_type), POINTER                           :: admm_env
     123              :       TYPE(cp_fm_type)                                   :: work_aux_orb, work_orb_orb
     124         3074 :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: A_xc_munu_sub, rho_ia_ao, &
     125         3074 :                                                             rho_ia_ao_aux_fit
     126              :       TYPE(dbcsr_type), POINTER                          :: dbwork
     127              :       TYPE(dft_control_type), POINTER                    :: dft_control
     128         3074 :       TYPE(lri_kind_type), DIMENSION(:), POINTER         :: lri_v_int
     129              :       TYPE(mp_para_env_type), POINTER                    :: para_env
     130         3074 :       TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER        :: rho_ia_g, rho_ia_g_aux_fit
     131              :       TYPE(pw_pool_type), POINTER                        :: auxbas_pw_pool
     132         3074 :       TYPE(pw_r3d_rs_type), ALLOCATABLE, DIMENSION(:)    :: V_rspace_sub
     133         3074 :       TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER        :: rho_ia_r, rho_ia_r_aux_fit
     134         3074 :       TYPE(rho_atom_type), DIMENSION(:), POINTER         :: rho1_atom_set, rho_atom_set
     135              :       TYPE(task_list_type), POINTER                      :: task_list
     136              : 
     137         3074 :       CALL timeset(routineN, handle)
     138              : 
     139         3074 :       nspins = SIZE(evects, 1)
     140         3074 :       nvects = SIZE(evects, 2)
     141         3074 :       IF (do_admm) THEN
     142          642 :          CPASSERT(do_hfx)
     143          642 :          CPASSERT(ASSOCIATED(sub_env%admm_A))
     144              :       END IF
     145         3074 :       CALL get_qs_env(qs_env, dft_control=dft_control)
     146              : 
     147         3074 :       gapw = dft_control%qs_control%gapw
     148         3074 :       gapw_xc = dft_control%qs_control%gapw_xc
     149         3074 :       spinflip = dft_control%tddfpt2_control%spinflip
     150              : 
     151         3074 :       do_noncol = spinflip == tddfpt_sf_noncol
     152              : 
     153         3074 :       CALL cp_fm_get_info(evects(1, 1), nrow_global=nao)
     154         6702 :       DO ispin = 1, nspins
     155         6702 :          CALL cp_fm_get_info(evects(ispin, 1), ncol_global=nactive(ispin))
     156              :       END DO
     157              : 
     158              :       CALL qs_rho_get(work_matrices%rho_orb_struct_sub, rho_ao=rho_ia_ao, &
     159         3074 :                       rho_g=rho_ia_g, rho_r=rho_ia_r)
     160         3074 :       IF (do_hfx .AND. do_admm) THEN
     161          642 :          CALL get_qs_env(qs_env, admm_env=admm_env)
     162              :          CALL qs_rho_get(work_matrices%rho_aux_fit_struct_sub, &
     163              :                          rho_ao=rho_ia_ao_aux_fit, rho_g=rho_ia_g_aux_fit, &
     164          642 :                          rho_r=rho_ia_r_aux_fit)
     165              :       END IF
     166              : 
     167        10460 :       DO ivect = 1, nvects
     168              : 
     169              :          ! Transform TDDFT vectors to AO space and store them into rho_ia_ao
     170         7386 :          IF (ALLOCATED(work_matrices%evects_sub)) THEN
     171           16 :             IF (ASSOCIATED(work_matrices%evects_sub(1, ivect)%matrix_struct)) THEN
     172           16 :                DO ispin = 1, nspins
     173            8 :                   CALL dbcsr_set(rho_ia_ao(ispin)%matrix, 0.0_dp)
     174              :                   CALL cp_dbcsr_plus_fm_fm_t(rho_ia_ao(ispin)%matrix, &
     175              :                                              matrix_v=sub_env%mos_active(ispin), &
     176              :                                              matrix_g=work_matrices%evects_sub(ispin, ivect), &
     177           16 :                                              ncol=nactive(ispin), symmetry_mode=1)
     178              :                END DO
     179              :             ELSE
     180              :                ! skip trial vectors which are assigned to different parallel groups
     181              :                CYCLE
     182              :             END IF
     183              :          ELSE
     184        16242 :             DO ispin = 1, nspins
     185         8872 :                CALL dbcsr_set(rho_ia_ao(ispin)%matrix, 0.0_dp)
     186              :                CALL cp_dbcsr_plus_fm_fm_t(rho_ia_ao(ispin)%matrix, &
     187              :                                           matrix_v=sub_env%mos_active(ispin), &
     188              :                                           matrix_g=evects(ispin, ivect), &
     189        16242 :                                           ncol=nactive(ispin), symmetry_mode=1)
     190              :             END DO
     191              :          END IF
     192              : 
     193         7378 :          IF (do_lrigpw) THEN
     194              :             CALL qs_rho_update_tddfpt(work_matrices%rho_orb_struct_sub, qs_env, &
     195              :                                       pw_env_external=sub_env%pw_env, &
     196              :                                       task_list_external=sub_env%task_list_orb, &
     197              :                                       para_env_external=sub_env%para_env, &
     198              :                                       tddfpt_lri_env=kernel_env%lri_env, &
     199          172 :                                       tddfpt_lri_density=kernel_env%lri_density)
     200         7206 :          ELSEIF (dft_control%qs_control%lrigpw .OR. &
     201              :                  dft_control%qs_control%rigpw) THEN
     202              :             CALL qs_rho_update_tddfpt(work_matrices%rho_orb_struct_sub, qs_env, &
     203              :                                       pw_env_external=sub_env%pw_env, &
     204              :                                       task_list_external=sub_env%task_list_orb, &
     205            0 :                                       para_env_external=sub_env%para_env)
     206              :          ELSE
     207         7206 :             IF (gapw) THEN
     208              :                CALL qs_rho_update_rho(work_matrices%rho_orb_struct_sub, qs_env, &
     209              :                                       local_rho_set=work_matrices%local_rho_set, &
     210              :                                       pw_env_external=sub_env%pw_env, &
     211              :                                       task_list_external=sub_env%task_list_orb_soft, &
     212         1298 :                                       para_env_external=sub_env%para_env)
     213              :                CALL prepare_gapw_den(qs_env, work_matrices%local_rho_set, &
     214         1298 :                                      do_rho0=(.NOT. is_rks_triplets), pw_env_sub=sub_env%pw_env)
     215         5908 :             ELSEIF (gapw_xc) THEN
     216              :                CALL qs_rho_update_rho(work_matrices%rho_orb_struct_sub, qs_env, &
     217              :                                       rho_xc_external=work_matrices%rho_xc_struct_sub, &
     218              :                                       local_rho_set=work_matrices%local_rho_set, &
     219              :                                       pw_env_external=sub_env%pw_env, &
     220              :                                       task_list_external=sub_env%task_list_orb, &
     221              :                                       task_list_external_soft=sub_env%task_list_orb_soft, &
     222          218 :                                       para_env_external=sub_env%para_env)
     223              :                CALL prepare_gapw_den(qs_env, work_matrices%local_rho_set, do_rho0=.FALSE., &
     224          218 :                                      pw_env_sub=sub_env%pw_env)
     225              :             ELSE
     226              :                CALL qs_rho_update_rho(work_matrices%rho_orb_struct_sub, qs_env, &
     227              :                                       pw_env_external=sub_env%pw_env, &
     228              :                                       task_list_external=sub_env%task_list_orb, &
     229         5690 :                                       para_env_external=sub_env%para_env)
     230              :             END IF
     231              :          END IF
     232              : 
     233        16258 :          DO ispin = 1, nspins
     234        16258 :             CALL dbcsr_set(work_matrices%A_ia_munu_sub(ispin)%matrix, 0.0_dp)
     235              :          END DO
     236              : 
     237              :          ! electron-hole exchange-correlation interaction
     238        16258 :          DO ispin = 1, nspins
     239        16258 :             CALL pw_zero(work_matrices%A_ia_rspace_sub(ispin))
     240              :          END DO
     241              : 
     242              :          ! Skip kernel if collinear xc-kernel for spin-flip is requested
     243         7378 :          IF (spinflip /= tddfpt_sf_col) THEN
     244              : 
     245         7260 :             IF (.NOT. dft_control%tddfpt2_control%do_bse) THEN
     246              :                ! C_x d^{2}E_{x}^{DFT}[\rho] / d\rho^2
     247              :                ! + C_{HF} d^{2}E_{x, ADMM}^{DFT}[\rho] / d\rho^2 in case of ADMM calculation
     248         7260 :                IF (gapw_xc) THEN
     249          218 :                   IF (kernel_env%do_exck) THEN
     250            0 :                      CPABORT("NYA")
     251              :                   ELSE
     252              :                      CALL tddfpt_apply_xc(A_ia_rspace=work_matrices%A_ia_rspace_sub, kernel_env=kernel_env, &
     253              :                                           rho_ia_struct=work_matrices%rho_xc_struct_sub, &
     254              :                                           is_rks_triplets=is_rks_triplets, pw_env=sub_env%pw_env, &
     255              :                                           work_v_xc=work_matrices%wpw_rspace_sub, &
     256              :                                           work_v_xc_tau=work_matrices%wpw_tau_rspace_sub, &
     257          218 :                                           spinflip=spinflip)
     258              :                   END IF
     259          436 :                   DO ispin = 1, nspins
     260              :                      CALL pw_scale(work_matrices%A_ia_rspace_sub(ispin), &
     261          218 :                                    work_matrices%A_ia_rspace_sub(ispin)%pw_grid%dvol)
     262              :                      CALL integrate_v_rspace(v_rspace=work_matrices%A_ia_rspace_sub(ispin), &
     263              :                                              hmat=work_matrices%A_ia_munu_sub(ispin), &
     264              :                                              qs_env=qs_env, calculate_forces=.FALSE., gapw=gapw_xc, &
     265              :                                              pw_env_external=sub_env%pw_env, &
     266          218 :                                              task_list_external=sub_env%task_list_orb_soft)
     267          436 :                      CALL pw_zero(work_matrices%A_ia_rspace_sub(ispin))
     268              :                   END DO
     269              :                ELSE
     270         7042 :                   IF (kernel_env%do_exck) THEN
     271              :                      CALL tddfpt_apply_xc_potential(work_matrices%A_ia_rspace_sub, work_matrices%fxc_rspace_sub, &
     272          156 :                                                     work_matrices%rho_orb_struct_sub, is_rks_triplets)
     273              :                   ELSE
     274              :                      CALL tddfpt_apply_xc(A_ia_rspace=work_matrices%A_ia_rspace_sub, kernel_env=kernel_env, &
     275              :                                           rho_ia_struct=work_matrices%rho_orb_struct_sub, &
     276              :                                           is_rks_triplets=is_rks_triplets, pw_env=sub_env%pw_env, &
     277              :                                           work_v_xc=work_matrices%wpw_rspace_sub, &
     278              :                                           work_v_xc_tau=work_matrices%wpw_tau_rspace_sub, &
     279         6886 :                                           spinflip=spinflip)
     280              :                   END IF
     281              :                END IF
     282         7260 :                IF (gapw .OR. gapw_xc) THEN
     283         1516 :                   rho_atom_set => sub_env%local_rho_set%rho_atom_set
     284         1516 :                   rho1_atom_set => work_matrices%local_rho_set%rho_atom_set
     285              :                   CALL calculate_xc_2nd_deriv_atom(rho_atom_set, rho1_atom_set, qs_env, kernel_env%xc_section, &
     286              :                                                    sub_env%para_env, do_tddfpt2=.TRUE., do_triplet=is_rks_triplets, &
     287         1516 :                                                    do_sf=do_noncol)
     288              :                END IF
     289              : 
     290              :             END IF  ! do_bse
     291              :          END IF ! spin-flip
     292              : 
     293              :          ! ADMM correction
     294         7378 :          IF (do_admm .AND. admm_xc_correction) THEN
     295         1174 :             IF (dft_control%admm_control%aux_exch_func /= do_admm_aux_exch_func_none) THEN
     296              :                CALL tddfpt_construct_aux_fit_density(rho_orb_struct=work_matrices%rho_orb_struct_sub, &
     297              :                                                      rho_aux_fit_struct=work_matrices%rho_aux_fit_struct_sub, &
     298              :                                                      local_rho_set=work_matrices%local_rho_set_admm, &
     299              :                                                      qs_env=qs_env, sub_env=sub_env, &
     300              :                                                      wfm_rho_orb=work_matrices%rho_ao_orb_fm_sub, &
     301              :                                                      wfm_rho_aux_fit=work_matrices%rho_ao_aux_fit_fm_sub, &
     302          846 :                                                      wfm_aux_orb=work_matrices%wfm_aux_orb_sub)
     303              :                ! - C_{HF} d^{2}E_{x, ADMM}^{DFT}[\hat{\rho}] / d\hat{\rho}^2
     304          846 :                IF (admm_symm) THEN
     305          846 :                   CALL dbcsr_get_info(rho_ia_ao_aux_fit(1)%matrix, row_blk_size=blk_sizes)
     306         3384 :                   ALLOCATE (A_xc_munu_sub(nspins))
     307         1692 :                   DO ispin = 1, nspins
     308          846 :                      ALLOCATE (A_xc_munu_sub(ispin)%matrix)
     309              :                      CALL dbcsr_create(matrix=A_xc_munu_sub(ispin)%matrix, name="ADMM_XC", &
     310              :                                        dist=sub_env%dbcsr_dist, matrix_type=dbcsr_type_symmetric, &
     311          846 :                                        row_blk_size=blk_sizes, col_blk_size=blk_sizes)
     312          846 :                      CALL cp_dbcsr_alloc_block_from_nbl(A_xc_munu_sub(ispin)%matrix, sub_env%sab_aux_fit)
     313         1692 :                      CALL dbcsr_set(A_xc_munu_sub(ispin)%matrix, 0.0_dp)
     314              :                   END DO
     315              : 
     316          846 :                   CALL pw_env_get(sub_env%pw_env, auxbas_pw_pool=auxbas_pw_pool)
     317         3384 :                   ALLOCATE (V_rspace_sub(nspins))
     318         1692 :                   DO ispin = 1, nspins
     319          846 :                      CALL auxbas_pw_pool%create_pw(V_rspace_sub(ispin))
     320         1692 :                      CALL pw_zero(V_rspace_sub(ispin))
     321              :                   END DO
     322              : 
     323          846 :                   IF (admm_env%do_gapw) THEN
     324          136 :                      basis_type = "AUX_FIT_SOFT"
     325          136 :                      task_list => sub_env%task_list_aux_fit_soft
     326              :                   ELSE
     327          710 :                      basis_type = "AUX_FIT"
     328          710 :                      task_list => sub_env%task_list_aux_fit
     329              :                   END IF
     330              : 
     331              :                   CALL tddfpt_apply_xc(A_ia_rspace=V_rspace_sub, &
     332              :                                        kernel_env=kernel_env_admm_aux, &
     333              :                                        rho_ia_struct=work_matrices%rho_aux_fit_struct_sub, &
     334              :                                        is_rks_triplets=is_rks_triplets, pw_env=sub_env%pw_env, &
     335              :                                        work_v_xc=work_matrices%wpw_rspace_sub, &
     336              :                                        work_v_xc_tau=work_matrices%wpw_tau_rspace_sub, &
     337          846 :                                        spinflip=spinflip)
     338         1692 :                   DO ispin = 1, nspins
     339          846 :                      CALL pw_scale(V_rspace_sub(ispin), V_rspace_sub(ispin)%pw_grid%dvol)
     340              :                      CALL integrate_v_rspace(v_rspace=V_rspace_sub(ispin), &
     341              :                                              hmat=A_xc_munu_sub(ispin), &
     342              :                                              qs_env=qs_env, calculate_forces=.FALSE., &
     343              :                                              pw_env_external=sub_env%pw_env, &
     344              :                                              basis_type=basis_type, &
     345         1692 :                                              task_list_external=task_list)
     346              :                   END DO
     347          846 :                   IF (admm_env%do_gapw) THEN
     348          136 :                      rho_atom_set => sub_env%local_rho_set_admm%rho_atom_set
     349          136 :                      rho1_atom_set => work_matrices%local_rho_set_admm%rho_atom_set
     350              :                      CALL calculate_xc_2nd_deriv_atom(rho_atom_set, rho1_atom_set, qs_env, &
     351              :                                                       kernel_env_admm_aux%xc_section, &
     352              :                                                       sub_env%para_env, do_tddfpt2=.TRUE., &
     353              :                                                       do_triplet=is_rks_triplets, do_sf=do_noncol, &
     354          136 :                                                       kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
     355              :                      CALL update_ks_atom(qs_env, A_xc_munu_sub, rho_ia_ao_aux_fit, forces=.FALSE., tddft=.TRUE., &
     356              :                                          rho_atom_external=rho1_atom_set, &
     357              :                                          kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
     358              :                                          oce_external=admm_env%admm_gapw_env%oce, &
     359          136 :                                          sab_external=sub_env%sab_aux_fit)
     360              :                   END IF
     361          846 :                   ALLOCATE (dbwork)
     362          846 :                   CALL dbcsr_create(dbwork, template=work_matrices%A_ia_munu_sub(1)%matrix)
     363              :                   CALL cp_fm_create(work_aux_orb, &
     364          846 :                                     matrix_struct=work_matrices%wfm_aux_orb_sub%matrix_struct)
     365              :                   CALL cp_fm_create(work_orb_orb, &
     366          846 :                                     matrix_struct=work_matrices%rho_ao_orb_fm_sub%matrix_struct)
     367          846 :                   CALL cp_fm_get_info(work_aux_orb, nrow_global=nao_aux, ncol_global=nao)
     368         1692 :                   DO ispin = 1, nspins
     369              :                      CALL cp_dbcsr_sm_fm_multiply(A_xc_munu_sub(ispin)%matrix, sub_env%admm_A, &
     370          846 :                                                   work_aux_orb, nao)
     371              :                      CALL parallel_gemm('T', 'N', nao, nao, nao_aux, 1.0_dp, sub_env%admm_A, &
     372          846 :                                         work_aux_orb, 0.0_dp, work_orb_orb)
     373          846 :                      CALL dbcsr_copy(dbwork, work_matrices%A_ia_munu_sub(1)%matrix)
     374          846 :                      CALL dbcsr_set(dbwork, 0.0_dp)
     375          846 :                      CALL copy_fm_to_dbcsr(work_orb_orb, dbwork, keep_sparsity=.TRUE.)
     376         1692 :                      CALL dbcsr_add(work_matrices%A_ia_munu_sub(ispin)%matrix, dbwork, 1.0_dp, 1.0_dp)
     377              :                   END DO
     378          846 :                   CALL dbcsr_release(dbwork)
     379          846 :                   DEALLOCATE (dbwork)
     380         1692 :                   DO ispin = 1, nspins
     381         1692 :                      CALL auxbas_pw_pool%give_back_pw(V_rspace_sub(ispin))
     382              :                   END DO
     383          846 :                   DEALLOCATE (V_rspace_sub)
     384          846 :                   CALL cp_fm_release(work_aux_orb)
     385          846 :                   CALL cp_fm_release(work_orb_orb)
     386         1692 :                   DO ispin = 1, nspins
     387         1692 :                      CALL dbcsr_deallocate_matrix(A_xc_munu_sub(ispin)%matrix)
     388              :                   END DO
     389         1692 :                   DEALLOCATE (A_xc_munu_sub)
     390              :                ELSE
     391              :                   CALL tddfpt_apply_xc(A_ia_rspace=work_matrices%A_ia_rspace_sub, &
     392              :                                        kernel_env=kernel_env_admm_aux, &
     393              :                                        rho_ia_struct=work_matrices%rho_aux_fit_struct_sub, &
     394              :                                        is_rks_triplets=is_rks_triplets, pw_env=sub_env%pw_env, &
     395              :                                        work_v_xc=work_matrices%wpw_rspace_sub, &
     396              :                                        work_v_xc_tau=work_matrices%wpw_tau_rspace_sub, &
     397            0 :                                        spinflip=spinflip)
     398            0 :                   IF (admm_env%do_gapw) THEN
     399            0 :                      CPWARN("GAPW/ADMM needs symmetric ADMM kernel")
     400            0 :                      CPABORT("GAPW/ADMM@TDDFT")
     401              :                   END IF
     402              :                END IF
     403              :             END IF
     404              :          END IF
     405              : 
     406              :          ! electron-hole Coulomb interaction
     407         7378 :          IF ((.NOT. is_rks_triplets) .AND. (spinflip == no_sf_tddfpt)) THEN
     408              :             ! a sum J_i{alpha}a{alpha}_munu + J_i{beta}a{beta}_munu can be computed by solving
     409              :             ! the Poisson equation for combined density (rho_{ia,alpha} + rho_{ia,beta}) .
     410              :             ! The following action will destroy reciprocal-space grid in spin-unrestricted case.
     411         7928 :             DO ispin = 2, nspins
     412         7928 :                CALL pw_axpy(rho_ia_g(ispin), rho_ia_g(1))
     413              :             END DO
     414              :             CALL tddfpt_apply_coulomb(A_ia_rspace=work_matrices%A_ia_rspace_sub, &
     415              :                                       rho_ia_g=rho_ia_g(1), &
     416              :                                       local_rho_set=work_matrices%local_rho_set, &
     417              :                                       hartree_local=work_matrices%hartree_local, &
     418              :                                       qs_env=qs_env, sub_env=sub_env, gapw=gapw, &
     419              :                                       work_v_gspace=work_matrices%wpw_gspace_sub(1), &
     420              :                                       work_v_rspace=work_matrices%wpw_rspace_sub(1), &
     421         6426 :                                       tddfpt_mgrid=tddfpt_mgrid)
     422              :          END IF
     423              : 
     424              :          ! convert from the plane-wave representation into the Gaussian basis set representation
     425        16258 :          DO ispin = 1, nspins
     426        16258 :             IF (.NOT. do_lrigpw) THEN
     427              :                CALL pw_scale(work_matrices%A_ia_rspace_sub(ispin), &
     428         8708 :                              work_matrices%A_ia_rspace_sub(ispin)%pw_grid%dvol)
     429              : 
     430         8708 :                IF (gapw) THEN
     431              :                   CALL integrate_v_rspace(v_rspace=work_matrices%A_ia_rspace_sub(ispin), &
     432              :                                           hmat=work_matrices%A_ia_munu_sub(ispin), &
     433              :                                           qs_env=qs_env, calculate_forces=.FALSE., gapw=gapw, &
     434              :                                           pw_env_external=sub_env%pw_env, &
     435         1418 :                                           task_list_external=sub_env%task_list_orb_soft)
     436         7290 :                ELSEIF (gapw_xc) THEN
     437          218 :                   IF (.NOT. is_rks_triplets) THEN
     438              :                      CALL integrate_v_rspace(v_rspace=work_matrices%A_ia_rspace_sub(ispin), &
     439              :                                              hmat=work_matrices%A_ia_munu_sub(ispin), &
     440              :                                              qs_env=qs_env, calculate_forces=.FALSE., gapw=.FALSE., &
     441          218 :                                              pw_env_external=sub_env%pw_env, task_list_external=sub_env%task_list_orb)
     442              :                   END IF
     443              :                ELSE
     444              :                   CALL integrate_v_rspace(v_rspace=work_matrices%A_ia_rspace_sub(ispin), &
     445              :                                           hmat=work_matrices%A_ia_munu_sub(ispin), &
     446              :                                           qs_env=qs_env, calculate_forces=.FALSE., gapw=.FALSE., &
     447         7072 :                                           pw_env_external=sub_env%pw_env, task_list_external=sub_env%task_list_orb)
     448              :                END IF
     449              :             ELSE ! for full kernel using lri
     450              :                CALL pw_scale(work_matrices%A_ia_rspace_sub(ispin), &
     451          172 :                              work_matrices%A_ia_rspace_sub(ispin)%pw_grid%dvol)
     452          172 :                lri_v_int => kernel_env%lri_density%lri_coefs(ispin)%lri_kinds
     453          172 :                CALL get_qs_env(qs_env, nkind=nkind, para_env=para_env)
     454          516 :                DO ikind = 1, nkind
     455       102304 :                   lri_v_int(ikind)%v_int = 0.0_dp
     456              :                END DO
     457              :                CALL integrate_v_rspace_one_center(work_matrices%A_ia_rspace_sub(ispin), &
     458          172 :                                                   qs_env, lri_v_int, .FALSE., "P_LRI_AUX")
     459          516 :                DO ikind = 1, nkind
     460       204092 :                   CALL para_env%sum(lri_v_int(ikind)%v_int)
     461              :                END DO
     462              :             END IF ! for full kernel using lri
     463              :          END DO
     464              : 
     465              :          ! local atom contributions
     466         7378 :          IF (.NOT. do_lrigpw) THEN
     467         7206 :             IF (gapw .OR. gapw_xc) THEN
     468              :                ! rho_ia_ao will not be touched
     469              :                CALL update_ks_atom(qs_env, work_matrices%A_ia_munu_sub, rho_ia_ao, forces=.FALSE., &
     470              :                                    rho_atom_external=work_matrices%local_rho_set%rho_atom_set, &
     471         1516 :                                    tddft=.TRUE.)
     472              :             END IF
     473              :          END IF
     474              : 
     475              :          ! calculate Coulomb contribution to response vector for lrigpw !
     476              :          ! this is restricting lri to Coulomb only at the moment !
     477         7378 :          IF (do_lrigpw .AND. (.NOT. is_rks_triplets)) THEN !
     478          172 :             CALL tddfpt2_lri_Amat(qs_env, sub_env, kernel_env%lri_env, lri_v_int, work_matrices%A_ia_munu_sub)
     479              :          END IF
     480              : 
     481        19332 :          DO ispin = 1, nspins
     482        16266 :             IF (ALLOCATED(work_matrices%evects_sub)) THEN
     483              :                CALL cp_dbcsr_sm_fm_multiply(work_matrices%A_ia_munu_sub(ispin)%matrix, &
     484              :                                             sub_env%mos_active(ispin), &
     485              :                                             work_matrices%Aop_evects_sub(ispin, ivect), &
     486            8 :                                             ncol=nactive(ispin), alpha=1.0_dp, beta=0.0_dp)
     487              :             ELSE
     488              :                CALL cp_dbcsr_sm_fm_multiply(work_matrices%A_ia_munu_sub(ispin)%matrix, &
     489              :                                             sub_env%mos_active(ispin), &
     490              :                                             Aop_evects(ispin, ivect), &
     491         8872 :                                             ncol=nactive(ispin), alpha=1.0_dp, beta=0.0_dp)
     492              :             END IF
     493              :          END DO
     494              :       END DO
     495              : 
     496         3074 :       CALL timestop(handle)
     497              : 
     498         6148 :    END SUBROUTINE fhxc_kernel
     499              : 
     500              : ! **************************************************************************************************
     501              : !> \brief Compute action matrix-vector products with the sTDA Kernel
     502              : !> \param Aop_evects            action of TDDFPT operator on trial vectors (modified on exit)
     503              : !> \param evects                TDDFPT trial vectors
     504              : !> \param is_rks_triplets       indicates that a triplet excited states calculation using
     505              : !>                              spin-unpolarised molecular orbitals has been requested
     506              : !> \param qs_env                Quickstep environment
     507              : !> \param stda_control          control parameters for sTDA kernel
     508              : !> \param stda_env ...
     509              : !> \param sub_env               parallel (sub)group environment
     510              : !> \param work_matrices         collection of work matrices (modified on exit)
     511              : !> \par History
     512              : !>    * 04.2019 initial version [JHU]
     513              : ! **************************************************************************************************
     514         2264 :    SUBROUTINE stda_kernel(Aop_evects, evects, is_rks_triplets, &
     515              :                           qs_env, stda_control, stda_env, &
     516              :                           sub_env, work_matrices)
     517              : 
     518              :       TYPE(cp_fm_type), DIMENSION(:, :), INTENT(INOUT)   :: Aop_evects
     519              :       TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN)      :: evects
     520              :       LOGICAL, INTENT(in)                                :: is_rks_triplets
     521              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     522              :       TYPE(stda_control_type)                            :: stda_control
     523              :       TYPE(stda_env_type)                                :: stda_env
     524              :       TYPE(tddfpt_subgroup_env_type)                     :: sub_env
     525              :       TYPE(tddfpt_work_matrices), INTENT(inout)          :: work_matrices
     526              : 
     527              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'stda_kernel'
     528              : 
     529              :       INTEGER                                            :: handle, ivect, nvects
     530              : 
     531         2264 :       CALL timeset(routineN, handle)
     532              : 
     533         2264 :       nvects = SIZE(evects, 2)
     534              : 
     535         8726 :       DO ivect = 1, nvects
     536         8726 :          IF (ALLOCATED(work_matrices%evects_sub)) THEN
     537            0 :             IF (ASSOCIATED(work_matrices%evects_sub(1, ivect)%matrix_struct)) THEN
     538              :                CALL stda_calculate_kernel(qs_env, stda_control, stda_env, sub_env, work_matrices, &
     539              :                                           is_rks_triplets, work_matrices%evects_sub(:, ivect), &
     540            0 :                                           work_matrices%Aop_evects_sub(:, ivect))
     541              :             ELSE
     542              :                ! skip trial vectors which are assigned to different parallel groups
     543              :                CYCLE
     544              :             END IF
     545              :          ELSE
     546              :             CALL stda_calculate_kernel(qs_env, stda_control, stda_env, sub_env, work_matrices, &
     547         6462 :                                        is_rks_triplets, evects(:, ivect), Aop_evects(:, ivect))
     548              :          END IF
     549              :       END DO
     550              : 
     551         2264 :       CALL timestop(handle)
     552              : 
     553         2264 :    END SUBROUTINE stda_kernel
     554              : 
     555              : ! **************************************************************************************************
     556              : 
     557              : END MODULE qs_tddfpt2_fhxc
        

Generated by: LCOV version 2.0-1