49#include "./base/base_uses.f90"
55 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'gw_ri_rs_non_periodic'
71 CHARACTER(LEN=*),
PARAMETER :: routinen =
'gw_calc_ri_rs_non_periodic'
74 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma, fm_w_time
76 CALL timeset(routinen, handle)
80 IF (bs_env%unit_nr > 0)
WRITE (bs_env%unit_nr,
'(A)')
' '
81 CALL print_ri_rs_memory_estimate(bs_env)
84 label=
'Memory per MPI process after computing Z_lP:')
100 CALL compute_w(bs_env, qs_env, bs_env%mat_chi_Gamma_tau, fm_w_time)
110 CALL compute_sigma_x(bs_env, qs_env, fm_sigma_x_gamma, bs_env%ri_rs%cutoff_radius_v_w)
124 CALL compute_sigma_c_and_qp_energies(bs_env, fm_w_time, fm_sigma_x_gamma)
128 CALL timestop(handle)
148 SUBROUTINE compute_sigma_c_and_qp_energies(bs_env, fm_W_time, fm_Sigma_x_Gamma)
151 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_w_time, fm_sigma_x_gamma
153 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_Sigma_c_and_QP_energies'
155 INTEGER :: handle, i_iter, n_iter
157 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: eigenval_scf_gamma_dft
158 REAL(kind=
dp),
DIMENSION(2) :: e_fermi_dft
159 REAL(kind=
dp),
DIMENSION(3, 2) :: band_prev
160 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
162 CALL timeset(routinen, handle)
166 CALL init_evgw0(bs_env, n_iter, band_prev, eigenval_scf_gamma_dft, e_fermi_dft)
169 DO i_iter = 1, n_iter
176 bs_env%ri_rs%cutoff_radius_v_w, keep_w_and_files=.true.)
180 CALL compute_qp_energies(bs_env, fm_sigma_x_gamma, fm_sigma_c_gamma_time, i_iter)
182 IF (bs_env%gw_flavour ==
g0w0)
EXIT
184 CALL print_evgw0_band_edges(bs_env, band_prev, i_iter, n_iter, converged)
186 IF (i_iter == n_iter .OR. converged)
EXIT
191 CALL update_eigenvalues_g(bs_env)
197 CALL reset_and_clean_bs_env(bs_env, eigenval_scf_gamma_dft, e_fermi_dft, fm_sigma_x_gamma)
201 CALL timestop(handle)
203 END SUBROUTINE compute_sigma_c_and_qp_energies
215 SUBROUTINE init_evgw0(bs_env, n_iter, band_prev, eigenval_scf_Gamma_dft, e_fermi_dft)
218 INTEGER,
INTENT(OUT) :: n_iter
219 REAL(kind=
dp),
DIMENSION(3, 2),
INTENT(OUT) :: band_prev
220 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :), &
221 INTENT(OUT) :: eigenval_scf_gamma_dft
222 REAL(kind=
dp),
DIMENSION(2),
INTENT(OUT) :: e_fermi_dft
224 CHARACTER(LEN=*),
PARAMETER :: routinen =
'init_evGW0'
228 CALL timeset(routinen, handle)
230 n_iter = bs_env%evgw0_n_iter
231 band_prev(:, :) = 0.0_dp
232 e_fermi_dft(:) = 0.0_dp
234 IF (bs_env%gw_flavour ==
evgw0)
THEN
237 bs_env%eigenval_evGW0(:, :, :) = bs_env%eigenval_scf(:, :, :)
239 ALLOCATE (eigenval_scf_gamma_dft, source=bs_env%eigenval_scf_Gamma)
240 e_fermi_dft(:) = bs_env%e_fermi(:)
243 CALL timestop(handle)
245 END SUBROUTINE init_evgw0
253 SUBROUTINE update_eigenvalues_g(bs_env)
257 CHARACTER(LEN=*),
PARAMETER :: routinen =
'update_eigenvalues_G'
259 INTEGER :: handle, i_mo, ispin
261 CALL timeset(routinen, handle)
264 bs_env%eigenval_evGW0(:, :, :) = bs_env%eigenval_GW(:, :, :)
266 DO ispin = 1, bs_env%n_spin
268 DO i_mo = 1, bs_env%n_mo_retained
269 bs_env%eigenval_scf_Gamma(i_mo, ispin) = bs_env%eigenval_GW(i_mo, 1, ispin)
271 bs_env%e_fermi(ispin) = &
272 0.5_dp*(bs_env%eigenval_GW(bs_env%n_occ(ispin), 1, ispin) + &
273 bs_env%eigenval_GW(bs_env%n_occ(ispin) + 1, 1, ispin))
276 CALL timestop(handle)
278 END SUBROUTINE update_eigenvalues_g
287 SUBROUTINE reset_and_clean_bs_env(bs_env, eigenval_scf_Gamma_dft, e_fermi_dft, fm_Sigma_x_Gamma)
290 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :), &
291 INTENT(INOUT) :: eigenval_scf_gamma_dft
292 REAL(kind=
dp),
DIMENSION(2),
INTENT(IN) :: e_fermi_dft
293 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
295 CHARACTER(LEN=*),
PARAMETER :: routinen =
'reset_and_clean_bs_env'
299 CALL timeset(routinen, handle)
301 IF (bs_env%gw_flavour ==
evgw0)
THEN
303 bs_env%eigenval_evGW0(:, :, :) = bs_env%eigenval_GW(:, :, :)
305 bs_env%eigenval_scf_Gamma(:, :) = eigenval_scf_gamma_dft(:, :)
306 bs_env%e_fermi(:) = e_fermi_dft(:)
307 DEALLOCATE (eigenval_scf_gamma_dft)
311 CALL timestop(handle)
313 END SUBROUTINE reset_and_clean_bs_env
323 SUBROUTINE print_evgw0_band_edges(bs_env, band_prev, i_iter, n_iter, converged)
326 REAL(kind=
dp),
DIMENSION(3, 2),
INTENT(INOUT) :: band_prev
327 INTEGER,
INTENT(IN) :: i_iter, n_iter
328 LOGICAL,
INTENT(OUT) :: converged
330 CHARACTER(LEN=*),
PARAMETER :: routinen =
'print_evGW0_band_edges'
332 INTEGER :: handle, homo, ispin, u
333 REAL(kind=
dp) :: max_delta
334 REAL(kind=
dp),
DIMENSION(3) :: band
336 CALL timeset(routinen, handle)
340 converged = (i_iter > 1)
345 WRITE (u,
'(T2,A)') repeat(
'-', 79)
346 WRITE (u,
'(T2,A,I4,A,I4)')
'evGW0 cycle', i_iter,
' /', n_iter
347 WRITE (u,
'(T2,A)') repeat(
'-', 79)
350 DO ispin = 1, bs_env%n_spin
352 homo = bs_env%n_occ(ispin)
353 band(1) = bs_env%eigenval_GW(homo, 1, ispin)
354 band(2) = bs_env%eigenval_GW(homo + 1, 1, ispin)
355 band(3) = band(2) - band(1)
358 max_delta = max(max_delta, maxval(abs(band(:) - band_prev(:, ispin))))
362 IF (bs_env%n_spin == 2)
WRITE (u,
'(T2,A,I0)')
'Spin ', ispin
363 WRITE (u,
'(T2,A,T61,F20.3)')
'evGW0 HOMO (eV)', band(1)*
evolt
364 WRITE (u,
'(T2,A,T61,F20.3)')
'evGW0 LUMO (eV)', band(2)*
evolt
365 WRITE (u,
'(T2,A,T61,F20.3)')
'evGW0 HOMO-LUMO gap (eV)', band(3)*
evolt
368 band_prev(:, ispin) = band(:)
373 converged = (max_delta < bs_env%evgw0_eps_iter)
374 IF (u > 0)
WRITE (u,
'(T2,A,T61,F20.6)')
'Max. change to previous cycle (eV)', &
378 IF (u > 0)
WRITE (u,
'(T2,A)') repeat(
'-', 79)
383 WRITE (u,
'(T2,A,I4,A)') &
384 'evGW0 eigenvalue self-consistency reached in', i_iter,
' cycles.'
387 ELSE IF (i_iter == n_iter)
THEN
388 CALL cp_warn(__location__, &
389 "The evGW0 eigenvalue self-consistency cycle did not converge "// &
390 "within MAX_ITER cycles. The reported quasiparticle energies are "// &
391 "those of the last cycle.")
394 CALL timestop(handle)
396 END SUBROUTINE print_evgw0_band_edges
402 SUBROUTINE print_ri_rs_memory_estimate(bs_env)
406 CHARACTER(LEN=*),
PARAMETER :: routinen =
'print_ri_rs_memory_estimate'
408 CHARACTER(LEN=max_line_length) :: msg
409 INTEGER :: handle, ipan, n_grid_total, n_procs, &
410 n_ri, pan_rows, pan_width
411 INTEGER(KIND=int_8) :: nze_tmpl
412 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: pan_first, pan_last
413 INTEGER,
DIMENSION(:),
POINTER :: r_blk_sizes
414 LOGICAL :: use_cutoff
415 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: grid_used
416 REAL(kind=
dp) :: mem_avail_gb, mem_pan_gb, mem_panels_gb, &
419 CALL timeset(routinen, handle)
421 n_grid_total = bs_env%ri_rs%n_grid_points
422 CALL dbcsr_get_info(bs_env%ri_rs%mat_phi_mu_l, row_blk_size=r_blk_sizes)
423 cpassert(sum(r_blk_sizes) == n_grid_total)
425 n_procs = bs_env%para_env%num_pe
429 mem_z_lp_gb = real(n_grid_total,
dp)*real(n_ri,
dp)*8.0_dp/ &
430 REAL(n_procs,
dp)*1.0e-9_dp
437 use_cutoff = bs_env%ri_rs%cutoff_radius_v_w > 0.0_dp .AND. &
438 ALLOCATED(bs_env%ri_rs%chunk_centroids)
440 pan_first, pan_last, bs_env%ri_rs%cutoff_radius_v_w)
441 mem_panels_gb = 0.0_dp
442 DO ipan = 1,
SIZE(pan_first)
443 pan_rows = sum(r_blk_sizes(pan_first(ipan):pan_last(ipan)))
446 pan_last(ipan), bs_env%ri_rs%cutoff_radius_v_w, &
448 pan_width = sum(r_blk_sizes, mask=grid_used)
450 grid_used, pan_first(ipan), pan_last(ipan), &
451 bs_env%ri_rs%cutoff_radius_v_w, nze_tmpl)
453 pan_width = n_grid_total
454 nze_tmpl = int(pan_rows,
int_8)*int(pan_width,
int_8)
457 n_ri, bs_env%n_ao, n_procs, mem_pan_gb)
458 mem_panels_gb = max(mem_panels_gb, mem_pan_gb)
460 mem_panels_gb = mem_panels_gb + &
461 REAL(n_ri,
dp)*
REAL(n_ri,
dp)*8.0_dp/
REAL(n_procs,
dp)*1.0e-9_dp
467 IF (bs_env%unit_nr > 0)
THEN
468 WRITE (bs_env%unit_nr,
'(A)')
' '
469 WRITE (bs_env%unit_nr,
'(T2,A)')
'RI-RS memory estimate per MPI process:'
470 WRITE (bs_env%unit_nr,
'(T4,A,F37.2,A)') &
471 'Available memory per process (system)', mem_avail_gb,
' GB'
472 WRITE (bs_env%unit_nr,
'(T4,A,F18.2,A)') &
473 'Required for Z_lP (dense upper bound; actual is sparser)', mem_z_lp_gb,
' GB'
474 WRITE (bs_env%unit_nr,
'(T4,A,F25.2,A)') &
475 'Required for χ, W, Σ panels (peak per panel step)', mem_panels_gb,
' GB'
476 IF (bs_env%ri_rs%Z_lP_exists .AND. .NOT. bs_env%auto_ri%enabled)
THEN
477 WRITE (bs_env%unit_nr,
'(T4,A)')
'Z_lP fitting skipped (matrix read from restart)'
482 IF (mem_avail_gb > 0.0_dp .AND. mem_z_lp_gb > mem_avail_gb)
THEN
483 WRITE (msg,
'(A,F0.2,A,F0.2,A)') &
484 "The estimated memory for Z_lP, ", mem_z_lp_gb,
" GB per process, exceeds the "// &
485 "available ", mem_avail_gb,
" GB. Z_lP (n_grid x n_RI) is distributed across all "// &
486 "MPI ranks, so add nodes or use fewer MPI ranks per node."
490 IF (mem_avail_gb > 0.0_dp .AND. mem_panels_gb > mem_avail_gb)
THEN
491 WRITE (msg,
'(A,F0.2,A,F0.2,A)') &
492 "The estimated peak memory of the chi/W/Sigma panels, ", mem_panels_gb, &
493 " GB per process, exceeds the available ", mem_avail_gb,
" GB. Panel memory "// &
494 "scales roughly as 3*panel_size*n_grid/n_procs, so add nodes, use fewer MPI ranks "// &
499 CALL timestop(handle)
501 END SUBROUTINE print_ri_rs_memory_estimate
511 SUBROUTINE compute_qp_energies(bs_env, fm_Sigma_x_Gamma, fm_Sigma_c_Gamma_time, i_iter)
514 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_sigma_x_gamma
515 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :, :) :: fm_sigma_c_gamma_time
516 INTEGER,
INTENT(IN) :: i_iter
518 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_QP_energies'
520 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:, :) :: sigma_c_n_freq
521 INTEGER :: handle, ispin, j_t
522 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: sigma_x_n, v_xc_n
523 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: sigma_c_n_time
524 TYPE(
cp_fm_type) :: fm_ks, fm_mos, fm_s, fm_work
526 CALL timeset(routinen, handle)
528 CALL cp_fm_create(fm_ks, bs_env%fm_s_Gamma%matrix_struct)
529 CALL cp_fm_create(fm_s, bs_env%fm_s_Gamma%matrix_struct)
530 CALL cp_fm_create(fm_mos, bs_env%fm_s_Gamma%matrix_struct)
531 CALL cp_fm_create(fm_work, bs_env%fm_s_Gamma%matrix_struct)
533 ALLOCATE (v_xc_n(bs_env%n_ao), sigma_x_n(bs_env%n_ao))
534 ALLOCATE (sigma_c_n_time(bs_env%n_ao, bs_env%num_time_freq_points, 2))
535 ALLOCATE (sigma_c_n_freq(bs_env%n_ao, bs_env%num_freq_points_fit))
537 DO ispin = 1, bs_env%n_spin
542 CALL cp_fm_geeig(fm_ks, fm_s, fm_mos, bs_env%eigenval_scf(:, 1, ispin), fm_work)
545 CALL to_gamma_and_mo_real(v_xc_n, bs_env%fm_V_xc_Gamma(ispin), fm_mos)
546 CALL to_gamma_and_mo_real(sigma_x_n, fm_sigma_x_gamma(ispin), fm_mos)
549 DO j_t = 1, bs_env%num_time_freq_points
550 CALL to_gamma_and_mo_real(sigma_c_n_time(:, j_t,
positive_time), &
552 CALL to_gamma_and_mo_real(sigma_c_n_time(:, j_t,
negative_time), &
558 sigma_c_n_freq(1:bs_env%n_occ(ispin), :) = conjg(sigma_c_n_freq(1:bs_env%n_occ(ispin), :))
562 bs_env%eigenval_scf(:, 1, ispin), 1, ispin, i_iter)
576 CALL timestop(handle)
578 END SUBROUTINE compute_qp_energies
586 SUBROUTINE to_gamma_and_mo_real(array_n, fm_Gamma, fm_mos)
588 REAL(kind=
dp),
DIMENSION(:) :: array_n
591 CHARACTER(LEN=*),
PARAMETER :: routinen =
'to_Gamma_and_mo_real'
596 CALL timeset(routinen, handle)
607 CALL timestop(handle)
609 END SUBROUTINE to_gamma_and_mo_real
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public cp_fm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work)
General Eigenvalue Problem AX = BXE. Use cuSOLVERMp directly when requested and large enough; otherwi...
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_diag(matrix, diag, n_active)
returns the diagonal elements of a fm
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
Coulomb matrices and screened interactions for imaginary-time GW.
subroutine, public compute_w(bs_env, qs_env, mat_chi_gamma_tau, fm_w_time)
Computes the screened Coulomb interaction on the imaginary-time grid, entirely in the RI auxiliary (P...
Shared RI-RS polarizability and self-energy assembly.
subroutine, public compute_sigma_c(bs_env, fm_w_time, fm_sigma_c_gamma_time, cutoff, keep_w_and_files)
Computes the correlation part of the GW self-energy on the imaginary-time grid: Σ^c_λσ(iτ<0) = -Σ_ll'...
subroutine, public get_mat_chi_gamma_tau(bs_env, mat_chi_gamma_tau, cutoff)
Computes χ_PQ(iτ) from the occupied and virtual Green's functions.
subroutine, public compute_sigma_x(bs_env, qs_env, fm_sigma_x_gamma, cutoff)
Computes the exact-exchange part of the GW self-energy: D_μν = Σ_n^occ C_μn C_νn (density matrix = G^...
GW using RI-RS Approximation for molecules.
subroutine, public gw_calc_ri_rs_non_periodic(qs_env, bs_env)
GW calculation using RI-RS formalism for molecules.
Routines from paper [Graml2024].
subroutine, public delete_unnecessary_files(bs_env)
...
Full-matrix operations not provided by the CP2K FM packages.
subroutine, public de_init_bs_env(qs_env, bs_env)
Releases the memory-heavy GW intermediates that cannot be freed in bs_env_release,...
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, i_iter)
...
Defines the basic variable types.
integer, parameter, public max_line_length
integer, parameter, public int_8
integer, parameter, public dp
Interface to the message passing library MPI.
subroutine, public mp_mem_avail_per_rank_gb(comm, mem_avail_gb)
Memory that is currently free on the node, per MPI rank of that node, in GB.
subroutine, public mp_print_mem_per_rank(comm, unit_nr, label)
Prints the memory available to and used by a single MPI rank at the moment of the call....
Definition of physical constants:
real(kind=dp), parameter, public evolt
subroutine, public get_all_vbm_cbm_bandgaps(bs_env)
...
DBCSR collocation, layouts and panel contractions for real-space resolution of the identity.
subroutine, public resolve_grid_panels(ri_rs, para_env, msg_elem_limit, pan_first, pan_last, cutoff)
Resolve and cache grid-panel boundaries for RI-RS streaming contractions.
subroutine, public panel_template_elems(r_blk_sizes, centroids, used, blk0, blk1, cutoff, nze_tmpl)
Exact allocated-element count of the geo template of panel [blk0, blk1]: the very same per-block-pair...
subroutine, public panel_mem_estimate_gb(nze_tmpl, pan_rows, width, n_grid_total, n_ri, n_ao, n_procs, mem_gb)
Per-rank peak memory (GB) of one panel step of the neighborhood-restricted contractions: up to three ...
subroutine, public mask_grid_blocks_near_panel(centroids, blk0, blk1, cutoff, used)
Marks the grid blocks whose centroid lies within cutoff of the bounding box of the panel [blk0,...
Builds the shared RI-RS grid, AO collocation and fitting representation.
subroutine, public ensure_ri_rs_representation(qs_env, bs_env)
Populate the RI-RS grid, AO collocation and auxiliary fitting coefficients once. Periodic systems use...
Definition and construction of time/frequency grids for correlation methods.
subroutine, public transform_time_to_frequency(grid, samples_tau, values_omega)
Transform real positive/negative-time samples to complex positive-frequency values....
integer, parameter, public negative_time
integer, parameter, public positive_time