93#include "./base/base_uses.f90"
99 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_large_cell_gamma'
121 CHARACTER(LEN=*),
PARAMETER :: routinen =
'gw_calc_large_cell_Gamma'
124 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma, fm_w_mic_time
125 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
127 CALL timeset(routinen, handle)
134 CALL get_mat_chi_gamma_tau(bs_env, qs_env, bs_env%mat_chi_Gamma_tau)
137 CALL get_w_mic(bs_env, qs_env, bs_env%mat_chi_Gamma_tau, fm_w_mic_time)
141 CALL get_sigma_x(bs_env, qs_env, fm_sigma_x_gamma)
145 CALL get_sigma_c(bs_env, qs_env, fm_w_mic_time, fm_sigma_c_gamma_time)
152 CALL timestop(handle)
162 SUBROUTINE get_mat_chi_gamma_tau(bs_env, qs_env, mat_chi_Gamma_tau)
165 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
167 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_mat_chi_Gamma_tau'
169 INTEGER :: handle, i_intval_idx, i_t, inner_loop_atoms_interval_index, ispin, j_intval_idx
170 INTEGER(KIND=int_8) :: flop
171 INTEGER,
DIMENSION(2) :: bounds_p, bounds_q, i_atoms, il_atoms, &
173 INTEGER,
DIMENSION(2, 2) :: bounds_comb
174 LOGICAL :: dist_too_long_i, dist_too_long_j
175 REAL(kind=
dp) :: t1, tau
176 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_3c_for_gocc, &
177 t_3c_for_gvir, t_3c_x_gocc, &
178 t_3c_x_gocc_2, t_3c_x_gvir, &
181 CALL timeset(routinen, handle)
183 DO i_t = 1, bs_env%num_time_freq_points
187 IF (bs_env%read_chi(i_t))
THEN
189 CALL fm_read(bs_env%fm_RI_RI, bs_env, bs_env%chi_name, i_t)
192 keep_sparsity=.false.)
194 IF (bs_env%unit_nr > 0)
THEN
195 WRITE (bs_env%unit_nr,
'(T2,A,I5,A,I3,A,F10.1,A)') &
196 'Read χ(iτ,k=0) from file for time point ', i_t,
' /', &
197 bs_env%num_time_freq_points, &
205 IF (.NOT. bs_env%calc_chi(i_t)) cycle
207 CALL create_tensors_chi(t_2c_gocc, t_2c_gvir, t_3c_for_gocc, t_3c_for_gvir, &
208 t_3c_x_gocc, t_3c_x_gvir, t_3c_x_gocc_2, t_3c_x_gvir_2, bs_env)
214 tau = bs_env%imag_time_points(i_t)
216 DO ispin = 1, bs_env%n_spin
217 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gocc, ispin, occ=.true., vir=.false.)
218 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gvir, ispin, occ=.false., vir=.true.)
221 bs_env%mat_ao_ao_tensor%matrix, t_2c_gocc, bs_env, &
222 bs_env%atoms_j_t_group)
224 bs_env%mat_ao_ao_tensor%matrix, t_2c_gvir, bs_env, &
225 bs_env%atoms_i_t_group)
229 DO i_intval_idx = 1, bs_env%n_intervals_i
230 DO j_intval_idx = 1, bs_env%n_intervals_j
231 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
232 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
234 IF (bs_env%skip_chi(i_intval_idx, j_intval_idx))
THEN
238 bs_env%n_skip_chi = bs_env%n_skip_chi + 1
243 DO inner_loop_atoms_interval_index = 1, bs_env%n_intervals_inner_loop_atoms
245 il_atoms = bs_env%inner_loop_atom_intervals(1:2, inner_loop_atoms_interval_index)
251 CALL check_dist(i_atoms, il_atoms, qs_env, bs_env, dist_too_long_i)
252 CALL check_dist(j_atoms, il_atoms, qs_env, bs_env, dist_too_long_j)
253 IF (.NOT. dist_too_long_i)
THEN
256 atoms_ao_1=i_atoms, atoms_ao_2=il_atoms)
258 CALL g_times_3c(t_3c_for_gocc, t_2c_gocc, t_3c_x_gocc, bs_env, &
259 j_atoms, i_atoms, il_atoms)
261 IF (.NOT. dist_too_long_j)
THEN
264 atoms_ao_1=j_atoms, atoms_ao_2=il_atoms)
266 CALL g_times_3c(t_3c_for_gvir, t_2c_gvir, t_3c_x_gvir, bs_env, &
267 i_atoms, j_atoms, il_atoms)
272 CALL dbt_copy(t_3c_x_gocc, t_3c_x_gocc_2, move_data=.true., order=[1, 3, 2])
273 CALL dbt_copy(t_3c_x_gvir, t_3c_x_gvir_2, move_data=.true.)
282 bounds_comb(1:2, 1) = [bs_env%i_ao_start_from_atom(j_atoms(1)), &
283 bs_env%i_ao_end_from_atom(j_atoms(2))]
284 bounds_comb(1:2, 2) = [bs_env%i_ao_start_from_atom(i_atoms(1)), &
285 bs_env%i_ao_end_from_atom(i_atoms(2))]
287 CALL get_bounds_from_atoms(bounds_p, i_atoms, [1, bs_env%n_atom], &
288 bs_env%min_RI_idx_from_AO_AO_atom, &
289 bs_env%max_RI_idx_from_AO_AO_atom)
290 CALL get_bounds_from_atoms(bounds_q, [1, bs_env%n_atom], j_atoms, &
291 bs_env%min_RI_idx_from_AO_AO_atom, &
292 bs_env%max_RI_idx_from_AO_AO_atom)
294 IF (bounds_q(1) > bounds_q(2) .OR. bounds_p(1) > bounds_p(2))
THEN
297 CALL dbt_contract(alpha=bs_env%spin_degeneracy, &
298 tensor_1=t_3c_x_gocc_2, tensor_2=t_3c_x_gvir_2, &
299 beta=1.0_dp, tensor_3=bs_env%t_chi, &
300 contract_1=[2, 3], notcontract_1=[1], map_1=[1], &
301 contract_2=[2, 3], notcontract_2=[1], map_2=[2], &
302 bounds_1=bounds_comb, &
305 filter_eps=bs_env%eps_filter, move_data=.false., flop=flop)
307 IF (flop == 0_int_8) bs_env%skip_chi(i_intval_idx, j_intval_idx) = .true.
317 mat_chi_gamma_tau(i_t)%matrix, bs_env%para_env)
319 CALL write_matrix(mat_chi_gamma_tau(i_t)%matrix, i_t, bs_env%chi_name, &
320 bs_env%fm_RI_RI, qs_env)
322 CALL destroy_tensors_chi(t_2c_gocc, t_2c_gvir, t_3c_for_gocc, t_3c_for_gvir, &
323 t_3c_x_gocc, t_3c_x_gvir, t_3c_x_gocc_2, t_3c_x_gvir_2)
325 IF (bs_env%unit_nr > 0)
THEN
326 WRITE (bs_env%unit_nr,
'(T2,A,I13,A,I3,A,F10.1,A)') &
327 'Computed χ(iτ,k=0) for time point', i_t,
' /', bs_env%num_time_freq_points, &
333 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
335 CALL timestop(handle)
337 END SUBROUTINE get_mat_chi_gamma_tau
349 CHARACTER(LEN=*) :: mat_name
352 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_read'
354 CHARACTER(LEN=default_path_length) :: f_chi
355 INTEGER :: handle, unit_nr
357 CALL timeset(routinen, handle)
360 IF (bs_env%para_env%is_source())
THEN
363 WRITE (f_chi,
'(3A,I1,A)') trim(bs_env%prefix), trim(mat_name),
"_0",
idx,
".matrix"
364 ELSE IF (
idx < 100)
THEN
365 WRITE (f_chi,
'(3A,I2,A)') trim(bs_env%prefix), trim(mat_name),
"_",
idx,
".matrix"
367 cpabort(
'Please implement more than 99 time/frequency points.')
370 CALL open_file(file_name=trim(f_chi), file_action=
"READ", file_form=
"UNFORMATTED", &
371 file_position=
"REWIND", file_status=
"OLD", unit_number=unit_nr)
377 IF (bs_env%para_env%is_source())
CALL close_file(unit_number=unit_nr)
379 CALL timestop(handle)
395 SUBROUTINE create_tensors_chi(t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, t_3c_for_Gvir, &
396 t_3c_x_Gocc, t_3c_x_Gvir, t_3c_x_Gocc_2, t_3c_x_Gvir_2, bs_env)
398 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_3c_for_gocc, &
399 t_3c_for_gvir, t_3c_x_gocc, &
400 t_3c_x_gvir, t_3c_x_gocc_2, &
404 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_tensors_chi'
408 CALL timeset(routinen, handle)
410 CALL dbt_create(bs_env%t_G, t_2c_gocc, name=
"Gocc 2c (AO|AO)")
411 CALL dbt_create(bs_env%t_G, t_2c_gvir, name=
"Gvir 2c (AO|AO)")
412 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_gocc, name=
"Gocc 3c (RI AO|AO)")
413 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_gvir, name=
"Gvir 3c (RI AO|AO)")
414 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_gocc, name=
"xGocc 3c (RI AO|AO)")
415 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_gvir, name=
"xGvir 3c (RI AO|AO)")
416 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_gocc_2, name=
"x2Gocc 3c (RI AO|AO)")
417 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_gvir_2, name=
"x2Gvir 3c (RI AO|AO)")
419 CALL timestop(handle)
421 END SUBROUTINE create_tensors_chi
434 SUBROUTINE destroy_tensors_chi(t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, t_3c_for_Gvir, &
435 t_3c_x_Gocc, t_3c_x_Gvir, t_3c_x_Gocc_2, t_3c_x_Gvir_2)
436 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_3c_for_gocc, &
437 t_3c_for_gvir, t_3c_x_gocc, &
438 t_3c_x_gvir, t_3c_x_gocc_2, &
441 CHARACTER(LEN=*),
PARAMETER :: routinen =
'destroy_tensors_chi'
445 CALL timeset(routinen, handle)
447 CALL dbt_destroy(t_2c_gocc)
448 CALL dbt_destroy(t_2c_gvir)
449 CALL dbt_destroy(t_3c_for_gocc)
450 CALL dbt_destroy(t_3c_for_gvir)
451 CALL dbt_destroy(t_3c_x_gocc)
452 CALL dbt_destroy(t_3c_x_gvir)
453 CALL dbt_destroy(t_3c_x_gocc_2)
454 CALL dbt_destroy(t_3c_x_gvir_2)
456 CALL timestop(handle)
458 END SUBROUTINE destroy_tensors_chi
470 INTEGER :: matrix_index
471 CHARACTER(LEN=*) :: matrix_name
475 CHARACTER(LEN=*),
PARAMETER :: routinen =
'write_matrix'
479 CALL timeset(routinen, handle)
485 CALL fm_write(fm, matrix_index, matrix_name, qs_env)
487 CALL timestop(handle)
498 SUBROUTINE fm_write(fm, matrix_index, matrix_name, qs_env)
500 INTEGER :: matrix_index
501 CHARACTER(LEN=*) :: matrix_name
504 CHARACTER(LEN=*),
PARAMETER :: key =
'PROPERTIES%BANDSTRUCTURE%GW%PRINT%RESTART', &
505 routinen =
'fm_write'
507 CHARACTER(LEN=default_path_length) :: filename
508 INTEGER :: handle, unit_nr
512 CALL timeset(routinen, handle)
520 IF (matrix_index < 10)
THEN
521 WRITE (filename,
'(3A,I1)')
"RESTART_", matrix_name,
"_0", matrix_index
522 ELSE IF (matrix_index < 100)
THEN
523 WRITE (filename,
'(3A,I2)')
"RESTART_", matrix_name,
"_", matrix_index
525 cpabort(
'Please implement more than 99 time/frequency points.')
529 file_form=
"UNFORMATTED", middle_name=trim(filename), &
530 file_position=
"REWIND", file_action=
"WRITE")
533 IF (unit_nr > 0)
THEN
538 CALL timestop(handle)
551 SUBROUTINE g_occ_vir(bs_env, tau, fm_G_Gamma, ispin, occ, vir)
558 CHARACTER(LEN=*),
PARAMETER :: routinen =
'G_occ_vir'
560 INTEGER :: handle, homo, i_row_local, j_col, &
561 j_col_local, n_mo, ncol_local, &
563 INTEGER,
DIMENSION(:),
POINTER :: col_indices
564 REAL(kind=
dp) :: tau_e
566 CALL timeset(routinen, handle)
568 cpassert(occ .NEQV. vir)
571 nrow_local=nrow_local, &
572 ncol_local=ncol_local, &
573 col_indices=col_indices)
576 homo = bs_env%n_occ(ispin)
578 CALL cp_fm_to_fm(bs_env%fm_mo_coeff_Gamma(ispin), bs_env%fm_work_mo(1))
580 DO i_row_local = 1, nrow_local
581 DO j_col_local = 1, ncol_local
583 j_col = col_indices(j_col_local)
585 tau_e = abs(tau*0.5_dp*(bs_env%eigenval_scf_Gamma(j_col, ispin) - bs_env%e_fermi(ispin)))
587 IF (tau_e < bs_env%stabilize_exp)
THEN
588 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = &
589 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local)*exp(-tau_e)
591 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = 0.0_dp
594 IF ((occ .AND. j_col > homo) .OR. (vir .AND. j_col <= homo))
THEN
595 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = 0.0_dp
601 CALL parallel_gemm(transa=
"N", transb=
"T", m=n_mo, n=n_mo, k=n_mo, alpha=1.0_dp, &
602 matrix_a=bs_env%fm_work_mo(1), matrix_b=bs_env%fm_work_mo(1), &
603 beta=0.0_dp, matrix_c=fm_g_gamma)
605 CALL timestop(handle)
621 TYPE(dbt_type) :: t_3c
622 INTEGER,
DIMENSION(2),
OPTIONAL :: atoms_ao_1, atoms_ao_2, atoms_ri
624 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_3c_integrals'
627 TYPE(dbt_type),
ALLOCATABLE,
DIMENSION(:, :) :: t_3c_array
629 CALL timeset(routinen, handle)
634 ALLOCATE (t_3c_array(1, 1))
635 CALL dbt_create(t_3c, t_3c_array(1, 1))
641 int_eps=bs_env%eps_filter, &
642 basis_i=bs_env%basis_set_RI, &
643 basis_j=bs_env%basis_set_AO, &
644 basis_k=bs_env%basis_set_AO, &
645 potential_parameter=bs_env%ri_metric, &
647 bounds_j=atoms_ao_1, &
648 bounds_k=atoms_ao_2, &
649 desymmetrize=.false.)
651 CALL dbt_filter(t_3c_array(1, 1), bs_env%eps_filter)
653 CALL dbt_copy(t_3c_array(1, 1), t_3c, move_data=.true.)
655 CALL dbt_destroy(t_3c_array(1, 1))
656 DEALLOCATE (t_3c_array)
658 CALL timestop(handle)
672 SUBROUTINE g_times_3c(t_3c_for_G, t_G, t_M, bs_env, atoms_AO_1, atoms_AO_2, atoms_IL)
673 TYPE(dbt_type) :: t_3c_for_g, t_g, t_m
675 INTEGER,
DIMENSION(2) :: atoms_ao_1, atoms_ao_2, atoms_il
677 CHARACTER(LEN=*),
PARAMETER :: routinen =
'G_times_3c'
680 INTEGER(KIND=int_8) :: flop
681 INTEGER,
DIMENSION(2) :: bounds_ao_1, bounds_il
682 INTEGER,
DIMENSION(2, 2) :: bounds_comb
684 CALL timeset(routinen, handle)
695 CALL get_bounds_from_atoms(bounds_il, [1, bs_env%n_atom], atoms_ao_2, &
696 bs_env%min_AO_idx_from_RI_AO_atom, &
697 bs_env%max_AO_idx_from_RI_AO_atom, &
699 indices_3_start=bs_env%i_ao_start_from_atom, &
700 indices_3_end=bs_env%i_ao_end_from_atom)
703 CALL get_bounds_from_atoms(bounds_comb(:, 1), atoms_il, atoms_ao_2, &
704 bs_env%min_RI_idx_from_AO_AO_atom, &
705 bs_env%max_RI_idx_from_AO_AO_atom)
708 CALL get_bounds_from_atoms(bounds_comb(:, 2), [1, bs_env%n_atom], atoms_il, &
709 bs_env%min_AO_idx_from_RI_AO_atom, &
710 bs_env%max_AO_idx_from_RI_AO_atom, &
711 atoms_3=atoms_ao_2, &
712 indices_3_start=bs_env%i_ao_start_from_atom, &
713 indices_3_end=bs_env%i_ao_end_from_atom)
716 bounds_ao_1(1:2) = [bs_env%i_ao_start_from_atom(atoms_ao_1(1)), &
717 bs_env%i_ao_end_from_atom(atoms_ao_1(2))]
719 IF (bounds_il(1) > bounds_il(2) .OR. bounds_comb(1, 2) > bounds_comb(2, 2))
THEN
722 CALL dbt_contract(alpha=1.0_dp, &
723 tensor_1=t_3c_for_g, &
727 contract_1=[3], notcontract_1=[1, 2], map_1=[1, 2], &
728 contract_2=[2], notcontract_2=[1], map_2=[3], &
729 bounds_1=bounds_il, &
730 bounds_2=bounds_comb, &
731 bounds_3=bounds_ao_1, &
733 filter_eps=bs_env%eps_filter)
736 CALL dbt_clear(t_3c_for_g)
738 CALL timestop(handle)
740 END SUBROUTINE g_times_3c
750 SUBROUTINE check_dist(atoms_1, atoms_2, qs_env, bs_env, dist_too_long)
751 INTEGER,
DIMENSION(2) :: atoms_1, atoms_2
754 LOGICAL :: dist_too_long
756 CHARACTER(LEN=*),
PARAMETER :: routinen =
'check_dist'
758 INTEGER :: atom_1, atom_2, handle
759 REAL(
dp) :: abs_rab, min_dist_ao_atoms
760 REAL(kind=
dp),
DIMENSION(3) :: rab
764 CALL timeset(routinen, handle)
766 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
768 min_dist_ao_atoms = huge(1.0_dp)
769 DO atom_1 = atoms_1(1), atoms_1(2)
770 DO atom_2 = atoms_2(1), atoms_2(2)
771 rab =
pbc(particle_set(atom_1)%r(1:3), particle_set(atom_2)%r(1:3), cell)
773 abs_rab = sqrt(rab(1)**2 + rab(2)**2 + rab(3)**2)
775 min_dist_ao_atoms = min(min_dist_ao_atoms, abs_rab)
779 dist_too_long = (min_dist_ao_atoms > bs_env%max_dist_AO_atoms)
781 CALL timestop(handle)
783 END SUBROUTINE check_dist
792 SUBROUTINE get_w_mic(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
795 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
796 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
798 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_W_MIC'
802 CALL timeset(routinen, handle)
804 IF (bs_env%all_W_exist)
THEN
805 CALL read_w_mic_time(bs_env, mat_chi_gamma_tau, fm_w_mic_time)
807 CALL compute_w_mic(bs_env, qs_env, mat_chi_gamma_tau, fm_w_mic_time)
810 CALL timestop(handle)
821 SUBROUTINE compute_v_k_by_lattice_sum(bs_env, qs_env, fm_V_kp, ikp_batch)
824 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
827 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_V_k_by_lattice_sum'
829 INTEGER :: handle, ikp, ikp_end, ikp_start, &
830 nkp_chi_eps_w_batch, re_im
833 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_v_kp
835 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
837 CALL timeset(routinen, handle)
839 nkp_chi_eps_w_batch = bs_env%nkp_chi_eps_W_batch
841 ikp_start = (ikp_batch - 1)*bs_env%nkp_chi_eps_W_batch + 1
842 ikp_end = min(ikp_batch*bs_env%nkp_chi_eps_W_batch, bs_env%kpoints_chi_eps_W%nkp)
845 ALLOCATE (mat_v_kp(ikp_start:ikp_end, 2))
848 DO ikp = ikp_start, ikp_end
849 NULLIFY (mat_v_kp(ikp, re_im)%matrix)
850 ALLOCATE (mat_v_kp(ikp, re_im)%matrix)
851 CALL dbcsr_create(mat_v_kp(ikp, re_im)%matrix, template=bs_env%mat_RI_RI%matrix)
853 CALL dbcsr_set(mat_v_kp(ikp, re_im)%matrix, 0.0_dp)
858 particle_set=particle_set, &
860 qs_kind_set=qs_kind_set, &
861 atomic_kind_set=atomic_kind_set)
863 IF (ikp_end <= bs_env%nkp_chi_eps_W_orig)
THEN
866 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
868 ELSE IF (ikp_start > bs_env%nkp_chi_eps_W_orig .AND. &
869 ikp_end <= bs_env%nkp_chi_eps_W_orig_plus_extra)
THEN
872 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_extra
876 cpabort(
"Error with k-point parallelization.")
881 bs_env%kpoints_chi_eps_W, &
882 basis_type=
"RI_AUX", &
884 particle_set=particle_set, &
885 qs_kind_set=qs_kind_set, &
886 atomic_kind_set=atomic_kind_set, &
887 size_lattice_sum=bs_env%size_lattice_sum_V, &
889 ikp_start=ikp_start, &
892 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
894 ALLOCATE (fm_v_kp(ikp_start:ikp_end, 2))
896 DO ikp = ikp_start, ikp_end
897 CALL cp_fm_create(fm_v_kp(ikp, re_im), bs_env%fm_RI_RI%matrix_struct)
902 DEALLOCATE (mat_v_kp)
904 CALL timestop(handle)
906 END SUBROUTINE compute_v_k_by_lattice_sum
917 SUBROUTINE compute_minvvsqrt_vsqrt(bs_env, qs_env, fm_V_kp, cfm_V_sqrt_ikp, &
918 cfm_M_inv_V_sqrt_ikp, ikp)
921 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
922 TYPE(
cp_cfm_type) :: cfm_v_sqrt_ikp, cfm_m_inv_v_sqrt_ikp
925 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_MinvVsqrt_Vsqrt'
927 INTEGER :: handle, info, n_ri
929 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_m_ikp
931 CALL timeset(routinen, handle)
937 n_ri, bs_env%ri_metric, do_kpoints=.true., &
938 kpoints=bs_env%kpoints_chi_eps_W, &
939 regularization_ri=bs_env%regularization_RI, ikp_ext=ikp, &
940 do_build_cell_index=(ikp == 1))
943 CALL cp_cfm_create(cfm_v_sqrt_ikp, fm_v_kp(ikp, 1)%matrix_struct)
944 CALL cp_cfm_create(cfm_m_inv_v_sqrt_ikp, fm_v_kp(ikp, 1)%matrix_struct)
946 CALL cp_cfm_create(cfm_m_inv_ikp, fm_v_kp(ikp, 1)%matrix_struct)
948 CALL cp_fm_to_cfm(fm_m_ikp(1, 1), fm_m_ikp(1, 2), cfm_m_inv_ikp)
949 CALL cp_fm_to_cfm(fm_v_kp(ikp, 1), fm_v_kp(ikp, 2), cfm_v_sqrt_ikp)
965 CALL cp_cfm_power(cfm_work, threshold=bs_env%eps_eigval_mat_RI, exponent=-1.0_dp)
974 CALL clean_lower_part(cfm_v_sqrt_ikp)
977 CALL cp_cfm_power(cfm_work, threshold=0.0_dp, exponent=0.5_dp)
983 CALL parallel_gemm(
"N",
"C", n_ri, n_ri, n_ri,
z_one, cfm_m_inv_ikp, cfm_v_sqrt_ikp, &
984 z_zero, cfm_m_inv_v_sqrt_ikp)
988 CALL timestop(handle)
990 END SUBROUTINE compute_minvvsqrt_vsqrt
998 SUBROUTINE read_w_mic_time(bs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
1000 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1001 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1003 CHARACTER(LEN=*),
PARAMETER :: routinen =
'read_W_MIC_time'
1005 INTEGER :: handle, i_t
1008 CALL timeset(routinen, handle)
1013 DO i_t = 1, bs_env%num_time_freq_points
1017 CALL fm_read(fm_w_mic_time(i_t), bs_env, bs_env%W_time_name, i_t)
1019 IF (bs_env%unit_nr > 0)
THEN
1020 WRITE (bs_env%unit_nr,
'(T2,A,I5,A,I3,A,F10.1,A)') &
1021 'Read W^MIC(iτ) from file for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1027 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1039 CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
1041 CALL fm_read(bs_env%fm_W_MIC_freq_zero, bs_env,
"W_freq_rtp", 0)
1042 IF (bs_env%unit_nr > 0)
THEN
1043 WRITE (bs_env%unit_nr,
'(T2,A,I3,A,I3,A,F10.1,A)') &
1044 'Read W^MIC(f=0) from file for freq. point ', 1,
' /', 1, &
1049 CALL timestop(handle)
1051 END SUBROUTINE read_w_mic_time
1060 SUBROUTINE compute_w_mic(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
1063 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1064 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1066 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_W_MIC'
1068 INTEGER :: handle, i_t, ikp, ikp_batch, &
1071 TYPE(
cp_cfm_type) :: cfm_m_inv_v_sqrt_ikp, cfm_v_sqrt_ikp
1072 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
1074 CALL timeset(routinen, handle)
1078 DO ikp_batch = 1, bs_env%num_chi_eps_W_batches
1083 CALL compute_v_k_by_lattice_sum(bs_env, qs_env, fm_v_kp, ikp_batch)
1085 DO ikp_in_batch = 1, bs_env%nkp_chi_eps_W_batch
1087 ikp = (ikp_batch - 1)*bs_env%nkp_chi_eps_W_batch + ikp_in_batch
1089 IF (ikp > bs_env%nkp_chi_eps_W_orig_plus_extra) cycle
1091 CALL compute_minvvsqrt_vsqrt(bs_env, qs_env, fm_v_kp, &
1092 cfm_v_sqrt_ikp, cfm_m_inv_v_sqrt_ikp, ikp)
1094 CALL bs_env%para_env%sync()
1098 DO j_w = 1, bs_env%num_time_freq_points
1101 IF (bs_env%approx_kp_extrapol .AND. j_w > 1 .AND. &
1102 ikp > bs_env%nkp_chi_eps_W_orig) cycle
1104 CALL compute_fm_w_mic_freq_j(bs_env, qs_env, bs_env%fm_W_MIC_freq, j_w, ikp, &
1105 mat_chi_gamma_tau, cfm_m_inv_v_sqrt_ikp, &
1115 DEALLOCATE (fm_v_kp)
1117 IF (bs_env%unit_nr > 0)
THEN
1118 WRITE (bs_env%unit_nr,
'(T2,A,I12,A,I3,A,F10.1,A)') &
1119 'Computed W(iτ,k) for k-point batch', &
1120 ikp_batch,
' /', bs_env%num_chi_eps_W_batches, &
1126 IF (bs_env%approx_kp_extrapol)
THEN
1127 CALL apply_extrapol_factor(bs_env, fm_w_mic_time)
1133 DO i_t = 1, bs_env%num_time_freq_points
1134 CALL fm_write(fm_w_mic_time(i_t), i_t, bs_env%W_time_name, qs_env)
1146 CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
1150 DO i_t = 1, bs_env%num_time_freq_points
1153 bs_env%imag_time_weights_freq_zero(i_t), fm_w_mic_time(i_t))
1156 CALL fm_write(bs_env%fm_W_MIC_freq_zero, 0,
"W_freq_rtp", qs_env)
1158 IF (bs_env%unit_nr > 0)
THEN
1159 WRITE (bs_env%unit_nr,
'(T2,A,I11,A,I3,A,F10.1,A)') &
1160 'Computed W(f=0,k) for k-point batch', &
1166 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1168 CALL timestop(handle)
1170 END SUBROUTINE compute_w_mic
1183 SUBROUTINE compute_fm_w_mic_freq_j(bs_env, qs_env, fm_W_MIC_freq_j, j_w, ikp, mat_chi_Gamma_tau, &
1184 cfm_M_inv_V_sqrt_ikp, cfm_V_sqrt_ikp)
1189 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1190 TYPE(
cp_cfm_type) :: cfm_m_inv_v_sqrt_ikp, cfm_v_sqrt_ikp
1192 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_fm_W_MIC_freq_j'
1195 TYPE(
cp_cfm_type) :: cfm_chi_ikp_freq_j, cfm_w_ikp_freq_j
1197 CALL timeset(routinen, handle)
1206 ikp, qs_env, bs_env%kpoints_chi_eps_W,
"RI_AUX")
1209 CALL cp_cfm_power(cfm_chi_ikp_freq_j, threshold=0.0_dp, exponent=1.0_dp)
1213 CALL compute_cfm_w_ikp_freq_j(bs_env, cfm_chi_ikp_freq_j, cfm_v_sqrt_ikp, &
1214 cfm_m_inv_v_sqrt_ikp, cfm_w_ikp_freq_j)
1217 SELECT CASE (bs_env%approx_kp_extrapol)
1221 bs_env%kpoints_chi_eps_W,
"RI_AUX")
1232 cfm_w_ikp_freq_j, ikp, bs_env%kpoints_chi_eps_W, &
1235 IF (ikp <= bs_env%nkp_chi_eps_W_orig)
THEN
1237 cfm_w_ikp_freq_j, ikp, bs_env%kpoints_chi_eps_W, &
1238 "RI_AUX", wkp_ext=bs_env%wkp_orig)
1244 IF (ikp <= bs_env%nkp_chi_eps_W_orig)
THEN
1246 ikp, bs_env%kpoints_chi_eps_W,
"RI_AUX", &
1247 wkp_ext=bs_env%wkp_orig)
1253 CALL timestop(handle)
1255 END SUBROUTINE compute_fm_w_mic_freq_j
1261 SUBROUTINE clean_lower_part(cfm_mat)
1264 CHARACTER(LEN=*),
PARAMETER :: routinen =
'clean_lower_part'
1266 INTEGER :: handle, i_row, j_col, j_global, &
1267 ncol_local, nrow_local
1268 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1270 CALL timeset(routinen, handle)
1273 nrow_local=nrow_local, ncol_local=ncol_local, &
1274 row_indices=row_indices, col_indices=col_indices)
1276 DO j_col = 1, ncol_local
1277 j_global = col_indices(j_col)
1278 DO i_row = 1, nrow_local
1279 IF (j_global < row_indices(i_row)) cfm_mat%local_data(i_row, j_col) =
z_zero
1283 CALL timestop(handle)
1285 END SUBROUTINE clean_lower_part
1292 SUBROUTINE apply_extrapol_factor(bs_env, fm_W_MIC_time)
1294 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1296 CHARACTER(LEN=*),
PARAMETER :: routinen =
'apply_extrapol_factor'
1298 INTEGER :: handle, i, i_t, j, ncol_local, nrow_local
1299 REAL(kind=
dp) :: extrapol_factor, w_extra_1, w_no_extra_1
1301 CALL timeset(routinen, handle)
1303 CALL cp_fm_get_info(matrix=fm_w_mic_time(1), nrow_local=nrow_local, ncol_local=ncol_local)
1305 DO i_t = 1, bs_env%num_time_freq_points
1306 DO j = 1, ncol_local
1307 DO i = 1, nrow_local
1309 w_extra_1 = bs_env%fm_W_MIC_freq_1_extra%local_data(i, j)
1310 w_no_extra_1 = bs_env%fm_W_MIC_freq_1_no_extra%local_data(i, j)
1312 IF (abs(w_no_extra_1) > 1.0e-13)
THEN
1313 extrapol_factor = abs(w_extra_1/w_no_extra_1)
1315 extrapol_factor = 1.0_dp
1319 IF (extrapol_factor > 10.0_dp) extrapol_factor = 1.0_dp
1321 fm_w_mic_time(i_t)%local_data(i, j) = fm_w_mic_time(i_t)%local_data(i, j) &
1327 CALL timestop(handle)
1329 END SUBROUTINE apply_extrapol_factor
1342 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1344 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_fm_chi_Gamma_freq'
1346 INTEGER :: handle, i_t
1347 REAL(kind=
dp) :: freq_j, time_i, weight_ij
1349 CALL timeset(routinen, handle)
1351 CALL dbcsr_set(bs_env%mat_RI_RI%matrix, 0.0_dp)
1353 freq_j = bs_env%imag_freq_points(j_w)
1355 DO i_t = 1, bs_env%num_time_freq_points
1357 time_i = bs_env%imag_time_points(i_t)
1358 weight_ij = bs_env%weights_cos_t_to_w(j_w, i_t)
1361 CALL dbcsr_add(bs_env%mat_RI_RI%matrix, mat_chi_gamma_tau(i_t)%matrix, &
1362 1.0_dp, cos(time_i*freq_j)*weight_ij)
1368 CALL timestop(handle)
1381 SUBROUTINE mat_ikp_from_mat_gamma(mat_ikp_re, mat_ikp_im, mat_Gamma, kpoints, ikp, qs_env)
1382 TYPE(
dbcsr_type) :: mat_ikp_re, mat_ikp_im, mat_gamma
1387 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mat_ikp_from_mat_Gamma'
1389 INTEGER :: col, handle, i_cell, j_cell, num_cells, &
1391 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell
1392 LOGICAL :: f, i_cell_is_the_minimum_image_cell
1393 REAL(kind=
dp) :: abs_rab_cell_i, abs_rab_cell_j, arg
1394 REAL(kind=
dp),
DIMENSION(3) :: cell_vector, cell_vector_j, rab_cell_i, &
1396 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat
1397 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block_im, block_re, data_block
1402 CALL timeset(routinen, handle)
1410 NULLIFY (cell, particle_set)
1411 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
1414 index_to_cell => kpoints%index_to_cell
1416 num_cells =
SIZE(index_to_cell, 2)
1418 DO i_cell = 1, num_cells
1424 cell_vector(1:3) = matmul(hmat, real(index_to_cell(1:3, i_cell),
dp))
1426 rab_cell_i(1:3) =
pbc(particle_set(row)%r(1:3), cell) - &
1427 (
pbc(particle_set(col)%r(1:3), cell) + cell_vector(1:3))
1428 abs_rab_cell_i = sqrt(rab_cell_i(1)**2 + rab_cell_i(2)**2 + rab_cell_i(3)**2)
1431 i_cell_is_the_minimum_image_cell = .true.
1432 DO j_cell = 1, num_cells
1433 cell_vector_j(1:3) = matmul(hmat, real(index_to_cell(1:3, j_cell),
dp))
1434 rab_cell_j(1:3) =
pbc(particle_set(row)%r(1:3), cell) - &
1435 (
pbc(particle_set(col)%r(1:3), cell) + cell_vector_j(1:3))
1436 abs_rab_cell_j = sqrt(rab_cell_j(1)**2 + rab_cell_j(2)**2 + rab_cell_j(3)**2)
1438 IF (abs_rab_cell_i > abs_rab_cell_j + 1.0e-6_dp)
THEN
1439 i_cell_is_the_minimum_image_cell = .false.
1443 IF (i_cell_is_the_minimum_image_cell)
THEN
1444 NULLIFY (block_re, block_im)
1445 CALL dbcsr_get_block_p(matrix=mat_ikp_re, row=row, col=col, block=block_re, found=f)
1446 CALL dbcsr_get_block_p(matrix=mat_ikp_im, row=row, col=col, block=block_im, found=f)
1447 cpassert(all(abs(block_re) < 1.0e-10_dp))
1448 cpassert(all(abs(block_im) < 1.0e-10_dp))
1450 arg = real(index_to_cell(1, i_cell),
dp)*kpoints%xkp(1, ikp) + &
1451 REAL(index_to_cell(2, i_cell),
dp)*kpoints%xkp(2, ikp) + &
1452 REAL(index_to_cell(3, i_cell),
dp)*kpoints%xkp(3, ikp)
1454 block_re(:, :) = cos(
twopi*arg)*data_block(:, :)
1455 block_im(:, :) = sin(
twopi*arg)*data_block(:, :)
1463 CALL timestop(handle)
1465 END SUBROUTINE mat_ikp_from_mat_gamma
1475 SUBROUTINE compute_cfm_w_ikp_freq_j(bs_env, cfm_chi_ikp_freq_j, cfm_V_sqrt_ikp, &
1476 cfm_M_inv_V_sqrt_ikp, cfm_W_ikp_freq_j)
1479 TYPE(
cp_cfm_type) :: cfm_chi_ikp_freq_j, cfm_v_sqrt_ikp, &
1480 cfm_m_inv_v_sqrt_ikp, cfm_w_ikp_freq_j
1482 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_cfm_W_ikp_freq_j'
1484 INTEGER :: handle, info, n_ri
1487 CALL timeset(routinen, handle)
1489 CALL cp_cfm_create(cfm_work, cfm_chi_ikp_freq_j%matrix_struct)
1496 cfm_chi_ikp_freq_j, cfm_m_inv_v_sqrt_ikp,
z_zero, cfm_work)
1500 CALL cp_cfm_create(cfm_eps_ikp_freq_j, cfm_work%matrix_struct)
1502 cfm_m_inv_v_sqrt_ikp, cfm_work,
z_zero, cfm_eps_ikp_freq_j)
1505 CALL cfm_add_on_diag(cfm_eps_ikp_freq_j,
z_one)
1518 CALL cfm_add_on_diag(cfm_eps_ikp_freq_j, -
z_one)
1521 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri,
z_one, cfm_eps_ikp_freq_j, cfm_v_sqrt_ikp, &
1525 CALL cp_cfm_create(cfm_w_ikp_freq_j, cfm_work%matrix_struct)
1527 z_zero, cfm_w_ikp_freq_j)
1532 CALL timestop(handle)
1534 END SUBROUTINE compute_cfm_w_ikp_freq_j
1541 SUBROUTINE cfm_add_on_diag(cfm, alpha)
1544 COMPLEX(KIND=dp) :: alpha
1546 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cfm_add_on_diag'
1548 INTEGER :: handle, i_row, j_col, j_global, &
1549 ncol_local, nrow_local
1550 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1552 CALL timeset(routinen, handle)
1555 nrow_local=nrow_local, &
1556 ncol_local=ncol_local, &
1557 row_indices=row_indices, &
1558 col_indices=col_indices)
1561 DO j_col = 1, ncol_local
1562 j_global = col_indices(j_col)
1563 DO i_row = 1, nrow_local
1564 IF (j_global == row_indices(i_row))
THEN
1565 cfm%local_data(i_row, j_col) = cfm%local_data(i_row, j_col) + alpha
1570 CALL timestop(handle)
1572 END SUBROUTINE cfm_add_on_diag
1581 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1583 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_fm_W_MIC_time'
1585 INTEGER :: handle, i_t
1587 CALL timeset(routinen, handle)
1589 ALLOCATE (fm_w_mic_time(bs_env%num_time_freq_points))
1590 DO i_t = 1, bs_env%num_time_freq_points
1591 CALL cp_fm_create(fm_w_mic_time(i_t), bs_env%fm_RI_RI%matrix_struct, set_zero=.true.)
1594 CALL timestop(handle)
1607 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1611 CHARACTER(LEN=*),
PARAMETER :: routinen =
'Fourier_transform_w_to_t'
1613 INTEGER :: handle, i_t
1614 REAL(kind=
dp) :: freq_j, time_i, weight_ij
1616 CALL timeset(routinen, handle)
1618 freq_j = bs_env%imag_freq_points(j_w)
1620 DO i_t = 1, bs_env%num_time_freq_points
1622 time_i = bs_env%imag_time_points(i_t)
1623 weight_ij = bs_env%weights_cos_w_to_t(i_t, j_w)
1627 beta=weight_ij*cos(time_i*freq_j), matrix_b=fm_w_mic_freq_j)
1631 CALL timestop(handle)
1644 TYPE(
cp_fm_type),
DIMENSION(:) :: fm_w_mic_time
1646 CHARACTER(LEN=*),
PARAMETER :: routinen =
'multiply_fm_W_MIC_time_with_Minv_Gamma'
1648 INTEGER :: handle, i_t, n_ri, ndep
1650 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_minv_gamma
1652 CALL timeset(routinen, handle)
1656 CALL cp_fm_create(fm_work, fm_w_mic_time(1)%matrix_struct)
1660 bs_env%ri_metric, do_kpoints=.false.)
1662 CALL cp_fm_power(fm_minv_gamma(1, 1), fm_work, -1.0_dp, 0.0_dp, ndep)
1665 DO i_t = 1,
SIZE(fm_w_mic_time)
1667 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_minv_gamma(1, 1), &
1668 fm_w_mic_time(i_t), 0.0_dp, fm_work)
1670 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_work, &
1671 fm_minv_gamma(1, 1), 0.0_dp, fm_w_mic_time(i_t))
1678 CALL timestop(handle)
1688 SUBROUTINE get_sigma_x(bs_env, qs_env, fm_Sigma_x_Gamma)
1691 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
1693 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_Sigma_x'
1695 INTEGER :: handle, ispin
1697 CALL timeset(routinen, handle)
1699 ALLOCATE (fm_sigma_x_gamma(bs_env%n_spin))
1700 DO ispin = 1, bs_env%n_spin
1701 CALL cp_fm_create(fm_sigma_x_gamma(ispin), bs_env%fm_s_Gamma%matrix_struct)
1704 IF (bs_env%Sigma_x_exists)
THEN
1705 DO ispin = 1, bs_env%n_spin
1706 CALL fm_read(fm_sigma_x_gamma(ispin), bs_env, bs_env%Sigma_x_name, ispin)
1709 CALL compute_sigma_x(bs_env, qs_env, fm_sigma_x_gamma)
1712 CALL timestop(handle)
1714 END SUBROUTINE get_sigma_x
1722 SUBROUTINE compute_sigma_x(bs_env, qs_env, fm_Sigma_x_Gamma)
1725 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
1727 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_x'
1729 INTEGER :: handle, i_intval_idx, ispin, j_intval_idx
1730 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
1732 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_vtr_gamma
1734 TYPE(dbt_type) :: t_2c_d, t_2c_sigma_x, t_2c_v, t_3c_x_v
1736 CALL timeset(routinen, handle)
1740 CALL dbt_create(bs_env%t_G, t_2c_d)
1741 CALL dbt_create(bs_env%t_W, t_2c_v)
1742 CALL dbt_create(bs_env%t_G, t_2c_sigma_x)
1743 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_v)
1744 CALL dbcsr_create(mat_sigma_x_gamma, template=bs_env%mat_ao_ao%matrix)
1748 bs_env%trunc_coulomb, do_kpoints=.false.)
1753 DO ispin = 1, bs_env%n_spin
1756 CALL g_occ_vir(bs_env, 0.0_dp, bs_env%fm_work_mo(2), ispin, occ=.true., vir=.false.)
1759 bs_env%mat_ao_ao_tensor%matrix, t_2c_d, bs_env, &
1760 bs_env%atoms_i_t_group)
1763 bs_env%mat_RI_RI_tensor%matrix, t_2c_v, bs_env, &
1764 bs_env%atoms_j_t_group)
1768 DO i_intval_idx = 1, bs_env%n_intervals_i
1769 DO j_intval_idx = 1, bs_env%n_intervals_j
1770 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
1771 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
1775 CALL compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_v, t_2c_v)
1779 CALL contract_to_sigma(t_2c_d, t_3c_x_v, t_2c_sigma_x, i_atoms, j_atoms, &
1780 qs_env, bs_env, occ=.true., vir=.false.)
1786 mat_sigma_x_gamma, bs_env%para_env)
1788 CALL write_matrix(mat_sigma_x_gamma, ispin, bs_env%Sigma_x_name, &
1789 bs_env%fm_work_mo(1), qs_env)
1795 IF (bs_env%unit_nr > 0)
THEN
1796 WRITE (bs_env%unit_nr,
'(T2,A,T55,A,F10.1,A)') &
1797 'Computed Σ^x(k=0),',
' Execution time',
m_walltime() - t1,
' s'
1798 WRITE (bs_env%unit_nr,
'(A)')
' '
1802 CALL dbt_destroy(t_2c_d)
1803 CALL dbt_destroy(t_2c_v)
1804 CALL dbt_destroy(t_2c_sigma_x)
1805 CALL dbt_destroy(t_3c_x_v)
1808 CALL timestop(handle)
1810 END SUBROUTINE compute_sigma_x
1819 SUBROUTINE get_sigma_c(bs_env, qs_env, fm_W_MIC_time, fm_Sigma_c_Gamma_time)
1822 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1823 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
1825 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_Sigma_c'
1827 INTEGER :: handle, i_intval_idx, i_t, ispin, &
1828 j_intval_idx, read_write_index
1829 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
1830 REAL(kind=
dp) :: t1, tau
1831 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
1832 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, &
1833 t_2c_sigma_neg_tau, &
1834 t_2c_sigma_pos_tau, t_2c_w, t_3c_x_w
1836 CALL timeset(routinen, handle)
1838 CALL create_mat_for_sigma_c(bs_env, t_2c_gocc, t_2c_gvir, t_2c_w, t_2c_sigma_neg_tau, &
1839 t_2c_sigma_pos_tau, t_3c_x_w, &
1840 mat_sigma_neg_tau, mat_sigma_pos_tau)
1842 DO i_t = 1, bs_env%num_time_freq_points
1844 DO ispin = 1, bs_env%n_spin
1848 read_write_index = i_t + (ispin - 1)*bs_env%num_time_freq_points
1851 IF (bs_env%Sigma_c_exists(i_t, ispin))
THEN
1852 CALL fm_read(bs_env%fm_work_mo(1), bs_env, bs_env%Sigma_p_name, read_write_index)
1853 CALL copy_fm_to_dbcsr(bs_env%fm_work_mo(1), mat_sigma_pos_tau(i_t, ispin)%matrix, &
1854 keep_sparsity=.false.)
1855 CALL fm_read(bs_env%fm_work_mo(1), bs_env, bs_env%Sigma_n_name, read_write_index)
1856 CALL copy_fm_to_dbcsr(bs_env%fm_work_mo(1), mat_sigma_neg_tau(i_t, ispin)%matrix, &
1857 keep_sparsity=.false.)
1858 IF (bs_env%unit_nr > 0)
THEN
1859 WRITE (bs_env%unit_nr,
'(T2,2A,I3,A,I3,A,F10.1,A)')
'Read Σ^c(iτ,k=0) ', &
1860 'from file for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1868 tau = bs_env%imag_time_points(i_t)
1870 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gocc, ispin, occ=.true., vir=.false.)
1871 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gvir, ispin, occ=.false., vir=.true.)
1875 bs_env%mat_ao_ao_tensor%matrix, t_2c_gocc, bs_env, &
1876 bs_env%atoms_i_t_group)
1878 bs_env%mat_ao_ao_tensor%matrix, t_2c_gvir, bs_env, &
1879 bs_env%atoms_i_t_group)
1881 bs_env%mat_RI_RI_tensor%matrix, t_2c_w, bs_env, &
1882 bs_env%atoms_j_t_group)
1886 DO i_intval_idx = 1, bs_env%n_intervals_i
1887 DO j_intval_idx = 1, bs_env%n_intervals_j
1888 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
1889 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
1891 IF (bs_env%skip_Sigma_occ(i_intval_idx, j_intval_idx) .AND. &
1892 bs_env%skip_Sigma_vir(i_intval_idx, j_intval_idx))
THEN
1896 bs_env%n_skip_sigma = bs_env%n_skip_sigma + 1
1903 CALL compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_w, t_2c_w)
1907 CALL contract_to_sigma(t_2c_gocc, t_3c_x_w, t_2c_sigma_neg_tau, i_atoms, j_atoms, &
1908 qs_env, bs_env, occ=.true., vir=.false., &
1909 can_skip=bs_env%skip_Sigma_occ(i_intval_idx, j_intval_idx))
1912 CALL contract_to_sigma(t_2c_gvir, t_3c_x_w, t_2c_sigma_pos_tau, i_atoms, j_atoms, &
1913 qs_env, bs_env, occ=.false., vir=.true., &
1914 can_skip=bs_env%skip_Sigma_vir(i_intval_idx, j_intval_idx))
1922 mat_sigma_neg_tau(i_t, ispin)%matrix, bs_env%para_env)
1924 mat_sigma_pos_tau(i_t, ispin)%matrix, bs_env%para_env)
1926 CALL write_matrix(mat_sigma_pos_tau(i_t, ispin)%matrix, read_write_index, &
1927 bs_env%Sigma_p_name, bs_env%fm_work_mo(1), qs_env)
1928 CALL write_matrix(mat_sigma_neg_tau(i_t, ispin)%matrix, read_write_index, &
1929 bs_env%Sigma_n_name, bs_env%fm_work_mo(1), qs_env)
1931 IF (bs_env%unit_nr > 0)
THEN
1932 WRITE (bs_env%unit_nr,
'(T2,A,I10,A,I3,A,F10.1,A)') &
1933 'Computed Σ^c(iτ,k=0) for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1941 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1944 mat_sigma_pos_tau, mat_sigma_neg_tau)
1946 CALL print_skipping(bs_env)
1948 CALL destroy_mat_sigma_c(t_2c_gocc, t_2c_gvir, t_2c_w, t_2c_sigma_neg_tau, &
1949 t_2c_sigma_pos_tau, t_3c_x_w, fm_w_mic_time, &
1950 mat_sigma_neg_tau, mat_sigma_pos_tau)
1954 CALL timestop(handle)
1956 END SUBROUTINE get_sigma_c
1970 SUBROUTINE create_mat_for_sigma_c(bs_env, t_2c_Gocc, t_2c_Gvir, t_2c_W, t_2c_Sigma_neg_tau, &
1971 t_2c_Sigma_pos_tau, t_3c_x_W, &
1972 mat_Sigma_neg_tau, mat_Sigma_pos_tau)
1975 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_2c_w, &
1976 t_2c_sigma_neg_tau, &
1977 t_2c_sigma_pos_tau, t_3c_x_w
1978 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
1980 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_mat_for_Sigma_c'
1982 INTEGER :: handle, i_t, ispin
1984 CALL timeset(routinen, handle)
1986 CALL dbt_create(bs_env%t_G, t_2c_gocc)
1987 CALL dbt_create(bs_env%t_G, t_2c_gvir)
1988 CALL dbt_create(bs_env%t_W, t_2c_w)
1989 CALL dbt_create(bs_env%t_G, t_2c_sigma_neg_tau)
1990 CALL dbt_create(bs_env%t_G, t_2c_sigma_pos_tau)
1991 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_w)
1993 NULLIFY (mat_sigma_neg_tau, mat_sigma_pos_tau)
1994 ALLOCATE (mat_sigma_neg_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1995 ALLOCATE (mat_sigma_pos_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1997 DO ispin = 1, bs_env%n_spin
1998 DO i_t = 1, bs_env%num_time_freq_points
1999 ALLOCATE (mat_sigma_neg_tau(i_t, ispin)%matrix)
2000 ALLOCATE (mat_sigma_pos_tau(i_t, ispin)%matrix)
2001 CALL dbcsr_create(mat_sigma_neg_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
2002 CALL dbcsr_create(mat_sigma_pos_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
2006 CALL timestop(handle)
2008 END SUBROUTINE create_mat_for_sigma_c
2019 SUBROUTINE compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_W, t_2c_W)
2023 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
2024 TYPE(dbt_type) :: t_3c_x_w, t_2c_w
2026 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_3c_and_contract_W'
2028 INTEGER :: handle, ri_intval_idx
2029 INTEGER(KIND=int_8) :: flop
2030 INTEGER,
DIMENSION(2) :: bounds_p, bounds_q, ri_atoms
2031 INTEGER,
DIMENSION(2, 2) :: bounds_ao
2032 TYPE(dbt_type) :: t_3c_for_w, t_3c_x_w_tmp
2034 CALL timeset(routinen, handle)
2036 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_w_tmp)
2037 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_for_w)
2047 bounds_q(1:2) = [bs_env%i_RI_start_from_atom(j_atoms(1)), &
2048 bs_env%i_RI_end_from_atom(j_atoms(2))]
2050 DO ri_intval_idx = 1, bs_env%n_intervals_inner_loop_atoms
2051 ri_atoms = bs_env%inner_loop_atom_intervals(1:2, ri_intval_idx)
2053 CALL get_bounds_from_atoms(bounds_p, i_atoms, [1, bs_env%n_atom], &
2054 bs_env%min_RI_idx_from_AO_AO_atom, &
2055 bs_env%max_RI_idx_from_AO_AO_atom, &
2057 indices_3_start=bs_env%i_RI_start_from_atom, &
2058 indices_3_end=bs_env%i_RI_end_from_atom)
2061 CALL get_bounds_from_atoms(bounds_ao(:, 2), ri_atoms, i_atoms, &
2062 bs_env%min_AO_idx_from_RI_AO_atom, &
2063 bs_env%max_AO_idx_from_RI_AO_atom)
2065 CALL get_bounds_from_atoms(bounds_ao(:, 1), ri_atoms, [1, bs_env%n_atom], &
2066 bs_env%min_AO_idx_from_RI_AO_atom, &
2067 bs_env%max_AO_idx_from_RI_AO_atom, &
2069 indices_3_start=bs_env%i_ao_start_from_atom, &
2070 indices_3_end=bs_env%i_ao_end_from_atom)
2072 IF (bounds_p(1) > bounds_p(2) .OR. bounds_ao(1, 2) > bounds_ao(2, 2))
THEN
2078 atoms_ao_1=i_atoms, atoms_ri=ri_atoms)
2081 CALL dbt_contract(alpha=1.0_dp, &
2083 tensor_2=t_3c_for_w, &
2085 tensor_3=t_3c_x_w_tmp, &
2086 contract_1=[2], notcontract_1=[1], map_1=[1], &
2087 contract_2=[1], notcontract_2=[2, 3], map_2=[2, 3], &
2088 bounds_1=bounds_p, &
2089 bounds_2=bounds_q, &
2090 bounds_3=bounds_ao, &
2092 move_data=.false., &
2093 filter_eps=bs_env%eps_filter)
2098 CALL dbt_copy(t_3c_x_w_tmp, t_3c_x_w, order=[1, 2, 3], move_data=.true.)
2100 CALL dbt_destroy(t_3c_x_w_tmp)
2101 CALL dbt_destroy(t_3c_for_w)
2103 CALL timestop(handle)
2105 END SUBROUTINE compute_3c_and_contract_w
2120 SUBROUTINE contract_to_sigma(t_2c_G, t_3c_x_W, t_2c_Sigma, i_atoms, j_atoms, qs_env, bs_env, &
2122 TYPE(dbt_type) :: t_2c_g, t_3c_x_w, t_2c_sigma
2123 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
2127 LOGICAL,
OPTIONAL :: can_skip
2129 CHARACTER(LEN=*),
PARAMETER :: routinen =
'contract_to_Sigma'
2131 INTEGER :: handle, inner_loop_atoms_interval_index
2132 INTEGER(KIND=int_8) :: flop
2133 INTEGER,
DIMENSION(2) :: bounds_lambda, bounds_mu, bounds_nu, &
2134 bounds_sigma, il_atoms
2135 INTEGER,
DIMENSION(2, 2) :: bounds_comb
2136 REAL(kind=
dp) :: sign_sigma
2137 TYPE(dbt_type) :: t_3c_for_g, t_3c_x_g, t_3c_x_g_2
2139 CALL timeset(routinen, handle)
2141 cpassert(occ .EQV. (.NOT. vir))
2142 IF (occ) sign_sigma = -1.0_dp
2143 IF (vir) sign_sigma = 1.0_dp
2145 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_g)
2146 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_g)
2147 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_g_2)
2160 bounds_nu(1:2) = [bs_env%i_ao_start_from_atom(i_atoms(1)), &
2161 bs_env%i_ao_end_from_atom(i_atoms(2))]
2163 DO inner_loop_atoms_interval_index = 1, bs_env%n_intervals_inner_loop_atoms
2164 il_atoms = bs_env%inner_loop_atom_intervals(1:2, inner_loop_atoms_interval_index)
2167 CALL get_bounds_from_atoms(bounds_mu, j_atoms, [1, bs_env%n_atom], &
2168 bs_env%min_AO_idx_from_RI_AO_atom, &
2169 bs_env%max_AO_idx_from_RI_AO_atom, &
2171 indices_3_start=bs_env%i_ao_start_from_atom, &
2172 indices_3_end=bs_env%i_ao_end_from_atom)
2175 CALL get_bounds_from_atoms(bounds_comb(:, 1), il_atoms, [1, bs_env%n_atom], &
2176 bs_env%min_RI_idx_from_AO_AO_atom, &
2177 bs_env%max_RI_idx_from_AO_AO_atom, &
2179 indices_3_start=bs_env%i_RI_start_from_atom, &
2180 indices_3_end=bs_env%i_RI_end_from_atom)
2183 CALL get_bounds_from_atoms(bounds_comb(:, 2), j_atoms, il_atoms, &
2184 bs_env%min_AO_idx_from_RI_AO_atom, &
2185 bs_env%max_AO_idx_from_RI_AO_atom)
2187 IF (bounds_mu(1) > bounds_mu(2) .OR. bounds_comb(1, 1) > bounds_comb(2, 1) .OR. &
2188 bounds_comb(1, 2) > bounds_comb(2, 2))
THEN
2193 atoms_ri=j_atoms, atoms_ao_2=il_atoms)
2195 CALL dbt_contract(alpha=1.0_dp, &
2197 tensor_2=t_3c_for_g, &
2199 tensor_3=t_3c_x_g, &
2200 contract_1=[2], notcontract_1=[1], map_1=[3], &
2201 contract_2=[3], notcontract_2=[1, 2], map_2=[1, 2], &
2202 bounds_1=bounds_mu, &
2203 bounds_2=bounds_nu, &
2204 bounds_3=bounds_comb, &
2206 move_data=.false., &
2207 filter_eps=bs_env%eps_filter)
2211 CALL dbt_copy(t_3c_x_g, t_3c_x_g_2, order=[1, 3, 2], move_data=.true.)
2215 bounds_comb(1:2, 1) = [bs_env%i_RI_start_from_atom(j_atoms(1)), &
2216 bs_env%i_RI_end_from_atom(j_atoms(2))]
2217 bounds_comb(1:2, 2) = bounds_nu(1:2)
2219 CALL get_bounds_from_atoms(bounds_lambda, j_atoms, [1, bs_env%n_atom], &
2220 bs_env%min_AO_idx_from_RI_AO_atom, &
2221 bs_env%max_AO_idx_from_RI_AO_atom)
2222 CALL get_bounds_from_atoms(bounds_sigma, [1, bs_env%n_atom], i_atoms, &
2223 bs_env%min_AO_idx_from_RI_AO_atom, &
2224 bs_env%max_AO_idx_from_RI_AO_atom)
2226 IF (bounds_sigma(1) > bounds_sigma(2) .OR. bounds_lambda(1) > bounds_lambda(2))
THEN
2229 CALL dbt_contract(alpha=sign_sigma, &
2230 tensor_1=t_3c_x_w, &
2231 tensor_2=t_3c_x_g_2, &
2233 tensor_3=t_2c_sigma, &
2234 contract_1=[1, 2], notcontract_1=[3], map_1=[1], &
2235 contract_2=[1, 2], notcontract_2=[3], map_2=[2], &
2236 bounds_1=bounds_comb, &
2237 bounds_2=bounds_sigma, &
2238 bounds_3=bounds_lambda, &
2239 filter_eps=bs_env%eps_filter, move_data=.false., flop=flop)
2242 IF (
PRESENT(can_skip))
THEN
2243 IF (flop == 0_int_8) can_skip = .true.
2246 CALL dbt_destroy(t_3c_for_g)
2247 CALL dbt_destroy(t_3c_x_g)
2248 CALL dbt_destroy(t_3c_x_g_2)
2250 CALL timestop(handle)
2252 END SUBROUTINE contract_to_sigma
2262 mat_Sigma_pos_tau, mat_Sigma_neg_tau)
2264 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
2266 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_pos_tau, mat_sigma_neg_tau
2268 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fill_fm_Sigma_c_Gamma_time'
2270 INTEGER :: handle, i_t, ispin, pos_neg
2272 CALL timeset(routinen, handle)
2274 ALLOCATE (fm_sigma_c_gamma_time(bs_env%num_time_freq_points, 2, bs_env%n_spin))
2275 DO ispin = 1, bs_env%n_spin
2276 DO i_t = 1, bs_env%num_time_freq_points
2278 CALL cp_fm_create(fm_sigma_c_gamma_time(i_t, pos_neg, ispin), &
2279 bs_env%fm_s_Gamma%matrix_struct)
2282 fm_sigma_c_gamma_time(i_t, 1, ispin))
2284 fm_sigma_c_gamma_time(i_t, 2, ispin))
2288 CALL timestop(handle)
2296 SUBROUTINE print_skipping(bs_env)
2300 CHARACTER(LEN=*),
PARAMETER :: routinen =
'print_skipping'
2302 INTEGER :: handle, n_pairs
2304 CALL timeset(routinen, handle)
2306 n_pairs = bs_env%n_intervals_i*bs_env%n_intervals_j*bs_env%n_spin
2308 CALL bs_env%para_env_tensor%sum(bs_env%n_skip_sigma)
2309 CALL bs_env%para_env_tensor%sum(bs_env%n_skip_chi)
2310 CALL bs_env%para_env_tensor%sum(n_pairs)
2312 IF (bs_env%unit_nr > 0)
THEN
2313 WRITE (bs_env%unit_nr,
'(T2,A,T74,F7.1,A)') &
2314 'Sparsity of Σ^c(iτ,k=0): Percentage of skipped atom pairs:', &
2315 REAL(100*bs_env%n_skip_sigma, kind=
dp)/real(n_pairs, kind=
dp),
' %'
2316 WRITE (bs_env%unit_nr,
'(T2,A,T74,F7.1,A)') &
2317 'Sparsity of χ(iτ,k=0): Percentage of skipped atom pairs:', &
2318 REAL(100*bs_env%n_skip_chi, kind=
dp)/real(n_pairs, kind=
dp),
' %'
2321 CALL timestop(handle)
2323 END SUBROUTINE print_skipping
2337 SUBROUTINE destroy_mat_sigma_c(t_2c_Gocc, t_2c_Gvir, t_2c_W, t_2c_Sigma_neg_tau, &
2338 t_2c_Sigma_pos_tau, t_3c_x_W, fm_W_MIC_time, &
2339 mat_Sigma_neg_tau, mat_Sigma_pos_tau)
2341 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_2c_w, &
2342 t_2c_sigma_neg_tau, &
2343 t_2c_sigma_pos_tau, t_3c_x_w
2344 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
2345 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
2347 CHARACTER(LEN=*),
PARAMETER :: routinen =
'destroy_mat_Sigma_c'
2351 CALL timeset(routinen, handle)
2353 CALL dbt_destroy(t_2c_gocc)
2354 CALL dbt_destroy(t_2c_gvir)
2355 CALL dbt_destroy(t_2c_w)
2356 CALL dbt_destroy(t_2c_sigma_neg_tau)
2357 CALL dbt_destroy(t_2c_sigma_pos_tau)
2358 CALL dbt_destroy(t_3c_x_w)
2363 CALL timestop(handle)
2365 END SUBROUTINE destroy_mat_sigma_c
2374 CHARACTER(LEN=*),
PARAMETER :: routinen =
'delete_unnecessary_files'
2376 CHARACTER(LEN=default_path_length) :: f_chi, f_w_t, prefix
2377 INTEGER :: handle, i_t
2379 CALL timeset(routinen, handle)
2381 prefix = bs_env%prefix
2383 DO i_t = 1, bs_env%num_time_freq_points
2386 WRITE (f_chi,
'(3A,I1,A)') trim(prefix), bs_env%chi_name,
"_00", i_t,
".matrix"
2387 WRITE (f_w_t,
'(3A,I1,A)') trim(prefix), bs_env%W_time_name,
"_00", i_t,
".matrix"
2388 ELSE IF (i_t < 100)
THEN
2389 WRITE (f_chi,
'(3A,I2,A)') trim(prefix), bs_env%chi_name,
"_0", i_t,
".matrix"
2390 WRITE (f_w_t,
'(3A,I2,A)') trim(prefix), bs_env%W_time_name,
"_0", i_t,
".matrix"
2392 cpabort(
'Please implement more than 99 time/frequency points.')
2395 CALL safe_delete(f_chi, bs_env)
2396 CALL safe_delete(f_w_t, bs_env)
2400 CALL timestop(handle)
2409 SUBROUTINE safe_delete(filename, bs_env)
2410 CHARACTER(LEN=*) :: filename
2413 CHARACTER(LEN=*),
PARAMETER :: routinen =
'safe_delete'
2418 CALL timeset(routinen, handle)
2420 IF (bs_env%para_env%mepos == 0)
THEN
2427 CALL timestop(handle)
2429 END SUBROUTINE safe_delete
2442 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
2443 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
2445 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_QP_energies'
2447 INTEGER :: handle, ikp, ispin, j_t
2448 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: sigma_x_ikp_n, v_xc_ikp_n
2449 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: sigma_c_ikp_n_freq, sigma_c_ikp_n_time
2450 TYPE(
cp_cfm_type) :: cfm_ks_ikp, cfm_mos_ikp, cfm_s_ikp, &
2451 cfm_sigma_x_ikp, cfm_work_ikp
2453 CALL timeset(routinen, handle)
2455 CALL cp_cfm_create(cfm_mos_ikp, bs_env%fm_s_Gamma%matrix_struct)
2456 CALL cp_cfm_create(cfm_work_ikp, bs_env%fm_s_Gamma%matrix_struct)
2458 ALLOCATE (v_xc_ikp_n(bs_env%n_ao), sigma_x_ikp_n(bs_env%n_ao))
2459 ALLOCATE (sigma_c_ikp_n_time(bs_env%n_ao, bs_env%num_time_freq_points, 2))
2460 ALLOCATE (sigma_c_ikp_n_freq(bs_env%n_ao, bs_env%num_time_freq_points, 2))
2462 DO ispin = 1, bs_env%n_spin
2464 DO ikp = 1, bs_env%nkp_bs_and_DOS
2468 ikp, qs_env, bs_env%kpoints_DOS,
"ORB")
2472 ikp, qs_env, bs_env%kpoints_DOS,
"ORB")
2475 CALL cp_cfm_geeig(cfm_ks_ikp, cfm_s_ikp, cfm_mos_ikp, &
2476 bs_env%eigenval_scf(:, ikp, ispin), cfm_work_ikp)
2479 CALL to_ikp_and_mo(v_xc_ikp_n, bs_env%fm_V_xc_Gamma(ispin), &
2480 ikp, qs_env, bs_env, cfm_mos_ikp)
2483 CALL to_ikp_and_mo(sigma_x_ikp_n, fm_sigma_x_gamma(ispin), &
2484 ikp, qs_env, bs_env, cfm_mos_ikp)
2487 DO j_t = 1, bs_env%num_time_freq_points
2488 CALL to_ikp_and_mo(sigma_c_ikp_n_time(:, j_t, 1), &
2489 fm_sigma_c_gamma_time(j_t, 1, ispin), &
2490 ikp, qs_env, bs_env, cfm_mos_ikp)
2491 CALL to_ikp_and_mo(sigma_c_ikp_n_time(:, j_t, 2), &
2492 fm_sigma_c_gamma_time(j_t, 2, ispin), &
2493 ikp, qs_env, bs_env, cfm_mos_ikp)
2497 CALL time_to_freq(bs_env, sigma_c_ikp_n_time, sigma_c_ikp_n_freq, ispin)
2502 bs_env%eigenval_scf(:, ikp, ispin), ikp, ispin)
2519 CALL timestop(handle)
2532 SUBROUTINE to_ikp_and_mo(array_ikp_n, fm_Gamma, ikp, qs_env, bs_env, cfm_mos_ikp)
2534 REAL(kind=
dp),
DIMENSION(:) :: array_ikp_n
2541 CHARACTER(LEN=*),
PARAMETER :: routinen =
'to_ikp_and_mo'
2546 CALL timeset(routinen, handle)
2548 CALL cp_fm_create(fm_ikp_mo_re, fm_gamma%matrix_struct)
2550 CALL fm_gamma_ao_to_cfm_ikp_mo(fm_gamma, fm_ikp_mo_re, ikp, qs_env, bs_env, cfm_mos_ikp)
2556 CALL timestop(handle)
2558 END SUBROUTINE to_ikp_and_mo
2569 SUBROUTINE fm_gamma_ao_to_cfm_ikp_mo(fm_Gamma, fm_ikp_mo_re, ikp, qs_env, bs_env, cfm_mos_ikp)
2576 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_Gamma_ao_to_cfm_ikp_mo'
2578 INTEGER :: handle, nmo
2579 TYPE(
cp_cfm_type) :: cfm_ikp_ao, cfm_ikp_mo, cfm_tmp
2581 CALL timeset(routinen, handle)
2600 CALL timestop(handle)
2602 END SUBROUTINE fm_gamma_ao_to_cfm_ikp_mo
2619 SUBROUTINE get_bounds_from_atoms(bounds_out, atoms_1, atoms_2, indices_min, indices_max, &
2620 atoms_3, indices_3_start, indices_3_end)
2622 INTEGER,
DIMENSION(2),
INTENT(OUT) :: bounds_out
2623 INTEGER,
DIMENSION(2),
INTENT(IN) :: atoms_1, atoms_2
2624 INTEGER,
DIMENSION(:, :) :: indices_min, indices_max
2625 INTEGER,
DIMENSION(2),
INTENT(IN),
OPTIONAL :: atoms_3
2626 INTEGER,
DIMENSION(:),
OPTIONAL :: indices_3_start, indices_3_end
2628 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_bounds_from_atoms'
2630 INTEGER :: handle, i_at, j_at
2632 CALL timeset(routinen, handle)
2633 bounds_out(1) = huge(0)
2636 DO i_at = atoms_1(1), atoms_1(2)
2637 DO j_at = atoms_2(1), atoms_2(2)
2638 bounds_out(1) = min(bounds_out(1), indices_min(i_at, j_at))
2639 bounds_out(2) = max(bounds_out(2), indices_max(i_at, j_at))
2643 IF (
PRESENT(atoms_3) .AND.
PRESENT(indices_3_start) .AND.
PRESENT(indices_3_end))
THEN
2644 bounds_out(1) = max(bounds_out(1), indices_3_start(atoms_3(1)))
2645 bounds_out(2) = min(bounds_out(2), indices_3_end(atoms_3(2)))
2648 CALL timestop(handle)
2650 END SUBROUTINE get_bounds_from_atoms
static GRID_HOST_DEVICE int idx(const orbital a)
Return coset index of given orbital angular momentum.
Define the atomic kind types and their sub types.
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public graml2024
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.
constants for the different operators of the 2c-integrals
integer, parameter, public operator_coulomb
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_uplo_to_full(matrix, workspace, uplo)
...
various cholesky decomposition related routines
subroutine, public cp_cfm_cholesky_decompose(matrix, n, info_out)
Used to replace a symmetric positive definite matrix M with its Cholesky decomposition U: M = U^T * U...
subroutine, public cp_cfm_cholesky_invert(matrix, n, info_out)
Used to replace Cholesky decomposition by the inverse.
used for collecting diagonalization schemes available for cp_cfm_type
subroutine, public cp_cfm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work, lowest_subset)
General Eigenvalue Problem AX = BXE Single option version: Cholesky decomposition of B.
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_fm_to_cfm(msourcer, msourcei, mtarget)
Construct a complex full matrix by taking its real and imaginary parts from two separate real-value f...
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_deallocate_matrix(matrix)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_reserve_all_blocks(matrix)
Reserves all blocks.
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Utility routines to open and close files. Tracking of preconnections.
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
logical function, public file_exists(file_name)
Checks if file exists, considering also the file discovery mechanism.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public cp_fm_power(matrix, work, exponent, threshold, n_dependent, verbose, eigvals)
...
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_diag(matrix, diag)
returns the diagonal elements of a fm
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_write_unformatted(fm, unit)
...
subroutine, public cp_fm_read_unformatted(fm, unit)
...
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
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
This is the start of a dbt_api, all publically needed functions are exported here....
subroutine, public fm_to_local_tensor(fm_global, mat_global, mat_local, tensor, bs_env, atom_ranges)
...
subroutine, public local_dbt_to_global_mat(tensor, mat_tensor, mat_global, para_env)
...
Routines from paper [Graml2024].
subroutine, public compute_fm_chi_gamma_freq(bs_env, fm_chi_gamma_freq, j_w, mat_chi_gamma_tau)
...
subroutine, public delete_unnecessary_files(bs_env)
...
subroutine, public fill_fm_sigma_c_gamma_time(fm_sigma_c_gamma_time, bs_env, mat_sigma_pos_tau, mat_sigma_neg_tau)
...
subroutine, public fm_write(fm, matrix_index, matrix_name, qs_env)
...
subroutine, public gw_calc_large_cell_gamma(qs_env, bs_env)
Perform GW band structure calculation.
subroutine, public compute_qp_energies(bs_env, qs_env, fm_sigma_x_gamma, fm_sigma_c_gamma_time)
...
subroutine, public multiply_fm_w_mic_time_with_minv_gamma(bs_env, qs_env, fm_w_mic_time)
...
subroutine, public fm_read(fm, bs_env, mat_name, idx)
...
subroutine, public get_w_mic(bs_env, qs_env, mat_chi_gamma_tau, fm_w_mic_time)
...
subroutine, public write_matrix(matrix, matrix_index, matrix_name, fm, qs_env)
...
subroutine, public g_occ_vir(bs_env, tau, fm_g_gamma, ispin, occ, vir)
...
subroutine, public create_fm_w_mic_time(bs_env, fm_w_mic_time)
...
subroutine, public compute_3c_integrals(qs_env, bs_env, t_3c, atoms_ao_1, atoms_ao_2, atoms_ri)
...
subroutine, public fourier_transform_w_to_t(bs_env, fm_w_mic_time, fm_w_mic_freq_j, j_w)
...
subroutine, public time_to_freq(bs_env, sigma_c_n_time, sigma_c_n_freq, ispin)
...
subroutine, public analyt_conti_and_print(bs_env, sigma_c_ikp_n_freq, sigma_x_ikp_n, v_xc_ikp_n, eigenval_scf, ikp, ispin)
...
subroutine, public de_init_bs_env(qs_env, bs_env)
Releases the memory-heavy GW intermediates that cannot be freed in bs_env_release,...
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
integer, parameter, public default_path_length
Routines to compute the Coulomb integral V_(alpha beta)(k) for a k-point k using lattice summation in...
subroutine, public build_2c_coulomb_matrix_kp(matrix_v_kp, kpoints, basis_type, cell, particle_set, qs_kind_set, atomic_kind_set, size_lattice_sum, operator_type, ikp_start, ikp_end)
...
Types and basic routines needed for a kpoint calculation.
Machine interface based on Fortran 2003 and POSIX.
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.
complex(kind=dp), parameter, public z_one
real(kind=dp), parameter, public twopi
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
subroutine, public mp_file_delete(filepath, info)
Deletes a file. Auxiliary routine to emulate 'replace' action for mp_file_open. Only the master proce...
Framework for 2c-integrals for RI.
subroutine, public ri_2c_integral_mat(qs_env, fm_matrix_minv_l_kpoints, fm_matrix_l, dimen_ri, ri_metric, do_kpoints, kpoints, put_mat_ks_env, regularization_ri, ikp_ext, do_build_cell_index)
...
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
subroutine, public cfm_ikp_from_fm_gamma(cfm_ikp, fm_gamma, ikp, qs_env, kpoints, basis_type)
...
subroutine, public get_all_vbm_cbm_bandgaps(bs_env)
...
subroutine, public mic_contribution_from_ikp(bs_env, qs_env, fm_w_mic_freq_j, cfm_w_ikp_freq_j, ikp, kpoints, basis_type, wkp_ext)
...
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.
Define the quickstep kind type and their sub types.
Utility methods to build 3-center integral tensors of various types.
subroutine, public build_3c_integrals(t3c, filter_eps, qs_env, nl_3c, basis_i, basis_j, basis_k, potential_parameter, int_eps, op_pos, do_kpoints, do_hfx_kpoints, desymmetrize, cell_sym, bounds_i, bounds_j, bounds_k, ri_range, img_to_ri_cell, cell_to_index_ext)
Build 3-center integral tensor.
Routines treating GW and RPA calculations with kpoints.
subroutine, public cp_cfm_power(matrix, threshold, exponent, min_eigval)
...
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Represent a complex full matrix.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains information about kpoints.
Provides all information about a quickstep kind.