(git:936074a)
Loading...
Searching...
No Matches
qs_tddfpt2_bse_utils.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
10 USE cp_dbcsr_api, ONLY: dbcsr_create,&
13 dbcsr_set,&
24 USE cp_fm_types, ONLY: cp_fm_create,&
32 USE kinds, ONLY: dp
39#include "./base/base_uses.f90"
40
41 IMPLICIT NONE
42
43 PRIVATE
44
45 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_tddfpt2_bse_utils'
46
47 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .false.
48 ! number of first derivative components (3: d/dx, d/dy, d/dz)
49 INTEGER, PARAMETER, PRIVATE :: nderivs = 3
50 INTEGER, PARAMETER, PRIVATE :: maxspins = 2
51
52 PUBLIC:: tddfpt_apply_bse
53 PUBLIC:: zeroth_order_gw
54
55CONTAINS
56! **************************************************************************************************
57!> \brief ...
58!> \param qs_env ...
59!> \param Aop_evects ...
60!> \param evects ...
61!> \param S_evects ...
62!> \param gs_mos ...
63!> \param matrix_s ...
64!> \param matrix_ks ...
65! **************************************************************************************************
66 SUBROUTINE zeroth_order_gw(qs_env, Aop_evects, evects, S_evects, gs_mos, matrix_s, matrix_ks)
67 TYPE(qs_environment_type), POINTER :: qs_env
68 TYPE(cp_fm_type), DIMENSION(:, :), INTENT(INOUT) :: aop_evects
69 TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN) :: evects, s_evects
70 TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
71 INTENT(in) :: gs_mos
72 TYPE(dbcsr_type), INTENT(in), POINTER :: matrix_s
73 TYPE(dbcsr_p_type), DIMENSION(:), INTENT(in) :: matrix_ks
74
75 CHARACTER(LEN=*), PARAMETER :: routinen = 'zeroth_order_gw'
76
77 INTEGER :: handle, i, ispin, ivect, j, nactive, &
78 nao, nmo, nspins, nvects, occ, virt
79 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: gw_occ, gw_virt
80 TYPE(cp_blacs_env_type), POINTER :: blacs_env
81 TYPE(cp_fm_struct_type), POINTER :: fmstruct, matrix_struct
82 TYPE(cp_fm_type) :: fms, hevec, matrixtmp, matrixtmp2, &
83 matrixtmp3, sweighted_vect, &
84 weighted_vect
85 TYPE(dbcsr_type) :: matrixf
86 TYPE(excited_energy_type), POINTER :: ex_env
87 TYPE(mp_para_env_type), POINTER :: para_env
88 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
89 POINTER :: sab_orb
90
91 CALL timeset(routinen, handle)
92
93 NULLIFY (ex_env, sab_orb)
94 CALL get_qs_env(qs_env, exstate_env=ex_env, sab_orb=sab_orb)
95
96 nspins = SIZE(matrix_ks, 1)
97 nspins = SIZE(evects, 1)
98 nvects = SIZE(evects, 2)
99
100 DO ispin = 1, nspins
101
102 cpassert(.NOT. ASSOCIATED(gs_mos(ispin)%evals_occ_matrix))
103
104 CALL dbcsr_create(matrixf, template=matrix_s)
105 nmo = SIZE(ex_env%gw_eigen)
106 CALL cp_fm_get_info(matrix=evects(ispin, 1), matrix_struct=matrix_struct, &
107 nrow_global=nao, ncol_global=nactive)
108 NULLIFY (blacs_env, para_env)
109 CALL get_qs_env(qs_env, para_env=para_env, blacs_env=blacs_env)
110
111 occ = SIZE(gs_mos(ispin)%evals_occ)
112 nactive = gs_mos(ispin)%nmo_active
113 nmo = SIZE(ex_env%gw_eigen)
114 virt = SIZE(gs_mos(ispin)%evals_virt)
115 NULLIFY (fmstruct)
116 CALL cp_fm_struct_create(fmstruct=fmstruct, para_env=para_env, &
117 context=blacs_env, nrow_global=virt, ncol_global=virt)
118 CALL cp_fm_create(matrixtmp, fmstruct)
119 CALL cp_fm_struct_release(fmstruct)
120
121 NULLIFY (fmstruct)
122 CALL cp_fm_struct_create(fmstruct=fmstruct, para_env=para_env, &
123 context=blacs_env, nrow_global=virt, ncol_global=nao)
124 CALL cp_fm_create(matrixtmp2, fmstruct)
125 CALL cp_fm_struct_release(fmstruct)
126
127 NULLIFY (fmstruct)
128 CALL cp_fm_struct_create(fmstruct=fmstruct, para_env=para_env, &
129 context=blacs_env, nrow_global=nao, ncol_global=nao)
130 CALL cp_fm_create(matrixtmp3, fmstruct)
131 CALL cp_fm_create(fms, fmstruct)
132 CALL cp_fm_struct_release(fmstruct)
133 CALL cp_dbcsr_alloc_block_from_nbl(matrixf, sab_orb)
134
135!--add virt eigenvalues
136 CALL dbcsr_set(matrixf, 0.0_dp)
137 CALL cp_fm_create(weighted_vect, gs_mos(ispin)%mos_virt%matrix_struct)
138 CALL cp_fm_create(sweighted_vect, gs_mos(ispin)%mos_virt%matrix_struct)
139 CALL cp_fm_to_fm(gs_mos(ispin)%mos_virt, weighted_vect)
140 CALL copy_dbcsr_to_fm(matrix_s, fms)
141
142 ALLOCATE (gw_virt(virt))
143 ALLOCATE (gw_occ(nactive))
144 gw_virt(1:virt) = ex_env%gw_eigen(occ + 1:nmo)
145 DO i = 1, nactive
146 j = gs_mos(ispin)%index_active(i)
147 gw_occ(i) = ex_env%gw_eigen(j)
148 END DO
149
150 CALL cp_fm_set_all(matrixtmp, 0.0_dp)
151 DO i = 1, virt
152 CALL cp_fm_set_element(matrixtmp, i, i, gw_virt(i))
153 END DO
154 DEALLOCATE (gw_virt)
155 CALL parallel_gemm('N', 'N', nao, virt, nao, 1.0_dp, fms, weighted_vect, 0.0_dp, sweighted_vect)
156 CALL parallel_gemm('N', 'T', virt, nao, virt, 1.0_dp, matrixtmp, sweighted_vect, 0.0_dp, matrixtmp2)
157 CALL parallel_gemm('N', 'N', nao, nao, virt, 1.0_dp, sweighted_vect, matrixtmp2, 0.0_dp, matrixtmp3)
158 CALL copy_fm_to_dbcsr(matrixtmp3, matrixf)
159
160 CALL cp_fm_release(weighted_vect)
161 CALL cp_fm_release(sweighted_vect)
162 CALL cp_fm_release(fms)
163!--add occ eigenvalues
164 CALL cp_fm_get_info(matrix=evects(ispin, 1), matrix_struct=matrix_struct, &
165 nrow_global=nao, ncol_global=nactive)
166 CALL cp_fm_create(hevec, matrix_struct)
167
168 DO ivect = 1, nvects
169 CALL cp_dbcsr_sm_fm_multiply(matrixf, evects(ispin, ivect), &
170 aop_evects(ispin, ivect), ncol=nactive, &
171 alpha=1.0_dp, beta=1.0_dp)
172
173 CALL cp_fm_to_fm(s_evects(ispin, ivect), hevec)
174 CALL cp_fm_column_scale(hevec, gw_occ)
175
176 CALL cp_fm_scale_and_add(1.0_dp, aop_evects(ispin, ivect), -1.0_dp, hevec)
177 END DO !ivect
178 DEALLOCATE (gw_occ)
179
180 CALL cp_fm_release(matrixtmp)
181 CALL cp_fm_release(matrixtmp2)
182 CALL cp_fm_release(matrixtmp3)
183
184 CALL dbcsr_release(matrixf)
185 CALL cp_fm_release(hevec)
186 END DO !ispin
187
188 virt = SIZE(aop_evects, 2)
189 CALL timestop(handle)
190
191 END SUBROUTINE zeroth_order_gw
192
193! **************************************************************************************************
194!> \brief Update action of TDDFPT operator on trial vectors by adding BSE W term.
195!> \param Aop_evects ...
196!> \param evects ...
197!> \param gs_mos ...
198!> \param qs_env ...
199!> \note Based on the subroutine tddfpt_apply_hfx() which was originally created by
200!> Mohamed Fawzi on 10.2002.
201! **************************************************************************************************
202 SUBROUTINE tddfpt_apply_bse(Aop_evects, evects, gs_mos, qs_env)
203
204 TYPE(cp_fm_type), DIMENSION(:, :), INTENT(INOUT) :: aop_evects
205 TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN) :: evects
206 TYPE(tddfpt_ground_state_mos), DIMENSION(:), &
207 INTENT(in) :: gs_mos
208 TYPE(qs_environment_type), POINTER :: qs_env
209
210 CHARACTER(LEN=*), PARAMETER :: routinen = 'tddfpt_apply_bse'
211
212 INTEGER :: a_nao_col, a_virt_col, b_nao_col, c_virt_col, handle, i_occ_row, i_row_global, &
213 ii, ispin, ivect, j_col_global, j_occ_row, jj, k_occ_col, mu_col_global, nao, ncol_block, &
214 ncol_local, nrow_block, nrow_local, nspins, nvects, nvirt
215 INTEGER, DIMENSION(2) :: nactive
216 INTEGER, DIMENSION(:), POINTER :: col_indices, row_indices
217 REAL(kind=dp) :: alpha
218 TYPE(cp_blacs_env_type), POINTER :: blacs_env
219 TYPE(cp_fm_struct_type), POINTER :: fmstruct, matrix_struct
220 TYPE(cp_fm_type) :: csvirt, fms, wxaoao, wxmat2, wxvirtao
221 TYPE(cp_fm_type), POINTER :: bse_w_matrix_mo
222 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
223 TYPE(excited_energy_type), POINTER :: ex_env
224 TYPE(mp_para_env_type), POINTER :: para_env
225
226 CALL timeset(routinen, handle)
227
228 nspins = SIZE(evects, 1)
229 nvects = SIZE(evects, 2)
230 IF (nspins > 1) THEN
231 alpha = 1.0_dp
232 ELSE
233 alpha = 2.0_dp
234 END IF
235 CALL cp_fm_get_info(gs_mos(1)%mos_occ, nrow_global=nao)
236 DO ispin = 1, nspins
237 CALL cp_fm_get_info(evects(ispin, 1), ncol_global=nactive(ispin))
238 END DO
239
240 NULLIFY (ex_env, para_env, blacs_env, matrix_s)
241 CALL get_qs_env(qs_env, exstate_env=ex_env, para_env=para_env, blacs_env=blacs_env, &
242 matrix_s=matrix_s)
243
244 CALL cp_fm_struct_create(fmstruct=fmstruct, para_env=para_env, &
245 context=blacs_env, nrow_global=nao, ncol_global=nao)
246 CALL cp_fm_create(fms, fmstruct)
247 CALL cp_fm_struct_release(fmstruct)
248 CALL copy_dbcsr_to_fm(matrix_s(1)%matrix, fms)
249
250 NULLIFY (bse_w_matrix_mo)
251 bse_w_matrix_mo => ex_env%bse_w_matrix_MO(1, 1)
252
253 DO ivect = 1, nvects
254 DO ispin = 1, nspins
255 NULLIFY (matrix_struct, fmstruct)
256 CALL cp_fm_get_info(matrix=evects(ispin, 1), matrix_struct=matrix_struct, &
257 nrow_global=nao, ncol_global=nactive(ispin))
258 nvirt = SIZE(gs_mos(ispin)%evals_virt)
259
260 CALL cp_fm_struct_create(fmstruct=fmstruct, para_env=para_env, &
261 context=blacs_env, nrow_global=nvirt, ncol_global=nao)
262 CALL cp_fm_create(csvirt, fmstruct)
263 CALL cp_fm_struct_release(fmstruct)
264
265 CALL cp_fm_struct_create(fmstruct=fmstruct, para_env=para_env, &
266 context=blacs_env, nrow_global=nactive(ispin)*nactive(ispin), &
267 ncol_global=nvirt*nao)
268 CALL cp_fm_create(wxvirtao, fmstruct)
269 CALL cp_fm_struct_release(fmstruct)
270 CALL cp_fm_set_all(wxvirtao, 0.0_dp)
271
272 CALL cp_fm_struct_create(fmstruct=fmstruct, para_env=para_env, &
273 context=blacs_env, nrow_global=nactive(ispin)*nactive(ispin), &
274 ncol_global=nao*nao)
275 CALL cp_fm_create(wxaoao, fmstruct)
276 CALL cp_fm_struct_release(fmstruct)
277 CALL cp_fm_set_all(wxaoao, 0.0_dp)
278
279 CALL parallel_gemm('T', 'N', nvirt, nao, nao, 1.0_dp, gs_mos(ispin)%mos_virt, fms, 0.0_dp, csvirt)
280 NULLIFY (row_indices, col_indices)
281 CALL cp_fm_get_info(matrix=wxvirtao, nrow_local=nrow_local, ncol_local=ncol_local, &
282 row_indices=row_indices, col_indices=col_indices, &
283 nrow_block=nrow_block, ncol_block=ncol_block)
284
285 CALL cp_fm_set_all(wxvirtao, 0.0_dp)
286 DO ii = 1, nrow_local
287 i_row_global = row_indices(ii)
288 DO jj = 1, ncol_local
289 j_col_global = col_indices(jj)
290
291 i_occ_row = (i_row_global - 1)/nactive(ispin) + 1
292 j_occ_row = mod(i_row_global - 1, nactive(ispin)) + 1
293
294 a_virt_col = (j_col_global - 1)/nao + 1
295 b_nao_col = mod(j_col_global - 1, nao) + 1
296
297 DO c_virt_col = 1, nvirt
298 mu_col_global = (a_virt_col - 1)*nvirt + c_virt_col
299
300 wxvirtao%local_data(i_row_global, j_col_global) = wxvirtao%local_data(i_row_global, j_col_global) + &
301 bse_w_matrix_mo%local_data(i_row_global, mu_col_global)*csvirt%local_data(c_virt_col, b_nao_col)
302
303 END DO
304 END DO
305 END DO
306
307 NULLIFY (row_indices, col_indices) ! redefine indices
308 CALL cp_fm_get_info(matrix=wxaoao, nrow_local=nrow_local, ncol_local=ncol_local, &
309 row_indices=row_indices, col_indices=col_indices, &
310 nrow_block=nrow_block, ncol_block=ncol_block)
311
312 CALL cp_fm_set_all(wxaoao, 0.0_dp)
313 DO ii = 1, nrow_local
314 i_row_global = row_indices(ii)
315 DO jj = 1, ncol_local
316 j_col_global = col_indices(jj)
317
318 i_occ_row = (i_row_global - 1)/nactive(ispin) + 1
319 j_occ_row = mod(i_row_global - 1, nactive(ispin)) + 1
320
321 a_nao_col = (j_col_global - 1)/nao + 1
322 b_nao_col = mod(j_col_global - 1, nao) + 1
323
324 DO k_occ_col = 1, nvirt
325 mu_col_global = (k_occ_col - 1)*nao + a_nao_col
326
327 wxaoao%local_data(i_row_global, j_col_global) = wxaoao%local_data(i_row_global, j_col_global) + &
328 wxvirtao%local_data(i_row_global, mu_col_global)*csvirt%local_data(k_occ_col, b_nao_col)
329
330 END DO
331 END DO
332 END DO
333
334 CALL cp_fm_release(wxvirtao)
335 CALL cp_fm_release(csvirt)
336
337 CALL cp_fm_struct_create(fmstruct=fmstruct, para_env=para_env, &
338 context=blacs_env, nrow_global=nao, ncol_global=nactive(ispin))
339 CALL cp_fm_create(wxmat2, fmstruct)
340 CALL cp_fm_struct_release(fmstruct)
341 CALL cp_fm_set_all(wxmat2, 0.0_dp)
342
343 DO ii = 1, nrow_local
344 i_row_global = row_indices(ii)
345 DO jj = 1, ncol_local
346 j_col_global = col_indices(jj)
347
348 i_occ_row = (i_row_global - 1)/nactive(ispin) + 1
349 j_occ_row = mod(i_row_global - 1, nactive(ispin)) + 1
350 a_nao_col = (j_col_global - 1)/nao + 1
351 b_nao_col = mod(j_col_global - 1, nao) + 1
352 IF (a_nao_col == b_nao_col) THEN
353 wxmat2%local_data(b_nao_col, i_occ_row) = wxmat2%local_data(b_nao_col, i_occ_row) + &
354 wxaoao%local_data(i_row_global, j_col_global)*evects(ispin, ivect)%local_data(a_nao_col, j_occ_row)
355 END IF
356 IF (a_nao_col /= b_nao_col) THEN
357 wxmat2%local_data(a_nao_col, i_occ_row) = wxmat2%local_data(a_nao_col, i_occ_row) + &
358 wxaoao%local_data(i_row_global, j_col_global)*evects(ispin, ivect)%local_data(b_nao_col, j_occ_row)
359 END IF
360 END DO
361 END DO
362
363 CALL cp_fm_release(wxaoao)
364
365 CALL cp_fm_scale_and_add(1.0_dp, aop_evects(ispin, ivect), -1.0_dp, wxmat2)
366
367 CALL cp_fm_release(wxmat2)
368
369 END do! ispin
370 END DO !ivect
371
372 CALL cp_fm_release(fms)
373
374 CALL timestop(handle)
375
376 END SUBROUTINE tddfpt_apply_bse
377END MODULE qs_tddfpt2_bse_utils
methods related to the blacs parallel environment
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
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.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
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....
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp, set_zero)
creates a new full matrix with the given structure
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_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_set_element(matrix, irow_global, icol_global, alpha)
sets an element of a matrix
Types for excited states potential energies.
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
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, 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, 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 neighbor list data types and the corresponding functionality.
subroutine, public zeroth_order_gw(qs_env, aop_evects, evects, s_evects, gs_mos, matrix_s, matrix_ks)
...
subroutine, public tddfpt_apply_bse(aop_evects, evects, gs_mos, qs_env)
Update action of TDDFPT operator on trial vectors by adding BSE W term.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
represent a full matrix
Contains information on the excited states energy.
stores all the informations relevant to an mpi environment
Ground state molecular orbitals.