55#include "../base/base_uses.f90"
61 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'rt_bse_ri_rs'
88 CHARACTER(LEN=*),
PARAMETER :: routinen =
'rt_bse_ri_rs_ensure_grid'
93 CALL timeset(routinen, handle)
95 IF (bs_env%ri_rs%grid_built)
THEN
105 IF (.NOT.
ALLOCATED(bs_env%ri_rs%radius_ao_per_atom))
THEN
108 CALL atomic_basis_at_grid_point(qs_env, bs_env, bs_env%ri_rs%grid_points, &
109 bs_env%ri_rs%mat_phi_mu_l)
110 CALL compute_coeff_z_lp(qs_env, bs_env, bs_env%ri_rs%grid_points, &
111 bs_env%ri_rs%mat_phi_mu_l, bs_env%ri_rs%mat_Z_lP)
113 bs_env%ri_rs%grid_built = .true.
115 IF (bs_env%unit_nr > 0)
THEN
116 WRITE (bs_env%unit_nr,
'(T2,A,T58,A,F7.1,A)') &
117 'Built RI-RS grid for RT-BSE (no GW_RI_RS used),',
' Execution time', &
119 WRITE (bs_env%unit_nr,
'(A)')
' '
122 CALL timestop(handle)
140 CHARACTER(LEN=*),
PARAMETER :: routinen =
'rt_bse_ri_rs_ensure_V_grid'
143 INTEGER,
DIMENSION(:),
POINTER :: blk_aux, dist_row_aux
145 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_vtr_gamma
148 CALL timeset(routinen, handle)
150 IF (bs_env%ri_rs%V_grid_built)
THEN
151 CALL timestop(handle)
161 bs_env%trunc_coulomb, do_kpoints=.false.)
166 CALL dbcsr_create(bs_env%ri_rs%mat_V_aux_rtbse,
"V_aux_rtbse", dist_aux_aux, &
167 dbcsr_type_no_symmetry, blk_aux, blk_aux)
169 keep_sparsity=.false.)
171 bs_env%ri_rs%V_grid_built = .true.
173 IF (bs_env%unit_nr > 0)
THEN
174 WRITE (bs_env%unit_nr,
'(T2,A,T57,A,F7.1,A)') &
175 'Precomputed RT-BSE RI-RS V_aux kernel,',
' Execution time', &
177 WRITE (bs_env%unit_nr,
'(A)')
' '
183 CALL timestop(handle)
201 CHARACTER(LEN=*),
PARAMETER :: routinen =
'rt_bse_ri_rs_ensure_W0_grid'
204 INTEGER,
DIMENSION(:),
POINTER :: blk_aux, blk_grid, dist_col_grid, &
207 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:, :) :: fm_vtr_gamma
209 TYPE(
dbcsr_type) :: matrix_v_aux, matrix_w_aux
211 CALL timeset(routinen, handle)
213 IF (bs_env%ri_rs%W0_grid_built)
THEN
214 CALL timestop(handle)
220 IF (.NOT.
ASSOCIATED(bs_env%fm_W_MIC_freq_zero%matrix_struct))
THEN
221 CALL cp_abort(__location__, &
222 "RT-BSE RI-RS kernel needs the screened interaction W(w=0), which the GW "// &
223 "step did not build. Select the RT-BSE propagator with '&RTBSE' or "// &
224 "'&RTBSE RTBSE', not '&RTBSE TDDFT'.")
235 bs_env%trunc_coulomb, do_kpoints=.false.)
238 CALL dbcsr_create(matrix_v_aux,
"V_aux_rtbse_W0", dist_aux_aux, dbcsr_type_no_symmetry, &
240 CALL copy_fm_to_dbcsr(fm_vtr_gamma(1, 1), matrix_v_aux, keep_sparsity=.false.)
242 CALL dbcsr_create(matrix_w_aux,
"W_aux_rtbse", dist_aux_aux, dbcsr_type_no_symmetry, &
244 CALL copy_fm_to_dbcsr(bs_env%fm_W_MIC_freq_zero, matrix_w_aux, keep_sparsity=.false.)
245 CALL dbcsr_add(matrix_w_aux, matrix_v_aux, 1.0_dp, 1.0_dp)
247 CALL dbcsr_create(bs_env%ri_rs%mat_W0_grid_rtbse,
"W0_grid_rtbse", dist_grid_grid, &
248 dbcsr_type_no_symmetry, blk_grid, blk_grid)
249 CALL contract_a_b_a(
"N",
"T", bs_env%ri_rs%mat_Z_lP, matrix_w_aux, &
250 bs_env%ri_rs%mat_W0_grid_rtbse, bs_env%eps_filter)
252 bs_env%ri_rs%W0_grid_built = .true.
253 bs_env%ri_rs%rtbse_kernels_ready = .true.
255 IF (bs_env%unit_nr > 0)
THEN
256 WRITE (bs_env%unit_nr,
'(T2,A,T57,A,F7.1,A)') &
257 'Precomputed RT-BSE RI-RS W0_grid kernel,',
' Execution time', &
259 WRITE (bs_env%unit_nr,
'(A)')
' '
264 m1=matrix_v_aux, m2=matrix_w_aux)
267 CALL timestop(handle)
288 TYPE(
cp_fm_type),
INTENT(INOUT) :: sigma_ao_fm
289 REAL(kind=
dp),
INTENT(IN) :: prefactor
291 REAL(kind=
dp),
INTENT(INOUT),
OPTIONAL :: grid_diag_accum(:)
293 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_sigma_ri_rs'
295 INTEGER :: handle, n_grid
296 INTEGER,
DIMENSION(:),
POINTER :: blk_ao, blk_grid, dist_col_grid, &
298 REAL(kind=
dp),
ALLOCATABLE :: diag_local(:)
300 TYPE(
dbcsr_type) :: matrix_rho_ao, matrix_rho_grid, &
303 CALL timeset(routinen, handle)
305 cpassert(bs_env%ri_rs%W0_grid_built)
311 CALL dbcsr_create(matrix_rho_ao,
"rho_AO_ri_rs", dist_ao_ao, dbcsr_type_no_symmetry, &
316 CALL dbcsr_create(matrix_rho_grid,
"rho_grid_ri_rs", dist_grid_grid, &
317 dbcsr_type_no_symmetry, blk_grid, blk_grid)
323 CALL contract_a_b_a(
"N",
"T", bs_env%ri_rs%mat_phi_mu_l, matrix_rho_ao, &
324 matrix_rho_grid, 0.0_dp)
331 IF (
PRESENT(grid_diag_accum))
THEN
332 n_grid =
SIZE(grid_diag_accum)
333 ALLOCATE (diag_local(n_grid))
336 CALL bs_env%para_env%sum(diag_local)
337 grid_diag_accum(:) = grid_diag_accum(:) + diag_local(:)
338 DEALLOCATE (diag_local)
346 CALL dbcsr_create(matrix_sigma_ao, template=matrix_rho_ao)
348 CALL contract_a_b_a(
"T",
"N", bs_env%ri_rs%mat_phi_mu_l, matrix_rho_grid, &
349 matrix_sigma_ao, 0.0_dp)
355 m1=matrix_rho_ao, m2=matrix_sigma_ao)
359 CALL timestop(handle)
375 grid_diag_re_accum, grid_diag_im_accum)
379 REAL(kind=
dp),
INTENT(IN) :: prefactor
381 REAL(kind=
dp),
INTENT(INOUT),
OPTIONAL :: grid_diag_re_accum(:), &
382 grid_diag_im_accum(:)
384 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_sigma_ri_rs_complex'
390 CALL timeset(routinen, handle)
392 CALL cp_fm_create(fm_rho, bs_env%fm_s_Gamma%matrix_struct)
393 CALL cp_fm_create(fm_sigma, bs_env%fm_s_Gamma%matrix_struct)
394 CALL cp_cfm_create(cfm_real_part, bs_env%fm_s_Gamma%matrix_struct)
399 grid_diag_accum=grid_diag_re_accum)
400 CALL cp_fm_to_cfm(msourcer=fm_sigma, mtarget=cfm_real_part)
404 grid_diag_accum=grid_diag_im_accum)
405 CALL cp_fm_to_cfm(msourcei=fm_sigma, mtarget=sigma_ao_cfm)
408 cmplx(1.0_dp, 0.0_dp, kind=
dp), cfm_real_part)
414 CALL timestop(handle)
434 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_hartree_ri_rs'
436 INTEGER :: handle, n_grid
437 INTEGER,
DIMENSION(:),
POINTER :: blk_ao, blk_grid, dist_col_grid, &
439 REAL(kind=
dp),
ALLOCATABLE :: n_vec(:)
441 TYPE(
dbcsr_type) :: matrix_rho_ao, matrix_rho_grid
443 CALL timeset(routinen, handle)
445 cpassert(bs_env%ri_rs%V_grid_built)
451 CALL dbcsr_create(matrix_rho_ao,
"rho_AO_hartree", dist_ao_ao, dbcsr_type_no_symmetry, &
455 n_grid = sum(blk_grid)
456 ALLOCATE (n_vec(n_grid))
461 CALL dbcsr_create(matrix_rho_grid,
"rho_grid_hartree", dist_grid_grid, &
462 dbcsr_type_no_symmetry, blk_grid, blk_grid)
467 CALL contract_a_b_a(
"N",
"T", bs_env%ri_rs%mat_phi_mu_l, matrix_rho_ao, &
468 matrix_rho_grid, 0.0_dp)
471 CALL bs_env%para_env%sum(n_vec)
482 CALL timestop(handle)
499 REAL(kind=
dp),
INTENT(IN) :: n_vec(:)
502 CHARACTER(LEN=*),
PARAMETER :: routinen =
'hartree_potential_from_diag_ri_rs'
505 INTEGER,
DIMENSION(:),
POINTER :: blk_ao, dist_row_ao
506 REAL(kind=
dp),
ALLOCATABLE :: u_ri(:), v_vec(:), w_ri(:)
510 CALL timeset(routinen, handle)
512 cpassert(bs_env%ri_rs%V_grid_built)
515 ALLOCATE (v_vec(
SIZE(n_vec)))
518 ALLOCATE (w_ri(bs_env%n_RI), u_ri(bs_env%n_RI))
520 CALL dbcsr_matvec_replicated(bs_env%ri_rs%mat_Z_lP, n_vec, w_ri, bs_env%para_env, &
523 CALL dbcsr_matvec_replicated(bs_env%ri_rs%mat_V_aux_rtbse, w_ri, u_ri, bs_env%para_env)
525 CALL dbcsr_matvec_replicated(bs_env%ri_rs%mat_Z_lP, u_ri, v_vec, bs_env%para_env)
526 DEALLOCATE (w_ri, u_ri)
529 CALL dbcsr_create(matrix_phi, template=bs_env%ri_rs%mat_phi_mu_l)
530 CALL dbcsr_copy(matrix_phi, bs_env%ri_rs%mat_phi_mu_l)
531 CALL dbcsr_scale_rows_replicated(matrix_phi, v_vec)
533 CALL dbcsr_create(matrix_v_h_ao,
"V_H_AO_hartree", dist_ao_ao, dbcsr_type_no_symmetry, &
536 CALL dbcsr_multiply(
"T",
"N", 1.0_dp, bs_env%ri_rs%mat_phi_mu_l, matrix_phi, &
537 0.0_dp, matrix_v_h_ao, filter_eps=0.0_dp)
547 CALL timestop(handle)
565 REAL(kind=
dp),
INTENT(IN) :: n_re(:)
567 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: n_im(:)
569 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_hartree_ri_rs_from_diag'
575 CALL timeset(routinen, handle)
577 CALL cp_fm_create(fm_v, bs_env%fm_s_Gamma%matrix_struct)
580 IF (
PRESENT(n_im))
THEN
581 CALL cp_cfm_create(cfm_real_part, bs_env%fm_s_Gamma%matrix_struct)
586 cmplx(1.0_dp, 0.0_dp, kind=
dp), cfm_real_part)
594 CALL timestop(handle)
612 CHARACTER(LEN=*),
PARAMETER :: routinen =
'compute_hartree_ri_rs_complex'
618 CALL timeset(routinen, handle)
620 CALL cp_fm_create(fm_rho, bs_env%fm_s_Gamma%matrix_struct)
621 CALL cp_fm_create(fm_v, bs_env%fm_s_Gamma%matrix_struct)
622 CALL cp_cfm_create(cfm_real_part, bs_env%fm_s_Gamma%matrix_struct)
633 cmplx(1.0_dp, 0.0_dp, kind=
dp), cfm_real_part)
639 CALL timestop(handle)
649 SUBROUTINE dbcsr_scale_rows_replicated(matrix, vec)
652 REAL(kind=
dp),
INTENT(IN) :: vec(:)
654 INTEGER :: col_blk, ic, ir, nblkrows_total, &
656 INTEGER,
ALLOCATABLE :: row_offset(:)
657 INTEGER,
DIMENSION(:),
POINTER :: row_blk_size
658 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: blk
661 CALL dbcsr_get_info(matrix, nblkrows_total=nblkrows_total, row_blk_size=row_blk_size)
662 ALLOCATE (row_offset(nblkrows_total + 1))
664 DO ir = 1, nblkrows_total
665 row_offset(ir + 1) = row_offset(ir) + row_blk_size(ir)
671 row_off = row_offset(row_blk)
672 DO ic = 1,
SIZE(blk, 2)
673 DO ir = 1,
SIZE(blk, 1)
674 blk(ir, ic) = vec(row_off + ir)*blk(ir, ic)
680 DEALLOCATE (row_offset)
682 END SUBROUTINE dbcsr_scale_rows_replicated
694 SUBROUTINE dbcsr_matvec_replicated(matrix, vec_in, vec_out, para_env, transposed)
697 REAL(kind=
dp),
INTENT(IN) :: vec_in(:)
698 REAL(kind=
dp),
INTENT(INOUT) :: vec_out(:)
700 LOGICAL,
INTENT(IN),
OPTIONAL :: transposed
702 INTEGER :: col_blk, col_off, ic, ir, &
703 nblkcols_total, nblkrows_total, &
705 INTEGER,
ALLOCATABLE :: col_offset(:), row_offset(:)
706 INTEGER,
DIMENSION(:),
POINTER :: col_blk_size, row_blk_size
708 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: block
712 IF (
PRESENT(transposed)) my_trans = transposed
715 nblkcols_total=nblkcols_total, &
716 row_blk_size=row_blk_size, col_blk_size=col_blk_size)
718 ALLOCATE (row_offset(nblkrows_total + 1), col_offset(nblkcols_total + 1))
720 DO ir = 1, nblkrows_total
721 row_offset(ir + 1) = row_offset(ir) + row_blk_size(ir)
724 DO ic = 1, nblkcols_total
725 col_offset(ic + 1) = col_offset(ic) + col_blk_size(ic)
733 row_off = row_offset(row_blk)
734 col_off = col_offset(col_blk)
736 DO ic = 1,
SIZE(block, 2)
737 DO ir = 1,
SIZE(block, 1)
738 vec_out(col_off + ic) = vec_out(col_off + ic) + &
739 block(ir, ic)*vec_in(row_off + ir)
743 DO ic = 1,
SIZE(block, 2)
744 DO ir = 1,
SIZE(block, 1)
745 vec_out(row_off + ir) = vec_out(row_off + ir) + &
746 block(ir, ic)*vec_in(col_off + ic)
753 DEALLOCATE (row_offset, col_offset)
755 CALL para_env%sum(vec_out)
757 END SUBROUTINE dbcsr_matvec_replicated
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_scale_and_add(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*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_to_fm(msource, mtargetr, mtargeti)
Copy real and imaginary parts of a complex full matrix into separate real-value full matrices.
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
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_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
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)
...
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_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_get_diag(matrix, diag)
Copies the diagonal elements from the given matrix into the given array.
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.
represent a full matrix distributed on many processors
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
GW using RI-RS Approximation for molecules.
subroutine, public release_dbcsr_topology_and_matrices(dist, mapped_dist, m1, m2, m3, m4)
DBCSR matrices deallocation.
subroutine, public hadamard_product_inplace(matrix_a, matrix_b, fac)
In-place Hadamard A <- fac * (A ◦ B). Value mutation only (no block insert/delete),...
subroutine, public contract_a_b_a(transa_left, transa_right, matrix_a, matrix_b, matrix_out, eps_filter)
Generalized routine to compute OUT = A * B * A^T OR OUT = A^T * B * A using DBCSR.
subroutine, public setup_square_topology(matrix_template, dim_type, square_dist, blk_sizes, mapped_dist)
DBCSR Topology Generation.
Routines from paper [Graml2024].
subroutine, public multiply_fm_w_mic_time_with_minv_gamma(bs_env, qs_env, fm_w_mic_time)
...
GW using RI-RS Approximation for molecules.
subroutine, public ri_rs_grid_assembler(qs_env, bs_env, ri_rs_grid_points)
Compute grid points for RI-RS Right now based on Ivan and Xavier implementation JCP 150,...
subroutine, public precompute_ri_rs_radii(qs_env, bs_env)
Compute per-atom AO and RI basis radii from the most diffuse Gaussian primitive in the AO ("ORB") and...
Defines the basic variable types.
integer, parameter, public dp
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
Interface to the message passing library MPI.
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)
...
RT-BSE RI-RS kernels: SEX and Hartree evaluated by collocation on grid points r_l....
subroutine, public compute_hartree_ri_rs_complex(bs_env, rho_ao_cfm, v_h_ao_cfm)
Complex-input Hartree potential via RI-RS. Re/Im split: feed each part to the real compute_hartree_ri...
subroutine, public rt_bse_ri_rs_ensure_w0_grid(bs_env, qs_env)
Build W^0_ll' = sum_PQ Z_lP (V + W^c(ω=0))_PQ Z_l'Q (statically screened W on the grid)....
subroutine, public hartree_potential_from_diag_ri_rs(bs_env, n_vec, v_h_ao_fm)
Hartree stages 2-3 from a precomputed grid density n_l (skips the stage-1 φρφ^T build): v_l = sum_PQl...
subroutine, public compute_sigma_ri_rs_complex(bs_env, sigma_ao_cfm, prefactor, rho_ao_cfm, grid_diag_re_accum, grid_diag_im_accum)
Complex-input AO SEX via Re/Im split: the kernel is real, so complex linearity holds as Σ[Δρ] = Σ[Re ...
subroutine, public rt_bse_ri_rs_ensure_grid(bs_env, qs_env)
Make sure the AO collocation φ_µ(r_l) (mat_phi_mu_l) and the RI fit coefficients Z_lP (mat_Z_lP) are ...
subroutine, public compute_sigma_ri_rs(bs_env, sigma_ao_fm, prefactor, rho_ao_fm, grid_diag_accum)
AO-domain SEX: Σ_µν = pref * sum_ll' φ_lµ [ρ^grid ∘ W^0]_ll' φ_l'ν, ρ^grid_ll' = sum_µν φ_lµ Δρ_µν φ_...
subroutine, public compute_hartree_ri_rs(bs_env, rho_ao_fm, v_h_ao_fm)
AO-domain Hartree via RI-RS: n_l = sum_µν φ_lµ Δρ_µν φ_lν = (φ ρ φ^T)_ll (diagonal of materialized gr...
subroutine, public compute_hartree_ri_rs_from_diag(bs_env, n_re, v_h_ao_cfm, n_im)
Complex Hartree from precomputed grid diagonals: V^H = V^H[n_re] + i V^H[n_im], each via hartree_pote...
subroutine, public rt_bse_ri_rs_ensure_v_grid(bs_env, qs_env)
Build V^aux_PQ = [M^-1 V^tr M^-1]_PQ (truncated Coulomb in the RI basis, M^-1-sandwiched to match the...
Represent a complex full matrix.
stores all the informations relevant to an mpi environment