91#include "./base/base_uses.f90"
97 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_large_cell_gamma'
118 CHARACTER(LEN=*),
PARAMETER :: routinen =
'gw_calc_large_cell_Gamma'
121 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma, fm_w_mic_time
122 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
124 CALL timeset(routinen, handle)
131 CALL get_mat_chi_gamma_tau(bs_env, qs_env, bs_env%mat_chi_Gamma_tau)
134 CALL get_w_mic(bs_env, qs_env, bs_env%mat_chi_Gamma_tau, fm_w_mic_time)
138 CALL get_sigma_x(bs_env, qs_env, fm_sigma_x_gamma)
142 CALL get_sigma_c(bs_env, qs_env, fm_w_mic_time, fm_sigma_c_gamma_time)
149 CALL timestop(handle)
159 SUBROUTINE get_mat_chi_gamma_tau(bs_env, qs_env, mat_chi_Gamma_tau)
162 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
164 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_mat_chi_Gamma_tau'
166 INTEGER :: handle, i_intval_idx, i_t, inner_loop_atoms_interval_index, ispin, j_intval_idx
167 INTEGER(KIND=int_8) :: flop
168 INTEGER,
DIMENSION(2) :: bounds_p, bounds_q, i_atoms, il_atoms, &
170 INTEGER,
DIMENSION(2, 2) :: bounds_comb
171 LOGICAL :: dist_too_long_i, dist_too_long_j
172 REAL(kind=
dp) :: t1, tau
173 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_3c_for_gocc, &
174 t_3c_for_gvir, t_3c_x_gocc, &
175 t_3c_x_gocc_2, t_3c_x_gvir, &
178 CALL timeset(routinen, handle)
180 DO i_t = 1, bs_env%num_time_freq_points
184 IF (bs_env%read_chi(i_t))
THEN
186 CALL fm_read(bs_env%fm_RI_RI, bs_env, bs_env%chi_name, i_t)
189 keep_sparsity=.false.)
191 IF (bs_env%unit_nr > 0)
THEN
192 WRITE (bs_env%unit_nr,
'(T2,A,I5,A,I3,A,F10.1,A)') &
193 χτ
'Read (i,k=0) from file for time point ', i_t,
' /', &
194 bs_env%num_time_freq_points, &
202 IF (.NOT. bs_env%calc_chi(i_t)) cycle
204 CALL create_tensors_chi(t_2c_gocc, t_2c_gvir, t_3c_for_gocc, t_3c_for_gvir, &
205 t_3c_x_gocc, t_3c_x_gvir, t_3c_x_gocc_2, t_3c_x_gvir_2, bs_env)
211 tau = bs_env%imag_time_points(i_t)
213 DO ispin = 1, bs_env%n_spin
214 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gocc, ispin, occ=.true., vir=.false.)
215 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gvir, ispin, occ=.false., vir=.true.)
218 bs_env%mat_ao_ao_tensor%matrix, t_2c_gocc, bs_env, &
219 bs_env%atoms_j_t_group)
221 bs_env%mat_ao_ao_tensor%matrix, t_2c_gvir, bs_env, &
222 bs_env%atoms_i_t_group)
226 DO i_intval_idx = 1, bs_env%n_intervals_i
227 DO j_intval_idx = 1, bs_env%n_intervals_j
228 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
229 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
231 IF (bs_env%skip_chi(i_intval_idx, j_intval_idx))
THEN
235 bs_env%n_skip_chi = bs_env%n_skip_chi + 1
240 DO inner_loop_atoms_interval_index = 1, bs_env%n_intervals_inner_loop_atoms
242 il_atoms = bs_env%inner_loop_atom_intervals(1:2, inner_loop_atoms_interval_index)
248 CALL check_dist(i_atoms, il_atoms, qs_env, bs_env, dist_too_long_i)
249 CALL check_dist(j_atoms, il_atoms, qs_env, bs_env, dist_too_long_j)
250 IF (.NOT. dist_too_long_i)
THEN
253 atoms_ao_1=i_atoms, atoms_ao_2=il_atoms)
255 CALL g_times_3c(t_3c_for_gocc, t_2c_gocc, t_3c_x_gocc, bs_env, &
256 j_atoms, i_atoms, il_atoms)
258 IF (.NOT. dist_too_long_j)
THEN
261 atoms_ao_1=j_atoms, atoms_ao_2=il_atoms)
263 CALL g_times_3c(t_3c_for_gvir, t_2c_gvir, t_3c_x_gvir, bs_env, &
264 i_atoms, j_atoms, il_atoms)
269 CALL dbt_copy(t_3c_x_gocc, t_3c_x_gocc_2, move_data=.true., order=[1, 3, 2])
270 CALL dbt_copy(t_3c_x_gvir, t_3c_x_gvir_2, move_data=.true.)
279 bounds_comb(1:2, 1) = [bs_env%i_ao_start_from_atom(j_atoms(1)), &
280 bs_env%i_ao_end_from_atom(j_atoms(2))]
281 bounds_comb(1:2, 2) = [bs_env%i_ao_start_from_atom(i_atoms(1)), &
282 bs_env%i_ao_end_from_atom(i_atoms(2))]
284 CALL get_bounds_from_atoms(bounds_p, i_atoms, [1, bs_env%n_atom], &
285 bs_env%min_RI_idx_from_AO_AO_atom, &
286 bs_env%max_RI_idx_from_AO_AO_atom)
287 CALL get_bounds_from_atoms(bounds_q, [1, bs_env%n_atom], j_atoms, &
288 bs_env%min_RI_idx_from_AO_AO_atom, &
289 bs_env%max_RI_idx_from_AO_AO_atom)
291 IF (bounds_q(1) > bounds_q(2) .OR. bounds_p(1) > bounds_p(2))
THEN
294 CALL dbt_contract(alpha=bs_env%spin_degeneracy, &
295 tensor_1=t_3c_x_gocc_2, tensor_2=t_3c_x_gvir_2, &
296 beta=1.0_dp, tensor_3=bs_env%t_chi, &
297 contract_1=[2, 3], notcontract_1=[1], map_1=[1], &
298 contract_2=[2, 3], notcontract_2=[1], map_2=[2], &
299 bounds_1=bounds_comb, &
302 filter_eps=bs_env%eps_filter, move_data=.false., flop=flop, &
303 unit_nr=bs_env%unit_nr_contract, &
304 log_verbose=bs_env%print_contract_verbose)
306 IF (flop == 0_int_8) bs_env%skip_chi(i_intval_idx, j_intval_idx) = .true.
316 mat_chi_gamma_tau(i_t)%matrix, bs_env%para_env)
318 CALL write_matrix(mat_chi_gamma_tau(i_t)%matrix, i_t, bs_env%chi_name, &
319 bs_env%fm_RI_RI, qs_env)
321 CALL destroy_tensors_chi(t_2c_gocc, t_2c_gvir, t_3c_for_gocc, t_3c_for_gvir, &
322 t_3c_x_gocc, t_3c_x_gvir, t_3c_x_gocc_2, t_3c_x_gvir_2)
324 IF (bs_env%unit_nr > 0)
THEN
325 WRITE (bs_env%unit_nr,
'(T2,A,I13,A,I3,A,F10.1,A)') &
326 χτ
'Computed (i,k=0) for time point', i_t,
' /', bs_env%num_time_freq_points, &
332 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
334 CALL timestop(handle)
336 END SUBROUTINE get_mat_chi_gamma_tau
348 CHARACTER(LEN=*) :: mat_name
351 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_read'
353 CHARACTER(LEN=default_path_length) :: f_chi
354 INTEGER :: handle, unit_nr
356 CALL timeset(routinen, handle)
359 IF (bs_env%para_env%is_source())
THEN
362 WRITE (f_chi,
'(3A,I1,A)') trim(bs_env%prefix), trim(mat_name),
"_0",
idx,
".matrix"
363 ELSE IF (
idx < 100)
THEN
364 WRITE (f_chi,
'(3A,I2,A)') trim(bs_env%prefix), trim(mat_name),
"_",
idx,
".matrix"
366 cpabort(
'Please implement more than 99 time/frequency points.')
369 CALL open_file(file_name=trim(f_chi), file_action=
"READ", file_form=
"UNFORMATTED", &
370 file_position=
"REWIND", file_status=
"OLD", unit_number=unit_nr)
376 IF (bs_env%para_env%is_source())
CALL close_file(unit_number=unit_nr)
378 CALL timestop(handle)
394 SUBROUTINE create_tensors_chi(t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, t_3c_for_Gvir, &
395 t_3c_x_Gocc, t_3c_x_Gvir, t_3c_x_Gocc_2, t_3c_x_Gvir_2, bs_env)
397 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_3c_for_gocc, &
398 t_3c_for_gvir, t_3c_x_gocc, &
399 t_3c_x_gvir, t_3c_x_gocc_2, &
403 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_tensors_chi'
407 CALL timeset(routinen, handle)
409 CALL dbt_create(bs_env%t_G, t_2c_gocc, name=
"Gocc 2c (AO|AO)")
410 CALL dbt_create(bs_env%t_G, t_2c_gvir, name=
"Gvir 2c (AO|AO)")
411 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_gocc, name=
"Gocc 3c (RI AO|AO)")
412 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_gvir, name=
"Gvir 3c (RI AO|AO)")
413 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_gocc, name=
"xGocc 3c (RI AO|AO)")
414 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_gvir, name=
"xGvir 3c (RI AO|AO)")
415 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_gocc_2, name=
"x2Gocc 3c (RI AO|AO)")
416 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_gvir_2, name=
"x2Gvir 3c (RI AO|AO)")
418 CALL timestop(handle)
420 END SUBROUTINE create_tensors_chi
433 SUBROUTINE destroy_tensors_chi(t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, t_3c_for_Gvir, &
434 t_3c_x_Gocc, t_3c_x_Gvir, t_3c_x_Gocc_2, t_3c_x_Gvir_2)
435 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_3c_for_gocc, &
436 t_3c_for_gvir, t_3c_x_gocc, &
437 t_3c_x_gvir, t_3c_x_gocc_2, &
440 CHARACTER(LEN=*),
PARAMETER :: routinen =
'destroy_tensors_chi'
444 CALL timeset(routinen, handle)
446 CALL dbt_destroy(t_2c_gocc)
447 CALL dbt_destroy(t_2c_gvir)
448 CALL dbt_destroy(t_3c_for_gocc)
449 CALL dbt_destroy(t_3c_for_gvir)
450 CALL dbt_destroy(t_3c_x_gocc)
451 CALL dbt_destroy(t_3c_x_gvir)
452 CALL dbt_destroy(t_3c_x_gocc_2)
453 CALL dbt_destroy(t_3c_x_gvir_2)
455 CALL timestop(handle)
457 END SUBROUTINE destroy_tensors_chi
469 INTEGER :: matrix_index
470 CHARACTER(LEN=*) :: matrix_name
474 CHARACTER(LEN=*),
PARAMETER :: routinen =
'write_matrix'
478 CALL timeset(routinen, handle)
484 CALL fm_write(fm, matrix_index, matrix_name, qs_env)
486 CALL timestop(handle)
497 SUBROUTINE fm_write(fm, matrix_index, matrix_name, qs_env)
499 INTEGER :: matrix_index
500 CHARACTER(LEN=*) :: matrix_name
503 CHARACTER(LEN=*),
PARAMETER :: key =
'PROPERTIES%BANDSTRUCTURE%GW%PRINT%RESTART', &
504 routinen =
'fm_write'
506 CHARACTER(LEN=default_path_length) :: filename
507 INTEGER :: handle, unit_nr
511 CALL timeset(routinen, handle)
519 IF (matrix_index < 10)
THEN
520 WRITE (filename,
'(3A,I1)')
"RESTART_", matrix_name,
"_0", matrix_index
521 ELSE IF (matrix_index < 100)
THEN
522 WRITE (filename,
'(3A,I2)')
"RESTART_", matrix_name,
"_", matrix_index
524 cpabort(
'Please implement more than 99 time/frequency points.')
528 file_form=
"UNFORMATTED", middle_name=trim(filename), &
529 file_position=
"REWIND", file_action=
"WRITE")
532 IF (unit_nr > 0)
THEN
537 CALL timestop(handle)
539 END SUBROUTINE fm_write
550 SUBROUTINE g_occ_vir(bs_env, tau, fm_G_Gamma, ispin, occ, vir)
557 CHARACTER(LEN=*),
PARAMETER :: routinen =
'G_occ_vir'
559 INTEGER :: handle, homo, i_row_local, j_col, &
560 j_col_local, n_mo, ncol_local, &
562 INTEGER,
DIMENSION(:),
POINTER :: col_indices
563 REAL(kind=
dp) :: tau_e
565 CALL timeset(routinen, handle)
567 cpassert(occ .NEQV. vir)
570 nrow_local=nrow_local, &
571 ncol_local=ncol_local, &
572 col_indices=col_indices)
575 homo = bs_env%n_occ(ispin)
577 CALL cp_fm_to_fm(bs_env%fm_mo_coeff_Gamma(ispin), bs_env%fm_work_mo(1))
579 DO i_row_local = 1, nrow_local
580 DO j_col_local = 1, ncol_local
582 j_col = col_indices(j_col_local)
584 tau_e = abs(tau*0.5_dp*(bs_env%eigenval_scf_Gamma(j_col, ispin) - bs_env%e_fermi(ispin)))
586 IF (tau_e < bs_env%stabilize_exp)
THEN
587 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = &
588 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local)*exp(-tau_e)
590 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = 0.0_dp
593 IF ((occ .AND. j_col > homo) .OR. (vir .AND. j_col <= homo))
THEN
594 bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = 0.0_dp
600 CALL parallel_gemm(transa=
"N", transb=
"T", m=n_mo, n=n_mo, k=n_mo, alpha=1.0_dp, &
601 matrix_a=bs_env%fm_work_mo(1), matrix_b=bs_env%fm_work_mo(1), &
602 beta=0.0_dp, matrix_c=fm_g_gamma)
604 CALL timestop(handle)
620 TYPE(dbt_type) :: t_3c
621 INTEGER,
DIMENSION(2),
OPTIONAL :: atoms_ao_1, atoms_ao_2, atoms_ri
623 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_3c_integrals'
626 TYPE(dbt_type),
ALLOCATABLE,
DIMENSION(:, :) :: t_3c_array
628 CALL timeset(routinen, handle)
633 ALLOCATE (t_3c_array(1, 1))
634 CALL dbt_create(t_3c, t_3c_array(1, 1))
640 int_eps=bs_env%eps_filter, &
641 basis_i=bs_env%basis_set_RI, &
642 basis_j=bs_env%basis_set_AO, &
643 basis_k=bs_env%basis_set_AO, &
644 potential_parameter=bs_env%ri_metric, &
646 bounds_j=atoms_ao_1, &
647 bounds_k=atoms_ao_2, &
648 desymmetrize=.false.)
650 CALL dbt_filter(t_3c_array(1, 1), bs_env%eps_filter)
652 CALL dbt_copy(t_3c_array(1, 1), t_3c, move_data=.true.)
654 CALL dbt_destroy(t_3c_array(1, 1))
655 DEALLOCATE (t_3c_array)
657 CALL timestop(handle)
671 SUBROUTINE g_times_3c(t_3c_for_G, t_G, t_M, bs_env, atoms_AO_1, atoms_AO_2, atoms_IL)
672 TYPE(dbt_type) :: t_3c_for_g, t_g, t_m
674 INTEGER,
DIMENSION(2) :: atoms_ao_1, atoms_ao_2, atoms_il
676 CHARACTER(LEN=*),
PARAMETER :: routinen =
'G_times_3c'
679 INTEGER(KIND=int_8) :: flop
680 INTEGER,
DIMENSION(2) :: bounds_ao_1, bounds_il
681 INTEGER,
DIMENSION(2, 2) :: bounds_comb
683 CALL timeset(routinen, handle)
694 CALL get_bounds_from_atoms(bounds_il, [1, bs_env%n_atom], atoms_ao_2, &
695 bs_env%min_AO_idx_from_RI_AO_atom, &
696 bs_env%max_AO_idx_from_RI_AO_atom, &
698 indices_3_start=bs_env%i_ao_start_from_atom, &
699 indices_3_end=bs_env%i_ao_end_from_atom)
702 CALL get_bounds_from_atoms(bounds_comb(:, 1), atoms_il, atoms_ao_2, &
703 bs_env%min_RI_idx_from_AO_AO_atom, &
704 bs_env%max_RI_idx_from_AO_AO_atom)
707 CALL get_bounds_from_atoms(bounds_comb(:, 2), [1, bs_env%n_atom], atoms_il, &
708 bs_env%min_AO_idx_from_RI_AO_atom, &
709 bs_env%max_AO_idx_from_RI_AO_atom, &
710 atoms_3=atoms_ao_2, &
711 indices_3_start=bs_env%i_ao_start_from_atom, &
712 indices_3_end=bs_env%i_ao_end_from_atom)
715 bounds_ao_1(1:2) = [bs_env%i_ao_start_from_atom(atoms_ao_1(1)), &
716 bs_env%i_ao_end_from_atom(atoms_ao_1(2))]
718 IF (bounds_il(1) > bounds_il(2) .OR. bounds_comb(1, 2) > bounds_comb(2, 2))
THEN
721 CALL dbt_contract(alpha=1.0_dp, &
722 tensor_1=t_3c_for_g, &
726 contract_1=[3], notcontract_1=[1, 2], map_1=[1, 2], &
727 contract_2=[2], notcontract_2=[1], map_2=[3], &
728 bounds_1=bounds_il, &
729 bounds_2=bounds_comb, &
730 bounds_3=bounds_ao_1, &
732 filter_eps=bs_env%eps_filter, &
733 unit_nr=bs_env%unit_nr_contract, &
734 log_verbose=bs_env%print_contract_verbose)
737 CALL dbt_clear(t_3c_for_g)
739 CALL timestop(handle)
741 END SUBROUTINE g_times_3c
751 SUBROUTINE check_dist(atoms_1, atoms_2, qs_env, bs_env, dist_too_long)
752 INTEGER,
DIMENSION(2) :: atoms_1, atoms_2
755 LOGICAL :: dist_too_long
757 CHARACTER(LEN=*),
PARAMETER :: routinen =
'check_dist'
759 INTEGER :: atom_1, atom_2, handle
760 REAL(
dp) :: abs_rab, min_dist_ao_atoms
761 REAL(kind=
dp),
DIMENSION(3) :: rab
765 CALL timeset(routinen, handle)
767 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
769 min_dist_ao_atoms = huge(1.0_dp)
770 DO atom_1 = atoms_1(1), atoms_1(2)
771 DO atom_2 = atoms_2(1), atoms_2(2)
772 rab =
pbc(particle_set(atom_1)%r(1:3), particle_set(atom_2)%r(1:3), cell)
774 abs_rab = sqrt(rab(1)**2 + rab(2)**2 + rab(3)**2)
776 min_dist_ao_atoms = min(min_dist_ao_atoms, abs_rab)
780 dist_too_long = (min_dist_ao_atoms > bs_env%max_dist_AO_atoms)
782 CALL timestop(handle)
784 END SUBROUTINE check_dist
793 SUBROUTINE get_w_mic(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
796 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
797 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
799 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_W_MIC'
803 CALL timeset(routinen, handle)
805 IF (bs_env%all_W_exist)
THEN
806 CALL read_w_mic_time(bs_env, mat_chi_gamma_tau, fm_w_mic_time)
808 CALL compute_w_mic(bs_env, qs_env, mat_chi_gamma_tau, fm_w_mic_time)
811 CALL timestop(handle)
822 SUBROUTINE compute_v_k_by_lattice_sum(bs_env, qs_env, fm_V_kp, ikp_batch)
825 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
828 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_V_k_by_lattice_sum'
830 INTEGER :: handle, ikp, ikp_end, ikp_start, &
831 nkp_chi_eps_w_batch, re_im
834 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_v_kp
836 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
838 CALL timeset(routinen, handle)
840 nkp_chi_eps_w_batch = bs_env%nkp_chi_eps_W_batch
842 ikp_start = (ikp_batch - 1)*bs_env%nkp_chi_eps_W_batch + 1
843 ikp_end = min(ikp_batch*bs_env%nkp_chi_eps_W_batch, bs_env%kpoints_chi_eps_W%nkp)
846 ALLOCATE (mat_v_kp(ikp_start:ikp_end, 2))
849 DO ikp = ikp_start, ikp_end
850 NULLIFY (mat_v_kp(ikp, re_im)%matrix)
851 ALLOCATE (mat_v_kp(ikp, re_im)%matrix)
852 CALL dbcsr_create(mat_v_kp(ikp, re_im)%matrix, template=bs_env%mat_RI_RI%matrix)
854 CALL dbcsr_set(mat_v_kp(ikp, re_im)%matrix, 0.0_dp)
859 particle_set=particle_set, &
861 qs_kind_set=qs_kind_set, &
862 atomic_kind_set=atomic_kind_set)
864 IF (ikp_end <= bs_env%nkp_chi_eps_W_orig)
THEN
867 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
869 ELSE IF (ikp_start > bs_env%nkp_chi_eps_W_orig .AND. &
870 ikp_end <= bs_env%nkp_chi_eps_W_orig_plus_extra)
THEN
873 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_extra
877 cpabort(
"Error with k-point parallelization.")
882 bs_env%kpoints_chi_eps_W, &
883 basis_type=
"RI_AUX", &
885 particle_set=particle_set, &
886 qs_kind_set=qs_kind_set, &
887 atomic_kind_set=atomic_kind_set, &
888 size_lattice_sum=bs_env%size_lattice_sum_V, &
890 ikp_start=ikp_start, &
893 bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
895 ALLOCATE (fm_v_kp(ikp_start:ikp_end, 2))
897 DO ikp = ikp_start, ikp_end
898 CALL cp_fm_create(fm_v_kp(ikp, re_im), bs_env%fm_RI_RI%matrix_struct)
903 DEALLOCATE (mat_v_kp)
905 CALL timestop(handle)
907 END SUBROUTINE compute_v_k_by_lattice_sum
918 SUBROUTINE compute_minvvsqrt_vsqrt(bs_env, qs_env, fm_V_kp, cfm_V_sqrt_ikp, &
919 cfm_M_inv_V_sqrt_ikp, ikp)
922 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
923 TYPE(
cp_cfm_type) :: cfm_v_sqrt_ikp, cfm_m_inv_v_sqrt_ikp
926 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_MinvVsqrt_Vsqrt'
928 INTEGER :: handle, info, n_ri
930 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_m_ikp
932 CALL timeset(routinen, handle)
938 n_ri, bs_env%ri_metric, do_kpoints=.true., &
939 kpoints=bs_env%kpoints_chi_eps_W, &
940 regularization_ri=bs_env%regularization_RI, ikp_ext=ikp, &
941 do_build_cell_index=(ikp == 1))
944 CALL cp_cfm_create(cfm_v_sqrt_ikp, fm_v_kp(ikp, 1)%matrix_struct)
945 CALL cp_cfm_create(cfm_m_inv_v_sqrt_ikp, fm_v_kp(ikp, 1)%matrix_struct)
947 CALL cp_cfm_create(cfm_m_inv_ikp, fm_v_kp(ikp, 1)%matrix_struct)
949 CALL cp_fm_to_cfm(fm_m_ikp(1, 1), fm_m_ikp(1, 2), cfm_m_inv_ikp)
950 CALL cp_fm_to_cfm(fm_v_kp(ikp, 1), fm_v_kp(ikp, 2), cfm_v_sqrt_ikp)
966 CALL cp_cfm_power(cfm_work, threshold=bs_env%eps_eigval_mat_RI, exponent=-1.0_dp)
975 CALL clean_lower_part(cfm_v_sqrt_ikp)
978 CALL cp_cfm_power(cfm_work, threshold=0.0_dp, exponent=0.5_dp)
984 CALL parallel_gemm(
"N",
"C", n_ri, n_ri, n_ri,
z_one, cfm_m_inv_ikp, cfm_v_sqrt_ikp, &
985 z_zero, cfm_m_inv_v_sqrt_ikp)
989 CALL timestop(handle)
991 END SUBROUTINE compute_minvvsqrt_vsqrt
999 SUBROUTINE read_w_mic_time(bs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
1001 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1002 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1004 CHARACTER(LEN=*),
PARAMETER :: routinen =
'read_W_MIC_time'
1006 INTEGER :: handle, i_t
1009 CALL timeset(routinen, handle)
1012 CALL create_fm_w_mic_time(bs_env, fm_w_mic_time)
1014 DO i_t = 1, bs_env%num_time_freq_points
1018 CALL fm_read(fm_w_mic_time(i_t), bs_env, bs_env%W_time_name, i_t)
1020 IF (bs_env%unit_nr > 0)
THEN
1021 WRITE (bs_env%unit_nr,
'(T2,A,I5,A,I3,A,F10.1,A)') &
1022 τ
'Read W^MIC(i) from file for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1028 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1033 CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
1035 CALL fm_read(bs_env%fm_W_MIC_freq_zero, bs_env,
"W_freq_rtp", 0)
1036 IF (bs_env%unit_nr > 0)
THEN
1037 WRITE (bs_env%unit_nr,
'(T2,A,I3,A,I3,A,F10.1,A)') &
1038 'Read W^MIC(f=0) from file for freq. point ', 1,
' /', 1, &
1043 CALL timestop(handle)
1045 END SUBROUTINE read_w_mic_time
1054 SUBROUTINE compute_w_mic(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
1057 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1058 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1060 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_W_MIC'
1062 INTEGER :: handle, i_t, ikp, ikp_batch, &
1065 TYPE(
cp_cfm_type) :: cfm_m_inv_v_sqrt_ikp, cfm_v_sqrt_ikp
1066 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_v_kp
1068 CALL timeset(routinen, handle)
1070 CALL create_fm_w_mic_time(bs_env, fm_w_mic_time)
1072 DO ikp_batch = 1, bs_env%num_chi_eps_W_batches
1077 CALL compute_v_k_by_lattice_sum(bs_env, qs_env, fm_v_kp, ikp_batch)
1079 DO ikp_in_batch = 1, bs_env%nkp_chi_eps_W_batch
1081 ikp = (ikp_batch - 1)*bs_env%nkp_chi_eps_W_batch + ikp_in_batch
1083 IF (ikp > bs_env%nkp_chi_eps_W_orig_plus_extra) cycle
1085 CALL compute_minvvsqrt_vsqrt(bs_env, qs_env, fm_v_kp, &
1086 cfm_v_sqrt_ikp, cfm_m_inv_v_sqrt_ikp, ikp)
1088 CALL bs_env%para_env%sync()
1092 DO j_w = 1, bs_env%num_time_freq_points
1095 IF (bs_env%approx_kp_extrapol .AND. j_w > 1 .AND. &
1096 ikp > bs_env%nkp_chi_eps_W_orig) cycle
1098 CALL compute_fm_w_mic_freq_j(bs_env, qs_env, bs_env%fm_W_MIC_freq, j_w, ikp, &
1099 mat_chi_gamma_tau, cfm_m_inv_v_sqrt_ikp, &
1103 CALL fourier_transform_w_to_t(bs_env, fm_w_mic_time, bs_env%fm_W_MIC_freq, j_w)
1109 DEALLOCATE (fm_v_kp)
1111 IF (bs_env%unit_nr > 0)
THEN
1112 WRITE (bs_env%unit_nr,
'(T2,A,I12,A,I3,A,F10.1,A)') &
1113 τ
'Computed W(i,k) for k-point batch', &
1114 ikp_batch,
' /', bs_env%num_chi_eps_W_batches, &
1120 IF (bs_env%approx_kp_extrapol)
THEN
1121 CALL apply_extrapol_factor(bs_env, fm_w_mic_time)
1127 DO i_t = 1, bs_env%num_time_freq_points
1128 CALL fm_write(fm_w_mic_time(i_t), i_t, bs_env%W_time_name, qs_env)
1138 CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
1142 DO i_t = 1, bs_env%num_time_freq_points
1145 bs_env%imag_time_weights_freq_zero(i_t), fm_w_mic_time(i_t))
1148 CALL fm_write(bs_env%fm_W_MIC_freq_zero, 0,
"W_freq_rtp", qs_env)
1150 IF (bs_env%unit_nr > 0)
THEN
1151 WRITE (bs_env%unit_nr,
'(T2,A,I11,A,I3,A,F10.1,A)') &
1152 'Computed W(f=0,k) for k-point batch', &
1158 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1160 CALL timestop(handle)
1162 END SUBROUTINE compute_w_mic
1175 SUBROUTINE compute_fm_w_mic_freq_j(bs_env, qs_env, fm_W_MIC_freq_j, j_w, ikp, mat_chi_Gamma_tau, &
1176 cfm_M_inv_V_sqrt_ikp, cfm_V_sqrt_ikp)
1181 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1182 TYPE(
cp_cfm_type) :: cfm_m_inv_v_sqrt_ikp, cfm_v_sqrt_ikp
1184 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_fm_W_MIC_freq_j'
1187 TYPE(
cp_cfm_type) :: cfm_chi_ikp_freq_j, cfm_w_ikp_freq_j
1189 CALL timeset(routinen, handle)
1192 CALL compute_fm_chi_gamma_freq(bs_env, bs_env%fm_chi_Gamma_freq, j_w, mat_chi_gamma_tau)
1198 ikp, qs_env, bs_env%kpoints_chi_eps_W,
"RI_AUX")
1201 CALL cp_cfm_power(cfm_chi_ikp_freq_j, threshold=0.0_dp, exponent=1.0_dp)
1205 CALL compute_cfm_w_ikp_freq_j(bs_env, cfm_chi_ikp_freq_j, cfm_v_sqrt_ikp, &
1206 cfm_m_inv_v_sqrt_ikp, cfm_w_ikp_freq_j)
1209 SELECT CASE (bs_env%approx_kp_extrapol)
1213 bs_env%kpoints_chi_eps_W,
"RI_AUX")
1224 cfm_w_ikp_freq_j, ikp, bs_env%kpoints_chi_eps_W, &
1227 IF (ikp <= bs_env%nkp_chi_eps_W_orig)
THEN
1229 cfm_w_ikp_freq_j, ikp, bs_env%kpoints_chi_eps_W, &
1230 "RI_AUX", wkp_ext=bs_env%wkp_orig)
1236 IF (ikp <= bs_env%nkp_chi_eps_W_orig)
THEN
1238 ikp, bs_env%kpoints_chi_eps_W,
"RI_AUX", &
1239 wkp_ext=bs_env%wkp_orig)
1245 CALL timestop(handle)
1247 END SUBROUTINE compute_fm_w_mic_freq_j
1253 SUBROUTINE clean_lower_part(cfm_mat)
1256 CHARACTER(LEN=*),
PARAMETER :: routinen =
'clean_lower_part'
1258 INTEGER :: handle, i_row, j_col, j_global, &
1259 ncol_local, nrow_local
1260 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1262 CALL timeset(routinen, handle)
1265 nrow_local=nrow_local, ncol_local=ncol_local, &
1266 row_indices=row_indices, col_indices=col_indices)
1268 DO j_col = 1, ncol_local
1269 j_global = col_indices(j_col)
1270 DO i_row = 1, nrow_local
1271 IF (j_global < row_indices(i_row)) cfm_mat%local_data(i_row, j_col) =
z_zero
1275 CALL timestop(handle)
1277 END SUBROUTINE clean_lower_part
1284 SUBROUTINE apply_extrapol_factor(bs_env, fm_W_MIC_time)
1286 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1288 CHARACTER(LEN=*),
PARAMETER :: routinen =
'apply_extrapol_factor'
1290 INTEGER :: handle, i, i_t, j, ncol_local, nrow_local
1291 REAL(kind=
dp) :: extrapol_factor, w_extra_1, w_no_extra_1
1293 CALL timeset(routinen, handle)
1295 CALL cp_fm_get_info(matrix=fm_w_mic_time(1), nrow_local=nrow_local, ncol_local=ncol_local)
1297 DO i_t = 1, bs_env%num_time_freq_points
1298 DO j = 1, ncol_local
1299 DO i = 1, nrow_local
1301 w_extra_1 = bs_env%fm_W_MIC_freq_1_extra%local_data(i, j)
1302 w_no_extra_1 = bs_env%fm_W_MIC_freq_1_no_extra%local_data(i, j)
1304 IF (abs(w_no_extra_1) > 1.0e-13)
THEN
1305 extrapol_factor = abs(w_extra_1/w_no_extra_1)
1307 extrapol_factor = 1.0_dp
1311 IF (extrapol_factor > 10.0_dp) extrapol_factor = 1.0_dp
1313 fm_w_mic_time(i_t)%local_data(i, j) = fm_w_mic_time(i_t)%local_data(i, j) &
1319 CALL timestop(handle)
1321 END SUBROUTINE apply_extrapol_factor
1330 SUBROUTINE compute_fm_chi_gamma_freq(bs_env, fm_chi_Gamma_freq, j_w, mat_chi_Gamma_tau)
1334 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_chi_gamma_tau
1336 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_fm_chi_Gamma_freq'
1338 INTEGER :: handle, i_t
1339 REAL(kind=
dp) :: freq_j, time_i, weight_ij
1341 CALL timeset(routinen, handle)
1343 CALL dbcsr_set(bs_env%mat_RI_RI%matrix, 0.0_dp)
1345 freq_j = bs_env%imag_freq_points(j_w)
1347 DO i_t = 1, bs_env%num_time_freq_points
1349 time_i = bs_env%imag_time_points(i_t)
1350 weight_ij = bs_env%weights_cos_t_to_w(j_w, i_t)
1353 CALL dbcsr_add(bs_env%mat_RI_RI%matrix, mat_chi_gamma_tau(i_t)%matrix, &
1354 1.0_dp, cos(time_i*freq_j)*weight_ij)
1360 CALL timestop(handle)
1362 END SUBROUTINE compute_fm_chi_gamma_freq
1373 SUBROUTINE mat_ikp_from_mat_gamma(mat_ikp_re, mat_ikp_im, mat_Gamma, kpoints, ikp, qs_env)
1374 TYPE(
dbcsr_type) :: mat_ikp_re, mat_ikp_im, mat_gamma
1379 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mat_ikp_from_mat_Gamma'
1381 INTEGER :: col, handle, i_cell, j_cell, num_cells, &
1383 INTEGER,
DIMENSION(:, :),
POINTER :: index_to_cell
1384 LOGICAL :: f, i_cell_is_the_minimum_image_cell
1385 REAL(kind=
dp) :: abs_rab_cell_i, abs_rab_cell_j, arg
1386 REAL(kind=
dp),
DIMENSION(3) :: cell_vector, cell_vector_j, rab_cell_i, &
1388 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat
1389 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block_im, block_re, data_block
1394 CALL timeset(routinen, handle)
1402 NULLIFY (cell, particle_set)
1403 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
1406 index_to_cell => kpoints%index_to_cell
1408 num_cells =
SIZE(index_to_cell, 2)
1410 DO i_cell = 1, num_cells
1416 cell_vector(1:3) = matmul(hmat, real(index_to_cell(1:3, i_cell),
dp))
1418 rab_cell_i(1:3) =
pbc(particle_set(row)%r(1:3), cell) - &
1419 (
pbc(particle_set(col)%r(1:3), cell) + cell_vector(1:3))
1420 abs_rab_cell_i = sqrt(rab_cell_i(1)**2 + rab_cell_i(2)**2 + rab_cell_i(3)**2)
1423 i_cell_is_the_minimum_image_cell = .true.
1424 DO j_cell = 1, num_cells
1425 cell_vector_j(1:3) = matmul(hmat, real(index_to_cell(1:3, j_cell),
dp))
1426 rab_cell_j(1:3) =
pbc(particle_set(row)%r(1:3), cell) - &
1427 (
pbc(particle_set(col)%r(1:3), cell) + cell_vector_j(1:3))
1428 abs_rab_cell_j = sqrt(rab_cell_j(1)**2 + rab_cell_j(2)**2 + rab_cell_j(3)**2)
1430 IF (abs_rab_cell_i > abs_rab_cell_j + 1.0e-6_dp)
THEN
1431 i_cell_is_the_minimum_image_cell = .false.
1435 IF (i_cell_is_the_minimum_image_cell)
THEN
1436 NULLIFY (block_re, block_im)
1437 CALL dbcsr_get_block_p(matrix=mat_ikp_re, row=row, col=col, block=block_re, found=f)
1438 CALL dbcsr_get_block_p(matrix=mat_ikp_im, row=row, col=col, block=block_im, found=f)
1439 cpassert(all(abs(block_re) < 1.0e-10_dp))
1440 cpassert(all(abs(block_im) < 1.0e-10_dp))
1442 arg = real(index_to_cell(1, i_cell),
dp)*kpoints%xkp(1, ikp) + &
1443 REAL(index_to_cell(2, i_cell),
dp)*kpoints%xkp(2, ikp) + &
1444 REAL(index_to_cell(3, i_cell),
dp)*kpoints%xkp(3, ikp)
1446 block_re(:, :) = cos(
twopi*arg)*data_block(:, :)
1447 block_im(:, :) = sin(
twopi*arg)*data_block(:, :)
1455 CALL timestop(handle)
1457 END SUBROUTINE mat_ikp_from_mat_gamma
1467 SUBROUTINE compute_cfm_w_ikp_freq_j(bs_env, cfm_chi_ikp_freq_j, cfm_V_sqrt_ikp, &
1468 cfm_M_inv_V_sqrt_ikp, cfm_W_ikp_freq_j)
1471 TYPE(
cp_cfm_type) :: cfm_chi_ikp_freq_j, cfm_v_sqrt_ikp, &
1472 cfm_m_inv_v_sqrt_ikp, cfm_w_ikp_freq_j
1474 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_cfm_W_ikp_freq_j'
1476 INTEGER :: handle, info, n_ri
1479 CALL timeset(routinen, handle)
1481 CALL cp_cfm_create(cfm_work, cfm_chi_ikp_freq_j%matrix_struct)
1488 cfm_chi_ikp_freq_j, cfm_m_inv_v_sqrt_ikp,
z_zero, cfm_work)
1492 CALL cp_cfm_create(cfm_eps_ikp_freq_j, cfm_work%matrix_struct)
1494 cfm_m_inv_v_sqrt_ikp, cfm_work,
z_zero, cfm_eps_ikp_freq_j)
1497 CALL cfm_add_on_diag(cfm_eps_ikp_freq_j,
z_one)
1510 CALL cfm_add_on_diag(cfm_eps_ikp_freq_j, -
z_one)
1513 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri,
z_one, cfm_eps_ikp_freq_j, cfm_v_sqrt_ikp, &
1517 CALL cp_cfm_create(cfm_w_ikp_freq_j, cfm_work%matrix_struct)
1519 z_zero, cfm_w_ikp_freq_j)
1524 CALL timestop(handle)
1526 END SUBROUTINE compute_cfm_w_ikp_freq_j
1533 SUBROUTINE cfm_add_on_diag(cfm, alpha)
1536 COMPLEX(KIND=dp) :: alpha
1538 CHARACTER(LEN=*),
PARAMETER :: routinen =
'cfm_add_on_diag'
1540 INTEGER :: handle, i_row, j_col, j_global, &
1541 ncol_local, nrow_local
1542 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1544 CALL timeset(routinen, handle)
1547 nrow_local=nrow_local, &
1548 ncol_local=ncol_local, &
1549 row_indices=row_indices, &
1550 col_indices=col_indices)
1553 DO j_col = 1, ncol_local
1554 j_global = col_indices(j_col)
1555 DO i_row = 1, nrow_local
1556 IF (j_global == row_indices(i_row))
THEN
1557 cfm%local_data(i_row, j_col) = cfm%local_data(i_row, j_col) + alpha
1562 CALL timestop(handle)
1564 END SUBROUTINE cfm_add_on_diag
1571 SUBROUTINE create_fm_w_mic_time(bs_env, fm_W_MIC_time)
1573 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1575 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_fm_W_MIC_time'
1577 INTEGER :: handle, i_t
1579 CALL timeset(routinen, handle)
1581 ALLOCATE (fm_w_mic_time(bs_env%num_time_freq_points))
1582 DO i_t = 1, bs_env%num_time_freq_points
1583 CALL cp_fm_create(fm_w_mic_time(i_t), bs_env%fm_RI_RI%matrix_struct, set_zero=.true.)
1586 CALL timestop(handle)
1588 END SUBROUTINE create_fm_w_mic_time
1597 SUBROUTINE fourier_transform_w_to_t(bs_env, fm_W_MIC_time, fm_W_MIC_freq_j, j_w)
1599 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1603 CHARACTER(LEN=*),
PARAMETER :: routinen =
'Fourier_transform_w_to_t'
1605 INTEGER :: handle, i_t
1606 REAL(kind=
dp) :: freq_j, time_i, weight_ij
1608 CALL timeset(routinen, handle)
1610 freq_j = bs_env%imag_freq_points(j_w)
1612 DO i_t = 1, bs_env%num_time_freq_points
1614 time_i = bs_env%imag_time_points(i_t)
1615 weight_ij = bs_env%weights_cos_w_to_t(i_t, j_w)
1619 beta=weight_ij*cos(time_i*freq_j), matrix_b=fm_w_mic_freq_j)
1623 CALL timestop(handle)
1625 END SUBROUTINE fourier_transform_w_to_t
1636 TYPE(
cp_fm_type),
DIMENSION(:) :: fm_w_mic_time
1638 CHARACTER(LEN=*),
PARAMETER :: routinen =
'multiply_fm_W_MIC_time_with_Minv_Gamma'
1640 INTEGER :: handle, i_t, n_ri, ndep
1642 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_minv_gamma
1644 CALL timeset(routinen, handle)
1648 CALL cp_fm_create(fm_work, fm_w_mic_time(1)%matrix_struct)
1652 bs_env%ri_metric, do_kpoints=.false.)
1654 CALL cp_fm_power(fm_minv_gamma(1, 1), fm_work, -1.0_dp, 0.0_dp, ndep)
1657 DO i_t = 1,
SIZE(fm_w_mic_time)
1659 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_minv_gamma(1, 1), &
1660 fm_w_mic_time(i_t), 0.0_dp, fm_work)
1662 CALL parallel_gemm(
'N',
'N', n_ri, n_ri, n_ri, 1.0_dp, fm_work, &
1663 fm_minv_gamma(1, 1), 0.0_dp, fm_w_mic_time(i_t))
1670 CALL timestop(handle)
1680 SUBROUTINE get_sigma_x(bs_env, qs_env, fm_Sigma_x_Gamma)
1683 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
1685 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_Sigma_x'
1687 INTEGER :: handle, ispin
1689 CALL timeset(routinen, handle)
1691 ALLOCATE (fm_sigma_x_gamma(bs_env%n_spin))
1692 DO ispin = 1, bs_env%n_spin
1693 CALL cp_fm_create(fm_sigma_x_gamma(ispin), bs_env%fm_s_Gamma%matrix_struct)
1696 IF (bs_env%Sigma_x_exists)
THEN
1697 DO ispin = 1, bs_env%n_spin
1698 CALL fm_read(fm_sigma_x_gamma(ispin), bs_env, bs_env%Sigma_x_name, ispin)
1701 CALL compute_sigma_x(bs_env, qs_env, fm_sigma_x_gamma)
1704 CALL timestop(handle)
1706 END SUBROUTINE get_sigma_x
1714 SUBROUTINE compute_sigma_x(bs_env, qs_env, fm_Sigma_x_Gamma)
1717 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
1719 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_x'
1721 INTEGER :: handle, i_intval_idx, ispin, j_intval_idx
1722 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
1724 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_vtr_gamma
1726 TYPE(dbt_type) :: t_2c_d, t_2c_sigma_x, t_2c_v, t_3c_x_v
1728 CALL timeset(routinen, handle)
1732 CALL dbt_create(bs_env%t_G, t_2c_d)
1733 CALL dbt_create(bs_env%t_W, t_2c_v)
1734 CALL dbt_create(bs_env%t_G, t_2c_sigma_x)
1735 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_v)
1736 CALL dbcsr_create(mat_sigma_x_gamma, template=bs_env%mat_ao_ao%matrix)
1740 bs_env%trunc_coulomb, do_kpoints=.false.)
1745 DO ispin = 1, bs_env%n_spin
1748 CALL g_occ_vir(bs_env, 0.0_dp, bs_env%fm_work_mo(2), ispin, occ=.true., vir=.false.)
1751 bs_env%mat_ao_ao_tensor%matrix, t_2c_d, bs_env, &
1752 bs_env%atoms_i_t_group)
1755 bs_env%mat_RI_RI_tensor%matrix, t_2c_v, bs_env, &
1756 bs_env%atoms_j_t_group)
1760 DO i_intval_idx = 1, bs_env%n_intervals_i
1761 DO j_intval_idx = 1, bs_env%n_intervals_j
1762 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
1763 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
1767 CALL compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_v, t_2c_v)
1771 CALL contract_to_sigma(t_2c_d, t_3c_x_v, t_2c_sigma_x, i_atoms, j_atoms, &
1772 qs_env, bs_env, occ=.true., vir=.false.)
1778 mat_sigma_x_gamma, bs_env%para_env)
1780 CALL write_matrix(mat_sigma_x_gamma, ispin, bs_env%Sigma_x_name, &
1781 bs_env%fm_work_mo(1), qs_env)
1787 IF (bs_env%unit_nr > 0)
THEN
1788 WRITE (bs_env%unit_nr,
'(T2,A,T55,A,F10.1,A)') &
1789 Σ
'Computed ^x(k=0),',
' Execution time',
m_walltime() - t1,
' s'
1790 WRITE (bs_env%unit_nr,
'(A)')
' '
1794 CALL dbt_destroy(t_2c_d)
1795 CALL dbt_destroy(t_2c_v)
1796 CALL dbt_destroy(t_2c_sigma_x)
1797 CALL dbt_destroy(t_3c_x_v)
1800 CALL timestop(handle)
1802 END SUBROUTINE compute_sigma_x
1811 SUBROUTINE get_sigma_c(bs_env, qs_env, fm_W_MIC_time, fm_Sigma_c_Gamma_time)
1814 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
1815 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
1817 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_Sigma_c'
1819 INTEGER :: handle, i_intval_idx, i_t, ispin, &
1820 j_intval_idx, read_write_index
1821 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
1822 REAL(kind=
dp) :: t1, tau
1823 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
1824 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, &
1825 t_2c_sigma_neg_tau, &
1826 t_2c_sigma_pos_tau, t_2c_w, t_3c_x_w
1828 CALL timeset(routinen, handle)
1830 CALL create_mat_for_sigma_c(bs_env, t_2c_gocc, t_2c_gvir, t_2c_w, t_2c_sigma_neg_tau, &
1831 t_2c_sigma_pos_tau, t_3c_x_w, &
1832 mat_sigma_neg_tau, mat_sigma_pos_tau)
1834 DO i_t = 1, bs_env%num_time_freq_points
1836 DO ispin = 1, bs_env%n_spin
1840 read_write_index = i_t + (ispin - 1)*bs_env%num_time_freq_points
1843 IF (bs_env%Sigma_c_exists(i_t, ispin))
THEN
1844 CALL fm_read(bs_env%fm_work_mo(1), bs_env, bs_env%Sigma_p_name, read_write_index)
1845 CALL copy_fm_to_dbcsr(bs_env%fm_work_mo(1), mat_sigma_pos_tau(i_t, ispin)%matrix, &
1846 keep_sparsity=.false.)
1847 CALL fm_read(bs_env%fm_work_mo(1), bs_env, bs_env%Sigma_n_name, read_write_index)
1848 CALL copy_fm_to_dbcsr(bs_env%fm_work_mo(1), mat_sigma_neg_tau(i_t, ispin)%matrix, &
1849 keep_sparsity=.false.)
1850 IF (bs_env%unit_nr > 0)
THEN
1851 WRITE (bs_env%unit_nr,
'(T2,2A,I3,A,I3,A,F10.1,A)') Στ
'Read ^c(i,k=0) ', &
1852 'from file for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1860 tau = bs_env%imag_time_points(i_t)
1862 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gocc, ispin, occ=.true., vir=.false.)
1863 CALL g_occ_vir(bs_env, tau, bs_env%fm_Gvir, ispin, occ=.false., vir=.true.)
1867 bs_env%mat_ao_ao_tensor%matrix, t_2c_gocc, bs_env, &
1868 bs_env%atoms_i_t_group)
1870 bs_env%mat_ao_ao_tensor%matrix, t_2c_gvir, bs_env, &
1871 bs_env%atoms_i_t_group)
1873 bs_env%mat_RI_RI_tensor%matrix, t_2c_w, bs_env, &
1874 bs_env%atoms_j_t_group)
1878 DO i_intval_idx = 1, bs_env%n_intervals_i
1879 DO j_intval_idx = 1, bs_env%n_intervals_j
1880 i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
1881 j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
1883 IF (bs_env%skip_Sigma_occ(i_intval_idx, j_intval_idx) .AND. &
1884 bs_env%skip_Sigma_vir(i_intval_idx, j_intval_idx))
THEN
1888 bs_env%n_skip_sigma = bs_env%n_skip_sigma + 1
1895 CALL compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_w, t_2c_w)
1899 CALL contract_to_sigma(t_2c_gocc, t_3c_x_w, t_2c_sigma_neg_tau, i_atoms, j_atoms, &
1900 qs_env, bs_env, occ=.true., vir=.false., &
1901 can_skip=bs_env%skip_Sigma_occ(i_intval_idx, j_intval_idx))
1904 CALL contract_to_sigma(t_2c_gvir, t_3c_x_w, t_2c_sigma_pos_tau, i_atoms, j_atoms, &
1905 qs_env, bs_env, occ=.false., vir=.true., &
1906 can_skip=bs_env%skip_Sigma_vir(i_intval_idx, j_intval_idx))
1914 mat_sigma_neg_tau(i_t, ispin)%matrix, bs_env%para_env)
1916 mat_sigma_pos_tau(i_t, ispin)%matrix, bs_env%para_env)
1918 CALL write_matrix(mat_sigma_pos_tau(i_t, ispin)%matrix, read_write_index, &
1919 bs_env%Sigma_p_name, bs_env%fm_work_mo(1), qs_env)
1920 CALL write_matrix(mat_sigma_neg_tau(i_t, ispin)%matrix, read_write_index, &
1921 bs_env%Sigma_n_name, bs_env%fm_work_mo(1), qs_env)
1923 IF (bs_env%unit_nr > 0)
THEN
1924 WRITE (bs_env%unit_nr,
'(T2,A,I10,A,I3,A,F10.1,A)') &
1925 Στ
'Computed ^c(i,k=0) for time point ', i_t,
' /', bs_env%num_time_freq_points, &
1933 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
1936 mat_sigma_pos_tau, mat_sigma_neg_tau)
1938 CALL print_skipping(bs_env)
1940 CALL destroy_mat_sigma_c(t_2c_gocc, t_2c_gvir, t_2c_w, t_2c_sigma_neg_tau, &
1941 t_2c_sigma_pos_tau, t_3c_x_w, fm_w_mic_time, &
1942 mat_sigma_neg_tau, mat_sigma_pos_tau)
1946 CALL timestop(handle)
1948 END SUBROUTINE get_sigma_c
1962 SUBROUTINE create_mat_for_sigma_c(bs_env, t_2c_Gocc, t_2c_Gvir, t_2c_W, t_2c_Sigma_neg_tau, &
1963 t_2c_Sigma_pos_tau, t_3c_x_W, &
1964 mat_Sigma_neg_tau, mat_Sigma_pos_tau)
1967 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_2c_w, &
1968 t_2c_sigma_neg_tau, &
1969 t_2c_sigma_pos_tau, t_3c_x_w
1970 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
1972 CHARACTER(LEN=*),
PARAMETER :: routinen =
'create_mat_for_Sigma_c'
1974 INTEGER :: handle, i_t, ispin
1976 CALL timeset(routinen, handle)
1978 CALL dbt_create(bs_env%t_G, t_2c_gocc)
1979 CALL dbt_create(bs_env%t_G, t_2c_gvir)
1980 CALL dbt_create(bs_env%t_W, t_2c_w)
1981 CALL dbt_create(bs_env%t_G, t_2c_sigma_neg_tau)
1982 CALL dbt_create(bs_env%t_G, t_2c_sigma_pos_tau)
1983 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_w)
1985 NULLIFY (mat_sigma_neg_tau, mat_sigma_pos_tau)
1986 ALLOCATE (mat_sigma_neg_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1987 ALLOCATE (mat_sigma_pos_tau(bs_env%num_time_freq_points, bs_env%n_spin))
1989 DO ispin = 1, bs_env%n_spin
1990 DO i_t = 1, bs_env%num_time_freq_points
1991 ALLOCATE (mat_sigma_neg_tau(i_t, ispin)%matrix)
1992 ALLOCATE (mat_sigma_pos_tau(i_t, ispin)%matrix)
1993 CALL dbcsr_create(mat_sigma_neg_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1994 CALL dbcsr_create(mat_sigma_pos_tau(i_t, ispin)%matrix, template=bs_env%mat_ao_ao%matrix)
1998 CALL timestop(handle)
2000 END SUBROUTINE create_mat_for_sigma_c
2011 SUBROUTINE compute_3c_and_contract_w(qs_env, bs_env, i_atoms, j_atoms, t_3c_x_W, t_2c_W)
2015 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
2016 TYPE(dbt_type) :: t_3c_x_w, t_2c_w
2018 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_3c_and_contract_W'
2020 INTEGER :: handle, ri_intval_idx
2021 INTEGER(KIND=int_8) :: flop
2022 INTEGER,
DIMENSION(2) :: bounds_p, bounds_q, ri_atoms
2023 INTEGER,
DIMENSION(2, 2) :: bounds_ao
2024 TYPE(dbt_type) :: t_3c_for_w, t_3c_x_w_tmp
2026 CALL timeset(routinen, handle)
2028 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_w_tmp)
2029 CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_for_w)
2039 bounds_q(1:2) = [bs_env%i_RI_start_from_atom(j_atoms(1)), &
2040 bs_env%i_RI_end_from_atom(j_atoms(2))]
2042 DO ri_intval_idx = 1, bs_env%n_intervals_inner_loop_atoms
2043 ri_atoms = bs_env%inner_loop_atom_intervals(1:2, ri_intval_idx)
2045 CALL get_bounds_from_atoms(bounds_p, i_atoms, [1, bs_env%n_atom], &
2046 bs_env%min_RI_idx_from_AO_AO_atom, &
2047 bs_env%max_RI_idx_from_AO_AO_atom, &
2049 indices_3_start=bs_env%i_RI_start_from_atom, &
2050 indices_3_end=bs_env%i_RI_end_from_atom)
2053 CALL get_bounds_from_atoms(bounds_ao(:, 2), ri_atoms, i_atoms, &
2054 bs_env%min_AO_idx_from_RI_AO_atom, &
2055 bs_env%max_AO_idx_from_RI_AO_atom)
2057 CALL get_bounds_from_atoms(bounds_ao(:, 1), ri_atoms, [1, bs_env%n_atom], &
2058 bs_env%min_AO_idx_from_RI_AO_atom, &
2059 bs_env%max_AO_idx_from_RI_AO_atom, &
2061 indices_3_start=bs_env%i_ao_start_from_atom, &
2062 indices_3_end=bs_env%i_ao_end_from_atom)
2064 IF (bounds_p(1) > bounds_p(2) .OR. bounds_ao(1, 2) > bounds_ao(2, 2))
THEN
2070 atoms_ao_1=i_atoms, atoms_ri=ri_atoms)
2073 CALL dbt_contract(alpha=1.0_dp, &
2075 tensor_2=t_3c_for_w, &
2077 tensor_3=t_3c_x_w_tmp, &
2078 contract_1=[2], notcontract_1=[1], map_1=[1], &
2079 contract_2=[1], notcontract_2=[2, 3], map_2=[2, 3], &
2080 bounds_1=bounds_p, &
2081 bounds_2=bounds_q, &
2082 bounds_3=bounds_ao, &
2084 move_data=.false., &
2085 filter_eps=bs_env%eps_filter, &
2086 unit_nr=bs_env%unit_nr_contract, &
2087 log_verbose=bs_env%print_contract_verbose)
2092 CALL dbt_copy(t_3c_x_w_tmp, t_3c_x_w, order=[1, 2, 3], move_data=.true.)
2094 CALL dbt_destroy(t_3c_x_w_tmp)
2095 CALL dbt_destroy(t_3c_for_w)
2097 CALL timestop(handle)
2099 END SUBROUTINE compute_3c_and_contract_w
2114 SUBROUTINE contract_to_sigma(t_2c_G, t_3c_x_W, t_2c_Sigma, i_atoms, j_atoms, qs_env, bs_env, &
2116 TYPE(dbt_type) :: t_2c_g, t_3c_x_w, t_2c_sigma
2117 INTEGER,
DIMENSION(2) :: i_atoms, j_atoms
2121 LOGICAL,
OPTIONAL :: can_skip
2123 CHARACTER(LEN=*),
PARAMETER :: routinen =
'contract_to_Sigma'
2125 INTEGER :: handle, inner_loop_atoms_interval_index
2126 INTEGER(KIND=int_8) :: flop
2127 INTEGER,
DIMENSION(2) :: bounds_lambda, bounds_mu, bounds_nu, &
2128 bounds_sigma, il_atoms
2129 INTEGER,
DIMENSION(2, 2) :: bounds_comb
2130 REAL(kind=
dp) :: sign_sigma
2131 TYPE(dbt_type) :: t_3c_for_g, t_3c_x_g, t_3c_x_g_2
2133 CALL timeset(routinen, handle)
2135 cpassert(occ .EQV. (.NOT. vir))
2136 IF (occ) sign_sigma = -1.0_dp
2137 IF (vir) sign_sigma = 1.0_dp
2139 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_g)
2140 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_g)
2141 CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_g_2)
2154 bounds_nu(1:2) = [bs_env%i_ao_start_from_atom(i_atoms(1)), &
2155 bs_env%i_ao_end_from_atom(i_atoms(2))]
2157 DO inner_loop_atoms_interval_index = 1, bs_env%n_intervals_inner_loop_atoms
2158 il_atoms = bs_env%inner_loop_atom_intervals(1:2, inner_loop_atoms_interval_index)
2161 CALL get_bounds_from_atoms(bounds_mu, j_atoms, [1, bs_env%n_atom], &
2162 bs_env%min_AO_idx_from_RI_AO_atom, &
2163 bs_env%max_AO_idx_from_RI_AO_atom, &
2165 indices_3_start=bs_env%i_ao_start_from_atom, &
2166 indices_3_end=bs_env%i_ao_end_from_atom)
2169 CALL get_bounds_from_atoms(bounds_comb(:, 1), il_atoms, [1, bs_env%n_atom], &
2170 bs_env%min_RI_idx_from_AO_AO_atom, &
2171 bs_env%max_RI_idx_from_AO_AO_atom, &
2173 indices_3_start=bs_env%i_RI_start_from_atom, &
2174 indices_3_end=bs_env%i_RI_end_from_atom)
2177 CALL get_bounds_from_atoms(bounds_comb(:, 2), j_atoms, il_atoms, &
2178 bs_env%min_AO_idx_from_RI_AO_atom, &
2179 bs_env%max_AO_idx_from_RI_AO_atom)
2181 IF (bounds_mu(1) > bounds_mu(2) .OR. bounds_comb(1, 1) > bounds_comb(2, 1) .OR. &
2182 bounds_comb(1, 2) > bounds_comb(2, 2))
THEN
2187 atoms_ri=j_atoms, atoms_ao_2=il_atoms)
2189 CALL dbt_contract(alpha=1.0_dp, &
2191 tensor_2=t_3c_for_g, &
2193 tensor_3=t_3c_x_g, &
2194 contract_1=[2], notcontract_1=[1], map_1=[3], &
2195 contract_2=[3], notcontract_2=[1, 2], map_2=[1, 2], &
2196 bounds_1=bounds_mu, &
2197 bounds_2=bounds_nu, &
2198 bounds_3=bounds_comb, &
2200 move_data=.false., &
2201 filter_eps=bs_env%eps_filter, &
2202 unit_nr=bs_env%unit_nr_contract, &
2203 log_verbose=bs_env%print_contract_verbose)
2207 CALL dbt_copy(t_3c_x_g, t_3c_x_g_2, order=[1, 3, 2], move_data=.true.)
2211 bounds_comb(1:2, 1) = [bs_env%i_RI_start_from_atom(j_atoms(1)), &
2212 bs_env%i_RI_end_from_atom(j_atoms(2))]
2213 bounds_comb(1:2, 2) = bounds_nu(1:2)
2215 CALL get_bounds_from_atoms(bounds_lambda, j_atoms, [1, bs_env%n_atom], &
2216 bs_env%min_AO_idx_from_RI_AO_atom, &
2217 bs_env%max_AO_idx_from_RI_AO_atom)
2218 CALL get_bounds_from_atoms(bounds_sigma, [1, bs_env%n_atom], i_atoms, &
2219 bs_env%min_AO_idx_from_RI_AO_atom, &
2220 bs_env%max_AO_idx_from_RI_AO_atom)
2222 IF (bounds_sigma(1) > bounds_sigma(2) .OR. bounds_lambda(1) > bounds_lambda(2))
THEN
2225 CALL dbt_contract(alpha=sign_sigma, &
2226 tensor_1=t_3c_x_w, &
2227 tensor_2=t_3c_x_g_2, &
2229 tensor_3=t_2c_sigma, &
2230 contract_1=[1, 2], notcontract_1=[3], map_1=[1], &
2231 contract_2=[1, 2], notcontract_2=[3], map_2=[2], &
2232 bounds_1=bounds_comb, &
2233 bounds_2=bounds_sigma, &
2234 bounds_3=bounds_lambda, &
2235 filter_eps=bs_env%eps_filter, move_data=.false., flop=flop, &
2236 unit_nr=bs_env%unit_nr_contract, &
2237 log_verbose=bs_env%print_contract_verbose)
2240 IF (
PRESENT(can_skip))
THEN
2241 IF (flop == 0_int_8) can_skip = .true.
2244 CALL dbt_destroy(t_3c_for_g)
2245 CALL dbt_destroy(t_3c_x_g)
2246 CALL dbt_destroy(t_3c_x_g_2)
2248 CALL timestop(handle)
2250 END SUBROUTINE contract_to_sigma
2260 mat_Sigma_pos_tau, mat_Sigma_neg_tau)
2262 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
2264 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_pos_tau, mat_sigma_neg_tau
2266 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fill_fm_Sigma_c_Gamma_time'
2268 INTEGER :: handle, i_t, ispin, pos_neg
2270 CALL timeset(routinen, handle)
2272 ALLOCATE (fm_sigma_c_gamma_time(bs_env%num_time_freq_points, 2, bs_env%n_spin))
2273 DO ispin = 1, bs_env%n_spin
2274 DO i_t = 1, bs_env%num_time_freq_points
2276 CALL cp_fm_create(fm_sigma_c_gamma_time(i_t, pos_neg, ispin), &
2277 bs_env%fm_s_Gamma%matrix_struct)
2280 fm_sigma_c_gamma_time(i_t, 1, ispin))
2282 fm_sigma_c_gamma_time(i_t, 2, ispin))
2286 CALL timestop(handle)
2294 SUBROUTINE print_skipping(bs_env)
2298 CHARACTER(LEN=*),
PARAMETER :: routinen =
'print_skipping'
2300 INTEGER :: handle, n_pairs
2302 CALL timeset(routinen, handle)
2304 n_pairs = bs_env%n_intervals_i*bs_env%n_intervals_j*bs_env%n_spin
2306 CALL bs_env%para_env_tensor%sum(bs_env%n_skip_sigma)
2307 CALL bs_env%para_env_tensor%sum(bs_env%n_skip_chi)
2308 CALL bs_env%para_env_tensor%sum(n_pairs)
2310 IF (bs_env%unit_nr > 0)
THEN
2311 WRITE (bs_env%unit_nr,
'(T2,A,T74,F7.1,A)') &
2312 Στ
'Sparsity of ^c(i,k=0): Percentage of skipped atom pairs:', &
2313 REAL(100*bs_env%n_skip_sigma, kind=
dp)/real(n_pairs, kind=
dp),
' %'
2314 WRITE (bs_env%unit_nr,
'(T2,A,T74,F7.1,A)') &
2315 χτ
'Sparsity of (i,k=0): Percentage of skipped atom pairs:', &
2316 REAL(100*bs_env%n_skip_chi, kind=
dp)/real(n_pairs, kind=
dp),
' %'
2319 CALL timestop(handle)
2321 END SUBROUTINE print_skipping
2335 SUBROUTINE destroy_mat_sigma_c(t_2c_Gocc, t_2c_Gvir, t_2c_W, t_2c_Sigma_neg_tau, &
2336 t_2c_Sigma_pos_tau, t_3c_x_W, fm_W_MIC_time, &
2337 mat_Sigma_neg_tau, mat_Sigma_pos_tau)
2339 TYPE(dbt_type) :: t_2c_gocc, t_2c_gvir, t_2c_w, &
2340 t_2c_sigma_neg_tau, &
2341 t_2c_sigma_pos_tau, t_3c_x_w
2342 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_mic_time
2343 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_sigma_neg_tau, mat_sigma_pos_tau
2345 CHARACTER(LEN=*),
PARAMETER :: routinen =
'destroy_mat_Sigma_c'
2349 CALL timeset(routinen, handle)
2351 CALL dbt_destroy(t_2c_gocc)
2352 CALL dbt_destroy(t_2c_gvir)
2353 CALL dbt_destroy(t_2c_w)
2354 CALL dbt_destroy(t_2c_sigma_neg_tau)
2355 CALL dbt_destroy(t_2c_sigma_pos_tau)
2356 CALL dbt_destroy(t_3c_x_w)
2361 CALL timestop(handle)
2363 END SUBROUTINE destroy_mat_sigma_c
2372 CHARACTER(LEN=*),
PARAMETER :: routinen =
'delete_unnecessary_files'
2374 CHARACTER(LEN=default_path_length) :: f_chi, f_w_t, prefix
2375 INTEGER :: handle, i_t
2377 CALL timeset(routinen, handle)
2379 prefix = bs_env%prefix
2381 DO i_t = 1, bs_env%num_time_freq_points
2384 WRITE (f_chi,
'(3A,I1,A)') trim(prefix), bs_env%chi_name,
"_00", i_t,
".matrix"
2385 WRITE (f_w_t,
'(3A,I1,A)') trim(prefix), bs_env%W_time_name,
"_00", i_t,
".matrix"
2386 ELSE IF (i_t < 100)
THEN
2387 WRITE (f_chi,
'(3A,I2,A)') trim(prefix), bs_env%chi_name,
"_0", i_t,
".matrix"
2388 WRITE (f_w_t,
'(3A,I2,A)') trim(prefix), bs_env%W_time_name,
"_0", i_t,
".matrix"
2390 cpabort(
'Please implement more than 99 time/frequency points.')
2393 CALL safe_delete(f_chi, bs_env)
2394 CALL safe_delete(f_w_t, bs_env)
2398 CALL timestop(handle)
2407 SUBROUTINE safe_delete(filename, bs_env)
2408 CHARACTER(LEN=*) :: filename
2411 CHARACTER(LEN=*),
PARAMETER :: routinen =
'safe_delete'
2416 CALL timeset(routinen, handle)
2418 IF (bs_env%para_env%mepos == 0)
THEN
2425 CALL timestop(handle)
2427 END SUBROUTINE safe_delete
2440 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
2441 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
2443 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_QP_energies'
2445 INTEGER :: handle, ikp, ispin, j_t
2446 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: sigma_x_ikp_n, v_xc_ikp_n
2447 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: sigma_c_ikp_n_freq, sigma_c_ikp_n_time
2448 TYPE(
cp_cfm_type) :: cfm_ks_ikp, cfm_mos_ikp, cfm_s_ikp, &
2449 cfm_sigma_x_ikp, cfm_work_ikp
2451 CALL timeset(routinen, handle)
2453 CALL cp_cfm_create(cfm_mos_ikp, bs_env%fm_s_Gamma%matrix_struct)
2454 CALL cp_cfm_create(cfm_work_ikp, bs_env%fm_s_Gamma%matrix_struct)
2456 ALLOCATE (v_xc_ikp_n(bs_env%n_ao), sigma_x_ikp_n(bs_env%n_ao))
2457 ALLOCATE (sigma_c_ikp_n_time(bs_env%n_ao, bs_env%num_time_freq_points, 2))
2458 ALLOCATE (sigma_c_ikp_n_freq(bs_env%n_ao, bs_env%num_time_freq_points, 2))
2460 DO ispin = 1, bs_env%n_spin
2462 DO ikp = 1, bs_env%nkp_bs_and_DOS
2466 ikp, qs_env, bs_env%kpoints_DOS,
"ORB")
2470 ikp, qs_env, bs_env%kpoints_DOS,
"ORB")
2473 CALL cp_cfm_geeig(cfm_ks_ikp, cfm_s_ikp, cfm_mos_ikp, &
2474 bs_env%eigenval_scf(:, ikp, ispin), cfm_work_ikp)
2477 CALL to_ikp_and_mo(v_xc_ikp_n, bs_env%fm_V_xc_Gamma(ispin), &
2478 ikp, qs_env, bs_env, cfm_mos_ikp)
2481 CALL to_ikp_and_mo(sigma_x_ikp_n, fm_sigma_x_gamma(ispin), &
2482 ikp, qs_env, bs_env, cfm_mos_ikp)
2485 DO j_t = 1, bs_env%num_time_freq_points
2486 CALL to_ikp_and_mo(sigma_c_ikp_n_time(:, j_t, 1), &
2487 fm_sigma_c_gamma_time(j_t, 1, ispin), &
2488 ikp, qs_env, bs_env, cfm_mos_ikp)
2489 CALL to_ikp_and_mo(sigma_c_ikp_n_time(:, j_t, 2), &
2490 fm_sigma_c_gamma_time(j_t, 2, ispin), &
2491 ikp, qs_env, bs_env, cfm_mos_ikp)
2495 CALL time_to_freq(bs_env, sigma_c_ikp_n_time, sigma_c_ikp_n_freq, ispin)
2500 bs_env%eigenval_scf(:, ikp, ispin), ikp, ispin)
2516 CALL timestop(handle)
2529 SUBROUTINE to_ikp_and_mo(array_ikp_n, fm_Gamma, ikp, qs_env, bs_env, cfm_mos_ikp)
2531 REAL(kind=
dp),
DIMENSION(:) :: array_ikp_n
2538 CHARACTER(LEN=*),
PARAMETER :: routinen =
'to_ikp_and_mo'
2543 CALL timeset(routinen, handle)
2545 CALL cp_fm_create(fm_ikp_mo_re, fm_gamma%matrix_struct)
2547 CALL fm_gamma_ao_to_cfm_ikp_mo(fm_gamma, fm_ikp_mo_re, ikp, qs_env, bs_env, cfm_mos_ikp)
2553 CALL timestop(handle)
2555 END SUBROUTINE to_ikp_and_mo
2566 SUBROUTINE fm_gamma_ao_to_cfm_ikp_mo(fm_Gamma, fm_ikp_mo_re, ikp, qs_env, bs_env, cfm_mos_ikp)
2573 CHARACTER(LEN=*),
PARAMETER :: routinen =
'fm_Gamma_ao_to_cfm_ikp_mo'
2575 INTEGER :: handle, nmo
2576 TYPE(
cp_cfm_type) :: cfm_ikp_ao, cfm_ikp_mo, cfm_tmp
2578 CALL timeset(routinen, handle)
2597 CALL timestop(handle)
2599 END SUBROUTINE fm_gamma_ao_to_cfm_ikp_mo
2616 SUBROUTINE get_bounds_from_atoms(bounds_out, atoms_1, atoms_2, indices_min, indices_max, &
2617 atoms_3, indices_3_start, indices_3_end)
2619 INTEGER,
DIMENSION(2),
INTENT(OUT) :: bounds_out
2620 INTEGER,
DIMENSION(2),
INTENT(IN) :: atoms_1, atoms_2
2621 INTEGER,
DIMENSION(:, :) :: indices_min, indices_max
2622 INTEGER,
DIMENSION(2),
INTENT(IN),
OPTIONAL :: atoms_3
2623 INTEGER,
DIMENSION(:),
OPTIONAL :: indices_3_start, indices_3_end
2625 CHARACTER(LEN=*),
PARAMETER :: routinen =
'get_bounds_from_atoms'
2627 INTEGER :: handle, i_at, j_at
2629 CALL timeset(routinen, handle)
2630 bounds_out(1) = huge(0)
2633 DO i_at = atoms_1(1), atoms_1(2)
2634 DO j_at = atoms_2(1), atoms_2(2)
2635 bounds_out(1) = min(bounds_out(1), indices_min(i_at, j_at))
2636 bounds_out(2) = max(bounds_out(2), indices_max(i_at, j_at))
2640 IF (
PRESENT(atoms_3) .AND.
PRESENT(indices_3_start) .AND.
PRESENT(indices_3_end))
THEN
2641 bounds_out(1) = max(bounds_out(1), indices_3_start(atoms_3(1)))
2642 bounds_out(2) = min(bounds_out(2), indices_3_end(atoms_3(2)))
2645 CALL timestop(handle)
2647 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_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 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 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 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_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.