Line data Source code
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 Utility method to build 3-center integrals for small cell GW
10 : ! **************************************************************************************************
11 : MODULE gw_utils_compute_integrals
12 : USE OMP_LIB, ONLY: omp_get_thread_num
13 : USE ai_contraction_sphi, ONLY: abc_contract_xsmm
14 : USE atomic_kind_types, ONLY: atomic_kind_type,&
15 : get_atomic_kind_set
16 : USE basis_set_types, ONLY: get_gto_basis_set,&
17 : gto_basis_set_p_type,&
18 : gto_basis_set_type
19 : USE cell_types, ONLY: cell_type,&
20 : get_cell,&
21 : pbc
22 : USE coulomb_integral_interface, ONLY: compute_coulomb_3c,&
23 : coulomb_integral_cleanup,&
24 : coulomb_integral_context_type,&
25 : coulomb_integral_init
26 : USE cp_array_utils, ONLY: cp_2d_r_p_type
27 : USE input_constants, ONLY: do_potential_coulomb,&
28 : do_potential_id,&
29 : do_potential_short,&
30 : do_potential_truncated
31 : USE integral_library_types, ONLY: coulomb_operator_type,&
32 : cutoff_screen_factor,&
33 : library_libint
34 : USE kinds, ONLY: dp
35 : USE message_passing, ONLY: mp_para_env_type
36 : USE orbital_pointers, ONLY: ncoset
37 : USE particle_types, ONLY: particle_type
38 : USE post_scf_bandstructure_types, ONLY: post_scf_bandstructure_type
39 : USE qs_environment_types, ONLY: get_qs_env,&
40 : qs_environment_type
41 : USE r12_fundamentals, ONLY: r12_fundamentals_init
42 :
43 : !$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num
44 : #include "./base/base_uses.f90"
45 :
46 : IMPLICIT NONE
47 :
48 : PRIVATE
49 :
50 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_utils_compute_integrals'
51 :
52 : PUBLIC :: build_3c_integral_block, build_3c_integral_block_ctx, &
53 : gw_3c_ctx_type, gw_3c_ctx_create, gw_3c_ctx_release, &
54 : gw_3c_ws_type, gw_3c_ws_create, gw_3c_ws_release
55 :
56 : ! **************************************************************************************************
57 : !> \brief Shared read-only context for repeated 3-center integral block builds: screening
58 : !> parameters, basis maxima, contracted sphi tables, and the one-time gamma /
59 : !> truncated-Coulomb table initializations. Create and release OUTSIDE any OMP parallel
60 : !> region; creation is MPI-collective when the potential is truncated.
61 : ! **************************************************************************************************
62 : TYPE gw_3c_ctx_type
63 : TYPE(coulomb_operator_type) :: potential_parameter = coulomb_operator_type()
64 : INTEGER :: op_ij = do_potential_id, &
65 : op_jk = do_potential_id
66 : REAL(KIND=dp) :: dr_ij = 0.0_dp, dr_jk = 0.0_dp, &
67 : dr_ik = 0.0_dp
68 : INTEGER :: maxli = 0, maxlj = 0, maxlk = 0, &
69 : max_am = 0, m_max = 0
70 : INTEGER :: max_ncoi = 0, max_ncoj = 0, max_ncok = 0
71 : INTEGER :: max_nsgfi = 0, max_nsgfj = 0, &
72 : max_nsgfk = 0, max_nset = 0, natom = 0
73 : TYPE(cp_2d_r_p_type), DIMENSION(:, :), POINTER :: spi => NULL(), tspj => NULL(), &
74 : spk => NULL()
75 : TYPE(gto_basis_set_p_type), DIMENSION(:), ALLOCATABLE :: basis_i, basis_j, basis_k
76 : INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_of
77 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set => NULL()
78 : TYPE(cell_type), POINTER :: cell => NULL()
79 : REAL(KIND=dp), DIMENSION(3, 3) :: hmat = 0.0_dp
80 : END TYPE gw_3c_ctx_type
81 :
82 : ! **************************************************************************************************
83 : !> \brief Per-thread workspace for 3-center integral block builds: libint object + contraction
84 : !> buffers. Each thread creates its own (inside the parallel region is fine).
85 : ! **************************************************************************************************
86 : TYPE gw_3c_ws_type
87 : TYPE(coulomb_integral_context_type) :: integrals = coulomb_integral_context_type()
88 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: cpp_buffer, ccp_buffer
89 : END TYPE gw_3c_ws_type
90 :
91 : CONTAINS
92 :
93 : ! **************************************************************************************************
94 : !> \brief Build the shared 3c-integral context from the band-structure environment and explicitly
95 : !> supplied potential and basis sets.
96 : !> \param ctx ...
97 : !> \param bs_env ...
98 : !> \param potential_parameter ...
99 : !> \param basis_j ...
100 : !> \param basis_k ...
101 : !> \param basis_i ...
102 : ! **************************************************************************************************
103 936 : SUBROUTINE gw_3c_ctx_create(ctx, bs_env, potential_parameter, basis_j, basis_k, basis_i)
104 : TYPE(gw_3c_ctx_type), INTENT(OUT) :: ctx
105 : TYPE(post_scf_bandstructure_type), POINTER :: bs_env
106 : TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
107 : TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_j, basis_k, basis_i
108 :
109 72 : CPASSERT(ASSOCIATED(bs_env%ri_rs%atomic_kind_set))
110 72 : CPASSERT(ASSOCIATED(bs_env%ri_rs%cell))
111 72 : CPASSERT(ASSOCIATED(bs_env%para_env))
112 72 : CPASSERT(ASSOCIATED(bs_env%ri_rs%particle_set))
113 :
114 : CALL gw_3c_ctx_create_core(ctx, potential_parameter, basis_j, basis_k, basis_i, &
115 : bs_env%ri_rs%atomic_kind_set, bs_env%ri_rs%cell, &
116 72 : bs_env%n_atom, bs_env%para_env, bs_env%ri_rs%particle_set)
117 72 : END SUBROUTINE gw_3c_ctx_create
118 :
119 : ! **************************************************************************************************
120 : !> \brief Build screening and contraction data shared by repeated 3c-integral block evaluations.
121 : !> \param ctx ...
122 : !> \param potential_parameter ...
123 : !> \param basis_j ...
124 : !> \param basis_k ...
125 : !> \param basis_i ...
126 : !> \param atomic_kind_set ...
127 : !> \param cell ...
128 : !> \param natom ...
129 : !> \param para_env ...
130 : !> \param particle_set ...
131 : ! **************************************************************************************************
132 181916 : SUBROUTINE gw_3c_ctx_create_core(ctx, potential_parameter, basis_j, basis_k, basis_i, &
133 : atomic_kind_set, cell, natom, para_env, particle_set)
134 : TYPE(gw_3c_ctx_type), INTENT(OUT) :: ctx
135 : TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
136 : TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_j, basis_k, basis_i
137 : TYPE(atomic_kind_type), DIMENSION(:), INTENT(IN), &
138 : POINTER :: atomic_kind_set
139 : TYPE(cell_type), INTENT(IN), POINTER :: cell
140 : INTEGER, INTENT(IN) :: natom
141 : TYPE(mp_para_env_type), INTENT(IN), POINTER :: para_env
142 : TYPE(particle_type), DIMENSION(:), INTENT(IN), &
143 : POINTER :: particle_set
144 :
145 : CHARACTER(LEN=*), PARAMETER :: routineN = 'gw_3c_ctx_create_core'
146 :
147 : INTEGER :: egfi, handle, ibasis, ilist, imax, iset, &
148 : jset, kset, l, nbasis, ncoi, npgf_l, &
149 : sgfi
150 12994 : INTEGER, DIMENSION(:), POINTER :: lmax_i, lmin_i, npgfi, npgfj, npgfk, &
151 12994 : nsgfi, nsgfj, nsgfk
152 : TYPE(gto_basis_set_type), POINTER :: basis_set
153 :
154 12994 : CALL timeset(routineN, handle)
155 :
156 12994 : ctx%potential_parameter = potential_parameter
157 12994 : ctx%op_ij = potential_parameter%potential_type
158 12994 : ctx%op_jk = do_potential_id
159 :
160 12994 : IF (ctx%op_ij == do_potential_truncated .OR. ctx%op_ij == do_potential_short) THEN
161 12994 : ctx%dr_ij = potential_parameter%cutoff_radius*cutoff_screen_factor
162 12994 : ctx%dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
163 0 : ELSE IF (ctx%op_ij == do_potential_coulomb) THEN
164 0 : ctx%dr_ij = 1000000.0_dp
165 0 : ctx%dr_ik = 1000000.0_dp
166 : END IF
167 :
168 12994 : ctx%cell => cell
169 12994 : ctx%natom = natom
170 12994 : ctx%particle_set => particle_set
171 12994 : CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=ctx%kind_of)
172 12994 : CALL get_cell(cell=ctx%cell, h=ctx%hmat)
173 :
174 51836 : ctx%basis_i = basis_i
175 51836 : ctx%basis_j = basis_j
176 51836 : ctx%basis_k = basis_k
177 :
178 : ! max l per basis for libint; max nset/nco/nsgf for the LIBXSMM contraction buffers
179 12994 : nbasis = SIZE(basis_i)
180 38842 : DO ibasis = 1, nbasis
181 : CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=imax, &
182 25848 : lmax=lmax_i, lmin=lmin_i, nset=iset, nsgf_set=nsgfi, npgf=npgfi)
183 25848 : ctx%maxli = MAX(ctx%maxli, imax)
184 25848 : ctx%max_nset = MAX(ctx%max_nset, iset)
185 65876 : ctx%max_nsgfi = MAX(ctx%max_nsgfi, MAXVAL(nsgfi))
186 65876 : ctx%max_ncoi = MAX(ctx%max_ncoi, MAXVAL(npgfi)*ncoset(ctx%maxli))
187 103740 : DO l = 0, imax
188 39050 : npgf_l = 0
189 108530 : DO jset = 1, iset
190 108530 : IF (lmin_i(jset) == l .AND. lmax_i(jset) == l) npgf_l = npgf_l + npgfi(jset)
191 : END DO
192 64898 : ctx%max_ncoi = MAX(ctx%max_ncoi, npgf_l*ncoset(l))
193 : END DO
194 : END DO
195 38842 : DO ibasis = 1, nbasis
196 : CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=imax, &
197 25848 : nset=jset, nsgf_set=nsgfj, npgf=npgfj)
198 25848 : ctx%maxlj = MAX(ctx%maxlj, imax)
199 25848 : ctx%max_nset = MAX(ctx%max_nset, jset)
200 77658 : ctx%max_nsgfj = MAX(ctx%max_nsgfj, MAXVAL(nsgfj))
201 116500 : ctx%max_ncoj = MAX(ctx%max_ncoj, MAXVAL(npgfj)*ncoset(ctx%maxlj))
202 : END DO
203 38842 : DO ibasis = 1, nbasis
204 : CALL get_gto_basis_set(gto_basis_set=basis_k(ibasis)%gto_basis_set, maxl=imax, &
205 25848 : nset=kset, nsgf_set=nsgfk, npgf=npgfk)
206 25848 : ctx%maxlk = MAX(ctx%maxlk, imax)
207 25848 : ctx%max_nset = MAX(ctx%max_nset, kset)
208 77658 : ctx%max_nsgfk = MAX(ctx%max_nsgfk, MAXVAL(nsgfk))
209 116500 : ctx%max_ncok = MAX(ctx%max_ncok, MAXVAL(npgfk)*ncoset(ctx%maxlk))
210 : END DO
211 12994 : ctx%m_max = ctx%maxli + ctx%maxlj + ctx%maxlk
212 12994 : ctx%max_am = MAX(ctx%maxli, ctx%maxlj, ctx%maxlk)
213 :
214 : ! contiguous (and for j transposed) sphi copies, shared read-only across threads
215 : ALLOCATE (ctx%spi(ctx%max_nset, nbasis), ctx%tspj(ctx%max_nset, nbasis), &
216 443422 : ctx%spk(ctx%max_nset, nbasis))
217 38842 : DO ibasis = 1, nbasis
218 117488 : DO iset = 1, ctx%max_nset
219 78646 : NULLIFY (ctx%spi(iset, ibasis)%array)
220 78646 : NULLIFY (ctx%tspj(iset, ibasis)%array)
221 104494 : NULLIFY (ctx%spk(iset, ibasis)%array)
222 : END DO
223 : END DO
224 51976 : DO ilist = 1, 3
225 129520 : DO ibasis = 1, nbasis
226 77544 : IF (ilist == 1) basis_set => basis_i(ibasis)%gto_basis_set
227 77544 : IF (ilist == 2) basis_set => basis_j(ibasis)%gto_basis_set
228 77544 : IF (ilist == 3) basis_set => basis_k(ibasis)%gto_basis_set
229 260174 : DO iset = 1, basis_set%nset
230 143648 : ncoi = basis_set%npgf(iset)*ncoset(basis_set%lmax(iset))
231 143648 : sgfi = basis_set%first_sgf(1, iset)
232 143648 : egfi = sgfi + basis_set%nsgf_set(iset) - 1
233 221192 : IF (ilist == 1) THEN
234 160112 : ALLOCATE (ctx%spi(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
235 333092 : ctx%spi(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
236 103620 : ELSE IF (ilist == 2) THEN
237 207240 : ALLOCATE (ctx%tspj(iset, ibasis)%array(basis_set%nsgf_set(iset), ncoi))
238 1646910 : ctx%tspj(iset, ibasis)%array(:, :) = TRANSPOSE(basis_set%sphi(1:ncoi, sgfi:egfi))
239 : ELSE
240 207240 : ALLOCATE (ctx%spk(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
241 1402588 : ctx%spk(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
242 : END IF
243 : END DO
244 : END DO
245 : END DO
246 :
247 : ! MPI-collective table preparation stays outside the per-thread workspace lifecycle.
248 12994 : CALL r12_fundamentals_init(ctx%m_max, potential_parameter, para_env)
249 :
250 12994 : CALL timestop(handle)
251 :
252 25988 : END SUBROUTINE gw_3c_ctx_create_core
253 :
254 : ! **************************************************************************************************
255 : !> \brief Releases the shared 3c-integral context.
256 : !> \param ctx ...
257 : ! **************************************************************************************************
258 12994 : SUBROUTINE gw_3c_ctx_release(ctx)
259 :
260 : TYPE(gw_3c_ctx_type), INTENT(INOUT) :: ctx
261 :
262 : INTEGER :: ibasis, iset
263 :
264 52830 : DO iset = 1, SIZE(ctx%spi, 1)
265 131476 : DO ibasis = 1, SIZE(ctx%spi, 2)
266 78646 : IF (ASSOCIATED(ctx%spi(iset, ibasis)%array)) DEALLOCATE (ctx%spi(iset, ibasis)%array)
267 78646 : IF (ASSOCIATED(ctx%tspj(iset, ibasis)%array)) DEALLOCATE (ctx%tspj(iset, ibasis)%array)
268 118482 : IF (ASSOCIATED(ctx%spk(iset, ibasis)%array)) DEALLOCATE (ctx%spk(iset, ibasis)%array)
269 : END DO
270 : END DO
271 12994 : DEALLOCATE (ctx%spi, ctx%tspj, ctx%spk)
272 12994 : NULLIFY (ctx%spi, ctx%tspj, ctx%spk, ctx%particle_set, ctx%cell)
273 12994 : IF (ALLOCATED(ctx%kind_of)) DEALLOCATE (ctx%kind_of)
274 12994 : IF (ALLOCATED(ctx%basis_i)) DEALLOCATE (ctx%basis_i)
275 12994 : IF (ALLOCATED(ctx%basis_j)) DEALLOCATE (ctx%basis_j)
276 12994 : IF (ALLOCATED(ctx%basis_k)) DEALLOCATE (ctx%basis_k)
277 :
278 12994 : END SUBROUTINE gw_3c_ctx_release
279 :
280 : ! **************************************************************************************************
281 : !> \brief Creates a per-thread 3c workspace: libint object + LIBXSMM contraction buffers.
282 : !> \param ws ...
283 : !> \param ctx ...
284 : ! **************************************************************************************************
285 13005 : SUBROUTINE gw_3c_ws_create(ws, ctx)
286 :
287 : TYPE(gw_3c_ws_type), INTENT(OUT) :: ws
288 : TYPE(gw_3c_ctx_type), INTENT(IN) :: ctx
289 :
290 : CALL coulomb_integral_init(ws%integrals, max_am_3c=ctx%max_am, &
291 13005 : derivative_order=0, library=library_libint)
292 0 : ALLOCATE (ws%cpp_buffer(ctx%max_nsgfj*ctx%max_ncok), &
293 65025 : ws%ccp_buffer(ctx%max_nsgfj*ctx%max_nsgfk*ctx%max_ncoi))
294 :
295 13005 : END SUBROUTINE gw_3c_ws_create
296 :
297 : ! **************************************************************************************************
298 : !> \brief Releases a per-thread 3c workspace.
299 : !> \param ws ...
300 : ! **************************************************************************************************
301 13005 : SUBROUTINE gw_3c_ws_release(ws)
302 :
303 : TYPE(gw_3c_ws_type), INTENT(INOUT) :: ws
304 :
305 13005 : CALL coulomb_integral_cleanup(ws%integrals)
306 13005 : DEALLOCATE (ws%cpp_buffer, ws%ccp_buffer)
307 :
308 13005 : END SUBROUTINE gw_3c_ws_release
309 :
310 : ! **************************************************************************************************
311 : !> \brief Computes the 3c integral block (mu(atom_j) nu(atom_k) | P(atom_i)) for ONE atom triple,
312 : !> accumulating into the caller-zeroed int_3c at the given block offsets.
313 : !> Thread-safe: reads the frozen ctx + read-only module tables, mutates only its arguments
314 : !> and the per-thread ws.
315 : !> \param int_3c pre-zeroed target; the triple's contribution is accumulated in place
316 : !> \param ctx shared context from gw_3c_ctx_create
317 : !> \param ws per-thread workspace from gw_3c_ws_create
318 : !> \param atom_j ...
319 : !> \param atom_k ...
320 : !> \param atom_i ...
321 : !> \param cell_j ...
322 : !> \param cell_k ...
323 : !> \param cell_i ...
324 : !> \param j_offset block offset of atom_j's first sgf in int_3c dim 1 (default 0)
325 : !> \param k_offset block offset of atom_k's first sgf in int_3c dim 2 (default 0)
326 : !> \param i_offset block offset of atom_i's first RI sgf in int_3c dim 3 (default 0)
327 : !> \param screened .TRUE. if the kind-radius screens killed the whole triple (int_3c untouched)
328 : ! **************************************************************************************************
329 13700 : SUBROUTINE build_3c_integral_block_ctx(int_3c, ctx, ws, atom_j, atom_k, atom_i, &
330 : cell_j, cell_k, cell_i, &
331 : j_offset, k_offset, i_offset, screened)
332 :
333 : REAL(KIND=dp), DIMENSION(:, :, :) :: int_3c
334 : TYPE(gw_3c_ctx_type), INTENT(IN) :: ctx
335 : TYPE(gw_3c_ws_type), INTENT(INOUT) :: ws
336 : INTEGER, INTENT(IN) :: atom_j, atom_k, atom_i
337 : INTEGER, DIMENSION(3), INTENT(IN), OPTIONAL :: cell_j, cell_k, cell_i
338 : INTEGER, INTENT(IN), OPTIONAL :: j_offset, k_offset, i_offset
339 : LOGICAL, INTENT(OUT), OPTIONAL :: screened
340 :
341 : INTEGER :: block_end_i, block_end_j, block_end_k, block_start_i, block_start_j, &
342 : block_start_k, ikind, iset, jkind, jset, kkind, kset, my_i_offset, my_j_offset, &
343 : my_k_offset, ncoi, ncoj, ncok, nseti, nsetj, nsetk, sgfi, sgfj, sgfk
344 : INTEGER, DIMENSION(3) :: my_cell_i, my_cell_j, my_cell_k
345 13700 : INTEGER, DIMENSION(:), POINTER :: lmax_i, lmax_j, lmax_k, lmin_i, lmin_j, &
346 13700 : lmin_k, npgfi, npgfj, npgfk, nsgfi, &
347 13700 : nsgfj, nsgfk
348 13700 : INTEGER, DIMENSION(:, :), POINTER :: first_sgf_i, first_sgf_j, first_sgf_k
349 : REAL(KIND=dp) :: dij, dik, djk, kind_radius_i, &
350 : kind_radius_j, kind_radius_k, sijk_ext
351 13700 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: sijk, sijk_contr
352 : REAL(KIND=dp), DIMENSION(3) :: ri, rij, rik, rj, rjk, rk
353 13700 : REAL(KIND=dp), DIMENSION(:), POINTER :: set_radius_i, set_radius_j, set_radius_k
354 13700 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: rpgf_i, rpgf_j, rpgf_k, zeti, zetj, zetk
355 :
356 276 : IF (PRESENT(screened)) screened = .FALSE.
357 :
358 13700 : my_cell_i(1:3) = 0
359 13700 : IF (PRESENT(cell_i)) my_cell_i(1:3) = cell_i(1:3)
360 13700 : my_cell_j(1:3) = 0
361 13700 : IF (PRESENT(cell_j)) my_cell_j(1:3) = cell_j(1:3)
362 13700 : my_cell_k(1:3) = 0
363 13700 : IF (PRESENT(cell_k)) my_cell_k(1:3) = cell_k(1:3)
364 13700 : my_i_offset = 0
365 13700 : IF (PRESENT(i_offset)) my_i_offset = i_offset
366 13700 : my_j_offset = 0
367 13700 : IF (PRESENT(j_offset)) my_j_offset = j_offset
368 13700 : my_k_offset = 0
369 13700 : IF (PRESENT(k_offset)) my_k_offset = k_offset
370 :
371 274000 : ri = pbc(ctx%particle_set(atom_i)%r(1:3), ctx%cell) + MATMUL(ctx%hmat, REAL(my_cell_i, dp))
372 274000 : rj = pbc(ctx%particle_set(atom_j)%r(1:3), ctx%cell) + MATMUL(ctx%hmat, REAL(my_cell_j, dp))
373 274000 : rk = pbc(ctx%particle_set(atom_k)%r(1:3), ctx%cell) + MATMUL(ctx%hmat, REAL(my_cell_k, dp))
374 :
375 54800 : rjk(1:3) = rk(1:3) - rj(1:3)
376 54800 : rij(1:3) = rj(1:3) - ri(1:3)
377 54800 : rik(1:3) = rk(1:3) - ri(1:3)
378 :
379 54800 : djk = NORM2(rjk)
380 54800 : dij = NORM2(rij)
381 54800 : dik = NORM2(rik)
382 :
383 13700 : ikind = ctx%kind_of(atom_i)
384 13700 : jkind = ctx%kind_of(atom_j)
385 13700 : kkind = ctx%kind_of(atom_k)
386 :
387 : CALL get_gto_basis_set(ctx%basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, &
388 : lmax=lmax_i, lmin=lmin_i, npgf=npgfi, nset=nseti, &
389 : nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
390 13700 : zet=zeti, kind_radius=kind_radius_i)
391 : CALL get_gto_basis_set(ctx%basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, &
392 : lmax=lmax_j, lmin=lmin_j, npgf=npgfj, nset=nsetj, &
393 : nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
394 13700 : zet=zetj, kind_radius=kind_radius_j)
395 : CALL get_gto_basis_set(ctx%basis_k(kkind)%gto_basis_set, first_sgf=first_sgf_k, &
396 : lmax=lmax_k, lmin=lmin_k, npgf=npgfk, nset=nsetk, &
397 : nsgf_set=nsgfk, pgf_radius=rpgf_k, set_radius=set_radius_k, &
398 13700 : zet=zetk, kind_radius=kind_radius_k)
399 :
400 : IF (kind_radius_j + kind_radius_i + ctx%dr_ij < dij .OR. &
401 13700 : kind_radius_j + kind_radius_k + ctx%dr_jk < djk .OR. &
402 : kind_radius_k + kind_radius_i + ctx%dr_ik < dik) THEN
403 0 : IF (PRESENT(screened)) screened = .TRUE.
404 0 : RETURN
405 : END IF
406 :
407 36127 : DO iset = 1, nseti
408 85482 : DO jset = 1, nsetj
409 49355 : IF (set_radius_j(jset) + set_radius_i(iset) + ctx%dr_ij < dij) CYCLE
410 177033 : DO kset = 1, nsetk
411 108995 : IF (set_radius_j(jset) + set_radius_k(kset) + ctx%dr_jk < djk) CYCLE
412 100895 : IF (set_radius_k(kset) + set_radius_i(iset) + ctx%dr_ik < dik) CYCLE
413 :
414 95353 : ncoi = npgfi(iset)*ncoset(lmax_i(iset))
415 95353 : ncoj = npgfj(jset)*ncoset(lmax_j(jset))
416 95353 : ncok = npgfk(kset)*ncoset(lmax_k(kset))
417 :
418 95353 : sgfi = first_sgf_i(1, iset)
419 95353 : sgfj = first_sgf_j(1, jset)
420 95353 : sgfk = first_sgf_k(1, kset)
421 :
422 95353 : IF (ncoj*ncok*ncoi <= 0) CYCLE
423 476765 : ALLOCATE (sijk(ncoj, ncok, ncoi))
424 95353 : sijk(:, :, :) = 0.0_dp
425 :
426 : CALL compute_coulomb_3c(ws%integrals, lmin_j(jset), lmax_j(jset), lmin_k(kset), lmax_k(kset), &
427 : lmin_i(iset), lmax_i(iset), npgfj(jset), npgfk(kset), npgfi(iset), zetj(:, jset), &
428 : zetk(:, kset), zeti(:, iset), rpgf_j(:, jset), rpgf_k(:, kset), rpgf_i(:, iset), rj, rk, ri, &
429 95353 : sijk, ctx%potential_parameter, dab=djk, dac=dij, dbc=dik, int_abc_ext=sijk_ext)
430 :
431 476765 : ALLOCATE (sijk_contr(nsgfj(jset), nsgfk(kset), nsgfi(iset)))
432 : CALL abc_contract_xsmm(sijk_contr, sijk, ctx%tspj(jset, jkind)%array, &
433 : ctx%spk(kset, kkind)%array, ctx%spi(iset, ikind)%array, &
434 : ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
435 95353 : nsgfi(iset), ws%cpp_buffer, ws%ccp_buffer)
436 95353 : DEALLOCATE (sijk)
437 :
438 95353 : block_start_j = sgfj + my_j_offset
439 95353 : block_end_j = sgfj + nsgfj(jset) - 1 + my_j_offset
440 95353 : block_start_k = sgfk + my_k_offset
441 95353 : block_end_k = sgfk + nsgfk(kset) - 1 + my_k_offset
442 95353 : block_start_i = sgfi + my_i_offset
443 95353 : block_end_i = sgfi + nsgfi(iset) - 1 + my_i_offset
444 :
445 : int_3c(block_start_j:block_end_j, &
446 : block_start_k:block_end_k, &
447 : block_start_i:block_end_i) = &
448 : int_3c(block_start_j:block_end_j, &
449 : block_start_k:block_end_k, &
450 : block_start_i:block_end_i) + &
451 1260128 : sijk_contr(:, :, :)
452 158350 : DEALLOCATE (sijk_contr)
453 :
454 : END DO
455 : END DO
456 : END DO
457 :
458 41100 : END SUBROUTINE build_3c_integral_block_ctx
459 :
460 : ! **************************************************************************************************
461 : !> \brief ...
462 : !> \param int_3c ...
463 : !> \param qs_env ...
464 : !> \param potential_parameter ...
465 : !> \param basis_j ...
466 : !> \param basis_k ...
467 : !> \param basis_i ...
468 : !> \param cell_j ...
469 : !> \param cell_k ...
470 : !> \param cell_i ...
471 : !> \param atom_j ...
472 : !> \param atom_k ...
473 : !> \param atom_i ...
474 : !> \param j_bf_start_from_atom ...
475 : !> \param k_bf_start_from_atom ...
476 : !> \param i_bf_start_from_atom ...
477 : ! **************************************************************************************************
478 38766 : SUBROUTINE build_3c_integral_block(int_3c, qs_env, potential_parameter, &
479 12922 : basis_j, basis_k, basis_i, &
480 : cell_j, cell_k, cell_i, atom_j, atom_k, atom_i, &
481 12922 : j_bf_start_from_atom, k_bf_start_from_atom, &
482 12922 : i_bf_start_from_atom)
483 :
484 : REAL(KIND=dp), DIMENSION(:, :, :) :: int_3c
485 : TYPE(qs_environment_type), POINTER :: qs_env
486 : TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
487 : TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_j, basis_k, basis_i
488 : INTEGER, DIMENSION(3), INTENT(IN), OPTIONAL :: cell_j, cell_k, cell_i
489 : INTEGER, INTENT(IN), OPTIONAL :: atom_j, atom_k, atom_i
490 : INTEGER, DIMENSION(:), OPTIONAL :: j_bf_start_from_atom, &
491 : k_bf_start_from_atom, &
492 : i_bf_start_from_atom
493 :
494 : CHARACTER(LEN=*), PARAMETER :: routineN = 'build_3c_integral_block'
495 :
496 : INTEGER :: at_i, at_j, at_k, handle, my_i_offset, &
497 : my_j_offset, my_k_offset, natom
498 12922 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
499 : TYPE(cell_type), POINTER :: cell
500 167986 : TYPE(gw_3c_ctx_type) :: ctx
501 12922 : TYPE(gw_3c_ws_type) :: ws
502 : TYPE(mp_para_env_type), POINTER :: para_env
503 12922 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
504 :
505 12922 : CALL timeset(routineN, handle)
506 :
507 12922 : NULLIFY (atomic_kind_set, cell, para_env, particle_set)
508 : CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, cell=cell, natom=natom, &
509 12922 : para_env=para_env, particle_set=particle_set)
510 : CALL gw_3c_ctx_create_core(ctx, potential_parameter, basis_j, basis_k, basis_i, &
511 12922 : atomic_kind_set, cell, natom, para_env, particle_set)
512 12922 : CALL gw_3c_ws_create(ws, ctx)
513 :
514 823215 : int_3c(:, :, :) = 0.0_dp
515 :
516 : ! loop over all RI atoms
517 51303 : DO at_i = 1, ctx%natom
518 : ! loop over all AO atoms
519 165676 : DO at_j = 1, ctx%natom
520 : ! loop over all AO atoms
521 494333 : DO at_k = 1, ctx%natom
522 :
523 341579 : IF (PRESENT(atom_i)) THEN
524 340779 : IF (at_i /= atom_i) CYCLE
525 : END IF
526 114773 : IF (PRESENT(atom_j)) THEN
527 114773 : IF (at_j /= atom_j) CYCLE
528 : END IF
529 38581 : IF (PRESENT(atom_k)) THEN
530 38581 : IF (at_k /= atom_k) CYCLE
531 : END IF
532 :
533 13022 : IF (PRESENT(atom_j)) THEN
534 13022 : my_j_offset = 0
535 : ELSE
536 0 : CPASSERT(PRESENT(j_bf_start_from_atom))
537 0 : my_j_offset = j_bf_start_from_atom(at_j) - 1
538 : END IF
539 13022 : IF (PRESENT(atom_k)) THEN
540 13022 : my_k_offset = 0
541 : ELSE
542 0 : CPASSERT(PRESENT(k_bf_start_from_atom))
543 0 : my_k_offset = k_bf_start_from_atom(at_k) - 1
544 : END IF
545 13022 : IF (PRESENT(atom_i)) THEN
546 12822 : my_i_offset = 0
547 : ELSE
548 200 : CPASSERT(PRESENT(i_bf_start_from_atom))
549 200 : my_i_offset = i_bf_start_from_atom(at_i) - 1
550 : END IF
551 :
552 : CALL build_3c_integral_block_ctx(int_3c, ctx, ws, at_j, at_k, at_i, &
553 : cell_j=cell_j, cell_k=cell_k, cell_i=cell_i, &
554 : j_offset=my_j_offset, k_offset=my_k_offset, &
555 455952 : i_offset=my_i_offset)
556 :
557 : END DO ! atom_k (AO)
558 : END DO ! atom_j (AO)
559 : END DO ! atom_i (RI)
560 :
561 12922 : CALL gw_3c_ws_release(ws)
562 12922 : CALL gw_3c_ctx_release(ctx)
563 :
564 12922 : CALL timestop(handle)
565 :
566 38766 : END SUBROUTINE build_3c_integral_block
567 :
568 0 : END MODULE gw_utils_compute_integrals
|