(git:27c966b)
Loading...
Searching...
No Matches
bse_main.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 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: a GW path
10!> prepares the BSE environment, bse_solve runs the solver on it
11!> \par History
12!> 04.2024 created [Maximilian Graml]
13!> 09.2026 split into prepare_bse_env and bse_solve [Maximilian Graml]
14! **************************************************************************************************
15
17
18 USE bse_full_diag, ONLY: create_a_and_b,&
27 USE bse_types, ONLY: bse_env_type
28 USE bse_util, ONLY: &
36 USE cp_fm_types, ONLY: cp_fm_create,&
43 USE input_constants, ONLY: bse_abba,&
44 bse_both,&
51 USE kinds, ONLY: dp
53 USE mo_window, ONLY: mo_window_type
58 USE qs_mo_types, ONLY: get_mo_set,&
61#include "./base/base_uses.f90"
62
63 IMPLICIT NONE
64
65 PRIVATE
66
67 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'bse_main'
68
71
72CONTAINS
73
74! **************************************************************************************************
75!> \brief Entry for the BSE of RI_RPA%GW, which hands over the slabs of all its GW levels and the
76!> static polarizability Q(0): re-reads the settings, cuts the window on the DFT axis out of
77!> the slabs and both energy sets, and inverts 1+Q(0) for W0 screening. Starts no solver.
78!> \param bse_env settings re-read from its section; state filled here
79!> \param fm_S_ia_full B^P_ia of the GW levels per spin, the RPA copy without the energy factor
80!> \param fm_S_ij_full B^P_ij per spin
81!> \param fm_S_ab_full B^P_ab per spin
82!> \param fm_Q the static polarizability Q(0), untouched; the caller releases it afterwards
83!> \param Eigenval quasiparticle energies (level, 1, spin)
84!> \param Eigenval_scf DFT energies (level, 1, spin)
85!> \param homo occupied MOs per spin
86!> \param virtual virtual MOs per spin
87!> \param dimen_RI RI dimension of the slabs
88!> \param dimen_RI_red reduced RI dimension of Q(0)
89!> \param gw_corr_lev_occ GW-corrected occupied levels; the window may not exceed them
90!> \param bse_lev_virt GW-corrected virtual levels per spin
91!> \param qs_env source of the pointers the solver reads and of the AO multipoles
92!> \param unit_nr output unit, positive on the writing rank only
93! **************************************************************************************************
94 SUBROUTINE prepare_bse_env_from_ri_rpa_gw(bse_env, fm_S_ia_full, fm_S_ij_full, fm_S_ab_full, fm_Q, &
95 Eigenval, Eigenval_scf, homo, virtual, dimen_RI, dimen_RI_red, &
96 gw_corr_lev_occ, bse_lev_virt, qs_env, unit_nr)
97
98 TYPE(bse_env_type), INTENT(INOUT) :: bse_env
99 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: fm_s_ia_full, fm_s_ij_full, fm_s_ab_full
100 TYPE(cp_fm_type), INTENT(IN) :: fm_q
101 REAL(kind=dp), DIMENSION(:, :, :), INTENT(IN) :: eigenval, eigenval_scf
102 INTEGER, DIMENSION(:), INTENT(IN) :: homo, virtual
103 INTEGER, INTENT(IN) :: dimen_ri, dimen_ri_red, gw_corr_lev_occ
104 INTEGER, DIMENSION(:), INTENT(IN) :: bse_lev_virt
105 TYPE(qs_environment_type), POINTER :: qs_env
106 INTEGER, INTENT(IN) :: unit_nr
107
108 CHARACTER(LEN=*), PARAMETER :: routinen = 'prepare_bse_env_from_ri_rpa_gw'
109
110 INTEGER :: handle, ispin, n_window, nspins
111 INTEGER, ALLOCATABLE, DIMENSION(:) :: n_mo
112 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigenval_dft_spin, eigenval_qp_spin
113 TYPE(mo_window_type) :: window
114 TYPE(section_vals_type), POINTER :: bse_section
115
116 CALL timeset(routinen, handle)
117
118 ! Re-read the settings afresh from the input, since adapt_BSE_screening here and
119 ! adapt_BSE_input_params in bse_solve normalise them in place, and a later energy evaluation
120 ! on the same environment runs the BSE again; the local pointer keeps the section apart from
121 ! bse_env, whose section pointer the reader sets
122
123 bse_section => bse_env%bse_section
124 CALL read_bse_section(bse_section, bse_env)
125 CALL adapt_bse_screening(bse_env, unit_nr)
126 CALL bse_resolve_memory_per_proc(bse_env%memory_per_proc_gb, fm_s_ia_full(1)%matrix_struct%para_env, unit_nr)
127
128 nspins = SIZE(homo)
129 ! the GW-corrected level counts are the ceiling of the window
130 CALL start_bse_env(bse_env, nspins, dimen_ri, dimen_ri_red, gw_corr_lev_occ, bse_lev_virt, unit_nr)
131
132 ! one absolute window on the DFT axis, then the window-sized slabs and both energy sets per spin
133 ALLOCATE (n_mo(nspins))
134 n_mo(:) = homo(:) + virtual(:)
135 CALL bse_window_from_dft(eigenval_scf(:, 1, :), n_mo, homo, bse_env%bse_cutoff_occ, &
136 bse_env%bse_cutoff_empty, window, warn=.true.)
137 DEALLOCATE (n_mo)
138
139 ALLOCATE (bse_env%homo_red(nspins), bse_env%virt_red(nspins), bse_env%homo_full(nspins))
140 ALLOCATE (bse_env%fm_S_ia(nspins), bse_env%fm_S_ij(nspins), bse_env%fm_S_ab(nspins))
141 bse_env%homo_full(:) = homo(:)
142 DO ispin = 1, nspins
143 ! the cutoff summary is printed for a closed-shell reference only
144 CALL truncate_bse_matrices(fm_s_ia_full(ispin), fm_s_ij_full(ispin), fm_s_ab_full(ispin), &
145 eigenval_scf(:, 1, ispin), eigenval(:, 1, ispin), &
146 eigenval_dft_spin, eigenval_qp_spin, homo(ispin), virtual(ispin), &
147 dimen_ri, unit_nr, ispin, bse_env, window, nspins == 1)
148 ! the window is one absolute range, so every spin has the same number of levels
149 IF (ispin == 1) THEN
150 n_window = SIZE(eigenval_qp_spin)
151 ALLOCATE (bse_env%eigenval_dft(n_window, nspins), bse_env%eigenval_qp(n_window, nspins))
152 END IF
153 bse_env%eigenval_dft(:, ispin) = eigenval_dft_spin(:)
154 bse_env%eigenval_qp(:, ispin) = eigenval_qp_spin(:)
155 DEALLOCATE (eigenval_dft_spin, eigenval_qp_spin)
156 END DO
157
158 IF (bse_env%screening_method == bse_screening_w0) THEN
159 CALL invert_static_screening(fm_q, dimen_ri_red, bse_env%fm_eps_inv)
160 END IF
161
162 CALL finish_bse_env(bse_env, qs_env, fm_s_ia_full(1)%matrix_struct%para_env)
163
164 CALL timestop(handle)
165
166 END SUBROUTINE prepare_bse_env_from_ri_rpa_gw
167
168! **************************************************************************************************
169!> \brief Entry for the BSE of PROPERTIES%BANDSTRUCTURE%GW (PROPERTIES%BSE), which hands over
170!> window-sized slabs and a ready inverse dielectric matrix: nothing is cut or inverted, the
171!> slabs are taken over as they are. Shares start_bse_env and finish_bse_env with
172!> prepare_bse_env_from_ri_rpa_gw. Starts no solver.
173!> \param bse_env settings read and screening normalised by the caller; state filled here
174!> \param fm_S_ia B^P_ia of the window per spin; moved into bse_env, deallocated on return
175!> \param fm_S_ij B^P_ij of the window per spin; moved into bse_env, deallocated on return
176!> \param fm_S_ab B^P_ab of the window per spin; moved into bse_env, deallocated on return
177!> \param fm_eps_inv the inverse dielectric matrix ε^-1_PQ the core screens the slabs with,
178!> \bar{B}^P_ij = sum_Q ε^-1_PQ B^Q_ij; RI x RI, copied for W0 only; stays the caller's
179!> May be uncreated for other screening methods.
180!> \param eigenval_qp quasiparticle energies of the window (level, spin)
181!> \param eigenval_dft DFT energies of the window (level, spin)
182!> \param homo_full occupied MOs per spin of the full reference
183!> \param homo_red occupied levels in the window per spin
184!> \param virt_red virtual levels in the window per spin
185!> \param dimen_RI RI dimension of the slabs and of fm_eps_inv
186!> \param qs_env source of the pointers the solver reads and of the AO multipoles
187!> \param unit_nr output unit, positive on the writing rank only
188! **************************************************************************************************
189 SUBROUTINE prepare_bse_env_from_bandstructure_gw(bse_env, fm_S_ia, fm_S_ij, fm_S_ab, fm_eps_inv, &
190 eigenval_qp, eigenval_dft, homo_full, homo_red, virt_red, &
191 dimen_RI, qs_env, unit_nr)
192
193 TYPE(bse_env_type), INTENT(INOUT) :: bse_env
194 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:), &
195 INTENT(INOUT) :: fm_s_ia, fm_s_ij, fm_s_ab
196 TYPE(cp_fm_type), INTENT(IN) :: fm_eps_inv
197 REAL(kind=dp), DIMENSION(:, :), INTENT(IN) :: eigenval_qp, eigenval_dft
198 INTEGER, DIMENSION(:), INTENT(IN) :: homo_full, homo_red, virt_red
199 INTEGER, INTENT(IN) :: dimen_ri
200 TYPE(qs_environment_type), POINTER :: qs_env
201 INTEGER, INTENT(IN) :: unit_nr
202
203 CHARACTER(LEN=*), PARAMETER :: routinen = 'prepare_bse_env_from_bandstructure_gw'
204
205 INTEGER :: handle, ispin, n_window, nspins
206
207 CALL timeset(routinen, handle)
208
209 ! the caller (bse_from_bs_env) read the settings afresh from the input; the entry of RI_RPA%GW reads them itself
210 IF (.NOT. ASSOCIATED(bse_env%bse_section)) cpabort("BSE settings not read: read_bse_section comes first")
211
212 nspins = SIZE(homo_full)
213 IF (SIZE(fm_s_ia) /= nspins .OR. SIZE(eigenval_qp, 2) /= nspins) THEN
214 cpabort("BSE needs one set of RI integrals and one set of energies per spin")
215 END IF
216 ! every window level carries a GW energy here, and the inverse dielectric matrix has the full RI dimension
217 CALL start_bse_env(bse_env, nspins, dimen_ri, dimen_ri, maxval(homo_red), virt_red, unit_nr)
218
219 ALLOCATE (bse_env%homo_red(nspins), bse_env%virt_red(nspins), bse_env%homo_full(nspins))
220 bse_env%homo_full(:) = homo_full(:)
221 bse_env%homo_red(:) = homo_red(:)
222 bse_env%virt_red(:) = virt_red(:)
223 n_window = SIZE(eigenval_qp, 1)
224 DO ispin = 1, nspins
225 ! one absolute window for every spin: its occupied and virtual levels fill it
226 IF (homo_red(ispin) + virt_red(ispin) /= n_window) THEN
227 cpabort("Occupied and virtual levels do not fill the BSE window")
228 END IF
229 END DO
230 ALLOCATE (bse_env%eigenval_dft(n_window, nspins), bse_env%eigenval_qp(n_window, nspins))
231 bse_env%eigenval_dft(:, :) = eigenval_dft(:, :)
232 bse_env%eigenval_qp(:, :) = eigenval_qp(:, :)
233
234 ! the slabs are window-sized already: take them over
235 CALL move_alloc(fm_s_ia, bse_env%fm_S_ia)
236 CALL move_alloc(fm_s_ij, bse_env%fm_S_ij)
237 CALL move_alloc(fm_s_ab, bse_env%fm_S_ab)
238 IF (bse_env%screening_method == bse_screening_w0) THEN
239 CALL cp_fm_create(bse_env%fm_eps_inv, fm_eps_inv%matrix_struct)
240 CALL cp_fm_to_fm(fm_eps_inv, bse_env%fm_eps_inv)
241 END IF
242
243 CALL finish_bse_env(bse_env, qs_env, bse_env%fm_S_ia(1)%matrix_struct%para_env)
244
245 CALL timestop(handle)
246
248
249! **************************************************************************************************
250!> \brief The part both entries share before their window: the sizes, the run flags from the
251!> settings, the start banner and the debug flag
252!> \param bse_env settings read from its section; sizes and flags set here
253!> \param nspins spin channels
254!> \param dimen_RI RI dimension of the slabs
255!> \param dimen_RI_red RI dimension of the inverse dielectric matrix
256!> \param gw_corr_lev_occ GW-corrected occupied levels
257!> \param gw_corr_lev_virt GW-corrected virtual levels per spin
258!> \param unit_nr output unit, positive on the writing rank only
259! **************************************************************************************************
260 SUBROUTINE start_bse_env(bse_env, nspins, dimen_RI, dimen_RI_red, gw_corr_lev_occ, gw_corr_lev_virt, unit_nr)
261
262 TYPE(bse_env_type), INTENT(INOUT) :: bse_env
263 INTEGER, INTENT(IN) :: nspins, dimen_ri, dimen_ri_red, &
264 gw_corr_lev_occ
265 INTEGER, DIMENSION(:), INTENT(IN) :: gw_corr_lev_virt
266 INTEGER, INTENT(IN) :: unit_nr
267
268 TYPE(cp_logger_type), POINTER :: logger
269
270 bse_env%nspins = nspins
271 bse_env%dimen_RI = dimen_ri
272 bse_env%dimen_RI_red = dimen_ri_red
273 bse_env%gw_corr_lev_occ = gw_corr_lev_occ
274 ALLOCATE (bse_env%gw_corr_lev_virt(nspins))
275 bse_env%gw_corr_lev_virt(:) = gw_corr_lev_virt(:)
276
277 ! run flags from the settings
278 bse_env%do_iterdiag = bse_env%bse_diag_method == bse_iterdiag
279 bse_env%do_fulldiag = bse_env%bse_diag_method == bse_fulldiag
280 bse_env%do_tda = bse_env%flag_tda == bse_tda .OR. bse_env%flag_tda == bse_both
281 bse_env%do_abba = bse_env%flag_tda == bse_abba .OR. bse_env%flag_tda == bse_both
282
283 CALL print_bse_start_flag(bse_env%do_tda, bse_env%do_abba, unit_nr)
284
285 ! the debug flag follows the debug print level
286 logger => cp_get_default_logger()
287 IF (logger%iter_info%print_level == debug_print_level) THEN
288 bse_env%bse_debug_print = .true.
289 END IF
290
291 END SUBROUTINE start_bse_env
292
293! **************************************************************************************************
294!> \brief The part both entries share once the window and the slabs are in place: the
295!> QS pointers, the open-shell checks, the spin-block layout and the AO multipoles
296!> \param bse_env state filled here
297!> \param qs_env source of the pointers the solver reads and of the AO multipoles
298!> \param para_env_slabs the communicator the slabs live on
299! **************************************************************************************************
300 SUBROUTINE finish_bse_env(bse_env, qs_env, para_env_slabs)
301
302 TYPE(bse_env_type), INTENT(INOUT) :: bse_env
303 TYPE(qs_environment_type), POINTER :: qs_env
304 TYPE(mp_para_env_type), POINTER :: para_env_slabs
305
306 CHARACTER(LEN=*), PARAMETER :: routinen = 'finish_bse_env'
307
308 INTEGER :: handle, nspins
309 INTEGER, ALLOCATABLE, DIMENSION(:) :: n_ov, offsets
310 TYPE(pw_poisson_parameter_type) :: poisson_params
311 TYPE(section_vals_type), POINTER :: input, poisson_section
312
313 CALL timeset(routinen, handle)
314
315 nspins = bse_env%nspins
316
317 ! what the solver reads from QS and the GW (pointers, none owned)
318 bse_env%para_env => para_env_slabs
319 CALL get_qs_env(qs_env, subsys=bse_env%subsys, pw_env=bse_env%pw_env, &
320 dft_control=bse_env%dft_control, mos=bse_env%mos, &
321 exstate_env=bse_env%exstate_env)
322 ! the Poisson periodicity from the input: PROPERTIES%BSE runs after the GW released the grids
323 NULLIFY (input, poisson_section)
324 CALL get_qs_env(qs_env, input=input)
325 poisson_section => section_vals_get_subs_vals(input, "DFT%POISSON")
326 CALL pw_poisson_read_parameters(poisson_section, poisson_params)
327 bse_env%n_periodic_poisson = count(poisson_params%periodic == 1)
328 CALL bse_env%para_env%sync()
329
330 IF (nspins > 1) THEN
331 IF (bse_env%do_iterdiag) THEN
332 cpabort("Iterative BSE is not yet available for open-shell references")
333 END IF
334 CALL cp_warn(__location__, &
335 "Open-shell (UKS/LSD) BSE is a recent addition and has not been "// &
336 "extensively validated. Verify results carefully before using them "// &
337 "for production calculations.")
338 END IF
339
340 ALLOCATE (n_ov(nspins), offsets(nspins))
341 CALL get_bse_spin_block_layout(bse_env%homo_red, bse_env%virt_red, n_ov, offsets, bse_env%n_ov_joint)
342 DEALLOCATE (n_ov, offsets)
343
344 ! the AO multipoles for the transition dipoles and, when asked for, the exciton descriptors;
345 ! the open-shell path computes no descriptors
346 CALL get_multipoles_ao(qs_env, 1, bse_env%matrix_dipole_ao, bse_env%multipole_ref_point)
347 IF (bse_env%num_print_exc_descr /= 0 .AND. nspins == 1) THEN
348 CALL get_multipoles_ao(qs_env, 2, bse_env%matrix_quadpole_ao, bse_env%multipole_ref_point)
349 END IF
350
351 CALL timestop(handle)
352
353 END SUBROUTINE finish_bse_env
354
355! **************************************************************************************************
356!> \brief The inverse dielectric matrix in the RI basis, [1+Q(0)]^-1_PQ on the leading dimen_RI_red
357!> block, P, Q ≤ dimen_RI_red, by Cholesky decomposition and inversion of a copy of Q(0)
358!> \param fm_Q the static polarizability Q_PQ(0), untouched
359!> \param dimen_RI_red reduced RI dimension of Q(0)
360!> \param fm_eps_inv [1+Q(0)]^-1_PQ, created here on fm_Q's structure
361! **************************************************************************************************
362 SUBROUTINE invert_static_screening(fm_Q, dimen_RI_red, fm_eps_inv)
363
364 TYPE(cp_fm_type), INTENT(IN) :: fm_q
365 INTEGER, INTENT(IN) :: dimen_ri_red
366 TYPE(cp_fm_type), INTENT(OUT) :: fm_eps_inv
367
368 CHARACTER(LEN=*), PARAMETER :: routinen = 'invert_static_screening'
369
370 INTEGER :: handle, info_chol
371 TYPE(cp_fm_type) :: fm_work
372
373 CALL timeset(routinen, handle)
374
375 ! a copy: the caller keeps Q(0), and the open-shell path inverts once for both spins
376 CALL cp_fm_create(fm_eps_inv, fm_q%matrix_struct)
377 CALL cp_fm_to_fm(fm_q, fm_eps_inv)
378 CALL cp_fm_create(fm_work, fm_q%matrix_struct)
379
380 ! δ_PQ + Q_PQ(0) on the leading dimen_RI_red block
381 CALL cp_fm_add_on_diag(fm_eps_inv, 1.0_dp, n_active=dimen_ri_red)
382
383 ! [1+Q(0)]^-1_PQ by Cholesky, symmetrised from the stored triangle
384 CALL cp_fm_cholesky_decompose(matrix=fm_eps_inv, n=dimen_ri_red, info_out=info_chol)
385 IF (info_chol /= 0) THEN
386 CALL cp_abort(__location__, 'Cholesky decomposition failed for static polarization in BSE')
387 END IF
388 CALL cp_fm_cholesky_invert(fm_eps_inv, n=dimen_ri_red, work=fm_work)
389
390 CALL cp_fm_release(fm_work)
391
392 CALL timestop(handle)
393
394 END SUBROUTINE invert_static_screening
395
396! **************************************************************************************************
397!> \brief Solves the BSE on a prepared environment: input normalisation, the screened slabs from
398!> [1+Q(0)]^-1, then the FULLDIAG or ITERDIAG solver on the energies USE_KS_ENERGIES selects
399!> \param bse_env prepared by a GW path; the screened slabs are formed here
400!> \param mo_coeff MO coefficients of the reference, per spin, for the properties
401!> \param unit_nr output unit, positive on the writing rank only
402! **************************************************************************************************
403 SUBROUTINE bse_solve(bse_env, mo_coeff, unit_nr)
404
405 TYPE(bse_env_type), INTENT(INOUT) :: bse_env
406 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: mo_coeff
407 INTEGER, INTENT(IN) :: unit_nr
408
409 CHARACTER(LEN=*), PARAMETER :: routinen = 'bse_solve'
410
411 INTEGER :: handle, ispin, n_window, nspins
412 REAL(kind=dp) :: diag_runtime_est
413 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigenval_joint
414 TYPE(cp_fm_type) :: fm_a_bse, fm_b_bse, fm_c_bse, &
415 fm_inv_sqrt_a_minus_b, &
416 fm_sqrt_a_minus_b
417 TYPE(tddfpt2_control_type), POINTER :: tddfpt_control
418
419 CALL timeset(routinen, handle)
420
421 nspins = bse_env%nspins
422
423 ! normalisation touches no slab; n_ov_joint x 1 is the transition count on either spin path
424 CALL adapt_bse_input_params(bse_env%n_ov_joint, 1, unit_nr, bse_env)
425
426 ! the energies the solver sees, flat joint layout [spin 1 window | spin 2 window]
427 n_window = SIZE(bse_env%eigenval_qp, 1)
428 ALLOCATE (eigenval_joint(n_window*nspins))
429 DO ispin = 1, nspins
430 IF (bse_env%use_ks_energies) THEN
431 eigenval_joint((ispin - 1)*n_window + 1:ispin*n_window) = bse_env%eigenval_dft(:, ispin)
432 ELSE
433 eigenval_joint((ispin - 1)*n_window + 1:ispin*n_window) = bse_env%eigenval_qp(:, ispin)
434 END IF
435 END DO
436
437 ! Keep default-initialised containers for the common solver interfaces. Only W0 needs
438 ! screened matrix storage; TDA needs barB_ij, and ABBA additionally needs barB_ia.
439 ALLOCATE (bse_env%fm_S_bar_ia(nspins), bse_env%fm_S_bar_ij(nspins))
440 IF (bse_env%screening_method == bse_screening_w0) THEN
441 DO ispin = 1, nspins
442 CALL screen_slabs(bse_env%fm_eps_inv, bse_env%fm_S_ij(ispin), bse_env%fm_S_ia(ispin), &
443 bse_env%dimen_RI_red, bse_env%homo_red(ispin), bse_env%virt_red(ispin), &
444 bse_env%fm_S_bar_ij(ispin), bse_env%fm_S_bar_ia(ispin), bse_env%do_abba)
445 END DO
446 END IF
447 CALL cp_fm_release(bse_env%fm_eps_inv)
448
449 IF (bse_env%do_iterdiag) THEN
450 CALL solve_bse_iteratively(eigenval_joint, &
451 bse_env%homo_red, bse_env%virt_red, bse_env%homo_full, &
452 bse_env%dimen_RI, bse_env%do_tda, bse_env%do_abba, &
453 bse_env, mo_coeff, unit_nr)
454 END IF
455
456 IF (bse_env%do_fulldiag) THEN
457 CALL estimate_bse_resources(bse_env%n_ov_joint, unit_nr, bse_env%do_abba, &
458 bse_env%para_env, diag_runtime_est)
459 CALL create_a_and_b(bse_env%fm_S_ia, bse_env%fm_S_ij, bse_env%fm_S_ab, &
460 bse_env%fm_S_bar_ia, bse_env%fm_S_bar_ij, fm_a_bse, fm_b_bse, &
461 bse_env%do_abba, eigenval_joint, unit_nr, bse_env%homo_red, &
462 bse_env%virt_red, bse_env%dimen_RI, bse_env)
463 IF (bse_env%do_abba) THEN
464 CALL create_hermitian_form_of_abba(fm_a_bse, fm_b_bse, fm_c_bse, &
465 fm_sqrt_a_minus_b, fm_inv_sqrt_a_minus_b, &
466 unit_nr, bse_env, diag_runtime_est)
467 END IF
468 CALL cp_fm_release(fm_b_bse)
469 tddfpt_control => bse_env%dft_control%tddfpt2_control
470 ! homo_full: per-spin absolute MO labels for the amplitude table, N_e = SUM(homo_full) for TRK
471 IF (bse_env%do_tda .AND. (.NOT. tddfpt_control%do_bse)) THEN
472 CALL diagonalize_a(fm_a_bse, bse_env%homo_red, bse_env%virt_red, bse_env%homo_full, &
473 unit_nr, diag_runtime_est, bse_env, mo_coeff)
474 END IF
475 CALL cp_fm_release(fm_a_bse)
476 IF (bse_env%do_abba) THEN
477 CALL diagonalize_c(fm_c_bse, bse_env%homo_red, bse_env%virt_red, bse_env%homo_full, &
478 fm_sqrt_a_minus_b, fm_inv_sqrt_a_minus_b, &
479 unit_nr, diag_runtime_est, bse_env, mo_coeff)
480 END IF
481 CALL cp_fm_release(fm_c_bse)
482 END IF
483
484 DEALLOCATE (eigenval_joint)
485
486 IF (unit_nr > 0) THEN
487 WRITE (unit_nr, '(T2,A4,T7,A53)') 'BSE|', 'The BSE was successfully calculated. Have a nice day!'
488 END IF
489
490 CALL timestop(handle)
491
492 END SUBROUTINE bse_solve
493
494! **************************************************************************************************
495!> \brief Early memory check for the full diagonalization, before any GW work: the window on the
496!> DFT axis gives n_ov = sum_spin n_occ n_virt, the estimate is estimate_BSE_resources', and
497!> the run stops when it exceeds what MEMORY_PER_PROC leaves after the memory the rank holds,
498!> since a full diagonalization has nothing to shrink
499!> \param bse_env settings; the TDA flag and MEMORY_PER_PROC, resolved here when still -1
500!> \param window the active MO window on the DFT axis, one absolute range for every spin
501!> \param homo occupied MOs per spin
502!> \param para_env the ranks that will hold the matrices
503!> \param unit_nr output unit, positive on the writing rank only
504! **************************************************************************************************
505 SUBROUTINE bse_fulldiag_memory_check(bse_env, window, homo, para_env, unit_nr)
506 TYPE(bse_env_type), INTENT(INOUT) :: bse_env
507 TYPE(mo_window_type), INTENT(IN) :: window
508 INTEGER, DIMENSION(:), INTENT(IN) :: homo
509 TYPE(mp_para_env_type), POINTER :: para_env
510 INTEGER, INTENT(IN) :: unit_nr
511
512 CHARACTER(LEN=*), PARAMETER :: routinen = 'bse_fulldiag_memory_check'
513
514 CHARACTER(LEN=16) :: left_str, mem_str
515 CHARACTER(LEN=80) :: remedy
516 INTEGER :: handle, ispin, n_ov_joint, nspins
517 REAL(kind=dp) :: mem_est_gb, mem_left_gb
518
519 CALL timeset(routinen, handle)
520
521 nspins = SIZE(homo)
522 n_ov_joint = 0
523 DO ispin = 1, nspins
524 n_ov_joint = n_ov_joint + (homo(ispin) - window%first_mo + 1)*(window%last_mo - homo(ispin))
525 END DO
526 mem_est_gb = fulldiag_memory_estimate_gb(n_ov_joint, bse_env%flag_tda /= bse_tda)/ &
527 REAL(para_env%num_pe, kind=dp)
528 CALL bse_resolve_memory_per_proc(bse_env%memory_per_proc_gb, para_env, unit_nr)
529 mem_left_gb = bse_memory_left_gb(bse_env%memory_per_proc_gb, para_env)
530
531 IF (unit_nr > 0) THEN
532 WRITE (unit_nr, '(T2,A4)') 'BSE|'
533 WRITE (unit_nr, '(T2,A4,T7,A)') 'BSE|', 'Early memory check for the full diagonalization'
534 WRITE (unit_nr, '(T2,A4,T7,A,T71,I10)') 'BSE|', 'Transition pairs in the active window (DFT axis)', &
535 n_ov_joint
536 WRITE (unit_nr, '(T2,A4,T7,A,T67,F14.3)') 'BSE|', 'Peak memory estimate per MPI rank (GB)', mem_est_gb
537 WRITE (unit_nr, '(T2,A4,T7,A,T67,F14.3)') 'BSE|', 'Memory per MPI rank for the BSE, MEMORY_PER_PROC (GB)', &
538 bse_env%memory_per_proc_gb
539 WRITE (unit_nr, '(T2,A4,T7,A,T67,F14.3)') 'BSE|', 'Left after the memory the rank holds (GB)', mem_left_gb
540 WRITE (unit_nr, '(T2,A4)') 'BSE|'
541 END IF
542
543 IF (mem_est_gb > mem_left_gb) THEN
544 WRITE (mem_str, '(F16.3)') mem_est_gb
545 WRITE (left_str, '(F16.3)') mem_left_gb
546 ! ITERDIAG is closed-shell only, so an open-shell run is not pointed to it
547 IF (nspins == 1) THEN
548 remedy = "more MPI ranks, a tighter window, ITERDIAG, a higher MEMORY_PER_PROC"
549 ELSE
550 remedy = "more MPI ranks, a tighter window, a higher MEMORY_PER_PROC"
551 END IF
552 CALL cp_abort(__location__, &
553 "BSE full diagonalization: the estimate of "//trim(adjustl(mem_str))// &
554 " GB per MPI rank exceeds the "//trim(adjustl(left_str))// &
555 " GB left of MEMORY_PER_PROC. Try one of: "//trim(remedy)//".")
556 END IF
557
558 CALL timestop(handle)
559
560 END SUBROUTINE bse_fulldiag_memory_check
561
562! **************************************************************************************************
563!> \brief bse_fulldiag_memory_check for a caller that holds MO sets: the window on the DFT axis
564!> from their eigenvalues, the occupied MOs per spin from their homo
565!> \param bse_env settings; the window cutoffs, the TDA flag and MEMORY_PER_PROC, resolved when still -1
566!> \param mos the MO sets the GW will correct, for their DFT eigenvalues and occupations
567!> \param para_env the ranks that will hold the matrices
568!> \param unit_nr output unit, positive on the writing rank only
569! **************************************************************************************************
570 SUBROUTINE bse_fulldiag_memory_check_from_mos(bse_env, mos, para_env, unit_nr)
571
572 TYPE(bse_env_type), INTENT(INOUT) :: bse_env
573 TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mos
574 TYPE(mp_para_env_type), POINTER :: para_env
575 INTEGER, INTENT(IN) :: unit_nr
576
577 INTEGER :: ispin
578 INTEGER, ALLOCATABLE, DIMENSION(:) :: homo
579 TYPE(mo_window_type) :: window
580
581 ! the preparer warns about a combined window; the estimate stays silent
582 CALL bse_window_from_mos(mos, bse_env%bse_cutoff_occ, bse_env%bse_cutoff_empty, window, warn=.false.)
583 ALLOCATE (homo(SIZE(mos)))
584 DO ispin = 1, SIZE(mos)
585 CALL get_mo_set(mos(ispin), homo=homo(ispin))
586 END DO
587 CALL bse_fulldiag_memory_check(bse_env, window, homo, para_env, unit_nr)
588 DEALLOCATE (homo)
589
591
592END MODULE bse_main
Routines for the full diagonalization of GW + Bethe-Salpeter for computing electronic excitations.
subroutine, public create_a_and_b(fm_s_ia, fm_s_ij, fm_s_ab, fm_s_bar_ia, fm_s_bar_ij, fm_a, fm_b, do_abba, eigenval, unit_nr, homo, virtual, dimen_ri, bse_env)
Explicit A, and B for ABBA, from the slabs the screening method contracts: the bare ones for TDHF and...
subroutine, public diagonalize_a(fm_a, homo, virtual, homo_irred, unit_nr, diag_est, bse_env, mo_coeff)
Solving hermitian eigenvalue equation A X^n = Ω^n X^n.
subroutine, public create_hermitian_form_of_abba(fm_a, fm_b, fm_c, fm_sqrt_a_minus_b, fm_inv_sqrt_a_minus_b, unit_nr, bse_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_c(fm_c, homo, virtual, homo_irred, fm_sqrt_a_minus_b, fm_inv_sqrt_a_minus_b, unit_nr, diag_est, bse_env, mo_coeff)
Solving eigenvalue equation C Z^n = (Ω^n)^2 Z^n . Here, the eigenvectors Z^n relate to X^n via Eq....
Reads the &BSE input section into the BSE environment; called by read_mp2_section with the section un...
Definition bse_input.F:15
subroutine, public read_bse_section(bse_section, bse_env)
Reads every keyword of the &BSE section into the settings of the BSE environment.
Definition bse_input.F:38
Iterative solution of the Bethe-Salpeter equation: the block Davidson solvers on top of the matrix-fr...
subroutine, public solve_bse_iteratively(eigenval_reduced, homo_red_arr, virt_red_arr, homo, dimen_ri, do_tda, do_abba, bse_env, mo_coeff, unit_nr)
Lowest excitations of a closed-shell reference from the block Davidson solvers on top of the matrix-f...
Main routines for GW + Bethe-Salpeter for computing electronic excitations: a GW path prepares the BS...
Definition bse_main.F:16
subroutine, public bse_fulldiag_memory_check_from_mos(bse_env, mos, para_env, unit_nr)
bse_fulldiag_memory_check for a caller that holds MO sets: the window on the DFT axis from their eige...
Definition bse_main.F:571
subroutine, public prepare_bse_env_from_bandstructure_gw(bse_env, fm_s_ia, fm_s_ij, fm_s_ab, fm_eps_inv, eigenval_qp, eigenval_dft, homo_full, homo_red, virt_red, dimen_ri, qs_env, unit_nr)
Entry for the BSE of PROPERTIESBANDSTRUCTUREGW (PROPERTIESBSE), which hands over window-sized slabs a...
Definition bse_main.F:192
subroutine, public bse_solve(bse_env, mo_coeff, unit_nr)
Solves the BSE on a prepared environment: input normalisation, the screened slabs from [1+Q(0)]^-1,...
Definition bse_main.F:404
subroutine, public prepare_bse_env_from_ri_rpa_gw(bse_env, fm_s_ia_full, fm_s_ij_full, fm_s_ab_full, fm_q, eigenval, eigenval_scf, homo, virtual, dimen_ri, dimen_ri_red, gw_corr_lev_occ, bse_lev_virt, qs_env, unit_nr)
Entry for the BSE of RI_RPAGW, which hands over the slabs of all its GW levels and the static polariz...
Definition bse_main.F:97
subroutine, public bse_fulldiag_memory_check(bse_env, window, homo, para_env, unit_nr)
Early memory check for the full diagonalization, before any GW work: the window on the DFT axis gives...
Definition bse_main.F:506
Matrix-free application of the BSE matrices A and B to trial vectors from RI slabs that are sliced al...
Definition bse_matvec.F:14
real(kind=dp) function, public bse_memory_left_gb(memory_per_proc_gb, para_env)
What MEMORY_PER_PROC leaves to a step: the resolved memory per MPI rank minus the memory the rank hol...
Definition bse_matvec.F:126
subroutine, public bse_resolve_memory_per_proc(memory_per_proc_gb, para_env, unit_nr)
MEMORY_PER_PROC of the BSE as a number: the keyword's value, or for -1 the memory the rank holds plus...
Definition bse_matvec.F:94
Routines for printing information in context of the BSE calculation.
Definition bse_print.F:13
subroutine, public print_bse_start_flag(bse_tda, bse_abba, unit_nr)
...
Definition bse_print.F:57
The BSE environment: the settings of the &BSE section and the state a GW path prepares for the solver...
Definition bse_types.F:14
Auxiliary routines for GW + Bethe-Salpeter for computing electronic excitations.
Definition bse_util.F:13
subroutine, public adapt_bse_screening(bse_env, unit_nr)
Resolve SCREENING_IN_W and its factor before constructing the dielectric matrix or slabs.
Definition bse_util.F:1121
subroutine, public truncate_bse_matrices(fm_s_ia_full, fm_s_ij_full, fm_s_ab_full, eigenval_scf, eigenval, eigenval_reduced_scf, eigenval_reduced_qp, homo, virtual, dimen_ri, unit_nr, ispin, bse_env, window, print_window)
Determines indices within the given energy cutoffs and truncates Eigenvalues and matrices.
Definition bse_util.F:662
subroutine, public estimate_bse_resources(n_ov_joint, unit_nr, bse_abba, para_env, diag_runtime_est)
Roughly estimates the needed runtime and memory during the BSE run.
Definition bse_util.F:354
subroutine, public adapt_bse_input_params(homo, virtual, unit_nr, bse_env)
Checks BSE input section and adapts them if necessary.
Definition bse_util.F:960
pure real(kind=dp) function, public fulldiag_memory_estimate_gb(n_ov_joint, do_abba)
Peak memory of the full diagonalization in GB, all ranks together: n_ov^2 doubles times the matrices ...
Definition bse_util.F:397
subroutine, public bse_window_from_dft(eigenval_scf, n_mo, homo, cutoff_occ, cutoff_empty, window, warn)
The active MO window on the DFT axis: one absolute MO range for every spin; when the spin windows dif...
Definition bse_util.F:576
subroutine, public screen_slabs(fm_eps_inv, fm_s_ij, fm_s_ia, dimen_ri_red, homo, virtual, fm_s_bar_ij, fm_s_bar_ia, do_abba)
The screened slabs \bar{B}^P_ij = sum_Q [1+Q(0)]^-1_PQ B^Q_ij and \bar{B}^P_ia = sum_Q [1+Q(0)]^-1_PQ...
Definition bse_util.F:148
subroutine, public get_bse_spin_block_layout(homo_red, virt_red, n_ov, offsets, n_ov_joint)
Spin-block layout for the open-shell (joint) BSE matrix: per-spin OV-pair counts and the block offset...
Definition bse_util.F:549
subroutine, public bse_window_from_mos(mos, cutoff_occ, cutoff_empty, window, warn)
The active MO window of bse_window_from_dft, from the DFT eigenvalues of the MO sets.
Definition bse_util.F:614
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_add_on_diag(matrix, alpha, n_active)
Adds a scalar to the diagonal of a distributed real full matrix.
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_invert(matrix, n, info_out, work)
Replace the upper Cholesky factor by the upper triangle of the inverse. When work is provided,...
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public debug_print_level
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_screening_w0
integer, parameter, public bse_tda
integer, parameter, public bse_both
integer, parameter, public bse_abba
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
Common selection and union operations for contiguous molecular-orbital windows.
Definition mo_window.F:11
Reading of input parameters for the pw_poisson-modules.
subroutine, public pw_poisson_read_parameters(poisson_section, params)
Reads the POISSON input-section and into pw_poisson_parameter_type.
functions related to the poisson solver on regular grids
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count, cmo_coeff)
Get the components of a MO set data structure.
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>.
Definition qs_moments.F:14
subroutine, public get_multipoles_ao(qs_env, n_moments, matrix_multipole, rpoint)
The AO multipoles M^k_µν = <φ_µ|(r - r_0)^k|φ_ν> of every order up to n_moments, on the block pattern...
Definition qs_moments.F:442
Settings of the &BSE section (read_bse_section, re-read before every BSE run, normalised in place by ...
Definition bse_types.F:44
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment
parameters for the poisson solver independet of input_section