28 USE dbcsr_api,
ONLY: &
29 dbcsr_add, dbcsr_clear, dbcsr_copy, dbcsr_create, dbcsr_distribution_get, &
30 dbcsr_distribution_type, dbcsr_filter, dbcsr_get_info, dbcsr_init_p, dbcsr_p_type, &
31 dbcsr_release_p, dbcsr_reserve_all_blocks, dbcsr_scale, dbcsr_set, dbcsr_type, &
32 dbcsr_type_no_symmetry
34 dbt_batched_contract_finalize, dbt_batched_contract_init, dbt_contract, dbt_copy, &
35 dbt_copy_matrix_to_tensor, dbt_copy_tensor_to_matrix, dbt_create, dbt_destroy, dbt_filter, &
36 dbt_get_info, dbt_nblks_total, dbt_nd_mp_comm, dbt_pgrid_destroy, dbt_pgrid_type, dbt_type
61 #include "./base/base_uses.f90"
67 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'rpa_im_time'
122 fm_scaled_dm_virt_tau, fm_mo_coeff_occ, fm_mo_coeff_virt, &
123 fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, &
127 t_3c_M, t_3c_O, t_3c_O_compressed, t_3c_O_ind, &
128 starts_array_mc, ends_array_mc, &
129 starts_array_mc_block, ends_array_mc_block, &
130 weights_cos_tf_t_to_w, &
131 tj, tau_tj, e_fermi, eps_filter, &
132 alpha, eps_filter_im_time, Eigenval, nmo, &
133 num_integ_points, cut_memory, unit_nr, &
135 qs_env, do_kpoints_from_Gamma, &
136 index_to_cell_3c, cell_to_index_3c, &
137 has_mat_P_blocks, do_ri_sos_laplace_mp2, &
138 dbcsr_time, dbcsr_nflop)
139 TYPE(dbcsr_p_type),
DIMENSION(:, :),
INTENT(IN) :: mat_p_omega
140 TYPE(cp_fm_type),
INTENT(IN) :: fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, &
141 fm_mo_coeff_occ, fm_mo_coeff_virt, fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled
142 TYPE(dbcsr_p_type),
INTENT(INOUT) :: mat_p_global
143 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s
144 INTEGER,
INTENT(IN) :: ispin
145 TYPE(dbt_type),
INTENT(INOUT) :: t_3c_m
146 TYPE(dbt_type),
DIMENSION(:, :),
INTENT(INOUT) :: t_3c_o
147 TYPE(hfx_compression_type),
DIMENSION(:, :, :), &
148 INTENT(INOUT) :: t_3c_o_compressed
149 TYPE(block_ind_type),
DIMENSION(:, :, :), &
150 INTENT(INOUT) :: t_3c_o_ind
151 INTEGER,
DIMENSION(:),
INTENT(IN) :: starts_array_mc, ends_array_mc, &
152 starts_array_mc_block, &
154 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :), &
155 INTENT(IN) :: weights_cos_tf_t_to_w
156 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
158 INTEGER,
INTENT(IN) :: num_integ_points, nmo
159 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: eigenval
160 REAL(kind=
dp),
INTENT(IN) :: eps_filter_im_time, alpha, eps_filter, &
162 REAL(kind=
dp),
DIMENSION(0:num_integ_points), &
164 INTEGER,
INTENT(IN) :: cut_memory, unit_nr
165 TYPE(mp2_type) :: mp2_env
166 TYPE(mp_para_env_type),
INTENT(IN) :: para_env
167 TYPE(qs_environment_type),
POINTER :: qs_env
168 LOGICAL,
INTENT(IN) :: do_kpoints_from_gamma
169 INTEGER,
ALLOCATABLE,
DIMENSION(:, :),
INTENT(IN) :: index_to_cell_3c
170 INTEGER,
ALLOCATABLE,
DIMENSION(:, :, :), &
171 INTENT(IN) :: cell_to_index_3c
172 LOGICAL,
DIMENSION(:, :, :, :, :),
INTENT(INOUT) :: has_mat_p_blocks
173 LOGICAL,
INTENT(IN) :: do_ri_sos_laplace_mp2
174 REAL(
dp),
INTENT(INOUT) :: dbcsr_time
175 INTEGER(int_8),
INTENT(INOUT) :: dbcsr_nflop
177 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_mat_P_omega'
179 INTEGER :: comm_2d_handle, handle, handle2, handle3, i, i_cell, i_cell_r_1, &
180 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, &
181 i_cell_t, i_mem, iquad, j, j_mem, jquad, num_3c_repl, num_cells_dm, unit_nr_dbcsr
182 INTEGER(int_8) :: nze, nze_dm_occ, nze_dm_virt, nze_m_occ, &
184 INTEGER(KIND=int_8) :: flops_1_occ, flops_1_virt, flops_2
185 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: dist_1, dist_2, mc_ranges, size_dm, &
187 INTEGER,
DIMENSION(2) :: pdims_2d
188 INTEGER,
DIMENSION(2, 1) :: ibounds_2, jbounds_2
189 INTEGER,
DIMENSION(2, 2) :: ibounds_1, jbounds_1
190 INTEGER,
DIMENSION(3) :: bounds_3c
191 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell_dm
192 LOGICAL :: do_gamma_rpa, do_kpoints_cubic_rpa, first_cycle_im_time, first_cycle_omega_loop, &
193 memory_info, r_1_minus_s_needed, r_1_minus_t_needed, r_2_minus_s_minus_t_needed
194 REAL(
dp) :: occ, occ_dm_occ, occ_dm_virt, occ_m_occ, &
195 occ_m_virt, occ_o, t1_flop
196 REAL(kind=
dp) :: omega, omega_old, t1, t2, tau, weight, &
198 TYPE(dbcsr_distribution_type) :: dist_p
199 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_dm_occ_global, mat_dm_virt_global
200 TYPE(dbt_pgrid_type) :: pgrid_2d
201 TYPE(dbt_type) :: t_3c_m_occ, t_3c_m_occ_tmp, t_3c_m_virt, &
202 t_3c_m_virt_tmp, t_dm, t_dm_tmp, t_p, &
204 TYPE(dbt_type),
ALLOCATABLE,
DIMENSION(:) :: t_dm_occ, t_dm_virt
205 TYPE(dbt_type),
ALLOCATABLE,
DIMENSION(:, :) :: t_3c_o_occ, t_3c_o_virt
206 TYPE(mp_comm_type) :: comm_2d
208 CALL timeset(routinen, handle)
210 memory_info = mp2_env%ri_rpa_im_time%memory_info
211 IF (memory_info)
THEN
212 unit_nr_dbcsr = unit_nr
217 do_kpoints_cubic_rpa = qs_env%mp2_env%ri_rpa_im_time%do_im_time_kpoints
218 do_gamma_rpa = .NOT. do_kpoints_cubic_rpa
219 num_3c_repl = maxval(cell_to_index_3c)
221 first_cycle_im_time = .true.
222 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)))
223 DO i = 1,
SIZE(t_3c_o, 1)
224 DO j = 1,
SIZE(t_3c_o, 2)
225 CALL dbt_create(t_3c_o(i, j), t_3c_o_occ(i, j))
226 CALL dbt_create(t_3c_o(i, j), t_3c_o_virt(i, j))
230 CALL dbt_create(t_3c_m, t_3c_m_occ, name=
"M occ (RI | AO AO)")
231 CALL dbt_create(t_3c_m, t_3c_m_virt, name=
"M virt (RI | AO AO)")
233 ALLOCATE (mc_ranges(cut_memory + 1))
234 mc_ranges(:cut_memory) = starts_array_mc_block(:)
235 mc_ranges(cut_memory + 1) = ends_array_mc_block(cut_memory) + 1
237 DO jquad = 1, num_integ_points
242 CALL compute_mat_dm_global(fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, tau_tj, num_integ_points, nmo, &
243 fm_mo_coeff_occ, fm_mo_coeff_virt, fm_mo_coeff_occ_scaled, &
244 fm_mo_coeff_virt_scaled, mat_dm_occ_global, mat_dm_virt_global, &
246 eigenval, e_fermi, eps_filter, memory_info, unit_nr, &
247 jquad, do_kpoints_cubic_rpa, do_kpoints_from_gamma, qs_env, &
248 num_cells_dm, index_to_cell_dm, para_env)
250 ALLOCATE (t_dm_virt(num_cells_dm))
251 ALLOCATE (t_dm_occ(num_cells_dm))
252 CALL dbcsr_get_info(mat_p_global%matrix, distribution=dist_p)
253 CALL dbcsr_distribution_get(dist_p, group=comm_2d_handle, nprows=pdims_2d(1), npcols=pdims_2d(2))
254 CALL comm_2d%set_handle(comm_2d_handle)
256 pgrid_2d = dbt_nd_mp_comm(comm_2d, [1], [2], pdims_2d=pdims_2d)
257 ALLOCATE (size_p(dbt_nblks_total(t_3c_m, 1)))
258 CALL dbt_get_info(t_3c_m, blk_size_1=size_p)
260 ALLOCATE (size_dm(dbt_nblks_total(t_3c_o(1, 1), 3)))
261 CALL dbt_get_info(t_3c_o(1, 1), blk_size_3=size_dm)
262 CALL create_2c_tensor(t_dm, dist_1, dist_2, pgrid_2d, size_dm, size_dm, name=
"D (AO | AO)")
264 DEALLOCATE (dist_1, dist_2)
265 CALL create_2c_tensor(t_p, dist_1, dist_2, pgrid_2d, size_p, size_p, name=
"P (RI | RI)")
267 DEALLOCATE (dist_1, dist_2)
268 CALL dbt_pgrid_destroy(pgrid_2d)
270 DO i_cell = 1, num_cells_dm
271 CALL dbt_create(t_dm, t_dm_virt(i_cell), name=
"D virt (AO | AO)")
272 CALL dbt_create(mat_dm_virt_global(jquad, i_cell)%matrix, t_dm_tmp)
273 CALL dbt_copy_matrix_to_tensor(mat_dm_virt_global(jquad, i_cell)%matrix, t_dm_tmp)
274 CALL dbt_copy(t_dm_tmp, t_dm_virt(i_cell), move_data=.true.)
275 CALL dbcsr_clear(mat_dm_virt_global(jquad, i_cell)%matrix)
277 CALL dbt_create(t_dm, t_dm_occ(i_cell), name=
"D occ (AO | AO)")
278 CALL dbt_copy_matrix_to_tensor(mat_dm_occ_global(jquad, i_cell)%matrix, t_dm_tmp)
279 CALL dbt_copy(t_dm_tmp, t_dm_occ(i_cell), move_data=.true.)
280 CALL dbt_destroy(t_dm_tmp)
281 CALL dbcsr_clear(mat_dm_occ_global(jquad, i_cell)%matrix)
287 CALL dbt_destroy(t_dm)
289 CALL dbt_create(t_3c_o_occ(1, 1), t_3c_m_occ_tmp, name=
"M (RI AO | AO)")
290 CALL dbt_create(t_3c_o_virt(1, 1), t_3c_m_virt_tmp, name=
"M (RI AO | AO)")
292 CALL timeset(routinen//
"_contract", handle2)
297 DO i = 1,
SIZE(t_3c_o_occ, 1)
298 DO j = 1,
SIZE(t_3c_o_occ, 2)
299 CALL dbt_batched_contract_init(t_3c_o_occ(i, j), batch_range_2=mc_ranges, batch_range_3=mc_ranges)
302 DO i = 1,
SIZE(t_3c_o_virt, 1)
303 DO j = 1,
SIZE(t_3c_o_virt, 2)
304 CALL dbt_batched_contract_init(t_3c_o_virt(i, j), batch_range_2=mc_ranges, batch_range_3=mc_ranges)
307 CALL dbt_batched_contract_init(t_3c_m_occ_tmp, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
308 CALL dbt_batched_contract_init(t_3c_m_virt_tmp, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
309 CALL dbt_batched_contract_init(t_3c_m_occ, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
310 CALL dbt_batched_contract_init(t_3c_m_virt, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
312 DO i_cell_t = 1, num_cells_dm/2 + 1
314 IF (.NOT. any(has_mat_p_blocks(i_cell_t, :, :, :, :))) cycle
316 CALL dbt_batched_contract_init(t_p)
318 IF (do_gamma_rpa)
THEN
327 DO j_mem = 1, cut_memory
329 CALL dbt_get_info(t_3c_o_occ(1, 1), nfull_total=bounds_3c)
331 jbounds_1(:, 1) = [1, bounds_3c(1)]
332 jbounds_1(:, 2) = [starts_array_mc(j_mem), ends_array_mc(j_mem)]
334 jbounds_2(:, 1) = [starts_array_mc(j_mem), ends_array_mc(j_mem)]
336 IF (do_gamma_rpa)
CALL dbt_batched_contract_init(t_dm_virt(1))
338 DO i_mem = 1, cut_memory
340 IF (.NOT. any(has_mat_p_blocks(i_cell_t, i_mem, j_mem, :, :))) cycle
342 ibounds_1(:, 1) = [1, bounds_3c(1)]
343 ibounds_1(:, 2) = [starts_array_mc(i_mem), ends_array_mc(i_mem)]
345 ibounds_2(:, 1) = [starts_array_mc(i_mem), ends_array_mc(i_mem)]
347 IF (unit_nr_dbcsr > 0)
WRITE (unit=unit_nr_dbcsr, fmt=
"(T3,A,I3,1X,I3)") &
348 "RPA_LOW_SCALING_INFO| Memory Cut iteration", i_mem, j_mem
350 DO i_cell_r_1 = 1, num_3c_repl
352 DO i_cell_r_2 = 1, num_3c_repl
354 IF (.NOT. has_mat_p_blocks(i_cell_t, i_mem, j_mem, i_cell_r_1, i_cell_r_2)) cycle
356 CALL get_diff_index_3c(i_cell_r_1, i_cell_t, i_cell_r_1_minus_t, &
357 index_to_cell_3c, cell_to_index_3c, index_to_cell_dm, &
358 r_1_minus_t_needed, do_kpoints_cubic_rpa)
360 IF (do_gamma_rpa)
CALL dbt_batched_contract_init(t_dm_occ(1))
361 DO i_cell_s = 1, num_cells_dm
362 CALL get_diff_index_3c(i_cell_r_1, i_cell_s, i_cell_r_1_minus_s, index_to_cell_3c, &
363 cell_to_index_3c, index_to_cell_dm, r_1_minus_s_needed, &
364 do_kpoints_cubic_rpa)
365 IF (r_1_minus_s_needed)
THEN
367 CALL timeset(routinen//
"_calc_M_occ_t", handle3)
369 t_3c_o_ind(i_cell_r_1_minus_s, i_cell_r_2, j_mem)%ind, &
370 t_3c_o_compressed(i_cell_r_1_minus_s, i_cell_r_2, j_mem), &
371 qs_env%mp2_env%ri_rpa_im_time%eps_compress)
373 IF (do_gamma_rpa .AND. i_mem == 1)
THEN
379 CALL dbt_copy(t_3c_o(i_cell_r_1_minus_s, i_cell_r_2), &
380 t_3c_o_occ(i_cell_r_1_minus_s, i_cell_r_2), move_data=.true.)
382 CALL dbt_contract(alpha=1.0_dp, &
383 tensor_1=t_3c_o_occ(i_cell_r_1_minus_s, i_cell_r_2), &
384 tensor_2=t_dm_occ(i_cell_s), &
386 tensor_3=t_3c_m_occ_tmp, &
387 contract_1=[3], notcontract_1=[1, 2], &
388 contract_2=[2], notcontract_2=[1], &
389 map_1=[1, 2], map_2=[3], &
390 bounds_2=jbounds_1, bounds_3=ibounds_2, &
391 filter_eps=eps_filter, unit_nr=unit_nr_dbcsr, &
393 CALL timestop(handle3)
395 dbcsr_nflop = dbcsr_nflop + flops_1_occ
400 IF (do_gamma_rpa)
CALL dbt_batched_contract_finalize(t_dm_occ(1))
405 CALL timeset(routinen//
"_copy_M_occ_t", handle3)
406 CALL dbt_copy(t_3c_m_occ_tmp, t_3c_m_occ, order=[1, 3, 2], move_data=.true.)
407 CALL dbt_filter(t_3c_m_occ, eps_filter)
408 CALL timestop(handle3)
410 IF (do_gamma_rpa)
THEN
412 nze_m_occ = nze_m_occ + nze
413 occ_m_occ = occ_m_occ + occ
416 DO i_cell_s = 1, num_cells_dm
417 CALL get_diff_diff_index_3c(i_cell_r_2, i_cell_s, i_cell_t, i_cell_r_2_minus_s_minus_t, &
418 index_to_cell_3c, cell_to_index_3c, index_to_cell_dm, &
419 r_2_minus_s_minus_t_needed, do_kpoints_cubic_rpa)
421 IF (r_1_minus_t_needed .AND. r_2_minus_s_minus_t_needed)
THEN
423 t_3c_o_ind(i_cell_r_2_minus_s_minus_t, i_cell_r_1_minus_t, i_mem)%ind, &
424 t_3c_o_compressed(i_cell_r_2_minus_s_minus_t, i_cell_r_1_minus_t, i_mem), &
425 qs_env%mp2_env%ri_rpa_im_time%eps_compress)
427 CALL dbt_copy(t_3c_o(i_cell_r_2_minus_s_minus_t, i_cell_r_1_minus_t), &
428 t_3c_o_virt(i_cell_r_2_minus_s_minus_t, i_cell_r_1_minus_t), move_data=.true.)
430 CALL timeset(routinen//
"_calc_M_virt_t", handle3)
431 CALL dbt_contract(alpha=alpha/2.0_dp, &
432 tensor_1=t_3c_o_virt( &
433 i_cell_r_2_minus_s_minus_t, i_cell_r_1_minus_t), &
434 tensor_2=t_dm_virt(i_cell_s), &
436 tensor_3=t_3c_m_virt_tmp, &
437 contract_1=[3], notcontract_1=[1, 2], &
438 contract_2=[2], notcontract_2=[1], &
439 map_1=[1, 2], map_2=[3], &
440 bounds_2=ibounds_1, bounds_3=jbounds_2, &
441 filter_eps=eps_filter, unit_nr=unit_nr_dbcsr, &
443 CALL timestop(handle3)
445 dbcsr_nflop = dbcsr_nflop + flops_1_virt
450 CALL timeset(routinen//
"_copy_M_virt_t", handle3)
451 CALL dbt_copy(t_3c_m_virt_tmp, t_3c_m_virt, move_data=.true.)
452 CALL dbt_filter(t_3c_m_virt, eps_filter)
453 CALL timestop(handle3)
455 IF (do_gamma_rpa)
THEN
457 nze_m_virt = nze_m_virt + nze
458 occ_m_virt = occ_m_virt + occ
463 CALL timeset(routinen//
"_calc_P_t", handle3)
465 CALL dbt_contract(alpha=1.0_dp, tensor_1=t_3c_m_occ, &
466 tensor_2=t_3c_m_virt, &
469 contract_1=[2, 3], notcontract_1=[1], &
470 contract_2=[2, 3], notcontract_2=[1], &
471 map_1=[1], map_2=[2], &
472 filter_eps=eps_filter_im_time/real(cut_memory**2, kind=
dp), &
475 unit_nr=unit_nr_dbcsr)
477 CALL timestop(handle3)
479 first_cycle_im_time = .false.
481 IF (jquad == 1 .AND. flops_2 == 0) &
482 has_mat_p_blocks(i_cell_t, i_mem, j_mem, i_cell_r_1, i_cell_r_2) = .false.
487 IF (do_gamma_rpa)
CALL dbt_batched_contract_finalize(t_dm_virt(1))
490 CALL dbt_batched_contract_finalize(t_p, unit_nr=unit_nr_dbcsr)
492 CALL dbt_create(mat_p_global%matrix, t_p_tmp)
493 CALL dbt_copy(t_p, t_p_tmp, move_data=.true.)
494 CALL dbt_copy_tensor_to_matrix(t_p_tmp, mat_p_global%matrix)
495 CALL dbt_destroy(t_p_tmp)
497 IF (do_ri_sos_laplace_mp2)
THEN
501 CALL dbcsr_add(mat_p_omega(jquad, i_cell_t)%matrix, mat_p_global%matrix, 1.0_dp, 1.0_dp)
503 CALL timeset(routinen//
"_Fourier_transform", handle3)
506 first_cycle_omega_loop = .true.
510 DO iquad = 1, num_integ_points
513 weight = weights_cos_tf_t_to_w(iquad, jquad)
515 IF (first_cycle_omega_loop)
THEN
518 CALL dbcsr_scale(mat_p_global%matrix, cos(omega*tau)*weight)
520 CALL dbcsr_scale(mat_p_global%matrix, cos(omega*tau)/cos(omega_old*tau)*weight/weight_old)
523 CALL dbcsr_add(mat_p_omega(iquad, i_cell_t)%matrix, mat_p_global%matrix, 1.0_dp, 1.0_dp)
525 first_cycle_omega_loop = .false.
532 CALL timestop(handle3)
537 CALL timestop(handle2)
539 CALL dbt_batched_contract_finalize(t_3c_m_occ_tmp)
540 CALL dbt_batched_contract_finalize(t_3c_m_virt_tmp)
541 CALL dbt_batched_contract_finalize(t_3c_m_occ)
542 CALL dbt_batched_contract_finalize(t_3c_m_virt)
544 DO i = 1,
SIZE(t_3c_o_occ, 1)
545 DO j = 1,
SIZE(t_3c_o_occ, 2)
546 CALL dbt_batched_contract_finalize(t_3c_o_occ(i, j))
550 DO i = 1,
SIZE(t_3c_o_virt, 1)
551 DO j = 1,
SIZE(t_3c_o_virt, 2)
552 CALL dbt_batched_contract_finalize(t_3c_o_virt(i, j))
556 CALL dbt_destroy(t_p)
557 DO i_cell = 1, num_cells_dm
558 CALL dbt_destroy(t_dm_virt(i_cell))
559 CALL dbt_destroy(t_dm_occ(i_cell))
562 CALL dbt_destroy(t_3c_m_occ_tmp)
563 CALL dbt_destroy(t_3c_m_virt_tmp)
564 DEALLOCATE (t_dm_virt)
565 DEALLOCATE (t_dm_occ)
570 dbcsr_time = dbcsr_time + t2 - t1_flop
572 IF (unit_nr > 0)
THEN
573 WRITE (unit_nr,
'(/T3,A,1X,I3)') &
574 'RPA_LOW_SCALING_INFO| Info for time point', jquad
575 WRITE (unit_nr,
'(T6,A,T56,F25.1)') &
576 'Execution time (s):', t2 - t1
577 WRITE (unit_nr,
'(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
578 'Occupancy of D occ:', real(nze_dm_occ,
dp),
'/', occ_dm_occ*100,
'%'
579 WRITE (unit_nr,
'(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
580 'Occupancy of D virt:', real(nze_dm_virt,
dp),
'/', occ_dm_virt*100,
'%'
581 IF (do_gamma_rpa)
THEN
582 WRITE (unit_nr,
'(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
583 'Occupancy of 3c ints:', real(nze_o,
dp),
'/', occ_o*100,
'%'
584 WRITE (unit_nr,
'(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
585 'Occupancy of M occ:', real(nze_m_occ,
dp),
'/', occ_m_occ*100,
'%'
586 WRITE (unit_nr,
'(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
587 'Occupancy of M virt:', real(nze_m_virt,
dp),
'/', occ_m_virt*100,
'%'
595 CALL dbt_destroy(t_3c_m_occ)
596 CALL dbt_destroy(t_3c_m_virt)
598 DO i = 1,
SIZE(t_3c_o, 1)
599 DO j = 1,
SIZE(t_3c_o, 2)
600 CALL dbt_destroy(t_3c_o_occ(i, j))
601 CALL dbt_destroy(t_3c_o_virt(i, j))
605 CALL clean_up(mat_dm_occ_global, mat_dm_virt_global)
607 CALL timestop(handle)
616 TYPE(dbcsr_p_type),
DIMENSION(:, :),
INTENT(IN) :: mat_p_omega
618 INTEGER :: i_kp, jquad
620 DO jquad = 1,
SIZE(mat_p_omega, 1)
621 DO i_kp = 1,
SIZE(mat_p_omega, 2)
623 CALL dbcsr_set(mat_p_omega(jquad, i_kp)%matrix, 0.0_dp)
659 fm_mo_coeff_occ, fm_mo_coeff_virt, fm_mo_coeff_occ_scaled, &
660 fm_mo_coeff_virt_scaled, mat_dm_occ_global, mat_dm_virt_global, &
662 Eigenval, e_fermi, eps_filter, memory_info, unit_nr, &
663 jquad, do_kpoints_cubic_RPA, do_kpoints_from_Gamma, qs_env, &
664 num_cells_dm, index_to_cell_dm, para_env)
666 TYPE(cp_fm_type),
INTENT(IN) :: fm_scaled_dm_occ_tau, &
667 fm_scaled_dm_virt_tau
668 INTEGER,
INTENT(IN) :: num_integ_points
669 REAL(kind=
dp),
DIMENSION(0:num_integ_points), &
671 INTEGER,
INTENT(IN) :: nmo
672 TYPE(cp_fm_type),
INTENT(IN) :: fm_mo_coeff_occ, fm_mo_coeff_virt, &
673 fm_mo_coeff_occ_scaled, &
674 fm_mo_coeff_virt_scaled
675 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_dm_occ_global, mat_dm_virt_global
676 TYPE(dbcsr_p_type),
DIMENSION(:),
INTENT(IN) :: matrix_s
677 INTEGER,
INTENT(IN) :: ispin
678 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: eigenval
679 REAL(kind=
dp),
INTENT(IN) :: e_fermi, eps_filter
680 LOGICAL,
INTENT(IN) :: memory_info
681 INTEGER,
INTENT(IN) :: unit_nr, jquad
682 LOGICAL,
INTENT(IN) :: do_kpoints_cubic_rpa, &
683 do_kpoints_from_gamma
684 TYPE(qs_environment_type),
POINTER :: qs_env
685 INTEGER,
INTENT(OUT) :: num_cells_dm
686 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell_dm
687 TYPE(mp_para_env_type),
INTENT(IN) :: para_env
689 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_mat_dm_global'
690 REAL(kind=
dp),
PARAMETER :: stabilize_exp = 70.0_dp
692 INTEGER :: handle, i_global, iib, iquad, jjb, &
693 ncol_local, nrow_local, size_dm_occ, &
695 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
698 CALL timeset(routinen, handle)
700 IF (memory_info .AND. unit_nr > 0)
WRITE (unit=unit_nr, fmt=
"(T3,A,T75,i6)") &
701 "RPA_LOW_SCALING_INFO| Started with time point: ", jquad
705 IF (do_kpoints_cubic_rpa)
THEN
708 ispin, num_integ_points, jquad, e_fermi, tau, &
709 eps_filter, num_cells_dm, index_to_cell_dm, &
710 remove_occ=.false., remove_virt=.true., first_jquad=1)
713 ispin, num_integ_points, jquad, e_fermi, tau, &
714 eps_filter, num_cells_dm, index_to_cell_dm, &
715 remove_occ=.true., remove_virt=.false., first_jquad=1)
717 ELSE IF (do_kpoints_from_gamma)
THEN
720 ispin, num_integ_points, jquad, e_fermi, tau, &
721 remove_occ=.false., remove_virt=.true., &
722 alloc_dm=(jquad == 1))
725 ispin, num_integ_points, jquad, e_fermi, tau, &
726 remove_occ=.true., remove_virt=.false., &
727 alloc_dm=(jquad == 1))
739 nrow_local=nrow_local, &
740 ncol_local=ncol_local, &
741 row_indices=row_indices, &
742 col_indices=col_indices)
749 DO jjb = 1, nrow_local
750 DO iib = 1, ncol_local
751 i_global = col_indices(iib)
755 IF (abs(tau*0.5_dp*(eigenval(i_global) - e_fermi)) < stabilize_exp)
THEN
756 fm_mo_coeff_occ_scaled%local_data(jjb, iib) = &
757 fm_mo_coeff_occ%local_data(jjb, iib)*exp(tau*0.5_dp*(eigenval(i_global) - e_fermi))
759 fm_mo_coeff_occ_scaled%local_data(jjb, iib) = 0.0_dp
767 nrow_local=nrow_local, &
768 ncol_local=ncol_local, &
769 row_indices=row_indices, &
770 col_indices=col_indices)
773 DO jjb = 1, nrow_local
774 DO iib = 1, ncol_local
775 i_global = col_indices(iib)
777 IF (abs(tau*0.5_dp*(eigenval(i_global) - e_fermi)) < stabilize_exp)
THEN
778 fm_mo_coeff_virt_scaled%local_data(jjb, iib) = &
779 fm_mo_coeff_virt%local_data(jjb, iib)*exp(-tau*0.5_dp*(eigenval(i_global) - e_fermi))
781 fm_mo_coeff_virt_scaled%local_data(jjb, iib) = 0.0_dp
792 CALL parallel_gemm(transa=
"N", transb=
"T", m=size_dm_occ, n=size_dm_occ, k=nmo, alpha=1.0_dp, &
793 matrix_a=fm_mo_coeff_occ_scaled, matrix_b=fm_mo_coeff_occ_scaled, beta=0.0_dp, &
794 matrix_c=fm_scaled_dm_occ_tau)
796 CALL parallel_gemm(transa=
"N", transb=
"T", m=size_dm_virt, n=size_dm_virt, k=nmo, alpha=1.0_dp, &
797 matrix_a=fm_mo_coeff_virt_scaled, matrix_b=fm_mo_coeff_virt_scaled, beta=0.0_dp, &
798 matrix_c=fm_scaled_dm_virt_tau)
803 NULLIFY (mat_dm_occ_global)
806 DO iquad = 1, num_integ_points
808 ALLOCATE (mat_dm_occ_global(iquad, 1)%matrix)
809 CALL dbcsr_create(matrix=mat_dm_occ_global(iquad, 1)%matrix, &
810 template=matrix_s(1)%matrix, &
811 matrix_type=dbcsr_type_no_symmetry)
818 mat_dm_occ_global(jquad, 1)%matrix, &
819 keep_sparsity=.false.)
821 CALL dbcsr_filter(mat_dm_occ_global(jquad, 1)%matrix, eps_filter)
825 NULLIFY (mat_dm_virt_global)
830 ALLOCATE (mat_dm_virt_global(jquad, 1)%matrix)
831 CALL dbcsr_create(matrix=mat_dm_virt_global(jquad, 1)%matrix, &
832 template=matrix_s(1)%matrix, &
833 matrix_type=dbcsr_type_no_symmetry)
835 mat_dm_virt_global(jquad, 1)%matrix, &
836 keep_sparsity=.false.)
838 CALL dbcsr_filter(mat_dm_virt_global(jquad, 1)%matrix, eps_filter)
842 CALL dbcsr_set(mat_dm_occ_global(jquad - 1, 1)%matrix, 0.0_dp)
843 CALL dbcsr_set(mat_dm_virt_global(jquad - 1, 1)%matrix, 0.0_dp)
844 CALL dbcsr_filter(mat_dm_occ_global(jquad - 1, 1)%matrix, 0.0_dp)
845 CALL dbcsr_filter(mat_dm_virt_global(jquad - 1, 1)%matrix, 0.0_dp)
850 CALL timestop(handle)
859 SUBROUTINE clean_up(mat_dm_occ_global, mat_dm_virt_global)
860 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_dm_occ_global, mat_dm_virt_global
865 END SUBROUTINE clean_up
875 SUBROUTINE kpoint_density_matrices_rpa(kpoint, tau, e_fermi, remove_occ, remove_virt)
877 TYPE(kpoint_type),
POINTER :: kpoint
878 REAL(kind=
dp),
INTENT(IN) :: tau, e_fermi
879 LOGICAL,
INTENT(IN) :: remove_occ, remove_virt
881 CHARACTER(LEN=*),
PARAMETER :: routinen =
'kpoint_density_matrices_rpa'
882 REAL(kind=
dp),
PARAMETER :: stabilize_exp = 70.0_dp
884 INTEGER :: handle, i_mo, ikpgr, ispin, kplocal, &
886 INTEGER,
DIMENSION(2) :: kp_range
887 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues, exp_scaling, occupation
888 TYPE(cp_fm_struct_type),
POINTER :: matrix_struct
889 TYPE(cp_fm_type) :: fwork
890 TYPE(cp_fm_type),
POINTER :: cpmat, rpmat
891 TYPE(kpoint_env_type),
POINTER :: kp
892 TYPE(mo_set_type),
POINTER :: mo_set
894 CALL timeset(routinen, handle)
897 cpassert(kpoint%use_real_wfn .EQV. .false.)
900 mo_set => kpoint%kp_env(1)%kpoint_env%mos(1, 1)
907 ALLOCATE (exp_scaling(nmo))
913 kplocal = kp_range(2) - kp_range(1) + 1
915 DO ikpgr = 1, kplocal
916 kp => kpoint%kp_env(ikpgr)%kpoint_env
917 nspin =
SIZE(kp%mos, 2)
919 mo_set => kp%mos(1, ispin)
920 CALL get_mo_set(mo_set, eigenvalues=eigenvalues)
921 rpmat => kp%wmat(1, ispin)
922 cpmat => kp%wmat(2, ispin)
923 CALL get_mo_set(mo_set, occupation_numbers=occupation)
924 CALL cp_fm_to_fm(mo_set%mo_coeff, fwork)
926 IF (remove_virt)
THEN
940 IF (abs(tau*0.5_dp*(eigenvalues(i_mo) - e_fermi)) < stabilize_exp)
THEN
941 exp_scaling(i_mo) = exp(-abs(tau*(eigenvalues(i_mo) - e_fermi)))
943 exp_scaling(i_mo) = 0.0_dp
950 CALL parallel_gemm(
"N",
"T", nao, nao, nmo, 1.0_dp, mo_set%mo_coeff, fwork, 0.0_dp, rpmat)
951 mo_set => kp%mos(2, ispin)
953 CALL parallel_gemm(
"N",
"T", nao, nao, nmo, -1.0_dp, mo_set%mo_coeff, fwork, 0.0_dp, cpmat)
955 CALL parallel_gemm(
"N",
"T", nao, nao, nmo, 1.0_dp, fwork, mo_set%mo_coeff, 1.0_dp, cpmat)
957 CALL cp_fm_to_fm(mo_set%mo_coeff, fwork)
959 IF (remove_virt)
THEN
972 IF (abs(tau*0.5_dp*(eigenvalues(i_mo) - e_fermi)) < stabilize_exp)
THEN
973 exp_scaling(i_mo) = exp(-abs(tau*(eigenvalues(i_mo) - e_fermi)))
975 exp_scaling(i_mo) = 0.0_dp
981 CALL parallel_gemm(
"N",
"T", nao, nao, nmo, 1.0_dp, mo_set%mo_coeff, fwork, 1.0_dp, rpmat)
987 CALL cp_fm_release(fwork)
988 DEALLOCATE (exp_scaling)
990 CALL timestop(handle)
992 END SUBROUTINE kpoint_density_matrices_rpa
1011 eps_filter, num_cells_dm, index_to_cell_dm, remove_occ, remove_virt, &
1013 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_dm_global
1014 TYPE(qs_environment_type),
POINTER :: qs_env
1015 INTEGER,
INTENT(IN) :: ispin, num_integ_points, jquad
1016 REAL(kind=
dp),
INTENT(IN) :: e_fermi, tau, eps_filter
1017 INTEGER,
INTENT(OUT) :: num_cells_dm
1018 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell_dm
1019 LOGICAL,
INTENT(IN) :: remove_occ, remove_virt
1020 INTEGER,
INTENT(IN) :: first_jquad
1022 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_transl_dm'
1024 INTEGER :: handle, i_dim, i_img, iquad, jspin, nspin
1025 INTEGER,
DIMENSION(3) :: cell_grid_dm
1026 TYPE(cell_type),
POINTER :: cell
1027 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_dm_global_work, matrix_s_kp
1028 TYPE(kpoint_type),
POINTER :: kpoints
1029 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
1031 CALL timeset(routinen, handle)
1034 matrix_s_kp=matrix_s_kp, &
1044 cell_grid_dm(i_dim) = (kpoints%nkp_grid(i_dim)/2)*2 - 1
1047 num_cells_dm = cell_grid_dm(1)*cell_grid_dm(2)*cell_grid_dm(3)
1049 NULLIFY (mat_dm_global_work)
1054 DO i_img = 1, num_cells_dm
1056 ALLOCATE (mat_dm_global_work(jspin, i_img)%matrix)
1057 CALL dbcsr_create(matrix=mat_dm_global_work(jspin, i_img)%matrix, &
1058 template=matrix_s_kp(1, 1)%matrix, &
1060 matrix_type=dbcsr_type_no_symmetry)
1062 CALL dbcsr_reserve_all_blocks(mat_dm_global_work(jspin, i_img)%matrix)
1064 CALL dbcsr_set(mat_dm_global_work(ispin, i_img)%matrix, 0.0_dp)
1071 CALL kpoint_density_matrices_rpa(kpoints, tau, e_fermi, &
1072 remove_occ=remove_occ, remove_virt=remove_virt)
1075 CALL init_cell_index_rpa(cell_grid_dm, kpoints%cell_to_index, kpoints%index_to_cell, cell)
1079 CALL density_matrix_from_kp_to_transl(kpoints, mat_dm_global_work, kpoints%index_to_cell)
1082 index_to_cell_dm => kpoints%index_to_cell
1085 IF (jquad == first_jquad)
THEN
1087 NULLIFY (mat_dm_global)
1088 ALLOCATE (mat_dm_global(first_jquad:num_integ_points, num_cells_dm))
1090 DO iquad = first_jquad, num_integ_points
1091 DO i_img = 1, num_cells_dm
1092 NULLIFY (mat_dm_global(iquad, i_img)%matrix)
1093 ALLOCATE (mat_dm_global(iquad, i_img)%matrix)
1094 CALL dbcsr_create(matrix=mat_dm_global(iquad, i_img)%matrix, &
1095 template=matrix_s_kp(1, 1)%matrix, &
1096 matrix_type=dbcsr_type_no_symmetry)
1103 DO i_img = 1, num_cells_dm
1106 CALL dbcsr_filter(mat_dm_global_work(ispin, i_img)%matrix, eps_filter)
1108 CALL dbcsr_copy(mat_dm_global(jquad, i_img)%matrix, &
1109 mat_dm_global_work(ispin, i_img)%matrix)
1115 CALL timestop(handle)
1133 remove_occ, remove_virt, alloc_dm)
1134 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_dm_global
1135 TYPE(qs_environment_type),
POINTER :: qs_env
1136 INTEGER,
INTENT(IN) :: ispin, num_integ_points, jquad
1137 REAL(kind=
dp),
INTENT(IN) :: e_fermi, tau
1138 LOGICAL,
INTENT(IN) :: remove_occ, remove_virt, alloc_dm
1140 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_periodic_dm'
1142 INTEGER :: handle, iquad, jspin, nspin, num_cells_dm
1143 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_dm_global_work, matrix_s_kp
1144 TYPE(kpoint_type),
POINTER :: kpoints_g
1145 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
1147 CALL timeset(routinen, handle)
1149 NULLIFY (matrix_s_kp, mos)
1152 matrix_s_kp=matrix_s_kp, &
1155 kpoints_g => qs_env%mp2_env%ri_rpa_im_time%kpoints_G
1161 NULLIFY (mat_dm_global_work)
1167 NULLIFY (mat_dm_global)
1168 ALLOCATE (mat_dm_global(1:num_integ_points, num_cells_dm))
1170 DO iquad = 1, num_integ_points
1171 NULLIFY (mat_dm_global(iquad, 1)%matrix)
1172 ALLOCATE (mat_dm_global(iquad, 1)%matrix)
1173 CALL dbcsr_create(matrix=mat_dm_global(iquad, 1)%matrix, &
1174 template=matrix_s_kp(1, 1)%matrix, &
1175 matrix_type=dbcsr_type_no_symmetry)
1183 ALLOCATE (mat_dm_global_work(jspin, 1)%matrix)
1184 CALL dbcsr_create(matrix=mat_dm_global_work(jspin, 1)%matrix, &
1185 template=matrix_s_kp(1, 1)%matrix, &
1186 matrix_type=dbcsr_type_no_symmetry)
1188 CALL dbcsr_reserve_all_blocks(mat_dm_global_work(jspin, 1)%matrix)
1190 CALL dbcsr_set(mat_dm_global_work(jspin, 1)%matrix, 0.0_dp)
1195 CALL kpoint_density_matrices_rpa(kpoints_g, tau, e_fermi, &
1196 remove_occ=remove_occ, remove_virt=remove_virt)
1198 CALL density_matrix_from_kp_to_mic(kpoints_g, mat_dm_global_work, qs_env)
1200 CALL dbcsr_copy(mat_dm_global(jquad, 1)%matrix, &
1201 mat_dm_global_work(ispin, 1)%matrix)
1205 CALL timestop(handle)
1215 SUBROUTINE density_matrix_from_kp_to_mic(kpoints_G, mat_dm_global_work, qs_env)
1217 TYPE(kpoint_type),
POINTER :: kpoints_g
1218 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_dm_global_work
1219 TYPE(qs_environment_type),
POINTER :: qs_env
1221 CHARACTER(LEN=*),
PARAMETER :: routinen =
'density_matrix_from_kp_to_mic'
1223 INTEGER :: handle, iatom, iatom_old, ik, irow, &
1224 ispin, jatom, jatom_old, jcol, nao, &
1225 ncol_local, nkp, nrow_local, nspin, &
1227 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_from_ao_index
1228 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1229 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell
1230 REAL(kind=
dp) :: contribution, weight_im, weight_re
1231 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat
1232 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wkp
1233 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
1234 TYPE(cell_type),
POINTER :: cell
1235 TYPE(cp_fm_type) :: fm_mat_work
1236 TYPE(cp_fm_type),
POINTER :: cpmat, rpmat
1237 TYPE(kpoint_env_type),
POINTER :: kp
1238 TYPE(mo_set_type),
POINTER :: mo_set
1239 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
1241 CALL timeset(routinen, handle)
1245 CALL cp_fm_create(fm_mat_work, kpoints_g%kp_env(1)%kpoint_env%wmat(1, 1)%matrix_struct)
1249 index_to_cell => kpoints_g%index_to_cell
1250 num_cells =
SIZE(index_to_cell, 2)
1252 nspin =
SIZE(mat_dm_global_work, 1)
1254 mo_set => kpoints_g%kp_env(1)%kpoint_env%mos(1, 1)
1257 ALLOCATE (atom_from_ao_index(nao))
1261 CALL cp_fm_get_info(matrix=kpoints_g%kp_env(1)%kpoint_env%wmat(1, 1), &
1262 nrow_local=nrow_local, &
1263 ncol_local=ncol_local, &
1264 row_indices=row_indices, &
1265 col_indices=col_indices)
1267 NULLIFY (cell, particle_set)
1268 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
1276 CALL dbcsr_set(mat_dm_global_work(ispin, 1)%matrix, 0.0_dp)
1280 kp => kpoints_g%kp_env(ik)%kpoint_env
1281 rpmat => kp%wmat(1, ispin)
1282 cpmat => kp%wmat(2, ispin)
1284 DO irow = 1, nrow_local
1285 DO jcol = 1, ncol_local
1287 iatom = atom_from_ao_index(row_indices(irow))
1288 jatom = atom_from_ao_index(col_indices(jcol))
1290 IF (iatom .NE. iatom_old .OR. jatom .NE. jatom_old)
THEN
1293 num_cells, iatom, jatom, xkp(1:3, ik), wkp(ik), &
1294 cell, index_to_cell, hmat, particle_set)
1302 contribution = weight_re*rpmat%local_data(irow, jcol) - &
1303 weight_im*cpmat%local_data(irow, jcol)
1305 fm_mat_work%local_data(irow, jcol) = fm_mat_work%local_data(irow, jcol) + contribution
1312 CALL copy_fm_to_dbcsr(fm_mat_work, mat_dm_global_work(ispin, 1)%matrix, keep_sparsity=.false.)
1317 CALL cp_fm_release(fm_mat_work)
1318 DEALLOCATE (atom_from_ao_index)
1320 CALL timestop(handle)
1322 END SUBROUTINE density_matrix_from_kp_to_mic
1330 SUBROUTINE density_matrix_from_kp_to_transl(kpoints, mat_dm_global_work, index_to_cell)
1332 TYPE(kpoint_type),
POINTER :: kpoints
1333 TYPE(dbcsr_p_type),
DIMENSION(:, :),
INTENT(IN) :: mat_dm_global_work
1334 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: index_to_cell
1336 CHARACTER(LEN=*),
PARAMETER :: routinen =
'density_matrix_from_kp_to_transl'
1338 INTEGER :: handle, icell, ik, ispin, nkp, nspin, &
1340 REAL(kind=
dp) :: arg, coskl, sinkl
1341 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wkp
1342 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
1343 TYPE(cp_fm_type),
POINTER :: cpmat, rpmat
1344 TYPE(dbcsr_type),
POINTER :: mat_work_im, mat_work_re
1345 TYPE(kpoint_env_type),
POINTER :: kp
1347 CALL timeset(routinen, handle)
1351 NULLIFY (mat_work_re)
1352 CALL dbcsr_init_p(mat_work_re)
1353 CALL dbcsr_create(matrix=mat_work_re, &
1354 template=mat_dm_global_work(1, 1)%matrix, &
1355 matrix_type=dbcsr_type_no_symmetry)
1357 NULLIFY (mat_work_im)
1358 CALL dbcsr_init_p(mat_work_im)
1359 CALL dbcsr_create(matrix=mat_work_im, &
1360 template=mat_dm_global_work(1, 1)%matrix, &
1361 matrix_type=dbcsr_type_no_symmetry)
1365 nspin =
SIZE(mat_dm_global_work, 1)
1367 cpassert(
SIZE(mat_dm_global_work, 2) ==
SIZE(index_to_cell, 2))
1371 DO icell = 1,
SIZE(mat_dm_global_work, 2)
1373 CALL dbcsr_set(mat_dm_global_work(ispin, icell)%matrix, 0.0_dp)
1383 kp => kpoints%kp_env(ik)%kpoint_env
1384 rpmat => kp%wmat(1, ispin)
1385 cpmat => kp%wmat(2, ispin)
1390 DO icell = 1,
SIZE(mat_dm_global_work, 2)
1392 xcell = index_to_cell(1, icell)
1393 ycell = index_to_cell(2, icell)
1394 zcell = index_to_cell(3, icell)
1396 arg = real(xcell,
dp)*xkp(1, ik) + real(ycell,
dp)*xkp(2, ik) + real(zcell,
dp)*xkp(3, ik)
1397 coskl = wkp(ik)*cos(
twopi*arg)
1398 sinkl = wkp(ik)*sin(
twopi*arg)
1400 CALL dbcsr_add(mat_dm_global_work(ispin, icell)%matrix, mat_work_re, 1.0_dp, coskl)
1401 CALL dbcsr_add(mat_dm_global_work(ispin, icell)%matrix, mat_work_im, 1.0_dp, sinkl)
1408 CALL dbcsr_release_p(mat_work_re)
1409 CALL dbcsr_release_p(mat_work_im)
1411 CALL timestop(handle)
1413 END SUBROUTINE density_matrix_from_kp_to_transl
1423 INTEGER,
DIMENSION(3),
INTENT(IN) :: cell_grid
1424 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index
1425 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell
1426 TYPE(cell_type),
INTENT(IN),
POINTER :: cell
1428 CHARACTER(LEN=*),
PARAMETER :: routinen =
'init_cell_index_rpa'
1430 INTEGER :: cell_counter, handle, i_cell, &
1431 index_min_dist, num_cells, xcell, &
1433 INTEGER,
DIMENSION(3) :: itm
1434 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell_unsorted
1435 INTEGER,
DIMENSION(:, :, :),
POINTER :: cell_to_index_unsorted
1436 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: abs_cell_vectors
1437 REAL(kind=
dp),
DIMENSION(3) :: cell_vector
1438 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat
1440 CALL timeset(routinen, handle)
1444 num_cells = cell_grid(1)*cell_grid(2)*cell_grid(3)
1445 itm(:) = cell_grid(:)/2
1449 cpassert(cell_grid(1) .NE. itm(1)*2)
1450 cpassert(cell_grid(2) .NE. itm(2)*2)
1451 cpassert(cell_grid(3) .NE. itm(3)*2)
1453 IF (
ASSOCIATED(cell_to_index))
DEALLOCATE (cell_to_index)
1454 IF (
ASSOCIATED(index_to_cell))
DEALLOCATE (index_to_cell)
1456 ALLOCATE (cell_to_index_unsorted(-itm(1):itm(1), -itm(2):itm(2), -itm(3):itm(3)))
1457 cell_to_index_unsorted(:, :, :) = 0
1459 ALLOCATE (index_to_cell_unsorted(3, num_cells))
1460 index_to_cell_unsorted(:, :) = 0
1462 ALLOCATE (cell_to_index(-itm(1):itm(1), -itm(2):itm(2), -itm(3):itm(3)))
1463 cell_to_index(:, :, :) = 0
1465 ALLOCATE (index_to_cell(3, num_cells))
1466 index_to_cell(:, :) = 0
1468 ALLOCATE (abs_cell_vectors(1:num_cells))
1472 DO xcell = -itm(1), itm(1)
1473 DO ycell = -itm(2), itm(2)
1474 DO zcell = -itm(3), itm(3)
1476 cell_counter = cell_counter + 1
1477 cell_to_index_unsorted(xcell, ycell, zcell) = cell_counter
1479 index_to_cell_unsorted(1, cell_counter) = xcell
1480 index_to_cell_unsorted(2, cell_counter) = ycell
1481 index_to_cell_unsorted(3, cell_counter) = zcell
1483 cell_vector(1:3) = matmul(hmat, real(index_to_cell_unsorted(1:3, cell_counter),
dp))
1485 abs_cell_vectors(cell_counter) = sqrt(cell_vector(1)**2 + cell_vector(2)**2 + cell_vector(3)**2)
1493 DO i_cell = 1, num_cells/2 + 1
1495 index_min_dist = minloc(abs_cell_vectors(1:num_cells/2 + 1), dim=1)
1497 xcell = index_to_cell_unsorted(1, index_min_dist)
1498 ycell = index_to_cell_unsorted(2, index_min_dist)
1499 zcell = index_to_cell_unsorted(3, index_min_dist)
1501 index_to_cell(1, i_cell) = xcell
1502 index_to_cell(2, i_cell) = ycell
1503 index_to_cell(3, i_cell) = zcell
1505 cell_to_index(xcell, ycell, zcell) = i_cell
1507 abs_cell_vectors(index_min_dist) = 10000000000.0_dp
1512 DO i_cell = num_cells/2 + 2, num_cells
1514 index_min_dist = minloc(abs_cell_vectors(1:num_cells), dim=1)
1516 xcell = index_to_cell_unsorted(1, index_min_dist)
1517 ycell = index_to_cell_unsorted(2, index_min_dist)
1518 zcell = index_to_cell_unsorted(3, index_min_dist)
1520 index_to_cell(1, i_cell) = xcell
1521 index_to_cell(2, i_cell) = ycell
1522 index_to_cell(3, i_cell) = zcell
1524 cell_to_index(xcell, ycell, zcell) = i_cell
1526 abs_cell_vectors(index_min_dist) = 10000000000.0_dp
1530 DEALLOCATE (index_to_cell_unsorted, cell_to_index_unsorted, abs_cell_vectors)
1532 CALL timestop(handle)
1547 SUBROUTINE get_diff_index_3c(i_cell_R, i_cell_S, i_cell_R_minus_S, index_to_cell_3c, &
1548 cell_to_index_3c, index_to_cell_dm, R_minus_S_needed, &
1549 do_kpoints_cubic_RPA)
1551 INTEGER,
INTENT(IN) :: i_cell_r, i_cell_s
1552 INTEGER,
INTENT(OUT) :: i_cell_r_minus_s
1553 INTEGER,
ALLOCATABLE,
DIMENSION(:, :),
INTENT(IN) :: index_to_cell_3c
1554 INTEGER,
ALLOCATABLE,
DIMENSION(:, :, :), &
1555 INTENT(IN) :: cell_to_index_3c
1556 INTEGER,
DIMENSION(:, :),
INTENT(IN),
POINTER :: index_to_cell_dm
1557 LOGICAL,
INTENT(OUT) :: r_minus_s_needed
1558 LOGICAL,
INTENT(IN) :: do_kpoints_cubic_rpa
1560 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_diff_index_3c'
1562 INTEGER :: handle, x_cell_r, x_cell_r_minus_s, x_cell_s, y_cell_r, y_cell_r_minus_s, &
1563 y_cell_s, z_cell_r, z_cell_r_minus_s, z_cell_s
1565 CALL timeset(routinen, handle)
1567 IF (do_kpoints_cubic_rpa)
THEN
1569 x_cell_r = index_to_cell_3c(1, i_cell_r)
1570 y_cell_r = index_to_cell_3c(2, i_cell_r)
1571 z_cell_r = index_to_cell_3c(3, i_cell_r)
1573 x_cell_s = index_to_cell_dm(1, i_cell_s)
1574 y_cell_s = index_to_cell_dm(2, i_cell_s)
1575 z_cell_s = index_to_cell_dm(3, i_cell_s)
1577 x_cell_r_minus_s = x_cell_r - x_cell_s
1578 y_cell_r_minus_s = y_cell_r - y_cell_s
1579 z_cell_r_minus_s = z_cell_r - z_cell_s
1581 IF (x_cell_r_minus_s .GE. lbound(cell_to_index_3c, 1) .AND. &
1582 x_cell_r_minus_s .LE. ubound(cell_to_index_3c, 1) .AND. &
1583 y_cell_r_minus_s .GE. lbound(cell_to_index_3c, 2) .AND. &
1584 y_cell_r_minus_s .LE. ubound(cell_to_index_3c, 2) .AND. &
1585 z_cell_r_minus_s .GE. lbound(cell_to_index_3c, 3) .AND. &
1586 z_cell_r_minus_s .LE. ubound(cell_to_index_3c, 3))
THEN
1588 i_cell_r_minus_s = cell_to_index_3c(x_cell_r_minus_s, y_cell_r_minus_s, z_cell_r_minus_s)
1591 IF (i_cell_r_minus_s == 0)
THEN
1593 r_minus_s_needed = .false.
1594 i_cell_r_minus_s = 0
1598 r_minus_s_needed = .true.
1604 i_cell_r_minus_s = 0
1605 r_minus_s_needed = .false.
1611 r_minus_s_needed = .true.
1612 i_cell_r_minus_s = 1
1616 CALL timestop(handle)
1618 END SUBROUTINE get_diff_index_3c
1632 SUBROUTINE get_diff_diff_index_3c(i_cell_R, i_cell_S, i_cell_T, i_cell_R_minus_S_minus_T, &
1633 index_to_cell_3c, cell_to_index_3c, index_to_cell_dm, &
1634 R_minus_S_minus_T_needed, &
1635 do_kpoints_cubic_RPA)
1637 INTEGER,
INTENT(IN) :: i_cell_r, i_cell_s, i_cell_t
1638 INTEGER,
INTENT(OUT) :: i_cell_r_minus_s_minus_t
1639 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: index_to_cell_3c
1640 INTEGER,
ALLOCATABLE,
DIMENSION(:, :, :), &
1641 INTENT(IN) :: cell_to_index_3c
1642 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: index_to_cell_dm
1643 LOGICAL,
INTENT(OUT) :: r_minus_s_minus_t_needed
1644 LOGICAL,
INTENT(IN) :: do_kpoints_cubic_rpa
1646 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_diff_diff_index_3c'
1648 INTEGER :: handle, x_cell_r, x_cell_r_minus_s_minus_t, x_cell_s, x_cell_t, y_cell_r, &
1649 y_cell_r_minus_s_minus_t, y_cell_s, y_cell_t, z_cell_r, z_cell_r_minus_s_minus_t, &
1652 CALL timeset(routinen, handle)
1654 IF (do_kpoints_cubic_rpa)
THEN
1656 x_cell_r = index_to_cell_3c(1, i_cell_r)
1657 y_cell_r = index_to_cell_3c(2, i_cell_r)
1658 z_cell_r = index_to_cell_3c(3, i_cell_r)
1660 x_cell_s = index_to_cell_dm(1, i_cell_s)
1661 y_cell_s = index_to_cell_dm(2, i_cell_s)
1662 z_cell_s = index_to_cell_dm(3, i_cell_s)
1664 x_cell_t = index_to_cell_dm(1, i_cell_t)
1665 y_cell_t = index_to_cell_dm(2, i_cell_t)
1666 z_cell_t = index_to_cell_dm(3, i_cell_t)
1668 x_cell_r_minus_s_minus_t = x_cell_r - x_cell_s - x_cell_t
1669 y_cell_r_minus_s_minus_t = y_cell_r - y_cell_s - y_cell_t
1670 z_cell_r_minus_s_minus_t = z_cell_r - z_cell_s - z_cell_t
1672 IF (x_cell_r_minus_s_minus_t .GE. lbound(cell_to_index_3c, 1) .AND. &
1673 x_cell_r_minus_s_minus_t .LE. ubound(cell_to_index_3c, 1) .AND. &
1674 y_cell_r_minus_s_minus_t .GE. lbound(cell_to_index_3c, 2) .AND. &
1675 y_cell_r_minus_s_minus_t .LE. ubound(cell_to_index_3c, 2) .AND. &
1676 z_cell_r_minus_s_minus_t .GE. lbound(cell_to_index_3c, 3) .AND. &
1677 z_cell_r_minus_s_minus_t .LE. ubound(cell_to_index_3c, 3))
THEN
1679 i_cell_r_minus_s_minus_t = cell_to_index_3c(x_cell_r_minus_s_minus_t, &
1680 y_cell_r_minus_s_minus_t, &
1681 z_cell_r_minus_s_minus_t)
1684 IF (i_cell_r_minus_s_minus_t == 0)
THEN
1686 r_minus_s_minus_t_needed = .false.
1690 r_minus_s_minus_t_needed = .true.
1696 i_cell_r_minus_s_minus_t = 0
1697 r_minus_s_minus_t_needed = .false.
1704 r_minus_s_minus_t_needed = .true.
1705 i_cell_r_minus_s_minus_t = 1
1709 CALL timestop(handle)
1711 END SUBROUTINE get_diff_diff_index_3c
Handles all functions related to the CELL.
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
DBCSR operations in CP2K.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
basic linear algebra operations for full matrices
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
subroutine, public cp_fm_scale(alpha, matrix_a)
scales a matrix matrix_a = alpha * matrix_b
represent the structure of a full matrix
represent a full matrix distributed on many processors
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, use_sp)
creates a new full matrix with the given structure
This is the start of a dbt_api, all publically needed functions are exported here....
Types and set/get functions for HFX.
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
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)
Retrieve information from a kpoint environment.
Machine interface based on Fortran 2003 and POSIX.
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition of mathematical constants and functions.
real(kind=dp), parameter, public twopi
Interface to the message passing library MPI.
Types needed for MP2 calculations.
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, 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_nonbond, sab_almo, sab_kp, sab_kp_nosym, 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, 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, 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, ecoul_1c, rho0_s_rs, rho0_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, 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, rhs)
Get the QUICKSTEP environment.
Definition and initialisation of the mo data type.
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)
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.
subroutine, public decompress_tensor(tensor, blk_indices, compressed, eps)
...
subroutine, public get_tensor_occupancy(tensor, nze, occ)
...
Utility routines for 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.
subroutine, public compute_mat_p_omega(mat_P_omega, fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, fm_mo_coeff_occ, fm_mo_coeff_virt, fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, 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, weights_cos_tf_t_to_w, tj, tau_tj, e_fermi, eps_filter, alpha, eps_filter_im_time, Eigenval, nmo, num_integ_points, 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_periodic_dm(mat_dm_global, qs_env, ispin, num_integ_points, jquad, e_fermi, tau, remove_occ, remove_virt, alloc_dm)
...
subroutine, public compute_mat_dm_global(fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, tau_tj, num_integ_points, nmo, fm_mo_coeff_occ, fm_mo_coeff_virt, fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, mat_dm_occ_global, mat_dm_virt_global, 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)
...
subroutine, public init_cell_index_rpa(cell_grid, cell_to_index, index_to_cell, cell)
...
subroutine, public zero_mat_p_omega(mat_P_omega)
...
subroutine, public compute_transl_dm(mat_dm_global, qs_env, ispin, num_integ_points, jquad, e_fermi, tau, eps_filter, num_cells_dm, index_to_cell_dm, remove_occ, remove_virt, first_jquad)
...