LCOV - code coverage report
Current view: top level - src - gw_tensor_small_cell_full_kp.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 99.6 % 468 466
Test Date: 2026-11-24 01:22:08 Functions: 100.0 % 21 21

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief
      10              : !> \author Jan Wilhelm
      11              : !> \date 05.2024
      12              : ! **************************************************************************************************
      13              : MODULE gw_tensor_small_cell_full_kp
      14              :    USE bibliography,                    ONLY: Pasquier2025,&
      15              :                                               cite_reference
      16              :    USE cp_cfm_basic_linalg,             ONLY: cp_cfm_get_diag
      17              :    USE cp_cfm_types,                    ONLY: cp_cfm_create,&
      18              :                                               cp_cfm_release,&
      19              :                                               cp_cfm_to_cfm,&
      20              :                                               cp_cfm_type
      21              :    USE cp_fm_redistribution,            ONLY: cp_fm_to_replicated_array
      22              :    USE cp_fm_types,                     ONLY: cp_fm_set_all,&
      23              :                                               cp_fm_set_submatrix,&
      24              :                                               cp_fm_type
      25              :    USE dbt_api,                         ONLY: dbt_clear,&
      26              :                                               dbt_contract,&
      27              :                                               dbt_copy,&
      28              :                                               dbt_create,&
      29              :                                               dbt_destroy,&
      30              :                                               dbt_type
      31              :    USE dbt_matrix_redistribution,       ONLY: cp_dbt_to_fm,&
      32              :                                               cp_fm_to_dbt
      33              :    USE gw_compute_V_and_W,              ONLY: get_V_tr_R
      34              :    USE gw_utils,                        ONLY: add_R,&
      35              :                                               analyt_conti_and_print,&
      36              :                                               de_init_bs_env,&
      37              :                                               gw_qp_summary_type,&
      38              :                                               is_cell_in_index_to_cell
      39              :    USE gw_utils_fm,                     ONLY: cfm_contract_ABA,&
      40              :                                               local_add_on_diag,&
      41              :                                               local_complex_power
      42              :    USE kinds,                           ONLY: dp,&
      43              :                                               int_8
      44              :    USE kpoint_coulomb_2c,               ONLY: build_2c_coulomb_matrix_kp_dense
      45              :    USE kpoint_k_r_trafo_simple,         ONLY: add_kp_to_all_rs,&
      46              :                                               fm_add_kp_to_all_rs,&
      47              :                                               fm_rs_to_kp,&
      48              :                                               rs_to_kp
      49              :    USE machine,                         ONLY: m_walltime
      50              :    USE mathconstants,                   ONLY: z_one,&
      51              :                                               z_zero
      52              :    USE mathlib,                         ONLY: gemm_square
      53              :    USE post_scf_bandstructure_types,    ONLY: post_scf_bandstructure_type
      54              :    USE post_scf_bandstructure_utils,    ONLY: get_all_VBM_CBM_bandgaps
      55              :    USE qs_environment_types,            ONLY: qs_environment_type
      56              :    USE rpa_gw_im_time_util,             ONLY: build_ao_propagator
      57              :    USE time_frequency_grids,            ONLY: negative_time,&
      58              :                                               positive_time,&
      59              :                                               transform_time_to_frequency
      60              : #include "./base/base_uses.f90"
      61              : 
      62              :    IMPLICIT NONE
      63              : 
      64              :    PRIVATE
      65              : 
      66              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_tensor_small_cell_full_kp'
      67              : 
      68              :    PUBLIC :: gw_calc_tensor_small_cell_full_kp
      69              : 
      70              : CONTAINS
      71              : 
      72              : ! **************************************************************************************************
      73              : !> \brief Perform GW band structure calculation
      74              : !> \param qs_env ...
      75              : !> \param bs_env Band-structure environment containing GW parameters.
      76              : !> \par History
      77              : !>    * 05.2024 created [Jan Wilhelm]
      78              : ! **************************************************************************************************
      79           16 :    SUBROUTINE gw_calc_tensor_small_cell_full_kp(qs_env, bs_env)
      80              :       TYPE(qs_environment_type), POINTER                 :: qs_env
      81              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
      82              : 
      83              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'gw_calc_tensor_small_cell_full_kp'
      84              : 
      85              :       INTEGER                                            :: handle
      86              : 
      87           16 :       CALL timeset(routineN, handle)
      88              : 
      89           16 :       CALL cite_reference(Pasquier2025)
      90              : 
      91              :       ! G^occ_µλ(i|τ|,k) = sum_n^occ C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k)
      92              :       ! G^vir_µλ(i|τ|,k) = sum_n^vir C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k)
      93              :       ! k-point k -> cell S: G^occ/vir_µλ^S(i|τ|) = sum_k w_k G^occ/vir_µλ(i|τ|,k) e^(ikS)
      94              :       ! χ_PQ^R(iτ) = sum_λR1νR2 [ sum_µS (µR1-S νR2 | P0) G^vir_λµ^S(i|τ|) ]
      95              :       !                         [ sum_σS (σR2-S λR1 | QR) G^occ_νσ^S(i|τ|) ]
      96           16 :       CALL compute_chi(bs_env)
      97              : 
      98              :       ! χ_PQ^R(iτ) -> χ_PQ(iω,k) -> ε_PQ(iω,k) -> W_PQ(iω,k) -> Ŵ(iω,k) = M^-1(k)*W(iω,k)*M^-1(k)
      99              :       !            -> Ŵ_PQ^R(iτ)
     100           16 :       CALL compute_W_real_space(bs_env, qs_env)
     101              : 
     102              :       ! D_µν(k) = sum_n^occ C^*_µn(k) C_νn(k), V^tr_PQ^R = <phi_P,0|V^tr|phi_Q,R>
     103              :       ! V^tr(k) = sum_R e^ikR V^tr^R, M(k) = sum_R e^ikR M^R, M(k) -> M^-1(k)
     104              :       ! -> Ṽ^tr(k) = M^-1(k) * V^tr(k) * M^-1(k) -> Ṽ^tr_PQ^R = sum_k w_k e^-ikR Ṽ^tr_PQ(k)
     105              :       ! Σ^x_λσ^R = sum_PR1νS1 [ sum_µS2 (λ0 µS1-S2 | PR1   ) D_µν^S2    ]
     106              :       !                       [ sum_QR2 (σR νS1    | QR1-R2) Ṽ^tr_PQ^R2 ]
     107           16 :       CALL compute_Sigma_x(bs_env, qs_env)
     108              : 
     109              :       ! Σ^c_λσ^R(iτ) = sum_PR1νS1 [ sum_µS2 (λ0 µS1-S2 | PR1   ) G^occ/vir_µν^S2(i|τ|) ]
     110              :       !                           [ sum_QR2 (σR νS1    | QR1-R2) Ŵ_PQ^R2(iτ)           ]
     111           16 :       CALL compute_Sigma_c(bs_env)
     112              : 
     113              :       ! Σ^c_λσ^R(iτ,k=0) -> Σ^c_nn(ϵ,k); ϵ_nk^GW = ϵ_nk^DFT + Σ^c_nn(ϵ,k) + Σ^x_nn(k) - v^xc_nn(k)
     114           16 :       CALL compute_QP_energies(bs_env)
     115              : 
     116           16 :       CALL de_init_bs_env(qs_env, bs_env)
     117              : 
     118           16 :       CALL timestop(handle)
     119              : 
     120           16 :    END SUBROUTINE gw_calc_tensor_small_cell_full_kp
     121              : 
     122              : ! **************************************************************************************************
     123              : !> \brief ...
     124              : !> \param bs_env ...
     125              : ! **************************************************************************************************
     126           16 :    SUBROUTINE compute_chi(bs_env)
     127              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     128              : 
     129              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'compute_chi'
     130              : 
     131              :       INTEGER                                            :: cell_DR(3), cell_R1(3), cell_R2(3), &
     132              :                                                             handle, i_cell_Delta_R, i_cell_R1, &
     133              :                                                             i_cell_R2, i_t, i_task_Delta_R_local, &
     134              :                                                             ispin
     135              :       LOGICAL                                            :: cell_found
     136              :       REAL(KIND=dp)                                      :: t1, tau
     137           16 :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:)          :: Gocc_S, Gvir_S, t_chi_R
     138           16 :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)       :: t_Gocc, t_Gvir
     139              : 
     140           16 :       CALL timeset(routineN, handle)
     141              : 
     142          120 :       DO i_t = 1, bs_env%num_time_freq_points
     143              : 
     144          104 :          CALL dbt_create_2c_R(Gocc_S, bs_env%t_G, bs_env%nimages_scf_desymm)
     145          104 :          CALL dbt_create_2c_R(Gvir_S, bs_env%t_G, bs_env%nimages_scf_desymm)
     146          104 :          CALL dbt_create_2c_R(t_chi_R, bs_env%t_chi, bs_env%nimages_scf_desymm)
     147          104 :          CALL dbt_create_3c_R1_R2(t_Gocc, bs_env%t_RI_AO__AO, bs_env%nimages_3c, bs_env%nimages_3c)
     148          104 :          CALL dbt_create_3c_R1_R2(t_Gvir, bs_env%t_RI_AO__AO, bs_env%nimages_3c, bs_env%nimages_3c)
     149              : 
     150          104 :          t1 = m_walltime()
     151          104 :          tau = bs_env%time_frequency_grid%imaginary_time(i_t)
     152              : 
     153          208 :          DO ispin = 1, bs_env%n_spin
     154              : 
     155              :             ! 1. compute G^occ,S(iτ) and G^vir^S(iτ) in imaginary time for cell S
     156              :             !    Background: G^σ,S(iτ) = G^occ,S,σ(iτ) * Θ(-τ) + G^vir,S,σ(iτ) * Θ(τ), σ ∈ {↑,↓}
     157              :             !    G^occ_µλ(i|τ|,k) = sum_n^occ C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k)
     158              :             !    G^vir_µλ(i|τ|,k) = sum_n^vir C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k)
     159              :             !    k-point k -> cell S: G^occ/vir_µλ^S(i|τ|) = sum_k w_k G^occ/vir_µλ(i|τ|,k) e^(ikS)
     160          104 :             CALL G_occ_vir(bs_env, tau, Gocc_S, ispin, occ=.TRUE., vir=.FALSE.)
     161          104 :             CALL G_occ_vir(bs_env, tau, Gvir_S, ispin, occ=.FALSE., vir=.TRUE.)
     162              : 
     163              :             ! loop over ΔR = R_1 - R_2 which are local in the tensor subgroup
     164         1598 :             DO i_task_Delta_R_local = 1, bs_env%n_tasks_Delta_R_local
     165              : 
     166         1390 :                IF (bs_env%skip_DR_chi(i_task_Delta_R_local)) CYCLE
     167              : 
     168          560 :                i_cell_Delta_R = bs_env%task_Delta_R(i_task_Delta_R_local)
     169              : 
     170         7035 :                DO i_cell_R2 = 1, bs_env%nimages_3c
     171              : 
     172        25900 :                   cell_R2(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_R2)
     173        25900 :                   cell_DR(1:3) = bs_env%index_to_cell_Delta_R(1:3, i_cell_Delta_R)
     174              : 
     175              :                   ! R_1 = R_2 + ΔR (from ΔR = R_2 - R_1)
     176              :                   CALL add_R(cell_R2, cell_DR, bs_env%index_to_cell_3c, cell_R1, &
     177         6475 :                              cell_found, bs_env%cell_to_index_3c, i_cell_R1)
     178              : 
     179              :                   ! 3-cells check because in M^vir_νR2,λR1,QR (step 3.): R2 is index on ν
     180         6475 :                   IF (.NOT. cell_found) CYCLE
     181              :                   ! 2. M^occ/vir_λR1,νR2,P0 = sum_µS (λR1 µR2-S | P0) G^occ/vir_νµ^S(iτ)
     182              :                   CALL G_times_3c(Gocc_S, t_Gocc, bs_env, i_cell_R1, i_cell_R2, &
     183         3491 :                                   i_task_Delta_R_local, bs_env%skip_DR_R12_S_Goccx3c_chi)
     184              :                   CALL G_times_3c(Gvir_S, t_Gvir, bs_env, i_cell_R2, i_cell_R1, &
     185        10526 :                                   i_task_Delta_R_local, bs_env%skip_DR_R12_S_Gvirx3c_chi)
     186              : 
     187              :                END DO ! i_cell_R2
     188              : 
     189              :                ! 3. χ_PQ^R(iτ) = sum_λR1,νR2 M^occ_λR1,νR2,P0 M^vir_νR2,λR1,QR
     190              :                CALL contract_M_occ_vir_to_chi(t_Gocc, t_Gvir, t_chi_R, bs_env, &
     191         1494 :                                               i_task_Delta_R_local)
     192              : 
     193              :             END DO ! i_cell_Delta_R_local
     194              : 
     195              :          END DO ! ispin
     196              : 
     197          104 :          CALL bs_env%para_env%sync()
     198              : 
     199              :          CALL cp_dbt_to_fm(t_chi_R, bs_env%fm_chi_R_t(:, i_t), bs_env%mat_RI_RI, bs_env%mat_RI_RI_tensor, &
     200          104 :                            bs_env%para_env)
     201              : 
     202          104 :          CALL destroy_t_1d(Gocc_S)
     203          104 :          CALL destroy_t_1d(Gvir_S)
     204          104 :          CALL destroy_t_1d(t_chi_R)
     205          104 :          CALL destroy_t_2d(t_Gocc)
     206          104 :          CALL destroy_t_2d(t_Gvir)
     207              : 
     208          120 :          IF (bs_env%unit_nr > 0) THEN
     209              :             WRITE (bs_env%unit_nr, '(T2,A,I13,A,I3,A,F7.1,A)') &
     210           52 :                'Computed χ^R(iτ) for time point', i_t, ' /', bs_env%num_time_freq_points, &
     211          104 :                ',      Execution time', m_walltime() - t1, ' s'
     212              :          END IF
     213              : 
     214              :       END DO ! i_t
     215              : 
     216           16 :       CALL timestop(handle)
     217              : 
     218           16 :    END SUBROUTINE compute_chi
     219              : 
     220              : ! *************************************************************************************************
     221              : !> \brief ...
     222              : !> \param R ...
     223              : !> \param template ...
     224              : !> \param nimages ...
     225              : ! **************************************************************************************************
     226          440 :    SUBROUTINE dbt_create_2c_R(R, template, nimages)
     227              : 
     228              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:)          :: R
     229              :       TYPE(dbt_type)                                     :: template
     230              :       INTEGER                                            :: nimages
     231              : 
     232              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'dbt_create_2c_R'
     233              : 
     234              :       INTEGER                                            :: handle, i_cell_S
     235              : 
     236          440 :       CALL timeset(routineN, handle)
     237              : 
     238         8800 :       ALLOCATE (R(nimages))
     239         4400 :       DO i_cell_S = 1, nimages
     240         4400 :          CALL dbt_create(template, R(i_cell_S))
     241              :       END DO
     242              : 
     243          440 :       CALL timestop(handle)
     244              : 
     245          440 :    END SUBROUTINE dbt_create_2c_R
     246              : 
     247              : ! **************************************************************************************************
     248              : !> \brief ...
     249              : !> \param t_3c_R1_R2 ...
     250              : !> \param t_3c_template ...
     251              : !> \param nimages_1 ...
     252              : !> \param nimages_2 ...
     253              : ! **************************************************************************************************
     254          240 :    SUBROUTINE dbt_create_3c_R1_R2(t_3c_R1_R2, t_3c_template, nimages_1, nimages_2)
     255              : 
     256              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)       :: t_3c_R1_R2
     257              :       TYPE(dbt_type)                                     :: t_3c_template
     258              :       INTEGER                                            :: nimages_1, nimages_2
     259              : 
     260              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'dbt_create_3c_R1_R2'
     261              : 
     262              :       INTEGER                                            :: handle, i_cell, j_cell
     263              : 
     264          240 :       CALL timeset(routineN, handle)
     265              : 
     266        34776 :       ALLOCATE (t_3c_R1_R2(nimages_1, nimages_2))
     267         2812 :       DO i_cell = 1, nimages_1
     268        32136 :          DO j_cell = 1, nimages_2
     269        31896 :             CALL dbt_create(t_3c_template, t_3c_R1_R2(i_cell, j_cell))
     270              :          END DO
     271              :       END DO
     272              : 
     273          240 :       CALL timestop(handle)
     274              : 
     275          240 :    END SUBROUTINE dbt_create_3c_R1_R2
     276              : 
     277              : ! **************************************************************************************************
     278              : !> \brief ...
     279              : !> \param t_G_S ...
     280              : !> \param t_M ...
     281              : !> \param bs_env ...
     282              : !> \param i_cell_R1 ...
     283              : !> \param i_cell_R2 ...
     284              : !> \param i_task_Delta_R_local ...
     285              : !> \param skip_DR_R1_S_Gx3c ...
     286              : ! **************************************************************************************************
     287         6982 :    SUBROUTINE G_times_3c(t_G_S, t_M, bs_env, i_cell_R1, i_cell_R2, i_task_Delta_R_local, &
     288              :                          skip_DR_R1_S_Gx3c)
     289              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:)          :: t_G_S
     290              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)       :: t_M
     291              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     292              :       INTEGER                                            :: i_cell_R1, i_cell_R2, &
     293              :                                                             i_task_Delta_R_local
     294              :       LOGICAL, ALLOCATABLE, DIMENSION(:, :, :)           :: skip_DR_R1_S_Gx3c
     295              : 
     296              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'G_times_3c'
     297              : 
     298              :       INTEGER                                            :: handle, i_cell_R1_p_S, i_cell_S
     299              :       INTEGER(KIND=int_8)                                :: flop
     300              :       INTEGER, DIMENSION(3)                              :: cell_R1, cell_R1_plus_cell_S, cell_R2, &
     301              :                                                             cell_S
     302              :       LOGICAL                                            :: cell_found
     303        62838 :       TYPE(dbt_type)                                     :: t_3c_int
     304              : 
     305         6982 :       CALL timeset(routineN, handle)
     306              : 
     307         6982 :       CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_int)
     308              : 
     309        27928 :       cell_R1(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_R1)
     310        27928 :       cell_R2(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_R2)
     311              : 
     312        69820 :       DO i_cell_S = 1, bs_env%nimages_scf_desymm
     313              : 
     314        62838 :          IF (skip_DR_R1_S_Gx3c(i_task_Delta_R_local, i_cell_R1, i_cell_S)) CYCLE
     315              : 
     316       207412 :          cell_S(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_S)
     317       207412 :          cell_R1_plus_cell_S(1:3) = cell_R1(1:3) + cell_S(1:3)
     318              : 
     319        51853 :          CALL is_cell_in_index_to_cell(cell_R1_plus_cell_S, bs_env%index_to_cell_3c, cell_found)
     320              : 
     321        51853 :          IF (.NOT. cell_found) CYCLE
     322              : 
     323              :          i_cell_R1_p_S = bs_env%cell_to_index_3c(cell_R1_plus_cell_S(1), cell_R1_plus_cell_S(2), &
     324        31949 :                                                  cell_R1_plus_cell_S(3))
     325              : 
     326        31949 :          IF (bs_env%nblocks_3c(i_cell_R2, i_cell_R1_p_S) == 0) CYCLE
     327              : 
     328        17173 :          CALL get_t_3c_int(t_3c_int, bs_env, i_cell_R2, i_cell_R1_p_S)
     329              : 
     330              :          CALL dbt_contract(alpha=1.0_dp, &
     331              :                            tensor_1=t_3c_int, &
     332              :                            tensor_2=t_G_S(i_cell_S), &
     333              :                            beta=1.0_dp, &
     334              :                            tensor_3=t_M(i_cell_R1, i_cell_R2), &
     335              :                            contract_1=[3], notcontract_1=[1, 2], map_1=[1, 2], &
     336              :                            contract_2=[2], notcontract_2=[1], map_2=[3], &
     337        17173 :                            filter_eps=bs_env%eps_filter, flop=flop)
     338              : 
     339        24155 :          IF (flop == 0_int_8) skip_DR_R1_S_Gx3c(i_task_Delta_R_local, i_cell_R1, i_cell_S) = .TRUE.
     340              : 
     341              :       END DO
     342              : 
     343         6982 :       CALL dbt_destroy(t_3c_int)
     344              : 
     345         6982 :       CALL timestop(handle)
     346              : 
     347         6982 :    END SUBROUTINE G_times_3c
     348              : 
     349              : ! **************************************************************************************************
     350              : !> \brief ...
     351              : !> \param t_3c_int ...
     352              : !> \param bs_env ...
     353              : !> \param j_cell ...
     354              : !> \param k_cell ...
     355              : ! **************************************************************************************************
     356        55971 :    SUBROUTINE get_t_3c_int(t_3c_int, bs_env, j_cell, k_cell)
     357              : 
     358              :       TYPE(dbt_type)                                     :: t_3c_int
     359              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     360              :       INTEGER                                            :: j_cell, k_cell
     361              : 
     362              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'get_t_3c_int'
     363              : 
     364              :       INTEGER                                            :: handle
     365              : 
     366        55971 :       CALL timeset(routineN, handle)
     367              : 
     368        55971 :       CALL dbt_clear(t_3c_int)
     369        55971 :       IF (j_cell < k_cell) THEN
     370        22833 :          CALL dbt_copy(bs_env%t_3c_int(k_cell, j_cell), t_3c_int, order=[1, 3, 2])
     371              :       ELSE
     372        33138 :          CALL dbt_copy(bs_env%t_3c_int(j_cell, k_cell), t_3c_int)
     373              :       END IF
     374              : 
     375        55971 :       CALL timestop(handle)
     376              : 
     377        55971 :    END SUBROUTINE get_t_3c_int
     378              : 
     379              : ! **************************************************************************************************
     380              : !> \brief ...
     381              : !> \param bs_env ...
     382              : !> \param tau ...
     383              : !> \param G_S ...
     384              : !> \param ispin ...
     385              : !> \param occ ...
     386              : !> \param vir ...
     387              : ! **************************************************************************************************
     388          432 :    SUBROUTINE G_occ_vir(bs_env, tau, G_S, ispin, occ, vir)
     389              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     390              :       REAL(KIND=dp)                                      :: tau
     391              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:)          :: G_S
     392              :       INTEGER                                            :: ispin
     393              :       LOGICAL                                            :: occ, vir
     394              : 
     395              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'G_occ_vir'
     396              : 
     397              :       INTEGER                                            :: first_mo, handle, homo, i_cell_S, ikp, &
     398              :                                                             j, last_mo, nkp
     399              :       REAL(KIND=dp)                                      :: tau_E
     400              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)           :: column_factors
     401              : 
     402          432 :       CALL timeset(routineN, handle)
     403              : 
     404          432 :       CPASSERT(occ .NEQV. vir)
     405              : 
     406          432 :       nkp = bs_env%nkp_scf_desymm
     407          432 :       homo = bs_env%n_occ(ispin)
     408          432 :       first_mo = 1
     409          432 :       last_mo = homo
     410          432 :       IF (vir) THEN
     411          208 :          first_mo = homo + 1
     412          208 :          last_mo = bs_env%n_ao
     413              :       END IF
     414         1296 :       ALLOCATE (column_factors(first_mo:last_mo))
     415              : 
     416         4320 :       DO i_cell_S = 1, bs_env%nimages_scf_desymm
     417         4320 :          CALL cp_fm_set_all(bs_env%fm_G_S(i_cell_S), 0.0_dp)
     418              :       END DO
     419              : 
     420         7344 :       DO ikp = 1, nkp
     421              : 
     422              :          ! G^occ/vir_µλ(i|τ|,k) = sum_n^occ/vir C_µn(k) e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k)^*
     423        51328 :          DO j = first_mo, last_mo
     424              :             ! 0.5 * |(ϵ_nk-ϵ_F)τ|
     425        44416 :             tau_E = ABS(tau*0.5_dp*(bs_env%eigenval_scf(j, ikp, ispin) - bs_env%e_fermi(ispin)))
     426        51328 :             IF (tau_E < bs_env%stabilize_exp) THEN
     427        44416 :                column_factors(j) = EXP(-tau_E)
     428              :             ELSE
     429            0 :                column_factors(j) = 0.0_dp
     430              :             END IF
     431              :          END DO
     432              : 
     433              :          CALL build_ao_propagator(bs_env%cfm_mo_coeff_kp(ikp, ispin), column_factors, first_mo, &
     434         6912 :                                   bs_env%cfm_work_mo, bs_env%cfm_work_mo_2)
     435              : 
     436              :          ! trafo k-point k -> cell S:  G^occ/vir_µλ(i|τ|,k) -> G^occ/vir,S_µλ(i|τ|)
     437              :          CALL fm_add_kp_to_all_rs(bs_env%cfm_work_mo_2, bs_env%fm_G_S, &
     438         7344 :                                   bs_env%kpoints_scf_desymm, ikp)
     439              : 
     440              :       END DO ! ikp
     441          432 :       DEALLOCATE (column_factors)
     442              : 
     443              :       ! replicate to tensor from local tensor group
     444         4320 :       DO i_cell_S = 1, bs_env%nimages_scf_desymm
     445              :          CALL cp_fm_to_dbt(bs_env%fm_G_S(i_cell_S), bs_env%mat_ao_ao%matrix, bs_env%mat_ao_ao_tensor%matrix, &
     446              :                            G_S(i_cell_S), bs_env%para_env, bs_env%para_env_tensor%num_pe, &
     447         4320 :                            bs_env%eps_filter)
     448              :       END DO
     449              : 
     450          432 :       CALL timestop(handle)
     451              : 
     452          432 :    END SUBROUTINE G_occ_vir
     453              : 
     454              : ! **************************************************************************************************
     455              : !> \brief ...
     456              : !> \param t_Gocc ...
     457              : !> \param t_Gvir ...
     458              : !> \param t_chi_R ...
     459              : !> \param bs_env ...
     460              : !> \param i_task_Delta_R_local ...
     461              : ! **************************************************************************************************
     462          560 :    SUBROUTINE contract_M_occ_vir_to_chi(t_Gocc, t_Gvir, t_chi_R, bs_env, i_task_Delta_R_local)
     463              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)       :: t_Gocc, t_Gvir
     464              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:)          :: t_chi_R
     465              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     466              :       INTEGER                                            :: i_task_Delta_R_local
     467              : 
     468              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'contract_M_occ_vir_to_chi'
     469              : 
     470              :       INTEGER                                            :: handle, i_cell_Delta_R, i_cell_R, &
     471              :                                                             i_cell_R1, i_cell_R1_minus_R, &
     472              :                                                             i_cell_R2, i_cell_R2_minus_R
     473              :       INTEGER(KIND=int_8)                                :: flop, flop_tmp
     474              :       INTEGER, DIMENSION(3)                              :: cell_DR, cell_R, cell_R1, &
     475              :                                                             cell_R1_minus_R, cell_R2, &
     476              :                                                             cell_R2_minus_R
     477              :       LOGICAL                                            :: cell_found
     478         9520 :       TYPE(dbt_type)                                     :: t_Gocc_2, t_Gvir_2
     479              : 
     480          560 :       CALL timeset(routineN, handle)
     481              : 
     482          560 :       CALL dbt_create(bs_env%t_RI__AO_AO, t_Gocc_2)
     483          560 :       CALL dbt_create(bs_env%t_RI__AO_AO, t_Gvir_2)
     484              : 
     485          560 :       flop = 0_int_8
     486              : 
     487              :       ! χ_PQ^R(iτ) = sum_λR1,νR2 M^occ_λR1,νR2,P0 M^vir_νR2,λR1,QR
     488         5600 :       DO i_cell_R = 1, bs_env%nimages_scf_desymm
     489              : 
     490        63875 :          DO i_cell_R2 = 1, bs_env%nimages_3c
     491              : 
     492        58275 :             IF (bs_env%skip_DR_R_R2_MxM_chi(i_task_Delta_R_local, i_cell_R2, i_cell_R)) CYCLE
     493              : 
     494        49778 :             i_cell_Delta_R = bs_env%task_Delta_R(i_task_Delta_R_local)
     495              : 
     496       199112 :             cell_R(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_R)
     497       199112 :             cell_R2(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_R2)
     498       199112 :             cell_DR(1:3) = bs_env%index_to_cell_Delta_R(1:3, i_cell_Delta_R)
     499              : 
     500              :             ! R_1 = R_2 + ΔR (from ΔR = R_2 - R_1)
     501              :             CALL add_R(cell_R2, cell_DR, bs_env%index_to_cell_3c, cell_R1, &
     502        49778 :                        cell_found, bs_env%cell_to_index_3c, i_cell_R1)
     503        49778 :             IF (.NOT. cell_found) CYCLE
     504              : 
     505              :             ! R_1 - R
     506              :             CALL add_R(cell_R1, -cell_R, bs_env%index_to_cell_3c, cell_R1_minus_R, &
     507        91688 :                        cell_found, bs_env%cell_to_index_3c, i_cell_R1_minus_R)
     508        22922 :             IF (.NOT. cell_found) CYCLE
     509              : 
     510              :             ! R_2 - R
     511              :             CALL add_R(cell_R2, -cell_R, bs_env%index_to_cell_3c, cell_R2_minus_R, &
     512        51880 :                        cell_found, bs_env%cell_to_index_3c, i_cell_R2_minus_R)
     513        12970 :             IF (.NOT. cell_found) CYCLE
     514              : 
     515              :             ! reorder tensors for efficient contraction to χ_PQ^R
     516         8328 :             CALL dbt_copy(t_Gocc(i_cell_R1, i_cell_R2), t_Gocc_2, order=[1, 3, 2])
     517         8328 :             CALL dbt_copy(t_Gvir(i_cell_R2_minus_R, i_cell_R1_minus_R), t_Gvir_2)
     518              : 
     519              :             ! χ_PQ^R(iτ) = sum_λR1,νR2 M^occ_λR1,νR2,P0 M^vir_νR2,λR1,QR
     520              :             CALL dbt_contract(alpha=bs_env%spin_degeneracy, &
     521              :                               tensor_1=t_Gocc_2, tensor_2=t_Gvir_2, &
     522              :                               beta=1.0_dp, tensor_3=t_chi_R(i_cell_R), &
     523              :                               contract_1=[2, 3], notcontract_1=[1], map_1=[1], &
     524              :                               contract_2=[2, 3], notcontract_2=[1], map_2=[2], &
     525         8328 :                               filter_eps=bs_env%eps_filter, move_data=.TRUE., flop=flop_tmp)
     526              : 
     527         8328 :             IF (flop_tmp == 0_int_8) bs_env%skip_DR_R_R2_MxM_chi(i_task_Delta_R_local, &
     528         3485 :                                                                  i_cell_R2, i_cell_R) = .TRUE.
     529              : 
     530        71643 :             flop = flop + flop_tmp
     531              : 
     532              :          END DO ! i_cell_R2
     533              : 
     534              :       END DO ! i_cell_R
     535              : 
     536          560 :       IF (flop == 0_int_8) bs_env%skip_DR_chi(i_task_Delta_R_local) = .TRUE.
     537              : 
     538              :       ! remove all data from t_Gocc and t_Gvir to safe memory
     539         7035 :       DO i_cell_R1 = 1, bs_env%nimages_3c
     540        83510 :          DO i_cell_R2 = 1, bs_env%nimages_3c
     541        76475 :             CALL dbt_clear(t_Gocc(i_cell_R1, i_cell_R2))
     542        82950 :             CALL dbt_clear(t_Gvir(i_cell_R1, i_cell_R2))
     543              :          END DO
     544              :       END DO
     545              : 
     546          560 :       CALL dbt_destroy(t_Gocc_2)
     547          560 :       CALL dbt_destroy(t_Gvir_2)
     548              : 
     549          560 :       CALL timestop(handle)
     550              : 
     551          560 :    END SUBROUTINE contract_M_occ_vir_to_chi
     552              : 
     553              : ! **************************************************************************************************
     554              : !> \brief ...
     555              : !> \param bs_env ...
     556              : !> \param qs_env ...
     557              : ! **************************************************************************************************
     558           16 :    SUBROUTINE compute_W_real_space(bs_env, qs_env)
     559              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     560              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     561              : 
     562              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_W_real_space'
     563              : 
     564              :       COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :)     :: chi_k_w, eps_k_w, W_k_w
     565           16 :       COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)  :: M_inv, M_inv_V_sqrt, V_sqrt
     566              :       INTEGER                                            :: handle, i_cell_R, i_t, ikp, ikp_local, &
     567              :                                                             j_w, n_RI, nimages_scf_desymm
     568              :       REAL(KIND=dp)                                      :: t1, weight_ij
     569              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)     :: chi_R, MWM_R, W_R
     570              : 
     571           16 :       CALL timeset(routineN, handle)
     572              : 
     573           16 :       n_RI = bs_env%n_RI
     574           16 :       nimages_scf_desymm = bs_env%nimages_scf_desymm
     575              : 
     576          128 :       ALLOCATE (chi_k_w(n_RI, n_RI), eps_k_w(n_RI, n_RI), W_k_w(n_RI, n_RI))
     577              :       ALLOCATE (chi_R(n_RI, n_RI, nimages_scf_desymm), W_R(n_RI, n_RI, nimages_scf_desymm), &
     578          176 :                 MWM_R(n_RI, n_RI, nimages_scf_desymm))
     579              : 
     580           16 :       t1 = m_walltime()
     581              : 
     582           16 :       CALL compute_Minv_and_Vsqrt(bs_env, qs_env, M_inv_V_sqrt, M_inv, V_sqrt)
     583              : 
     584           16 :       IF (bs_env%unit_nr > 0) THEN
     585              :          WRITE (bs_env%unit_nr, '(T2,A,T58,A,F7.1,A)') &
     586            8 :             'Computed V_PQ(k),', 'Execution time', m_walltime() - t1, ' s'
     587            8 :          WRITE (bs_env%unit_nr, '(A)') ' '
     588              :       END IF
     589              : 
     590           16 :       t1 = m_walltime()
     591              : 
     592          120 :       DO j_w = 1, bs_env%num_time_freq_points
     593              : 
     594              :          ! χ_PQ^R(iτ) -> χ_PQ^R(iω_j) (which is stored in chi_R, single ω_j from j_w loop)
     595          104 :          chi_R(:, :, :) = 0.0_dp
     596          808 :          DO i_t = 1, bs_env%num_time_freq_points
     597          704 :             weight_ij = bs_env%time_frequency_grid%cosine_time_to_frequency(j_w, i_t)
     598              : 
     599          808 :             CALL cp_fm_to_replicated_array(bs_env%fm_chi_R_t(:, i_t), chi_R, weight_ij, add=.TRUE.)
     600              :          END DO
     601              : 
     602          104 :          ikp_local = 0
     603          104 :          W_R(:, :, :) = 0.0_dp
     604        66664 :          DO ikp = 1, bs_env%nkp_chi_eps_W_orig_plus_extra
     605              : 
     606              :             ! trivial parallelization over k-points
     607        66560 :             IF (MODULO(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) CYCLE
     608              : 
     609        33280 :             ikp_local = ikp_local + 1
     610              : 
     611              :             ! 1. χ_PQ^R(iω_j) -> χ_PQ(iω_j,k)
     612              :             CALL rs_to_kp(chi_R, chi_k_w, bs_env%kpoints_scf_desymm%index_to_cell, &
     613        33280 :                           bs_env%kpoints_chi_eps_W%xkp(1:3, ikp))
     614              : 
     615              :             ! 2. remove negative eigenvalues from χ_PQ(iω,k)
     616        33280 :             CALL local_complex_power(chi_k_w, 1.0_dp, bs_env%eps_eigval_mat_RI)
     617              : 
     618              :             ! 3. ε(iω_j,k_i) = I + V^0.5(k_i)*M^-1(k_i)*χ(iω_j,k_i)*M^-1(k_i)*V^0.5(k_i)
     619              :             !    a) eps_work = V^0.5(k_i)*M^-1(k_i)*χ(iω_j,k_i)*M^-1(k_i)*V^0.5(k_i)
     620              :             CALL gemm_square(M_inv_V_sqrt(:, :, ikp_local), 'C', chi_k_w, 'N', &
     621        33280 :                              M_inv_V_sqrt(:, :, ikp_local), 'N', eps_k_w)
     622              : 
     623              :             !    b) ε(iω_j,k_i) = eps_work + I
     624        33280 :             CALL local_add_on_diag(eps_k_w, z_one)
     625              : 
     626              :             ! 4. W(iω_j,k_i) = V^0.5(k_i)*(ε^-1(iω_j,k_i)-I)*V^0.5(k_i)
     627              :             !    a) Invert ε(iω_j,k_i) using its Cholesky decomposition
     628        33280 :             CALL local_complex_power(eps_k_w, -1.0_dp, 0.0_dp)
     629              : 
     630              :             !    b) ε^-1(iω_j,k_i)-I
     631        33280 :             CALL local_add_on_diag(eps_k_w, -z_one)
     632              : 
     633              :             !    c) W(iω_j,k_i) = V^0.5(k_i)*(ε^-1(iω_j,k_i)-I)*V^0.5(k_i)
     634              :             CALL gemm_square(V_sqrt(:, :, ikp_local), 'N', eps_k_w, 'N', &
     635        33280 :                              V_sqrt(:, :, ikp_local), 'C', W_k_w)
     636              : 
     637              :             ! 5. W(iω,k_i) -> W^R(iω) = sum_k w_k e^(-ikR) W(iω,k) (k-point extrapolation here)
     638              :             CALL add_kp_to_all_rs(W_k_w, W_R, bs_env%kpoints_chi_eps_W, ikp, &
     639        66664 :                                   index_to_cell_ext=bs_env%kpoints_scf_desymm%index_to_cell)
     640              : 
     641              :          END DO ! ikp
     642              : 
     643          104 :          CALL bs_env%para_env%sync()
     644          104 :          CALL bs_env%para_env%sum(W_R)
     645              : 
     646              :          ! 6. W^R(iω) -> W(iω,k) [k-mesh is not extrapolated for stable mult. with M^-1(k) ]
     647              :          !            -> M^-1(k)*W(iω,k)*M^-1(k) =: Ŵ(iω,k) -> Ŵ^R(iω) (stored in MWM_R)
     648          104 :          CALL mult_W_with_Minv(W_R, MWM_R, bs_env, qs_env)
     649              : 
     650              :          ! 7. Ŵ^R(iω) -> Ŵ^R(iτ) and to fully distributed fm matrix bs_env%fm_MWM_R_t
     651          824 :          DO i_t = 1, bs_env%num_time_freq_points
     652          704 :             weight_ij = bs_env%time_frequency_grid%cosine_frequency_to_time(i_t, j_w)
     653         7144 :             DO i_cell_R = 1, nimages_scf_desymm
     654              :                CALL cp_fm_set_submatrix(bs_env%fm_MWM_R_t(i_cell_R, i_t), MWM_R(:, :, i_cell_R), &
     655         7040 :                                         alpha=weight_ij, beta=1.0_dp)
     656              :             END DO
     657              :          END DO ! i_t
     658              : 
     659              :       END DO ! j_w
     660              : 
     661           16 :       IF (bs_env%unit_nr > 0) THEN
     662              :          WRITE (bs_env%unit_nr, '(T2,A,T60,A,F7.1,A)') &
     663            8 :             'Computed W_PQ(k,iω) for all k and τ,', 'Execution time', m_walltime() - t1, ' s'
     664            8 :          WRITE (bs_env%unit_nr, '(A)') ' '
     665              :       END IF
     666              : 
     667           16 :       CALL timestop(handle)
     668              : 
     669           32 :    END SUBROUTINE compute_W_real_space
     670              : 
     671              : ! **************************************************************************************************
     672              : !> \brief ...
     673              : !> \param bs_env ...
     674              : !> \param qs_env ...
     675              : !> \param M_inv_V_sqrt ...
     676              : !> \param M_inv ...
     677              : !> \param V_sqrt ...
     678              : ! **************************************************************************************************
     679           16 :    SUBROUTINE compute_Minv_and_Vsqrt(bs_env, qs_env, M_inv_V_sqrt, M_inv, V_sqrt)
     680              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     681              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     682              :       COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)  :: M_inv_V_sqrt, M_inv, V_sqrt
     683              : 
     684              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_Minv_and_Vsqrt'
     685              : 
     686              :       INTEGER                                            :: handle, ikp, ikp_local, n_RI, nkp, &
     687              :                                                             nkp_local, nkp_orig
     688           16 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)     :: M_R
     689              : 
     690           16 :       CALL timeset(routineN, handle)
     691              : 
     692           16 :       nkp = bs_env%nkp_chi_eps_W_orig_plus_extra
     693           16 :       nkp_orig = bs_env%nkp_chi_eps_W_orig
     694           16 :       n_RI = bs_env%n_RI
     695              : 
     696           16 :       nkp_local = 0
     697        10256 :       DO ikp = 1, nkp
     698              :          ! trivial parallelization over k-points
     699        10240 :          IF (MODULO(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) CYCLE
     700        10256 :          nkp_local = nkp_local + 1
     701              :       END DO
     702              : 
     703            0 :       ALLOCATE (M_inv_V_sqrt(n_RI, n_RI, nkp_local), M_inv(n_RI, n_RI, nkp_local), &
     704          176 :                 V_sqrt(n_RI, n_RI, nkp_local))
     705              : 
     706           16 :       M_inv_V_sqrt(:, :, :) = z_zero
     707           16 :       M_inv(:, :, :) = z_zero
     708           16 :       V_sqrt(:, :, :) = z_zero
     709              : 
     710              :       ! 1. 2c Coulomb integrals for the first "original" k-point grid
     711           64 :       bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
     712              :       CALL build_2c_coulomb_matrix_kp_dense(V_sqrt, qs_env, bs_env%kpoints_chi_eps_W, &
     713              :                                             bs_env%size_lattice_sum_V, basis_type="RI_AUX", &
     714           16 :                                             ikp_start=1, ikp_end=nkp_orig)
     715              : 
     716              :       ! 2. 2c Coulomb integrals for the second "extrapolation" k-point grid
     717           64 :       bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_extra
     718              :       CALL build_2c_coulomb_matrix_kp_dense(V_sqrt, qs_env, bs_env%kpoints_chi_eps_W, &
     719              :                                             bs_env%size_lattice_sum_V, basis_type="RI_AUX", &
     720           16 :                                             ikp_start=nkp_orig + 1, ikp_end=nkp)
     721              : 
     722              :       ! now get M^-1(k) and M^-1(k)*V^0.5(k)
     723              : 
     724              :       ! compute M^R_PQ = <phi_P,0|V^tr(rc=3Å)|phi_Q,R> for RI metric
     725           16 :       CALL get_V_tr_R(M_R, bs_env%ri_metric, bs_env%regularization_RI, bs_env, qs_env)
     726              : 
     727           16 :       ikp_local = 0
     728        10256 :       DO ikp = 1, nkp
     729              : 
     730              :          ! trivial parallelization
     731        10240 :          IF (MODULO(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) CYCLE
     732              : 
     733         5120 :          ikp_local = ikp_local + 1
     734              : 
     735              :          ! M(k) = sum_R e^ikR M^R
     736              :          CALL rs_to_kp(M_R, M_inv(:, :, ikp_local), &
     737              :                        bs_env%kpoints_scf_desymm%index_to_cell, &
     738         5120 :                        bs_env%kpoints_chi_eps_W%xkp(1:3, ikp))
     739              : 
     740              :          ! invert M_PQ(k)
     741         5120 :          CALL local_complex_power(M_inv(:, :, ikp_local), -1.0_dp, 0.0_dp)
     742              : 
     743              :          ! V^0.5(k)
     744         5120 :          CALL local_complex_power(V_sqrt(:, :, ikp_local), 0.5_dp, 0.0_dp)
     745              : 
     746              :          ! M^-1(k)*V^0.5(k)
     747        10256 :          CALL gemm_square(M_inv(:, :, ikp_local), 'N', V_sqrt(:, :, ikp_local), 'C', M_inv_V_sqrt(:, :, ikp_local))
     748              : 
     749              :       END DO ! ikp
     750              : 
     751           16 :       CALL timestop(handle)
     752              : 
     753           32 :    END SUBROUTINE compute_Minv_and_Vsqrt
     754              : 
     755              : ! **************************************************************************************************
     756              : !> \brief ...
     757              : !> \param W_R ...
     758              : !> \param MWM_R ...
     759              : !> \param bs_env ...
     760              : !> \param qs_env ...
     761              : ! **************************************************************************************************
     762          104 :    SUBROUTINE mult_W_with_Minv(W_R, MWM_R, bs_env, qs_env)
     763              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)     :: W_R, MWM_R
     764              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     765              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     766              : 
     767              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'mult_W_with_Minv'
     768              : 
     769              :       COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :)     :: M_inv, W_k, work
     770              :       INTEGER                                            :: handle, ikp, n_RI
     771          104 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)     :: M_R
     772              : 
     773          104 :       CALL timeset(routineN, handle)
     774              : 
     775              :       ! compute M^R again
     776          104 :       CALL get_V_tr_R(M_R, bs_env%ri_metric, bs_env%regularization_RI, bs_env, qs_env)
     777              : 
     778          104 :       n_RI = bs_env%n_RI
     779          832 :       ALLOCATE (M_inv(n_RI, n_RI), W_k(n_RI, n_RI), work(n_RI, n_RI))
     780          104 :       MWM_R(:, :, :) = 0.0_dp
     781              : 
     782         1768 :       DO ikp = 1, bs_env%nkp_scf_desymm
     783              : 
     784              :          ! trivial parallelization
     785         1664 :          IF (MODULO(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) CYCLE
     786              : 
     787              :          ! M(k) = sum_R e^ikR M^R
     788              :          CALL rs_to_kp(M_R, M_inv, &
     789              :                        bs_env%kpoints_scf_desymm%index_to_cell, &
     790          832 :                        bs_env%kpoints_scf_desymm%xkp(1:3, ikp))
     791              : 
     792              :          ! invert M_PQ(k)
     793          832 :          CALL local_complex_power(M_inv, -1.0_dp, 0.0_dp)
     794              : 
     795              :          ! W(k) = sum_R e^ikR W^R [only R in the supercell that is determined by the SCF k-mesh]
     796              :          CALL rs_to_kp(W_R, W_k, &
     797              :                        bs_env%kpoints_scf_desymm%index_to_cell, &
     798          832 :                        bs_env%kpoints_scf_desymm%xkp(1:3, ikp))
     799              : 
     800              :          ! Ŵ(k) = M^-1(k)*W^trunc(k)*M^-1(k)
     801          832 :          CALL gemm_square(M_inv, 'N', W_k, 'N', M_inv, 'N', work)
     802        33856 :          W_k(:, :) = work(:, :)
     803              : 
     804              :          ! Ŵ^R = sum_k w_k e^(-ikR) Ŵ^(k)
     805         1768 :          CALL add_kp_to_all_rs(W_k, MWM_R, bs_env%kpoints_scf_desymm, ikp)
     806              : 
     807              :       END DO ! ikp
     808              : 
     809          104 :       CALL bs_env%para_env%sync()
     810          104 :       CALL bs_env%para_env%sum(MWM_R)
     811              : 
     812          104 :       CALL timestop(handle)
     813              : 
     814          208 :    END SUBROUTINE mult_W_with_Minv
     815              : 
     816              : ! **************************************************************************************************
     817              : !> \brief ...
     818              : !> \param bs_env ...
     819              : !> \param qs_env ...
     820              : ! **************************************************************************************************
     821           16 :    SUBROUTINE compute_Sigma_x(bs_env, qs_env)
     822              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     823              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     824              : 
     825              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'compute_Sigma_x'
     826              : 
     827              :       INTEGER                                            :: handle, i_task_Delta_R_local, ispin
     828              :       REAL(KIND=dp)                                      :: t1
     829           16 :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:)          :: D_S, Mi_Vtr_Mi_R, Sigma_x_R
     830           16 :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)       :: t_V
     831              : 
     832           16 :       CALL timeset(routineN, handle)
     833              : 
     834           16 :       CALL dbt_create_2c_R(Mi_Vtr_Mi_R, bs_env%t_W, bs_env%nimages_scf_desymm)
     835           16 :       CALL dbt_create_2c_R(D_S, bs_env%t_G, bs_env%nimages_scf_desymm)
     836           16 :       CALL dbt_create_2c_R(Sigma_x_R, bs_env%t_G, bs_env%nimages_scf_desymm)
     837           16 :       CALL dbt_create_3c_R1_R2(t_V, bs_env%t_RI_AO__AO, bs_env%nimages_3c, bs_env%nimages_3c)
     838              : 
     839           16 :       t1 = m_walltime()
     840              : 
     841              :       ! V^tr_PQ^R = <phi_P,0|V^tr|phi_Q,R>, V^tr(k) = sum_R e^ikR V^tr^R
     842              :       ! M(k) = sum_R e^ikR M^R, M(k) -> M^-1(k) -> Ṽ^tr(k) = M^-1(k) * V^tr(k) * M^-1(k)
     843              :       !                                         -> Ṽ^tr_PQ^R = sum_k w_k e^-ikR Ṽ^tr_PQ(k)
     844           16 :       CALL get_Minv_Vtr_Minv_R(Mi_Vtr_Mi_R, bs_env, qs_env)
     845              : 
     846              :       ! Σ^x_λσ^R = sum_PR1νS1 [ sum_µS2 (λ0 µS1-S2 | PR1   ) D_µν^S2       ]
     847              :       !                       [ sum_QR2 (σR νS1    | QR1-R2) Ṽ^tr_PQ^R2 ]
     848           32 :       DO ispin = 1, bs_env%n_spin
     849              : 
     850              :          ! compute D^S(iτ) for cell S from D_µν(k) = sum_n^occ C^*_µn(k) C_νn(k):
     851              :          ! trafo k-point k -> cell S: D_µν^S = sum_k w_k D_µν(k) e^(ikS)
     852           16 :          CALL G_occ_vir(bs_env, 0.0_dp, D_S, ispin, occ=.TRUE., vir=.FALSE.)
     853              : 
     854              :          ! loop over ΔR = S_1 - R_1 which are local in the tensor subgroup
     855          239 :          DO i_task_Delta_R_local = 1, bs_env%n_tasks_Delta_R_local
     856              : 
     857              :             ! M^V_σ0,νS1,PR1 = sum_QR2 ( σ0 νS1 | QR1-R2 ) Ṽ^tr_QP^R2 for i_task_local
     858          223 :             CALL contract_W(t_V, Mi_Vtr_Mi_R, bs_env, i_task_Delta_R_local)
     859              : 
     860              :             ! M^D_λ0,νS1,PR1 = sum_µS2 (λ0 µS1-S2 | PR1) D_µν^S2
     861              :             ! Σ^x_λσ^R = sum_PR1νS1 M^D_λ0,νS1,PR1 * M^V_σR,νS1,PR1 for i_task_local, where
     862              :             !                                        M^V_σR,νS1,PR1 = M^V_σ0,νS1-R,PR1-R
     863              :             CALL contract_to_Sigma(Sigma_x_R, t_V, D_S, i_task_Delta_R_local, bs_env, &
     864          239 :                                    occ=.TRUE., vir=.FALSE., clear_t_W=.TRUE., fill_skip=.FALSE.)
     865              : 
     866              :          END DO ! i_cell_Delta_R_local
     867              : 
     868           16 :          CALL bs_env%para_env%sync()
     869              : 
     870              :          CALL cp_dbt_to_fm(Sigma_x_R, bs_env%fm_Sigma_x_R, bs_env%mat_ao_ao, bs_env%mat_ao_ao_tensor, &
     871           32 :                            bs_env%para_env)
     872              : 
     873              :       END DO ! ispin
     874              : 
     875           16 :       IF (bs_env%unit_nr > 0) THEN
     876              :          WRITE (bs_env%unit_nr, '(T2,A,T58,A,F7.1,A)') &
     877            8 :             'Computed Σ^x,', ' Execution time', m_walltime() - t1, ' s'
     878            8 :          WRITE (bs_env%unit_nr, '(A)') ' '
     879              :       END IF
     880              : 
     881           16 :       CALL destroy_t_1d(Mi_Vtr_Mi_R)
     882           16 :       CALL destroy_t_1d(D_S)
     883           16 :       CALL destroy_t_1d(Sigma_x_R)
     884           16 :       CALL destroy_t_2d(t_V)
     885              : 
     886           16 :       CALL timestop(handle)
     887              : 
     888           16 :    END SUBROUTINE compute_Sigma_x
     889              : 
     890              : ! **************************************************************************************************
     891              : !> \brief ...
     892              : !> \param bs_env ...
     893              : ! **************************************************************************************************
     894           16 :    SUBROUTINE compute_Sigma_c(bs_env)
     895              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     896              : 
     897              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'compute_Sigma_c'
     898              : 
     899              :       INTEGER                                            :: handle, i_t, i_task_Delta_R_local, ispin
     900              :       REAL(KIND=dp)                                      :: t1, tau
     901           16 :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:)          :: Gocc_S, Gvir_S, Sigma_c_R_neg_tau, &
     902           16 :                                                             Sigma_c_R_pos_tau, W_R
     903           16 :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)       :: t_W
     904              : 
     905           16 :       CALL timeset(routineN, handle)
     906              : 
     907           16 :       CALL dbt_create_2c_R(Gocc_S, bs_env%t_G, bs_env%nimages_scf_desymm)
     908           16 :       CALL dbt_create_2c_R(Gvir_S, bs_env%t_G, bs_env%nimages_scf_desymm)
     909           16 :       CALL dbt_create_2c_R(W_R, bs_env%t_W, bs_env%nimages_scf_desymm)
     910           16 :       CALL dbt_create_3c_R1_R2(t_W, bs_env%t_RI_AO__AO, bs_env%nimages_3c, bs_env%nimages_3c)
     911           16 :       CALL dbt_create_2c_R(Sigma_c_R_neg_tau, bs_env%t_G, bs_env%nimages_scf_desymm)
     912           16 :       CALL dbt_create_2c_R(Sigma_c_R_pos_tau, bs_env%t_G, bs_env%nimages_scf_desymm)
     913              : 
     914              :       ! Σ^c_λσ^R(iτ) = sum_PR1νS1 [ sum_µS2 (λ0 µS1-S2 | PR1   ) G^occ/vir_µν^S2(i|τ|) ]
     915              :       !                           [ sum_QR2 (σR νS1    | QR1-R2) Ŵ_PQ^R2(iτ)           ]
     916          120 :       DO i_t = 1, bs_env%num_time_freq_points
     917              : 
     918          224 :          DO ispin = 1, bs_env%n_spin
     919              : 
     920          104 :             t1 = m_walltime()
     921              : 
     922          104 :             tau = bs_env%time_frequency_grid%imaginary_time(i_t)
     923              : 
     924              :             ! G^occ_µλ(i|τ|,k) = sum_n^occ C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k), τ < 0
     925              :             ! G^vir_µλ(i|τ|,k) = sum_n^vir C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k), τ > 0
     926              :             ! k-point k -> cell S: G^occ/vir_µλ^S(i|τ|) = sum_k w_k G^occ/vir_µλ(i|τ|,k) e^(ikS)
     927          104 :             CALL G_occ_vir(bs_env, tau, Gocc_S, ispin, occ=.TRUE., vir=.FALSE.)
     928          104 :             CALL G_occ_vir(bs_env, tau, Gvir_S, ispin, occ=.FALSE., vir=.TRUE.)
     929              : 
     930              :             ! write data of W^R_PQ(iτ) to W_R 2-index tensor
     931          104 :             CALL fm_MWM_R_t_to_local_tensor_W_R(bs_env%fm_MWM_R_t(:, i_t), W_R, bs_env)
     932              : 
     933              :             ! loop over ΔR = S_1 - R_1 which are local in the tensor subgroup
     934         1494 :             DO i_task_Delta_R_local = 1, bs_env%n_tasks_Delta_R_local
     935              : 
     936         1390 :                IF (bs_env%skip_DR_Sigma(i_task_Delta_R_local)) CYCLE
     937              : 
     938              :                ! for i_task_local (i.e. fixed ΔR = S_1 - R_1) and for all τ (W(iτ) = W(-iτ)):
     939              :                ! M^W_σ0,νS1,PR1 = sum_QR2 ( σ0 νS1 | QR1-R2 ) W(iτ)_QP^R2
     940          510 :                CALL contract_W(t_W, W_R, bs_env, i_task_Delta_R_local)
     941              : 
     942              :                ! for τ < 0 and for i_task_local (i.e. fixed ΔR = S_1 - R_1):
     943              :                ! M^G_λ0,νS1,PR1 = sum_µS2 (λ0 µS1-S2 | PR1) G^occ(i|τ|)_µν^S2
     944              :                ! Σ^c_λσ^R(iτ) = sum_PR1νS1 M^G_λ0,νS1,PR1 * M^W_σR,νS1,PR1
     945              :                !                                      where M^W_σR,νS1,PR1 = M^W_σ0,νS1-R,PR1-R
     946              :                CALL contract_to_Sigma(Sigma_c_R_neg_tau, t_W, Gocc_S, i_task_Delta_R_local, bs_env, &
     947          510 :                                       occ=.TRUE., vir=.FALSE., clear_t_W=.FALSE., fill_skip=.FALSE.)
     948              : 
     949              :                ! for τ > 0: same as for τ < 0, but G^occ -> G^vir
     950              :                CALL contract_to_Sigma(Sigma_c_R_pos_tau, t_W, Gvir_S, i_task_Delta_R_local, bs_env, &
     951         1494 :                                       occ=.FALSE., vir=.TRUE., clear_t_W=.TRUE., fill_skip=.TRUE.)
     952              : 
     953              :             END DO ! i_cell_Delta_R_local
     954              : 
     955          104 :             CALL bs_env%para_env%sync()
     956              : 
     957              :             CALL cp_dbt_to_fm(Sigma_c_R_pos_tau, bs_env%fm_Sigma_c_R_pos_tau(:, i_t, ispin), bs_env%mat_ao_ao, &
     958          104 :                               bs_env%mat_ao_ao_tensor, bs_env%para_env)
     959              : 
     960              :             CALL cp_dbt_to_fm(Sigma_c_R_neg_tau, bs_env%fm_Sigma_c_R_neg_tau(:, i_t, ispin), bs_env%mat_ao_ao, &
     961          104 :                               bs_env%mat_ao_ao_tensor, bs_env%para_env)
     962              : 
     963          208 :             IF (bs_env%unit_nr > 0) THEN
     964              :                WRITE (bs_env%unit_nr, '(T2,A,I10,A,I3,A,F7.1,A)') &
     965           52 :                   'Computed Σ^c(iτ) for time point   ', i_t, ' /', bs_env%num_time_freq_points, &
     966          104 :                   ',      Execution time', m_walltime() - t1, ' s'
     967              :             END IF
     968              : 
     969              :          END DO ! ispin
     970              : 
     971              :       END DO ! i_t
     972              : 
     973           16 :       CALL destroy_t_1d(Gocc_S)
     974           16 :       CALL destroy_t_1d(Gvir_S)
     975           16 :       CALL destroy_t_1d(W_R)
     976           16 :       CALL destroy_t_1d(Sigma_c_R_neg_tau)
     977           16 :       CALL destroy_t_1d(Sigma_c_R_pos_tau)
     978           16 :       CALL destroy_t_2d(t_W)
     979              : 
     980           16 :       CALL timestop(handle)
     981              : 
     982           16 :    END SUBROUTINE compute_Sigma_c
     983              : 
     984              : ! **************************************************************************************************
     985              : !> \brief ...
     986              : !> \param Mi_Vtr_Mi_R ...
     987              : !> \param bs_env ...
     988              : !> \param qs_env ...
     989              : ! **************************************************************************************************
     990           16 :    SUBROUTINE get_Minv_Vtr_Minv_R(Mi_Vtr_Mi_R, bs_env, qs_env)
     991              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:)          :: Mi_Vtr_Mi_R
     992              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     993              :       TYPE(qs_environment_type), POINTER                 :: qs_env
     994              : 
     995              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'get_Minv_Vtr_Minv_R'
     996              : 
     997              :       COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :)     :: M_kp, Mi_Vtr_Mi_kp, V_tr_kp
     998              :       INTEGER                                            :: handle, i_cell_R, ikp, n_RI, &
     999              :                                                             nimages_scf, nkp_scf
    1000           16 :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)     :: M_R, Mi_Vtr_Mi_R_arr, V_tr_R
    1001              : 
    1002           16 :       CALL timeset(routineN, handle)
    1003              : 
    1004           16 :       nimages_scf = bs_env%nimages_scf_desymm
    1005           16 :       nkp_scf = bs_env%kpoints_scf_desymm%nkp
    1006           16 :       n_RI = bs_env%n_RI
    1007              : 
    1008           16 :       CALL get_V_tr_R(V_tr_R, bs_env%trunc_coulomb, 0.0_dp, bs_env, qs_env)
    1009           16 :       CALL get_V_tr_R(M_R, bs_env%ri_metric, bs_env%regularization_RI, bs_env, qs_env)
    1010              : 
    1011              :       ALLOCATE (V_tr_kp(n_RI, n_RI), M_kp(n_RI, n_RI), &
    1012          192 :                 Mi_Vtr_Mi_kp(n_RI, n_RI), Mi_Vtr_Mi_R_arr(n_RI, n_RI, nimages_scf))
    1013           16 :       Mi_Vtr_Mi_R_arr(:, :, :) = 0.0_dp
    1014              : 
    1015          272 :       DO ikp = 1, nkp_scf
    1016              :          ! trivial parallelization
    1017          256 :          IF (MODULO(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) CYCLE
    1018              :          ! V_tr(k) = sum_R e^ikR V_tr^R
    1019              :          CALL rs_to_kp(V_tr_R, V_tr_kp, bs_env%kpoints_scf_desymm%index_to_cell, &
    1020          128 :                        bs_env%kpoints_scf_desymm%xkp(1:3, ikp))
    1021              :          ! M(k)    = sum_R e^ikR M^R
    1022              :          CALL rs_to_kp(M_R, M_kp, bs_env%kpoints_scf_desymm%index_to_cell, &
    1023          128 :                        bs_env%kpoints_scf_desymm%xkp(1:3, ikp))
    1024              :          ! M(k) -> M^-1(k)
    1025          128 :          CALL local_complex_power(M_kp, -1.0_dp, 0.0_dp)
    1026              :          ! Ṽ(k) = M^-1(k) * V_tr(k) * M^-1(k)
    1027          128 :          CALL gemm_square(M_kp, 'N', V_tr_kp, 'N', M_kp, 'N', Mi_Vtr_Mi_kp)
    1028              :          ! Ṽ^R = sum_k w_k e^-ikR Ṽ(k)
    1029          272 :          CALL add_kp_to_all_rs(Mi_Vtr_Mi_kp, Mi_Vtr_Mi_R_arr, bs_env%kpoints_scf_desymm, ikp)
    1030              :       END DO
    1031           16 :       CALL bs_env%para_env%sync()
    1032           16 :       CALL bs_env%para_env%sum(Mi_Vtr_Mi_R_arr)
    1033              : 
    1034              :       ! use bs_env%fm_chi_R_t for temporary storage
    1035          160 :       DO i_cell_R = 1, nimages_scf
    1036          160 :          CALL cp_fm_set_submatrix(bs_env%fm_chi_R_t(i_cell_R, 1), Mi_Vtr_Mi_R_arr(:, :, i_cell_R))
    1037              :       END DO
    1038              : 
    1039              :       ! communicate Mi_Vtr_Mi_R to tensor format; full replication in tensor group
    1040          160 :       DO i_cell_R = 1, nimages_scf
    1041              :          CALL cp_fm_to_dbt(bs_env%fm_chi_R_t(i_cell_R, 1), bs_env%mat_RI_RI%matrix, &
    1042              :                            bs_env%mat_RI_RI_tensor%matrix, Mi_Vtr_Mi_R(i_cell_R), bs_env%para_env, &
    1043          160 :                            bs_env%para_env_tensor%num_pe, bs_env%eps_filter)
    1044              :       END DO
    1045              : 
    1046           16 :       CALL timestop(handle)
    1047              : 
    1048           32 :    END SUBROUTINE get_Minv_Vtr_Minv_R
    1049              : 
    1050              : ! **************************************************************************************************
    1051              : !> \brief ...
    1052              : !> \param t_1d ...
    1053              : ! **************************************************************************************************
    1054          440 :    SUBROUTINE destroy_t_1d(t_1d)
    1055              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:)          :: t_1d
    1056              : 
    1057              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'destroy_t_1d'
    1058              : 
    1059              :       INTEGER                                            :: handle, i
    1060              : 
    1061          440 :       CALL timeset(routineN, handle)
    1062              : 
    1063         4400 :       DO i = 1, SIZE(t_1d)
    1064         4400 :          CALL dbt_destroy(t_1d(i))
    1065              :       END DO
    1066         4400 :       DEALLOCATE (t_1d)
    1067              : 
    1068          440 :       CALL timestop(handle)
    1069              : 
    1070          440 :    END SUBROUTINE destroy_t_1d
    1071              : 
    1072              : ! **************************************************************************************************
    1073              : !> \brief ...
    1074              : !> \param t_2d ...
    1075              : ! **************************************************************************************************
    1076          240 :    SUBROUTINE destroy_t_2d(t_2d)
    1077              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)       :: t_2d
    1078              : 
    1079              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'destroy_t_2d'
    1080              : 
    1081              :       INTEGER                                            :: handle, i, j
    1082              : 
    1083          240 :       CALL timeset(routineN, handle)
    1084              : 
    1085         2812 :       DO i = 1, SIZE(t_2d, 1)
    1086        32136 :       DO j = 1, SIZE(t_2d, 2)
    1087        31896 :          CALL dbt_destroy(t_2d(i, j))
    1088              :       END DO
    1089              :       END DO
    1090        29564 :       DEALLOCATE (t_2d)
    1091              : 
    1092          240 :       CALL timestop(handle)
    1093              : 
    1094          240 :    END SUBROUTINE destroy_t_2d
    1095              : 
    1096              : ! **************************************************************************************************
    1097              : !> \brief ...
    1098              : !> \param t_W ...
    1099              : !> \param W_R ...
    1100              : !> \param bs_env ...
    1101              : !> \param i_task_Delta_R_local ...
    1102              : ! **************************************************************************************************
    1103          733 :    SUBROUTINE contract_W(t_W, W_R, bs_env, i_task_Delta_R_local)
    1104              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)       :: t_W
    1105              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:)          :: W_R
    1106              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
    1107              :       INTEGER                                            :: i_task_Delta_R_local
    1108              : 
    1109              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'contract_W'
    1110              : 
    1111              :       INTEGER                                            :: handle, i_cell_Delta_R, i_cell_R1, &
    1112              :                                                             i_cell_R2, i_cell_R2_m_R1, i_cell_S1, &
    1113              :                                                             i_cell_S1_m_R1_p_R2
    1114              :       INTEGER, DIMENSION(3)                              :: cell_DR, cell_R1, cell_R2, cell_R2_m_R1, &
    1115              :                                                             cell_S1, cell_S1_m_R2_p_R1
    1116              :       LOGICAL                                            :: cell_found
    1117        12461 :       TYPE(dbt_type)                                     :: t_3c_int, t_W_tmp
    1118              : 
    1119          733 :       CALL timeset(routineN, handle)
    1120              : 
    1121          733 :       CALL dbt_create(bs_env%t_RI__AO_AO, t_W_tmp)
    1122          733 :       CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_int)
    1123              : 
    1124          733 :       i_cell_Delta_R = bs_env%task_Delta_R(i_task_Delta_R_local)
    1125              : 
    1126         9200 :       DO i_cell_R1 = 1, bs_env%nimages_3c
    1127              : 
    1128        33868 :          cell_R1(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_R1)
    1129        33868 :          cell_DR(1:3) = bs_env%index_to_cell_Delta_R(1:3, i_cell_Delta_R)
    1130              : 
    1131              :          ! S_1 = R_1 + ΔR (from ΔR = S_1 - R_1)
    1132              :          CALL add_R(cell_R1, cell_DR, bs_env%index_to_cell_3c, cell_S1, &
    1133         8467 :                     cell_found, bs_env%cell_to_index_3c, i_cell_S1)
    1134         8467 :          IF (.NOT. cell_found) CYCLE
    1135              : 
    1136        50570 :          DO i_cell_R2 = 1, bs_env%nimages_scf_desymm
    1137              : 
    1138       148932 :             cell_R2(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_R2)
    1139              : 
    1140              :             ! R_2 - R_1
    1141              :             CALL add_R(cell_R2, -cell_R1, bs_env%index_to_cell_3c, cell_R2_m_R1, &
    1142       148932 :                        cell_found, bs_env%cell_to_index_3c, i_cell_R2_m_R1)
    1143        37233 :             IF (.NOT. cell_found) CYCLE
    1144              : 
    1145              :             ! S_1 - R_1 + R_2
    1146              :             CALL add_R(cell_S1, cell_R2_m_R1, bs_env%index_to_cell_3c, cell_S1_m_R2_p_R1, &
    1147        22627 :                        cell_found, bs_env%cell_to_index_3c, i_cell_S1_m_R1_p_R2)
    1148        22627 :             IF (.NOT. cell_found) CYCLE
    1149              : 
    1150        17285 :             CALL get_t_3c_int(t_3c_int, bs_env, i_cell_S1_m_R1_p_R2, i_cell_R2_m_R1)
    1151              : 
    1152              :             ! M^W_σ0,νS1,PR1 = sum_QR2 ( σ0     νS1       | QR1-R2 ) W_QP^R2
    1153              :             !                = sum_QR2 ( σR2-R1 νS1-R1+R2 | Q0     ) W_QP^R2
    1154              :             ! for ΔR = S_1 - R_1
    1155              :             CALL dbt_contract(alpha=1.0_dp, &
    1156              :                               tensor_1=W_R(i_cell_R2), &
    1157              :                               tensor_2=t_3c_int, &
    1158              :                               beta=0.0_dp, &
    1159              :                               tensor_3=t_W_tmp, &
    1160              :                               contract_1=[1], notcontract_1=[2], map_1=[1], &
    1161              :                               contract_2=[1], notcontract_2=[2, 3], map_2=[2, 3], &
    1162        17285 :                               filter_eps=bs_env%eps_filter)
    1163              : 
    1164              :             ! reorder tensor
    1165              :             CALL dbt_copy(t_W_tmp, t_W(i_cell_S1, i_cell_R1), order=[1, 2, 3], &
    1166        62985 :                           move_data=.TRUE., summation=.TRUE.)
    1167              : 
    1168              :          END DO ! i_cell_R2
    1169              : 
    1170              :       END DO ! i_cell_R1
    1171              : 
    1172          733 :       CALL dbt_destroy(t_W_tmp)
    1173          733 :       CALL dbt_destroy(t_3c_int)
    1174              : 
    1175          733 :       CALL timestop(handle)
    1176              : 
    1177          733 :    END SUBROUTINE contract_W
    1178              : 
    1179              : ! **************************************************************************************************
    1180              : !> \brief ...
    1181              : !> \param Sigma_R ...
    1182              : !> \param t_W ...
    1183              : !> \param G_S ...
    1184              : !> \param i_task_Delta_R_local ...
    1185              : !> \param bs_env ...
    1186              : !> \param occ ...
    1187              : !> \param vir ...
    1188              : !> \param clear_t_W ...
    1189              : !> \param fill_skip ...
    1190              : ! **************************************************************************************************
    1191         1243 :    SUBROUTINE contract_to_Sigma(Sigma_R, t_W, G_S, i_task_Delta_R_local, bs_env, occ, vir, &
    1192              :                                 clear_t_W, fill_skip)
    1193              :       TYPE(dbt_type), DIMENSION(:)                       :: Sigma_R
    1194              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)       :: t_W
    1195              :       TYPE(dbt_type), DIMENSION(:)                       :: G_S
    1196              :       INTEGER                                            :: i_task_Delta_R_local
    1197              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
    1198              :       LOGICAL                                            :: occ, vir, clear_t_W, fill_skip
    1199              : 
    1200              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'contract_to_Sigma'
    1201              : 
    1202              :       INTEGER :: handle, handle2, i_cell_Delta_R, i_cell_m_R1, i_cell_R, i_cell_R1, &
    1203              :          i_cell_R1_minus_R, i_cell_S1, i_cell_S1_minus_R, i_cell_S1_p_S2_m_R1, i_cell_S2
    1204              :       INTEGER(KIND=int_8)                                :: flop, flop_tmp
    1205              :       INTEGER, DIMENSION(3)                              :: cell_DR, cell_m_R1, cell_R, cell_R1, &
    1206              :                                                             cell_R1_minus_R, cell_S1, &
    1207              :                                                             cell_S1_minus_R, cell_S1_p_S2_m_R1, &
    1208              :                                                             cell_S2
    1209              :       LOGICAL                                            :: cell_found
    1210              :       REAL(KIND=dp)                                      :: sign_Sigma
    1211        31075 :       TYPE(dbt_type)                                     :: t_3c_int, t_G, t_G_2
    1212              : 
    1213         1243 :       CALL timeset(routineN, handle)
    1214              : 
    1215         1243 :       CPASSERT(occ .EQV. (.NOT. vir))
    1216         1243 :       IF (occ) sign_Sigma = -1.0_dp
    1217         1243 :       IF (vir) sign_Sigma = 1.0_dp
    1218              : 
    1219         1243 :       CALL dbt_create(bs_env%t_RI_AO__AO, t_G)
    1220         1243 :       CALL dbt_create(bs_env%t_RI_AO__AO, t_G_2)
    1221         1243 :       CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_int)
    1222              : 
    1223         1243 :       i_cell_Delta_R = bs_env%task_Delta_R(i_task_Delta_R_local)
    1224              : 
    1225         1243 :       flop = 0_int_8
    1226              : 
    1227        15592 :       DO i_cell_R1 = 1, bs_env%nimages_3c
    1228              : 
    1229        57396 :          cell_R1(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_R1)
    1230        57396 :          cell_DR(1:3) = bs_env%index_to_cell_Delta_R(1:3, i_cell_Delta_R)
    1231              : 
    1232              :          ! S_1 = R_1 + ΔR (from ΔR = S_1 - R_1)
    1233              :          CALL add_R(cell_R1, cell_DR, bs_env%index_to_cell_3c, cell_S1, cell_found, &
    1234        14349 :                     bs_env%cell_to_index_3c, i_cell_S1)
    1235        14349 :          IF (.NOT. cell_found) CYCLE
    1236              : 
    1237        73040 :          DO i_cell_S2 = 1, bs_env%nimages_scf_desymm
    1238              : 
    1239        65736 :             IF (bs_env%skip_DR_R1_S2_Gx3c_Sigma(i_task_Delta_R_local, i_cell_R1, i_cell_S2)) CYCLE
    1240              : 
    1241       207144 :             cell_S2(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_S2)
    1242       207144 :             cell_m_R1(1:3) = -cell_R1(1:3)
    1243       207144 :             cell_S1_p_S2_m_R1(1:3) = cell_S1(1:3) + cell_S2(1:3) - cell_R1(1:3)
    1244              : 
    1245        51786 :             CALL is_cell_in_index_to_cell(cell_m_R1, bs_env%index_to_cell_3c, cell_found)
    1246        51786 :             IF (.NOT. cell_found) CYCLE
    1247              : 
    1248        38997 :             CALL is_cell_in_index_to_cell(cell_S1_p_S2_m_R1, bs_env%index_to_cell_3c, cell_found)
    1249        38997 :             IF (.NOT. cell_found) CYCLE
    1250              : 
    1251        21513 :             i_cell_m_R1 = bs_env%cell_to_index_3c(cell_m_R1(1), cell_m_R1(2), cell_m_R1(3))
    1252              :             i_cell_S1_p_S2_m_R1 = bs_env%cell_to_index_3c(cell_S1_p_S2_m_R1(1), &
    1253              :                                                           cell_S1_p_S2_m_R1(2), &
    1254        21513 :                                                           cell_S1_p_S2_m_R1(3))
    1255              : 
    1256        21513 :             CALL timeset(routineN//"_3c_x_G", handle2)
    1257              : 
    1258        21513 :             CALL get_t_3c_int(t_3c_int, bs_env, i_cell_m_R1, i_cell_S1_p_S2_m_R1)
    1259              : 
    1260              :             ! M_λ0,νS1,PR1 = sum_µS2 ( λ0   µS1-S2    | PR1 ) G^occ/vir_µν^S2(i|τ|)
    1261              :             !              = sum_µS2 ( λ-R1 µS1-S2-R1 | P0  ) G^occ/vir_µν^S2(i|τ|)
    1262              :             ! for ΔR = S_1 - R_1
    1263              :             CALL dbt_contract(alpha=1.0_dp, &
    1264              :                               tensor_1=G_S(i_cell_S2), &
    1265              :                               tensor_2=t_3c_int, &
    1266              :                               beta=1.0_dp, &
    1267              :                               tensor_3=t_G, &
    1268              :                               contract_1=[2], notcontract_1=[1], map_1=[3], &
    1269              :                               contract_2=[3], notcontract_2=[1, 2], map_2=[1, 2], &
    1270        21513 :                               filter_eps=bs_env%eps_filter, flop=flop_tmp)
    1271              : 
    1272        21513 :             IF (flop_tmp == 0_int_8 .AND. fill_skip) THEN
    1273         2561 :                bs_env%skip_DR_R1_S2_Gx3c_Sigma(i_task_Delta_R_local, i_cell_R1, i_cell_S2) = .TRUE.
    1274              :             END IF
    1275              : 
    1276        94553 :             CALL timestop(handle2)
    1277              : 
    1278              :          END DO ! i_cell_S2
    1279              : 
    1280         7304 :          CALL dbt_copy(t_G, t_G_2, order=[1, 3, 2], move_data=.TRUE.)
    1281              : 
    1282         7304 :          CALL timeset(routineN//"_contract", handle2)
    1283              : 
    1284        73040 :          DO i_cell_R = 1, bs_env%nimages_scf_desymm
    1285              : 
    1286        65736 :             IF (bs_env%skip_DR_R1_R_MxM_Sigma(i_task_Delta_R_local, i_cell_R1, i_cell_R)) CYCLE
    1287              : 
    1288       189192 :             cell_R = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_R)
    1289              : 
    1290              :             ! R_1 - R
    1291              :             CALL add_R(cell_R1, -cell_R, bs_env%index_to_cell_3c, cell_R1_minus_R, &
    1292       189192 :                        cell_found, bs_env%cell_to_index_3c, i_cell_R1_minus_R)
    1293        47298 :             IF (.NOT. cell_found) CYCLE
    1294              : 
    1295              :             ! S_1 - R
    1296              :             CALL add_R(cell_S1, -cell_R, bs_env%index_to_cell_3c, cell_S1_minus_R, &
    1297       103036 :                        cell_found, bs_env%cell_to_index_3c, i_cell_S1_minus_R)
    1298        25759 :             IF (.NOT. cell_found) CYCLE
    1299              : 
    1300              :             ! Σ_λσ^R = sum_PR1νS1 M^G_λ0,νS1,PR1 M^W_σR,νS1,PR1, where
    1301              :             ! M^G_λ0,νS1,PR1 = sum_µS2 (λ0 µS1-S2 | PR1) G_µν^S2
    1302              :             ! M^W_σR,νS1,PR1 = sum_QR2 (σR νS1 | QR1-R2) W_PQ^R2 = M^W_σ0,νS1-R,PR1-R
    1303              :             CALL dbt_contract(alpha=sign_Sigma, &
    1304              :                               tensor_1=t_G_2, &
    1305              :                               tensor_2=t_W(i_cell_S1_minus_R, i_cell_R1_minus_R), &
    1306              :                               beta=1.0_dp, &
    1307              :                               tensor_3=Sigma_R(i_cell_R), &
    1308              :                               contract_1=[1, 2], notcontract_1=[3], map_1=[1], &
    1309              :                               contract_2=[1, 2], notcontract_2=[3], map_2=[2], &
    1310        16108 :                               filter_eps=bs_env%eps_filter, flop=flop_tmp)
    1311              : 
    1312        16108 :             flop = flop + flop_tmp
    1313              : 
    1314        23412 :             IF (flop_tmp == 0_int_8 .AND. fill_skip) THEN
    1315         3900 :                bs_env%skip_DR_R1_R_MxM_Sigma(i_task_Delta_R_local, i_cell_R1, i_cell_R) = .TRUE.
    1316              :             END IF
    1317              : 
    1318              :          END DO ! i_cell_R
    1319              : 
    1320         7304 :          CALL dbt_clear(t_G_2)
    1321              : 
    1322        30200 :          CALL timestop(handle2)
    1323              : 
    1324              :       END DO ! i_cell_R1
    1325              : 
    1326         1243 :       IF (vir .AND. flop == 0_int_8) bs_env%skip_DR_Sigma(i_task_Delta_R_local) = .TRUE.
    1327              : 
    1328              :       ! release memory
    1329         1243 :       IF (clear_t_W) THEN
    1330         9200 :          DO i_cell_S1 = 1, bs_env%nimages_3c
    1331       109159 :             DO i_cell_R1 = 1, bs_env%nimages_3c
    1332       108426 :                CALL dbt_clear(t_W(i_cell_S1, i_cell_R1))
    1333              :             END DO
    1334              :          END DO
    1335              :       END IF
    1336              : 
    1337         1243 :       CALL dbt_destroy(t_G)
    1338         1243 :       CALL dbt_destroy(t_G_2)
    1339         1243 :       CALL dbt_destroy(t_3c_int)
    1340              : 
    1341         1243 :       CALL timestop(handle)
    1342              : 
    1343         1243 :    END SUBROUTINE contract_to_Sigma
    1344              : 
    1345              : ! **************************************************************************************************
    1346              : !> \brief ...
    1347              : !> \param fm_W_R ...
    1348              : !> \param W_R ...
    1349              : !> \param bs_env ...
    1350              : ! **************************************************************************************************
    1351          104 :    SUBROUTINE fm_MWM_R_t_to_local_tensor_W_R(fm_W_R, W_R, bs_env)
    1352              :       TYPE(cp_fm_type), DIMENSION(:)                     :: fm_W_R
    1353              :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:)          :: W_R
    1354              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
    1355              : 
    1356              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'fm_MWM_R_t_to_local_tensor_W_R'
    1357              : 
    1358              :       INTEGER                                            :: handle, i_cell_R
    1359              : 
    1360          104 :       CALL timeset(routineN, handle)
    1361              : 
    1362              :       ! communicate fm_W_R to tensor W_R; full replication in tensor group
    1363         1040 :       DO i_cell_R = 1, bs_env%nimages_scf_desymm
    1364              :          CALL cp_fm_to_dbt(fm_W_R(i_cell_R), bs_env%mat_RI_RI%matrix, bs_env%mat_RI_RI_tensor%matrix, &
    1365              :                            W_R(i_cell_R), bs_env%para_env, bs_env%para_env_tensor%num_pe, &
    1366         1040 :                            bs_env%eps_filter)
    1367              :       END DO
    1368              : 
    1369          104 :       CALL timestop(handle)
    1370              : 
    1371          104 :    END SUBROUTINE fm_MWM_R_t_to_local_tensor_W_R
    1372              : 
    1373              : ! **************************************************************************************************
    1374              : !> \brief ...
    1375              : !> \param bs_env ...
    1376              : ! **************************************************************************************************
    1377           16 :    SUBROUTINE compute_QP_energies(bs_env)
    1378              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
    1379              : 
    1380              :       CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_QP_energies'
    1381              : 
    1382              :       COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :)     :: Sigma_c_ikp_n_freq
    1383              :       INTEGER                                            :: handle, ikp, ispin, j_t
    1384              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:)           :: Sigma_x_ikp_n
    1385              :       REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :)     :: Sigma_c_ikp_n_time
    1386              :       TYPE(cp_cfm_type)                                  :: cfm_mo_coeff
    1387              :       TYPE(gw_qp_summary_type)                           :: qp_summary
    1388              : 
    1389           16 :       CALL timeset(routineN, handle)
    1390              : 
    1391           16 :       CALL cp_cfm_create(cfm_mo_coeff, bs_env%fm_s_Gamma%matrix_struct)
    1392           48 :       ALLOCATE (Sigma_x_ikp_n(bs_env%n_ao))
    1393           80 :       ALLOCATE (Sigma_c_ikp_n_time(bs_env%n_ao, bs_env%num_time_freq_points, 2))
    1394           64 :       ALLOCATE (Sigma_c_ikp_n_freq(bs_env%n_ao, bs_env%num_freq_points_fit))
    1395              : 
    1396           16 :       qp_summary%n_kpoints = bs_env%nkp_bs_and_DOS
    1397           32 :       DO ispin = 1, bs_env%n_spin
    1398              : 
    1399          350 :          DO ikp = 1, bs_env%nkp_bs_and_DOS
    1400              : 
    1401              :             ! 1. get C_µn(k)
    1402          318 :             CALL cp_cfm_to_cfm(bs_env%cfm_mo_coeff_kp(ikp, ispin), cfm_mo_coeff)
    1403              : 
    1404              :             ! 2. Σ^x_µν(k) = sum_R Σ^x_µν^R e^ikR
    1405              :             !    Σ^x_nn(k) = sum_µν C^*_µn(k) Σ^x_µν(k) C_νn(k)
    1406          318 :             CALL trafo_to_k_and_nn(bs_env%fm_Sigma_x_R, Sigma_x_ikp_n, cfm_mo_coeff, bs_env, ikp)
    1407              : 
    1408              :             ! 3. Σ^c_µν(k,+/-i|τ_j|) = sum_R Σ^c_µν^R(+/-i|τ_j|) e^ikR
    1409              :             !    Σ^c_nn(k,+/-i|τ_j|) = sum_µν C^*_µn(k) Σ^c_µν(k,+/-i|τ_j|) C_νn(k)
    1410         2602 :             DO j_t = 1, bs_env%num_time_freq_points
    1411              :                CALL trafo_to_k_and_nn(bs_env%fm_Sigma_c_R_pos_tau(:, j_t, ispin), &
    1412         2284 :                                       Sigma_c_ikp_n_time(:, j_t, positive_time), cfm_mo_coeff, bs_env, ikp)
    1413              :                CALL trafo_to_k_and_nn(bs_env%fm_Sigma_c_R_neg_tau(:, j_t, ispin), &
    1414         2602 :                                       Sigma_c_ikp_n_time(:, j_t, negative_time), cfm_mo_coeff, bs_env, ikp)
    1415              :             END DO
    1416              : 
    1417              :             ! 4. Σ^c_nn(k_i,iω) = ∫ from -∞ to ∞ dτ e^-iωτ Σ^c_nn(k_i,iτ)
    1418          318 :             CALL transform_time_to_frequency(bs_env%time_frequency_grid_sigma, Sigma_c_ikp_n_time, Sigma_c_ikp_n_freq)
    1419        11098 :             Sigma_c_ikp_n_freq(1:bs_env%n_occ(ispin), :) = CONJG(Sigma_c_ikp_n_freq(1:bs_env%n_occ(ispin), :))
    1420              : 
    1421              :             ! 5. Analytic continuation Σ^c_nn(k_i,iω) -> Σ^c_nn(k_i,ϵ) and
    1422              :             !    ϵ_nk_i^GW = ϵ_nk_i^DFT + Σ^c_nn(k_i,ϵ) + Σ^x_nn(k_i) - v^xc_nn(k_i)
    1423              :             CALL analyt_conti_and_print(bs_env, Sigma_c_ikp_n_freq, Sigma_x_ikp_n, &
    1424              :                                         bs_env%v_xc_n(:, ikp, ispin), &
    1425          334 :                                         bs_env%eigenval_scf(:, ikp, ispin), ikp, ispin, qp_summary)
    1426              : 
    1427              :          END DO ! ikp
    1428              : 
    1429              :       END DO ! ispin
    1430              : 
    1431           16 :       CALL get_all_VBM_CBM_bandgaps(bs_env)
    1432              : 
    1433           16 :       CALL cp_cfm_release(cfm_mo_coeff)
    1434              : 
    1435           16 :       CALL timestop(handle)
    1436              : 
    1437           32 :    END SUBROUTINE compute_QP_energies
    1438              : 
    1439              : ! **************************************************************************************************
    1440              : !> \brief ...
    1441              : !> \param fm_rs ...
    1442              : !> \param array_ikp_n ...
    1443              : !> \param cfm_mo_coeff ...
    1444              : !> \param bs_env ...
    1445              : !> \param ikp ...
    1446              : ! **************************************************************************************************
    1447         4886 :    SUBROUTINE trafo_to_k_and_nn(fm_rs, array_ikp_n, cfm_mo_coeff, bs_env, ikp)
    1448              :       TYPE(cp_fm_type), DIMENSION(:)                     :: fm_rs
    1449              :       REAL(KIND=dp), DIMENSION(:)                        :: array_ikp_n
    1450              :       TYPE(cp_cfm_type)                                  :: cfm_mo_coeff
    1451              :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
    1452              :       INTEGER                                            :: ikp
    1453              : 
    1454              :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'trafo_to_k_and_nn'
    1455              : 
    1456              :       COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:)        :: cdiag
    1457              :       INTEGER                                            :: handle
    1458              :       TYPE(cp_cfm_type)                                  :: cfm_ikp
    1459              : 
    1460         4886 :       CALL timeset(routineN, handle)
    1461              : 
    1462         4886 :       CALL cp_cfm_create(cfm_ikp, cfm_mo_coeff%matrix_struct)
    1463              : 
    1464              :       ! Σ_µν(k_i) = sum_R e^ik_iR Σ_µν^R
    1465         4886 :       CALL fm_rs_to_kp(cfm_ikp, fm_rs, bs_env%kpoints_DOS, ikp)
    1466              : 
    1467              :       ! Σ_nm(k_i) = sum_µν C^*_µn(k_i) Σ_µν(k_i) C_νn(k_i)
    1468         4886 :       CALL cfm_contract_ABA(cfm_mo_coeff, cfm_ikp)
    1469              : 
    1470              :       ! get Σ_nn(k_i) which is a real quantity as Σ^x and Σ^c(iτ) is Hermitian
    1471        14658 :       ALLOCATE (cdiag(SIZE(array_ikp_n)))
    1472         4886 :       CALL cp_cfm_get_diag(cfm_ikp, cdiag)
    1473        63420 :       array_ikp_n = REAL(cdiag, KIND=dp)
    1474              : 
    1475         4886 :       DEALLOCATE (cdiag)
    1476         4886 :       CALL cp_cfm_release(cfm_ikp)
    1477              : 
    1478         4886 :       CALL timestop(handle)
    1479              : 
    1480         4886 :    END SUBROUTINE trafo_to_k_and_nn
    1481              : 
    1482              : END MODULE gw_tensor_small_cell_full_kp
        

Generated by: LCOV version 2.0-1