(git:cd2a8c4)
Loading...
Searching...
No Matches
gw_utils_compute_integrals.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 Utility method to build 3-center integrals for small cell GW
10! **************************************************************************************************
12 USE omp_lib, ONLY: omp_get_thread_num
19 USE cell_types, ONLY: cell_type,&
20 get_cell,&
21 pbc
23 USE cp_files, ONLY: close_file,&
25 USE gamma, ONLY: init_md_ftable
30 USE kinds, ONLY: dp
33 libint_potential_type
39 USE orbital_pointers, ONLY: ncoset
44 USE t_c_g0, ONLY: get_lmax_init,&
45 init
46
47!$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num
48#include "./base/base_uses.f90"
49
50 IMPLICIT NONE
51
52 PRIVATE
53
54 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_utils_compute_integrals'
55
59
60! **************************************************************************************************
61!> \brief Shared read-only context for repeated 3-center integral block builds: screening
62!> parameters, basis maxima, contracted sphi tables, and the one-time gamma /
63!> truncated-Coulomb table initializations. Create and release OUTSIDE any OMP parallel
64!> region; creation is MPI-collective when the potential is truncated.
65! **************************************************************************************************
67 TYPE(libint_potential_type) :: potential_parameter = libint_potential_type()
68 INTEGER :: op_ij = do_potential_id, &
69 op_jk = do_potential_id
70 REAL(kind=dp) :: dr_ij = 0.0_dp, dr_jk = 0.0_dp, &
71 dr_ik = 0.0_dp
72 INTEGER :: maxli = 0, maxlj = 0, maxlk = 0, &
73 max_am = 0, m_max = 0
74 INTEGER :: max_ncoi = 0, max_ncoj = 0, max_ncok = 0
75 INTEGER :: max_nsgfi = 0, max_nsgfj = 0, &
76 max_nsgfk = 0, max_nset = 0, natom = 0
77 TYPE(cp_2d_r_p_type), DIMENSION(:, :), POINTER :: spi => null(), tspj => null(), &
78 spk => null()
79 TYPE(gto_basis_set_p_type), DIMENSION(:), ALLOCATABLE :: basis_i, basis_j, basis_k
80 INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_of
81 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set => null()
82 TYPE(cell_type), POINTER :: cell => null()
83 REAL(kind=dp), DIMENSION(3, 3) :: hmat = 0.0_dp
84 END TYPE gw_3c_ctx_type
85
86! **************************************************************************************************
87!> \brief Per-thread workspace for 3-center integral block builds: libint object + contraction
88!> buffers. Each thread creates its own (inside the parallel region is fine).
89! **************************************************************************************************
91 TYPE(cp_libint_t), ALLOCATABLE :: lib
92 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: cpp_buffer, ccp_buffer
93 END TYPE gw_3c_ws_type
94
95CONTAINS
96
97! **************************************************************************************************
98!> \brief Build the shared 3c-integral context from the band-structure environment and explicitly
99!> supplied potential and basis sets.
100!> \param ctx ...
101!> \param bs_env ...
102!> \param potential_parameter ...
103!> \param basis_j ...
104!> \param basis_k ...
105!> \param basis_i ...
106! **************************************************************************************************
107 SUBROUTINE gw_3c_ctx_create(ctx, bs_env, potential_parameter, basis_j, basis_k, basis_i)
108 TYPE(gw_3c_ctx_type), INTENT(OUT) :: ctx
109 TYPE(post_scf_bandstructure_type), POINTER :: bs_env
110 TYPE(libint_potential_type), INTENT(IN) :: potential_parameter
111 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_j, basis_k, basis_i
112
113 cpassert(ASSOCIATED(bs_env%ri_rs%atomic_kind_set))
114 cpassert(ASSOCIATED(bs_env%ri_rs%cell))
115 cpassert(ASSOCIATED(bs_env%para_env))
116 cpassert(ASSOCIATED(bs_env%ri_rs%particle_set))
117
118 CALL gw_3c_ctx_create_core(ctx, potential_parameter, basis_j, basis_k, basis_i, &
119 bs_env%ri_rs%atomic_kind_set, bs_env%ri_rs%cell, &
120 bs_env%n_atom, bs_env%para_env, bs_env%ri_rs%particle_set)
121 END SUBROUTINE gw_3c_ctx_create
122
123! **************************************************************************************************
124!> \brief Build screening and contraction data shared by repeated 3c-integral block evaluations.
125!> \param ctx ...
126!> \param potential_parameter ...
127!> \param basis_j ...
128!> \param basis_k ...
129!> \param basis_i ...
130!> \param atomic_kind_set ...
131!> \param cell ...
132!> \param natom ...
133!> \param para_env ...
134!> \param particle_set ...
135! **************************************************************************************************
136 SUBROUTINE gw_3c_ctx_create_core(ctx, potential_parameter, basis_j, basis_k, basis_i, &
137 atomic_kind_set, cell, natom, para_env, particle_set)
138 TYPE(gw_3c_ctx_type), INTENT(OUT) :: ctx
139 TYPE(libint_potential_type), INTENT(IN) :: potential_parameter
140 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_j, basis_k, basis_i
141 TYPE(atomic_kind_type), DIMENSION(:), INTENT(IN), &
142 POINTER :: atomic_kind_set
143 TYPE(cell_type), INTENT(IN), POINTER :: cell
144 INTEGER, INTENT(IN) :: natom
145 TYPE(mp_para_env_type), INTENT(IN), POINTER :: para_env
146 TYPE(particle_type), DIMENSION(:), INTENT(IN), &
147 POINTER :: particle_set
148
149 CHARACTER(LEN=*), PARAMETER :: routinen = 'gw_3c_ctx_create_core'
150
151 INTEGER :: egfi, handle, ibasis, ilist, imax, iset, &
152 jset, kset, l, nbasis, ncoi, npgf_l, &
153 sgfi, unit_id
154 INTEGER, DIMENSION(:), POINTER :: lmax_i, lmin_i, npgfi, npgfj, npgfk, &
155 nsgfi, nsgfj, nsgfk
156 TYPE(gto_basis_set_type), POINTER :: basis_set
157
158 CALL timeset(routinen, handle)
159
160 ctx%potential_parameter = potential_parameter
161 ctx%op_ij = potential_parameter%potential_type
162 ctx%op_jk = do_potential_id
163
164 IF (ctx%op_ij == do_potential_truncated .OR. ctx%op_ij == do_potential_short) THEN
165 ctx%dr_ij = potential_parameter%cutoff_radius*cutoff_screen_factor
166 ctx%dr_ik = potential_parameter%cutoff_radius*cutoff_screen_factor
167 ELSE IF (ctx%op_ij == do_potential_coulomb) THEN
168 ctx%dr_ij = 1000000.0_dp
169 ctx%dr_ik = 1000000.0_dp
170 END IF
171
172 ctx%cell => cell
173 ctx%natom = natom
174 ctx%particle_set => particle_set
175 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, kind_of=ctx%kind_of)
176 CALL get_cell(cell=ctx%cell, h=ctx%hmat)
177
178 ctx%basis_i = basis_i
179 ctx%basis_j = basis_j
180 ctx%basis_k = basis_k
181
182 ! max l per basis for libint; max nset/nco/nsgf for the LIBXSMM contraction buffers
183 nbasis = SIZE(basis_i)
184 DO ibasis = 1, nbasis
185 CALL get_gto_basis_set(gto_basis_set=basis_i(ibasis)%gto_basis_set, maxl=imax, &
186 lmax=lmax_i, lmin=lmin_i, nset=iset, nsgf_set=nsgfi, npgf=npgfi)
187 ctx%maxli = max(ctx%maxli, imax)
188 ctx%max_nset = max(ctx%max_nset, iset)
189 ctx%max_nsgfi = max(ctx%max_nsgfi, maxval(nsgfi))
190 ctx%max_ncoi = max(ctx%max_ncoi, maxval(npgfi)*ncoset(ctx%maxli))
191 DO l = 0, imax
192 npgf_l = 0
193 DO jset = 1, iset
194 IF (lmin_i(jset) == l .AND. lmax_i(jset) == l) npgf_l = npgf_l + npgfi(jset)
195 END DO
196 ctx%max_ncoi = max(ctx%max_ncoi, npgf_l*ncoset(l))
197 END DO
198 END DO
199 DO ibasis = 1, nbasis
200 CALL get_gto_basis_set(gto_basis_set=basis_j(ibasis)%gto_basis_set, maxl=imax, &
201 nset=jset, nsgf_set=nsgfj, npgf=npgfj)
202 ctx%maxlj = max(ctx%maxlj, imax)
203 ctx%max_nset = max(ctx%max_nset, jset)
204 ctx%max_nsgfj = max(ctx%max_nsgfj, maxval(nsgfj))
205 ctx%max_ncoj = max(ctx%max_ncoj, maxval(npgfj)*ncoset(ctx%maxlj))
206 END DO
207 DO ibasis = 1, nbasis
208 CALL get_gto_basis_set(gto_basis_set=basis_k(ibasis)%gto_basis_set, maxl=imax, &
209 nset=kset, nsgf_set=nsgfk, npgf=npgfk)
210 ctx%maxlk = max(ctx%maxlk, imax)
211 ctx%max_nset = max(ctx%max_nset, kset)
212 ctx%max_nsgfk = max(ctx%max_nsgfk, maxval(nsgfk))
213 ctx%max_ncok = max(ctx%max_ncok, maxval(npgfk)*ncoset(ctx%maxlk))
214 END DO
215 ctx%m_max = ctx%maxli + ctx%maxlj + ctx%maxlk
216 ctx%max_am = max(ctx%maxli, ctx%maxlj, ctx%maxlk)
217
218 ! contiguous (and for j transposed) sphi copies, shared read-only across threads
219 ALLOCATE (ctx%spi(ctx%max_nset, nbasis), ctx%tspj(ctx%max_nset, nbasis), &
220 ctx%spk(ctx%max_nset, nbasis))
221 DO ibasis = 1, nbasis
222 DO iset = 1, ctx%max_nset
223 NULLIFY (ctx%spi(iset, ibasis)%array)
224 NULLIFY (ctx%tspj(iset, ibasis)%array)
225 NULLIFY (ctx%spk(iset, ibasis)%array)
226 END DO
227 END DO
228 DO ilist = 1, 3
229 DO ibasis = 1, nbasis
230 IF (ilist == 1) basis_set => basis_i(ibasis)%gto_basis_set
231 IF (ilist == 2) basis_set => basis_j(ibasis)%gto_basis_set
232 IF (ilist == 3) basis_set => basis_k(ibasis)%gto_basis_set
233 DO iset = 1, basis_set%nset
234 ncoi = basis_set%npgf(iset)*ncoset(basis_set%lmax(iset))
235 sgfi = basis_set%first_sgf(1, iset)
236 egfi = sgfi + basis_set%nsgf_set(iset) - 1
237 IF (ilist == 1) THEN
238 ALLOCATE (ctx%spi(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
239 ctx%spi(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
240 ELSE IF (ilist == 2) THEN
241 ALLOCATE (ctx%tspj(iset, ibasis)%array(basis_set%nsgf_set(iset), ncoi))
242 ctx%tspj(iset, ibasis)%array(:, :) = transpose(basis_set%sphi(1:ncoi, sgfi:egfi))
243 ELSE
244 ALLOCATE (ctx%spk(iset, ibasis)%array(ncoi, basis_set%nsgf_set(iset)))
245 ctx%spk(iset, ibasis)%array(:, :) = basis_set%sphi(1:ncoi, sgfi:egfi)
246 END IF
247 END DO
248 END DO
249 END DO
250
251 ! one-time table inits; the truncated-Coulomb init reads a file + bcasts => MPI-collective,
252 ! must happen here and never inside the per-block path or an OMP region
253 IF (ctx%op_ij == do_potential_truncated .OR. ctx%op_jk == do_potential_truncated) THEN
254 IF (ctx%m_max > get_lmax_init()) THEN
255 IF (para_env%mepos == 0) THEN
256 CALL open_file(unit_number=unit_id, file_name=potential_parameter%filename)
257 END IF
258 CALL init(ctx%m_max, unit_id, para_env%mepos, para_env)
259 IF (para_env%mepos == 0) THEN
260 CALL close_file(unit_id)
261 END IF
262 END IF
263 END IF
264 CALL init_md_ftable(nmax=ctx%m_max)
265
266 CALL timestop(handle)
267
268 END SUBROUTINE gw_3c_ctx_create_core
269
270! **************************************************************************************************
271!> \brief Releases the shared 3c-integral context.
272!> \param ctx ...
273! **************************************************************************************************
274 SUBROUTINE gw_3c_ctx_release(ctx)
275
276 TYPE(gw_3c_ctx_type), INTENT(INOUT) :: ctx
277
278 INTEGER :: ibasis, iset
279
280 DO iset = 1, SIZE(ctx%spi, 1)
281 DO ibasis = 1, SIZE(ctx%spi, 2)
282 IF (ASSOCIATED(ctx%spi(iset, ibasis)%array)) DEALLOCATE (ctx%spi(iset, ibasis)%array)
283 IF (ASSOCIATED(ctx%tspj(iset, ibasis)%array)) DEALLOCATE (ctx%tspj(iset, ibasis)%array)
284 IF (ASSOCIATED(ctx%spk(iset, ibasis)%array)) DEALLOCATE (ctx%spk(iset, ibasis)%array)
285 END DO
286 END DO
287 DEALLOCATE (ctx%spi, ctx%tspj, ctx%spk)
288 NULLIFY (ctx%spi, ctx%tspj, ctx%spk, ctx%particle_set, ctx%cell)
289 IF (ALLOCATED(ctx%kind_of)) DEALLOCATE (ctx%kind_of)
290 IF (ALLOCATED(ctx%basis_i)) DEALLOCATE (ctx%basis_i)
291 IF (ALLOCATED(ctx%basis_j)) DEALLOCATE (ctx%basis_j)
292 IF (ALLOCATED(ctx%basis_k)) DEALLOCATE (ctx%basis_k)
293
294 END SUBROUTINE gw_3c_ctx_release
295
296! **************************************************************************************************
297!> \brief Creates a per-thread 3c workspace: libint object + LIBXSMM contraction buffers.
298!> \param ws ...
299!> \param ctx ...
300! **************************************************************************************************
301 SUBROUTINE gw_3c_ws_create(ws, ctx)
302
303 TYPE(gw_3c_ws_type), INTENT(OUT) :: ws
304 TYPE(gw_3c_ctx_type), INTENT(IN) :: ctx
305
306 ALLOCATE (ws%lib)
307 CALL cp_libint_init_3eri(ws%lib, ctx%max_am)
308 CALL cp_libint_set_contrdepth(ws%lib, 1)
309 ALLOCATE (ws%cpp_buffer(ctx%max_nsgfj*ctx%max_ncok), &
310 ws%ccp_buffer(ctx%max_nsgfj*ctx%max_nsgfk*ctx%max_ncoi))
311
312 END SUBROUTINE gw_3c_ws_create
313
314! **************************************************************************************************
315!> \brief Releases a per-thread 3c workspace.
316!> \param ws ...
317! **************************************************************************************************
318 SUBROUTINE gw_3c_ws_release(ws)
319
320 TYPE(gw_3c_ws_type), INTENT(INOUT) :: ws
321
322 CALL cp_libint_cleanup_3eri(ws%lib)
323 DEALLOCATE (ws%lib)
324 DEALLOCATE (ws%cpp_buffer, ws%ccp_buffer)
325
326 END SUBROUTINE gw_3c_ws_release
327
328! **************************************************************************************************
329!> \brief Computes the 3c integral block (mu(atom_j) nu(atom_k) | P(atom_i)) for ONE atom triple,
330!> accumulating into the caller-zeroed int_3c at the given block offsets.
331!> Thread-safe: reads the frozen ctx + read-only module tables, mutates only its arguments
332!> and the per-thread ws.
333!> \param int_3c pre-zeroed target; the triple's contribution is accumulated in place
334!> \param ctx shared context from gw_3c_ctx_create
335!> \param ws per-thread workspace from gw_3c_ws_create
336!> \param atom_j ...
337!> \param atom_k ...
338!> \param atom_i ...
339!> \param cell_j ...
340!> \param cell_k ...
341!> \param cell_i ...
342!> \param j_offset block offset of atom_j's first sgf in int_3c dim 1 (default 0)
343!> \param k_offset block offset of atom_k's first sgf in int_3c dim 2 (default 0)
344!> \param i_offset block offset of atom_i's first RI sgf in int_3c dim 3 (default 0)
345!> \param screened .TRUE. if the kind-radius screens killed the whole triple (int_3c untouched)
346! **************************************************************************************************
347 SUBROUTINE build_3c_integral_block_ctx(int_3c, ctx, ws, atom_j, atom_k, atom_i, &
348 cell_j, cell_k, cell_i, &
349 j_offset, k_offset, i_offset, screened)
350
351 REAL(kind=dp), DIMENSION(:, :, :) :: int_3c
352 TYPE(gw_3c_ctx_type), INTENT(IN) :: ctx
353 TYPE(gw_3c_ws_type), INTENT(INOUT) :: ws
354 INTEGER, INTENT(IN) :: atom_j, atom_k, atom_i
355 INTEGER, DIMENSION(3), INTENT(IN), OPTIONAL :: cell_j, cell_k, cell_i
356 INTEGER, INTENT(IN), OPTIONAL :: j_offset, k_offset, i_offset
357 LOGICAL, INTENT(OUT), OPTIONAL :: screened
358
359 INTEGER :: block_end_i, block_end_j, block_end_k, block_start_i, block_start_j, &
360 block_start_k, ikind, iset, jkind, jset, kkind, kset, my_i_offset, my_j_offset, &
361 my_k_offset, ncoi, ncoj, ncok, nseti, nsetj, nsetk, sgfi, sgfj, sgfk
362 INTEGER, DIMENSION(3) :: my_cell_i, my_cell_j, my_cell_k
363 INTEGER, DIMENSION(:), POINTER :: lmax_i, lmax_j, lmax_k, lmin_i, lmin_j, &
364 lmin_k, npgfi, npgfj, npgfk, nsgfi, &
365 nsgfj, nsgfk
366 INTEGER, DIMENSION(:, :), POINTER :: first_sgf_i, first_sgf_j, first_sgf_k
367 REAL(kind=dp) :: dij, dik, djk, kind_radius_i, &
368 kind_radius_j, kind_radius_k, sijk_ext
369 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: sijk, sijk_contr
370 REAL(kind=dp), DIMENSION(3) :: ri, rij, rik, rj, rjk, rk
371 REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_i, set_radius_j, set_radius_k
372 REAL(kind=dp), DIMENSION(:, :), POINTER :: rpgf_i, rpgf_j, rpgf_k, zeti, zetj, zetk
373
374 IF (PRESENT(screened)) screened = .false.
375
376 my_cell_i(1:3) = 0
377 IF (PRESENT(cell_i)) my_cell_i(1:3) = cell_i(1:3)
378 my_cell_j(1:3) = 0
379 IF (PRESENT(cell_j)) my_cell_j(1:3) = cell_j(1:3)
380 my_cell_k(1:3) = 0
381 IF (PRESENT(cell_k)) my_cell_k(1:3) = cell_k(1:3)
382 my_i_offset = 0
383 IF (PRESENT(i_offset)) my_i_offset = i_offset
384 my_j_offset = 0
385 IF (PRESENT(j_offset)) my_j_offset = j_offset
386 my_k_offset = 0
387 IF (PRESENT(k_offset)) my_k_offset = k_offset
388
389 ri = pbc(ctx%particle_set(atom_i)%r(1:3), ctx%cell) + matmul(ctx%hmat, real(my_cell_i, dp))
390 rj = pbc(ctx%particle_set(atom_j)%r(1:3), ctx%cell) + matmul(ctx%hmat, real(my_cell_j, dp))
391 rk = pbc(ctx%particle_set(atom_k)%r(1:3), ctx%cell) + matmul(ctx%hmat, real(my_cell_k, dp))
392
393 rjk(1:3) = rk(1:3) - rj(1:3)
394 rij(1:3) = rj(1:3) - ri(1:3)
395 rik(1:3) = rk(1:3) - ri(1:3)
396
397 djk = norm2(rjk)
398 dij = norm2(rij)
399 dik = norm2(rik)
400
401 ikind = ctx%kind_of(atom_i)
402 jkind = ctx%kind_of(atom_j)
403 kkind = ctx%kind_of(atom_k)
404
405 CALL get_gto_basis_set(ctx%basis_i(ikind)%gto_basis_set, first_sgf=first_sgf_i, &
406 lmax=lmax_i, lmin=lmin_i, npgf=npgfi, nset=nseti, &
407 nsgf_set=nsgfi, pgf_radius=rpgf_i, set_radius=set_radius_i, &
408 zet=zeti, kind_radius=kind_radius_i)
409 CALL get_gto_basis_set(ctx%basis_j(jkind)%gto_basis_set, first_sgf=first_sgf_j, &
410 lmax=lmax_j, lmin=lmin_j, npgf=npgfj, nset=nsetj, &
411 nsgf_set=nsgfj, pgf_radius=rpgf_j, set_radius=set_radius_j, &
412 zet=zetj, kind_radius=kind_radius_j)
413 CALL get_gto_basis_set(ctx%basis_k(kkind)%gto_basis_set, first_sgf=first_sgf_k, &
414 lmax=lmax_k, lmin=lmin_k, npgf=npgfk, nset=nsetk, &
415 nsgf_set=nsgfk, pgf_radius=rpgf_k, set_radius=set_radius_k, &
416 zet=zetk, kind_radius=kind_radius_k)
417
418 IF (kind_radius_j + kind_radius_i + ctx%dr_ij < dij .OR. &
419 kind_radius_j + kind_radius_k + ctx%dr_jk < djk .OR. &
420 kind_radius_k + kind_radius_i + ctx%dr_ik < dik) THEN
421 IF (PRESENT(screened)) screened = .true.
422 RETURN
423 END IF
424
425 DO iset = 1, nseti
426 DO jset = 1, nsetj
427 IF (set_radius_j(jset) + set_radius_i(iset) + ctx%dr_ij < dij) cycle
428 DO kset = 1, nsetk
429 IF (set_radius_j(jset) + set_radius_k(kset) + ctx%dr_jk < djk) cycle
430 IF (set_radius_k(kset) + set_radius_i(iset) + ctx%dr_ik < dik) cycle
431
432 ncoi = npgfi(iset)*ncoset(lmax_i(iset))
433 ncoj = npgfj(jset)*ncoset(lmax_j(jset))
434 ncok = npgfk(kset)*ncoset(lmax_k(kset))
435
436 sgfi = first_sgf_i(1, iset)
437 sgfj = first_sgf_j(1, jset)
438 sgfk = first_sgf_k(1, kset)
439
440 IF (ncoj*ncok*ncoi <= 0) cycle
441 ALLOCATE (sijk(ncoj, ncok, ncoi))
442 sijk(:, :, :) = 0.0_dp
443
444 CALL eri_3center(sijk, &
445 lmin_j(jset), lmax_j(jset), npgfj(jset), zetj(:, jset), &
446 rpgf_j(:, jset), rj, &
447 lmin_k(kset), lmax_k(kset), npgfk(kset), zetk(:, kset), &
448 rpgf_k(:, kset), rk, &
449 lmin_i(iset), lmax_i(iset), npgfi(iset), zeti(:, iset), &
450 rpgf_i(:, iset), ri, &
451 djk, dij, dik, ws%lib, ctx%potential_parameter, &
452 int_abc_ext=sijk_ext)
453
454 ALLOCATE (sijk_contr(nsgfj(jset), nsgfk(kset), nsgfi(iset)))
455 CALL abc_contract_xsmm(sijk_contr, sijk, ctx%tspj(jset, jkind)%array, &
456 ctx%spk(kset, kkind)%array, ctx%spi(iset, ikind)%array, &
457 ncoj, ncok, ncoi, nsgfj(jset), nsgfk(kset), &
458 nsgfi(iset), ws%cpp_buffer, ws%ccp_buffer)
459 DEALLOCATE (sijk)
460
461 block_start_j = sgfj + my_j_offset
462 block_end_j = sgfj + nsgfj(jset) - 1 + my_j_offset
463 block_start_k = sgfk + my_k_offset
464 block_end_k = sgfk + nsgfk(kset) - 1 + my_k_offset
465 block_start_i = sgfi + my_i_offset
466 block_end_i = sgfi + nsgfi(iset) - 1 + my_i_offset
467
468 int_3c(block_start_j:block_end_j, &
469 block_start_k:block_end_k, &
470 block_start_i:block_end_i) = &
471 int_3c(block_start_j:block_end_j, &
472 block_start_k:block_end_k, &
473 block_start_i:block_end_i) + &
474 sijk_contr(:, :, :)
475 DEALLOCATE (sijk_contr)
476
477 END DO
478 END DO
479 END DO
480
481 END SUBROUTINE build_3c_integral_block_ctx
482
483! **************************************************************************************************
484!> \brief ...
485!> \param int_3c ...
486!> \param qs_env ...
487!> \param potential_parameter ...
488!> \param basis_j ...
489!> \param basis_k ...
490!> \param basis_i ...
491!> \param cell_j ...
492!> \param cell_k ...
493!> \param cell_i ...
494!> \param atom_j ...
495!> \param atom_k ...
496!> \param atom_i ...
497!> \param j_bf_start_from_atom ...
498!> \param k_bf_start_from_atom ...
499!> \param i_bf_start_from_atom ...
500! **************************************************************************************************
501 SUBROUTINE build_3c_integral_block(int_3c, qs_env, potential_parameter, &
502 basis_j, basis_k, basis_i, &
503 cell_j, cell_k, cell_i, atom_j, atom_k, atom_i, &
504 j_bf_start_from_atom, k_bf_start_from_atom, &
505 i_bf_start_from_atom)
506
507 REAL(kind=dp), DIMENSION(:, :, :) :: int_3c
508 TYPE(qs_environment_type), POINTER :: qs_env
509 TYPE(libint_potential_type), INTENT(IN) :: potential_parameter
510 TYPE(gto_basis_set_p_type), DIMENSION(:) :: basis_j, basis_k, basis_i
511 INTEGER, DIMENSION(3), INTENT(IN), OPTIONAL :: cell_j, cell_k, cell_i
512 INTEGER, INTENT(IN), OPTIONAL :: atom_j, atom_k, atom_i
513 INTEGER, DIMENSION(:), OPTIONAL :: j_bf_start_from_atom, &
514 k_bf_start_from_atom, &
515 i_bf_start_from_atom
516
517 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_3c_integral_block'
518
519 INTEGER :: at_i, at_j, at_k, handle, my_i_offset, &
520 my_j_offset, my_k_offset, natom
521 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
522 TYPE(cell_type), POINTER :: cell
523 TYPE(gw_3c_ctx_type) :: ctx
524 TYPE(gw_3c_ws_type) :: ws
525 TYPE(mp_para_env_type), POINTER :: para_env
526 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
527
528 CALL timeset(routinen, handle)
529
530 NULLIFY (atomic_kind_set, cell, para_env, particle_set)
531 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, cell=cell, natom=natom, &
532 para_env=para_env, particle_set=particle_set)
533 CALL gw_3c_ctx_create_core(ctx, potential_parameter, basis_j, basis_k, basis_i, &
534 atomic_kind_set, cell, natom, para_env, particle_set)
535 CALL gw_3c_ws_create(ws, ctx)
536
537 int_3c(:, :, :) = 0.0_dp
538
539 ! loop over all RI atoms
540 DO at_i = 1, ctx%natom
541 ! loop over all AO atoms
542 DO at_j = 1, ctx%natom
543 ! loop over all AO atoms
544 DO at_k = 1, ctx%natom
545
546 IF (PRESENT(atom_i)) THEN
547 IF (at_i /= atom_i) cycle
548 END IF
549 IF (PRESENT(atom_j)) THEN
550 IF (at_j /= atom_j) cycle
551 END IF
552 IF (PRESENT(atom_k)) THEN
553 IF (at_k /= atom_k) cycle
554 END IF
555
556 IF (PRESENT(atom_j)) THEN
557 my_j_offset = 0
558 ELSE
559 cpassert(PRESENT(j_bf_start_from_atom))
560 my_j_offset = j_bf_start_from_atom(at_j) - 1
561 END IF
562 IF (PRESENT(atom_k)) THEN
563 my_k_offset = 0
564 ELSE
565 cpassert(PRESENT(k_bf_start_from_atom))
566 my_k_offset = k_bf_start_from_atom(at_k) - 1
567 END IF
568 IF (PRESENT(atom_i)) THEN
569 my_i_offset = 0
570 ELSE
571 cpassert(PRESENT(i_bf_start_from_atom))
572 my_i_offset = i_bf_start_from_atom(at_i) - 1
573 END IF
574
575 CALL build_3c_integral_block_ctx(int_3c, ctx, ws, at_j, at_k, at_i, &
576 cell_j=cell_j, cell_k=cell_k, cell_i=cell_i, &
577 j_offset=my_j_offset, k_offset=my_k_offset, &
578 i_offset=my_i_offset)
579
580 END DO ! atom_k (AO)
581 END DO ! atom_j (AO)
582 END DO ! atom_i (RI)
583
584 CALL gw_3c_ws_release(ws)
585 CALL gw_3c_ctx_release(ctx)
586
587 CALL timestop(handle)
588
589 END SUBROUTINE build_3c_integral_block
590
static int imax(int x, int y)
Returns the larger of two given integers (missing from the C standard).
Contraction of integrals over primitive Cartesian Gaussians based on the contraction matrix sphi whic...
subroutine, public abc_contract_xsmm(abcint, sabc, sphi_a, sphi_b, sphi_c, ncoa, ncob, ncoc, nsgfa, nsgfb, nsgfc, cpp_buffer, ccp_buffer, prefac, pstfac)
3-center contraction routine from primitive cartesian Gaussians to spherical Gaussian functions using...
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum, ccon)
...
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
Definition cell_types.F:233
various utilities that regard array of different kinds: output, allocation,... maybe it is not a good...
Utility routines to open and close files. Tracking of preconnections.
Definition cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition cp_files.F:322
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Definition cp_files.F:122
Calculation of the incomplete Gamma function F_n(t) for multi-center integrals over Cartesian Gaussia...
Definition gamma.F:15
subroutine, public init_md_ftable(nmax)
Initialize a table of F_n(t) values in the range 0 <= t <= 12 with a stepsize of 0....
Definition gamma.F:540
Utility method to build 3-center integrals for small cell GW.
subroutine, public gw_3c_ws_create(ws, ctx)
Creates a per-thread 3c workspace: libint object + LIBXSMM contraction buffers.
subroutine, public build_3c_integral_block_ctx(int_3c, ctx, ws, atom_j, atom_k, atom_i, cell_j, cell_k, cell_i, j_offset, k_offset, i_offset, screened)
Computes the 3c integral block (mu(atom_j) nu(atom_k) | P(atom_i)) for ONE atom triple,...
subroutine, public gw_3c_ctx_release(ctx)
Releases the shared 3c-integral context.
subroutine, public build_3c_integral_block(int_3c, qs_env, potential_parameter, basis_j, basis_k, basis_i, cell_j, cell_k, cell_i, atom_j, atom_k, atom_i, j_bf_start_from_atom, k_bf_start_from_atom, i_bf_start_from_atom)
...
subroutine, public gw_3c_ws_release(ws)
Releases a per-thread 3c workspace.
subroutine, public gw_3c_ctx_create(ctx, bs_env, potential_parameter, basis_j, basis_k, basis_i)
Build the shared 3c-integral context from the band-structure environment and explicitly supplied pote...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_potential_truncated
integer, parameter, public do_potential_id
integer, parameter, public do_potential_coulomb
integer, parameter, public do_potential_short
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
2- and 3-center electron repulsion integral routines based on libint2 Currently available operators: ...
subroutine, public eri_3center(int_abc, la_min, la_max, npgfa, zeta, rpgfa, ra, lb_min, lb_max, npgfb, zetb, rpgfb, rb, lc_min, lc_max, npgfc, zetc, rpgfc, rc, dab, dac, dbc, lib, potential_parameter, int_abc_ext)
Computes the 3-center electron repulsion integrals (ab|c) for a given set of cartesian gaussian orbit...
real(kind=dp), parameter, public cutoff_screen_factor
Interface to the Libint-Library or a c++ wrapper.
subroutine, public cp_libint_init_3eri(lib, max_am)
subroutine, public cp_libint_cleanup_3eri(lib)
subroutine, public cp_libint_set_contrdepth(lib, contrdepth)
Interface to the message passing library MPI.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
Define the data structure for the particle information.
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.
This module computes the basic integrals for the truncated coulomb operator.
Definition t_c_g0.F:58
subroutine, public init(nder, iunit, mepos, group)
...
Definition t_c_g0.F:1361
integer function, public get_lmax_init()
Returns the value of nderiv_init so that one can check if opening the potential file is worhtwhile.
Definition t_c_g0.F:1468
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
represent a pointer to a 2d array
Shared read-only context for repeated 3-center integral block builds: screening parameters,...
Per-thread workspace for 3-center integral block builds: libint object + contraction buffers....
stores all the informations relevant to an mpi environment