(git:27c966b)
Loading...
Searching...
No Matches
rpa_im_time.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 Routines for low-scaling RPA/GW with imaginary time
10!> \par History
11!> 10.2015 created [Jan Wilhelm]
12! **************************************************************************************************
14 USE cell_types, ONLY: cell_type,&
18 USE cp_cfm_types, ONLY: cp_cfm_create,&
24 USE cp_dbcsr_api, ONLY: &
27 dbcsr_release_p, dbcsr_set, dbcsr_type, dbcsr_type_no_symmetry
32 USE cp_fm_types, ONLY: cp_fm_create,&
37 USE dbt_api, ONLY: &
38 dbt_batched_contract_finalize, dbt_batched_contract_init, dbt_contract, dbt_copy, &
39 dbt_copy_matrix_to_tensor, dbt_copy_tensor_to_matrix, dbt_create, dbt_destroy, dbt_filter, &
40 dbt_get_info, dbt_nblks_total, dbt_nd_mp_comm, dbt_pgrid_destroy, dbt_pgrid_type, dbt_type
41 USE hfx_types, ONLY: block_ind_type,&
43 USE kinds, ONLY: dp,&
44 int_8
45 USE kpoint_types, ONLY: get_kpoint_info,&
48 USE machine, ONLY: m_flush,&
50 USE mathconstants, ONLY: twopi
51 USE message_passing, ONLY: mp_comm_type,&
53 USE mp2_types, ONLY: mp2_type
58 USE qs_mo_types, ONLY: get_mo_set,&
60 USE qs_tensors, ONLY: decompress_tensor,&
67#include "./base/base_uses.f90"
68
69 IMPLICIT NONE
70
71 PRIVATE
72
73 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'rpa_im_time'
74
75 INTEGER, PARAMETER, PUBLIC :: propagator_sector_occupied = 1
76 INTEGER, PARAMETER, PUBLIC :: propagator_sector_virtual = 2
77 INTEGER, PARAMETER, PUBLIC :: propagator_number_of_sectors = 2
78
79 PUBLIC :: compute_mat_p_omega, &
86
87CONTAINS
88
89! **************************************************************************************************
90!> \brief Creates the sector-, time-, and cell-resolved propagator matrix set.
91!> \param propagator propagator matrix set to create
92!> \param ntime number of time or frequency points
93!> \param matrix_template DBCSR matrix template for every matrix
94!> \param index_to_cell cell coordinates for the third matrix-set index
95! **************************************************************************************************
96 SUBROUTINE create_propagator_matrix_set(propagator, ntime, matrix_template, index_to_cell)
97 TYPE(dbcsr_p_type), DIMENSION(:, :, :), POINTER :: propagator
98 INTEGER, INTENT(IN) :: ntime
99 TYPE(dbcsr_type), INTENT(IN) :: matrix_template
100 INTEGER, DIMENSION(:, :), INTENT(IN) :: index_to_cell
101
102 INTEGER :: icell, isector, jtime, ncell
103
104 cpassert(ntime > 0)
105 cpassert(SIZE(index_to_cell, 1) == 3)
106 ncell = SIZE(index_to_cell, 2)
107 cpassert(ncell > 0)
108
109 CALL dbcsr_allocate_matrix_set(propagator, propagator_number_of_sectors, ntime, ncell)
110
111 DO icell = 1, ncell
112 DO jtime = 1, ntime
113 DO isector = 1, propagator_number_of_sectors
114 ALLOCATE (propagator(isector, jtime, icell)%matrix)
115 CALL dbcsr_create(matrix=propagator(isector, jtime, icell)%matrix, &
116 template=matrix_template, &
117 matrix_type=dbcsr_type_no_symmetry)
118 END DO
119 END DO
120 END DO
121
122 END SUBROUTINE create_propagator_matrix_set
123
124! **************************************************************************************************
125!> \brief ...
126!> \param mat_P_omega ...
127!> \param fm_mo_coeff ...
128!> \param homo ...
129!> \param mat_P_global ...
130!> \param matrix_s ...
131!> \param ispin ...
132!> \param t_3c_M ...
133!> \param t_3c_O ...
134!> \param t_3c_O_compressed ...
135!> \param t_3c_O_ind ...
136!> \param starts_array_mc ...
137!> \param ends_array_mc ...
138!> \param starts_array_mc_block ...
139!> \param ends_array_mc_block ...
140!> \param grid ...
141!> \param e_fermi ...
142!> \param eps_filter ...
143!> \param alpha ...
144!> \param eps_filter_im_time ...
145!> \param Eigenval ...
146!> \param nmo ...
147!> \param cut_memory ...
148!> \param unit_nr ...
149!> \param mp2_env ...
150!> \param para_env ...
151!> \param qs_env ...
152!> \param do_kpoints_from_Gamma ...
153!> \param index_to_cell_3c ...
154!> \param cell_to_index_3c ...
155!> \param has_mat_P_blocks ...
156!> \param do_ri_sos_laplace_mp2 ...
157!> \param dbcsr_time ...
158!> \param dbcsr_nflop ...
159! **************************************************************************************************
160 SUBROUTINE compute_mat_p_omega(mat_P_omega, fm_mo_coeff, homo, &
161 mat_P_global, &
162 matrix_s, &
163 ispin, &
164 t_3c_M, t_3c_O, t_3c_O_compressed, t_3c_O_ind, &
165 starts_array_mc, ends_array_mc, &
166 starts_array_mc_block, ends_array_mc_block, &
167 grid, e_fermi, eps_filter, &
168 alpha, eps_filter_im_time, Eigenval, nmo, &
169 cut_memory, unit_nr, &
170 mp2_env, para_env, &
171 qs_env, do_kpoints_from_Gamma, &
172 index_to_cell_3c, cell_to_index_3c, &
173 has_mat_P_blocks, do_ri_sos_laplace_mp2, &
174 dbcsr_time, dbcsr_nflop)
175 TYPE(dbcsr_p_type), DIMENSION(:, :), INTENT(IN) :: mat_p_omega
176 TYPE(cp_fm_type), INTENT(IN) :: fm_mo_coeff
177 INTEGER, INTENT(IN) :: homo
178 TYPE(dbcsr_p_type), INTENT(INOUT) :: mat_p_global
179 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
180 INTEGER, INTENT(IN) :: ispin
181 TYPE(dbt_type), INTENT(INOUT) :: t_3c_m
182 TYPE(dbt_type), DIMENSION(:, :), INTENT(INOUT) :: t_3c_o
183 TYPE(hfx_compression_type), DIMENSION(:, :, :), &
184 INTENT(INOUT) :: t_3c_o_compressed
185 TYPE(block_ind_type), DIMENSION(:, :, :), &
186 INTENT(INOUT) :: t_3c_o_ind
187 INTEGER, DIMENSION(:), INTENT(IN) :: starts_array_mc, ends_array_mc, &
188 starts_array_mc_block, &
189 ends_array_mc_block
190 TYPE(time_frequency_grid_type), INTENT(IN) :: grid
191 REAL(kind=dp), INTENT(IN) :: e_fermi, eps_filter, alpha, &
192 eps_filter_im_time
193 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: eigenval
194 INTEGER, INTENT(IN) :: nmo, cut_memory, unit_nr
195 TYPE(mp2_type) :: mp2_env
196 TYPE(mp_para_env_type), INTENT(IN) :: para_env
197 TYPE(qs_environment_type), POINTER :: qs_env
198 LOGICAL, INTENT(IN) :: do_kpoints_from_gamma
199 INTEGER, ALLOCATABLE, DIMENSION(:, :), INTENT(IN) :: index_to_cell_3c
200 INTEGER, ALLOCATABLE, DIMENSION(:, :, :), &
201 INTENT(IN) :: cell_to_index_3c
202 LOGICAL, DIMENSION(:, :, :, :, :), INTENT(INOUT) :: has_mat_p_blocks
203 LOGICAL, INTENT(IN) :: do_ri_sos_laplace_mp2
204 REAL(dp), INTENT(INOUT) :: dbcsr_time
205 INTEGER(int_8), INTENT(INOUT) :: dbcsr_nflop
206
207 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_mat_P_omega'
208
209 INTEGER :: comm_2d_handle, handle, handle2, handle3, i, i_cell, i_cell_r_1, &
210 i_cell_r_1_minus_s, i_cell_r_1_minus_t, i_cell_r_2, i_cell_r_2_minus_s_minus_t, i_cell_s, &
211 i_cell_t, i_mem, iquad, j, j_mem, jquad, num_3c_repl, num_cells_dm, num_integ_points, &
212 unit_nr_dbcsr
213 INTEGER(int_8) :: nze, nze_dm_occ, nze_dm_virt, nze_m_occ, &
214 nze_m_virt, nze_o
215 INTEGER(KIND=int_8) :: flops_1_occ, flops_1_virt, flops_2
216 INTEGER, ALLOCATABLE, DIMENSION(:) :: dist_1, dist_2, mc_ranges, size_dm, &
217 size_p
218 INTEGER, DIMENSION(2) :: pdims_2d
219 INTEGER, DIMENSION(2, 1) :: ibounds_2, jbounds_2
220 INTEGER, DIMENSION(2, 2) :: ibounds_1, jbounds_1
221 INTEGER, DIMENSION(3) :: bounds_3c
222 INTEGER, DIMENSION(:, :), POINTER :: index_to_cell_dm
223 LOGICAL :: do_gamma_rpa, do_kpoints_cubic_rpa, first_cycle_im_time, memory_info, &
224 r_1_minus_s_needed, r_1_minus_t_needed, r_2_minus_s_minus_t_needed
225 REAL(dp) :: occ, occ_dm_occ, occ_dm_virt, occ_m_occ, &
226 occ_m_virt, occ_o, t1_flop
227 REAL(kind=dp) :: t1, t2, weight
228 TYPE(dbcsr_distribution_type) :: dist_p
229 TYPE(dbcsr_p_type), DIMENSION(:, :, :), POINTER :: propagator
230 TYPE(dbt_pgrid_type) :: pgrid_2d
231 TYPE(dbt_type) :: t_3c_m_occ, t_3c_m_occ_tmp, t_3c_m_virt, &
232 t_3c_m_virt_tmp, t_dm, t_dm_tmp, t_p, &
233 t_p_tmp
234 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: t_dm_occ, t_dm_virt
235 TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_3c_o_occ, t_3c_o_virt
236 TYPE(mp_comm_type) :: comm_2d
237
238 CALL timeset(routinen, handle)
239
240 DO jquad = 1, SIZE(mat_p_omega, 1)
241 DO i_cell_t = 1, SIZE(mat_p_omega, 2)
242 CALL dbcsr_set(mat_p_omega(jquad, i_cell_t)%matrix, 0.0_dp)
243 END DO
244 END DO
245
246 IF (do_ri_sos_laplace_mp2) THEN
247 num_integ_points = SIZE(grid%imaginary_time)
248 ELSE
249 num_integ_points = SIZE(grid%frequency)
250 END IF
251
252 NULLIFY (propagator)
253
254 memory_info = mp2_env%ri_rpa_im_time%memory_info
255 IF (memory_info) THEN
256 unit_nr_dbcsr = unit_nr
257 ELSE
258 unit_nr_dbcsr = 0
259 END IF
260
261 do_kpoints_cubic_rpa = qs_env%mp2_env%ri_rpa_im_time%do_im_time_kpoints
262 do_gamma_rpa = .NOT. do_kpoints_cubic_rpa
263 num_3c_repl = maxval(cell_to_index_3c)
264
265 first_cycle_im_time = .true.
266 ALLOCATE (t_3c_o_occ(SIZE(t_3c_o, 1), SIZE(t_3c_o, 2)), t_3c_o_virt(SIZE(t_3c_o, 1), SIZE(t_3c_o, 2)))
267 DO i = 1, SIZE(t_3c_o, 1)
268 DO j = 1, SIZE(t_3c_o, 2)
269 CALL dbt_create(t_3c_o(i, j), t_3c_o_occ(i, j))
270 CALL dbt_create(t_3c_o(i, j), t_3c_o_virt(i, j))
271 END DO
272 END DO
273
274 CALL dbt_create(t_3c_m, t_3c_m_occ, name="M occ (RI | AO AO)")
275 CALL dbt_create(t_3c_m, t_3c_m_virt, name="M virt (RI | AO AO)")
276
277 ALLOCATE (mc_ranges(cut_memory + 1))
278 mc_ranges(:cut_memory) = starts_array_mc_block(:)
279 mc_ranges(cut_memory + 1) = ends_array_mc_block(cut_memory) + 1
280
281 DO jquad = 1, num_integ_points
282
283 CALL para_env%sync()
284 t1 = m_walltime()
285
286 CALL compute_mat_dm_global(grid, nmo, fm_mo_coeff, homo, propagator, &
287 matrix_s, ispin, &
288 eigenval, e_fermi, eps_filter, memory_info, unit_nr, &
289 jquad, do_kpoints_cubic_rpa, do_kpoints_from_gamma, qs_env, &
290 num_cells_dm, index_to_cell_dm, para_env)
291
292 ALLOCATE (t_dm_virt(num_cells_dm))
293 ALLOCATE (t_dm_occ(num_cells_dm))
294 CALL dbcsr_get_info(mat_p_global%matrix, distribution=dist_p)
295 CALL dbcsr_distribution_get(dist_p, group=comm_2d_handle, nprows=pdims_2d(1), npcols=pdims_2d(2))
296 CALL comm_2d%set_handle(comm_2d_handle)
297
298 pgrid_2d = dbt_nd_mp_comm(comm_2d, [1], [2], pdims_2d=pdims_2d)
299 ALLOCATE (size_p(dbt_nblks_total(t_3c_m, 1)))
300 CALL dbt_get_info(t_3c_m, blk_size_1=size_p)
301
302 ALLOCATE (size_dm(dbt_nblks_total(t_3c_o(1, 1), 3)))
303 CALL dbt_get_info(t_3c_o(1, 1), blk_size_3=size_dm)
304 CALL create_2c_tensor(t_dm, dist_1, dist_2, pgrid_2d, size_dm, size_dm, name="D (AO | AO)")
305 DEALLOCATE (size_dm)
306 DEALLOCATE (dist_1, dist_2)
307 CALL create_2c_tensor(t_p, dist_1, dist_2, pgrid_2d, size_p, size_p, name="P (RI | RI)")
308 DEALLOCATE (size_p)
309 DEALLOCATE (dist_1, dist_2)
310 CALL dbt_pgrid_destroy(pgrid_2d)
311
312 DO i_cell = 1, num_cells_dm
313 CALL dbt_create(t_dm, t_dm_virt(i_cell), name="D virt (AO | AO)")
314 CALL dbt_create(propagator(propagator_sector_virtual, jquad, i_cell)%matrix, t_dm_tmp)
315 CALL dbt_copy_matrix_to_tensor(propagator(propagator_sector_virtual, jquad, i_cell)%matrix, t_dm_tmp)
316 CALL dbt_copy(t_dm_tmp, t_dm_virt(i_cell), move_data=.true.)
317 CALL dbcsr_clear(propagator(propagator_sector_virtual, jquad, i_cell)%matrix)
318
319 CALL dbt_create(t_dm, t_dm_occ(i_cell), name="D occ (AO | AO)")
320 CALL dbt_copy_matrix_to_tensor(propagator(propagator_sector_occupied, jquad, i_cell)%matrix, t_dm_tmp)
321 CALL dbt_copy(t_dm_tmp, t_dm_occ(i_cell), move_data=.true.)
322 CALL dbt_destroy(t_dm_tmp)
323 CALL dbcsr_clear(propagator(propagator_sector_occupied, jquad, i_cell)%matrix)
324 END DO
325
326 CALL get_tensor_occupancy(t_dm_occ(1), nze_dm_occ, occ_dm_occ)
327 CALL get_tensor_occupancy(t_dm_virt(1), nze_dm_virt, occ_dm_virt)
328
329 CALL dbt_destroy(t_dm)
330
331 CALL dbt_create(t_3c_o_occ(1, 1), t_3c_m_occ_tmp, name="M (RI AO | AO)")
332 CALL dbt_create(t_3c_o_virt(1, 1), t_3c_m_virt_tmp, name="M (RI AO | AO)")
333
334 CALL timeset(routinen//"_contract", handle2)
335
336 CALL para_env%sync()
337 t1_flop = m_walltime()
338
339 DO i = 1, SIZE(t_3c_o_occ, 1)
340 DO j = 1, SIZE(t_3c_o_occ, 2)
341 CALL dbt_batched_contract_init(t_3c_o_occ(i, j), batch_range_2=mc_ranges, batch_range_3=mc_ranges)
342 END DO
343 END DO
344 DO i = 1, SIZE(t_3c_o_virt, 1)
345 DO j = 1, SIZE(t_3c_o_virt, 2)
346 CALL dbt_batched_contract_init(t_3c_o_virt(i, j), batch_range_2=mc_ranges, batch_range_3=mc_ranges)
347 END DO
348 END DO
349 CALL dbt_batched_contract_init(t_3c_m_occ_tmp, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
350 CALL dbt_batched_contract_init(t_3c_m_virt_tmp, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
351 CALL dbt_batched_contract_init(t_3c_m_occ, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
352 CALL dbt_batched_contract_init(t_3c_m_virt, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
353
354 DO i_cell_t = 1, num_cells_dm/2 + 1
355
356 IF (.NOT. any(has_mat_p_blocks(i_cell_t, :, :, :, :))) cycle
357
358 CALL dbt_batched_contract_init(t_p)
359
360 IF (do_gamma_rpa) THEN
361 nze_o = 0
362 nze_m_virt = 0
363 nze_m_occ = 0
364 occ_m_virt = 0.0_dp
365 occ_m_occ = 0.0_dp
366 occ_o = 0.0_dp
367 END IF
368
369 DO j_mem = 1, cut_memory
370
371 CALL dbt_get_info(t_3c_o_occ(1, 1), nfull_total=bounds_3c)
372
373 jbounds_1(:, 1) = [1, bounds_3c(1)]
374 jbounds_1(:, 2) = [starts_array_mc(j_mem), ends_array_mc(j_mem)]
375
376 jbounds_2(:, 1) = [starts_array_mc(j_mem), ends_array_mc(j_mem)]
377
378 IF (do_gamma_rpa) CALL dbt_batched_contract_init(t_dm_virt(1))
379
380 DO i_mem = 1, cut_memory
381
382 IF (.NOT. any(has_mat_p_blocks(i_cell_t, i_mem, j_mem, :, :))) cycle
383
384 ibounds_1(:, 1) = [1, bounds_3c(1)]
385 ibounds_1(:, 2) = [starts_array_mc(i_mem), ends_array_mc(i_mem)]
386
387 ibounds_2(:, 1) = [starts_array_mc(i_mem), ends_array_mc(i_mem)]
388
389 IF (unit_nr_dbcsr > 0) WRITE (unit=unit_nr_dbcsr, fmt="(T3,A,I3,1X,I3)") &
390 "RPA_LOW_SCALING_INFO| Memory Cut iteration", i_mem, j_mem
391
392 DO i_cell_r_1 = 1, num_3c_repl
393
394 DO i_cell_r_2 = 1, num_3c_repl
395
396 IF (.NOT. has_mat_p_blocks(i_cell_t, i_mem, j_mem, i_cell_r_1, i_cell_r_2)) cycle
397
398 CALL get_diff_index_3c(i_cell_r_1, i_cell_t, i_cell_r_1_minus_t, &
399 index_to_cell_3c, cell_to_index_3c, index_to_cell_dm, &
400 r_1_minus_t_needed, do_kpoints_cubic_rpa)
401
402 IF (do_gamma_rpa) CALL dbt_batched_contract_init(t_dm_occ(1))
403 DO i_cell_s = 1, num_cells_dm
404 CALL get_diff_index_3c(i_cell_r_1, i_cell_s, i_cell_r_1_minus_s, index_to_cell_3c, &
405 cell_to_index_3c, index_to_cell_dm, r_1_minus_s_needed, &
406 do_kpoints_cubic_rpa)
407 IF (r_1_minus_s_needed) THEN
408
409 CALL timeset(routinen//"_calc_M_occ_t", handle3)
410 CALL decompress_tensor(t_3c_o(i_cell_r_1_minus_s, i_cell_r_2), &
411 t_3c_o_ind(i_cell_r_1_minus_s, i_cell_r_2, j_mem)%ind, &
412 t_3c_o_compressed(i_cell_r_1_minus_s, i_cell_r_2, j_mem), &
413 qs_env%mp2_env%ri_rpa_im_time%eps_compress)
414
415 IF (do_gamma_rpa .AND. i_mem == 1) THEN
416 CALL get_tensor_occupancy(t_3c_o(1, 1), nze, occ)
417 nze_o = nze_o + nze
418 occ_o = occ_o + occ
419 END IF
420
421 CALL dbt_copy(t_3c_o(i_cell_r_1_minus_s, i_cell_r_2), &
422 t_3c_o_occ(i_cell_r_1_minus_s, i_cell_r_2), move_data=.true.)
423
424 CALL dbt_contract(alpha=1.0_dp, &
425 tensor_1=t_3c_o_occ(i_cell_r_1_minus_s, i_cell_r_2), &
426 tensor_2=t_dm_occ(i_cell_s), &
427 beta=1.0_dp, &
428 tensor_3=t_3c_m_occ_tmp, &
429 contract_1=[3], notcontract_1=[1, 2], &
430 contract_2=[2], notcontract_2=[1], &
431 map_1=[1, 2], map_2=[3], &
432 bounds_2=jbounds_1, bounds_3=ibounds_2, &
433 filter_eps=eps_filter, unit_nr=unit_nr_dbcsr, &
434 flop=flops_1_occ)
435 CALL timestop(handle3)
436
437 dbcsr_nflop = dbcsr_nflop + flops_1_occ
438
439 END IF
440 END DO
441
442 IF (do_gamma_rpa) CALL dbt_batched_contract_finalize(t_dm_occ(1))
443
444 ! copy matrix to optimal contraction layout - copy is done manually in order
445 ! to better control memory allocations (we can release data of previous
446 ! representation)
447 CALL timeset(routinen//"_copy_M_occ_t", handle3)
448 CALL dbt_copy(t_3c_m_occ_tmp, t_3c_m_occ, order=[1, 3, 2], move_data=.true.)
449 CALL dbt_filter(t_3c_m_occ, eps_filter)
450 CALL timestop(handle3)
451
452 IF (do_gamma_rpa) THEN
453 CALL get_tensor_occupancy(t_3c_m_occ, nze, occ)
454 nze_m_occ = nze_m_occ + nze
455 occ_m_occ = occ_m_occ + occ
456 END IF
457
458 DO i_cell_s = 1, num_cells_dm
459 CALL get_diff_diff_index_3c(i_cell_r_2, i_cell_s, i_cell_t, i_cell_r_2_minus_s_minus_t, &
460 index_to_cell_3c, cell_to_index_3c, index_to_cell_dm, &
461 r_2_minus_s_minus_t_needed, do_kpoints_cubic_rpa)
462
463 IF (r_1_minus_t_needed .AND. r_2_minus_s_minus_t_needed) THEN
464 CALL decompress_tensor(t_3c_o(i_cell_r_2_minus_s_minus_t, i_cell_r_1_minus_t), &
465 t_3c_o_ind(i_cell_r_2_minus_s_minus_t, i_cell_r_1_minus_t, i_mem)%ind, &
466 t_3c_o_compressed(i_cell_r_2_minus_s_minus_t, i_cell_r_1_minus_t, i_mem), &
467 qs_env%mp2_env%ri_rpa_im_time%eps_compress)
468
469 CALL dbt_copy(t_3c_o(i_cell_r_2_minus_s_minus_t, i_cell_r_1_minus_t), &
470 t_3c_o_virt(i_cell_r_2_minus_s_minus_t, i_cell_r_1_minus_t), move_data=.true.)
471
472 CALL timeset(routinen//"_calc_M_virt_t", handle3)
473 CALL dbt_contract(alpha=alpha/2.0_dp, &
474 tensor_1=t_3c_o_virt( &
475 i_cell_r_2_minus_s_minus_t, i_cell_r_1_minus_t), &
476 tensor_2=t_dm_virt(i_cell_s), &
477 beta=1.0_dp, &
478 tensor_3=t_3c_m_virt_tmp, &
479 contract_1=[3], notcontract_1=[1, 2], &
480 contract_2=[2], notcontract_2=[1], &
481 map_1=[1, 2], map_2=[3], &
482 bounds_2=ibounds_1, bounds_3=jbounds_2, &
483 filter_eps=eps_filter, unit_nr=unit_nr_dbcsr, &
484 flop=flops_1_virt)
485 CALL timestop(handle3)
486
487 dbcsr_nflop = dbcsr_nflop + flops_1_virt
488
489 END IF
490 END DO
491
492 CALL timeset(routinen//"_copy_M_virt_t", handle3)
493 CALL dbt_copy(t_3c_m_virt_tmp, t_3c_m_virt, move_data=.true.)
494 CALL dbt_filter(t_3c_m_virt, eps_filter)
495 CALL timestop(handle3)
496
497 IF (do_gamma_rpa) THEN
498 CALL get_tensor_occupancy(t_3c_m_virt, nze, occ)
499 nze_m_virt = nze_m_virt + nze
500 occ_m_virt = occ_m_virt + occ
501 END IF
502
503 flops_2 = 0
504
505 CALL timeset(routinen//"_calc_P_t", handle3)
506
507 CALL dbt_contract(alpha=1.0_dp, tensor_1=t_3c_m_occ, &
508 tensor_2=t_3c_m_virt, &
509 beta=1.0_dp, &
510 tensor_3=t_p, &
511 contract_1=[2, 3], notcontract_1=[1], &
512 contract_2=[2, 3], notcontract_2=[1], &
513 map_1=[1], map_2=[2], &
514 filter_eps=eps_filter_im_time/real(cut_memory**2, kind=dp), &
515 flop=flops_2, &
516 move_data=.true., &
517 unit_nr=unit_nr_dbcsr)
518
519 CALL timestop(handle3)
520
521 first_cycle_im_time = .false.
522
523 IF (jquad == 1 .AND. flops_2 == 0) THEN
524 has_mat_p_blocks(i_cell_t, i_mem, j_mem, i_cell_r_1, i_cell_r_2) = .false.
525 END IF
526
527 END DO
528 END DO
529 END DO
530 IF (do_gamma_rpa) CALL dbt_batched_contract_finalize(t_dm_virt(1))
531 END DO
532
533 CALL dbt_batched_contract_finalize(t_p, unit_nr=unit_nr_dbcsr)
534
535 CALL dbt_create(mat_p_global%matrix, t_p_tmp)
536 CALL dbt_copy(t_p, t_p_tmp, move_data=.true.)
537 CALL dbt_copy_tensor_to_matrix(t_p_tmp, mat_p_global%matrix)
538 CALL dbt_destroy(t_p_tmp)
539
540 IF (do_ri_sos_laplace_mp2) THEN
541 ! For RI-SOS-Laplace-MP2 we do not perform a cosine transform,
542 ! but we have to copy P_local to the output matrix
543
544 CALL dbcsr_add(mat_p_omega(jquad, i_cell_t)%matrix, mat_p_global%matrix, 1.0_dp, 1.0_dp)
545 ELSE
546 CALL timeset(routinen//"_Fourier_transform", handle3)
547
548 ! Fourier transform of P(it) to P(iw)
549 DO iquad = 1, num_integ_points
550
551 weight = grid%cosine_time_to_frequency(iquad, jquad)
552
553 ! no multiplication with 2.0 as in Kresses paper (Kaltak, JCTC 10, 2498 (2014), Eq. 12)
554 ! because this factor is already absorbed in the weight w_j
555 CALL dbcsr_add(mat_p_omega(iquad, i_cell_t)%matrix, mat_p_global%matrix, &
556 1.0_dp, weight)
557
558 END DO
559
560 CALL timestop(handle3)
561 END IF
562
563 END DO
564
565 CALL timestop(handle2)
566
567 CALL dbt_batched_contract_finalize(t_3c_m_occ_tmp)
568 CALL dbt_batched_contract_finalize(t_3c_m_virt_tmp)
569 CALL dbt_batched_contract_finalize(t_3c_m_occ)
570 CALL dbt_batched_contract_finalize(t_3c_m_virt)
571
572 DO i = 1, SIZE(t_3c_o_occ, 1)
573 DO j = 1, SIZE(t_3c_o_occ, 2)
574 CALL dbt_batched_contract_finalize(t_3c_o_occ(i, j))
575 END DO
576 END DO
577
578 DO i = 1, SIZE(t_3c_o_virt, 1)
579 DO j = 1, SIZE(t_3c_o_virt, 2)
580 CALL dbt_batched_contract_finalize(t_3c_o_virt(i, j))
581 END DO
582 END DO
583
584 CALL dbt_destroy(t_p)
585 DO i_cell = 1, num_cells_dm
586 CALL dbt_destroy(t_dm_virt(i_cell))
587 CALL dbt_destroy(t_dm_occ(i_cell))
588 END DO
589
590 CALL dbt_destroy(t_3c_m_occ_tmp)
591 CALL dbt_destroy(t_3c_m_virt_tmp)
592 DEALLOCATE (t_dm_virt)
593 DEALLOCATE (t_dm_occ)
594
595 CALL para_env%sync()
596 t2 = m_walltime()
597
598 dbcsr_time = dbcsr_time + t2 - t1_flop
599
600 IF (unit_nr > 0) THEN
601 WRITE (unit_nr, '(/T3,A,1X,I3)') &
602 'RPA_LOW_SCALING_INFO| Info for time point', jquad
603 WRITE (unit_nr, '(T6,A,T56,F25.1)') &
604 'Execution time (s):', t2 - t1
605 WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
606 'Occupancy of D occ:', real(nze_dm_occ, dp), '/', occ_dm_occ*100, '%'
607 WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
608 'Occupancy of D virt:', real(nze_dm_virt, dp), '/', occ_dm_virt*100, '%'
609 IF (do_gamma_rpa) THEN
610 WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
611 'Occupancy of 3c ints:', real(nze_o, dp), '/', occ_o*100, '%'
612 WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
613 'Occupancy of M occ:', real(nze_m_occ, dp), '/', occ_m_occ*100, '%'
614 WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
615 'Occupancy of M virt:', real(nze_m_virt, dp), '/', occ_m_virt*100, '%'
616 END IF
617 WRITE (unit_nr, *)
618 CALL m_flush(unit_nr)
619 END IF
620
621 END DO ! time points
622
623 CALL dbt_destroy(t_3c_m_occ)
624 CALL dbt_destroy(t_3c_m_virt)
625
626 DO i = 1, SIZE(t_3c_o, 1)
627 DO j = 1, SIZE(t_3c_o, 2)
628 CALL dbt_destroy(t_3c_o_occ(i, j))
629 CALL dbt_destroy(t_3c_o_virt(i, j))
630 END DO
631 END DO
632
633 CALL dbcsr_deallocate_matrix_set(propagator)
634
635 CALL timestop(handle)
636
637 END SUBROUTINE compute_mat_p_omega
638
639! **************************************************************************************************
640!> \brief ...
641!> \param grid ...
642!> \param nmo ...
643!> \param fm_mo_coeff ...
644!> \param homo ...
645!> \param propagator ...
646!> \param matrix_s ...
647!> \param ispin ...
648!> \param Eigenval ...
649!> \param e_fermi ...
650!> \param eps_filter ...
651!> \param memory_info ...
652!> \param unit_nr ...
653!> \param jquad ...
654!> \param do_kpoints_cubic_RPA ...
655!> \param do_kpoints_from_Gamma ...
656!> \param qs_env ...
657!> \param num_cells_dm ...
658!> \param index_to_cell_dm ...
659!> \param para_env ...
660! **************************************************************************************************
661 SUBROUTINE compute_mat_dm_global(grid, nmo, fm_mo_coeff, homo, propagator, &
662 matrix_s, ispin, &
663 Eigenval, e_fermi, eps_filter, memory_info, unit_nr, &
664 jquad, do_kpoints_cubic_RPA, do_kpoints_from_Gamma, qs_env, &
665 num_cells_dm, index_to_cell_dm, para_env)
666
667 TYPE(time_frequency_grid_type), INTENT(IN) :: grid
668 INTEGER, INTENT(IN) :: nmo
669 TYPE(cp_fm_type), INTENT(IN) :: fm_mo_coeff
670 INTEGER, INTENT(IN) :: homo
671 TYPE(dbcsr_p_type), DIMENSION(:, :, :), &
672 INTENT(INOUT), POINTER :: propagator
673 TYPE(dbcsr_p_type), DIMENSION(:), INTENT(IN) :: matrix_s
674 INTEGER, INTENT(IN) :: ispin
675 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: eigenval
676 REAL(kind=dp), INTENT(IN) :: e_fermi, eps_filter
677 LOGICAL, INTENT(IN) :: memory_info
678 INTEGER, INTENT(IN) :: unit_nr, jquad
679 LOGICAL, INTENT(IN) :: do_kpoints_cubic_rpa, &
680 do_kpoints_from_gamma
681 TYPE(qs_environment_type), POINTER :: qs_env
682 INTEGER, INTENT(OUT) :: num_cells_dm
683 INTEGER, DIMENSION(:, :), POINTER :: index_to_cell_dm
684 TYPE(mp_para_env_type), INTENT(IN) :: para_env
685
686 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_mat_dm_global'
687
688 INTEGER :: handle, num_integ_points
689 INTEGER, DIMENSION(3, 1) :: index_to_cell_zero
690 REAL(kind=dp) :: tau
691
692 index_to_cell_zero = 0
693 num_integ_points = SIZE(grid%imaginary_time)
694
695 CALL timeset(routinen, handle)
696
697 IF (memory_info .AND. unit_nr > 0) WRITE (unit=unit_nr, fmt="(T3,A,T75,i6)") &
698 "RPA_LOW_SCALING_INFO| Started with time point: ", jquad
699
700 tau = grid%imaginary_time(jquad)
701
702 IF (do_kpoints_cubic_rpa) THEN
703
704 CALL compute_transl_dm(propagator, qs_env, &
705 ispin, num_integ_points, jquad, e_fermi, tau, &
706 eps_filter, num_cells_dm, index_to_cell_dm, &
708
709 CALL compute_transl_dm(propagator, qs_env, &
710 ispin, num_integ_points, jquad, e_fermi, tau, &
711 eps_filter, num_cells_dm, index_to_cell_dm, &
713
714 ELSE IF (do_kpoints_from_gamma) THEN
715
716 CALL compute_periodic_dm(propagator, qs_env, &
717 ispin, num_integ_points, jquad, e_fermi, tau, &
719
720 CALL compute_periodic_dm(propagator, qs_env, &
721 ispin, num_integ_points, jquad, e_fermi, tau, &
723
724 num_cells_dm = 1
725
726 ELSE
727
728 num_cells_dm = 1
729
730 IF (jquad == 1) THEN
731 CALL create_propagator_matrix_set(propagator, num_integ_points, matrix_s(1)%matrix, &
732 index_to_cell_zero)
733 END IF
734
735 CALL compute_gamma_propagator(propagator, jquad, fm_mo_coeff, homo, eigenval, nmo, &
736 eps_filter, e_fermi, tau, para_env)
737
738 ! release memory
739 IF (jquad > 1) THEN
740 CALL dbcsr_set(propagator(propagator_sector_occupied, jquad - 1, 1)%matrix, 0.0_dp)
741 CALL dbcsr_set(propagator(propagator_sector_virtual, jquad - 1, 1)%matrix, 0.0_dp)
742 CALL dbcsr_filter(propagator(propagator_sector_occupied, jquad - 1, 1)%matrix, 0.0_dp)
743 CALL dbcsr_filter(propagator(propagator_sector_virtual, jquad - 1, 1)%matrix, 0.0_dp)
744 END IF
745
746 END IF ! do kpoints
747
748 CALL timestop(handle)
749
750 END SUBROUTINE compute_mat_dm_global
751
752! **************************************************************************************************
753!> \brief Builds the Gamma-point occupied and virtual propagators.
754!> \param propagator sector/time/cell propagator matrix set
755!> \param jquad time-point index
756!> \param fm_mo_coeff real Gamma-point MO coefficient matrix
757!> \param homo number of occupied orbitals
758!> \param Eigenval orbital energies
759!> \param nmo number of orbitals
760!> \param eps_filter DBCSR filtering threshold
761!> \param e_fermi Fermi energy
762!> \param tau imaginary time
763!> \param para_env parallel environment
764! **************************************************************************************************
765 SUBROUTINE compute_gamma_propagator(propagator, jquad, fm_mo_coeff, homo, Eigenval, nmo, &
766 eps_filter, e_fermi, tau, para_env)
767 TYPE(dbcsr_p_type), DIMENSION(:, :, :), &
768 INTENT(INOUT), POINTER :: propagator
769 INTEGER, INTENT(IN) :: jquad
770 TYPE(cp_fm_type), INTENT(IN) :: fm_mo_coeff
771 INTEGER, INTENT(IN) :: homo
772 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: eigenval
773 INTEGER, INTENT(IN) :: nmo
774 REAL(kind=dp), INTENT(IN) :: eps_filter, e_fermi, tau
775 TYPE(mp_para_env_type), INTENT(IN) :: para_env
776
777 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_gamma_propagator'
778 REAL(kind=dp), PARAMETER :: stabilize_exp = 70.0_dp
779
780 INTEGER :: first_mo, handle, i_mo, isector, &
781 last_mo, nao
782 REAL(kind=dp) :: column_factors(nmo), tau_e
783 TYPE(cp_fm_type) :: fm_mo_coeff_scaled, fm_scaled_dm_tau
784 TYPE(dbcsr_type), POINTER :: mat
785
786 CALL timeset(routinen, handle)
787 CALL para_env%sync()
788
789 CALL cp_fm_get_info(fm_mo_coeff, nrow_global=nao)
790 CALL cp_fm_create(fm_scaled_dm_tau, fm_mo_coeff%matrix_struct, nrow=nao, ncol=nao)
791 CALL cp_fm_create(fm_mo_coeff_scaled, fm_mo_coeff%matrix_struct)
792
793 DO i_mo = 1, nmo
794 tau_e = tau*0.5_dp*(eigenval(i_mo) - e_fermi)
795 IF (abs(tau_e) < stabilize_exp) THEN
796 IF (i_mo > homo) tau_e = -tau_e
797 column_factors(i_mo) = exp(tau_e)
798 ELSE
799 column_factors(i_mo) = 0.0_dp
800 END IF
801 END DO
802
803 CALL para_env%sync()
804
806 first_mo = 1
807 last_mo = homo
808 IF (isector == propagator_sector_virtual) THEN
809 first_mo = homo + 1
810 last_mo = nmo
811 END IF
812 CALL build_ao_propagator(fm_mo_coeff, column_factors(first_mo:last_mo), first_mo, &
813 fm_mo_coeff_scaled, fm_scaled_dm_tau)
814
815 ! Each sector is copied before the dense coefficient and AO workspaces are reused.
816 mat => propagator(isector, jquad, 1)%matrix
817 CALL dbcsr_set(mat, 0.0_dp)
818 CALL copy_fm_to_dbcsr(fm_scaled_dm_tau, mat, keep_sparsity=.false.)
819 CALL dbcsr_filter(mat, eps_filter)
820 END DO
821
822 CALL cp_fm_release(fm_scaled_dm_tau)
823 CALL cp_fm_release(fm_mo_coeff_scaled)
824 CALL timestop(handle)
825
826 END SUBROUTINE compute_gamma_propagator
827
828! **************************************************************************************************
829!> \brief Calculate one kpoint density matrix in the complex AO representation.
830!> \param kpoint kpoint environment
831!> \param ikpgr local kpoint index
832!> \param ispin spin index
833!> \param tau ...
834!> \param e_fermi ...
835!> \param sector ...
836!> \param density complex AO density matrix
837! **************************************************************************************************
838 SUBROUTINE build_kpoint_density_matrix_rpa(kpoint, ikpgr, ispin, tau, e_fermi, sector, density)
839
840 TYPE(kpoint_type), POINTER :: kpoint
841 INTEGER, INTENT(IN) :: ikpgr, ispin
842 REAL(kind=dp), INTENT(IN) :: tau, e_fermi
843 INTEGER, INTENT(IN) :: sector
844 TYPE(cp_cfm_type), INTENT(INOUT) :: density
845
846 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_kpoint_density_matrix_rpa'
847 REAL(kind=dp), PARAMETER :: stabilize_exp = 70.0_dp
848
849 INTEGER :: handle, i_mo, nao, nmo, nspin
850 REAL(kind=dp), DIMENSION(:), POINTER :: eigenvalues, exp_scaling, occupation
851 TYPE(cp_cfm_type) :: cfm_work
852 TYPE(cp_cfm_type), POINTER :: cfm_mo_coeff
853 TYPE(kpoint_env_type), POINTER :: kp
854 TYPE(mo_set_type), POINTER :: mo_set
855
856 CALL timeset(routinen, handle)
857
858 cpassert(sector == propagator_sector_occupied .OR. sector == propagator_sector_virtual)
859 cpassert(kpoint%use_real_wfn .EQV. .false.)
860
861 kp => kpoint%kp_env(ikpgr)%kpoint_env
862 nspin = SIZE(kp%mos)
863 cpassert(ispin >= 1 .AND. ispin <= nspin)
864 mo_set => kp%mos(ispin)
865 CALL get_mo_set(mo_set, cmo_coeff=cfm_mo_coeff, nao=nao, nmo=nmo, &
866 eigenvalues=eigenvalues, occupation_numbers=occupation)
867
868 ! if this CPASSERT is triggered, please add all virtual MOs to SCF section,
869 ! e.g. ADDED_MOS 1000000
870 cpassert(nao == nmo)
871
872 ALLOCATE (exp_scaling(nmo))
873 CALL cp_cfm_create(cfm_work, cfm_mo_coeff%matrix_struct)
874 CALL cp_cfm_to_cfm(cfm_mo_coeff, cfm_work)
875
876 IF (sector == propagator_sector_occupied) THEN
877 CALL cp_cfm_column_scale(cfm_work, cmplx(occupation, 0.0_dp, kind=dp))
878 ELSE
879 CALL cp_cfm_column_scale(cfm_work, &
880 cmplx(2.0_dp/real(nspin, kind=dp) - occupation, 0.0_dp, kind=dp))
881 END IF
882
883 IF (nspin == 1) THEN
884 CALL cp_cfm_scale(0.5_dp, cfm_work)
885 END IF
886
887 DO i_mo = 1, nmo
888 IF (abs(tau*0.5_dp*(eigenvalues(i_mo) - e_fermi)) < stabilize_exp) THEN
889 exp_scaling(i_mo) = exp(-abs(tau*(eigenvalues(i_mo) - e_fermi)))
890 ELSE
891 exp_scaling(i_mo) = 0.0_dp
892 END IF
893 END DO
894
895 CALL cp_cfm_column_scale(cfm_work, cmplx(exp_scaling, 0.0_dp, kind=dp))
896 CALL parallel_gemm("N", "C", nao, nao, nmo, (1.0_dp, 0.0_dp), cfm_mo_coeff, cfm_work, &
897 (0.0_dp, 0.0_dp), density)
898
899 CALL cp_cfm_release(cfm_work)
900 DEALLOCATE (exp_scaling)
901
902 CALL timestop(handle)
903
904 END SUBROUTINE build_kpoint_density_matrix_rpa
905
906! **************************************************************************************************
907!> \brief ...
908!> \param propagator ...
909!> \param qs_env ...
910!> \param ispin ...
911!> \param num_integ_points ...
912!> \param jquad ...
913!> \param e_fermi ...
914!> \param tau ...
915!> \param eps_filter ...
916!> \param num_cells_dm ...
917!> \param index_to_cell_dm ...
918!> \param sector ...
919! **************************************************************************************************
920 SUBROUTINE compute_transl_dm(propagator, qs_env, ispin, num_integ_points, jquad, e_fermi, tau, &
921 eps_filter, num_cells_dm, index_to_cell_dm, &
922 sector)
923 TYPE(dbcsr_p_type), DIMENSION(:, :, :), &
924 INTENT(INOUT), POINTER :: propagator
925 TYPE(qs_environment_type), POINTER :: qs_env
926 INTEGER, INTENT(IN) :: ispin, num_integ_points, jquad
927 REAL(kind=dp), INTENT(IN) :: e_fermi, tau, eps_filter
928 INTEGER, INTENT(OUT) :: num_cells_dm
929 INTEGER, DIMENSION(:, :), POINTER :: index_to_cell_dm
930 INTEGER, INTENT(IN) :: sector
931
932 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_transl_dm'
933
934 INTEGER :: handle, i_dim, i_img, nao
935 INTEGER, DIMENSION(3) :: cell_grid_dm
936 TYPE(cell_type), POINTER :: cell
937 TYPE(cp_cfm_type) :: cfm_density
938 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mat_dm_global_work
939 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s_kp
940 TYPE(kpoint_type), POINTER :: kpoints
941
942 CALL timeset(routinen, handle)
943
944 CALL get_qs_env(qs_env, &
945 matrix_s_kp=matrix_s_kp, &
946 kpoints=kpoints, &
947 cell=cell)
948
949 ! we always use an odd number of image cells
950 ! CAUTION: also at another point, cell_grid_dm is defined, these definitions have to be identical
951 DO i_dim = 1, 3
952 cell_grid_dm(i_dim) = (kpoints%nkp_grid(i_dim)/2)*2 - 1
953 END DO
954
955 num_cells_dm = cell_grid_dm(1)*cell_grid_dm(2)*cell_grid_dm(3)
956
957 NULLIFY (mat_dm_global_work)
958 ! Only the requested spin is built.
959 CALL dbcsr_allocate_matrix_set(mat_dm_global_work, num_cells_dm)
960
961 DO i_img = 1, num_cells_dm
962
963 ALLOCATE (mat_dm_global_work(i_img)%matrix)
964 CALL dbcsr_create(matrix=mat_dm_global_work(i_img)%matrix, &
965 template=matrix_s_kp(1, 1)%matrix, &
966 ! matrix_type=dbcsr_type_symmetric)
967 matrix_type=dbcsr_type_no_symmetry)
968
969 CALL dbcsr_reserve_all_blocks(mat_dm_global_work(i_img)%matrix)
970
971 END DO
972
973 ! Reusable complex AO scratch for the k-point density source.
974 CALL get_mo_set(kpoints%kp_env(1)%kpoint_env%mos(1), nao=nao)
975 CALL cp_cfm_create(cfm_density, kpoints%kp_env(1)%kpoint_env%mos(1)%cmo_coeff%matrix_struct, &
976 nrow=nao, ncol=nao)
977
978 ! overwrite the cell indices in kpoints
979 CALL init_cell_index_rpa(cell_grid_dm, kpoints%cell_to_index, kpoints%index_to_cell, cell)
980
981 ! density matrices in real space, the cell vectors T for transforming are taken from kpoints%index_to_cell
982 ! (custom made for RPA) and not from sab_nl (which is symmetric and from SCF)
983 CALL density_matrix_from_kp_to_transl(kpoints, cfm_density, mat_dm_global_work, kpoints%index_to_cell, &
984 ispin, tau, e_fermi, sector)
985
986 CALL cp_cfm_release(cfm_density)
987
988 ! we need the index to cell for the density matrices later
989 index_to_cell_dm => kpoints%index_to_cell
990
991 ! The first request owns allocation of the complete time-indexed propagator set.
992 IF (.NOT. ASSOCIATED(propagator)) THEN
993 CALL create_propagator_matrix_set(propagator, num_integ_points, matrix_s_kp(1, 1)%matrix, &
994 kpoints%index_to_cell)
995 END IF
996
997 DO i_img = 1, num_cells_dm
998
999 ! filter to get rid of the blocks full with zeros on the lower half, otherwise blocks doubled
1000 CALL dbcsr_filter(mat_dm_global_work(i_img)%matrix, eps_filter)
1001
1002 CALL dbcsr_copy(propagator(sector, jquad, i_img)%matrix, &
1003 mat_dm_global_work(i_img)%matrix)
1004
1005 END DO
1006
1007 CALL dbcsr_deallocate_matrix_set(mat_dm_global_work)
1008
1009 CALL timestop(handle)
1010
1011 END SUBROUTINE compute_transl_dm
1012
1013! **************************************************************************************************
1014!> \brief ...
1015!> \param propagator ...
1016!> \param qs_env ...
1017!> \param ispin ...
1018!> \param num_integ_points ...
1019!> \param jquad ...
1020!> \param e_fermi ...
1021!> \param tau ...
1022!> \param sector ...
1023! **************************************************************************************************
1024 SUBROUTINE compute_periodic_dm(propagator, qs_env, ispin, num_integ_points, jquad, e_fermi, tau, &
1025 sector)
1026 TYPE(dbcsr_p_type), DIMENSION(:, :, :), &
1027 INTENT(INOUT), POINTER :: propagator
1028 TYPE(qs_environment_type), POINTER :: qs_env
1029 INTEGER, INTENT(IN) :: ispin, num_integ_points, jquad
1030 REAL(kind=dp), INTENT(IN) :: e_fermi, tau
1031 INTEGER, INTENT(IN) :: sector
1032
1033 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_periodic_dm'
1034
1035 INTEGER :: handle, nao, num_cells_dm
1036 INTEGER, DIMENSION(3, 1) :: index_to_cell_zero
1037 TYPE(cp_cfm_type) :: cfm_density
1038 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mat_dm_global_work
1039 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s_kp
1040 TYPE(kpoint_type), POINTER :: kpoints_g
1041
1042 CALL timeset(routinen, handle)
1043
1044 NULLIFY (matrix_s_kp)
1045
1046 CALL get_qs_env(qs_env, &
1047 matrix_s_kp=matrix_s_kp)
1048
1049 kpoints_g => qs_env%mp2_env%ri_rpa_im_time%kpoints_G
1050
1051 num_cells_dm = 1
1052 index_to_cell_zero = 0
1053
1054 NULLIFY (mat_dm_global_work)
1055 ! Only the requested spin is built.
1056 CALL dbcsr_allocate_matrix_set(mat_dm_global_work, num_cells_dm)
1057
1058 ! The first request owns allocation of the complete time-indexed propagator set.
1059 IF (.NOT. ASSOCIATED(propagator)) THEN
1060 CALL create_propagator_matrix_set(propagator, num_integ_points, matrix_s_kp(1, 1)%matrix, &
1061 index_to_cell_zero)
1062 END IF
1063
1064 ALLOCATE (mat_dm_global_work(1)%matrix)
1065 CALL dbcsr_create(matrix=mat_dm_global_work(1)%matrix, &
1066 template=matrix_s_kp(1, 1)%matrix, &
1067 matrix_type=dbcsr_type_no_symmetry)
1068
1069 CALL dbcsr_reserve_all_blocks(mat_dm_global_work(1)%matrix)
1070
1071 CALL dbcsr_set(mat_dm_global_work(1)%matrix, 0.0_dp)
1072
1073 ! Reusable complex AO scratch for the k-point density source.
1074 CALL get_mo_set(kpoints_g%kp_env(1)%kpoint_env%mos(1), nao=nao)
1075 CALL cp_cfm_create(cfm_density, kpoints_g%kp_env(1)%kpoint_env%mos(1)%cmo_coeff%matrix_struct, &
1076 nrow=nao, ncol=nao)
1077
1078 CALL density_matrix_from_kp_to_mic(kpoints_g, cfm_density, mat_dm_global_work, qs_env, ispin, tau, e_fermi, sector)
1079
1080 CALL cp_cfm_release(cfm_density)
1081
1082 CALL dbcsr_copy(propagator(sector, jquad, 1)%matrix, &
1083 mat_dm_global_work(1)%matrix)
1084
1085 CALL dbcsr_deallocate_matrix_set(mat_dm_global_work)
1086
1087 CALL timestop(handle)
1088
1089 END SUBROUTINE compute_periodic_dm
1090
1091 ! **************************************************************************************************
1092!> \brief ...
1093!> \param kpoints_G ...
1094!> \param density complex AO density scratch matrix
1095!> \param mat_dm_global_work ...
1096!> \param qs_env ...
1097!> \param ispin ...
1098!> \param tau ...
1099!> \param e_fermi ...
1100!> \param sector ...
1101! **************************************************************************************************
1102 SUBROUTINE density_matrix_from_kp_to_mic(kpoints_G, density, mat_dm_global_work, qs_env, ispin, tau, e_fermi, sector)
1103
1104 TYPE(kpoint_type), POINTER :: kpoints_g
1105 TYPE(cp_cfm_type), INTENT(INOUT) :: density
1106 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mat_dm_global_work
1107 TYPE(qs_environment_type), POINTER :: qs_env
1108 INTEGER, INTENT(IN) :: ispin
1109 REAL(kind=dp), INTENT(IN) :: tau, e_fermi
1110 INTEGER, INTENT(IN) :: sector
1111
1112 CHARACTER(LEN=*), PARAMETER :: routinen = 'density_matrix_from_kp_to_mic'
1113
1114 COMPLEX(KIND=dp), CONTIGUOUS, DIMENSION(:, :), &
1115 POINTER :: cfm_data
1116 INTEGER :: handle, iatom, iatom_old, ik, ik_global, &
1117 ik_old, irow, jatom, jatom_old, jcol, &
1118 nao, ncol_local, nrow_local, num_cells
1119 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_from_ao_index
1120 INTEGER, DIMENSION(:), POINTER :: col_indices, row_indices
1121 INTEGER, DIMENSION(:, :), POINTER :: index_to_cell
1122 REAL(kind=dp) :: contribution, weight_im, weight_re
1123 REAL(kind=dp), DIMENSION(3, 3) :: hmat
1124 REAL(kind=dp), DIMENSION(:), POINTER :: wkp
1125 REAL(kind=dp), DIMENSION(:, :), POINTER :: xkp
1126 TYPE(cell_type), POINTER :: cell
1127 TYPE(cp_fm_type) :: fm_mat_work
1128 TYPE(kpoint_env_type), POINTER :: kp
1129 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1130
1131 CALL timeset(routinen, handle)
1132
1133 NULLIFY (xkp, wkp)
1134
1135 CALL get_kpoint_info(kpoints_g, xkp=xkp, wkp=wkp)
1136 index_to_cell => kpoints_g%index_to_cell
1137 num_cells = SIZE(index_to_cell, 2)
1138
1139 CALL cp_cfm_get_info(density, nrow_global=nao, nrow_local=nrow_local, ncol_local=ncol_local, &
1140 row_indices=row_indices, col_indices=col_indices)
1141 CALL cp_fm_create(fm_mat_work, density%matrix_struct, set_zero=.true.)
1142
1143 ALLOCATE (atom_from_ao_index(nao))
1144
1145 CALL get_atom_index_from_basis_function_index(qs_env, atom_from_ao_index, nao, "ORB")
1146
1147 NULLIFY (cell, particle_set)
1148 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
1149 CALL get_cell(cell=cell, h=hmat)
1150
1151 iatom_old = 0
1152 jatom_old = 0
1153 ik_old = 0
1154
1155 CALL dbcsr_set(mat_dm_global_work(1)%matrix, 0.0_dp)
1156
1157 DO ik = 1, SIZE(kpoints_g%kp_env)
1158
1159 kp => kpoints_g%kp_env(ik)%kpoint_env
1160 ik_global = kp%nkpoint
1161 CALL build_kpoint_density_matrix_rpa(kpoints_g, ik, ispin, tau, e_fermi, sector, density)
1162 CALL cp_cfm_get_info(density, local_data=cfm_data)
1163
1164 DO irow = 1, nrow_local
1165 DO jcol = 1, ncol_local
1166
1167 iatom = atom_from_ao_index(row_indices(irow))
1168 jatom = atom_from_ao_index(col_indices(jcol))
1169
1170 IF (ik_global /= ik_old .OR. iatom /= iatom_old .OR. jatom /= jatom_old) THEN
1171
1172 CALL compute_weight_re_im(weight_re, weight_im, &
1173 num_cells, iatom, jatom, xkp(1:3, ik_global), wkp(ik_global), &
1174 cell, index_to_cell, hmat, particle_set)
1175
1176 iatom_old = iatom
1177 jatom_old = jatom
1178 ik_old = ik_global
1179
1180 END IF
1181
1182 contribution = real(cmplx(weight_re, -weight_im, kind=dp)*cfm_data(irow, jcol), kind=dp)
1183
1184 fm_mat_work%local_data(irow, jcol) = fm_mat_work%local_data(irow, jcol) + contribution
1185
1186 END DO
1187 END DO
1188
1189 END DO ! ik
1190
1191 CALL copy_fm_to_dbcsr(fm_mat_work, mat_dm_global_work(1)%matrix, keep_sparsity=.false.)
1192
1193 CALL cp_fm_set_all(fm_mat_work, 0.0_dp)
1194
1195 CALL cp_fm_release(fm_mat_work)
1196 DEALLOCATE (atom_from_ao_index)
1197
1198 CALL timestop(handle)
1199
1200 END SUBROUTINE density_matrix_from_kp_to_mic
1201
1202! **************************************************************************************************
1203!> \brief ...
1204!> \param kpoints ...
1205!> \param density complex AO density scratch matrix
1206!> \param mat_dm_global_work ...
1207!> \param index_to_cell ...
1208!> \param ispin ...
1209!> \param tau ...
1210!> \param e_fermi ...
1211!> \param sector ...
1212! **************************************************************************************************
1213 SUBROUTINE density_matrix_from_kp_to_transl(kpoints, density, mat_dm_global_work, index_to_cell, &
1214 ispin, tau, e_fermi, sector)
1215
1216 TYPE(kpoint_type), POINTER :: kpoints
1217 TYPE(cp_cfm_type), INTENT(INOUT) :: density
1218 TYPE(dbcsr_p_type), DIMENSION(:), INTENT(IN) :: mat_dm_global_work
1219 INTEGER, DIMENSION(:, :), INTENT(IN) :: index_to_cell
1220 INTEGER, INTENT(IN) :: ispin
1221 REAL(kind=dp), INTENT(IN) :: tau, e_fermi
1222 INTEGER, INTENT(IN) :: sector
1223
1224 CHARACTER(LEN=*), PARAMETER :: routinen = 'density_matrix_from_kp_to_transl'
1225
1226 INTEGER :: handle, icell, ik, ik_global, xcell, &
1227 ycell, zcell
1228 REAL(kind=dp) :: arg, coskl, sinkl
1229 REAL(kind=dp), DIMENSION(:), POINTER :: wkp
1230 REAL(kind=dp), DIMENSION(:, :), POINTER :: xkp
1231 TYPE(cp_fm_type) :: fm_mat_im, fm_mat_re
1232 TYPE(dbcsr_type), POINTER :: mat_work_im, mat_work_re
1233 TYPE(kpoint_env_type), POINTER :: kp
1234
1235 CALL timeset(routinen, handle)
1236
1237 NULLIFY (xkp, wkp)
1238
1239 NULLIFY (mat_work_re)
1240 CALL dbcsr_init_p(mat_work_re)
1241 CALL dbcsr_create(matrix=mat_work_re, &
1242 template=mat_dm_global_work(1)%matrix, &
1243 matrix_type=dbcsr_type_no_symmetry)
1244
1245 NULLIFY (mat_work_im)
1246 CALL dbcsr_init_p(mat_work_im)
1247 CALL dbcsr_create(matrix=mat_work_im, &
1248 template=mat_dm_global_work(1)%matrix, &
1249 matrix_type=dbcsr_type_no_symmetry)
1250
1251 CALL cp_fm_create(fm_mat_re, density%matrix_struct)
1252 CALL cp_fm_create(fm_mat_im, density%matrix_struct)
1253
1254 CALL get_kpoint_info(kpoints, xkp=xkp, wkp=wkp)
1255
1256 cpassert(SIZE(mat_dm_global_work) == SIZE(index_to_cell, 2))
1257
1258 DO icell = 1, SIZE(mat_dm_global_work)
1259
1260 CALL dbcsr_set(mat_dm_global_work(icell)%matrix, 0.0_dp)
1261
1262 END DO
1263
1264 DO ik = 1, SIZE(kpoints%kp_env)
1265
1266 kp => kpoints%kp_env(ik)%kpoint_env
1267 ik_global = kp%nkpoint
1268 CALL build_kpoint_density_matrix_rpa(kpoints, ik, ispin, tau, e_fermi, sector, density)
1269 CALL cp_cfm_to_fm(density, fm_mat_re, fm_mat_im)
1270
1271 CALL copy_fm_to_dbcsr(fm_mat_re, mat_work_re, keep_sparsity=.false.)
1272 CALL copy_fm_to_dbcsr(fm_mat_im, mat_work_im, keep_sparsity=.false.)
1273
1274 DO icell = 1, SIZE(mat_dm_global_work)
1275
1276 xcell = index_to_cell(1, icell)
1277 ycell = index_to_cell(2, icell)
1278 zcell = index_to_cell(3, icell)
1279
1280 arg = real(xcell, dp)*xkp(1, ik_global) + real(ycell, dp)*xkp(2, ik_global) + &
1281 REAL(zcell, dp)*xkp(3, ik_global)
1282 coskl = wkp(ik_global)*cos(twopi*arg)
1283 sinkl = wkp(ik_global)*sin(twopi*arg)
1284
1285 CALL dbcsr_add(mat_dm_global_work(icell)%matrix, mat_work_re, 1.0_dp, coskl)
1286 ! The real-space convention is Re(exp(i k R) G(k)).
1287 CALL dbcsr_add(mat_dm_global_work(icell)%matrix, mat_work_im, 1.0_dp, -sinkl)
1288
1289 END DO
1290
1291 END DO
1292
1293 CALL dbcsr_release_p(mat_work_re)
1294 CALL dbcsr_release_p(mat_work_im)
1295 CALL cp_fm_release(fm_mat_re)
1296 CALL cp_fm_release(fm_mat_im)
1297
1298 CALL timestop(handle)
1299
1300 END SUBROUTINE density_matrix_from_kp_to_transl
1301
1302! **************************************************************************************************
1303!> \brief ...
1304!> \param cell_grid ...
1305!> \param cell_to_index ...
1306!> \param index_to_cell ...
1307!> \param cell ...
1308! **************************************************************************************************
1309 SUBROUTINE init_cell_index_rpa(cell_grid, cell_to_index, index_to_cell, cell)
1310 INTEGER, DIMENSION(3), INTENT(IN) :: cell_grid
1311 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
1312 INTEGER, DIMENSION(:, :), POINTER :: index_to_cell
1313 TYPE(cell_type), INTENT(IN), POINTER :: cell
1314
1315 CHARACTER(LEN=*), PARAMETER :: routinen = 'init_cell_index_rpa'
1316
1317 INTEGER :: cell_counter, handle, i_cell, &
1318 index_min_dist, num_cells, xcell, &
1319 ycell, zcell
1320 INTEGER, DIMENSION(3) :: itm
1321 INTEGER, DIMENSION(:, :), POINTER :: index_to_cell_unsorted
1322 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index_unsorted
1323 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: abs_cell_vectors
1324 REAL(kind=dp), DIMENSION(3) :: cell_vector
1325 REAL(kind=dp), DIMENSION(3, 3) :: hmat
1326
1327 CALL timeset(routinen, handle)
1328
1329 CALL get_cell(cell=cell, h=hmat)
1330
1331 num_cells = cell_grid(1)*cell_grid(2)*cell_grid(3)
1332 itm(:) = cell_grid(:)/2
1333
1334 ! check that real space super lattice is a (2n+1)x(2m+1)x(2k+1) super lattice with the unit cell
1335 ! in the middle
1336 cpassert(cell_grid(1) /= itm(1)*2)
1337 cpassert(cell_grid(2) /= itm(2)*2)
1338 cpassert(cell_grid(3) /= itm(3)*2)
1339
1340 IF (ASSOCIATED(cell_to_index)) DEALLOCATE (cell_to_index)
1341 IF (ASSOCIATED(index_to_cell)) DEALLOCATE (index_to_cell)
1342
1343 ALLOCATE (cell_to_index_unsorted(-itm(1):itm(1), -itm(2):itm(2), -itm(3):itm(3)))
1344 cell_to_index_unsorted(:, :, :) = 0
1345
1346 ALLOCATE (index_to_cell_unsorted(3, num_cells))
1347 index_to_cell_unsorted(:, :) = 0
1348
1349 ALLOCATE (cell_to_index(-itm(1):itm(1), -itm(2):itm(2), -itm(3):itm(3)))
1350 cell_to_index(:, :, :) = 0
1351
1352 ALLOCATE (index_to_cell(3, num_cells))
1353 index_to_cell(:, :) = 0
1354
1355 ALLOCATE (abs_cell_vectors(1:num_cells))
1356
1357 cell_counter = 0
1358
1359 DO xcell = -itm(1), itm(1)
1360 DO ycell = -itm(2), itm(2)
1361 DO zcell = -itm(3), itm(3)
1362
1363 cell_counter = cell_counter + 1
1364 cell_to_index_unsorted(xcell, ycell, zcell) = cell_counter
1365
1366 index_to_cell_unsorted(1, cell_counter) = xcell
1367 index_to_cell_unsorted(2, cell_counter) = ycell
1368 index_to_cell_unsorted(3, cell_counter) = zcell
1369
1370 cell_vector(1:3) = matmul(hmat, real(index_to_cell_unsorted(1:3, cell_counter), dp))
1371
1372 abs_cell_vectors(cell_counter) = sqrt(cell_vector(1)**2 + cell_vector(2)**2 + cell_vector(3)**2)
1373
1374 END DO
1375 END DO
1376 END DO
1377
1378 ! first only do all symmetry non-equivalent cells, we need that because chi^T is computed for
1379 ! cell indices T from index_to_cell(:,1:num_cells/2+1)
1380 DO i_cell = 1, num_cells/2 + 1
1381
1382 index_min_dist = minloc(abs_cell_vectors(1:num_cells/2 + 1), dim=1)
1383
1384 xcell = index_to_cell_unsorted(1, index_min_dist)
1385 ycell = index_to_cell_unsorted(2, index_min_dist)
1386 zcell = index_to_cell_unsorted(3, index_min_dist)
1387
1388 index_to_cell(1, i_cell) = xcell
1389 index_to_cell(2, i_cell) = ycell
1390 index_to_cell(3, i_cell) = zcell
1391
1392 cell_to_index(xcell, ycell, zcell) = i_cell
1393
1394 abs_cell_vectors(index_min_dist) = 10000000000.0_dp
1395
1396 END DO
1397
1398 ! now all the remaining cells
1399 DO i_cell = num_cells/2 + 2, num_cells
1400
1401 index_min_dist = minloc(abs_cell_vectors(1:num_cells), dim=1)
1402
1403 xcell = index_to_cell_unsorted(1, index_min_dist)
1404 ycell = index_to_cell_unsorted(2, index_min_dist)
1405 zcell = index_to_cell_unsorted(3, index_min_dist)
1406
1407 index_to_cell(1, i_cell) = xcell
1408 index_to_cell(2, i_cell) = ycell
1409 index_to_cell(3, i_cell) = zcell
1410
1411 cell_to_index(xcell, ycell, zcell) = i_cell
1412
1413 abs_cell_vectors(index_min_dist) = 10000000000.0_dp
1414
1415 END DO
1416
1417 DEALLOCATE (index_to_cell_unsorted, cell_to_index_unsorted, abs_cell_vectors)
1418
1419 CALL timestop(handle)
1420
1421 END SUBROUTINE init_cell_index_rpa
1422
1423! **************************************************************************************************
1424!> \brief ...
1425!> \param i_cell_R ...
1426!> \param i_cell_S ...
1427!> \param i_cell_R_minus_S ...
1428!> \param index_to_cell_3c ...
1429!> \param cell_to_index_3c ...
1430!> \param index_to_cell_dm ...
1431!> \param R_minus_S_needed ...
1432!> \param do_kpoints_cubic_RPA ...
1433! **************************************************************************************************
1434 SUBROUTINE get_diff_index_3c(i_cell_R, i_cell_S, i_cell_R_minus_S, index_to_cell_3c, &
1435 cell_to_index_3c, index_to_cell_dm, R_minus_S_needed, &
1436 do_kpoints_cubic_RPA)
1437
1438 INTEGER, INTENT(IN) :: i_cell_r, i_cell_s
1439 INTEGER, INTENT(OUT) :: i_cell_r_minus_s
1440 INTEGER, ALLOCATABLE, DIMENSION(:, :), INTENT(IN) :: index_to_cell_3c
1441 INTEGER, ALLOCATABLE, DIMENSION(:, :, :), &
1442 INTENT(IN) :: cell_to_index_3c
1443 INTEGER, DIMENSION(:, :), INTENT(IN), POINTER :: index_to_cell_dm
1444 LOGICAL, INTENT(OUT) :: r_minus_s_needed
1445 LOGICAL, INTENT(IN) :: do_kpoints_cubic_rpa
1446
1447 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_diff_index_3c'
1448
1449 INTEGER :: handle, x_cell_r, x_cell_r_minus_s, x_cell_s, y_cell_r, y_cell_r_minus_s, &
1450 y_cell_s, z_cell_r, z_cell_r_minus_s, z_cell_s
1451
1452 CALL timeset(routinen, handle)
1453
1454 IF (do_kpoints_cubic_rpa) THEN
1455
1456 x_cell_r = index_to_cell_3c(1, i_cell_r)
1457 y_cell_r = index_to_cell_3c(2, i_cell_r)
1458 z_cell_r = index_to_cell_3c(3, i_cell_r)
1459
1460 x_cell_s = index_to_cell_dm(1, i_cell_s)
1461 y_cell_s = index_to_cell_dm(2, i_cell_s)
1462 z_cell_s = index_to_cell_dm(3, i_cell_s)
1463
1464 x_cell_r_minus_s = x_cell_r - x_cell_s
1465 y_cell_r_minus_s = y_cell_r - y_cell_s
1466 z_cell_r_minus_s = z_cell_r - z_cell_s
1467
1468 IF (x_cell_r_minus_s >= lbound(cell_to_index_3c, 1) .AND. &
1469 x_cell_r_minus_s <= ubound(cell_to_index_3c, 1) .AND. &
1470 y_cell_r_minus_s >= lbound(cell_to_index_3c, 2) .AND. &
1471 y_cell_r_minus_s <= ubound(cell_to_index_3c, 2) .AND. &
1472 z_cell_r_minus_s >= lbound(cell_to_index_3c, 3) .AND. &
1473 z_cell_r_minus_s <= ubound(cell_to_index_3c, 3)) THEN
1474
1475 i_cell_r_minus_s = cell_to_index_3c(x_cell_r_minus_s, y_cell_r_minus_s, z_cell_r_minus_s)
1476
1477 ! 0 means that there is no 3c index with this R-S vector because R-S is too big and the 3c integral is 0
1478 IF (i_cell_r_minus_s == 0) THEN
1479
1480 r_minus_s_needed = .false.
1481 i_cell_r_minus_s = 0
1482
1483 ELSE
1484
1485 r_minus_s_needed = .true.
1486
1487 END IF
1488
1489 ELSE
1490
1491 i_cell_r_minus_s = 0
1492 r_minus_s_needed = .false.
1493
1494 END IF
1495
1496 ELSE ! no k-points
1497
1498 r_minus_s_needed = .true.
1499 i_cell_r_minus_s = 1
1500
1501 END IF
1502
1503 CALL timestop(handle)
1504
1505 END SUBROUTINE get_diff_index_3c
1506
1507! **************************************************************************************************
1508!> \brief ...
1509!> \param i_cell_R ...
1510!> \param i_cell_S ...
1511!> \param i_cell_T ...
1512!> \param i_cell_R_minus_S_minus_T ...
1513!> \param index_to_cell_3c ...
1514!> \param cell_to_index_3c ...
1515!> \param index_to_cell_dm ...
1516!> \param R_minus_S_minus_T_needed ...
1517!> \param do_kpoints_cubic_RPA ...
1518! **************************************************************************************************
1519 SUBROUTINE get_diff_diff_index_3c(i_cell_R, i_cell_S, i_cell_T, i_cell_R_minus_S_minus_T, &
1520 index_to_cell_3c, cell_to_index_3c, index_to_cell_dm, &
1521 R_minus_S_minus_T_needed, &
1522 do_kpoints_cubic_RPA)
1523
1524 INTEGER, INTENT(IN) :: i_cell_r, i_cell_s, i_cell_t
1525 INTEGER, INTENT(OUT) :: i_cell_r_minus_s_minus_t
1526 INTEGER, DIMENSION(:, :), INTENT(IN) :: index_to_cell_3c
1527 INTEGER, ALLOCATABLE, DIMENSION(:, :, :), &
1528 INTENT(IN) :: cell_to_index_3c
1529 INTEGER, DIMENSION(:, :), INTENT(IN) :: index_to_cell_dm
1530 LOGICAL, INTENT(OUT) :: r_minus_s_minus_t_needed
1531 LOGICAL, INTENT(IN) :: do_kpoints_cubic_rpa
1532
1533 CHARACTER(LEN=*), PARAMETER :: routinen = 'get_diff_diff_index_3c'
1534
1535 INTEGER :: handle, x_cell_r, x_cell_r_minus_s_minus_t, x_cell_s, x_cell_t, y_cell_r, &
1536 y_cell_r_minus_s_minus_t, y_cell_s, y_cell_t, z_cell_r, z_cell_r_minus_s_minus_t, &
1537 z_cell_s, z_cell_t
1538
1539 CALL timeset(routinen, handle)
1540
1541 IF (do_kpoints_cubic_rpa) THEN
1542
1543 x_cell_r = index_to_cell_3c(1, i_cell_r)
1544 y_cell_r = index_to_cell_3c(2, i_cell_r)
1545 z_cell_r = index_to_cell_3c(3, i_cell_r)
1546
1547 x_cell_s = index_to_cell_dm(1, i_cell_s)
1548 y_cell_s = index_to_cell_dm(2, i_cell_s)
1549 z_cell_s = index_to_cell_dm(3, i_cell_s)
1550
1551 x_cell_t = index_to_cell_dm(1, i_cell_t)
1552 y_cell_t = index_to_cell_dm(2, i_cell_t)
1553 z_cell_t = index_to_cell_dm(3, i_cell_t)
1554
1555 x_cell_r_minus_s_minus_t = x_cell_r - x_cell_s - x_cell_t
1556 y_cell_r_minus_s_minus_t = y_cell_r - y_cell_s - y_cell_t
1557 z_cell_r_minus_s_minus_t = z_cell_r - z_cell_s - z_cell_t
1558
1559 IF (x_cell_r_minus_s_minus_t >= lbound(cell_to_index_3c, 1) .AND. &
1560 x_cell_r_minus_s_minus_t <= ubound(cell_to_index_3c, 1) .AND. &
1561 y_cell_r_minus_s_minus_t >= lbound(cell_to_index_3c, 2) .AND. &
1562 y_cell_r_minus_s_minus_t <= ubound(cell_to_index_3c, 2) .AND. &
1563 z_cell_r_minus_s_minus_t >= lbound(cell_to_index_3c, 3) .AND. &
1564 z_cell_r_minus_s_minus_t <= ubound(cell_to_index_3c, 3)) THEN
1565
1566 i_cell_r_minus_s_minus_t = cell_to_index_3c(x_cell_r_minus_s_minus_t, &
1567 y_cell_r_minus_s_minus_t, &
1568 z_cell_r_minus_s_minus_t)
1569
1570 ! index 0 means that there are only no 3c matrix elements because R-S-T is too big
1571 IF (i_cell_r_minus_s_minus_t == 0) THEN
1572
1573 r_minus_s_minus_t_needed = .false.
1574
1575 ELSE
1576
1577 r_minus_s_minus_t_needed = .true.
1578
1579 END IF
1580
1581 ELSE
1582
1583 i_cell_r_minus_s_minus_t = 0
1584 r_minus_s_minus_t_needed = .false.
1585
1586 END IF
1587
1588 ! no k-kpoints
1589 ELSE
1590
1591 r_minus_s_minus_t_needed = .true.
1592 i_cell_r_minus_s_minus_t = 1
1593
1594 END IF
1595
1596 CALL timestop(handle)
1597
1598 END SUBROUTINE get_diff_diff_index_3c
1599
1600END MODULE rpa_im_time
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
Definition cell_types.F:234
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_column_scale(matrix_a, scaling, first_col, source)
Scales columns of the full matrix by corresponding factors.
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.
subroutine, public cp_cfm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, matrix_struct, para_env)
Returns information about a full matrix.
subroutine, public cp_cfm_to_fm(msource, mtargetr, mtargeti)
Copy real and imaginary parts of a complex full matrix into separate real-value full matrices.
subroutine, public dbcsr_release_p(matrix)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_init_p(matrix)
...
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_clear(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_distribution_get(dist, row_dist, col_dist, nrows, ncols, has_threads, group, mynode, numnodes, nprows, npcols, myprow, mypcol, pgrid, subgroups_defined, prow_group, pcol_group)
...
subroutine, public dbcsr_reserve_all_blocks(matrix)
Reserves all blocks.
DBCSR operations in CP2K.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
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
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
This is the start of a dbt_api, all publically needed functions are exported here....
Definition dbt_api.F:17
Types and set/get functions for HFX.
Definition hfx_types.F:16
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
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered, lattice_fft)
Retrieve information from a kpoint environment.
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
Definition machine.F:127
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.
real(kind=dp), parameter, public twopi
Interface to the message passing library MPI.
Types needed for MP2 calculations.
Definition mp2_types.F:14
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count, cmo_coeff)
Get the components of a MO set data structure.
Utility methods to build 3-center integral tensors of various types.
subroutine, public create_2c_tensor(t2c, dist_1, dist_2, pgrid, sizes_1, sizes_2, order, name)
...
Utility methods to build 3-center integral tensors of various types.
Definition qs_tensors.F:11
subroutine, public decompress_tensor(tensor, blk_indices, compressed, eps)
...
subroutine, public get_tensor_occupancy(tensor, nze, occ)
...
Utility routines for RPA and GW with imaginary time.
subroutine, public compute_weight_re_im(weight_re, weight_im, num_cells, iatom, jatom, xkp, wkp_w, cell, index_to_cell, hmat, particle_set)
...
subroutine, public get_atom_index_from_basis_function_index(qs_env, atom_from_basis_index, basis_size, basis_type, first_bf_from_atom)
...
Routines for low-scaling RPA/GW with imaginary time.
Definition rpa_im_time.F:13
subroutine, public create_propagator_matrix_set(propagator, ntime, matrix_template, index_to_cell)
Creates the sector-, time-, and cell-resolved propagator matrix set.
Definition rpa_im_time.F:97
integer, parameter, public propagator_sector_virtual
Definition rpa_im_time.F:76
subroutine, public compute_periodic_dm(propagator, qs_env, ispin, num_integ_points, jquad, e_fermi, tau, sector)
...
subroutine, public init_cell_index_rpa(cell_grid, cell_to_index, index_to_cell, cell)
...
integer, parameter, public propagator_sector_occupied
Definition rpa_im_time.F:75
subroutine, public compute_mat_p_omega(mat_p_omega, fm_mo_coeff, homo, mat_p_global, matrix_s, ispin, t_3c_m, t_3c_o, t_3c_o_compressed, t_3c_o_ind, starts_array_mc, ends_array_mc, starts_array_mc_block, ends_array_mc_block, grid, e_fermi, eps_filter, alpha, eps_filter_im_time, eigenval, nmo, cut_memory, unit_nr, mp2_env, para_env, qs_env, do_kpoints_from_gamma, index_to_cell_3c, cell_to_index_3c, has_mat_p_blocks, do_ri_sos_laplace_mp2, dbcsr_time, dbcsr_nflop)
...
subroutine, public compute_gamma_propagator(propagator, jquad, fm_mo_coeff, homo, eigenval, nmo, eps_filter, e_fermi, tau, para_env)
Builds the Gamma-point occupied and virtual propagators.
subroutine, public compute_transl_dm(propagator, qs_env, ispin, num_integ_points, jquad, e_fermi, tau, eps_filter, num_cells_dm, index_to_cell_dm, sector)
...
subroutine, public compute_mat_dm_global(grid, nmo, fm_mo_coeff, homo, propagator, matrix_s, ispin, eigenval, e_fermi, eps_filter, memory_info, unit_nr, jquad, do_kpoints_cubic_rpa, do_kpoints_from_gamma, qs_env, num_cells_dm, index_to_cell_dm, para_env)
...
integer, parameter, public propagator_number_of_sectors
Definition rpa_im_time.F:77
Definition and construction of time/frequency grids for correlation methods.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
Represent a complex full matrix.
represent a full matrix
Keeps information about a specific k-point.
Contains information about kpoints.
stores all the informations relevant to an mpi environment