(git:6a2e663)
bse_main.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief Main routines for GW + Bethe-Salpeter for computing electronic excitations
10 !> \par History
11 !> 04.2024 created [Maximilian Graml]
12 ! **************************************************************************************************
13 
14 MODULE bse_main
15 
16  USE bse_full_diag, ONLY: create_a,&
17  create_b,&
28  USE cp_fm_types, ONLY: cp_fm_release,&
29  cp_fm_type
30  USE group_dist_types, ONLY: group_dist_d1_type
31  USE input_constants, ONLY: bse_abba,&
32  bse_both,&
33  bse_fulldiag,&
34  bse_iterdiag,&
35  bse_tda
36  USE kinds, ONLY: dp
37  USE message_passing, ONLY: mp_para_env_type
38  USE mp2_types, ONLY: mp2_type
39 #include "./base/base_uses.f90"
40 
41  IMPLICIT NONE
42 
43  PRIVATE
44 
45  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'bse_main'
46 
47  PUBLIC :: start_bse_calculation
48 
49 CONTAINS
50 
51 ! **************************************************************************************************
52 !> \brief Main subroutine managing BSE calculations
53 !> \param fm_mat_S_ia_bse ...
54 !> \param fm_mat_S_ij_bse ...
55 !> \param fm_mat_S_ab_bse ...
56 !> \param fm_mat_Q_static_bse ...
57 !> \param fm_mat_Q_static_bse_gemm ...
58 !> \param Eigenval ...
59 !> \param homo ...
60 !> \param virtual ...
61 !> \param dimen_RI ...
62 !> \param dimen_RI_red ...
63 !> \param gd_array ...
64 !> \param color_sub ...
65 !> \param mp2_env ...
66 !> \param unit_nr ...
67 ! **************************************************************************************************
68  SUBROUTINE start_bse_calculation(fm_mat_S_ia_bse, fm_mat_S_ij_bse, fm_mat_S_ab_bse, &
69  fm_mat_Q_static_bse, fm_mat_Q_static_bse_gemm, &
70  Eigenval, homo, virtual, dimen_RI, dimen_RI_red, &
71  gd_array, color_sub, mp2_env, unit_nr)
72 
73  TYPE(cp_fm_type), INTENT(IN) :: fm_mat_s_ia_bse, fm_mat_s_ij_bse, &
74  fm_mat_s_ab_bse
75  TYPE(cp_fm_type), INTENT(INOUT) :: fm_mat_q_static_bse, &
76  fm_mat_q_static_bse_gemm
77  REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :), &
78  INTENT(IN) :: eigenval
79  INTEGER, DIMENSION(:), INTENT(IN) :: homo, virtual
80  INTEGER, INTENT(IN) :: dimen_ri, dimen_ri_red
81  TYPE(group_dist_d1_type), INTENT(IN) :: gd_array
82  INTEGER, INTENT(IN) :: color_sub
83  TYPE(mp2_type) :: mp2_env
84  INTEGER, INTENT(IN) :: unit_nr
85 
86  CHARACTER(LEN=*), PARAMETER :: routinen = 'start_bse_calculation'
87 
88  INTEGER :: handle, homo_red, virtual_red
89  LOGICAL :: my_do_abba, my_do_fulldiag, &
90  my_do_iterat_diag, my_do_tda
91  REAL(kind=dp) :: diag_runtime_est
92  REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigenval_reduced
93  REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: b_abq_bse_local, b_bar_iaq_bse_local, &
94  b_bar_ijq_bse_local, b_iaq_bse_local
95  TYPE(cp_fm_type) :: fm_a_bse, fm_b_bse, fm_c_bse, fm_inv_sqrt_a_minus_b, fm_mat_s_ab_trunc, &
96  fm_mat_s_bar_ia_bse, fm_mat_s_bar_ij_bse, fm_mat_s_ia_trunc, fm_mat_s_ij_trunc, &
97  fm_sqrt_a_minus_b
98  TYPE(mp_para_env_type), POINTER :: para_env
99 
100  CALL timeset(routinen, handle)
101 
102  para_env => fm_mat_s_ia_bse%matrix_struct%para_env
103 
104  my_do_fulldiag = .false.
105  my_do_iterat_diag = .false.
106  my_do_tda = .false.
107  my_do_abba = .false.
108  !Method: Iterative or full diagonalization
109  SELECT CASE (mp2_env%ri_g0w0%bse_diag_method)
110  CASE (bse_iterdiag)
111  my_do_iterat_diag = .true.
112  !MG: Basics of the Davidson solver are implemented, but not rigorously checked.
113  cpabort("Iterative BSE not yet implemented")
114  CASE (bse_fulldiag)
115  my_do_fulldiag = .true.
116  END SELECT
117  !Approximation: TDA and/or full ABBA matrix
118  SELECT CASE (mp2_env%ri_g0w0%bse_approx)
119  CASE (bse_tda)
120  my_do_tda = .true.
121  CASE (bse_abba)
122  my_do_abba = .true.
123  CASE (bse_both)
124  my_do_tda = .true.
125  my_do_abba = .true.
126  END SELECT
127 
128  CALL print_bse_start_flag(my_do_tda, my_do_abba, unit_nr)
129 
130  CALL fm_mat_s_ia_bse%matrix_struct%para_env%sync()
131 
132  ! Reduce matrices in case of energy cutoff for occupied and unoccupied in A/B-BSE-matrices
133  CALL truncate_bse_matrices(fm_mat_s_ia_bse, fm_mat_s_ij_bse, fm_mat_s_ab_bse, &
134  fm_mat_s_ia_trunc, fm_mat_s_ij_trunc, fm_mat_s_ab_trunc, &
135  eigenval(:, 1, 1), eigenval_reduced, &
136  homo(1), virtual(1), dimen_ri, unit_nr, &
137  homo_red, virtual_red, &
138  mp2_env)
139  ! \bar{B}^P_rs = \sum_R W_PR B^R_rs where B^R_rs = \sum_T [1/sqrt(v)]_RT (T|rs)
140  ! r,s: MO-index, P,R,T: RI-index
141  ! B: fm_mat_S_..., W: fm_mat_Q_...
142  CALL mult_b_with_w(fm_mat_s_ij_trunc, fm_mat_s_ia_trunc, fm_mat_s_bar_ia_bse, &
143  fm_mat_s_bar_ij_bse, fm_mat_q_static_bse_gemm, &
144  dimen_ri_red, homo_red, virtual_red)
145 
146  IF (my_do_iterat_diag) THEN
147  CALL fill_local_3c_arrays(fm_mat_s_ab_trunc, fm_mat_s_ia_trunc, &
148  fm_mat_s_bar_ia_bse, fm_mat_s_bar_ij_bse, &
149  b_bar_ijq_bse_local, b_abq_bse_local, b_bar_iaq_bse_local, &
150  b_iaq_bse_local, dimen_ri_red, homo_red, virtual_red, &
151  gd_array, color_sub, para_env)
152  END IF
153 
154  IF (my_do_fulldiag) THEN
155  ! Quick estimate of memory consumption and runtime of diagonalizations
156  CALL estimate_bse_resources(homo_red, virtual_red, unit_nr, my_do_abba, &
157  para_env, diag_runtime_est)
158  ! Matrix A constructed from GW energies and 3c-B-matrices (cf. subroutine mult_B_with_W)
159  ! A_ia,jb = (ε_a-ε_i) δ_ij δ_ab + α * v_ia,jb - W_ij,ab
160  ! ε_a, ε_i are GW singleparticle energies from Eigenval_reduced
161  ! α is a spin-dependent factor
162  ! v_ia,jb = \sum_P B^P_ia B^P_jb (unscreened Coulomb interaction)
163  ! W_ij,ab = \sum_P \bar{B}^P_ij B^P_ab (screened Coulomb interaction)
164  CALL create_a(fm_mat_s_ia_trunc, fm_mat_s_bar_ij_bse, fm_mat_s_ab_trunc, &
165  fm_a_bse, eigenval_reduced, unit_nr, &
166  homo_red, virtual_red, dimen_ri, mp2_env, &
167  para_env)
168  IF (my_do_abba) THEN
169  ! Matrix B constructed from 3c-B-matrices (cf. subroutine mult_B_with_W)
170  ! B_ia,jb = α * v_ia,jb - W_ib,aj
171  ! α is a spin-dependent factor
172  ! v_ia,jb = \sum_P B^P_ia B^P_jb (unscreened Coulomb interaction)
173  ! W_ib,aj = \sum_P \bar{B}^P_ib B^P_aj (screened Coulomb interaction)
174  CALL create_b(fm_mat_s_ia_trunc, fm_mat_s_bar_ia_bse, fm_b_bse, &
175  homo_red, virtual_red, dimen_ri, unit_nr, mp2_env)
176  ! Construct Matrix C=(A-B)^0.5 (A+B) (A-B)^0.5 to solve full BSE matrix as a hermitian problem
177  ! (cf. Eq. (A7) in F. Furche J. Chem. Phys., Vol. 114, No. 14, (2001)).
178  ! We keep fm_sqrt_A_minus_B and fm_inv_sqrt_A_minus_B for print of singleparticle transitions
179  ! of ABBA as described in Eq. (A10) in F. Furche J. Chem. Phys., Vol. 114, No. 14, (2001).
180  CALL create_hermitian_form_of_abba(fm_a_bse, fm_b_bse, fm_c_bse, &
181  fm_sqrt_a_minus_b, fm_inv_sqrt_a_minus_b, &
182  homo_red, virtual_red, unit_nr, mp2_env, diag_runtime_est)
183  END IF
184  CALL cp_fm_release(fm_b_bse)
185  IF (my_do_tda) THEN
186  ! Solving the hermitian eigenvalue equation A X^n = Ω^n X^n
187  CALL diagonalize_a(fm_a_bse, homo_red, virtual_red, homo(1), &
188  unit_nr, diag_runtime_est, mp2_env)
189  END IF
190  ! Release to avoid faulty use of changed A matrix
191  CALL cp_fm_release(fm_a_bse)
192  IF (my_do_abba) THEN
193  ! Solving eigenvalue equation C Z^n = (Ω^n)^2 Z^n .
194  ! Here, the eigenvectors Z^n relate to X^n via
195  ! Eq. (A10) in F. Furche J. Chem. Phys., Vol. 114, No. 14, (2001).
196  CALL diagonalize_c(fm_c_bse, homo_red, virtual_red, homo(1), &
197  fm_sqrt_a_minus_b, fm_inv_sqrt_a_minus_b, &
198  unit_nr, diag_runtime_est, mp2_env)
199  END IF
200  ! Release to avoid faulty use of changed C matrix
201  CALL cp_fm_release(fm_c_bse)
202  END IF
203 
204  CALL deallocate_matrices_bse(fm_mat_s_bar_ia_bse, fm_mat_s_bar_ij_bse, &
205  fm_mat_s_ia_trunc, fm_mat_s_ij_trunc, fm_mat_s_ab_trunc, &
206  fm_mat_q_static_bse, fm_mat_q_static_bse_gemm)
207  DEALLOCATE (eigenval_reduced)
208  IF (my_do_iterat_diag) THEN
209  ! Contains untested Block-Davidson algorithm
210  CALL do_subspace_iterations(b_bar_ijq_bse_local, b_abq_bse_local, b_bar_iaq_bse_local, &
211  b_iaq_bse_local, homo(1), virtual(1), mp2_env%ri_g0w0%bse_spin_config, unit_nr, &
212  eigenval(:, 1, 1), para_env, mp2_env)
213  ! Deallocate local 3c-B-matrices
214  DEALLOCATE (b_bar_ijq_bse_local, b_abq_bse_local, b_bar_iaq_bse_local, b_iaq_bse_local)
215  END IF
216 
217  IF (unit_nr > 0) THEN
218  WRITE (unit_nr, '(T2,A4,T7,A53)') 'BSE|', 'The BSE was successfully calculated. Have a nice day!'
219  END IF
220 
221  CALL timestop(handle)
222 
223  END SUBROUTINE start_bse_calculation
224 
225 END MODULE bse_main
Routines for the full diagonalization of GW + Bethe-Salpeter for computing electronic excitations.
Definition: bse_full_diag.F:14
subroutine, public create_a(fm_mat_S_ia_bse, fm_mat_S_bar_ij_bse, fm_mat_S_ab_bse, fm_A, Eigenval, unit_nr, homo, virtual, dimen_RI, mp2_env, para_env)
Matrix A constructed from GW energies and 3c-B-matrices (cf. subroutine mult_B_with_W) A_ia,...
Definition: bse_full_diag.F:77
subroutine, public diagonalize_c(fm_C, homo, virtual, homo_irred, fm_sqrt_A_minus_B, fm_inv_sqrt_A_minus_B, unit_nr, diag_est, mp2_env)
Solving eigenvalue equation C Z^n = (Ω^n)^2 Z^n . Here, the eigenvectors Z^n relate to X^n via Eq....
subroutine, public create_b(fm_mat_S_ia_bse, fm_mat_S_bar_ia_bse, fm_B, homo, virtual, dimen_RI, unit_nr, mp2_env)
Matrix B constructed from 3c-B-matrices (cf. subroutine mult_B_with_W) B_ia,jb = α * v_ia,...
subroutine, public create_hermitian_form_of_abba(fm_A, fm_B, fm_C, fm_sqrt_A_minus_B, fm_inv_sqrt_A_minus_B, homo, virtual, unit_nr, mp2_env, diag_est)
Construct Matrix C=(A-B)^0.5 (A+B) (A-B)^0.5 to solve full BSE matrix as a hermitian problem (cf....
subroutine, public diagonalize_a(fm_A, homo, virtual, homo_irred, unit_nr, diag_est, mp2_env)
Solving hermitian eigenvalue equation A X^n = Ω^n X^n.
Iterative routines for GW + Bethe-Salpeter for computing electronic excitations.
Definition: bse_iterative.F:14
subroutine, public fill_local_3c_arrays(fm_mat_S_ab_bse, fm_mat_S, fm_mat_S_bar_ia_bse, fm_mat_S_bar_ij_bse, B_bar_ijQ_bse_local, B_abQ_bse_local, B_bar_iaQ_bse_local, B_iaQ_bse_local, dimen_RI, homo, virtual, gd_array, color_sub, para_env)
...
subroutine, public do_subspace_iterations(B_bar_ijQ_bse_local, B_abQ_bse_local, B_bar_iaQ_bse_local, B_iaQ_bse_local, homo, virtual, bse_spin_config, unit_nr, Eigenval, para_env, mp2_env)
...
Definition: bse_iterative.F:57
Main routines for GW + Bethe-Salpeter for computing electronic excitations.
Definition: bse_main.F:14
subroutine, public start_bse_calculation(fm_mat_S_ia_bse, fm_mat_S_ij_bse, fm_mat_S_ab_bse, fm_mat_Q_static_bse, fm_mat_Q_static_bse_gemm, Eigenval, homo, virtual, dimen_RI, dimen_RI_red, gd_array, color_sub, mp2_env, unit_nr)
Main subroutine managing BSE calculations.
Definition: bse_main.F:72
Auxiliary routines for GW + Bethe-Salpeter for computing electronic excitations.
Definition: bse_util.F:13
subroutine, public estimate_bse_resources(homo_red, virtual_red, unit_nr, bse_abba, para_env, diag_runtime_est)
Roughly estimates the needed runtime and memory during the BSE run.
Definition: bse_util.F:1014
subroutine, public mult_b_with_w(fm_mat_S_ij_bse, fm_mat_S_ia_bse, fm_mat_S_bar_ia_bse, fm_mat_S_bar_ij_bse, fm_mat_Q_static_bse_gemm, dimen_RI, homo, virtual)
Multiplies B-matrix (RI-3c-Integrals) with W (screening) to obtain \bar{B}.
Definition: bse_util.F:67
subroutine, public print_bse_start_flag(bse_tda, bse_abba, unit_nr)
...
Definition: bse_util.F:788
subroutine, public deallocate_matrices_bse(fm_mat_S_bar_ia_bse, fm_mat_S_bar_ij_bse, fm_mat_S_trunc, fm_mat_S_ij_trunc, fm_mat_S_ab_trunc, fm_mat_Q_static_bse, fm_mat_Q_static_bse_gemm)
...
Definition: bse_util.F:833
subroutine, public truncate_bse_matrices(fm_mat_S_ia_bse, fm_mat_S_ij_bse, fm_mat_S_ab_bse, fm_mat_S_trunc, fm_mat_S_ij_trunc, fm_mat_S_ab_trunc, Eigenval, Eigenval_reduced, homo, virtual, dimen_RI, unit_nr, homo_red, virt_red, mp2_env)
Determines indices within the given energy cutoffs and truncates Eigenvalues and matrices.
Definition: bse_util.F:1208
represent a full matrix distributed on many processors
Definition: cp_fm_types.F:15
Types to describe group distributions.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public bse_iterdiag
integer, parameter, public bse_fulldiag
integer, parameter, public bse_tda
integer, parameter, public bse_both
integer, parameter, public bse_abba
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Interface to the message passing library MPI.
Types needed for MP2 calculations.
Definition: mp2_types.F:14