(git:27c966b)
Loading...
Searching...
No Matches
gw_tensor_small_cell_full_kp.F
Go to the documentation of this file.
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! **************************************************************************************************
14 USE bibliography, ONLY: pasquier2025,&
15 cite_reference
17 USE cp_cfm_types, ONLY: cp_cfm_create,&
22 USE cp_fm_types, ONLY: cp_fm_set_all,&
25 USE dbt_api, ONLY: dbt_clear,&
26 dbt_contract,&
27 dbt_copy,&
28 dbt_create,&
29 dbt_destroy,&
30 dbt_type
34 USE gw_utils, ONLY: add_r,&
38 USE gw_utils_fm, ONLY: cfm_contract_aba,&
41 USE kinds, ONLY: dp,&
42 int_8
48 USE machine, ONLY: m_walltime
49 USE mathconstants, ONLY: z_one,&
50 z_zero
51 USE mathlib, ONLY: gemm_square
59#include "./base/base_uses.f90"
60
61 IMPLICIT NONE
62
63 PRIVATE
64
65 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_tensor_small_cell_full_kp'
66
68
69CONTAINS
70
71! **************************************************************************************************
72!> \brief Perform GW band structure calculation
73!> \param qs_env ...
74!> \param bs_env Band-structure environment containing GW parameters.
75!> \par History
76!> * 05.2024 created [Jan Wilhelm]
77! **************************************************************************************************
78 SUBROUTINE gw_calc_tensor_small_cell_full_kp(qs_env, bs_env)
79 TYPE(qs_environment_type), POINTER :: qs_env
80 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
81
82 CHARACTER(LEN=*), PARAMETER :: routinen = 'gw_calc_tensor_small_cell_full_kp'
83
84 INTEGER :: handle
85
86 CALL timeset(routinen, handle)
87
88 CALL cite_reference(pasquier2025)
89
90 ! G^occ_µλ(i|τ|,k) = sum_n^occ C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k)
91 ! G^vir_µλ(i|τ|,k) = sum_n^vir C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k)
92 ! k-point k -> cell S: G^occ/vir_µλ^S(i|τ|) = sum_k w_k G^occ/vir_µλ(i|τ|,k) e^(ikS)
93 ! χ_PQ^R(iτ) = sum_λR1νR2 [ sum_µS (µR1-S νR2 | P0) G^vir_λµ^S(i|τ|) ]
94 ! [ sum_σS (σR2-S λR1 | QR) G^occ_νσ^S(i|τ|) ]
95 CALL compute_chi(bs_env)
96
97 ! χ_PQ^R(iτ) -> χ_PQ(iω,k) -> ε_PQ(iω,k) -> W_PQ(iω,k) -> Ŵ(iω,k) = M^-1(k)*W(iω,k)*M^-1(k)
98 ! -> Ŵ_PQ^R(iτ)
99 CALL compute_w_real_space(bs_env, qs_env)
100
101 ! D_µν(k) = sum_n^occ C^*_µn(k) C_νn(k), V^tr_PQ^R = <phi_P,0|V^tr|phi_Q,R>
102 ! V^tr(k) = sum_R e^ikR V^tr^R, M(k) = sum_R e^ikR M^R, M(k) -> M^-1(k)
103 ! -> Ṽ^tr(k) = M^-1(k) * V^tr(k) * M^-1(k) -> Ṽ^tr_PQ^R = sum_k w_k e^-ikR Ṽ^tr_PQ(k)
104 ! Σ^x_λσ^R = sum_PR1νS1 [ sum_µS2 (λ0 µS1-S2 | PR1 ) D_µν^S2 ]
105 ! [ sum_QR2 (σR νS1 | QR1-R2) Ṽ^tr_PQ^R2 ]
106 CALL compute_sigma_x(bs_env, qs_env)
107
108 ! Σ^c_λσ^R(iτ) = sum_PR1νS1 [ sum_µS2 (λ0 µS1-S2 | PR1 ) G^occ/vir_µν^S2(i|τ|) ]
109 ! [ sum_QR2 (σR νS1 | QR1-R2) Ŵ_PQ^R2(iτ) ]
110 CALL compute_sigma_c(bs_env)
111
112 ! Σ^c_λσ^R(iτ,k=0) -> Σ^c_nn(ϵ,k); ϵ_nk^GW = ϵ_nk^DFT + Σ^c_nn(ϵ,k) + Σ^x_nn(k) - v^xc_nn(k)
113 CALL compute_qp_energies(bs_env)
114
115 CALL de_init_bs_env(qs_env, bs_env)
116
117 CALL timestop(handle)
118
120
121! **************************************************************************************************
122!> \brief ...
123!> \param bs_env ...
124! **************************************************************************************************
125 SUBROUTINE compute_chi(bs_env)
126 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
127
128 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_chi'
129
130 INTEGER :: cell_dr(3), cell_r1(3), cell_r2(3), &
131 handle, i_cell_delta_r, i_cell_r1, &
132 i_cell_r2, i_t, i_task_delta_r_local, &
133 ispin
134 LOGICAL :: cell_found
135 REAL(kind=dp) :: t1, tau
136 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: gocc_s, gvir_s, t_chi_r
137 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_gocc, t_gvir
138
139 CALL timeset(routinen, handle)
140
141 DO i_t = 1, bs_env%num_time_freq_points
142
143 CALL dbt_create_2c_r(gocc_s, bs_env%t_G, bs_env%nimages_scf_desymm)
144 CALL dbt_create_2c_r(gvir_s, bs_env%t_G, bs_env%nimages_scf_desymm)
145 CALL dbt_create_2c_r(t_chi_r, bs_env%t_chi, bs_env%nimages_scf_desymm)
146 CALL dbt_create_3c_r1_r2(t_gocc, bs_env%t_RI_AO__AO, bs_env%nimages_3c, bs_env%nimages_3c)
147 CALL dbt_create_3c_r1_r2(t_gvir, bs_env%t_RI_AO__AO, bs_env%nimages_3c, bs_env%nimages_3c)
148
149 t1 = m_walltime()
150 tau = bs_env%time_frequency_grid%imaginary_time(i_t)
151
152 DO ispin = 1, bs_env%n_spin
153
154 ! 1. compute G^occ,S(iτ) and G^vir^S(iτ) in imaginary time for cell S
155 ! Background: G^σ,S(iτ) = G^occ,S,σ(iτ) * Θ(-τ) + G^vir,S,σ(iτ) * Θ(τ), σ ∈ {↑,↓}
156 ! G^occ_µλ(i|τ|,k) = sum_n^occ C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k)
157 ! G^vir_µλ(i|τ|,k) = sum_n^vir C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k)
158 ! k-point k -> cell S: G^occ/vir_µλ^S(i|τ|) = sum_k w_k G^occ/vir_µλ(i|τ|,k) e^(ikS)
159 CALL g_occ_vir(bs_env, tau, gocc_s, ispin, occ=.true., vir=.false.)
160 CALL g_occ_vir(bs_env, tau, gvir_s, ispin, occ=.false., vir=.true.)
161
162 ! loop over ΔR = R_1 - R_2 which are local in the tensor subgroup
163 DO i_task_delta_r_local = 1, bs_env%n_tasks_Delta_R_local
164
165 IF (bs_env%skip_DR_chi(i_task_delta_r_local)) cycle
166
167 i_cell_delta_r = bs_env%task_Delta_R(i_task_delta_r_local)
168
169 DO i_cell_r2 = 1, bs_env%nimages_3c
170
171 cell_r2(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_r2)
172 cell_dr(1:3) = bs_env%index_to_cell_Delta_R(1:3, i_cell_delta_r)
173
174 ! R_1 = R_2 + ΔR (from ΔR = R_2 - R_1)
175 CALL add_r(cell_r2, cell_dr, bs_env%index_to_cell_3c, cell_r1, &
176 cell_found, bs_env%cell_to_index_3c, i_cell_r1)
177
178 ! 3-cells check because in M^vir_νR2,λR1,QR (step 3.): R2 is index on ν
179 IF (.NOT. cell_found) cycle
180 ! 2. M^occ/vir_λR1,νR2,P0 = sum_µS (λR1 µR2-S | P0) G^occ/vir_νµ^S(iτ)
181 CALL g_times_3c(gocc_s, t_gocc, bs_env, i_cell_r1, i_cell_r2, &
182 i_task_delta_r_local, bs_env%skip_DR_R12_S_Goccx3c_chi)
183 CALL g_times_3c(gvir_s, t_gvir, bs_env, i_cell_r2, i_cell_r1, &
184 i_task_delta_r_local, bs_env%skip_DR_R12_S_Gvirx3c_chi)
185
186 END DO ! i_cell_R2
187
188 ! 3. χ_PQ^R(iτ) = sum_λR1,νR2 M^occ_λR1,νR2,P0 M^vir_νR2,λR1,QR
189 CALL contract_m_occ_vir_to_chi(t_gocc, t_gvir, t_chi_r, bs_env, &
190 i_task_delta_r_local)
191
192 END DO ! i_cell_Delta_R_local
193
194 END DO ! ispin
195
196 CALL bs_env%para_env%sync()
197
198 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, &
199 bs_env%para_env)
200
201 CALL destroy_t_1d(gocc_s)
202 CALL destroy_t_1d(gvir_s)
203 CALL destroy_t_1d(t_chi_r)
204 CALL destroy_t_2d(t_gocc)
205 CALL destroy_t_2d(t_gvir)
206
207 IF (bs_env%unit_nr > 0) THEN
208 WRITE (bs_env%unit_nr, '(T2,A,I13,A,I3,A,F7.1,A)') &
209 'Computed χ^R(iτ) for time point', i_t, ' /', bs_env%num_time_freq_points, &
210 ', Execution time', m_walltime() - t1, ' s'
211 END IF
212
213 END DO ! i_t
214
215 CALL timestop(handle)
216
217 END SUBROUTINE compute_chi
218
219! *************************************************************************************************
220!> \brief ...
221!> \param R ...
222!> \param template ...
223!> \param nimages ...
224! **************************************************************************************************
225 SUBROUTINE dbt_create_2c_r(R, template, nimages)
226
227 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: r
228 TYPE(dbt_type) :: template
229 INTEGER :: nimages
230
231 CHARACTER(LEN=*), PARAMETER :: routinen = 'dbt_create_2c_R'
232
233 INTEGER :: handle, i_cell_s
234
235 CALL timeset(routinen, handle)
236
237 ALLOCATE (r(nimages))
238 DO i_cell_s = 1, nimages
239 CALL dbt_create(template, r(i_cell_s))
240 END DO
241
242 CALL timestop(handle)
243
244 END SUBROUTINE dbt_create_2c_r
245
246! **************************************************************************************************
247!> \brief ...
248!> \param t_3c_R1_R2 ...
249!> \param t_3c_template ...
250!> \param nimages_1 ...
251!> \param nimages_2 ...
252! **************************************************************************************************
253 SUBROUTINE dbt_create_3c_r1_r2(t_3c_R1_R2, t_3c_template, nimages_1, nimages_2)
254
255 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_3c_r1_r2
256 TYPE(dbt_type) :: t_3c_template
257 INTEGER :: nimages_1, nimages_2
258
259 CHARACTER(LEN=*), PARAMETER :: routinen = 'dbt_create_3c_R1_R2'
260
261 INTEGER :: handle, i_cell, j_cell
262
263 CALL timeset(routinen, handle)
264
265 ALLOCATE (t_3c_r1_r2(nimages_1, nimages_2))
266 DO i_cell = 1, nimages_1
267 DO j_cell = 1, nimages_2
268 CALL dbt_create(t_3c_template, t_3c_r1_r2(i_cell, j_cell))
269 END DO
270 END DO
271
272 CALL timestop(handle)
273
274 END SUBROUTINE dbt_create_3c_r1_r2
275
276! **************************************************************************************************
277!> \brief ...
278!> \param t_G_S ...
279!> \param t_M ...
280!> \param bs_env ...
281!> \param i_cell_R1 ...
282!> \param i_cell_R2 ...
283!> \param i_task_Delta_R_local ...
284!> \param skip_DR_R1_S_Gx3c ...
285! **************************************************************************************************
286 SUBROUTINE g_times_3c(t_G_S, t_M, bs_env, i_cell_R1, i_cell_R2, i_task_Delta_R_local, &
287 skip_DR_R1_S_Gx3c)
288 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: t_g_s
289 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_m
290 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
291 INTEGER :: i_cell_r1, i_cell_r2, &
292 i_task_delta_r_local
293 LOGICAL, ALLOCATABLE, DIMENSION(:, :, :) :: skip_dr_r1_s_gx3c
294
295 CHARACTER(LEN=*), PARAMETER :: routinen = 'G_times_3c'
296
297 INTEGER :: handle, i_cell_r1_p_s, i_cell_s
298 INTEGER(KIND=int_8) :: flop
299 INTEGER, DIMENSION(3) :: cell_r1, cell_r1_plus_cell_s, cell_r2, &
300 cell_s
301 LOGICAL :: cell_found
302 TYPE(dbt_type) :: t_3c_int
303
304 CALL timeset(routinen, handle)
305
306 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_int)
307
308 cell_r1(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_r1)
309 cell_r2(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_r2)
310
311 DO i_cell_s = 1, bs_env%nimages_scf_desymm
312
313 IF (skip_dr_r1_s_gx3c(i_task_delta_r_local, i_cell_r1, i_cell_s)) cycle
314
315 cell_s(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_s)
316 cell_r1_plus_cell_s(1:3) = cell_r1(1:3) + cell_s(1:3)
317
318 CALL is_cell_in_index_to_cell(cell_r1_plus_cell_s, bs_env%index_to_cell_3c, cell_found)
319
320 IF (.NOT. cell_found) cycle
321
322 i_cell_r1_p_s = bs_env%cell_to_index_3c(cell_r1_plus_cell_s(1), cell_r1_plus_cell_s(2), &
323 cell_r1_plus_cell_s(3))
324
325 IF (bs_env%nblocks_3c(i_cell_r2, i_cell_r1_p_s) == 0) cycle
326
327 CALL get_t_3c_int(t_3c_int, bs_env, i_cell_r2, i_cell_r1_p_s)
328
329 CALL dbt_contract(alpha=1.0_dp, &
330 tensor_1=t_3c_int, &
331 tensor_2=t_g_s(i_cell_s), &
332 beta=1.0_dp, &
333 tensor_3=t_m(i_cell_r1, i_cell_r2), &
334 contract_1=[3], notcontract_1=[1, 2], map_1=[1, 2], &
335 contract_2=[2], notcontract_2=[1], map_2=[3], &
336 filter_eps=bs_env%eps_filter, flop=flop)
337
338 IF (flop == 0_int_8) skip_dr_r1_s_gx3c(i_task_delta_r_local, i_cell_r1, i_cell_s) = .true.
339
340 END DO
341
342 CALL dbt_destroy(t_3c_int)
343
344 CALL timestop(handle)
345
346 END SUBROUTINE g_times_3c
347
348! **************************************************************************************************
349!> \brief ...
350!> \param t_3c_int ...
351!> \param bs_env ...
352!> \param j_cell ...
353!> \param k_cell ...
354! **************************************************************************************************
355 SUBROUTINE get_t_3c_int(t_3c_int, bs_env, j_cell, k_cell)
356
357 TYPE(dbt_type) :: t_3c_int
358 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
359 INTEGER :: j_cell, k_cell
360
361 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_t_3c_int'
362
363 INTEGER :: handle
364
365 CALL timeset(routinen, handle)
366
367 CALL dbt_clear(t_3c_int)
368 IF (j_cell < k_cell) THEN
369 CALL dbt_copy(bs_env%t_3c_int(k_cell, j_cell), t_3c_int, order=[1, 3, 2])
370 ELSE
371 CALL dbt_copy(bs_env%t_3c_int(j_cell, k_cell), t_3c_int)
372 END IF
373
374 CALL timestop(handle)
375
376 END SUBROUTINE get_t_3c_int
377
378! **************************************************************************************************
379!> \brief ...
380!> \param bs_env ...
381!> \param tau ...
382!> \param G_S ...
383!> \param ispin ...
384!> \param occ ...
385!> \param vir ...
386! **************************************************************************************************
387 SUBROUTINE g_occ_vir(bs_env, tau, G_S, ispin, occ, vir)
388 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
389 REAL(kind=dp) :: tau
390 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: g_s
391 INTEGER :: ispin
392 LOGICAL :: occ, vir
393
394 CHARACTER(LEN=*), PARAMETER :: routinen = 'G_occ_vir'
395
396 INTEGER :: first_mo, handle, homo, i_cell_s, ikp, &
397 j, last_mo, nkp
398 REAL(kind=dp) :: tau_e
399 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: column_factors
400
401 CALL timeset(routinen, handle)
402
403 cpassert(occ .NEQV. vir)
404
405 nkp = bs_env%nkp_scf_desymm
406 homo = bs_env%n_occ(ispin)
407 first_mo = 1
408 last_mo = homo
409 IF (vir) THEN
410 first_mo = homo + 1
411 last_mo = bs_env%n_ao
412 END IF
413 ALLOCATE (column_factors(first_mo:last_mo))
414
415 DO i_cell_s = 1, bs_env%nimages_scf_desymm
416 CALL cp_fm_set_all(bs_env%fm_G_S(i_cell_s), 0.0_dp)
417 END DO
418
419 DO ikp = 1, nkp
420
421 ! G^occ/vir_µλ(i|τ|,k) = sum_n^occ/vir C_µn(k) e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k)^*
422 DO j = first_mo, last_mo
423 ! 0.5 * |(ϵ_nk-ϵ_F)τ|
424 tau_e = abs(tau*0.5_dp*(bs_env%eigenval_scf(j, ikp, ispin) - bs_env%e_fermi(ispin)))
425 IF (tau_e < bs_env%stabilize_exp) THEN
426 column_factors(j) = exp(-tau_e)
427 ELSE
428 column_factors(j) = 0.0_dp
429 END IF
430 END DO
431
432 CALL build_ao_propagator(bs_env%cfm_mo_coeff_kp(ikp, ispin), column_factors, first_mo, &
433 bs_env%cfm_work_mo, bs_env%cfm_work_mo_2)
434
435 ! trafo k-point k -> cell S: G^occ/vir_µλ(i|τ|,k) -> G^occ/vir,S_µλ(i|τ|)
436 CALL fm_add_kp_to_all_rs(bs_env%cfm_work_mo_2, bs_env%fm_G_S, &
437 bs_env%kpoints_scf_desymm, ikp)
438
439 END DO ! ikp
440 DEALLOCATE (column_factors)
441
442 ! replicate to tensor from local tensor group
443 DO i_cell_s = 1, bs_env%nimages_scf_desymm
444 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, &
445 g_s(i_cell_s), bs_env%para_env, bs_env%para_env_tensor%num_pe, &
446 bs_env%eps_filter)
447 END DO
448
449 CALL timestop(handle)
450
451 END SUBROUTINE g_occ_vir
452
453! **************************************************************************************************
454!> \brief ...
455!> \param t_Gocc ...
456!> \param t_Gvir ...
457!> \param t_chi_R ...
458!> \param bs_env ...
459!> \param i_task_Delta_R_local ...
460! **************************************************************************************************
461 SUBROUTINE contract_m_occ_vir_to_chi(t_Gocc, t_Gvir, t_chi_R, bs_env, i_task_Delta_R_local)
462 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_gocc, t_gvir
463 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: t_chi_r
464 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
465 INTEGER :: i_task_delta_r_local
466
467 CHARACTER(LEN=*), PARAMETER :: routinen = 'contract_M_occ_vir_to_chi'
468
469 INTEGER :: handle, i_cell_delta_r, i_cell_r, &
470 i_cell_r1, i_cell_r1_minus_r, &
471 i_cell_r2, i_cell_r2_minus_r
472 INTEGER(KIND=int_8) :: flop, flop_tmp
473 INTEGER, DIMENSION(3) :: cell_dr, cell_r, cell_r1, &
474 cell_r1_minus_r, cell_r2, &
475 cell_r2_minus_r
476 LOGICAL :: cell_found
477 TYPE(dbt_type) :: t_gocc_2, t_gvir_2
478
479 CALL timeset(routinen, handle)
480
481 CALL dbt_create(bs_env%t_RI__AO_AO, t_gocc_2)
482 CALL dbt_create(bs_env%t_RI__AO_AO, t_gvir_2)
483
484 flop = 0_int_8
485
486 ! χ_PQ^R(iτ) = sum_λR1,νR2 M^occ_λR1,νR2,P0 M^vir_νR2,λR1,QR
487 DO i_cell_r = 1, bs_env%nimages_scf_desymm
488
489 DO i_cell_r2 = 1, bs_env%nimages_3c
490
491 IF (bs_env%skip_DR_R_R2_MxM_chi(i_task_delta_r_local, i_cell_r2, i_cell_r)) cycle
492
493 i_cell_delta_r = bs_env%task_Delta_R(i_task_delta_r_local)
494
495 cell_r(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_r)
496 cell_r2(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_r2)
497 cell_dr(1:3) = bs_env%index_to_cell_Delta_R(1:3, i_cell_delta_r)
498
499 ! R_1 = R_2 + ΔR (from ΔR = R_2 - R_1)
500 CALL add_r(cell_r2, cell_dr, bs_env%index_to_cell_3c, cell_r1, &
501 cell_found, bs_env%cell_to_index_3c, i_cell_r1)
502 IF (.NOT. cell_found) cycle
503
504 ! R_1 - R
505 CALL add_r(cell_r1, -cell_r, bs_env%index_to_cell_3c, cell_r1_minus_r, &
506 cell_found, bs_env%cell_to_index_3c, i_cell_r1_minus_r)
507 IF (.NOT. cell_found) cycle
508
509 ! R_2 - R
510 CALL add_r(cell_r2, -cell_r, bs_env%index_to_cell_3c, cell_r2_minus_r, &
511 cell_found, bs_env%cell_to_index_3c, i_cell_r2_minus_r)
512 IF (.NOT. cell_found) cycle
513
514 ! reorder tensors for efficient contraction to χ_PQ^R
515 CALL dbt_copy(t_gocc(i_cell_r1, i_cell_r2), t_gocc_2, order=[1, 3, 2])
516 CALL dbt_copy(t_gvir(i_cell_r2_minus_r, i_cell_r1_minus_r), t_gvir_2)
517
518 ! χ_PQ^R(iτ) = sum_λR1,νR2 M^occ_λR1,νR2,P0 M^vir_νR2,λR1,QR
519 CALL dbt_contract(alpha=bs_env%spin_degeneracy, &
520 tensor_1=t_gocc_2, tensor_2=t_gvir_2, &
521 beta=1.0_dp, tensor_3=t_chi_r(i_cell_r), &
522 contract_1=[2, 3], notcontract_1=[1], map_1=[1], &
523 contract_2=[2, 3], notcontract_2=[1], map_2=[2], &
524 filter_eps=bs_env%eps_filter, move_data=.true., flop=flop_tmp)
525
526 IF (flop_tmp == 0_int_8) bs_env%skip_DR_R_R2_MxM_chi(i_task_delta_r_local, &
527 i_cell_r2, i_cell_r) = .true.
528
529 flop = flop + flop_tmp
530
531 END DO ! i_cell_R2
532
533 END DO ! i_cell_R
534
535 IF (flop == 0_int_8) bs_env%skip_DR_chi(i_task_delta_r_local) = .true.
536
537 ! remove all data from t_Gocc and t_Gvir to safe memory
538 DO i_cell_r1 = 1, bs_env%nimages_3c
539 DO i_cell_r2 = 1, bs_env%nimages_3c
540 CALL dbt_clear(t_gocc(i_cell_r1, i_cell_r2))
541 CALL dbt_clear(t_gvir(i_cell_r1, i_cell_r2))
542 END DO
543 END DO
544
545 CALL dbt_destroy(t_gocc_2)
546 CALL dbt_destroy(t_gvir_2)
547
548 CALL timestop(handle)
549
550 END SUBROUTINE contract_m_occ_vir_to_chi
551
552! **************************************************************************************************
553!> \brief ...
554!> \param bs_env ...
555!> \param qs_env ...
556! **************************************************************************************************
557 SUBROUTINE compute_w_real_space(bs_env, qs_env)
558 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
559 TYPE(qs_environment_type), POINTER :: qs_env
560
561 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_W_real_space'
562
563 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: chi_k_w, eps_k_w, w_k_w
564 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: m_inv, m_inv_v_sqrt, v_sqrt
565 INTEGER :: handle, i_cell_r, i_t, ikp, ikp_local, &
566 j_w, n_ri, nimages_scf_desymm
567 REAL(kind=dp) :: t1, weight_ij
568 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: chi_r, mwm_r, w_r
569
570 CALL timeset(routinen, handle)
571
572 n_ri = bs_env%n_RI
573 nimages_scf_desymm = bs_env%nimages_scf_desymm
574
575 ALLOCATE (chi_k_w(n_ri, n_ri), eps_k_w(n_ri, n_ri), w_k_w(n_ri, n_ri))
576 ALLOCATE (chi_r(n_ri, n_ri, nimages_scf_desymm), w_r(n_ri, n_ri, nimages_scf_desymm), &
577 mwm_r(n_ri, n_ri, nimages_scf_desymm))
578
579 t1 = m_walltime()
580
581 CALL compute_minv_and_vsqrt(bs_env, qs_env, m_inv_v_sqrt, m_inv, v_sqrt)
582
583 IF (bs_env%unit_nr > 0) THEN
584 WRITE (bs_env%unit_nr, '(T2,A,T58,A,F7.1,A)') &
585 'Computed V_PQ(k),', 'Execution time', m_walltime() - t1, ' s'
586 WRITE (bs_env%unit_nr, '(A)') ' '
587 END IF
588
589 t1 = m_walltime()
590
591 DO j_w = 1, bs_env%num_time_freq_points
592
593 ! χ_PQ^R(iτ) -> χ_PQ^R(iω_j) (which is stored in chi_R, single ω_j from j_w loop)
594 chi_r(:, :, :) = 0.0_dp
595 DO i_t = 1, bs_env%num_time_freq_points
596 weight_ij = bs_env%time_frequency_grid%cosine_time_to_frequency(j_w, i_t)
597
598 CALL cp_fm_to_replicated_array(bs_env%fm_chi_R_t(:, i_t), chi_r, weight_ij, add=.true.)
599 END DO
600
601 ikp_local = 0
602 w_r(:, :, :) = 0.0_dp
603 DO ikp = 1, bs_env%nkp_chi_eps_W_orig_plus_extra
604
605 ! trivial parallelization over k-points
606 IF (modulo(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
607
608 ikp_local = ikp_local + 1
609
610 ! 1. χ_PQ^R(iω_j) -> χ_PQ(iω_j,k)
611 CALL rs_to_kp(chi_r, chi_k_w, bs_env%kpoints_scf_desymm%index_to_cell, &
612 bs_env%kpoints_chi_eps_W%xkp(1:3, ikp))
613
614 ! 2. remove negative eigenvalues from χ_PQ(iω,k)
615 CALL local_complex_power(chi_k_w, 1.0_dp, bs_env%eps_eigval_mat_RI)
616
617 ! 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)
618 ! 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)
619 CALL gemm_square(m_inv_v_sqrt(:, :, ikp_local), 'C', chi_k_w, 'N', &
620 m_inv_v_sqrt(:, :, ikp_local), 'N', eps_k_w)
621
622 ! b) ε(iω_j,k_i) = eps_work + I
623 CALL local_add_on_diag(eps_k_w, z_one)
624
625 ! 4. W(iω_j,k_i) = V^0.5(k_i)*(ε^-1(iω_j,k_i)-I)*V^0.5(k_i)
626 ! a) Invert ε(iω_j,k_i) using its Cholesky decomposition
627 CALL local_complex_power(eps_k_w, -1.0_dp, 0.0_dp)
628
629 ! b) ε^-1(iω_j,k_i)-I
630 CALL local_add_on_diag(eps_k_w, -z_one)
631
632 ! c) W(iω_j,k_i) = V^0.5(k_i)*(ε^-1(iω_j,k_i)-I)*V^0.5(k_i)
633 CALL gemm_square(v_sqrt(:, :, ikp_local), 'N', eps_k_w, 'N', &
634 v_sqrt(:, :, ikp_local), 'C', w_k_w)
635
636 ! 5. W(iω,k_i) -> W^R(iω) = sum_k w_k e^(-ikR) W(iω,k) (k-point extrapolation here)
637 CALL add_kp_to_all_rs(w_k_w, w_r, bs_env%kpoints_chi_eps_W, ikp, &
638 index_to_cell_ext=bs_env%kpoints_scf_desymm%index_to_cell)
639
640 END DO ! ikp
641
642 CALL bs_env%para_env%sync()
643 CALL bs_env%para_env%sum(w_r)
644
645 ! 6. W^R(iω) -> W(iω,k) [k-mesh is not extrapolated for stable mult. with M^-1(k) ]
646 ! -> M^-1(k)*W(iω,k)*M^-1(k) =: Ŵ(iω,k) -> Ŵ^R(iω) (stored in MWM_R)
647 CALL mult_w_with_minv(w_r, mwm_r, bs_env, qs_env)
648
649 ! 7. Ŵ^R(iω) -> Ŵ^R(iτ) and to fully distributed fm matrix bs_env%fm_MWM_R_t
650 DO i_t = 1, bs_env%num_time_freq_points
651 weight_ij = bs_env%time_frequency_grid%cosine_frequency_to_time(i_t, j_w)
652 DO i_cell_r = 1, nimages_scf_desymm
653 CALL cp_fm_set_submatrix(bs_env%fm_MWM_R_t(i_cell_r, i_t), mwm_r(:, :, i_cell_r), &
654 alpha=weight_ij, beta=1.0_dp)
655 END DO
656 END DO ! i_t
657
658 END DO ! j_w
659
660 IF (bs_env%unit_nr > 0) THEN
661 WRITE (bs_env%unit_nr, '(T2,A,T60,A,F7.1,A)') &
662 'Computed W_PQ(k,iω) for all k and τ,', 'Execution time', m_walltime() - t1, ' s'
663 WRITE (bs_env%unit_nr, '(A)') ' '
664 END IF
665
666 CALL timestop(handle)
667
668 END SUBROUTINE compute_w_real_space
669
670! **************************************************************************************************
671!> \brief ...
672!> \param bs_env ...
673!> \param qs_env ...
674!> \param M_inv_V_sqrt ...
675!> \param M_inv ...
676!> \param V_sqrt ...
677! **************************************************************************************************
678 SUBROUTINE compute_minv_and_vsqrt(bs_env, qs_env, M_inv_V_sqrt, M_inv, V_sqrt)
679 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
680 TYPE(qs_environment_type), POINTER :: qs_env
681 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: m_inv_v_sqrt, m_inv, v_sqrt
682
683 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_Minv_and_Vsqrt'
684
685 INTEGER :: handle, ikp, ikp_local, n_ri, nkp, &
686 nkp_local, nkp_orig
687 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: m_r
688
689 CALL timeset(routinen, handle)
690
691 nkp = bs_env%nkp_chi_eps_W_orig_plus_extra
692 nkp_orig = bs_env%nkp_chi_eps_W_orig
693 n_ri = bs_env%n_RI
694
695 nkp_local = 0
696 DO ikp = 1, nkp
697 ! trivial parallelization over k-points
698 IF (modulo(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
699 nkp_local = nkp_local + 1
700 END DO
701
702 ALLOCATE (m_inv_v_sqrt(n_ri, n_ri, nkp_local), m_inv(n_ri, n_ri, nkp_local), &
703 v_sqrt(n_ri, n_ri, nkp_local))
704
705 m_inv_v_sqrt(:, :, :) = z_zero
706 m_inv(:, :, :) = z_zero
707 v_sqrt(:, :, :) = z_zero
708
709 ! 1. 2c Coulomb integrals for the first "original" k-point grid
710 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
711 CALL build_2c_coulomb_matrix_kp_dense(v_sqrt, qs_env, bs_env%kpoints_chi_eps_W, &
712 bs_env%size_lattice_sum_V, basis_type="RI_AUX", &
713 ikp_start=1, ikp_end=nkp_orig)
714
715 ! 2. 2c Coulomb integrals for the second "extrapolation" k-point grid
716 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_extra
717 CALL build_2c_coulomb_matrix_kp_dense(v_sqrt, qs_env, bs_env%kpoints_chi_eps_W, &
718 bs_env%size_lattice_sum_V, basis_type="RI_AUX", &
719 ikp_start=nkp_orig + 1, ikp_end=nkp)
720
721 ! now get M^-1(k) and M^-1(k)*V^0.5(k)
722
723 ! compute M^R_PQ = <phi_P,0|V^tr(rc=3Å)|phi_Q,R> for RI metric
724 CALL get_v_tr_r(m_r, bs_env%ri_metric, bs_env%regularization_RI, bs_env, qs_env)
725
726 ikp_local = 0
727 DO ikp = 1, nkp
728
729 ! trivial parallelization
730 IF (modulo(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
731
732 ikp_local = ikp_local + 1
733
734 ! M(k) = sum_R e^ikR M^R
735 CALL rs_to_kp(m_r, m_inv(:, :, ikp_local), &
736 bs_env%kpoints_scf_desymm%index_to_cell, &
737 bs_env%kpoints_chi_eps_W%xkp(1:3, ikp))
738
739 ! invert M_PQ(k)
740 CALL local_complex_power(m_inv(:, :, ikp_local), -1.0_dp, 0.0_dp)
741
742 ! V^0.5(k)
743 CALL local_complex_power(v_sqrt(:, :, ikp_local), 0.5_dp, 0.0_dp)
744
745 ! M^-1(k)*V^0.5(k)
746 CALL gemm_square(m_inv(:, :, ikp_local), 'N', v_sqrt(:, :, ikp_local), 'C', m_inv_v_sqrt(:, :, ikp_local))
747
748 END DO ! ikp
749
750 CALL timestop(handle)
751
752 END SUBROUTINE compute_minv_and_vsqrt
753
754! **************************************************************************************************
755!> \brief ...
756!> \param W_R ...
757!> \param MWM_R ...
758!> \param bs_env ...
759!> \param qs_env ...
760! **************************************************************************************************
761 SUBROUTINE mult_w_with_minv(W_R, MWM_R, bs_env, qs_env)
762 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: w_r, mwm_r
763 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
764 TYPE(qs_environment_type), POINTER :: qs_env
765
766 CHARACTER(LEN=*), PARAMETER :: routinen = 'mult_W_with_Minv'
767
768 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: m_inv, w_k, work
769 INTEGER :: handle, ikp, n_ri
770 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: m_r
771
772 CALL timeset(routinen, handle)
773
774 ! compute M^R again
775 CALL get_v_tr_r(m_r, bs_env%ri_metric, bs_env%regularization_RI, bs_env, qs_env)
776
777 n_ri = bs_env%n_RI
778 ALLOCATE (m_inv(n_ri, n_ri), w_k(n_ri, n_ri), work(n_ri, n_ri))
779 mwm_r(:, :, :) = 0.0_dp
780
781 DO ikp = 1, bs_env%nkp_scf_desymm
782
783 ! trivial parallelization
784 IF (modulo(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
785
786 ! M(k) = sum_R e^ikR M^R
787 CALL rs_to_kp(m_r, m_inv, &
788 bs_env%kpoints_scf_desymm%index_to_cell, &
789 bs_env%kpoints_scf_desymm%xkp(1:3, ikp))
790
791 ! invert M_PQ(k)
792 CALL local_complex_power(m_inv, -1.0_dp, 0.0_dp)
793
794 ! W(k) = sum_R e^ikR W^R [only R in the supercell that is determined by the SCF k-mesh]
795 CALL rs_to_kp(w_r, w_k, &
796 bs_env%kpoints_scf_desymm%index_to_cell, &
797 bs_env%kpoints_scf_desymm%xkp(1:3, ikp))
798
799 ! Ŵ(k) = M^-1(k)*W^trunc(k)*M^-1(k)
800 CALL gemm_square(m_inv, 'N', w_k, 'N', m_inv, 'N', work)
801 w_k(:, :) = work(:, :)
802
803 ! Ŵ^R = sum_k w_k e^(-ikR) Ŵ^(k)
804 CALL add_kp_to_all_rs(w_k, mwm_r, bs_env%kpoints_scf_desymm, ikp)
805
806 END DO ! ikp
807
808 CALL bs_env%para_env%sync()
809 CALL bs_env%para_env%sum(mwm_r)
810
811 CALL timestop(handle)
812
813 END SUBROUTINE mult_w_with_minv
814
815! **************************************************************************************************
816!> \brief ...
817!> \param bs_env ...
818!> \param qs_env ...
819! **************************************************************************************************
820 SUBROUTINE compute_sigma_x(bs_env, qs_env)
821 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
822 TYPE(qs_environment_type), POINTER :: qs_env
823
824 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_Sigma_x'
825
826 INTEGER :: handle, i_task_delta_r_local, ispin
827 REAL(kind=dp) :: t1
828 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: d_s, mi_vtr_mi_r, sigma_x_r
829 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_v
830
831 CALL timeset(routinen, handle)
832
833 CALL dbt_create_2c_r(mi_vtr_mi_r, bs_env%t_W, bs_env%nimages_scf_desymm)
834 CALL dbt_create_2c_r(d_s, bs_env%t_G, bs_env%nimages_scf_desymm)
835 CALL dbt_create_2c_r(sigma_x_r, bs_env%t_G, bs_env%nimages_scf_desymm)
836 CALL dbt_create_3c_r1_r2(t_v, bs_env%t_RI_AO__AO, bs_env%nimages_3c, bs_env%nimages_3c)
837
838 t1 = m_walltime()
839
840 ! V^tr_PQ^R = <phi_P,0|V^tr|phi_Q,R>, V^tr(k) = sum_R e^ikR V^tr^R
841 ! M(k) = sum_R e^ikR M^R, M(k) -> M^-1(k) -> Ṽ^tr(k) = M^-1(k) * V^tr(k) * M^-1(k)
842 ! -> Ṽ^tr_PQ^R = sum_k w_k e^-ikR Ṽ^tr_PQ(k)
843 CALL get_minv_vtr_minv_r(mi_vtr_mi_r, bs_env, qs_env)
844
845 ! Σ^x_λσ^R = sum_PR1νS1 [ sum_µS2 (λ0 µS1-S2 | PR1 ) D_µν^S2 ]
846 ! [ sum_QR2 (σR νS1 | QR1-R2) Ṽ^tr_PQ^R2 ]
847 DO ispin = 1, bs_env%n_spin
848
849 ! compute D^S(iτ) for cell S from D_µν(k) = sum_n^occ C^*_µn(k) C_νn(k):
850 ! trafo k-point k -> cell S: D_µν^S = sum_k w_k D_µν(k) e^(ikS)
851 CALL g_occ_vir(bs_env, 0.0_dp, d_s, ispin, occ=.true., vir=.false.)
852
853 ! loop over ΔR = S_1 - R_1 which are local in the tensor subgroup
854 DO i_task_delta_r_local = 1, bs_env%n_tasks_Delta_R_local
855
856 ! M^V_σ0,νS1,PR1 = sum_QR2 ( σ0 νS1 | QR1-R2 ) Ṽ^tr_QP^R2 for i_task_local
857 CALL contract_w(t_v, mi_vtr_mi_r, bs_env, i_task_delta_r_local)
858
859 ! M^D_λ0,νS1,PR1 = sum_µS2 (λ0 µS1-S2 | PR1) D_µν^S2
860 ! Σ^x_λσ^R = sum_PR1νS1 M^D_λ0,νS1,PR1 * M^V_σR,νS1,PR1 for i_task_local, where
861 ! M^V_σR,νS1,PR1 = M^V_σ0,νS1-R,PR1-R
862 CALL contract_to_sigma(sigma_x_r, t_v, d_s, i_task_delta_r_local, bs_env, &
863 occ=.true., vir=.false., clear_t_w=.true., fill_skip=.false.)
864
865 END DO ! i_cell_Delta_R_local
866
867 CALL bs_env%para_env%sync()
868
869 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, &
870 bs_env%para_env)
871
872 END DO ! ispin
873
874 IF (bs_env%unit_nr > 0) THEN
875 WRITE (bs_env%unit_nr, '(T2,A,T58,A,F7.1,A)') &
876 'Computed Σ^x,', ' Execution time', m_walltime() - t1, ' s'
877 WRITE (bs_env%unit_nr, '(A)') ' '
878 END IF
879
880 CALL destroy_t_1d(mi_vtr_mi_r)
881 CALL destroy_t_1d(d_s)
882 CALL destroy_t_1d(sigma_x_r)
883 CALL destroy_t_2d(t_v)
884
885 CALL timestop(handle)
886
887 END SUBROUTINE compute_sigma_x
888
889! **************************************************************************************************
890!> \brief ...
891!> \param bs_env ...
892! **************************************************************************************************
893 SUBROUTINE compute_sigma_c(bs_env)
894 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
895
896 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_Sigma_c'
897
898 INTEGER :: handle, i_t, i_task_delta_r_local, ispin
899 REAL(kind=dp) :: t1, tau
900 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: gocc_s, gvir_s, sigma_c_r_neg_tau, &
901 sigma_c_r_pos_tau, w_r
902 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_w
903
904 CALL timeset(routinen, handle)
905
906 CALL dbt_create_2c_r(gocc_s, bs_env%t_G, bs_env%nimages_scf_desymm)
907 CALL dbt_create_2c_r(gvir_s, bs_env%t_G, bs_env%nimages_scf_desymm)
908 CALL dbt_create_2c_r(w_r, bs_env%t_W, bs_env%nimages_scf_desymm)
909 CALL dbt_create_3c_r1_r2(t_w, bs_env%t_RI_AO__AO, bs_env%nimages_3c, bs_env%nimages_3c)
910 CALL dbt_create_2c_r(sigma_c_r_neg_tau, bs_env%t_G, bs_env%nimages_scf_desymm)
911 CALL dbt_create_2c_r(sigma_c_r_pos_tau, bs_env%t_G, bs_env%nimages_scf_desymm)
912
913 ! Σ^c_λσ^R(iτ) = sum_PR1νS1 [ sum_µS2 (λ0 µS1-S2 | PR1 ) G^occ/vir_µν^S2(i|τ|) ]
914 ! [ sum_QR2 (σR νS1 | QR1-R2) Ŵ_PQ^R2(iτ) ]
915 DO i_t = 1, bs_env%num_time_freq_points
916
917 DO ispin = 1, bs_env%n_spin
918
919 t1 = m_walltime()
920
921 tau = bs_env%time_frequency_grid%imaginary_time(i_t)
922
923 ! G^occ_µλ(i|τ|,k) = sum_n^occ C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k), τ < 0
924 ! G^vir_µλ(i|τ|,k) = sum_n^vir C_µn(k)^* e^(-|(ϵ_nk-ϵ_F)τ|) C_λn(k), τ > 0
925 ! k-point k -> cell S: G^occ/vir_µλ^S(i|τ|) = sum_k w_k G^occ/vir_µλ(i|τ|,k) e^(ikS)
926 CALL g_occ_vir(bs_env, tau, gocc_s, ispin, occ=.true., vir=.false.)
927 CALL g_occ_vir(bs_env, tau, gvir_s, ispin, occ=.false., vir=.true.)
928
929 ! write data of W^R_PQ(iτ) to W_R 2-index tensor
930 CALL fm_mwm_r_t_to_local_tensor_w_r(bs_env%fm_MWM_R_t(:, i_t), w_r, bs_env)
931
932 ! loop over ΔR = S_1 - R_1 which are local in the tensor subgroup
933 DO i_task_delta_r_local = 1, bs_env%n_tasks_Delta_R_local
934
935 IF (bs_env%skip_DR_Sigma(i_task_delta_r_local)) cycle
936
937 ! for i_task_local (i.e. fixed ΔR = S_1 - R_1) and for all τ (W(iτ) = W(-iτ)):
938 ! M^W_σ0,νS1,PR1 = sum_QR2 ( σ0 νS1 | QR1-R2 ) W(iτ)_QP^R2
939 CALL contract_w(t_w, w_r, bs_env, i_task_delta_r_local)
940
941 ! for τ < 0 and for i_task_local (i.e. fixed ΔR = S_1 - R_1):
942 ! M^G_λ0,νS1,PR1 = sum_µS2 (λ0 µS1-S2 | PR1) G^occ(i|τ|)_µν^S2
943 ! Σ^c_λσ^R(iτ) = sum_PR1νS1 M^G_λ0,νS1,PR1 * M^W_σR,νS1,PR1
944 ! where M^W_σR,νS1,PR1 = M^W_σ0,νS1-R,PR1-R
945 CALL contract_to_sigma(sigma_c_r_neg_tau, t_w, gocc_s, i_task_delta_r_local, bs_env, &
946 occ=.true., vir=.false., clear_t_w=.false., fill_skip=.false.)
947
948 ! for τ > 0: same as for τ < 0, but G^occ -> G^vir
949 CALL contract_to_sigma(sigma_c_r_pos_tau, t_w, gvir_s, i_task_delta_r_local, bs_env, &
950 occ=.false., vir=.true., clear_t_w=.true., fill_skip=.true.)
951
952 END DO ! i_cell_Delta_R_local
953
954 CALL bs_env%para_env%sync()
955
956 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, &
957 bs_env%mat_ao_ao_tensor, bs_env%para_env)
958
959 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, &
960 bs_env%mat_ao_ao_tensor, bs_env%para_env)
961
962 IF (bs_env%unit_nr > 0) THEN
963 WRITE (bs_env%unit_nr, '(T2,A,I10,A,I3,A,F7.1,A)') &
964 'Computed Σ^c(iτ) for time point ', i_t, ' /', bs_env%num_time_freq_points, &
965 ', Execution time', m_walltime() - t1, ' s'
966 END IF
967
968 END DO ! ispin
969
970 END DO ! i_t
971
972 CALL destroy_t_1d(gocc_s)
973 CALL destroy_t_1d(gvir_s)
974 CALL destroy_t_1d(w_r)
975 CALL destroy_t_1d(sigma_c_r_neg_tau)
976 CALL destroy_t_1d(sigma_c_r_pos_tau)
977 CALL destroy_t_2d(t_w)
978
979 CALL timestop(handle)
980
981 END SUBROUTINE compute_sigma_c
982
983! **************************************************************************************************
984!> \brief ...
985!> \param Mi_Vtr_Mi_R ...
986!> \param bs_env ...
987!> \param qs_env ...
988! **************************************************************************************************
989 SUBROUTINE get_minv_vtr_minv_r(Mi_Vtr_Mi_R, bs_env, qs_env)
990 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: mi_vtr_mi_r
991 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
992 TYPE(qs_environment_type), POINTER :: qs_env
993
994 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_Minv_Vtr_Minv_R'
995
996 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: m_kp, mi_vtr_mi_kp, v_tr_kp
997 INTEGER :: handle, i_cell_r, ikp, n_ri, &
998 nimages_scf, nkp_scf
999 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: m_r, mi_vtr_mi_r_arr, v_tr_r
1000
1001 CALL timeset(routinen, handle)
1002
1003 nimages_scf = bs_env%nimages_scf_desymm
1004 nkp_scf = bs_env%kpoints_scf_desymm%nkp
1005 n_ri = bs_env%n_RI
1006
1007 CALL get_v_tr_r(v_tr_r, bs_env%trunc_coulomb, 0.0_dp, bs_env, qs_env)
1008 CALL get_v_tr_r(m_r, bs_env%ri_metric, bs_env%regularization_RI, bs_env, qs_env)
1009
1010 ALLOCATE (v_tr_kp(n_ri, n_ri), m_kp(n_ri, n_ri), &
1011 mi_vtr_mi_kp(n_ri, n_ri), mi_vtr_mi_r_arr(n_ri, n_ri, nimages_scf))
1012 mi_vtr_mi_r_arr(:, :, :) = 0.0_dp
1013
1014 DO ikp = 1, nkp_scf
1015 ! trivial parallelization
1016 IF (modulo(ikp, bs_env%para_env%num_pe) /= bs_env%para_env%mepos) cycle
1017 ! V_tr(k) = sum_R e^ikR V_tr^R
1018 CALL rs_to_kp(v_tr_r, v_tr_kp, bs_env%kpoints_scf_desymm%index_to_cell, &
1019 bs_env%kpoints_scf_desymm%xkp(1:3, ikp))
1020 ! M(k) = sum_R e^ikR M^R
1021 CALL rs_to_kp(m_r, m_kp, bs_env%kpoints_scf_desymm%index_to_cell, &
1022 bs_env%kpoints_scf_desymm%xkp(1:3, ikp))
1023 ! M(k) -> M^-1(k)
1024 CALL local_complex_power(m_kp, -1.0_dp, 0.0_dp)
1025 ! Ṽ(k) = M^-1(k) * V_tr(k) * M^-1(k)
1026 CALL gemm_square(m_kp, 'N', v_tr_kp, 'N', m_kp, 'N', mi_vtr_mi_kp)
1027 ! Ṽ^R = sum_k w_k e^-ikR Ṽ(k)
1028 CALL add_kp_to_all_rs(mi_vtr_mi_kp, mi_vtr_mi_r_arr, bs_env%kpoints_scf_desymm, ikp)
1029 END DO
1030 CALL bs_env%para_env%sync()
1031 CALL bs_env%para_env%sum(mi_vtr_mi_r_arr)
1032
1033 ! use bs_env%fm_chi_R_t for temporary storage
1034 DO i_cell_r = 1, nimages_scf
1035 CALL cp_fm_set_submatrix(bs_env%fm_chi_R_t(i_cell_r, 1), mi_vtr_mi_r_arr(:, :, i_cell_r))
1036 END DO
1037
1038 ! communicate Mi_Vtr_Mi_R to tensor format; full replication in tensor group
1039 DO i_cell_r = 1, nimages_scf
1040 CALL cp_fm_to_dbt(bs_env%fm_chi_R_t(i_cell_r, 1), bs_env%mat_RI_RI%matrix, &
1041 bs_env%mat_RI_RI_tensor%matrix, mi_vtr_mi_r(i_cell_r), bs_env%para_env, &
1042 bs_env%para_env_tensor%num_pe, bs_env%eps_filter)
1043 END DO
1044
1045 CALL timestop(handle)
1046
1047 END SUBROUTINE get_minv_vtr_minv_r
1048
1049! **************************************************************************************************
1050!> \brief ...
1051!> \param t_1d ...
1052! **************************************************************************************************
1053 SUBROUTINE destroy_t_1d(t_1d)
1054 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: t_1d
1055
1056 CHARACTER(LEN=*), PARAMETER :: routinen = 'destroy_t_1d'
1057
1058 INTEGER :: handle, i
1059
1060 CALL timeset(routinen, handle)
1061
1062 DO i = 1, SIZE(t_1d)
1063 CALL dbt_destroy(t_1d(i))
1064 END DO
1065 DEALLOCATE (t_1d)
1066
1067 CALL timestop(handle)
1068
1069 END SUBROUTINE destroy_t_1d
1070
1071! **************************************************************************************************
1072!> \brief ...
1073!> \param t_2d ...
1074! **************************************************************************************************
1075 SUBROUTINE destroy_t_2d(t_2d)
1076 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_2d
1077
1078 CHARACTER(LEN=*), PARAMETER :: routinen = 'destroy_t_2d'
1079
1080 INTEGER :: handle, i, j
1081
1082 CALL timeset(routinen, handle)
1083
1084 DO i = 1, SIZE(t_2d, 1)
1085 DO j = 1, SIZE(t_2d, 2)
1086 CALL dbt_destroy(t_2d(i, j))
1087 END DO
1088 END DO
1089 DEALLOCATE (t_2d)
1090
1091 CALL timestop(handle)
1092
1093 END SUBROUTINE destroy_t_2d
1094
1095! **************************************************************************************************
1096!> \brief ...
1097!> \param t_W ...
1098!> \param W_R ...
1099!> \param bs_env ...
1100!> \param i_task_Delta_R_local ...
1101! **************************************************************************************************
1102 SUBROUTINE contract_w(t_W, W_R, bs_env, i_task_Delta_R_local)
1103 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_w
1104 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: w_r
1105 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1106 INTEGER :: i_task_delta_r_local
1107
1108 CHARACTER(LEN=*), PARAMETER :: routinen = 'contract_W'
1109
1110 INTEGER :: handle, i_cell_delta_r, i_cell_r1, &
1111 i_cell_r2, i_cell_r2_m_r1, i_cell_s1, &
1112 i_cell_s1_m_r1_p_r2
1113 INTEGER, DIMENSION(3) :: cell_dr, cell_r1, cell_r2, cell_r2_m_r1, &
1114 cell_s1, cell_s1_m_r2_p_r1
1115 LOGICAL :: cell_found
1116 TYPE(dbt_type) :: t_3c_int, t_w_tmp
1117
1118 CALL timeset(routinen, handle)
1119
1120 CALL dbt_create(bs_env%t_RI__AO_AO, t_w_tmp)
1121 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_int)
1122
1123 i_cell_delta_r = bs_env%task_Delta_R(i_task_delta_r_local)
1124
1125 DO i_cell_r1 = 1, bs_env%nimages_3c
1126
1127 cell_r1(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_r1)
1128 cell_dr(1:3) = bs_env%index_to_cell_Delta_R(1:3, i_cell_delta_r)
1129
1130 ! S_1 = R_1 + ΔR (from ΔR = S_1 - R_1)
1131 CALL add_r(cell_r1, cell_dr, bs_env%index_to_cell_3c, cell_s1, &
1132 cell_found, bs_env%cell_to_index_3c, i_cell_s1)
1133 IF (.NOT. cell_found) cycle
1134
1135 DO i_cell_r2 = 1, bs_env%nimages_scf_desymm
1136
1137 cell_r2(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_r2)
1138
1139 ! R_2 - R_1
1140 CALL add_r(cell_r2, -cell_r1, bs_env%index_to_cell_3c, cell_r2_m_r1, &
1141 cell_found, bs_env%cell_to_index_3c, i_cell_r2_m_r1)
1142 IF (.NOT. cell_found) cycle
1143
1144 ! S_1 - R_1 + R_2
1145 CALL add_r(cell_s1, cell_r2_m_r1, bs_env%index_to_cell_3c, cell_s1_m_r2_p_r1, &
1146 cell_found, bs_env%cell_to_index_3c, i_cell_s1_m_r1_p_r2)
1147 IF (.NOT. cell_found) cycle
1148
1149 CALL get_t_3c_int(t_3c_int, bs_env, i_cell_s1_m_r1_p_r2, i_cell_r2_m_r1)
1150
1151 ! M^W_σ0,νS1,PR1 = sum_QR2 ( σ0 νS1 | QR1-R2 ) W_QP^R2
1152 ! = sum_QR2 ( σR2-R1 νS1-R1+R2 | Q0 ) W_QP^R2
1153 ! for ΔR = S_1 - R_1
1154 CALL dbt_contract(alpha=1.0_dp, &
1155 tensor_1=w_r(i_cell_r2), &
1156 tensor_2=t_3c_int, &
1157 beta=0.0_dp, &
1158 tensor_3=t_w_tmp, &
1159 contract_1=[1], notcontract_1=[2], map_1=[1], &
1160 contract_2=[1], notcontract_2=[2, 3], map_2=[2, 3], &
1161 filter_eps=bs_env%eps_filter)
1162
1163 ! reorder tensor
1164 CALL dbt_copy(t_w_tmp, t_w(i_cell_s1, i_cell_r1), order=[1, 2, 3], &
1165 move_data=.true., summation=.true.)
1166
1167 END DO ! i_cell_R2
1168
1169 END DO ! i_cell_R1
1170
1171 CALL dbt_destroy(t_w_tmp)
1172 CALL dbt_destroy(t_3c_int)
1173
1174 CALL timestop(handle)
1175
1176 END SUBROUTINE contract_w
1177
1178! **************************************************************************************************
1179!> \brief ...
1180!> \param Sigma_R ...
1181!> \param t_W ...
1182!> \param G_S ...
1183!> \param i_task_Delta_R_local ...
1184!> \param bs_env ...
1185!> \param occ ...
1186!> \param vir ...
1187!> \param clear_t_W ...
1188!> \param fill_skip ...
1189! **************************************************************************************************
1190 SUBROUTINE contract_to_sigma(Sigma_R, t_W, G_S, i_task_Delta_R_local, bs_env, occ, vir, &
1191 clear_t_W, fill_skip)
1192 TYPE(dbt_type), DIMENSION(:) :: sigma_r
1193 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_w
1194 TYPE(dbt_type), DIMENSION(:) :: g_s
1195 INTEGER :: i_task_delta_r_local
1196 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1197 LOGICAL :: occ, vir, clear_t_w, fill_skip
1198
1199 CHARACTER(LEN=*), PARAMETER :: routinen = 'contract_to_Sigma'
1200
1201 INTEGER :: handle, handle2, i_cell_delta_r, i_cell_m_r1, i_cell_r, i_cell_r1, &
1202 i_cell_r1_minus_r, i_cell_s1, i_cell_s1_minus_r, i_cell_s1_p_s2_m_r1, i_cell_s2
1203 INTEGER(KIND=int_8) :: flop, flop_tmp
1204 INTEGER, DIMENSION(3) :: cell_dr, cell_m_r1, cell_r, cell_r1, &
1205 cell_r1_minus_r, cell_s1, &
1206 cell_s1_minus_r, cell_s1_p_s2_m_r1, &
1207 cell_s2
1208 LOGICAL :: cell_found
1209 REAL(kind=dp) :: sign_sigma
1210 TYPE(dbt_type) :: t_3c_int, t_g, t_g_2
1211
1212 CALL timeset(routinen, handle)
1213
1214 cpassert(occ .EQV. (.NOT. vir))
1215 IF (occ) sign_sigma = -1.0_dp
1216 IF (vir) sign_sigma = 1.0_dp
1217
1218 CALL dbt_create(bs_env%t_RI_AO__AO, t_g)
1219 CALL dbt_create(bs_env%t_RI_AO__AO, t_g_2)
1220 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_int)
1221
1222 i_cell_delta_r = bs_env%task_Delta_R(i_task_delta_r_local)
1223
1224 flop = 0_int_8
1225
1226 DO i_cell_r1 = 1, bs_env%nimages_3c
1227
1228 cell_r1(1:3) = bs_env%index_to_cell_3c(1:3, i_cell_r1)
1229 cell_dr(1:3) = bs_env%index_to_cell_Delta_R(1:3, i_cell_delta_r)
1230
1231 ! S_1 = R_1 + ΔR (from ΔR = S_1 - R_1)
1232 CALL add_r(cell_r1, cell_dr, bs_env%index_to_cell_3c, cell_s1, cell_found, &
1233 bs_env%cell_to_index_3c, i_cell_s1)
1234 IF (.NOT. cell_found) cycle
1235
1236 DO i_cell_s2 = 1, bs_env%nimages_scf_desymm
1237
1238 IF (bs_env%skip_DR_R1_S2_Gx3c_Sigma(i_task_delta_r_local, i_cell_r1, i_cell_s2)) cycle
1239
1240 cell_s2(1:3) = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_s2)
1241 cell_m_r1(1:3) = -cell_r1(1:3)
1242 cell_s1_p_s2_m_r1(1:3) = cell_s1(1:3) + cell_s2(1:3) - cell_r1(1:3)
1243
1244 CALL is_cell_in_index_to_cell(cell_m_r1, bs_env%index_to_cell_3c, cell_found)
1245 IF (.NOT. cell_found) cycle
1246
1247 CALL is_cell_in_index_to_cell(cell_s1_p_s2_m_r1, bs_env%index_to_cell_3c, cell_found)
1248 IF (.NOT. cell_found) cycle
1249
1250 i_cell_m_r1 = bs_env%cell_to_index_3c(cell_m_r1(1), cell_m_r1(2), cell_m_r1(3))
1251 i_cell_s1_p_s2_m_r1 = bs_env%cell_to_index_3c(cell_s1_p_s2_m_r1(1), &
1252 cell_s1_p_s2_m_r1(2), &
1253 cell_s1_p_s2_m_r1(3))
1254
1255 CALL timeset(routinen//"_3c_x_G", handle2)
1256
1257 CALL get_t_3c_int(t_3c_int, bs_env, i_cell_m_r1, i_cell_s1_p_s2_m_r1)
1258
1259 ! M_λ0,νS1,PR1 = sum_µS2 ( λ0 µS1-S2 | PR1 ) G^occ/vir_µν^S2(i|τ|)
1260 ! = sum_µS2 ( λ-R1 µS1-S2-R1 | P0 ) G^occ/vir_µν^S2(i|τ|)
1261 ! for ΔR = S_1 - R_1
1262 CALL dbt_contract(alpha=1.0_dp, &
1263 tensor_1=g_s(i_cell_s2), &
1264 tensor_2=t_3c_int, &
1265 beta=1.0_dp, &
1266 tensor_3=t_g, &
1267 contract_1=[2], notcontract_1=[1], map_1=[3], &
1268 contract_2=[3], notcontract_2=[1, 2], map_2=[1, 2], &
1269 filter_eps=bs_env%eps_filter, flop=flop_tmp)
1270
1271 IF (flop_tmp == 0_int_8 .AND. fill_skip) THEN
1272 bs_env%skip_DR_R1_S2_Gx3c_Sigma(i_task_delta_r_local, i_cell_r1, i_cell_s2) = .true.
1273 END IF
1274
1275 CALL timestop(handle2)
1276
1277 END DO ! i_cell_S2
1278
1279 CALL dbt_copy(t_g, t_g_2, order=[1, 3, 2], move_data=.true.)
1280
1281 CALL timeset(routinen//"_contract", handle2)
1282
1283 DO i_cell_r = 1, bs_env%nimages_scf_desymm
1284
1285 IF (bs_env%skip_DR_R1_R_MxM_Sigma(i_task_delta_r_local, i_cell_r1, i_cell_r)) cycle
1286
1287 cell_r = bs_env%kpoints_scf_desymm%index_to_cell(1:3, i_cell_r)
1288
1289 ! R_1 - R
1290 CALL add_r(cell_r1, -cell_r, bs_env%index_to_cell_3c, cell_r1_minus_r, &
1291 cell_found, bs_env%cell_to_index_3c, i_cell_r1_minus_r)
1292 IF (.NOT. cell_found) cycle
1293
1294 ! S_1 - R
1295 CALL add_r(cell_s1, -cell_r, bs_env%index_to_cell_3c, cell_s1_minus_r, &
1296 cell_found, bs_env%cell_to_index_3c, i_cell_s1_minus_r)
1297 IF (.NOT. cell_found) cycle
1298
1299 ! Σ_λσ^R = sum_PR1νS1 M^G_λ0,νS1,PR1 M^W_σR,νS1,PR1, where
1300 ! M^G_λ0,νS1,PR1 = sum_µS2 (λ0 µS1-S2 | PR1) G_µν^S2
1301 ! M^W_σR,νS1,PR1 = sum_QR2 (σR νS1 | QR1-R2) W_PQ^R2 = M^W_σ0,νS1-R,PR1-R
1302 CALL dbt_contract(alpha=sign_sigma, &
1303 tensor_1=t_g_2, &
1304 tensor_2=t_w(i_cell_s1_minus_r, i_cell_r1_minus_r), &
1305 beta=1.0_dp, &
1306 tensor_3=sigma_r(i_cell_r), &
1307 contract_1=[1, 2], notcontract_1=[3], map_1=[1], &
1308 contract_2=[1, 2], notcontract_2=[3], map_2=[2], &
1309 filter_eps=bs_env%eps_filter, flop=flop_tmp)
1310
1311 flop = flop + flop_tmp
1312
1313 IF (flop_tmp == 0_int_8 .AND. fill_skip) THEN
1314 bs_env%skip_DR_R1_R_MxM_Sigma(i_task_delta_r_local, i_cell_r1, i_cell_r) = .true.
1315 END IF
1316
1317 END DO ! i_cell_R
1318
1319 CALL dbt_clear(t_g_2)
1320
1321 CALL timestop(handle2)
1322
1323 END DO ! i_cell_R1
1324
1325 IF (vir .AND. flop == 0_int_8) bs_env%skip_DR_Sigma(i_task_delta_r_local) = .true.
1326
1327 ! release memory
1328 IF (clear_t_w) THEN
1329 DO i_cell_s1 = 1, bs_env%nimages_3c
1330 DO i_cell_r1 = 1, bs_env%nimages_3c
1331 CALL dbt_clear(t_w(i_cell_s1, i_cell_r1))
1332 END DO
1333 END DO
1334 END IF
1335
1336 CALL dbt_destroy(t_g)
1337 CALL dbt_destroy(t_g_2)
1338 CALL dbt_destroy(t_3c_int)
1339
1340 CALL timestop(handle)
1341
1342 END SUBROUTINE contract_to_sigma
1343
1344! **************************************************************************************************
1345!> \brief ...
1346!> \param fm_W_R ...
1347!> \param W_R ...
1348!> \param bs_env ...
1349! **************************************************************************************************
1350 SUBROUTINE fm_mwm_r_t_to_local_tensor_w_r(fm_W_R, W_R, bs_env)
1351 TYPE(cp_fm_type), DIMENSION(:) :: fm_w_r
1352 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: w_r
1353 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1354
1355 CHARACTER(LEN=*), PARAMETER :: routinen = 'fm_MWM_R_t_to_local_tensor_W_R'
1356
1357 INTEGER :: handle, i_cell_r
1358
1359 CALL timeset(routinen, handle)
1360
1361 ! communicate fm_W_R to tensor W_R; full replication in tensor group
1362 DO i_cell_r = 1, bs_env%nimages_scf_desymm
1363 CALL cp_fm_to_dbt(fm_w_r(i_cell_r), bs_env%mat_RI_RI%matrix, bs_env%mat_RI_RI_tensor%matrix, &
1364 w_r(i_cell_r), bs_env%para_env, bs_env%para_env_tensor%num_pe, &
1365 bs_env%eps_filter)
1366 END DO
1367
1368 CALL timestop(handle)
1369
1370 END SUBROUTINE fm_mwm_r_t_to_local_tensor_w_r
1371
1372! **************************************************************************************************
1373!> \brief ...
1374!> \param bs_env ...
1375! **************************************************************************************************
1376 SUBROUTINE compute_qp_energies(bs_env)
1377 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1378
1379 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_QP_energies'
1380
1381 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: sigma_c_ikp_n_freq
1382 INTEGER :: handle, ikp, ispin, j_t
1383 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: sigma_x_ikp_n
1384 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: sigma_c_ikp_n_time
1385 TYPE(cp_cfm_type) :: cfm_mo_coeff
1386
1387 CALL timeset(routinen, handle)
1388
1389 CALL cp_cfm_create(cfm_mo_coeff, bs_env%fm_s_Gamma%matrix_struct)
1390 ALLOCATE (sigma_x_ikp_n(bs_env%n_ao))
1391 ALLOCATE (sigma_c_ikp_n_time(bs_env%n_ao, bs_env%num_time_freq_points, 2))
1392 ALLOCATE (sigma_c_ikp_n_freq(bs_env%n_ao, bs_env%num_freq_points_fit))
1393
1394 DO ispin = 1, bs_env%n_spin
1395
1396 DO ikp = 1, bs_env%nkp_bs_and_DOS
1397
1398 ! 1. get C_µn(k)
1399 CALL cp_cfm_to_cfm(bs_env%cfm_mo_coeff_kp(ikp, ispin), cfm_mo_coeff)
1400
1401 ! 2. Σ^x_µν(k) = sum_R Σ^x_µν^R e^ikR
1402 ! Σ^x_nn(k) = sum_µν C^*_µn(k) Σ^x_µν(k) C_νn(k)
1403 CALL trafo_to_k_and_nn(bs_env%fm_Sigma_x_R, sigma_x_ikp_n, cfm_mo_coeff, bs_env, ikp)
1404
1405 ! 3. Σ^c_µν(k,+/-i|τ_j|) = sum_R Σ^c_µν^R(+/-i|τ_j|) e^ikR
1406 ! Σ^c_nn(k,+/-i|τ_j|) = sum_µν C^*_µn(k) Σ^c_µν(k,+/-i|τ_j|) C_νn(k)
1407 DO j_t = 1, bs_env%num_time_freq_points
1408 CALL trafo_to_k_and_nn(bs_env%fm_Sigma_c_R_pos_tau(:, j_t, ispin), &
1409 sigma_c_ikp_n_time(:, j_t, positive_time), cfm_mo_coeff, bs_env, ikp)
1410 CALL trafo_to_k_and_nn(bs_env%fm_Sigma_c_R_neg_tau(:, j_t, ispin), &
1411 sigma_c_ikp_n_time(:, j_t, negative_time), cfm_mo_coeff, bs_env, ikp)
1412 END DO
1413
1414 ! 4. Σ^c_nn(k_i,iω) = ∫ from -∞ to ∞ dτ e^-iωτ Σ^c_nn(k_i,iτ)
1415 CALL transform_time_to_frequency(bs_env%time_frequency_grid_sigma, sigma_c_ikp_n_time, sigma_c_ikp_n_freq)
1416 sigma_c_ikp_n_freq(1:bs_env%n_occ(ispin), :) = conjg(sigma_c_ikp_n_freq(1:bs_env%n_occ(ispin), :))
1417
1418 ! 5. Analytic continuation Σ^c_nn(k_i,iω) -> Σ^c_nn(k_i,ϵ) and
1419 ! ϵ_nk_i^GW = ϵ_nk_i^DFT + Σ^c_nn(k_i,ϵ) + Σ^x_nn(k_i) - v^xc_nn(k_i)
1420 CALL analyt_conti_and_print(bs_env, sigma_c_ikp_n_freq, sigma_x_ikp_n, &
1421 bs_env%v_xc_n(:, ikp, ispin), &
1422 bs_env%eigenval_scf(:, ikp, ispin), ikp, ispin)
1423
1424 END DO ! ikp
1425
1426 END DO ! ispin
1427
1428 CALL get_all_vbm_cbm_bandgaps(bs_env)
1429
1430 CALL cp_cfm_release(cfm_mo_coeff)
1431
1432 CALL timestop(handle)
1433
1434 END SUBROUTINE compute_qp_energies
1435
1436! **************************************************************************************************
1437!> \brief ...
1438!> \param fm_rs ...
1439!> \param array_ikp_n ...
1440!> \param cfm_mo_coeff ...
1441!> \param bs_env ...
1442!> \param ikp ...
1443! **************************************************************************************************
1444 SUBROUTINE trafo_to_k_and_nn(fm_rs, array_ikp_n, cfm_mo_coeff, bs_env, ikp)
1445 TYPE(cp_fm_type), DIMENSION(:) :: fm_rs
1446 REAL(kind=dp), DIMENSION(:) :: array_ikp_n
1447 TYPE(cp_cfm_type) :: cfm_mo_coeff
1448 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
1449 INTEGER :: ikp
1450
1451 CHARACTER(LEN=*), PARAMETER :: routinen = 'trafo_to_k_and_nn'
1452
1453 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:) :: cdiag
1454 INTEGER :: handle
1455 TYPE(cp_cfm_type) :: cfm_ikp
1456
1457 CALL timeset(routinen, handle)
1458
1459 CALL cp_cfm_create(cfm_ikp, cfm_mo_coeff%matrix_struct)
1460
1461 ! Σ_µν(k_i) = sum_R e^ik_iR Σ_µν^R
1462 CALL fm_rs_to_kp(cfm_ikp, fm_rs, bs_env%kpoints_DOS, ikp)
1463
1464 ! Σ_nm(k_i) = sum_µν C^*_µn(k_i) Σ_µν(k_i) C_νn(k_i)
1465 CALL cfm_contract_aba(cfm_mo_coeff, cfm_ikp)
1466
1467 ! get Σ_nn(k_i) which is a real quantity as Σ^x and Σ^c(iτ) is Hermitian
1468 ALLOCATE (cdiag(SIZE(array_ikp_n)))
1469 CALL cp_cfm_get_diag(cfm_ikp, cdiag)
1470 array_ikp_n = real(cdiag, kind=dp)
1471
1472 DEALLOCATE (cdiag)
1473 CALL cp_cfm_release(cfm_ikp)
1474
1475 CALL timestop(handle)
1476
1477 END SUBROUTINE trafo_to_k_and_nn
1478
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public pasquier2025
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_get_diag(matrix, diag, n_active)
returns the diagonal of a complex full matrix: diag(i)= A_{ii}. Each diagonal entry is owned by one p...
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
Redistribution of full matrices and distributed arrays.
subroutine, public cp_fm_to_replicated_array(fm_s, array_s, weight, add)
...
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_set_submatrix(fm, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
sets a submatrix of a full matrix fm(start_row:start_row+n_rows,start_col:start_col+n_cols) = alpha*o...
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
This is the start of a dbt_api, all publically needed functions are exported here....
Definition dbt_api.F:17
Redistribute matrices between full-matrix and tensor process layouts.
subroutine, public cp_dbt_to_fm(t_r, fm_r, mat_global, mat_local, para_env)
...
subroutine, public cp_fm_to_dbt(fm_global, mat_global, mat_local, tensor, para_env, num_pe_sub, eps_filter, block_row_ranges)
...
Coulomb matrices and screened interactions for imaginary-time GW.
subroutine, public get_v_tr_r(v_tr_r, pot_type, regularization_ri, bs_env, qs_env)
...
subroutine, public gw_calc_tensor_small_cell_full_kp(qs_env, bs_env)
Perform GW band structure calculation.
Full-matrix operations not provided by the CP2K FM packages.
Definition gw_utils_fm.F:13
subroutine, public local_add_on_diag(matrix, alpha)
Add a scalar to the diagonal of a local complex matrix.
subroutine, public cfm_contract_aba(matrix_a, matrix_b, matrix_c, workspace)
Computes A^H B A for complex full matrices.
Definition gw_utils_fm.F:59
subroutine, public local_complex_power(matrix, exponent, eps, cond_nr, min_ev, max_ev, relative_eps)
Compute a spectral power of a local complex Hermitian matrix. Eigenvalues not larger than eps (or rel...
subroutine, public add_r(cell_1, cell_2, index_to_cell, cell_1_plus_2, cell_found, cell_to_index, i_cell_1_plus_2)
...
Definition gw_utils.F:3071
subroutine, public de_init_bs_env(qs_env, bs_env)
Releases the memory-heavy GW intermediates that cannot be freed in bs_env_release,...
Definition gw_utils.F:3562
subroutine, public analyt_conti_and_print(bs_env, sigma_c_ikp_n_freq, sigma_x_ikp_n, v_xc_ikp_n, eigenval_scf, ikp, ispin, i_iter)
...
Definition gw_utils.F:3653
subroutine, public is_cell_in_index_to_cell(cell, index_to_cell, cell_found)
...
Definition gw_utils.F:3110
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
Routines to compute the Coulomb integral V_(alpha beta)(k) for a k-point k using lattice summation in...
subroutine, public build_2c_coulomb_matrix_kp_dense(v_k, qs_env, kpoints, size_lattice_sum, basis_type, ikp_start, ikp_end)
Dense 2-center Coulomb matrix V_PQ(k) from a direct real-space lattice sum.
Implements simple k-space/R-space transformations and Gamma-point MIC reconstruction.
subroutine, public rs_to_kp(rs_real, ks_complex, index_to_cell, xkp, deriv_direction, hmat)
Integrate RS matrices (stored as Fortran array) into a kpoint matrix at given kp.
subroutine, public fm_add_kp_to_all_rs(cfm_kp, fm_rs, kpoints, ikp)
Adds given kpoint matrix to a single rs matrix.
subroutine, public add_kp_to_all_rs(array_kp, array_rs, kpoints, ikp, index_to_cell_ext)
Adds given kpoint matrix to all rs matrices.
subroutine, public fm_rs_to_kp(cfm_kp, fm_rs, kpoints, ikp)
Transforms array of fm RS matrices into cfm k-space matrix, at given kpoint index.
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition machine.F:144
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public z_zero
Collection of simple mathematical functions and subroutines.
Definition mathlib.F:15
subroutine, public get_all_vbm_cbm_bandgaps(bs_env)
...
Utility routines for RPA and GW with imaginary time.
Definition and construction of time/frequency grids for correlation methods.
subroutine, public transform_time_to_frequency(grid, samples_tau, values_omega)
Transform real positive/negative-time samples to complex positive-frequency values....
integer, parameter, public negative_time
integer, parameter, public positive_time
Represent a complex full matrix.
represent a full matrix