91#include "./base/base_uses.f90"
97 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_large_cell_gamma'
119 CHARACTER(LEN=*),
PARAMETER :: routinen =
'gw_calc_large_cell_Gamma'
122 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma, fm_w_mic_time
123 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
125 CALL timeset(routinen, handle)
132 CALL get_mat_chi_gamma_tau(bs_env, qs_env, bs_env%mat_chi_Gamma_tau)
135 CALL get_w_mic(bs_env, qs_env, bs_env%mat_chi_Gamma_tau, fm_w_mic_time)
139 CALL get_sigma_x(bs_env, qs_env, fm_sigma_x_gamma)
143 CALL get_sigma_c(bs_env, qs_env, fm_w_mic_time, fm_sigma_c_gamma_time)
150 CALL timestop(handle)
160 SUBROUTINE get_mat_chi_gamma_tau(bs_env, qs_env, mat_chi_Gamma_tau)
163 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
165 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_mat_chi_Gamma_tau'
167 INTEGER :: handle, i_intval_idx, i_t, inner_loop_atoms_interval_index, ispin, j_intval_idx
168 INTEGER(KIND=int_8) :: flop
169 INTEGER,
DIMENSION(2) :: bounds_p, bounds_q, i_atoms, il_atoms, &
171 INTEGER,
DIMENSION(2, 2) :: bounds_comb
172 LOGICAL :: dist_too_long_i, dist_too_long_j
173 REAL(kind=
dp) :: t1, tau
174 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_3c_for_gocc, &
175 t_3c_for_gvir, t_3c_x_gocc, &
176 t_3c_x_gocc_2, t_3c_x_gvir, &
179 CALL timeset(routinen, handle)
181 DO i_t = 1, bs_env%num_time_freq_points
185 IF (bs_env%read_chi(i_t))
THEN
187 CALL fm_read(bs_env%fm_RI_RI, bs_env, bs_env%chi_name, i_t)
190 keep_sparsity=.false.)
192 IF (bs_env%unit_nr > 0)
THEN
193 WRITE (bs_env%unit_nr,
'(T2,A,I5,A,I3,A,F10.1,A)') &
194 χτ
'Read (i,k=0) from file for time point ', i_t,
' /', &
195 bs_env%num_time_freq_points, &
203 IF (.NOT. bs_env%calc_chi(i_t)) cycle
205 CALL create_tensors_chi(t_2c_gocc, t_2c_gvir, t_3c_for_gocc, t_3c_for_gvir, &
206 t_3c_x_gocc, t_3c_x_gvir, t_3c_x_gocc_2, t_3c_x_gvir_2, bs_env)
212 tau = bs_env%imag_time_points(i_t)
214 DO ispin = 1, bs_env%n_spin
215 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gocc, ispin, occ=.true., vir=.false.)
216 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gvir, ispin, occ=.false., vir=.true.)
219 bs_env%mat_ao_ao_tensor%matrix, t_2c_gocc, bs_env, &
220 bs_env%atoms_j_t_group)
222 bs_env%mat_ao_ao_tensor%matrix, t_2c_gvir, bs_env, &
223 bs_env%atoms_i_t_group)
227 DO i_intval_idx = 1, bs_env%n_intervals_i
228 DO j_intval_idx = 1, bs_env%n_intervals_j
229 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
230 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
232 IF (bs_env%skip_chi(i_intval_idx, j_intval_idx))
THEN
236 bs_env%n_skip_chi = bs_env%n_skip_chi + 1
241 DO inner_loop_atoms_interval_index = 1, bs_env%n_intervals_inner_loop_atoms
243 il_atoms = bs_env%inner_loop_atom_intervals(1:2, inner_loop_atoms_interval_index)
249 CALL check_dist(i_atoms, il_atoms, qs_env, bs_env, dist_too_long_i)
250 CALL check_dist(j_atoms, il_atoms, qs_env, bs_env, dist_too_long_j)
251 IF (.NOT. dist_too_long_i)
THEN
254 atoms_ao_1=i_atoms, atoms_ao_2=il_atoms)
256 CALL g_times_3c(t_3c_for_gocc, t_2c_gocc, t_3c_x_gocc, bs_env, &
257 j_atoms, i_atoms, il_atoms)
259 IF (.NOT. dist_too_long_j)
THEN
262 atoms_ao_1=j_atoms, atoms_ao_2=il_atoms)
264 CALL g_times_3c(t_3c_for_gvir, t_2c_gvir, t_3c_x_gvir, bs_env, &
265 i_atoms, j_atoms, il_atoms)
270 CALL dbt_copy(t_3c_x_gocc, t_3c_x_gocc_2, move_data=.true., order=[1, 3, 2])
271 CALL dbt_copy(t_3c_x_gvir, t_3c_x_gvir_2, move_data=.true.)
280 bounds_comb(1:2, 1) = [bs_env%i_ao_start_from_atom(j_atoms(1)), &
281 bs_env%i_ao_end_from_atom(j_atoms(2))]
282 bounds_comb(1:2, 2) = [bs_env%i_ao_start_from_atom(i_atoms(1)), &
283 bs_env%i_ao_end_from_atom(i_atoms(2))]
285 CALL get_bounds_from_atoms(bounds_p, i_atoms, [1, bs_env%n_atom], &
286 bs_env%min_RI_idx_from_AO_AO_atom, &
287 bs_env%max_RI_idx_from_AO_AO_atom)
288 CALL get_bounds_from_atoms(bounds_q, [1, bs_env%n_atom], j_atoms, &
289 bs_env%min_RI_idx_from_AO_AO_atom, &
290 bs_env%max_RI_idx_from_AO_AO_atom)
292 IF (bounds_q(1) > bounds_q(2) .OR. bounds_p(1) > bounds_p(2))
THEN
295 CALL dbt_contract(alpha=bs_env%spin_degeneracy, &
296 tensor_1=t_3c_x_gocc_2, tensor_2=t_3c_x_gvir_2, &
297 beta=1.0_dp, tensor_3=bs_env%t_chi, &
298 contract_1=[2, 3], notcontract_1=[1], map_1=[1], &
299 contract_2=[2, 3], notcontract_2=[1], map_2=[2], &
300 bounds_1=bounds_comb, &
303 filter_eps=bs_env%eps_filter, move_data=.false., flop=flop, &
304 unit_nr=bs_env%unit_nr_contract, &
305 log_verbose=bs_env%print_contract_verbose)
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, &
734 unit_nr=bs_env%unit_nr_contract, &
735 log_verbose=bs_env%print_contract_verbose)
738 CALL dbt_clear(t_3c_for_g)
740 CALL timestop(handle)
742 END SUBROUTINE g_times_3c
752 SUBROUTINE check_dist(atoms_1, atoms_2, qs_env, bs_env, dist_too_long)
753 INTEGER,
DIMENSION(2) :: atoms_1, atoms_2
756 LOGICAL :: dist_too_long
758 CHARACTER(LEN=*),
PARAMETER :: routinen =
'check_dist'
760 INTEGER :: atom_1, atom_2, handle
761 REAL(
dp) :: abs_rab, min_dist_ao_atoms
762 REAL(kind=
dp),
DIMENSION(3) :: rab
766 CALL timeset(routinen, handle)
768 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
770 min_dist_ao_atoms = huge(1.0_dp)
771 DO atom_1 = atoms_1(1), atoms_1(2)
772 DO atom_2 = atoms_2(1), atoms_2(2)
773 rab =
pbc(particle_set(atom_1)%r(1:3), particle_set(atom_2)%r(1:3), cell)
775 abs_rab = sqrt(rab(1)**2 + rab(2)**2 + rab(3)**2)
777 min_dist_ao_atoms = min(min_dist_ao_atoms, abs_rab)
781 dist_too_long = (min_dist_ao_atoms > bs_env%max_dist_AO_atoms)
783 CALL timestop(handle)
785 END SUBROUTINE check_dist
794 SUBROUTINE get_w_mic(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
797 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
798 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
800 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_W_MIC'
804 CALL timeset(routinen, handle)
806 IF (bs_env%all_W_exist)
THEN
807 CALL read_w_mic_time(bs_env, mat_chi_gamma_tau, fm_w_mic_time)
809 CALL compute_w_mic(bs_env, qs_env, mat_chi_gamma_tau, fm_w_mic_time)
812 CALL timestop(handle)
823 SUBROUTINE compute_v_k_by_lattice_sum(bs_env, qs_env, fm_V_kp, ikp_batch)
826 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
829 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_V_k_by_lattice_sum'
831 INTEGER :: handle, ikp, ikp_end, ikp_start, &
832 nkp_chi_eps_w_batch, re_im
835 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_v_kp
837 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
839 CALL timeset(routinen, handle)
841 nkp_chi_eps_w_batch = bs_env%nkp_chi_eps_W_batch
843 ikp_start = (ikp_batch - 1)*bs_env%nkp_chi_eps_W_batch + 1
844 ikp_end = min(ikp_batch*bs_env%nkp_chi_eps_W_batch, bs_env%kpoints_chi_eps_W%nkp)
847 ALLOCATE (mat_v_kp(ikp_start:ikp_end, 2))
850 DO ikp = ikp_start, ikp_end
851 NULLIFY (mat_v_kp(ikp, re_im)%matrix)
852 ALLOCATE (mat_v_kp(ikp, re_im)%matrix)
853 CALL dbcsr_create(mat_v_kp(ikp, re_im)%matrix, template=bs_env%mat_RI_RI%matrix)
855 CALL dbcsr_set(mat_v_kp(ikp, re_im)%matrix, 0.0_dp)
860 particle_set=particle_set, &
862 qs_kind_set=qs_kind_set, &
863 atomic_kind_set=atomic_kind_set)
865 IF (ikp_end <= bs_env%nkp_chi_eps_W_orig)
THEN
868 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
870 ELSE IF (ikp_start > bs_env%nkp_chi_eps_W_orig .AND. &
871 ikp_end <= bs_env%nkp_chi_eps_W_orig_plus_extra)
THEN
874 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_extra
878 cpabort(
"Error with k-point parallelization.")
883 bs_env%kpoints_chi_eps_W, &
884 basis_type=
"RI_AUX", &
886 particle_set=particle_set, &
887 qs_kind_set=qs_kind_set, &
888 atomic_kind_set=atomic_kind_set, &
889 size_lattice_sum=bs_env%size_lattice_sum_V, &
891 ikp_start=ikp_start, &
894 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
896 ALLOCATE (fm_v_kp(ikp_start:ikp_end, 2))
898 DO ikp = ikp_start, ikp_end
899 CALL cp_fm_create(fm_v_kp(ikp, re_im), bs_env%fm_RI_RI%matrix_struct)
904 DEALLOCATE (mat_v_kp)
906 CALL timestop(handle)
908 END SUBROUTINE compute_v_k_by_lattice_sum
919 SUBROUTINE compute_minvvsqrt_vsqrt(bs_env, qs_env, fm_V_kp, cfm_V_sqrt_ikp, &
920 cfm_M_inv_V_sqrt_ikp, ikp)
923 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
924 TYPE(
cp_cfm_type) :: cfm_v_sqrt_ikp, cfm_m_inv_v_sqrt_ikp
927 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_MinvVsqrt_Vsqrt'
929 INTEGER :: handle, info, n_ri
931 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_m_ikp
933 CALL timeset(routinen, handle)
939 n_ri, bs_env%ri_metric, do_kpoints=.true., &
940 kpoints=bs_env%kpoints_chi_eps_W, &
941 regularization_ri=bs_env%regularization_RI, ikp_ext=ikp, &
942 do_build_cell_index=(ikp == 1))
945 CALL cp_cfm_create(cfm_v_sqrt_ikp, fm_v_kp(ikp, 1)%matrix_struct)
946 CALL cp_cfm_create(cfm_m_inv_v_sqrt_ikp, fm_v_kp(ikp, 1)%matrix_struct)
948 CALL cp_cfm_create(cfm_m_inv_ikp, fm_v_kp(ikp, 1)%matrix_struct)
950 CALL cp_fm_to_cfm(fm_m_ikp(1, 1), fm_m_ikp(1, 2), cfm_m_inv_ikp)
951 CALL cp_fm_to_cfm(fm_v_kp(ikp, 1), fm_v_kp(ikp, 2), cfm_v_sqrt_ikp)
967 CALL cp_cfm_power(cfm_work, threshold=bs_env%eps_eigval_mat_RI, exponent=-1.0_dp)
976 CALL clean_lower_part(cfm_v_sqrt_ikp)
979 CALL cp_cfm_power(cfm_work, threshold=0.0_dp, exponent=0.5_dp)
985 CALL parallel_gemm(
"N",
"C", n_ri, n_ri, n_ri,
z_one, cfm_m_inv_ikp, cfm_v_sqrt_ikp, &
986 z_zero, cfm_m_inv_v_sqrt_ikp)
990 CALL timestop(handle)
992 END SUBROUTINE compute_minvvsqrt_vsqrt
1000 SUBROUTINE read_w_mic_time(bs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
1002 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1003 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1005 CHARACTER(LEN=*),
PARAMETER :: routinen =
'read_W_MIC_time'
1007 INTEGER :: handle, i_t
1010 CALL timeset(routinen, handle)
1015 DO i_t = 1, bs_env%num_time_freq_points
1019 CALL fm_read(fm_w_mic_time(i_t), bs_env, bs_env%W_time_name, i_t)
1021 IF (bs_env%unit_nr > 0)
THEN
1022 WRITE (bs_env%unit_nr,
'(T2,A,I5,A,I3,A,F10.1,A)') &
1023 τ
'Read W^MIC(i) from file for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1029 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1034 CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
1036 CALL fm_read(bs_env%fm_W_MIC_freq_zero, bs_env,
"W_freq_rtp", 0)
1037 IF (bs_env%unit_nr > 0)
THEN
1038 WRITE (bs_env%unit_nr,
'(T2,A,I3,A,I3,A,F10.1,A)') &
1039 'Read W^MIC(f=0) from file for freq. point ', 1,
' /', 1, &
1044 CALL timestop(handle)
1046 END SUBROUTINE read_w_mic_time
1055 SUBROUTINE compute_w_mic(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
1058 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1059 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1061 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_W_MIC'
1063 INTEGER :: handle, i_t, ikp, ikp_batch, &
1066 TYPE(
cp_cfm_type) :: cfm_m_inv_v_sqrt_ikp, cfm_v_sqrt_ikp
1067 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
1069 CALL timeset(routinen, handle)
1073 DO ikp_batch = 1, bs_env%num_chi_eps_W_batches
1078 CALL compute_v_k_by_lattice_sum(bs_env, qs_env, fm_v_kp, ikp_batch)
1080 DO ikp_in_batch = 1, bs_env%nkp_chi_eps_W_batch
1082 ikp = (ikp_batch - 1)*bs_env%nkp_chi_eps_W_batch + ikp_in_batch
1084 IF (ikp > bs_env%nkp_chi_eps_W_orig_plus_extra) cycle
1086 CALL compute_minvvsqrt_vsqrt(bs_env, qs_env, fm_v_kp, &
1087 cfm_v_sqrt_ikp, cfm_m_inv_v_sqrt_ikp, ikp)
1089 CALL bs_env%para_env%sync()
1093 DO j_w = 1, bs_env%num_time_freq_points
1096 IF (bs_env%approx_kp_extrapol .AND. j_w > 1 .AND. &
1097 ikp > bs_env%nkp_chi_eps_W_orig) cycle
1099 CALL compute_fm_w_mic_freq_j(bs_env, qs_env, bs_env%fm_W_MIC_freq, j_w, ikp, &
1100 mat_chi_gamma_tau, cfm_m_inv_v_sqrt_ikp, &
1110 DEALLOCATE (fm_v_kp)
1112 IF (bs_env%unit_nr > 0)
THEN
1113 WRITE (bs_env%unit_nr,
'(T2,A,I12,A,I3,A,F10.1,A)') &
1114 τ
'Computed W(i,k) for k-point batch', &
1115 ikp_batch,
' /', bs_env%num_chi_eps_W_batches, &
1121 IF (bs_env%approx_kp_extrapol)
THEN
1122 CALL apply_extrapol_factor(bs_env, fm_w_mic_time)
1128 DO i_t = 1, bs_env%num_time_freq_points
1129 CALL fm_write(fm_w_mic_time(i_t), i_t, bs_env%W_time_name, qs_env)
1139 CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
1143 DO i_t = 1, bs_env%num_time_freq_points
1146 bs_env%imag_time_weights_freq_zero(i_t), fm_w_mic_time(i_t))
1149 CALL fm_write(bs_env%fm_W_MIC_freq_zero, 0,
"W_freq_rtp", qs_env)
1151 IF (bs_env%unit_nr > 0)
THEN
1152 WRITE (bs_env%unit_nr,
'(T2,A,I11,A,I3,A,F10.1,A)') &
1153 'Computed W(f=0,k) for k-point batch', &
1159 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1161 CALL timestop(handle)
1163 END SUBROUTINE compute_w_mic
1176 SUBROUTINE compute_fm_w_mic_freq_j(bs_env, qs_env, fm_W_MIC_freq_j, j_w, ikp, mat_chi_Gamma_tau, &
1177 cfm_M_inv_V_sqrt_ikp, cfm_V_sqrt_ikp)
1182 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1183 TYPE(
cp_cfm_type) :: cfm_m_inv_v_sqrt_ikp, cfm_v_sqrt_ikp
1185 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_fm_W_MIC_freq_j'
1188 TYPE(
cp_cfm_type) :: cfm_chi_ikp_freq_j, cfm_w_ikp_freq_j
1190 CALL timeset(routinen, handle)
1199 ikp, qs_env, bs_env%kpoints_chi_eps_W,
"RI_AUX")
1202 CALL cp_cfm_power(cfm_chi_ikp_freq_j, threshold=0.0_dp, exponent=1.0_dp)
1206 CALL compute_cfm_w_ikp_freq_j(bs_env, cfm_chi_ikp_freq_j, cfm_v_sqrt_ikp, &
1207 cfm_m_inv_v_sqrt_ikp, cfm_w_ikp_freq_j)
1210 SELECT CASE (bs_env%approx_kp_extrapol)
1214 bs_env%kpoints_chi_eps_W,
"RI_AUX")
1225 cfm_w_ikp_freq_j, ikp, bs_env%kpoints_chi_eps_W, &
1228 IF (ikp <= bs_env%nkp_chi_eps_W_orig)
THEN
1230 cfm_w_ikp_freq_j, ikp, bs_env%kpoints_chi_eps_W, &
1231 "RI_AUX", wkp_ext=bs_env%wkp_orig)
1237 IF (ikp <= bs_env%nkp_chi_eps_W_orig)
THEN
1239 ikp, bs_env%kpoints_chi_eps_W,
"RI_AUX", &
1240 wkp_ext=bs_env%wkp_orig)
1246 CALL timestop(handle)
1248 END SUBROUTINE compute_fm_w_mic_freq_j
1254 SUBROUTINE clean_lower_part(cfm_mat)
1257 CHARACTER(LEN=*),
PARAMETER :: routinen =
'clean_lower_part'
1259 INTEGER :: handle, i_row, j_col, j_global, &
1260 ncol_local, nrow_local
1261 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1263 CALL timeset(routinen, handle)
1266 nrow_local=nrow_local, ncol_local=ncol_local, &
1267 row_indices=row_indices, col_indices=col_indices)
1269 DO j_col = 1, ncol_local
1270 j_global = col_indices(j_col)
1271 DO i_row = 1, nrow_local
1272 IF (j_global < row_indices(i_row)) cfm_mat%local_data(i_row, j_col) =
z_zero
1276 CALL timestop(handle)
1278 END SUBROUTINE clean_lower_part
1285 SUBROUTINE apply_extrapol_factor(bs_env, fm_W_MIC_time)
1287 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1289 CHARACTER(LEN=*),
PARAMETER :: routinen =
'apply_extrapol_factor'
1291 INTEGER :: handle, i, i_t, j, ncol_local, nrow_local
1292 REAL(kind=
dp) :: extrapol_factor, w_extra_1, w_no_extra_1
1294 CALL timeset(routinen, handle)
1296 CALL cp_fm_get_info(matrix=fm_w_mic_time(1), nrow_local=nrow_local, ncol_local=ncol_local)
1298 DO i_t = 1, bs_env%num_time_freq_points
1299 DO j = 1, ncol_local
1300 DO i = 1, nrow_local
1302 w_extra_1 = bs_env%fm_W_MIC_freq_1_extra%local_data(i, j)
1303 w_no_extra_1 = bs_env%fm_W_MIC_freq_1_no_extra%local_data(i, j)
1305 IF (abs(w_no_extra_1) > 1.0e-13)
THEN
1306 extrapol_factor = abs(w_extra_1/w_no_extra_1)
1308 extrapol_factor = 1.0_dp
1312 IF (extrapol_factor > 10.0_dp) extrapol_factor = 1.0_dp
1314 fm_w_mic_time(i_t)%local_data(i, j) = fm_w_mic_time(i_t)%local_data(i, j) &
1320 CALL timestop(handle)
1322 END SUBROUTINE apply_extrapol_factor
1335 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1337 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_fm_chi_Gamma_freq'
1339 INTEGER :: handle, i_t
1340 REAL(kind=
dp) :: freq_j, time_i, weight_ij
1342 CALL timeset(routinen, handle)
1344 CALL dbcsr_set(bs_env%mat_RI_RI%matrix, 0.0_dp)
1346 freq_j = bs_env%imag_freq_points(j_w)
1348 DO i_t = 1, bs_env%num_time_freq_points
1350 time_i = bs_env%imag_time_points(i_t)
1351 weight_ij = bs_env%weights_cos_t_to_w(j_w, i_t)
1354 CALL dbcsr_add(bs_env%mat_RI_RI%matrix, mat_chi_gamma_tau(i_t)%matrix, &
1355 1.0_dp, cos(time_i*freq_j)*weight_ij)
1361 CALL timestop(handle)
1374 SUBROUTINE mat_ikp_from_mat_gamma(mat_ikp_re, mat_ikp_im, mat_Gamma, kpoints, ikp, qs_env)
1375 TYPE(
dbcsr_type) :: mat_ikp_re, mat_ikp_im, mat_gamma
1380 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mat_ikp_from_mat_Gamma'
1382 INTEGER :: col, handle, i_cell, j_cell, num_cells, &
1384 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell
1385 LOGICAL :: f, i_cell_is_the_minimum_image_cell
1386 REAL(kind=
dp) :: abs_rab_cell_i, abs_rab_cell_j, arg
1387 REAL(kind=
dp),
DIMENSION(3) :: cell_vector, cell_vector_j, rab_cell_i, &
1389 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat
1390 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block_im, block_re, data_block
1395 CALL timeset(routinen, handle)
1403 NULLIFY (cell, particle_set)
1404 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
1407 index_to_cell => kpoints%index_to_cell
1409 num_cells =
SIZE(index_to_cell, 2)
1411 DO i_cell = 1, num_cells
1417 cell_vector(1:3) = matmul(hmat, real(index_to_cell(1:3, i_cell),
dp))
1419 rab_cell_i(1:3) =
pbc(particle_set(row)%r(1:3), cell) - &
1420 (
pbc(particle_set(col)%r(1:3), cell) + cell_vector(1:3))
1421 abs_rab_cell_i = sqrt(rab_cell_i(1)**2 + rab_cell_i(2)**2 + rab_cell_i(3)**2)
1424 i_cell_is_the_minimum_image_cell = .true.
1425 DO j_cell = 1, num_cells
1426 cell_vector_j(1:3) = matmul(hmat, real(index_to_cell(1:3, j_cell),
dp))
1427 rab_cell_j(1:3) =
pbc(particle_set(row)%r(1:3), cell) - &
1428 (
pbc(particle_set(col)%r(1:3), cell) + cell_vector_j(1:3))
1429 abs_rab_cell_j = sqrt(rab_cell_j(1)**2 + rab_cell_j(2)**2 + rab_cell_j(3)**2)
1431 IF (abs_rab_cell_i > abs_rab_cell_j + 1.0e-6_dp)
THEN
1432 i_cell_is_the_minimum_image_cell = .false.
1436 IF (i_cell_is_the_minimum_image_cell)
THEN
1437 NULLIFY (block_re, block_im)
1438 CALL dbcsr_get_block_p(matrix=mat_ikp_re, row=row, col=col, block=block_re, found=f)
1439 CALL dbcsr_get_block_p(matrix=mat_ikp_im, row=row, col=col, block=block_im, found=f)
1440 cpassert(all(abs(block_re) < 1.0e-10_dp))
1441 cpassert(all(abs(block_im) < 1.0e-10_dp))
1443 arg = real(index_to_cell(1, i_cell),
dp)*kpoints%xkp(1, ikp) + &
1444 REAL(index_to_cell(2, i_cell),
dp)*kpoints%xkp(2, ikp) + &
1445 REAL(index_to_cell(3, i_cell),
dp)*kpoints%xkp(3, ikp)
1447 block_re(:, :) = cos(
twopi*arg)*data_block(:, :)
1448 block_im(:, :) = sin(
twopi*arg)*data_block(:, :)
1456 CALL timestop(handle)
1458 END SUBROUTINE mat_ikp_from_mat_gamma
1468 SUBROUTINE compute_cfm_w_ikp_freq_j(bs_env, cfm_chi_ikp_freq_j, cfm_V_sqrt_ikp, &
1469 cfm_M_inv_V_sqrt_ikp, cfm_W_ikp_freq_j)
1472 TYPE(
cp_cfm_type) :: cfm_chi_ikp_freq_j, cfm_v_sqrt_ikp, &
1473 cfm_m_inv_v_sqrt_ikp, cfm_w_ikp_freq_j
1475 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_cfm_W_ikp_freq_j'
1477 INTEGER :: handle, info, n_ri
1480 CALL timeset(routinen, handle)
1482 CALL cp_cfm_create(cfm_work, cfm_chi_ikp_freq_j%matrix_struct)
1489 cfm_chi_ikp_freq_j, cfm_m_inv_v_sqrt_ikp,
z_zero, cfm_work)
1493 CALL cp_cfm_create(cfm_eps_ikp_freq_j, cfm_work%matrix_struct)
1495 cfm_m_inv_v_sqrt_ikp, cfm_work,
z_zero, cfm_eps_ikp_freq_j)
1498 CALL cfm_add_on_diag(cfm_eps_ikp_freq_j,
z_one)
1511 CALL cfm_add_on_diag(cfm_eps_ikp_freq_j, -
z_one)
1514 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri,
z_one, cfm_eps_ikp_freq_j, cfm_v_sqrt_ikp, &
1518 CALL cp_cfm_create(cfm_w_ikp_freq_j, cfm_work%matrix_struct)
1520 z_zero, cfm_w_ikp_freq_j)
1525 CALL timestop(handle)
1527 END SUBROUTINE compute_cfm_w_ikp_freq_j
1534 SUBROUTINE cfm_add_on_diag(cfm, alpha)
1537 COMPLEX(KIND=dp) :: alpha
1539 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cfm_add_on_diag'
1541 INTEGER :: handle, i_row, j_col, j_global, &
1542 ncol_local, nrow_local
1543 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1545 CALL timeset(routinen, handle)
1548 nrow_local=nrow_local, &
1549 ncol_local=ncol_local, &
1550 row_indices=row_indices, &
1551 col_indices=col_indices)
1554 DO j_col = 1, ncol_local
1555 j_global = col_indices(j_col)
1556 DO i_row = 1, nrow_local
1557 IF (j_global == row_indices(i_row))
THEN
1558 cfm%local_data(i_row, j_col) = cfm%local_data(i_row, j_col) + alpha
1563 CALL timestop(handle)
1565 END SUBROUTINE cfm_add_on_diag
1574 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1576 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_fm_W_MIC_time'
1578 INTEGER :: handle, i_t
1580 CALL timeset(routinen, handle)
1582 ALLOCATE (fm_w_mic_time(bs_env%num_time_freq_points))
1583 DO i_t = 1, bs_env%num_time_freq_points
1584 CALL cp_fm_create(fm_w_mic_time(i_t), bs_env%fm_RI_RI%matrix_struct, set_zero=.true.)
1587 CALL timestop(handle)
1600 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1604 CHARACTER(LEN=*),
PARAMETER :: routinen =
'Fourier_transform_w_to_t'
1606 INTEGER :: handle, i_t
1607 REAL(kind=
dp) :: freq_j, time_i, weight_ij
1609 CALL timeset(routinen, handle)
1611 freq_j = bs_env%imag_freq_points(j_w)
1613 DO i_t = 1, bs_env%num_time_freq_points
1615 time_i = bs_env%imag_time_points(i_t)
1616 weight_ij = bs_env%weights_cos_w_to_t(i_t, j_w)
1620 beta=weight_ij*cos(time_i*freq_j), matrix_b=fm_w_mic_freq_j)
1624 CALL timestop(handle)
1637 TYPE(
cp_fm_type),
DIMENSION(:) :: fm_w_mic_time
1639 CHARACTER(LEN=*),
PARAMETER :: routinen =
'multiply_fm_W_MIC_time_with_Minv_Gamma'
1641 INTEGER :: handle, i_t, n_ri, ndep
1643 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_minv_gamma
1645 CALL timeset(routinen, handle)
1649 CALL cp_fm_create(fm_work, fm_w_mic_time(1)%matrix_struct)
1653 bs_env%ri_metric, do_kpoints=.false.)
1655 CALL cp_fm_power(fm_minv_gamma(1, 1), fm_work, -1.0_dp, 0.0_dp, ndep)
1658 DO i_t = 1,
SIZE(fm_w_mic_time)
1660 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_minv_gamma(1, 1), &
1661 fm_w_mic_time(i_t), 0.0_dp, fm_work)
1663 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_work, &
1664 fm_minv_gamma(1, 1), 0.0_dp, fm_w_mic_time(i_t))
1671 CALL timestop(handle)
1681 SUBROUTINE get_sigma_x(bs_env, qs_env, fm_Sigma_x_Gamma)
1684 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
1686 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_Sigma_x'
1688 INTEGER :: handle, ispin
1690 CALL timeset(routinen, handle)
1692 ALLOCATE (fm_sigma_x_gamma(bs_env%n_spin))
1693 DO ispin = 1, bs_env%n_spin
1694 CALL cp_fm_create(fm_sigma_x_gamma(ispin), bs_env%fm_s_Gamma%matrix_struct)
1697 IF (bs_env%Sigma_x_exists)
THEN
1698 DO ispin = 1, bs_env%n_spin
1699 CALL fm_read(fm_sigma_x_gamma(ispin), bs_env, bs_env%Sigma_x_name, ispin)
1702 CALL compute_sigma_x(bs_env, qs_env, fm_sigma_x_gamma)
1705 CALL timestop(handle)
1707 END SUBROUTINE get_sigma_x
1715 SUBROUTINE compute_sigma_x(bs_env, qs_env, fm_Sigma_x_Gamma)
1718 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
1720 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_x'
1722 INTEGER :: handle, i_intval_idx, ispin, j_intval_idx
1723 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
1725 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_vtr_gamma
1727 TYPE(dbt_type) :: t_2c_d, t_2c_sigma_x, t_2c_v, t_3c_x_v
1729 CALL timeset(routinen, handle)
1733 CALL dbt_create(bs_env%t_G, t_2c_d)
1734 CALL dbt_create(bs_env%t_W, t_2c_v)
1735 CALL dbt_create(bs_env%t_G, t_2c_sigma_x)
1736 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_v)
1737 CALL dbcsr_create(mat_sigma_x_gamma, template=bs_env%mat_ao_ao%matrix)
1741 bs_env%trunc_coulomb, do_kpoints=.false.)
1746 DO ispin = 1, bs_env%n_spin
1749 CALL g_occ_vir(bs_env, 0.0_dp, bs_env%fm_work_mo(2), ispin, occ=.true., vir=.false.)
1752 bs_env%mat_ao_ao_tensor%matrix, t_2c_d, bs_env, &
1753 bs_env%atoms_i_t_group)
1756 bs_env%mat_RI_RI_tensor%matrix, t_2c_v, bs_env, &
1757 bs_env%atoms_j_t_group)
1761 DO i_intval_idx = 1, bs_env%n_intervals_i
1762 DO j_intval_idx = 1, bs_env%n_intervals_j
1763 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
1764 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
1768 CALL compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_v, t_2c_v)
1772 CALL contract_to_sigma(t_2c_d, t_3c_x_v, t_2c_sigma_x, i_atoms, j_atoms, &
1773 qs_env, bs_env, occ=.true., vir=.false.)
1779 mat_sigma_x_gamma, bs_env%para_env)
1781 CALL write_matrix(mat_sigma_x_gamma, ispin, bs_env%Sigma_x_name, &
1782 bs_env%fm_work_mo(1), qs_env)
1788 IF (bs_env%unit_nr > 0)
THEN
1789 WRITE (bs_env%unit_nr,
'(T2,A,T55,A,F10.1,A)') &
1790 Σ
'Computed ^x(k=0),',
' Execution time',
m_walltime() - t1,
' s'
1791 WRITE (bs_env%unit_nr,
'(A)')
' '
1795 CALL dbt_destroy(t_2c_d)
1796 CALL dbt_destroy(t_2c_v)
1797 CALL dbt_destroy(t_2c_sigma_x)
1798 CALL dbt_destroy(t_3c_x_v)
1801 CALL timestop(handle)
1803 END SUBROUTINE compute_sigma_x
1812 SUBROUTINE get_sigma_c(bs_env, qs_env, fm_W_MIC_time, fm_Sigma_c_Gamma_time)
1815 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1816 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
1818 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_Sigma_c'
1820 INTEGER :: handle, i_intval_idx, i_t, ispin, &
1821 j_intval_idx, read_write_index
1822 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
1823 REAL(kind=
dp) :: t1, tau
1824 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
1825 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, &
1826 t_2c_sigma_neg_tau, &
1827 t_2c_sigma_pos_tau, t_2c_w, t_3c_x_w
1829 CALL timeset(routinen, handle)
1831 CALL create_mat_for_sigma_c(bs_env, t_2c_gocc, t_2c_gvir, t_2c_w, t_2c_sigma_neg_tau, &
1832 t_2c_sigma_pos_tau, t_3c_x_w, &
1833 mat_sigma_neg_tau, mat_sigma_pos_tau)
1835 DO i_t = 1, bs_env%num_time_freq_points
1837 DO ispin = 1, bs_env%n_spin
1841 read_write_index = i_t + (ispin - 1)*bs_env%num_time_freq_points
1844 IF (bs_env%Sigma_c_exists(i_t, ispin))
THEN
1845 CALL fm_read(bs_env%fm_work_mo(1), bs_env, bs_env%Sigma_p_name, read_write_index)
1846 CALL copy_fm_to_dbcsr(bs_env%fm_work_mo(1), mat_sigma_pos_tau(i_t, ispin)%matrix, &
1847 keep_sparsity=.false.)
1848 CALL fm_read(bs_env%fm_work_mo(1), bs_env, bs_env%Sigma_n_name, read_write_index)
1849 CALL copy_fm_to_dbcsr(bs_env%fm_work_mo(1), mat_sigma_neg_tau(i_t, ispin)%matrix, &
1850 keep_sparsity=.false.)
1851 IF (bs_env%unit_nr > 0)
THEN
1852 WRITE (bs_env%unit_nr,
'(T2,2A,I3,A,I3,A,F10.1,A)') Στ
'Read ^c(i,k=0) ', &
1853 'from file for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1861 tau = bs_env%imag_time_points(i_t)
1863 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gocc, ispin, occ=.true., vir=.false.)
1864 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gvir, ispin, occ=.false., vir=.true.)
1868 bs_env%mat_ao_ao_tensor%matrix, t_2c_gocc, bs_env, &
1869 bs_env%atoms_i_t_group)
1871 bs_env%mat_ao_ao_tensor%matrix, t_2c_gvir, bs_env, &
1872 bs_env%atoms_i_t_group)
1874 bs_env%mat_RI_RI_tensor%matrix, t_2c_w, bs_env, &
1875 bs_env%atoms_j_t_group)
1879 DO i_intval_idx = 1, bs_env%n_intervals_i
1880 DO j_intval_idx = 1, bs_env%n_intervals_j
1881 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
1882 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
1884 IF (bs_env%skip_Sigma_occ(i_intval_idx, j_intval_idx) .AND. &
1885 bs_env%skip_Sigma_vir(i_intval_idx, j_intval_idx))
THEN
1889 bs_env%n_skip_sigma = bs_env%n_skip_sigma + 1
1896 CALL compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_w, t_2c_w)
1900 CALL contract_to_sigma(t_2c_gocc, t_3c_x_w, t_2c_sigma_neg_tau, i_atoms, j_atoms, &
1901 qs_env, bs_env, occ=.true., vir=.false., &
1902 can_skip=bs_env%skip_Sigma_occ(i_intval_idx, j_intval_idx))
1905 CALL contract_to_sigma(t_2c_gvir, t_3c_x_w, t_2c_sigma_pos_tau, i_atoms, j_atoms, &
1906 qs_env, bs_env, occ=.false., vir=.true., &
1907 can_skip=bs_env%skip_Sigma_vir(i_intval_idx, j_intval_idx))
1915 mat_sigma_neg_tau(i_t, ispin)%matrix, bs_env%para_env)
1917 mat_sigma_pos_tau(i_t, ispin)%matrix, bs_env%para_env)
1919 CALL write_matrix(mat_sigma_pos_tau(i_t, ispin)%matrix, read_write_index, &
1920 bs_env%Sigma_p_name, bs_env%fm_work_mo(1), qs_env)
1921 CALL write_matrix(mat_sigma_neg_tau(i_t, ispin)%matrix, read_write_index, &
1922 bs_env%Sigma_n_name, bs_env%fm_work_mo(1), qs_env)
1924 IF (bs_env%unit_nr > 0)
THEN
1925 WRITE (bs_env%unit_nr,
'(T2,A,I10,A,I3,A,F10.1,A)') &
1926 Στ
'Computed ^c(i,k=0) for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1934 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1937 mat_sigma_pos_tau, mat_sigma_neg_tau)
1939 CALL print_skipping(bs_env)
1941 CALL destroy_mat_sigma_c(t_2c_gocc, t_2c_gvir, t_2c_w, t_2c_sigma_neg_tau, &
1942 t_2c_sigma_pos_tau, t_3c_x_w, fm_w_mic_time, &
1943 mat_sigma_neg_tau, mat_sigma_pos_tau)
1947 CALL timestop(handle)
1949 END SUBROUTINE get_sigma_c
1963 SUBROUTINE create_mat_for_sigma_c(bs_env, t_2c_Gocc, t_2c_Gvir, t_2c_W, t_2c_Sigma_neg_tau, &
1964 t_2c_Sigma_pos_tau, t_3c_x_W, &
1965 mat_Sigma_neg_tau, mat_Sigma_pos_tau)
1968 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_2c_w, &
1969 t_2c_sigma_neg_tau, &
1970 t_2c_sigma_pos_tau, t_3c_x_w
1971 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
1973 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_mat_for_Sigma_c'
1975 INTEGER :: handle, i_t, ispin
1977 CALL timeset(routinen, handle)
1979 CALL dbt_create(bs_env%t_G, t_2c_gocc)
1980 CALL dbt_create(bs_env%t_G, t_2c_gvir)
1981 CALL dbt_create(bs_env%t_W, t_2c_w)
1982 CALL dbt_create(bs_env%t_G, t_2c_sigma_neg_tau)
1983 CALL dbt_create(bs_env%t_G, t_2c_sigma_pos_tau)
1984 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_w)
1986 NULLIFY (mat_sigma_neg_tau, mat_sigma_pos_tau)
1987 ALLOCATE (mat_sigma_neg_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1988 ALLOCATE (mat_sigma_pos_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1990 DO ispin = 1, bs_env%n_spin
1991 DO i_t = 1, bs_env%num_time_freq_points
1992 ALLOCATE (mat_sigma_neg_tau(i_t, ispin)%matrix)
1993 ALLOCATE (mat_sigma_pos_tau(i_t, ispin)%matrix)
1994 CALL dbcsr_create(mat_sigma_neg_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1995 CALL dbcsr_create(mat_sigma_pos_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1999 CALL timestop(handle)
2001 END SUBROUTINE create_mat_for_sigma_c
2012 SUBROUTINE compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_W, t_2c_W)
2016 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
2017 TYPE(dbt_type) :: t_3c_x_w, t_2c_w
2019 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_3c_and_contract_W'
2021 INTEGER :: handle, ri_intval_idx
2022 INTEGER(KIND=int_8) :: flop
2023 INTEGER,
DIMENSION(2) :: bounds_p, bounds_q, ri_atoms
2024 INTEGER,
DIMENSION(2, 2) :: bounds_ao
2025 TYPE(dbt_type) :: t_3c_for_w, t_3c_x_w_tmp
2027 CALL timeset(routinen, handle)
2029 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_w_tmp)
2030 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_for_w)
2040 bounds_q(1:2) = [bs_env%i_RI_start_from_atom(j_atoms(1)), &
2041 bs_env%i_RI_end_from_atom(j_atoms(2))]
2043 DO ri_intval_idx = 1, bs_env%n_intervals_inner_loop_atoms
2044 ri_atoms = bs_env%inner_loop_atom_intervals(1:2, ri_intval_idx)
2046 CALL get_bounds_from_atoms(bounds_p, i_atoms, [1, bs_env%n_atom], &
2047 bs_env%min_RI_idx_from_AO_AO_atom, &
2048 bs_env%max_RI_idx_from_AO_AO_atom, &
2050 indices_3_start=bs_env%i_RI_start_from_atom, &
2051 indices_3_end=bs_env%i_RI_end_from_atom)
2054 CALL get_bounds_from_atoms(bounds_ao(:, 2), ri_atoms, i_atoms, &
2055 bs_env%min_AO_idx_from_RI_AO_atom, &
2056 bs_env%max_AO_idx_from_RI_AO_atom)
2058 CALL get_bounds_from_atoms(bounds_ao(:, 1), ri_atoms, [1, bs_env%n_atom], &
2059 bs_env%min_AO_idx_from_RI_AO_atom, &
2060 bs_env%max_AO_idx_from_RI_AO_atom, &
2062 indices_3_start=bs_env%i_ao_start_from_atom, &
2063 indices_3_end=bs_env%i_ao_end_from_atom)
2065 IF (bounds_p(1) > bounds_p(2) .OR. bounds_ao(1, 2) > bounds_ao(2, 2))
THEN
2071 atoms_ao_1=i_atoms, atoms_ri=ri_atoms)
2074 CALL dbt_contract(alpha=1.0_dp, &
2076 tensor_2=t_3c_for_w, &
2078 tensor_3=t_3c_x_w_tmp, &
2079 contract_1=[2], notcontract_1=[1], map_1=[1], &
2080 contract_2=[1], notcontract_2=[2, 3], map_2=[2, 3], &
2081 bounds_1=bounds_p, &
2082 bounds_2=bounds_q, &
2083 bounds_3=bounds_ao, &
2085 move_data=.false., &
2086 filter_eps=bs_env%eps_filter, &
2087 unit_nr=bs_env%unit_nr_contract, &
2088 log_verbose=bs_env%print_contract_verbose)
2093 CALL dbt_copy(t_3c_x_w_tmp, t_3c_x_w, order=[1, 2, 3], move_data=.true.)
2095 CALL dbt_destroy(t_3c_x_w_tmp)
2096 CALL dbt_destroy(t_3c_for_w)
2098 CALL timestop(handle)
2100 END SUBROUTINE compute_3c_and_contract_w
2115 SUBROUTINE contract_to_sigma(t_2c_G, t_3c_x_W, t_2c_Sigma, i_atoms, j_atoms, qs_env, bs_env, &
2117 TYPE(dbt_type) :: t_2c_g, t_3c_x_w, t_2c_sigma
2118 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
2122 LOGICAL,
OPTIONAL :: can_skip
2124 CHARACTER(LEN=*),
PARAMETER :: routinen =
'contract_to_Sigma'
2126 INTEGER :: handle, inner_loop_atoms_interval_index
2127 INTEGER(KIND=int_8) :: flop
2128 INTEGER,
DIMENSION(2) :: bounds_lambda, bounds_mu, bounds_nu, &
2129 bounds_sigma, il_atoms
2130 INTEGER,
DIMENSION(2, 2) :: bounds_comb
2131 REAL(kind=
dp) :: sign_sigma
2132 TYPE(dbt_type) :: t_3c_for_g, t_3c_x_g, t_3c_x_g_2
2134 CALL timeset(routinen, handle)
2136 cpassert(occ .EQV. (.NOT. vir))
2137 IF (occ) sign_sigma = -1.0_dp
2138 IF (vir) sign_sigma = 1.0_dp
2140 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_g)
2141 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_g)
2142 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_g_2)
2155 bounds_nu(1:2) = [bs_env%i_ao_start_from_atom(i_atoms(1)), &
2156 bs_env%i_ao_end_from_atom(i_atoms(2))]
2158 DO inner_loop_atoms_interval_index = 1, bs_env%n_intervals_inner_loop_atoms
2159 il_atoms = bs_env%inner_loop_atom_intervals(1:2, inner_loop_atoms_interval_index)
2162 CALL get_bounds_from_atoms(bounds_mu, j_atoms, [1, bs_env%n_atom], &
2163 bs_env%min_AO_idx_from_RI_AO_atom, &
2164 bs_env%max_AO_idx_from_RI_AO_atom, &
2166 indices_3_start=bs_env%i_ao_start_from_atom, &
2167 indices_3_end=bs_env%i_ao_end_from_atom)
2170 CALL get_bounds_from_atoms(bounds_comb(:, 1), il_atoms, [1, bs_env%n_atom], &
2171 bs_env%min_RI_idx_from_AO_AO_atom, &
2172 bs_env%max_RI_idx_from_AO_AO_atom, &
2174 indices_3_start=bs_env%i_RI_start_from_atom, &
2175 indices_3_end=bs_env%i_RI_end_from_atom)
2178 CALL get_bounds_from_atoms(bounds_comb(:, 2), j_atoms, il_atoms, &
2179 bs_env%min_AO_idx_from_RI_AO_atom, &
2180 bs_env%max_AO_idx_from_RI_AO_atom)
2182 IF (bounds_mu(1) > bounds_mu(2) .OR. bounds_comb(1, 1) > bounds_comb(2, 1) .OR. &
2183 bounds_comb(1, 2) > bounds_comb(2, 2))
THEN
2188 atoms_ri=j_atoms, atoms_ao_2=il_atoms)
2190 CALL dbt_contract(alpha=1.0_dp, &
2192 tensor_2=t_3c_for_g, &
2194 tensor_3=t_3c_x_g, &
2195 contract_1=[2], notcontract_1=[1], map_1=[3], &
2196 contract_2=[3], notcontract_2=[1, 2], map_2=[1, 2], &
2197 bounds_1=bounds_mu, &
2198 bounds_2=bounds_nu, &
2199 bounds_3=bounds_comb, &
2201 move_data=.false., &
2202 filter_eps=bs_env%eps_filter, &
2203 unit_nr=bs_env%unit_nr_contract, &
2204 log_verbose=bs_env%print_contract_verbose)
2208 CALL dbt_copy(t_3c_x_g, t_3c_x_g_2, order=[1, 3, 2], move_data=.true.)
2212 bounds_comb(1:2, 1) = [bs_env%i_RI_start_from_atom(j_atoms(1)), &
2213 bs_env%i_RI_end_from_atom(j_atoms(2))]
2214 bounds_comb(1:2, 2) = bounds_nu(1:2)
2216 CALL get_bounds_from_atoms(bounds_lambda, j_atoms, [1, bs_env%n_atom], &
2217 bs_env%min_AO_idx_from_RI_AO_atom, &
2218 bs_env%max_AO_idx_from_RI_AO_atom)
2219 CALL get_bounds_from_atoms(bounds_sigma, [1, bs_env%n_atom], i_atoms, &
2220 bs_env%min_AO_idx_from_RI_AO_atom, &
2221 bs_env%max_AO_idx_from_RI_AO_atom)
2223 IF (bounds_sigma(1) > bounds_sigma(2) .OR. bounds_lambda(1) > bounds_lambda(2))
THEN
2226 CALL dbt_contract(alpha=sign_sigma, &
2227 tensor_1=t_3c_x_w, &
2228 tensor_2=t_3c_x_g_2, &
2230 tensor_3=t_2c_sigma, &
2231 contract_1=[1, 2], notcontract_1=[3], map_1=[1], &
2232 contract_2=[1, 2], notcontract_2=[3], map_2=[2], &
2233 bounds_1=bounds_comb, &
2234 bounds_2=bounds_sigma, &
2235 bounds_3=bounds_lambda, &
2236 filter_eps=bs_env%eps_filter, move_data=.false., flop=flop, &
2237 unit_nr=bs_env%unit_nr_contract, &
2238 log_verbose=bs_env%print_contract_verbose)
2241 IF (
PRESENT(can_skip))
THEN
2242 IF (flop == 0_int_8) can_skip = .true.
2245 CALL dbt_destroy(t_3c_for_g)
2246 CALL dbt_destroy(t_3c_x_g)
2247 CALL dbt_destroy(t_3c_x_g_2)
2249 CALL timestop(handle)
2251 END SUBROUTINE contract_to_sigma
2261 mat_Sigma_pos_tau, mat_Sigma_neg_tau)
2263 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
2265 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_pos_tau, mat_sigma_neg_tau
2267 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fill_fm_Sigma_c_Gamma_time'
2269 INTEGER :: handle, i_t, ispin, pos_neg
2271 CALL timeset(routinen, handle)
2273 ALLOCATE (fm_sigma_c_gamma_time(bs_env%num_time_freq_points, 2, bs_env%n_spin))
2274 DO ispin = 1, bs_env%n_spin
2275 DO i_t = 1, bs_env%num_time_freq_points
2277 CALL cp_fm_create(fm_sigma_c_gamma_time(i_t, pos_neg, ispin), &
2278 bs_env%fm_s_Gamma%matrix_struct)
2281 fm_sigma_c_gamma_time(i_t, 1, ispin))
2283 fm_sigma_c_gamma_time(i_t, 2, ispin))
2287 CALL timestop(handle)
2295 SUBROUTINE print_skipping(bs_env)
2299 CHARACTER(LEN=*),
PARAMETER :: routinen =
'print_skipping'
2301 INTEGER :: handle, n_pairs
2303 CALL timeset(routinen, handle)
2305 n_pairs = bs_env%n_intervals_i*bs_env%n_intervals_j*bs_env%n_spin
2307 CALL bs_env%para_env_tensor%sum(bs_env%n_skip_sigma)
2308 CALL bs_env%para_env_tensor%sum(bs_env%n_skip_chi)
2309 CALL bs_env%para_env_tensor%sum(n_pairs)
2311 IF (bs_env%unit_nr > 0)
THEN
2312 WRITE (bs_env%unit_nr,
'(T2,A,T74,F7.1,A)') &
2313 Στ
'Sparsity of ^c(i,k=0): Percentage of skipped atom pairs:', &
2314 REAL(100*bs_env%n_skip_sigma, kind=
dp)/real(n_pairs, kind=
dp),
' %'
2315 WRITE (bs_env%unit_nr,
'(T2,A,T74,F7.1,A)') &
2316 χτ
'Sparsity of (i,k=0): Percentage of skipped atom pairs:', &
2317 REAL(100*bs_env%n_skip_chi, kind=
dp)/real(n_pairs, kind=
dp),
' %'
2320 CALL timestop(handle)
2322 END SUBROUTINE print_skipping
2336 SUBROUTINE destroy_mat_sigma_c(t_2c_Gocc, t_2c_Gvir, t_2c_W, t_2c_Sigma_neg_tau, &
2337 t_2c_Sigma_pos_tau, t_3c_x_W, fm_W_MIC_time, &
2338 mat_Sigma_neg_tau, mat_Sigma_pos_tau)
2340 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_2c_w, &
2341 t_2c_sigma_neg_tau, &
2342 t_2c_sigma_pos_tau, t_3c_x_w
2343 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
2344 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
2346 CHARACTER(LEN=*),
PARAMETER :: routinen =
'destroy_mat_Sigma_c'
2350 CALL timeset(routinen, handle)
2352 CALL dbt_destroy(t_2c_gocc)
2353 CALL dbt_destroy(t_2c_gvir)
2354 CALL dbt_destroy(t_2c_w)
2355 CALL dbt_destroy(t_2c_sigma_neg_tau)
2356 CALL dbt_destroy(t_2c_sigma_pos_tau)
2357 CALL dbt_destroy(t_3c_x_w)
2362 CALL timestop(handle)
2364 END SUBROUTINE destroy_mat_sigma_c
2373 CHARACTER(LEN=*),
PARAMETER :: routinen =
'delete_unnecessary_files'
2375 CHARACTER(LEN=default_path_length) :: f_chi, f_w_t, prefix
2376 INTEGER :: handle, i_t
2378 CALL timeset(routinen, handle)
2380 prefix = bs_env%prefix
2382 DO i_t = 1, bs_env%num_time_freq_points
2385 WRITE (f_chi,
'(3A,I1,A)') trim(prefix), bs_env%chi_name,
"_00", i_t,
".matrix"
2386 WRITE (f_w_t,
'(3A,I1,A)') trim(prefix), bs_env%W_time_name,
"_00", i_t,
".matrix"
2387 ELSE IF (i_t < 100)
THEN
2388 WRITE (f_chi,
'(3A,I2,A)') trim(prefix), bs_env%chi_name,
"_0", i_t,
".matrix"
2389 WRITE (f_w_t,
'(3A,I2,A)') trim(prefix), bs_env%W_time_name,
"_0", i_t,
".matrix"
2391 cpabort(
'Please implement more than 99 time/frequency points.')
2394 CALL safe_delete(f_chi, bs_env)
2395 CALL safe_delete(f_w_t, bs_env)
2399 CALL timestop(handle)
2408 SUBROUTINE safe_delete(filename, bs_env)
2409 CHARACTER(LEN=*) :: filename
2412 CHARACTER(LEN=*),
PARAMETER :: routinen =
'safe_delete'
2417 CALL timeset(routinen, handle)
2419 IF (bs_env%para_env%mepos == 0)
THEN
2426 CALL timestop(handle)
2428 END SUBROUTINE safe_delete
2441 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
2442 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
2444 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_QP_energies'
2446 INTEGER :: handle, ikp, ispin, j_t
2447 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: sigma_x_ikp_n, v_xc_ikp_n
2448 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: sigma_c_ikp_n_freq, sigma_c_ikp_n_time
2449 TYPE(
cp_cfm_type) :: cfm_ks_ikp, cfm_mos_ikp, cfm_s_ikp, &
2450 cfm_sigma_x_ikp, cfm_work_ikp
2452 CALL timeset(routinen, handle)
2454 CALL cp_cfm_create(cfm_mos_ikp, bs_env%fm_s_Gamma%matrix_struct)
2455 CALL cp_cfm_create(cfm_work_ikp, bs_env%fm_s_Gamma%matrix_struct)
2457 ALLOCATE (v_xc_ikp_n(bs_env%n_ao), sigma_x_ikp_n(bs_env%n_ao))
2458 ALLOCATE (sigma_c_ikp_n_time(bs_env%n_ao, bs_env%num_time_freq_points, 2))
2459 ALLOCATE (sigma_c_ikp_n_freq(bs_env%n_ao, bs_env%num_time_freq_points, 2))
2461 DO ispin = 1, bs_env%n_spin
2463 DO ikp = 1, bs_env%nkp_bs_and_DOS
2467 ikp, qs_env, bs_env%kpoints_DOS,
"ORB")
2471 ikp, qs_env, bs_env%kpoints_DOS,
"ORB")
2474 CALL cp_cfm_geeig(cfm_ks_ikp, cfm_s_ikp, cfm_mos_ikp, &
2475 bs_env%eigenval_scf(:, ikp, ispin), cfm_work_ikp)
2478 CALL to_ikp_and_mo(v_xc_ikp_n, bs_env%fm_V_xc_Gamma(ispin), &
2479 ikp, qs_env, bs_env, cfm_mos_ikp)
2482 CALL to_ikp_and_mo(sigma_x_ikp_n, fm_sigma_x_gamma(ispin), &
2483 ikp, qs_env, bs_env, cfm_mos_ikp)
2486 DO j_t = 1, bs_env%num_time_freq_points
2487 CALL to_ikp_and_mo(sigma_c_ikp_n_time(:, j_t, 1), &
2488 fm_sigma_c_gamma_time(j_t, 1, ispin), &
2489 ikp, qs_env, bs_env, cfm_mos_ikp)
2490 CALL to_ikp_and_mo(sigma_c_ikp_n_time(:, j_t, 2), &
2491 fm_sigma_c_gamma_time(j_t, 2, ispin), &
2492 ikp, qs_env, bs_env, cfm_mos_ikp)
2496 CALL time_to_freq(bs_env, sigma_c_ikp_n_time, sigma_c_ikp_n_freq, ispin)
2501 bs_env%eigenval_scf(:, ikp, ispin), ikp, ispin)
2517 CALL timestop(handle)
2530 SUBROUTINE to_ikp_and_mo(array_ikp_n, fm_Gamma, ikp, qs_env, bs_env, cfm_mos_ikp)
2532 REAL(kind=
dp),
DIMENSION(:) :: array_ikp_n
2539 CHARACTER(LEN=*),
PARAMETER :: routinen =
'to_ikp_and_mo'
2544 CALL timeset(routinen, handle)
2546 CALL cp_fm_create(fm_ikp_mo_re, fm_gamma%matrix_struct)
2548 CALL fm_gamma_ao_to_cfm_ikp_mo(fm_gamma, fm_ikp_mo_re, ikp, qs_env, bs_env, cfm_mos_ikp)
2554 CALL timestop(handle)
2556 END SUBROUTINE to_ikp_and_mo
2567 SUBROUTINE fm_gamma_ao_to_cfm_ikp_mo(fm_Gamma, fm_ikp_mo_re, ikp, qs_env, bs_env, cfm_mos_ikp)
2574 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_Gamma_ao_to_cfm_ikp_mo'
2576 INTEGER :: handle, nmo
2577 TYPE(
cp_cfm_type) :: cfm_ikp_ao, cfm_ikp_mo, cfm_tmp
2579 CALL timeset(routinen, handle)
2598 CALL timestop(handle)
2600 END SUBROUTINE fm_gamma_ao_to_cfm_ikp_mo
2617 SUBROUTINE get_bounds_from_atoms(bounds_out, atoms_1, atoms_2, indices_min, indices_max, &
2618 atoms_3, indices_3_start, indices_3_end)
2620 INTEGER,
DIMENSION(2),
INTENT(OUT) :: bounds_out
2621 INTEGER,
DIMENSION(2),
INTENT(IN) :: atoms_1, atoms_2
2622 INTEGER,
DIMENSION(:, :) :: indices_min, indices_max
2623 INTEGER,
DIMENSION(2),
INTENT(IN),
OPTIONAL :: atoms_3
2624 INTEGER,
DIMENSION(:),
OPTIONAL :: indices_3_start, indices_3_end
2626 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_bounds_from_atoms'
2628 INTEGER :: handle, i_at, j_at
2630 CALL timeset(routinen, handle)
2631 bounds_out(1) = huge(0)
2634 DO i_at = atoms_1(1), atoms_1(2)
2635 DO j_at = atoms_2(1), atoms_2(2)
2636 bounds_out(1) = min(bounds_out(1), indices_min(i_at, j_at))
2637 bounds_out(2) = max(bounds_out(2), indices_max(i_at, j_at))
2641 IF (
PRESENT(atoms_3) .AND.
PRESENT(indices_3_start) .AND.
PRESENT(indices_3_end))
THEN
2642 bounds_out(1) = max(bounds_out(1), indices_3_start(atoms_3(1)))
2643 bounds_out(2) = min(bounds_out(2), indices_3_end(atoms_3(2)))
2646 CALL timestop(handle)
2648 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)
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 de_init_bs_env(bs_env)
...
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)
...
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, 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.