91#include "./base/base_uses.f90"
97 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_large_cell_gamma'
115 CHARACTER(LEN=*),
PARAMETER :: routinen =
'gw_calc_large_cell_Gamma'
118 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma, fm_w_mic_time
119 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
121 CALL timeset(routinen, handle)
128 CALL get_mat_chi_gamma_tau(bs_env, qs_env, bs_env%mat_chi_Gamma_tau)
131 CALL get_w_mic(bs_env, qs_env, bs_env%mat_chi_Gamma_tau, fm_w_mic_time)
135 CALL get_sigma_x(bs_env, qs_env, fm_sigma_x_gamma)
139 CALL get_sigma_c(bs_env, qs_env, fm_w_mic_time, fm_sigma_c_gamma_time)
142 CALL compute_qp_energies(bs_env, qs_env, fm_sigma_x_gamma, fm_sigma_c_gamma_time)
146 CALL timestop(handle)
156 SUBROUTINE get_mat_chi_gamma_tau(bs_env, qs_env, mat_chi_Gamma_tau)
159 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
161 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_mat_chi_Gamma_tau'
163 INTEGER :: handle, i_intval_idx, i_t, inner_loop_atoms_interval_index, ispin, j_intval_idx
164 INTEGER(KIND=int_8) :: flop
165 INTEGER,
DIMENSION(2) :: bounds_p, bounds_q, i_atoms, il_atoms, &
167 INTEGER,
DIMENSION(2, 2) :: bounds_comb
168 LOGICAL :: dist_too_long_i, dist_too_long_j
169 REAL(kind=
dp) :: t1, tau
170 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_3c_for_gocc, &
171 t_3c_for_gvir, t_3c_x_gocc, &
172 t_3c_x_gocc_2, t_3c_x_gvir, &
175 CALL timeset(routinen, handle)
177 DO i_t = 1, bs_env%num_time_freq_points
181 IF (bs_env%read_chi(i_t))
THEN
183 CALL fm_read(bs_env%fm_RI_RI, bs_env, bs_env%chi_name, i_t)
186 keep_sparsity=.false.)
188 IF (bs_env%unit_nr > 0)
THEN
189 WRITE (bs_env%unit_nr,
'(T2,A,I5,A,I3,A,F10.1,A)') &
190 χτ
'Read (i,k=0) from file for time point ', i_t,
' /', &
191 bs_env%num_time_freq_points, &
199 IF (.NOT. bs_env%calc_chi(i_t)) cycle
201 CALL create_tensors_chi(t_2c_gocc, t_2c_gvir, t_3c_for_gocc, t_3c_for_gvir, &
202 t_3c_x_gocc, t_3c_x_gvir, t_3c_x_gocc_2, t_3c_x_gvir_2, bs_env)
208 tau = bs_env%imag_time_points(i_t)
210 DO ispin = 1, bs_env%n_spin
211 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gocc, ispin, occ=.true., vir=.false.)
212 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gvir, ispin, occ=.false., vir=.true.)
215 bs_env%mat_ao_ao_tensor%matrix, t_2c_gocc, bs_env, &
216 bs_env%atoms_j_t_group)
218 bs_env%mat_ao_ao_tensor%matrix, t_2c_gvir, bs_env, &
219 bs_env%atoms_i_t_group)
223 DO i_intval_idx = 1, bs_env%n_intervals_i
224 DO j_intval_idx = 1, bs_env%n_intervals_j
225 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
226 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
228 IF (bs_env%skip_chi(i_intval_idx, j_intval_idx))
THEN
232 bs_env%n_skip_chi = bs_env%n_skip_chi + 1
237 DO inner_loop_atoms_interval_index = 1, bs_env%n_intervals_inner_loop_atoms
239 il_atoms = bs_env%inner_loop_atom_intervals(1:2, inner_loop_atoms_interval_index)
245 CALL check_dist(i_atoms, il_atoms, qs_env, bs_env, dist_too_long_i)
246 CALL check_dist(j_atoms, il_atoms, qs_env, bs_env, dist_too_long_j)
247 IF (.NOT. dist_too_long_i)
THEN
250 atoms_ao_1=i_atoms, atoms_ao_2=il_atoms)
252 CALL g_times_3c(t_3c_for_gocc, t_2c_gocc, t_3c_x_gocc, bs_env, &
253 j_atoms, i_atoms, il_atoms)
255 IF (.NOT. dist_too_long_j)
THEN
258 atoms_ao_1=j_atoms, atoms_ao_2=il_atoms)
260 CALL g_times_3c(t_3c_for_gvir, t_2c_gvir, t_3c_x_gvir, bs_env, &
261 i_atoms, j_atoms, il_atoms)
266 CALL dbt_copy(t_3c_x_gocc, t_3c_x_gocc_2, move_data=.true., order=[1, 3, 2])
267 CALL dbt_copy(t_3c_x_gvir, t_3c_x_gvir_2, move_data=.true.)
276 bounds_comb(1:2, 1) = [bs_env%i_ao_start_from_atom(j_atoms(1)), &
277 bs_env%i_ao_end_from_atom(j_atoms(2))]
278 bounds_comb(1:2, 2) = [bs_env%i_ao_start_from_atom(i_atoms(1)), &
279 bs_env%i_ao_end_from_atom(i_atoms(2))]
281 CALL get_bounds_from_atoms(bounds_p, i_atoms, [1, bs_env%n_atom], &
282 bs_env%min_RI_idx_from_AO_AO_atom, &
283 bs_env%max_RI_idx_from_AO_AO_atom)
284 CALL get_bounds_from_atoms(bounds_q, [1, bs_env%n_atom], j_atoms, &
285 bs_env%min_RI_idx_from_AO_AO_atom, &
286 bs_env%max_RI_idx_from_AO_AO_atom)
288 IF (bounds_q(1) > bounds_q(2) .OR. bounds_p(1) > bounds_p(2))
THEN
291 CALL dbt_contract(alpha=bs_env%spin_degeneracy, &
292 tensor_1=t_3c_x_gocc_2, tensor_2=t_3c_x_gvir_2, &
293 beta=1.0_dp, tensor_3=bs_env%t_chi, &
294 contract_1=[2, 3], notcontract_1=[1], map_1=[1], &
295 contract_2=[2, 3], notcontract_2=[1], map_2=[2], &
296 bounds_1=bounds_comb, &
299 filter_eps=bs_env%eps_filter, move_data=.false., flop=flop, &
300 unit_nr=bs_env%unit_nr_contract, &
301 log_verbose=bs_env%print_contract_verbose)
303 IF (flop == 0_int_8) bs_env%skip_chi(i_intval_idx, j_intval_idx) = .true.
313 mat_chi_gamma_tau(i_t)%matrix, bs_env%para_env)
315 CALL write_matrix(mat_chi_gamma_tau(i_t)%matrix, i_t, bs_env%chi_name, &
316 bs_env%fm_RI_RI, qs_env)
318 CALL destroy_tensors_chi(t_2c_gocc, t_2c_gvir, t_3c_for_gocc, t_3c_for_gvir, &
319 t_3c_x_gocc, t_3c_x_gvir, t_3c_x_gocc_2, t_3c_x_gvir_2)
321 IF (bs_env%unit_nr > 0)
THEN
322 WRITE (bs_env%unit_nr,
'(T2,A,I13,A,I3,A,F10.1,A)') &
323 χτ
'Computed (i,k=0) for time point', i_t,
' /', bs_env%num_time_freq_points, &
329 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
331 CALL timestop(handle)
333 END SUBROUTINE get_mat_chi_gamma_tau
342 SUBROUTINE fm_read(fm, bs_env, mat_name, idx)
345 CHARACTER(LEN=*) :: mat_name
348 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_read'
350 CHARACTER(LEN=default_string_length) :: f_chi
351 INTEGER :: handle, unit_nr
353 CALL timeset(routinen, handle)
356 IF (bs_env%para_env%is_source())
THEN
359 WRITE (f_chi,
'(3A,I1,A)') trim(bs_env%prefix), trim(mat_name),
"_0",
idx,
".matrix"
360 ELSE IF (
idx < 100)
THEN
361 WRITE (f_chi,
'(3A,I2,A)') trim(bs_env%prefix), trim(mat_name),
"_",
idx,
".matrix"
363 cpabort(
'Please implement more than 99 time/frequency points.')
366 CALL open_file(file_name=trim(f_chi), file_action=
"READ", file_form=
"UNFORMATTED", &
367 file_position=
"REWIND", file_status=
"OLD", unit_number=unit_nr)
373 IF (bs_env%para_env%is_source())
CALL close_file(unit_number=unit_nr)
375 CALL timestop(handle)
377 END SUBROUTINE fm_read
391 SUBROUTINE create_tensors_chi(t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, t_3c_for_Gvir, &
392 t_3c_x_Gocc, t_3c_x_Gvir, t_3c_x_Gocc_2, t_3c_x_Gvir_2, bs_env)
394 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_3c_for_gocc, &
395 t_3c_for_gvir, t_3c_x_gocc, &
396 t_3c_x_gvir, t_3c_x_gocc_2, &
400 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_tensors_chi'
404 CALL timeset(routinen, handle)
406 CALL dbt_create(bs_env%t_G, t_2c_gocc, name=
"Gocc 2c (AO|AO)")
407 CALL dbt_create(bs_env%t_G, t_2c_gvir, name=
"Gvir 2c (AO|AO)")
408 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_gocc, name=
"Gocc 3c (RI AO|AO)")
409 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_gvir, name=
"Gvir 3c (RI AO|AO)")
410 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_gocc, name=
"xGocc 3c (RI AO|AO)")
411 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_gvir, name=
"xGvir 3c (RI AO|AO)")
412 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_gocc_2, name=
"x2Gocc 3c (RI AO|AO)")
413 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_gvir_2, name=
"x2Gvir 3c (RI AO|AO)")
415 CALL timestop(handle)
417 END SUBROUTINE create_tensors_chi
430 SUBROUTINE destroy_tensors_chi(t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, t_3c_for_Gvir, &
431 t_3c_x_Gocc, t_3c_x_Gvir, t_3c_x_Gocc_2, t_3c_x_Gvir_2)
432 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_3c_for_gocc, &
433 t_3c_for_gvir, t_3c_x_gocc, &
434 t_3c_x_gvir, t_3c_x_gocc_2, &
437 CHARACTER(LEN=*),
PARAMETER :: routinen =
'destroy_tensors_chi'
441 CALL timeset(routinen, handle)
443 CALL dbt_destroy(t_2c_gocc)
444 CALL dbt_destroy(t_2c_gvir)
445 CALL dbt_destroy(t_3c_for_gocc)
446 CALL dbt_destroy(t_3c_for_gvir)
447 CALL dbt_destroy(t_3c_x_gocc)
448 CALL dbt_destroy(t_3c_x_gvir)
449 CALL dbt_destroy(t_3c_x_gocc_2)
450 CALL dbt_destroy(t_3c_x_gvir_2)
452 CALL timestop(handle)
454 END SUBROUTINE destroy_tensors_chi
464 SUBROUTINE write_matrix(matrix, matrix_index, matrix_name, fm, qs_env)
466 INTEGER :: matrix_index
467 CHARACTER(LEN=*) :: matrix_name
471 CHARACTER(LEN=*),
PARAMETER :: routinen =
'write_matrix'
475 CALL timeset(routinen, handle)
481 CALL fm_write(fm, matrix_index, matrix_name, qs_env)
483 CALL timestop(handle)
485 END SUBROUTINE write_matrix
494 SUBROUTINE fm_write(fm, matrix_index, matrix_name, qs_env)
496 INTEGER :: matrix_index
497 CHARACTER(LEN=*) :: matrix_name
500 CHARACTER(LEN=*),
PARAMETER :: key =
'PROPERTIES%BANDSTRUCTURE%GW%PRINT%RESTART', &
501 routinen =
'fm_write'
503 CHARACTER(LEN=default_string_length) :: filename
504 INTEGER :: handle, unit_nr
508 CALL timeset(routinen, handle)
516 IF (matrix_index < 10)
THEN
517 WRITE (filename,
'(3A,I1)')
"RESTART_", matrix_name,
"_0", matrix_index
518 ELSE IF (matrix_index < 100)
THEN
519 WRITE (filename,
'(3A,I2)')
"RESTART_", matrix_name,
"_", matrix_index
521 cpabort(
'Please implement more than 99 time/frequency points.')
525 file_form=
"UNFORMATTED", middle_name=trim(filename), &
526 file_position=
"REWIND", file_action=
"WRITE")
529 IF (unit_nr > 0)
THEN
534 CALL timestop(handle)
536 END SUBROUTINE fm_write
547 SUBROUTINE g_occ_vir(bs_env, tau, fm_G_Gamma, ispin, occ, vir)
554 CHARACTER(LEN=*),
PARAMETER :: routinen =
'G_occ_vir'
556 INTEGER :: handle, homo, i_row_local, j_col, &
557 j_col_local, n_mo, ncol_local, &
559 INTEGER,
DIMENSION(:),
POINTER :: col_indices
560 REAL(kind=
dp) :: tau_e
562 CALL timeset(routinen, handle)
564 cpassert(occ .NEQV. vir)
567 nrow_local=nrow_local, &
568 ncol_local=ncol_local, &
569 col_indices=col_indices)
572 homo = bs_env%n_occ(ispin)
574 CALL cp_fm_to_fm(bs_env%fm_mo_coeff_Gamma(ispin), bs_env%fm_work_mo(1))
576 DO i_row_local = 1, nrow_local
577 DO j_col_local = 1, ncol_local
579 j_col = col_indices(j_col_local)
581 tau_e = abs(tau*0.5_dp*(bs_env%eigenval_scf_Gamma(j_col, ispin) - bs_env%e_fermi(ispin)))
583 IF (tau_e < bs_env%stabilize_exp)
THEN
584 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = &
585 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local)*exp(-tau_e)
587 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = 0.0_dp
590 IF ((occ .AND. j_col > homo) .OR. (vir .AND. j_col <= homo))
THEN
591 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = 0.0_dp
597 CALL parallel_gemm(transa=
"N", transb=
"T", m=n_mo, n=n_mo, k=n_mo, alpha=1.0_dp, &
598 matrix_a=bs_env%fm_work_mo(1), matrix_b=bs_env%fm_work_mo(1), &
599 beta=0.0_dp, matrix_c=fm_g_gamma)
601 CALL timestop(handle)
603 END SUBROUTINE g_occ_vir
617 TYPE(dbt_type) :: t_3c
618 INTEGER,
DIMENSION(2),
OPTIONAL :: atoms_ao_1, atoms_ao_2, atoms_ri
620 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_3c_integrals'
623 TYPE(dbt_type),
ALLOCATABLE,
DIMENSION(:, :) :: t_3c_array
625 CALL timeset(routinen, handle)
630 ALLOCATE (t_3c_array(1, 1))
631 CALL dbt_create(t_3c, t_3c_array(1, 1))
637 int_eps=bs_env%eps_filter, &
638 basis_i=bs_env%basis_set_RI, &
639 basis_j=bs_env%basis_set_AO, &
640 basis_k=bs_env%basis_set_AO, &
641 potential_parameter=bs_env%ri_metric, &
643 bounds_j=atoms_ao_1, &
644 bounds_k=atoms_ao_2, &
645 desymmetrize=.false.)
647 CALL dbt_filter(t_3c_array(1, 1), bs_env%eps_filter)
649 CALL dbt_copy(t_3c_array(1, 1), t_3c, move_data=.true.)
651 CALL dbt_destroy(t_3c_array(1, 1))
652 DEALLOCATE (t_3c_array)
654 CALL timestop(handle)
668 SUBROUTINE g_times_3c(t_3c_for_G, t_G, t_M, bs_env, atoms_AO_1, atoms_AO_2, atoms_IL)
669 TYPE(dbt_type) :: t_3c_for_g, t_g, t_m
671 INTEGER,
DIMENSION(2) :: atoms_ao_1, atoms_ao_2, atoms_il
673 CHARACTER(LEN=*),
PARAMETER :: routinen =
'G_times_3c'
676 INTEGER(KIND=int_8) :: flop
677 INTEGER,
DIMENSION(2) :: bounds_ao_1, bounds_il
678 INTEGER,
DIMENSION(2, 2) :: bounds_comb
680 CALL timeset(routinen, handle)
691 CALL get_bounds_from_atoms(bounds_il, [1, bs_env%n_atom], atoms_ao_2, &
692 bs_env%min_AO_idx_from_RI_AO_atom, &
693 bs_env%max_AO_idx_from_RI_AO_atom, &
695 indices_3_start=bs_env%i_ao_start_from_atom, &
696 indices_3_end=bs_env%i_ao_end_from_atom)
699 CALL get_bounds_from_atoms(bounds_comb(:, 1), atoms_il, atoms_ao_2, &
700 bs_env%min_RI_idx_from_AO_AO_atom, &
701 bs_env%max_RI_idx_from_AO_AO_atom)
704 CALL get_bounds_from_atoms(bounds_comb(:, 2), [1, bs_env%n_atom], atoms_il, &
705 bs_env%min_AO_idx_from_RI_AO_atom, &
706 bs_env%max_AO_idx_from_RI_AO_atom, &
707 atoms_3=atoms_ao_2, &
708 indices_3_start=bs_env%i_ao_start_from_atom, &
709 indices_3_end=bs_env%i_ao_end_from_atom)
712 bounds_ao_1(1:2) = [bs_env%i_ao_start_from_atom(atoms_ao_1(1)), &
713 bs_env%i_ao_end_from_atom(atoms_ao_1(2))]
715 IF (bounds_il(1) > bounds_il(2) .OR. bounds_comb(1, 2) > bounds_comb(2, 2))
THEN
718 CALL dbt_contract(alpha=1.0_dp, &
719 tensor_1=t_3c_for_g, &
723 contract_1=[3], notcontract_1=[1, 2], map_1=[1, 2], &
724 contract_2=[2], notcontract_2=[1], map_2=[3], &
725 bounds_1=bounds_il, &
726 bounds_2=bounds_comb, &
727 bounds_3=bounds_ao_1, &
729 filter_eps=bs_env%eps_filter, &
730 unit_nr=bs_env%unit_nr_contract, &
731 log_verbose=bs_env%print_contract_verbose)
734 CALL dbt_clear(t_3c_for_g)
736 CALL timestop(handle)
738 END SUBROUTINE g_times_3c
748 SUBROUTINE check_dist(atoms_1, atoms_2, qs_env, bs_env, dist_too_long)
749 INTEGER,
DIMENSION(2) :: atoms_1, atoms_2
752 LOGICAL :: dist_too_long
754 CHARACTER(LEN=*),
PARAMETER :: routinen =
'check_dist'
756 INTEGER :: atom_1, atom_2, handle
757 REAL(
dp) :: abs_rab, min_dist_ao_atoms
758 REAL(kind=
dp),
DIMENSION(3) :: rab
762 CALL timeset(routinen, handle)
764 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
766 min_dist_ao_atoms = huge(1.0_dp)
767 DO atom_1 = atoms_1(1), atoms_1(2)
768 DO atom_2 = atoms_2(1), atoms_2(2)
769 rab =
pbc(particle_set(atom_1)%r(1:3), particle_set(atom_2)%r(1:3), cell)
771 abs_rab = sqrt(rab(1)**2 + rab(2)**2 + rab(3)**2)
773 min_dist_ao_atoms = min(min_dist_ao_atoms, abs_rab)
777 dist_too_long = (min_dist_ao_atoms > bs_env%max_dist_AO_atoms)
779 CALL timestop(handle)
781 END SUBROUTINE check_dist
790 SUBROUTINE get_w_mic(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
793 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
794 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
796 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_W_MIC'
800 CALL timeset(routinen, handle)
802 IF (bs_env%all_W_exist)
THEN
803 CALL read_w_mic_time(bs_env, mat_chi_gamma_tau, fm_w_mic_time)
805 CALL compute_w_mic(bs_env, qs_env, mat_chi_gamma_tau, fm_w_mic_time)
808 CALL timestop(handle)
810 END SUBROUTINE get_w_mic
819 SUBROUTINE compute_v_k_by_lattice_sum(bs_env, qs_env, fm_V_kp, ikp_batch)
822 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
825 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_V_k_by_lattice_sum'
827 INTEGER :: handle, ikp, ikp_end, ikp_start, &
828 nkp_chi_eps_w_batch, re_im
831 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_v_kp
833 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
835 CALL timeset(routinen, handle)
837 nkp_chi_eps_w_batch = bs_env%nkp_chi_eps_W_batch
839 ikp_start = (ikp_batch - 1)*bs_env%nkp_chi_eps_W_batch + 1
840 ikp_end = min(ikp_batch*bs_env%nkp_chi_eps_W_batch, bs_env%kpoints_chi_eps_W%nkp)
843 ALLOCATE (mat_v_kp(ikp_start:ikp_end, 2))
846 DO ikp = ikp_start, ikp_end
847 NULLIFY (mat_v_kp(ikp, re_im)%matrix)
848 ALLOCATE (mat_v_kp(ikp, re_im)%matrix)
849 CALL dbcsr_create(mat_v_kp(ikp, re_im)%matrix, template=bs_env%mat_RI_RI%matrix)
851 CALL dbcsr_set(mat_v_kp(ikp, re_im)%matrix, 0.0_dp)
856 particle_set=particle_set, &
858 qs_kind_set=qs_kind_set, &
859 atomic_kind_set=atomic_kind_set)
861 IF (ikp_end <= bs_env%nkp_chi_eps_W_orig)
THEN
864 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
866 ELSE IF (ikp_start > bs_env%nkp_chi_eps_W_orig .AND. &
867 ikp_end <= bs_env%nkp_chi_eps_W_orig_plus_extra)
THEN
870 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_extra
874 cpabort(
"Error with k-point parallelization.")
879 bs_env%kpoints_chi_eps_W, &
880 basis_type=
"RI_AUX", &
882 particle_set=particle_set, &
883 qs_kind_set=qs_kind_set, &
884 atomic_kind_set=atomic_kind_set, &
885 size_lattice_sum=bs_env%size_lattice_sum_V, &
887 ikp_start=ikp_start, &
890 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
892 ALLOCATE (fm_v_kp(ikp_start:ikp_end, 2))
894 DO ikp = ikp_start, ikp_end
895 CALL cp_fm_create(fm_v_kp(ikp, re_im), bs_env%fm_RI_RI%matrix_struct)
900 DEALLOCATE (mat_v_kp)
902 CALL timestop(handle)
904 END SUBROUTINE compute_v_k_by_lattice_sum
915 SUBROUTINE compute_minvvsqrt_vsqrt(bs_env, qs_env, fm_V_kp, cfm_V_sqrt_ikp, &
916 cfm_M_inv_V_sqrt_ikp, ikp)
919 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
920 TYPE(
cp_cfm_type) :: cfm_v_sqrt_ikp, cfm_m_inv_v_sqrt_ikp
923 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_MinvVsqrt_Vsqrt'
925 INTEGER :: handle, info, n_ri
927 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_m_ikp
929 CALL timeset(routinen, handle)
935 n_ri, bs_env%ri_metric, do_kpoints=.true., &
936 kpoints=bs_env%kpoints_chi_eps_W, &
937 regularization_ri=bs_env%regularization_RI, ikp_ext=ikp, &
938 do_build_cell_index=(ikp == 1))
941 CALL cp_cfm_create(cfm_v_sqrt_ikp, fm_v_kp(ikp, 1)%matrix_struct)
942 CALL cp_cfm_create(cfm_m_inv_v_sqrt_ikp, fm_v_kp(ikp, 1)%matrix_struct)
944 CALL cp_cfm_create(cfm_m_inv_ikp, fm_v_kp(ikp, 1)%matrix_struct)
946 CALL cp_fm_to_cfm(fm_m_ikp(1, 1), fm_m_ikp(1, 2), cfm_m_inv_ikp)
947 CALL cp_fm_to_cfm(fm_v_kp(ikp, 1), fm_v_kp(ikp, 2), cfm_v_sqrt_ikp)
963 CALL cp_cfm_power(cfm_work, threshold=bs_env%eps_eigval_mat_RI, exponent=-1.0_dp)
972 CALL clean_lower_part(cfm_v_sqrt_ikp)
975 CALL cp_cfm_power(cfm_work, threshold=0.0_dp, exponent=0.5_dp)
981 CALL parallel_gemm(
"N",
"C", n_ri, n_ri, n_ri,
z_one, cfm_m_inv_ikp, cfm_v_sqrt_ikp, &
982 z_zero, cfm_m_inv_v_sqrt_ikp)
986 CALL timestop(handle)
988 END SUBROUTINE compute_minvvsqrt_vsqrt
996 SUBROUTINE read_w_mic_time(bs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
998 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
999 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1001 CHARACTER(LEN=*),
PARAMETER :: routinen =
'read_W_MIC_time'
1003 INTEGER :: handle, i_t
1006 CALL timeset(routinen, handle)
1009 CALL create_fm_w_mic_time(bs_env, fm_w_mic_time)
1011 DO i_t = 1, bs_env%num_time_freq_points
1015 CALL fm_read(fm_w_mic_time(i_t), bs_env, bs_env%W_time_name, i_t)
1017 IF (bs_env%unit_nr > 0)
THEN
1018 WRITE (bs_env%unit_nr,
'(T2,A,I5,A,I3,A,F10.1,A)') &
1019 τ
'Read W^MIC(i) from file for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1025 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1030 CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
1032 CALL fm_read(bs_env%fm_W_MIC_freq_zero, bs_env,
"W_freq_rtp", 0)
1033 IF (bs_env%unit_nr > 0)
THEN
1034 WRITE (bs_env%unit_nr,
'(T2,A,I3,A,I3,A,F10.1,A)') &
1035 'Read W^MIC(f=0) from file for freq. point ', 1,
' /', 1, &
1040 CALL timestop(handle)
1042 END SUBROUTINE read_w_mic_time
1051 SUBROUTINE compute_w_mic(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
1054 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1055 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1057 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_W_MIC'
1059 INTEGER :: handle, i_t, ikp, ikp_batch, &
1062 TYPE(
cp_cfm_type) :: cfm_m_inv_v_sqrt_ikp, cfm_v_sqrt_ikp
1063 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
1065 CALL timeset(routinen, handle)
1067 CALL create_fm_w_mic_time(bs_env, fm_w_mic_time)
1069 DO ikp_batch = 1, bs_env%num_chi_eps_W_batches
1074 CALL compute_v_k_by_lattice_sum(bs_env, qs_env, fm_v_kp, ikp_batch)
1076 DO ikp_in_batch = 1, bs_env%nkp_chi_eps_W_batch
1078 ikp = (ikp_batch - 1)*bs_env%nkp_chi_eps_W_batch + ikp_in_batch
1080 IF (ikp > bs_env%nkp_chi_eps_W_orig_plus_extra) cycle
1082 CALL compute_minvvsqrt_vsqrt(bs_env, qs_env, fm_v_kp, &
1083 cfm_v_sqrt_ikp, cfm_m_inv_v_sqrt_ikp, ikp)
1085 CALL bs_env%para_env%sync()
1089 DO j_w = 1, bs_env%num_time_freq_points
1092 IF (bs_env%approx_kp_extrapol .AND. j_w > 1 .AND. &
1093 ikp > bs_env%nkp_chi_eps_W_orig) cycle
1095 CALL compute_fm_w_mic_freq_j(bs_env, qs_env, bs_env%fm_W_MIC_freq, j_w, ikp, &
1096 mat_chi_gamma_tau, cfm_m_inv_v_sqrt_ikp, &
1100 CALL fourier_transform_w_to_t(bs_env, fm_w_mic_time, bs_env%fm_W_MIC_freq, j_w)
1106 DEALLOCATE (fm_v_kp)
1108 IF (bs_env%unit_nr > 0)
THEN
1109 WRITE (bs_env%unit_nr,
'(T2,A,I12,A,I3,A,F10.1,A)') &
1110 τ
'Computed W(i,k) for k-point batch', &
1111 ikp_batch,
' /', bs_env%num_chi_eps_W_batches, &
1117 IF (bs_env%approx_kp_extrapol)
THEN
1118 CALL apply_extrapol_factor(bs_env, fm_w_mic_time)
1122 CALL multiply_fm_w_mic_time_with_minv_gamma(bs_env, qs_env, fm_w_mic_time)
1124 DO i_t = 1, bs_env%num_time_freq_points
1125 CALL fm_write(fm_w_mic_time(i_t), i_t, bs_env%W_time_name, qs_env)
1135 CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
1139 DO i_t = 1, bs_env%num_time_freq_points
1142 bs_env%imag_time_weights_freq_zero(i_t), fm_w_mic_time(i_t))
1145 CALL fm_write(bs_env%fm_W_MIC_freq_zero, 0,
"W_freq_rtp", qs_env)
1147 IF (bs_env%unit_nr > 0)
THEN
1148 WRITE (bs_env%unit_nr,
'(T2,A,I11,A,I3,A,F10.1,A)') &
1149 'Computed W(f=0,k) for k-point batch', &
1155 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1157 CALL timestop(handle)
1159 END SUBROUTINE compute_w_mic
1172 SUBROUTINE compute_fm_w_mic_freq_j(bs_env, qs_env, fm_W_MIC_freq_j, j_w, ikp, mat_chi_Gamma_tau, &
1173 cfm_M_inv_V_sqrt_ikp, cfm_V_sqrt_ikp)
1178 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1179 TYPE(
cp_cfm_type) :: cfm_m_inv_v_sqrt_ikp, cfm_v_sqrt_ikp
1181 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_fm_W_MIC_freq_j'
1184 TYPE(
cp_cfm_type) :: cfm_chi_ikp_freq_j, cfm_w_ikp_freq_j
1186 CALL timeset(routinen, handle)
1189 CALL compute_fm_chi_gamma_freq(bs_env, bs_env%fm_chi_Gamma_freq, j_w, mat_chi_gamma_tau)
1195 ikp, qs_env, bs_env%kpoints_chi_eps_W,
"RI_AUX")
1198 CALL cp_cfm_power(cfm_chi_ikp_freq_j, threshold=0.0_dp, exponent=1.0_dp)
1202 CALL compute_cfm_w_ikp_freq_j(bs_env, cfm_chi_ikp_freq_j, cfm_v_sqrt_ikp, &
1203 cfm_m_inv_v_sqrt_ikp, cfm_w_ikp_freq_j)
1206 SELECT CASE (bs_env%approx_kp_extrapol)
1210 bs_env%kpoints_chi_eps_W,
"RI_AUX")
1221 cfm_w_ikp_freq_j, ikp, bs_env%kpoints_chi_eps_W, &
1224 IF (ikp <= bs_env%nkp_chi_eps_W_orig)
THEN
1226 cfm_w_ikp_freq_j, ikp, bs_env%kpoints_chi_eps_W, &
1227 "RI_AUX", wkp_ext=bs_env%wkp_orig)
1233 IF (ikp <= bs_env%nkp_chi_eps_W_orig)
THEN
1235 ikp, bs_env%kpoints_chi_eps_W,
"RI_AUX", &
1236 wkp_ext=bs_env%wkp_orig)
1242 CALL timestop(handle)
1244 END SUBROUTINE compute_fm_w_mic_freq_j
1250 SUBROUTINE clean_lower_part(cfm_mat)
1253 CHARACTER(LEN=*),
PARAMETER :: routinen =
'clean_lower_part'
1255 INTEGER :: handle, i_row, j_col, j_global, &
1256 ncol_local, nrow_local
1257 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1259 CALL timeset(routinen, handle)
1262 nrow_local=nrow_local, ncol_local=ncol_local, &
1263 row_indices=row_indices, col_indices=col_indices)
1265 DO j_col = 1, ncol_local
1266 j_global = col_indices(j_col)
1267 DO i_row = 1, nrow_local
1268 IF (j_global < row_indices(i_row)) cfm_mat%local_data(i_row, j_col) =
z_zero
1272 CALL timestop(handle)
1274 END SUBROUTINE clean_lower_part
1281 SUBROUTINE apply_extrapol_factor(bs_env, fm_W_MIC_time)
1283 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1285 CHARACTER(LEN=*),
PARAMETER :: routinen =
'apply_extrapol_factor'
1287 INTEGER :: handle, i, i_t, j, ncol_local, nrow_local
1288 REAL(kind=
dp) :: extrapol_factor, w_extra_1, w_no_extra_1
1290 CALL timeset(routinen, handle)
1292 CALL cp_fm_get_info(matrix=fm_w_mic_time(1), nrow_local=nrow_local, ncol_local=ncol_local)
1294 DO i_t = 1, bs_env%num_time_freq_points
1295 DO j = 1, ncol_local
1296 DO i = 1, nrow_local
1298 w_extra_1 = bs_env%fm_W_MIC_freq_1_extra%local_data(i, j)
1299 w_no_extra_1 = bs_env%fm_W_MIC_freq_1_no_extra%local_data(i, j)
1301 IF (abs(w_no_extra_1) > 1.0e-13)
THEN
1302 extrapol_factor = abs(w_extra_1/w_no_extra_1)
1304 extrapol_factor = 1.0_dp
1308 IF (extrapol_factor > 10.0_dp) extrapol_factor = 1.0_dp
1310 fm_w_mic_time(i_t)%local_data(i, j) = fm_w_mic_time(i_t)%local_data(i, j) &
1316 CALL timestop(handle)
1318 END SUBROUTINE apply_extrapol_factor
1327 SUBROUTINE compute_fm_chi_gamma_freq(bs_env, fm_chi_Gamma_freq, j_w, mat_chi_Gamma_tau)
1331 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1333 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_fm_chi_Gamma_freq'
1335 INTEGER :: handle, i_t
1336 REAL(kind=
dp) :: freq_j, time_i, weight_ij
1338 CALL timeset(routinen, handle)
1340 CALL dbcsr_set(bs_env%mat_RI_RI%matrix, 0.0_dp)
1342 freq_j = bs_env%imag_freq_points(j_w)
1344 DO i_t = 1, bs_env%num_time_freq_points
1346 time_i = bs_env%imag_time_points(i_t)
1347 weight_ij = bs_env%weights_cos_t_to_w(j_w, i_t)
1350 CALL dbcsr_add(bs_env%mat_RI_RI%matrix, mat_chi_gamma_tau(i_t)%matrix, &
1351 1.0_dp, cos(time_i*freq_j)*weight_ij)
1357 CALL timestop(handle)
1359 END SUBROUTINE compute_fm_chi_gamma_freq
1370 SUBROUTINE mat_ikp_from_mat_gamma(mat_ikp_re, mat_ikp_im, mat_Gamma, kpoints, ikp, qs_env)
1371 TYPE(
dbcsr_type) :: mat_ikp_re, mat_ikp_im, mat_gamma
1376 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mat_ikp_from_mat_Gamma'
1378 INTEGER :: col, handle, i_cell, j_cell, num_cells, &
1380 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell
1381 LOGICAL :: f, i_cell_is_the_minimum_image_cell
1382 REAL(kind=
dp) :: abs_rab_cell_i, abs_rab_cell_j, arg
1383 REAL(kind=
dp),
DIMENSION(3) :: cell_vector, cell_vector_j, rab_cell_i, &
1385 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat
1386 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block_im, block_re, data_block
1391 CALL timeset(routinen, handle)
1399 NULLIFY (cell, particle_set)
1400 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
1403 index_to_cell => kpoints%index_to_cell
1405 num_cells =
SIZE(index_to_cell, 2)
1407 DO i_cell = 1, num_cells
1413 cell_vector(1:3) = matmul(hmat, real(index_to_cell(1:3, i_cell),
dp))
1415 rab_cell_i(1:3) =
pbc(particle_set(row)%r(1:3), cell) - &
1416 (
pbc(particle_set(col)%r(1:3), cell) + cell_vector(1:3))
1417 abs_rab_cell_i = sqrt(rab_cell_i(1)**2 + rab_cell_i(2)**2 + rab_cell_i(3)**2)
1420 i_cell_is_the_minimum_image_cell = .true.
1421 DO j_cell = 1, num_cells
1422 cell_vector_j(1:3) = matmul(hmat, real(index_to_cell(1:3, j_cell),
dp))
1423 rab_cell_j(1:3) =
pbc(particle_set(row)%r(1:3), cell) - &
1424 (
pbc(particle_set(col)%r(1:3), cell) + cell_vector_j(1:3))
1425 abs_rab_cell_j = sqrt(rab_cell_j(1)**2 + rab_cell_j(2)**2 + rab_cell_j(3)**2)
1427 IF (abs_rab_cell_i > abs_rab_cell_j + 1.0e-6_dp)
THEN
1428 i_cell_is_the_minimum_image_cell = .false.
1432 IF (i_cell_is_the_minimum_image_cell)
THEN
1433 NULLIFY (block_re, block_im)
1434 CALL dbcsr_get_block_p(matrix=mat_ikp_re, row=row, col=col, block=block_re, found=f)
1435 CALL dbcsr_get_block_p(matrix=mat_ikp_im, row=row, col=col, block=block_im, found=f)
1436 cpassert(all(abs(block_re) < 1.0e-10_dp))
1437 cpassert(all(abs(block_im) < 1.0e-10_dp))
1439 arg = real(index_to_cell(1, i_cell),
dp)*kpoints%xkp(1, ikp) + &
1440 REAL(index_to_cell(2, i_cell),
dp)*kpoints%xkp(2, ikp) + &
1441 REAL(index_to_cell(3, i_cell),
dp)*kpoints%xkp(3, ikp)
1443 block_re(:, :) = cos(
twopi*arg)*data_block(:, :)
1444 block_im(:, :) = sin(
twopi*arg)*data_block(:, :)
1452 CALL timestop(handle)
1454 END SUBROUTINE mat_ikp_from_mat_gamma
1464 SUBROUTINE compute_cfm_w_ikp_freq_j(bs_env, cfm_chi_ikp_freq_j, cfm_V_sqrt_ikp, &
1465 cfm_M_inv_V_sqrt_ikp, cfm_W_ikp_freq_j)
1468 TYPE(
cp_cfm_type) :: cfm_chi_ikp_freq_j, cfm_v_sqrt_ikp, &
1469 cfm_m_inv_v_sqrt_ikp, cfm_w_ikp_freq_j
1471 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_cfm_W_ikp_freq_j'
1473 INTEGER :: handle, info, n_ri
1476 CALL timeset(routinen, handle)
1478 CALL cp_cfm_create(cfm_work, cfm_chi_ikp_freq_j%matrix_struct)
1485 cfm_chi_ikp_freq_j, cfm_m_inv_v_sqrt_ikp,
z_zero, cfm_work)
1489 CALL cp_cfm_create(cfm_eps_ikp_freq_j, cfm_work%matrix_struct)
1491 cfm_m_inv_v_sqrt_ikp, cfm_work,
z_zero, cfm_eps_ikp_freq_j)
1494 CALL cfm_add_on_diag(cfm_eps_ikp_freq_j,
z_one)
1507 CALL cfm_add_on_diag(cfm_eps_ikp_freq_j, -
z_one)
1510 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri,
z_one, cfm_eps_ikp_freq_j, cfm_v_sqrt_ikp, &
1514 CALL cp_cfm_create(cfm_w_ikp_freq_j, cfm_work%matrix_struct)
1516 z_zero, cfm_w_ikp_freq_j)
1521 CALL timestop(handle)
1523 END SUBROUTINE compute_cfm_w_ikp_freq_j
1530 SUBROUTINE cfm_add_on_diag(cfm, alpha)
1533 COMPLEX(KIND=dp) :: alpha
1535 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cfm_add_on_diag'
1537 INTEGER :: handle, i_row, j_col, j_global, &
1538 ncol_local, nrow_local
1539 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1541 CALL timeset(routinen, handle)
1544 nrow_local=nrow_local, &
1545 ncol_local=ncol_local, &
1546 row_indices=row_indices, &
1547 col_indices=col_indices)
1550 DO j_col = 1, ncol_local
1551 j_global = col_indices(j_col)
1552 DO i_row = 1, nrow_local
1553 IF (j_global == row_indices(i_row))
THEN
1554 cfm%local_data(i_row, j_col) = cfm%local_data(i_row, j_col) + alpha
1559 CALL timestop(handle)
1561 END SUBROUTINE cfm_add_on_diag
1568 SUBROUTINE create_fm_w_mic_time(bs_env, fm_W_MIC_time)
1570 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1572 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_fm_W_MIC_time'
1574 INTEGER :: handle, i_t
1576 CALL timeset(routinen, handle)
1578 ALLOCATE (fm_w_mic_time(bs_env%num_time_freq_points))
1579 DO i_t = 1, bs_env%num_time_freq_points
1580 CALL cp_fm_create(fm_w_mic_time(i_t), bs_env%fm_RI_RI%matrix_struct, set_zero=.true.)
1583 CALL timestop(handle)
1585 END SUBROUTINE create_fm_w_mic_time
1594 SUBROUTINE fourier_transform_w_to_t(bs_env, fm_W_MIC_time, fm_W_MIC_freq_j, j_w)
1596 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1600 CHARACTER(LEN=*),
PARAMETER :: routinen =
'Fourier_transform_w_to_t'
1602 INTEGER :: handle, i_t
1603 REAL(kind=
dp) :: freq_j, time_i, weight_ij
1605 CALL timeset(routinen, handle)
1607 freq_j = bs_env%imag_freq_points(j_w)
1609 DO i_t = 1, bs_env%num_time_freq_points
1611 time_i = bs_env%imag_time_points(i_t)
1612 weight_ij = bs_env%weights_cos_w_to_t(i_t, j_w)
1616 beta=weight_ij*cos(time_i*freq_j), matrix_b=fm_w_mic_freq_j)
1620 CALL timestop(handle)
1622 END SUBROUTINE fourier_transform_w_to_t
1630 SUBROUTINE multiply_fm_w_mic_time_with_minv_gamma(bs_env, qs_env, fm_W_MIC_time)
1633 TYPE(
cp_fm_type),
DIMENSION(:) :: fm_w_mic_time
1635 CHARACTER(LEN=*),
PARAMETER :: routinen =
'multiply_fm_W_MIC_time_with_Minv_Gamma'
1637 INTEGER :: handle, i_t, n_ri, ndep
1639 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_minv_gamma
1641 CALL timeset(routinen, handle)
1645 CALL cp_fm_create(fm_work, fm_w_mic_time(1)%matrix_struct)
1649 bs_env%ri_metric, do_kpoints=.false.)
1651 CALL cp_fm_power(fm_minv_gamma(1, 1), fm_work, -1.0_dp, 0.0_dp, ndep)
1654 DO i_t = 1,
SIZE(fm_w_mic_time)
1656 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_minv_gamma(1, 1), &
1657 fm_w_mic_time(i_t), 0.0_dp, fm_work)
1659 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_work, &
1660 fm_minv_gamma(1, 1), 0.0_dp, fm_w_mic_time(i_t))
1667 CALL timestop(handle)
1669 END SUBROUTINE multiply_fm_w_mic_time_with_minv_gamma
1677 SUBROUTINE get_sigma_x(bs_env, qs_env, fm_Sigma_x_Gamma)
1680 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
1682 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_Sigma_x'
1684 INTEGER :: handle, ispin
1686 CALL timeset(routinen, handle)
1688 ALLOCATE (fm_sigma_x_gamma(bs_env%n_spin))
1689 DO ispin = 1, bs_env%n_spin
1690 CALL cp_fm_create(fm_sigma_x_gamma(ispin), bs_env%fm_s_Gamma%matrix_struct)
1693 IF (bs_env%Sigma_x_exists)
THEN
1694 DO ispin = 1, bs_env%n_spin
1695 CALL fm_read(fm_sigma_x_gamma(ispin), bs_env, bs_env%Sigma_x_name, ispin)
1698 CALL compute_sigma_x(bs_env, qs_env, fm_sigma_x_gamma)
1701 CALL timestop(handle)
1703 END SUBROUTINE get_sigma_x
1711 SUBROUTINE compute_sigma_x(bs_env, qs_env, fm_Sigma_x_Gamma)
1714 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
1716 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_x'
1718 INTEGER :: handle, i_intval_idx, ispin, j_intval_idx
1719 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
1721 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_vtr_gamma
1723 TYPE(dbt_type) :: t_2c_d, t_2c_sigma_x, t_2c_v, t_3c_x_v
1725 CALL timeset(routinen, handle)
1729 CALL dbt_create(bs_env%t_G, t_2c_d)
1730 CALL dbt_create(bs_env%t_W, t_2c_v)
1731 CALL dbt_create(bs_env%t_G, t_2c_sigma_x)
1732 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_v)
1733 CALL dbcsr_create(mat_sigma_x_gamma, template=bs_env%mat_ao_ao%matrix)
1737 bs_env%trunc_coulomb, do_kpoints=.false.)
1740 CALL multiply_fm_w_mic_time_with_minv_gamma(bs_env, qs_env, fm_vtr_gamma(:, 1))
1742 DO ispin = 1, bs_env%n_spin
1745 CALL g_occ_vir(bs_env, 0.0_dp, bs_env%fm_work_mo(2), ispin, occ=.true., vir=.false.)
1748 bs_env%mat_ao_ao_tensor%matrix, t_2c_d, bs_env, &
1749 bs_env%atoms_i_t_group)
1752 bs_env%mat_RI_RI_tensor%matrix, t_2c_v, bs_env, &
1753 bs_env%atoms_j_t_group)
1757 DO i_intval_idx = 1, bs_env%n_intervals_i
1758 DO j_intval_idx = 1, bs_env%n_intervals_j
1759 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
1760 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
1764 CALL compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_v, t_2c_v)
1768 CALL contract_to_sigma(t_2c_d, t_3c_x_v, t_2c_sigma_x, i_atoms, j_atoms, &
1769 qs_env, bs_env, occ=.true., vir=.false.)
1775 mat_sigma_x_gamma, bs_env%para_env)
1777 CALL write_matrix(mat_sigma_x_gamma, ispin, bs_env%Sigma_x_name, &
1778 bs_env%fm_work_mo(1), qs_env)
1784 IF (bs_env%unit_nr > 0)
THEN
1785 WRITE (bs_env%unit_nr,
'(T2,A,T55,A,F10.1,A)') &
1786 Σ
'Computed ^x(k=0),',
' Execution time',
m_walltime() - t1,
' s'
1787 WRITE (bs_env%unit_nr,
'(A)')
' '
1791 CALL dbt_destroy(t_2c_d)
1792 CALL dbt_destroy(t_2c_v)
1793 CALL dbt_destroy(t_2c_sigma_x)
1794 CALL dbt_destroy(t_3c_x_v)
1797 CALL timestop(handle)
1799 END SUBROUTINE compute_sigma_x
1808 SUBROUTINE get_sigma_c(bs_env, qs_env, fm_W_MIC_time, fm_Sigma_c_Gamma_time)
1811 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1812 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
1814 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_Sigma_c'
1816 INTEGER :: handle, i_intval_idx, i_t, ispin, &
1817 j_intval_idx, read_write_index
1818 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
1819 REAL(kind=
dp) :: t1, tau
1820 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
1821 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, &
1822 t_2c_sigma_neg_tau, &
1823 t_2c_sigma_pos_tau, t_2c_w, t_3c_x_w
1825 CALL timeset(routinen, handle)
1827 CALL create_mat_for_sigma_c(bs_env, t_2c_gocc, t_2c_gvir, t_2c_w, t_2c_sigma_neg_tau, &
1828 t_2c_sigma_pos_tau, t_3c_x_w, &
1829 mat_sigma_neg_tau, mat_sigma_pos_tau)
1831 DO i_t = 1, bs_env%num_time_freq_points
1833 DO ispin = 1, bs_env%n_spin
1837 read_write_index = i_t + (ispin - 1)*bs_env%num_time_freq_points
1840 IF (bs_env%Sigma_c_exists(i_t, ispin))
THEN
1841 CALL fm_read(bs_env%fm_work_mo(1), bs_env, bs_env%Sigma_p_name, read_write_index)
1842 CALL copy_fm_to_dbcsr(bs_env%fm_work_mo(1), mat_sigma_pos_tau(i_t, ispin)%matrix, &
1843 keep_sparsity=.false.)
1844 CALL fm_read(bs_env%fm_work_mo(1), bs_env, bs_env%Sigma_n_name, read_write_index)
1845 CALL copy_fm_to_dbcsr(bs_env%fm_work_mo(1), mat_sigma_neg_tau(i_t, ispin)%matrix, &
1846 keep_sparsity=.false.)
1847 IF (bs_env%unit_nr > 0)
THEN
1848 WRITE (bs_env%unit_nr,
'(T2,2A,I3,A,I3,A,F10.1,A)') Στ
'Read ^c(i,k=0) ', &
1849 'from file for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1857 tau = bs_env%imag_time_points(i_t)
1859 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gocc, ispin, occ=.true., vir=.false.)
1860 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gvir, ispin, occ=.false., vir=.true.)
1864 bs_env%mat_ao_ao_tensor%matrix, t_2c_gocc, bs_env, &
1865 bs_env%atoms_i_t_group)
1867 bs_env%mat_ao_ao_tensor%matrix, t_2c_gvir, bs_env, &
1868 bs_env%atoms_i_t_group)
1870 bs_env%mat_RI_RI_tensor%matrix, t_2c_w, bs_env, &
1871 bs_env%atoms_j_t_group)
1875 DO i_intval_idx = 1, bs_env%n_intervals_i
1876 DO j_intval_idx = 1, bs_env%n_intervals_j
1877 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
1878 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
1880 IF (bs_env%skip_Sigma_occ(i_intval_idx, j_intval_idx) .AND. &
1881 bs_env%skip_Sigma_vir(i_intval_idx, j_intval_idx))
THEN
1885 bs_env%n_skip_sigma = bs_env%n_skip_sigma + 1
1892 CALL compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_w, t_2c_w)
1896 CALL contract_to_sigma(t_2c_gocc, t_3c_x_w, t_2c_sigma_neg_tau, i_atoms, j_atoms, &
1897 qs_env, bs_env, occ=.true., vir=.false., &
1898 can_skip=bs_env%skip_Sigma_occ(i_intval_idx, j_intval_idx))
1901 CALL contract_to_sigma(t_2c_gvir, t_3c_x_w, t_2c_sigma_pos_tau, i_atoms, j_atoms, &
1902 qs_env, bs_env, occ=.false., vir=.true., &
1903 can_skip=bs_env%skip_Sigma_vir(i_intval_idx, j_intval_idx))
1911 mat_sigma_neg_tau(i_t, ispin)%matrix, bs_env%para_env)
1913 mat_sigma_pos_tau(i_t, ispin)%matrix, bs_env%para_env)
1915 CALL write_matrix(mat_sigma_pos_tau(i_t, ispin)%matrix, read_write_index, &
1916 bs_env%Sigma_p_name, bs_env%fm_work_mo(1), qs_env)
1917 CALL write_matrix(mat_sigma_neg_tau(i_t, ispin)%matrix, read_write_index, &
1918 bs_env%Sigma_n_name, bs_env%fm_work_mo(1), qs_env)
1920 IF (bs_env%unit_nr > 0)
THEN
1921 WRITE (bs_env%unit_nr,
'(T2,A,I10,A,I3,A,F10.1,A)') &
1922 Στ
'Computed ^c(i,k=0) for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1930 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1932 CALL fill_fm_sigma_c_gamma_time(fm_sigma_c_gamma_time, bs_env, &
1933 mat_sigma_pos_tau, mat_sigma_neg_tau)
1935 CALL print_skipping(bs_env)
1937 CALL destroy_mat_sigma_c(t_2c_gocc, t_2c_gvir, t_2c_w, t_2c_sigma_neg_tau, &
1938 t_2c_sigma_pos_tau, t_3c_x_w, fm_w_mic_time, &
1939 mat_sigma_neg_tau, mat_sigma_pos_tau)
1941 CALL delete_unnecessary_files(bs_env)
1943 CALL timestop(handle)
1945 END SUBROUTINE get_sigma_c
1959 SUBROUTINE create_mat_for_sigma_c(bs_env, t_2c_Gocc, t_2c_Gvir, t_2c_W, t_2c_Sigma_neg_tau, &
1960 t_2c_Sigma_pos_tau, t_3c_x_W, &
1961 mat_Sigma_neg_tau, mat_Sigma_pos_tau)
1964 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_2c_w, &
1965 t_2c_sigma_neg_tau, &
1966 t_2c_sigma_pos_tau, t_3c_x_w
1967 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
1969 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_mat_for_Sigma_c'
1971 INTEGER :: handle, i_t, ispin
1973 CALL timeset(routinen, handle)
1975 CALL dbt_create(bs_env%t_G, t_2c_gocc)
1976 CALL dbt_create(bs_env%t_G, t_2c_gvir)
1977 CALL dbt_create(bs_env%t_W, t_2c_w)
1978 CALL dbt_create(bs_env%t_G, t_2c_sigma_neg_tau)
1979 CALL dbt_create(bs_env%t_G, t_2c_sigma_pos_tau)
1980 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_w)
1982 NULLIFY (mat_sigma_neg_tau, mat_sigma_pos_tau)
1983 ALLOCATE (mat_sigma_neg_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1984 ALLOCATE (mat_sigma_pos_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1986 DO ispin = 1, bs_env%n_spin
1987 DO i_t = 1, bs_env%num_time_freq_points
1988 ALLOCATE (mat_sigma_neg_tau(i_t, ispin)%matrix)
1989 ALLOCATE (mat_sigma_pos_tau(i_t, ispin)%matrix)
1990 CALL dbcsr_create(mat_sigma_neg_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1991 CALL dbcsr_create(mat_sigma_pos_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1995 CALL timestop(handle)
1997 END SUBROUTINE create_mat_for_sigma_c
2008 SUBROUTINE compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_W, t_2c_W)
2012 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
2013 TYPE(dbt_type) :: t_3c_x_w, t_2c_w
2015 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_3c_and_contract_W'
2017 INTEGER :: handle, ri_intval_idx
2018 INTEGER(KIND=int_8) :: flop
2019 INTEGER,
DIMENSION(2) :: bounds_p, bounds_q, ri_atoms
2020 INTEGER,
DIMENSION(2, 2) :: bounds_ao
2021 TYPE(dbt_type) :: t_3c_for_w, t_3c_x_w_tmp
2023 CALL timeset(routinen, handle)
2025 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_w_tmp)
2026 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_for_w)
2036 bounds_q(1:2) = [bs_env%i_RI_start_from_atom(j_atoms(1)), &
2037 bs_env%i_RI_end_from_atom(j_atoms(2))]
2039 DO ri_intval_idx = 1, bs_env%n_intervals_inner_loop_atoms
2040 ri_atoms = bs_env%inner_loop_atom_intervals(1:2, ri_intval_idx)
2042 CALL get_bounds_from_atoms(bounds_p, i_atoms, [1, bs_env%n_atom], &
2043 bs_env%min_RI_idx_from_AO_AO_atom, &
2044 bs_env%max_RI_idx_from_AO_AO_atom, &
2046 indices_3_start=bs_env%i_RI_start_from_atom, &
2047 indices_3_end=bs_env%i_RI_end_from_atom)
2050 CALL get_bounds_from_atoms(bounds_ao(:, 2), ri_atoms, i_atoms, &
2051 bs_env%min_AO_idx_from_RI_AO_atom, &
2052 bs_env%max_AO_idx_from_RI_AO_atom)
2054 CALL get_bounds_from_atoms(bounds_ao(:, 1), ri_atoms, [1, bs_env%n_atom], &
2055 bs_env%min_AO_idx_from_RI_AO_atom, &
2056 bs_env%max_AO_idx_from_RI_AO_atom, &
2058 indices_3_start=bs_env%i_ao_start_from_atom, &
2059 indices_3_end=bs_env%i_ao_end_from_atom)
2061 IF (bounds_p(1) > bounds_p(2) .OR. bounds_ao(1, 2) > bounds_ao(2, 2))
THEN
2067 atoms_ao_1=i_atoms, atoms_ri=ri_atoms)
2070 CALL dbt_contract(alpha=1.0_dp, &
2072 tensor_2=t_3c_for_w, &
2074 tensor_3=t_3c_x_w_tmp, &
2075 contract_1=[2], notcontract_1=[1], map_1=[1], &
2076 contract_2=[1], notcontract_2=[2, 3], map_2=[2, 3], &
2077 bounds_1=bounds_p, &
2078 bounds_2=bounds_q, &
2079 bounds_3=bounds_ao, &
2081 move_data=.false., &
2082 filter_eps=bs_env%eps_filter, &
2083 unit_nr=bs_env%unit_nr_contract, &
2084 log_verbose=bs_env%print_contract_verbose)
2089 CALL dbt_copy(t_3c_x_w_tmp, t_3c_x_w, order=[1, 2, 3], move_data=.true.)
2091 CALL dbt_destroy(t_3c_x_w_tmp)
2092 CALL dbt_destroy(t_3c_for_w)
2094 CALL timestop(handle)
2096 END SUBROUTINE compute_3c_and_contract_w
2111 SUBROUTINE contract_to_sigma(t_2c_G, t_3c_x_W, t_2c_Sigma, i_atoms, j_atoms, qs_env, bs_env, &
2113 TYPE(dbt_type) :: t_2c_g, t_3c_x_w, t_2c_sigma
2114 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
2118 LOGICAL,
OPTIONAL :: can_skip
2120 CHARACTER(LEN=*),
PARAMETER :: routinen =
'contract_to_Sigma'
2122 INTEGER :: handle, inner_loop_atoms_interval_index
2123 INTEGER(KIND=int_8) :: flop
2124 INTEGER,
DIMENSION(2) :: bounds_lambda, bounds_mu, bounds_nu, &
2125 bounds_sigma, il_atoms
2126 INTEGER,
DIMENSION(2, 2) :: bounds_comb
2127 REAL(kind=
dp) :: sign_sigma
2128 TYPE(dbt_type) :: t_3c_for_g, t_3c_x_g, t_3c_x_g_2
2130 CALL timeset(routinen, handle)
2132 cpassert(occ .EQV. (.NOT. vir))
2133 IF (occ) sign_sigma = -1.0_dp
2134 IF (vir) sign_sigma = 1.0_dp
2136 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_g)
2137 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_g)
2138 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_g_2)
2151 bounds_nu(1:2) = [bs_env%i_ao_start_from_atom(i_atoms(1)), &
2152 bs_env%i_ao_end_from_atom(i_atoms(2))]
2154 DO inner_loop_atoms_interval_index = 1, bs_env%n_intervals_inner_loop_atoms
2155 il_atoms = bs_env%inner_loop_atom_intervals(1:2, inner_loop_atoms_interval_index)
2158 CALL get_bounds_from_atoms(bounds_mu, j_atoms, [1, bs_env%n_atom], &
2159 bs_env%min_AO_idx_from_RI_AO_atom, &
2160 bs_env%max_AO_idx_from_RI_AO_atom, &
2162 indices_3_start=bs_env%i_ao_start_from_atom, &
2163 indices_3_end=bs_env%i_ao_end_from_atom)
2166 CALL get_bounds_from_atoms(bounds_comb(:, 1), il_atoms, [1, bs_env%n_atom], &
2167 bs_env%min_RI_idx_from_AO_AO_atom, &
2168 bs_env%max_RI_idx_from_AO_AO_atom, &
2170 indices_3_start=bs_env%i_RI_start_from_atom, &
2171 indices_3_end=bs_env%i_RI_end_from_atom)
2174 CALL get_bounds_from_atoms(bounds_comb(:, 2), j_atoms, il_atoms, &
2175 bs_env%min_AO_idx_from_RI_AO_atom, &
2176 bs_env%max_AO_idx_from_RI_AO_atom)
2178 IF (bounds_mu(1) > bounds_mu(2) .OR. bounds_comb(1, 1) > bounds_comb(2, 1) .OR. &
2179 bounds_comb(1, 2) > bounds_comb(2, 2))
THEN
2184 atoms_ri=j_atoms, atoms_ao_2=il_atoms)
2186 CALL dbt_contract(alpha=1.0_dp, &
2188 tensor_2=t_3c_for_g, &
2190 tensor_3=t_3c_x_g, &
2191 contract_1=[2], notcontract_1=[1], map_1=[3], &
2192 contract_2=[3], notcontract_2=[1, 2], map_2=[1, 2], &
2193 bounds_1=bounds_mu, &
2194 bounds_2=bounds_nu, &
2195 bounds_3=bounds_comb, &
2197 move_data=.false., &
2198 filter_eps=bs_env%eps_filter, &
2199 unit_nr=bs_env%unit_nr_contract, &
2200 log_verbose=bs_env%print_contract_verbose)
2204 CALL dbt_copy(t_3c_x_g, t_3c_x_g_2, order=[1, 3, 2], move_data=.true.)
2208 bounds_comb(1:2, 1) = [bs_env%i_RI_start_from_atom(j_atoms(1)), &
2209 bs_env%i_RI_end_from_atom(j_atoms(2))]
2210 bounds_comb(1:2, 2) = bounds_nu(1:2)
2212 CALL get_bounds_from_atoms(bounds_lambda, j_atoms, [1, bs_env%n_atom], &
2213 bs_env%min_AO_idx_from_RI_AO_atom, &
2214 bs_env%max_AO_idx_from_RI_AO_atom)
2215 CALL get_bounds_from_atoms(bounds_sigma, [1, bs_env%n_atom], i_atoms, &
2216 bs_env%min_AO_idx_from_RI_AO_atom, &
2217 bs_env%max_AO_idx_from_RI_AO_atom)
2219 IF (bounds_sigma(1) > bounds_sigma(2) .OR. bounds_lambda(1) > bounds_lambda(2))
THEN
2222 CALL dbt_contract(alpha=sign_sigma, &
2223 tensor_1=t_3c_x_w, &
2224 tensor_2=t_3c_x_g_2, &
2226 tensor_3=t_2c_sigma, &
2227 contract_1=[1, 2], notcontract_1=[3], map_1=[1], &
2228 contract_2=[1, 2], notcontract_2=[3], map_2=[2], &
2229 bounds_1=bounds_comb, &
2230 bounds_2=bounds_sigma, &
2231 bounds_3=bounds_lambda, &
2232 filter_eps=bs_env%eps_filter, move_data=.false., flop=flop, &
2233 unit_nr=bs_env%unit_nr_contract, &
2234 log_verbose=bs_env%print_contract_verbose)
2237 IF (
PRESENT(can_skip))
THEN
2238 IF (flop == 0_int_8) can_skip = .true.
2241 CALL dbt_destroy(t_3c_for_g)
2242 CALL dbt_destroy(t_3c_x_g)
2243 CALL dbt_destroy(t_3c_x_g_2)
2245 CALL timestop(handle)
2247 END SUBROUTINE contract_to_sigma
2256 SUBROUTINE fill_fm_sigma_c_gamma_time(fm_Sigma_c_Gamma_time, bs_env, &
2257 mat_Sigma_pos_tau, mat_Sigma_neg_tau)
2259 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
2261 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_pos_tau, mat_sigma_neg_tau
2263 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fill_fm_Sigma_c_Gamma_time'
2265 INTEGER :: handle, i_t, ispin, pos_neg
2267 CALL timeset(routinen, handle)
2269 ALLOCATE (fm_sigma_c_gamma_time(bs_env%num_time_freq_points, 2, bs_env%n_spin))
2270 DO ispin = 1, bs_env%n_spin
2271 DO i_t = 1, bs_env%num_time_freq_points
2273 CALL cp_fm_create(fm_sigma_c_gamma_time(i_t, pos_neg, ispin), &
2274 bs_env%fm_s_Gamma%matrix_struct)
2277 fm_sigma_c_gamma_time(i_t, 1, ispin))
2279 fm_sigma_c_gamma_time(i_t, 2, ispin))
2283 CALL timestop(handle)
2285 END SUBROUTINE fill_fm_sigma_c_gamma_time
2291 SUBROUTINE print_skipping(bs_env)
2295 CHARACTER(LEN=*),
PARAMETER :: routinen =
'print_skipping'
2297 INTEGER :: handle, n_pairs
2299 CALL timeset(routinen, handle)
2301 n_pairs = bs_env%n_intervals_i*bs_env%n_intervals_j*bs_env%n_spin
2303 CALL bs_env%para_env_tensor%sum(bs_env%n_skip_sigma)
2304 CALL bs_env%para_env_tensor%sum(bs_env%n_skip_chi)
2305 CALL bs_env%para_env_tensor%sum(n_pairs)
2307 IF (bs_env%unit_nr > 0)
THEN
2308 WRITE (bs_env%unit_nr,
'(T2,A,T74,F7.1,A)') &
2309 Στ
'Sparsity of ^c(i,k=0): Percentage of skipped atom pairs:', &
2310 REAL(100*bs_env%n_skip_sigma, kind=
dp)/real(n_pairs, kind=
dp),
' %'
2311 WRITE (bs_env%unit_nr,
'(T2,A,T74,F7.1,A)') &
2312 χτ
'Sparsity of (i,k=0): Percentage of skipped atom pairs:', &
2313 REAL(100*bs_env%n_skip_chi, kind=
dp)/real(n_pairs, kind=
dp),
' %'
2316 CALL timestop(handle)
2318 END SUBROUTINE print_skipping
2332 SUBROUTINE destroy_mat_sigma_c(t_2c_Gocc, t_2c_Gvir, t_2c_W, t_2c_Sigma_neg_tau, &
2333 t_2c_Sigma_pos_tau, t_3c_x_W, fm_W_MIC_time, &
2334 mat_Sigma_neg_tau, mat_Sigma_pos_tau)
2336 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_2c_w, &
2337 t_2c_sigma_neg_tau, &
2338 t_2c_sigma_pos_tau, t_3c_x_w
2339 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
2340 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
2342 CHARACTER(LEN=*),
PARAMETER :: routinen =
'destroy_mat_Sigma_c'
2346 CALL timeset(routinen, handle)
2348 CALL dbt_destroy(t_2c_gocc)
2349 CALL dbt_destroy(t_2c_gvir)
2350 CALL dbt_destroy(t_2c_w)
2351 CALL dbt_destroy(t_2c_sigma_neg_tau)
2352 CALL dbt_destroy(t_2c_sigma_pos_tau)
2353 CALL dbt_destroy(t_3c_x_w)
2358 CALL timestop(handle)
2360 END SUBROUTINE destroy_mat_sigma_c
2366 SUBROUTINE delete_unnecessary_files(bs_env)
2369 CHARACTER(LEN=*),
PARAMETER :: routinen =
'delete_unnecessary_files'
2371 CHARACTER(LEN=default_string_length) :: f_chi, f_w_t, prefix
2372 INTEGER :: handle, i_t
2374 CALL timeset(routinen, handle)
2376 prefix = bs_env%prefix
2378 DO i_t = 1, bs_env%num_time_freq_points
2381 WRITE (f_chi,
'(3A,I1,A)') trim(prefix), bs_env%chi_name,
"_00", i_t,
".matrix"
2382 WRITE (f_w_t,
'(3A,I1,A)') trim(prefix), bs_env%W_time_name,
"_00", i_t,
".matrix"
2383 ELSE IF (i_t < 100)
THEN
2384 WRITE (f_chi,
'(3A,I2,A)') trim(prefix), bs_env%chi_name,
"_0", i_t,
".matrix"
2385 WRITE (f_w_t,
'(3A,I2,A)') trim(prefix), bs_env%W_time_name,
"_0", i_t,
".matrix"
2387 cpabort(
'Please implement more than 99 time/frequency points.')
2390 CALL safe_delete(f_chi, bs_env)
2391 CALL safe_delete(f_w_t, bs_env)
2395 CALL timestop(handle)
2397 END SUBROUTINE delete_unnecessary_files
2404 SUBROUTINE safe_delete(filename, bs_env)
2405 CHARACTER(LEN=*) :: filename
2408 CHARACTER(LEN=*),
PARAMETER :: routinen =
'safe_delete'
2413 CALL timeset(routinen, handle)
2415 IF (bs_env%para_env%mepos == 0)
THEN
2422 CALL timestop(handle)
2424 END SUBROUTINE safe_delete
2433 SUBROUTINE compute_qp_energies(bs_env, qs_env, fm_Sigma_x_Gamma, fm_Sigma_c_Gamma_time)
2437 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
2438 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
2440 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_QP_energies'
2442 INTEGER :: handle, ikp, ispin, j_t
2443 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: sigma_x_ikp_n, v_xc_ikp_n
2444 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: sigma_c_ikp_n_freq, sigma_c_ikp_n_time
2445 TYPE(
cp_cfm_type) :: cfm_ks_ikp, cfm_mos_ikp, cfm_s_ikp, &
2446 cfm_sigma_x_ikp, cfm_work_ikp
2448 CALL timeset(routinen, handle)
2450 CALL cp_cfm_create(cfm_mos_ikp, bs_env%fm_s_Gamma%matrix_struct)
2451 CALL cp_cfm_create(cfm_work_ikp, bs_env%fm_s_Gamma%matrix_struct)
2453 ALLOCATE (v_xc_ikp_n(bs_env%n_ao), sigma_x_ikp_n(bs_env%n_ao))
2454 ALLOCATE (sigma_c_ikp_n_time(bs_env%n_ao, bs_env%num_time_freq_points, 2))
2455 ALLOCATE (sigma_c_ikp_n_freq(bs_env%n_ao, bs_env%num_time_freq_points, 2))
2457 DO ispin = 1, bs_env%n_spin
2459 DO ikp = 1, bs_env%nkp_bs_and_DOS
2463 ikp, qs_env, bs_env%kpoints_DOS,
"ORB")
2467 ikp, qs_env, bs_env%kpoints_DOS,
"ORB")
2470 CALL cp_cfm_geeig(cfm_ks_ikp, cfm_s_ikp, cfm_mos_ikp, &
2471 bs_env%eigenval_scf(:, ikp, ispin), cfm_work_ikp)
2474 CALL to_ikp_and_mo(v_xc_ikp_n, bs_env%fm_V_xc_Gamma(ispin), &
2475 ikp, qs_env, bs_env, cfm_mos_ikp)
2478 CALL to_ikp_and_mo(sigma_x_ikp_n, fm_sigma_x_gamma(ispin), &
2479 ikp, qs_env, bs_env, cfm_mos_ikp)
2482 DO j_t = 1, bs_env%num_time_freq_points
2483 CALL to_ikp_and_mo(sigma_c_ikp_n_time(:, j_t, 1), &
2484 fm_sigma_c_gamma_time(j_t, 1, ispin), &
2485 ikp, qs_env, bs_env, cfm_mos_ikp)
2486 CALL to_ikp_and_mo(sigma_c_ikp_n_time(:, j_t, 2), &
2487 fm_sigma_c_gamma_time(j_t, 2, ispin), &
2488 ikp, qs_env, bs_env, cfm_mos_ikp)
2492 CALL time_to_freq(bs_env, sigma_c_ikp_n_time, sigma_c_ikp_n_freq, ispin)
2497 bs_env%eigenval_scf(:, ikp, ispin), ikp, ispin)
2513 CALL timestop(handle)
2515 END SUBROUTINE compute_qp_energies
2526 SUBROUTINE to_ikp_and_mo(array_ikp_n, fm_Gamma, ikp, qs_env, bs_env, cfm_mos_ikp)
2528 REAL(kind=
dp),
DIMENSION(:) :: array_ikp_n
2535 CHARACTER(LEN=*),
PARAMETER :: routinen =
'to_ikp_and_mo'
2540 CALL timeset(routinen, handle)
2542 CALL cp_fm_create(fm_ikp_mo_re, fm_gamma%matrix_struct)
2544 CALL fm_gamma_ao_to_cfm_ikp_mo(fm_gamma, fm_ikp_mo_re, ikp, qs_env, bs_env, cfm_mos_ikp)
2550 CALL timestop(handle)
2552 END SUBROUTINE to_ikp_and_mo
2563 SUBROUTINE fm_gamma_ao_to_cfm_ikp_mo(fm_Gamma, fm_ikp_mo_re, ikp, qs_env, bs_env, cfm_mos_ikp)
2570 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_Gamma_ao_to_cfm_ikp_mo'
2572 INTEGER :: handle, nmo
2573 TYPE(
cp_cfm_type) :: cfm_ikp_ao, cfm_ikp_mo, cfm_tmp
2575 CALL timeset(routinen, handle)
2594 CALL timestop(handle)
2596 END SUBROUTINE fm_gamma_ao_to_cfm_ikp_mo
2613 SUBROUTINE get_bounds_from_atoms(bounds_out, atoms_1, atoms_2, indices_min, indices_max, &
2614 atoms_3, indices_3_start, indices_3_end)
2616 INTEGER,
DIMENSION(2),
INTENT(OUT) :: bounds_out
2617 INTEGER,
DIMENSION(2),
INTENT(IN) :: atoms_1, atoms_2
2618 INTEGER,
DIMENSION(:, :) :: indices_min, indices_max
2619 INTEGER,
DIMENSION(2),
INTENT(IN),
OPTIONAL :: atoms_3
2620 INTEGER,
DIMENSION(:),
OPTIONAL :: indices_3_start, indices_3_end
2622 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_bounds_from_atoms'
2624 INTEGER :: handle, i_at, j_at
2626 CALL timeset(routinen, handle)
2627 bounds_out(1) = huge(0)
2630 DO i_at = atoms_1(1), atoms_1(2)
2631 DO j_at = atoms_2(1), atoms_2(2)
2632 bounds_out(1) = min(bounds_out(1), indices_min(i_at, j_at))
2633 bounds_out(2) = max(bounds_out(2), indices_max(i_at, j_at))
2637 IF (
PRESENT(atoms_3) .AND.
PRESENT(indices_3_start) .AND.
PRESENT(indices_3_end))
THEN
2638 bounds_out(1) = max(bounds_out(1), indices_3_start(atoms_3(1)))
2639 bounds_out(2) = min(bounds_out(2), indices_3_end(atoms_3(2)))
2642 CALL timestop(handle)
2644 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)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset)
...
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_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_create(matrix, matrix_struct, name, use_sp, nrow, ncol, set_zero)
creates a new full matrix with the given structure
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
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 gw_calc_large_cell_gamma(qs_env, bs_env)
Perform GW band structure calculation.
subroutine, public compute_3c_integrals(qs_env, bs_env, t_3c, atoms_ao_1, atoms_ao_2, atoms_ri)
...
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_string_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.