(git:3d5d2e5)
Loading...
Searching...
No Matches
libgint_wrapper.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 Interface to the LibGint-Library.
10!> \par History
11!> 10.2024 Created
12!> \author Marcello Puligheddu
13! **************************************************************************************************
15
16 USE kinds, ONLY: dp
17#if(__LIBGINT)
19 USE libgint, ONLY: libgint_init, libgint_set_potential_truncated, libgint_set_hf_fac, libgint_set_max_mem, &
20 libgint_set_p, libgint_set_p_polarized, libgint_set_k, libgint_set_k_polarized, &
21 libgint_get_k, libgint_get_k_polarized, libgint_set_atom, libgint_set_atom_l, &
22 libgint_set_cell, libgint_set_neighs, &
23 libgint_add_prm, libgint_add_shell, libgint_add_cell, libgint_add_qrt, &
24 libgint_add_qrtt, libgint_add_set
25 USE t_c_g0, ONLY: c0
26#endif
27 USE hfx_types, ONLY: hfx_type, hfx_memory_type, hfx_potential_type, &
28 hfx_screen_coeff_type, hfx_cell_type, hfx_basis_type
29
30 USE cell_types, ONLY: cell_type
33
34 USE iso_c_binding, ONLY: c_ptr
35
36#include "./base/base_uses.f90"
37 IMPLICIT NONE
38 PRIVATE
39
40#if(__LIBGINT)
41 INTEGER, ALLOCATABLE, DIMENSION(:), SAVE :: first_set_of_atom
42 TYPE(bra_t), TARGET, SAVE :: bra, ket
43 LOGICAL, SAVE :: first_call = .true.
44 TYPE(c_ptr), SAVE :: libGint_handle
45 !$OMP THREADPRIVATE( first_set_of_atom, first_call )
46 !$OMP THREADPRIVATE( bra,ket )
47 !$OMP THREADPRIVATE( libGint_handle )
48#endif
49
52 CHARACTER(LEN=*), PARAMETER, PRIVATE :: moduleN = 'libGint_wrapper'
53
54! Comunicates the current density to the libGint engine.
55! Sets the Fock matrix on the device to zero
57 MODULE PROCEDURE libgint_set_density_a
58 MODULE PROCEDURE libgint_set_density_ab
59 END INTERFACE
60
62 MODULE PROCEDURE libgint_get_fock_matrix_a
63 MODULE PROCEDURE libgint_get_fock_matrix_ab
64 END INTERFACE
65
66CONTAINS
67! **************************************************************************************************
68!> \brief Sets libGint internal enviroment, must be called at least once before libGint can be used
69!> \param[in] actual_x_data pointer to hfx_data
70! **************************************************************************************************
71 SUBROUTINE cp_libgint_init(actual_x_data)
72
73 TYPE(hfx_type), POINTER, INTENT(IN) :: actual_x_data
74#if(__LIBGINT)
75 ! Init the offload library, creates an handle unique to this omp thread
76 CALL libgint_init(libgint_handle)
77 ! Comunicate the chosen potential and its parameters to libGint
78 IF (actual_x_data%potential_parameter%potential_type == do_potential_truncated) THEN
79 ! truncated coulomb needs the C0 coefficients. We do not read or compute them,
80 ! they must be already saved in C0 from the t[runcated]_c[oulomb]_g0 module
81 CALL libgint_set_potential_truncated(libgint_handle, &
82 actual_x_data%potential_parameter%cutoff_radius, &
83 c0(:, :))
84 ELSE
85 cpabort("The selected interaction potential type is not available with libGint")
86 END IF
87 first_call = .false.
88#else
89 mark_used(actual_x_data)
90 cpabort("This CP2K executable has not been linked against the required library libGint.")
91#endif
92 END SUBROUTINE cp_libgint_init
93! **************************************************************************************************
94!> \brief Initialize and update the libGint computational environment. Must be called at least once
95!> after geo_change and before libGint can be used.
96!>
97!> This routine sets up data required by the libGint integral engine, including
98!> Hartree–Fock scaling factors, memory limits, periodic cell information, and
99!> per-atom/basis-set data. It also allocates CPU-side buffers (`bra` and `ket`)
100!> used for storing screened Gaussian primitive pairs.
101!>
102!> \param[in] fac Fraction of exact exchange
103!> \param[in] memory_parameter Pointer to memory configuration
104!> \param[in] do_periodic Logical flag: whether to consider pbc
105!> \param[in] cell primitive simulation cell
106!> \param[in] actual_x_data HF exchange data
107!> \param[in] nneighbors Lattice points
108!> \param[in] max_pgf Maximum number of primitive Gaussians per shel
109!> \param[in] natom Number of atoms in the system
110!> \param[in] kind_of Array mapping atom indices to atomic kinds
111!> \param[in] particle_set particle set, we extract the positions
112!> \param[in] basis_parameter gaussian basis set parameters
113!>
114! **************************************************************************************************
115 SUBROUTINE libgint_update_env(fac, memory_parameter, do_periodic, cell, actual_x_data, nneighbors, max_pgf, &
116 natom, kind_of, particle_set, basis_parameter)
117
118 REAL(dp) :: fac
119 TYPE(hfx_memory_type), POINTER :: memory_parameter
120 LOGICAL :: do_periodic
121 TYPE(cell_type), POINTER :: cell
122 TYPE(hfx_type), POINTER :: actual_x_data
123 INTEGER :: nneighbors, max_pgf, natom
124 INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_of
125 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
126 TYPE(hfx_basis_type), DIMENSION(:), POINTER :: basis_parameter
127#if(__LIBGINT)
128 LOGICAL(1) :: do_pbc
129 REAL(dp), DIMENSION(:, :), ALLOCATABLE :: cell_r
130 REAL(dp), DIMENSION(:), ALLOCATABLE :: flat_gcc
131 INTEGER, DIMENSION(:), POINTER :: la_min, la_max, npgfa, nsgfa
132 INTEGER, DIMENSION(:, :), POINTER :: nsgfl_a
133 INTEGER :: i, l, iset, jset, iatom, ikind, nseta, &
134 inla, nla
135 REAL(dp) :: ra(3)
136 REAL(dp), DIMENSION(:, :), POINTER :: zeta
137 REAL(dp), DIMENSION(:, :, :), POINTER :: gcc
138 TYPE(bra_t), POINTER :: bra_p, ket_p
139
140 ! Set the multiplicative factor fac (the fraction of exact exchange times the spin factor) for libGint
141 CALL libgint_set_hf_fac(libgint_handle, fac)
142 ! Comunicate max gpu mem per mpi
143 CALL libgint_set_max_mem(libgint_handle, memory_parameter%max_memory)
144
145 ! Info about periodic cells and neighbouring cells
146 do_pbc = do_periodic
147 ALLOCATE (cell_r(3, nneighbors))
148 DO i = 1, nneighbors
149 cell_r(:, i) = actual_x_data%neighbor_cells(i)%cell_r(:)
150 END DO
151 CALL libgint_set_cell(libgint_handle, do_pbc, cell%hmat, cell%h_inv)
152 CALL libgint_set_neighs(libgint_handle, cell_r, nneighbors)
153
154 ! CPU side temporary arrays for info about the <AB(g) and CD(n)> pairs
155 bra_p => bra
156 ket_p => ket
157 CALL allocate_bra(bra_p, max_pgf, nneighbors)
158 CALL allocate_bra(ket_p, max_pgf, nneighbors)
159
160 ! Comunicate atomset and atom info to the engine
161 jset = 1
162 IF (ALLOCATED(first_set_of_atom)) DEALLOCATE (first_set_of_atom)
163 ALLOCATE (first_set_of_atom(natom))
164 DO iatom = 1, natom
165 ikind = kind_of(iatom)
166 ra = particle_set(iatom)%r(:)
167 nseta = basis_parameter(ikind)%nset
168 npgfa => basis_parameter(ikind)%npgf
169 la_min => basis_parameter(ikind)%lmin
170 la_max => basis_parameter(ikind)%lmax
171 zeta => basis_parameter(ikind)%zet
172 nsgfa => basis_parameter(ikind)%nsgf
173 nsgfl_a => basis_parameter(ikind)%nsgfl
174 gcc => basis_parameter(ikind)%gcc
175 first_set_of_atom(iatom) = jset
176 DO iset = 1, nseta
177 CALL libgint_set_atom(libgint_handle, jset - 1, ra, zeta(:, iset), npgfa(iset))
178 inla = 1
179 DO l = la_min(iset), la_max(iset)
180 nla = nsgfl_a(l, iset)
181 IF (ALLOCATED(flat_gcc)) DEALLOCATE (flat_gcc)
182 ALLOCATE (flat_gcc(npgfa(iset)*nla))
183 flat_gcc(:) = pack(gcc(1:npgfa(iset), inla:inla + nla - 1, iset), .true.)
184 CALL libgint_set_atom_l(libgint_handle, jset - 1, l, nla, flat_gcc)
185 inla = inla + nla
186 END DO
187 jset = jset + 1
188 END DO
189 END DO
190#else
191 mark_used(fac)
192 mark_used(memory_parameter)
193 mark_used(do_periodic)
194 mark_used(cell)
195 mark_used(actual_x_data)
196 mark_used(nneighbors)
197 mark_used(max_pgf)
198 mark_used(natom)
199 mark_used(kind_of)
200 mark_used(particle_set)
201 mark_used(basis_parameter)
202 cpabort("This CP2K executable has not been linked against the required library libGint.")
203#endif
204 END SUBROUTINE libgint_update_env
205
206! **************************************************************************************************
207!> \brief communicates the density to libGint, no spin case
208!>
209!> \param[in] full_density_alpha full density matrix array
210! **************************************************************************************************
211 SUBROUTINE libgint_set_density_a(full_density_alpha)
212
213 REAL(dp), DIMENSION(:, :), POINTER :: full_density_alpha
214#if(__LIBGINT)
215 CALL libgint_set_p(libgint_handle, full_density_alpha(:, 1))
216#else
217 mark_used(full_density_alpha)
218 cpabort("This CP2K executable has not been linked against the required library libGint.")
219#endif
220 END SUBROUTINE libgint_set_density_a
221
222! **************************************************************************************************
223!> \brief communicates the density to libGint, spin case
224!>
225!> \param[in] full_density_alpha full density matrix array on the alpha channel
226!> \param[in] full_density_beta full density matrix array on the beta channel
227! **************************************************************************************************
228 SUBROUTINE libgint_set_density_ab(full_density_alpha, full_density_beta)
229
230 REAL(dp), DIMENSION(:, :), POINTER :: full_density_alpha, full_density_beta
231#if(__LIBGINT)
232 CALL libgint_set_p_polarized(libgint_handle, full_density_alpha(:, 1), full_density_beta(:, 1))
233#else
234 mark_used(full_density_alpha)
235 mark_used(full_density_beta)
236 cpabort("This CP2K executable has not been linked against the required library libGint.")
237#endif
238 END SUBROUTINE libgint_set_density_ab
239
240! **************************************************************************************************
241!> \brief requests the Fock matrix ( hf_fraction * D @@ I ) from libGint. When this function
242!> returns, full_ks_alpha_from_gpu will contain the fock matrix for this MPI rank.
243!>
244!> \param[out] full_ks_alpha_from_gpu location, already allocated, for the Fock matrix
245!> \note assumes full_ks_alpha_from_gpu is already allocated with enough memory
246! **************************************************************************************************
247 SUBROUTINE libgint_get_fock_matrix_a(full_ks_alpha_from_gpu)
248
249 REAL(dp), DIMENSION(:, :), POINTER :: full_ks_alpha_from_gpu
250#if(__LIBGINT)
251 CALL libgint_get_k(libgint_handle, full_ks_alpha_from_gpu(:, 1))
252#else
253 mark_used(full_ks_alpha_from_gpu)
254 cpabort("This CP2K executable has not been linked against the required library libGint.")
255#endif
256 END SUBROUTINE libgint_get_fock_matrix_a
257
258! **************************************************************************************************
259!> \brief requests the Fock matrices from libGint for both channels. When this function
260!> returns, full_ks_alpha_from_gpu and beta will contain the fock matrix for this MPI rank.
261!>
262!> \param[out] full_ks_alpha_from_gpu location, already allocated, for the Fock matrix alpha
263!> \param[out] full_ks_beta_from_gpu location, already allocated, for the Fock matrix beta
264!> \note assumes full_ks_alpha_from_gpu and full_ks_beta_from_gpu are already allocated
265! **************************************************************************************************
266 SUBROUTINE libgint_get_fock_matrix_ab(full_ks_alpha_from_gpu, full_ks_beta_from_gpu)
267
268 REAL(dp), DIMENSION(:, :), POINTER :: full_ks_alpha_from_gpu, &
269 full_ks_beta_from_gpu
270#if(__LIBGINT)
271 CALL libgint_get_k_polarized(libgint_handle, full_ks_alpha_from_gpu(:, 1), full_ks_beta_from_gpu(:, 1))
272#else
273 mark_used(full_ks_alpha_from_gpu)
274 mark_used(full_ks_beta_from_gpu)
275 cpabort("This CP2K executable has not been linked against the required library libGint.")
276#endif
277 END SUBROUTINE libgint_get_fock_matrix_ab
278
279! **************************************************************************************************
280!> \brief Assign two-electron integrals of a quartet/shell to libGint
281!>
282!> First we build a list of ab primitives and cd primitives using build_pair_list_pbc_pgf
283!> These lists will contain (before screening) n_cell * npgf * npgf.
284!> We loop over both and send ab(g) | cd(h) to libgint, which will loop internally over n
285!>
286!> \param[in] iatom index of atom I / A
287!> \param[in] jatom index of atom J / B
288!> \param[in] katom index of atom K / C
289!> \param[in] latom index of atom L / D
290!> \param[in] iset index of the set for atom iatom we are adding
291!> \param[in] jset index of the set for atom jatom we are adding
292!> \param[in] kset index of the set for atom katom we are adding
293!> \param[in] lset index of the set for atom latom we are adding
294!> \param[in] ra position of atom iatom
295!> \param[in] rb position of atom jatom
296!> \param[in] rc position of atom katom
297!> \param[in] rd position of atom latom
298!> \param[in] npgfa number of gaussians in set iset of atom iatom
299!> \param[in] npgfb number of gaussians in set jset of atom jatom
300!> \param[in] npgfc number of gaussians in set kset of atom katom
301!> \param[in] npgfd number of gaussians in set lset of atom latom
302!> \param[in] potential_parameter information about the potential
303!> \param[in] screen1 screening information for AB pair
304!> \param[in] screen2 screening information for CD pair
305!> \param[in] log10_pmax density screening factor
306!> \param[in] log10_eps_schwarz screening tolerance
307!> \param[in] pgf1 screening information for each AB pair primitive
308!> \param[in] pgf2 screening information for each CD pair primitive
309!> \param[in] neighbor_cells array with lattice vectors
310!> \param[in] cell information about the simulation box
311!> \param[in] do_periodic flag for pbc
312!> \param[out] screened whether the whole quartet was screened out
313! **************************************************************************************************
314
315 SUBROUTINE libgint_coulomb4(iatom, jatom, katom, latom, iset, jset, kset, lset, &
316 ra, rb, rc, rd, npgfa, npgfb, npgfc, npgfd, &
317 potential_parameter, &
318 screen1, screen2, log10_pmax, log10_eps_schwarz, &
319 pgf1, pgf2, &
320 neighbor_cells, cell, do_periodic, screened)
321
322 INTEGER, INTENT(IN) :: iatom, jatom, katom, latom, iset, &
323 jset, kset, lset
324 REAL(dp), INTENT(IN) :: ra(3), rb(3), rc(3), rd(3)
325 INTEGER, INTENT(IN) :: npgfa, npgfb, npgfc, npgfd
326 TYPE(hfx_potential_type) :: potential_parameter
327 REAL(dp), INTENT(IN) :: screen1(2), screen2(2)
328 REAL(dp), INTENT(IN) :: log10_pmax, log10_eps_schwarz
329 TYPE(hfx_screen_coeff_type), DIMENSION(:, :), &
330 POINTER :: pgf1, pgf2
331 TYPE(hfx_cell_type), DIMENSION(:), POINTER :: neighbor_cells
332 TYPE(cell_type), POINTER :: cell
333 LOGICAL, INTENT(IN) :: do_periodic
334 LOGICAL, INTENT(OUT) :: screened
335
336#if(__LIBGINT)
337 TYPE(bra_t), POINTER :: bra_p, ket_p
338 LOGICAL :: cell_was_screened
339 INTEGER :: idx_n1, idx_n2, n1, n2, idx_ij, idx_kl, o_ij, n_ij, o_kl, n_kl !, n3
340 INTEGER :: ipgf, jpgf, kpgf, lpgf, iatom_set, &
341 jatom_set, katom_set, latom_set
342 REAL(dp) :: pgf_max_1, pgf_max_2 ! , R1, R2, rpq2
343 INTEGER :: nelements_ij, nelements_kl
344
345 cell = cell
346 potential_parameter = potential_parameter
347 bra_p => bra
348 ket_p => ket
349
350 screened = .true.
351 iatom_set = first_set_of_atom(iatom) + iset - 2
352 jatom_set = first_set_of_atom(jatom) + jset - 2
353 katom_set = first_set_of_atom(katom) + kset - 2
354 latom_set = first_set_of_atom(latom) + lset - 2
355
356 CALL build_pair_list_pbc_pgf(npgfa, npgfb, bra_p, screen1, screen2, &
357 pgf1, log10_pmax, log10_eps_schwarz, ra, rb, &
358 nelements_ij, neighbor_cells, do_periodic)
359
360 CALL build_pair_list_pbc_pgf(npgfc, npgfd, ket_p, screen2, screen1, &
361 pgf2, log10_pmax, log10_eps_schwarz, rc, rd, &
362 nelements_kl, neighbor_cells, do_periodic)
363
364 ! Note: we use 3 numbers n1 n2 and n3 as indices for the lattice traslantion vectors
365 ! n1 for the AB pair, n2 for the CD pair and n3 for the PQ pair
366 ! so that e.g. B = B0 + ua(n1) means B.x = B0.x + ua(n1).x (and same for y and z)
367 ! the ua, saved in neighbor_cells(:)%cell_r(:), are already computed
368 ! lattice translation vectors T = i a1 + j a2 + k a3
369 ! where a1,a2 and a3 are lattice vectors and i,j and k integers.
370 ! So, B.x = B0.x + n1.i * a1.x + n1.j * a2.x + n1.k * a3.x (and same for y and z)
371 !
372
373 DO idx_n1 = 1, bra%cell_cnt
374
375 n1 = bra%cell_idx(1, idx_n1)
376 n_ij = bra%cell_idx(2, idx_n1)
377 o_ij = bra%cell_idx(3, idx_n1)
378
379 DO idx_n2 = 1, ket%cell_cnt
380
381 n2 = ket%cell_idx(1, idx_n2)
382 n_kl = ket%cell_idx(2, idx_n2)
383 o_kl = ket%cell_idx(3, idx_n2)
384
385 cell_was_screened = .true.
386 DO idx_ij = o_ij + 1, o_ij + n_ij
387
388 ipgf = bra%pgf_idx(1, idx_ij)
389 jpgf = bra%pgf_idx(2, idx_ij)
390
391 pgf_max_1 = bra%pgf_scr(1, idx_ij)
392
393 DO idx_kl = o_kl + 1, o_kl + n_kl
394 kpgf = ket%pgf_idx(1, idx_kl)
395 lpgf = ket%pgf_idx(2, idx_kl)
396
397 pgf_max_2 = ket%pgf_scr(1, idx_kl)
398
399 IF (pgf_max_1 + pgf_max_2 + log10_pmax < log10_eps_schwarz) cycle
400
401 CALL libgint_add_prm(libgint_handle, ipgf - 1, jpgf - 1, kpgf - 1, lpgf - 1)
402 cell_was_screened = .false.
403
404 END DO ! ket pgf
405 END DO ! bra pgf
406
407 IF (.NOT. cell_was_screened) THEN
408 CALL libgint_add_shell(libgint_handle, iatom_set, jatom_set, katom_set, latom_set, n1 - 1, n2 - 1)
409 screened = .false.
410 END IF
411
412 END DO ! ket n2
413 END DO ! bra n1
414#else
415 mark_used(iatom)
416 mark_used(jatom)
417 mark_used(katom)
418 mark_used(latom)
419 mark_used(iset)
420 mark_used(jset)
421 mark_used(kset)
422 mark_used(lset)
423 mark_used(ra)
424 mark_used(rb)
425 mark_used(rc)
426 mark_used(rd)
427 mark_used(npgfa)
428 mark_used(npgfb)
429 mark_used(npgfc)
430 mark_used(npgfd)
431 mark_used(potential_parameter)
432 mark_used(screen1)
433 mark_used(screen2)
434 mark_used(log10_pmax)
435 mark_used(log10_eps_schwarz)
436 mark_used(pgf1)
437 mark_used(pgf2)
438 mark_used(neighbor_cells)
439 mark_used(cell)
440 mark_used(do_periodic)
441 mark_used(screened)
442 cpabort("This CP2K executable has not been linked against the required library libGint.")
443#endif
444 END SUBROUTINE libgint_coulomb4
445
446! **************************************************************************************************
447!> \brief The previous coulomb_4 function assigned an integral between primitive gaussian.
448!> Now we assign the nsgfa(iset)*b*c*d gcc integrals form this set,
449!> along with the Pac Pad Pbc Pbd density to the Kbd Kbc Kad Kac Fock matrix
450!>
451!> \param[in] symm_fac simmetry factor from iatom=jatom and the like
452!> \param[in] iatom index of atom A
453!> \param[in] jatom index of atom B
454!> \param[in] katom index of atom C
455!> \param[in] latom index of atom D
456!> \param[in] iset index of set for atom A
457!> \param[in] jset index of set for atom B
458!> \param[in] kset index of set for atom C
459!> \param[in] lset index of set for atom D
460!> \param[in] atomic_offset_ac global offset for the pair of A and C atom in the density ( and Fock) matrix
461!> \param[in] atomic_offset_ad global offset for the pair of A and D atom in the density ( and Fock) matrix
462!> \param[in] atomic_offset_bc global offset for the pair of B and C atom in the density ( and Fock) matrix
463!> \param[in] atomic_offset_bd global offset for the pair of B and D atom in the density ( and Fock) matrix
464!> \param[in] offset_ac_set matrix of sub_offset for sets in atomic_offset_ac
465!> \param[in] offset_ad_set matrix of sub_offset for sets in atomic_offset_ad
466!> \param[in] offset_bc_set matrix of sub_offset for sets in atomic_offset_bc
467!> \param[in] offset_bd_set matrix of sub_offset for sets in atomic_offset_bd
468!> \param[in] nsgfa total number of (spherical, contracted) integrals for iset.
469!> Used as leading dimension of the AC, AD sublock, depending on transposition
470!> \param[in] nsgfb total number of (spherical, contracted) integrals for jset.
471!> Used as leading dimension of the BC, BD sublock, depending on transposition
472!> \param[in] nsgfc total number of (spherical, contracted) integrals for kset.
473!> Used as leading dimension of the AC, BC sublock, depending on transposition
474!> \param[in] nsgfd total number of (spherical, contracted) integrals for lset.
475!> Used as leading dimension of the AD, BD sublock, depending on transposition
476!> \param[in] la_min minumum angular moment in set iset of atom A
477!> \param[in] la_max maximum angular moment in set iset of atom A
478!> \param[in] lb_min minumum angular moment in set iset of atom B
479!> \param[in] lb_max maximum angular moment in set iset of atom B
480!> \param[in] lc_min minumum angular moment in set iset of atom C
481!> \param[in] lc_max maximum angular moment in set iset of atom C
482!> \param[in] ld_min minumum angular moment in set iset of atom D
483!> \param[in] ld_max maximum angular moment in set iset of atom D
484!> \param[in] nsgfl_a matrix with the number of linear combinations of primitive gaussians
485!> for each angular moment for each set in atom A. We only read iset
486!> \param[in] nsgfl_b matrix with the number of linear combinations of primitive gaussians
487!> for each angular moment for each set in atom B. We only read jset
488!> \param[in] nsgfl_c matrix with the number of linear combinations of primitive gaussians
489!> for each angular moment for each set in atom C. We only read kset
490!> \param[in] nsgfl_d matrix with the number of linear combinations of primitive gaussians
491!> for each angular moment for each set in atom D. We only read lset
492!> \note
493!> The atomic_offset_xy, offset_xy_set matrices provide set offsets which are combined with per-L and
494!> per linear combination offsets to produce the final indices into the dense (but block-sparse)
495!> density and Fock matrices
496!> - The routine assumes Fortran column major order and contiguous storage for the per set
497!> density subblocks as described in the code comments.
498!> - The code computes transposition flags to only use the lower part of P and K
499!>
500!>
501! **************************************************************************************************
502
504 symm_fac, &
505 iatom, jatom, katom, latom, &
506 iset, jset, kset, lset, &
507 atomic_offset_ac, atomic_offset_ad, atomic_offset_bc, atomic_offset_bd, &
508 offset_ac_set, offset_ad_set, offset_bc_set, offset_bd_set, &
509 nsgfa, nsgfb, nsgfc, nsgfd, &
510 la_min, la_max, lb_min, lb_max, &
511 lc_min, lc_max, ld_min, ld_max, &
512 nsgfl_a, nsgfl_b, nsgfl_c, nsgfl_d)
513
514 REAL(dp) :: symm_fac
515 INTEGER :: iatom, jatom, katom, latom
516 INTEGER :: iset, jset, kset, lset
517 INTEGER :: atomic_offset_ac, atomic_offset_ad, &
518 atomic_offset_bc, atomic_offset_bd
519 INTEGER, DIMENSION(:, :), POINTER :: offset_ac_set, offset_ad_set
520 INTEGER, DIMENSION(:, :), POINTER :: offset_bc_set, offset_bd_set
521 INTEGER :: nsgfa, nsgfb, nsgfc, nsgfd
522 INTEGER :: la_min, la_max, lb_min, lb_max
523 INTEGER :: lc_min, lc_max, ld_min, ld_max
524 INTEGER, DIMENSION(:, :), POINTER :: nsgfl_a, nsgfl_b, nsgfl_c, nsgfl_d
525
526#if(__LIBGINT)
527 !! (Hyp)
528 ! Let a be a set composed of 2 s and 1 p function.
529 ! Let c be a set composed of 1 s and 2 p function.
530 ! (1) The density matrix for the ac pair is a 5 x 7 matrix organized as
531 !
532 ! ----------------------------------------------------------------------------------------------------------------------
533 ! | a_s1_0@c_s1_0 || a_s1_0@c_p1_0 | a_s1_0@c_p1_1 | a_s1_0@c_p1_2 || a_s1_0@c_p2_0 | a_s1_0@c_p2_1 | a_s1_0@c_p2_2 |
534 ! | a_s2_0@c_s1_0 || a_s2_0@c_p1_0 | a_s2_0@c_p1_1 | a_s2_0@c_p1_2 || a_s2_0@c_p2_0 | a_s2_0@c_p2_1 | a_s2_0@c_p2_2 |
535 ! | a_p1_0@c_s1_0 || a_p1_0@c_p1_0 | a_p1_0@c_p1_1 | a_p1_0@c_p1_2 || a_p1_0@c_p2_0 | a_p1_0@c_p2_1 | a_p1_0@c_p2_2 |
536 ! | a_p1_1@c_s1_0 || a_p1_1@c_p1_0 | a_p1_1@c_p1_1 | a_p1_1@c_p1_2 || a_p1_1@c_p2_0 | a_p1_1@c_p2_1 | a_p1_1@c_p2_2 |
537 ! | a_p1_2@c_s1_0 || a_p1_2@c_p1_0 | a_p1_2@c_p1_1 | a_p1_2@c_p1_2 || a_p1_2@c_p2_0 | a_p1_2@c_p2_1 | a_p1_2@c_p2_2 |
538 ! ----------------------------------------------------------------------------------------------------------------------
539 !
540 ! where A_LX_Y means the (Y+1) component of the Xth linear combination of the L angular moment for atom A
541 !
542 ! (2) This matrix is dense, rectangular and contigous in memory, in fortran column major order.
543 ! (3) The big matrix with all pairs is block sparse triangular, only the lower part is valid.
544
545 LOGICAL(1) :: tac, tad, tbc, tbd
546 INTEGER :: offset_ac_l_set, offset_ad_l_set, &
547 offset_bc_l_set, offset_bd_l_set
548 INTEGER :: s_offset_a, s_offset_b, s_offset_c, &
549 s_offset_d
550 INTEGER :: s_offset_a_l, s_offset_b_l, &
551 s_offset_c_l, s_offset_d_l
552 INTEGER :: s_offset_ac, s_offset_ad, s_offset_bc, &
553 s_offset_bd
554 INTEGER :: ld_ac_set, ld_ad_set, ld_bc_set, &
555 ld_bd_set
556 INTEGER :: la, lb, lc, ld, nla, nlb, nlc, nld, &
557 inla, inlb, inlc, inld
558 ! TODO rewrite as update_fock_matrix_gpu(libGint_handle, iatomset,jatomset,katomset,latomset )
559 ! AFTER TODO communicate (the pointer to) atomic_offset to libGint AND
560 ! AFTER TODO communicate (the pointer to) set_offset to libGint AND
561 ! AFTER TODO check if this idea makes sense in general for other codes
562 !
563 ! Note: this would not change the need to compute sub offsets and
564 ! the 8 loops, it would just transfer them to libGint
565 ! Except, if libGint can be sure every set has 1 l, it can collapse the l loops
566 ! and/or, if libGint can be sure every l has 1 nl, it can collapse the n loops
567 IF (jatom >= latom) THEN
568 offset_bd_l_set = offset_bd_set(jset, lset) + atomic_offset_bd - 2
569 ld_bd_set = nsgfb
570 tbd = .false.
571 ELSE
572 offset_bd_l_set = offset_bd_set(lset, jset) + atomic_offset_bd - 2
573 ld_bd_set = nsgfd
574 tbd = .true.
575 END IF
576 IF (jatom >= katom) THEN
577 offset_bc_l_set = offset_bc_set(jset, kset) + atomic_offset_bc - 2
578 ld_bc_set = nsgfb
579 tbc = .false.
580 ELSE
581 offset_bc_l_set = offset_bc_set(kset, jset) + atomic_offset_bc - 2
582 ld_bc_set = nsgfc
583 tbc = .true.
584 END IF
585
586 IF (iatom >= latom) THEN
587 offset_ad_l_set = offset_ad_set(iset, lset) + atomic_offset_ad - 2
588 ld_ad_set = nsgfa
589 tad = .false.
590 ELSE
591 offset_ad_l_set = offset_ad_set(lset, iset) + atomic_offset_ad - 2
592 ld_ad_set = nsgfd
593 tad = .true.
594 END IF
595
596 IF (iatom >= katom) THEN
597 offset_ac_l_set = offset_ac_set(iset, kset) + atomic_offset_ac - 2
598 ld_ac_set = nsgfa
599 tac = .false.
600 ELSE
601 offset_ac_l_set = offset_ac_set(kset, iset) + atomic_offset_ac - 2
602 ld_ac_set = nsgfc
603 tac = .true.
604 END IF
605
606 s_offset_a_l = 0
607 DO la = la_min, la_max
608 nla = nsgfl_a(la, iset)
609 s_offset_b_l = 0
610 DO lb = lb_min, lb_max
611 nlb = nsgfl_b(lb, jset)
612 s_offset_c_l = 0
613 DO lc = lc_min, lc_max
614 nlc = nsgfl_c(lc, kset)
615 s_offset_d_l = 0
616 ld_loop: DO ld = ld_min, ld_max
617 nld = nsgfl_d(ld, lset)
618 CALL libgint_add_qrt(libgint_handle, la, lb, lc, ld, nla, nlb, nlc, nld)
619 DO inla = 1, nla
620 s_offset_a = s_offset_a_l + (inla - 1)*(2*la + 1)
621 DO inlb = 1, nlb
622 s_offset_b = s_offset_b_l + (inlb - 1)*(2*lb + 1)
623 DO inlc = 1, nlc
624 s_offset_c = s_offset_c_l + (inlc - 1)*(2*lc + 1)
625 DO inld = 1, nld
626 s_offset_d = s_offset_d_l + (inld - 1)*(2*ld + 1)
627 IF (.NOT. tac) THEN
628 s_offset_ac = offset_ac_l_set + s_offset_c*ld_ac_set + s_offset_a
629 ELSE
630 s_offset_ac = offset_ac_l_set + s_offset_a*ld_ac_set + s_offset_c
631 END IF
632
633 IF (.NOT. tad) THEN
634 s_offset_ad = offset_ad_l_set + s_offset_d*ld_ad_set + s_offset_a
635 ELSE
636 s_offset_ad = offset_ad_l_set + s_offset_a*ld_ad_set + s_offset_d
637 END IF
638
639 IF (.NOT. tbc) THEN
640 s_offset_bc = offset_bc_l_set + s_offset_c*ld_bc_set + s_offset_b
641 ELSE
642 s_offset_bc = offset_bc_l_set + s_offset_b*ld_bc_set + s_offset_c
643 END IF
644
645 IF (.NOT. tbd) THEN
646 s_offset_bd = offset_bd_l_set + s_offset_d*ld_bd_set + s_offset_b
647 ELSE
648 s_offset_bd = offset_bd_l_set + s_offset_b*ld_bd_set + s_offset_d
649 END IF
650
651 CALL libgint_add_qrtt(libgint_handle, symm_fac, &
652 la, lb, lc, ld, inla - 1, inlb - 1, inlc - 1, inld - 1, &
653 ld_ac_set, ld_ad_set, ld_bc_set, ld_bd_set, &
654 s_offset_ac, s_offset_ad, s_offset_bc, s_offset_bd, &
655 tac, tad, tbc, tbd)
656
657 END DO
658 END DO
659 END DO
660 END DO
661 s_offset_d_l = s_offset_d_l + nld*(2*ld + 1)
662 END DO ld_loop
663 s_offset_c_l = s_offset_c_l + nlc*(2*lc + 1)
664 END DO
665 s_offset_b_l = s_offset_b_l + nlb*(2*lb + 1)
666 END DO
667 s_offset_a_l = s_offset_a_l + nla*(2*la + 1)
668 END DO
669
670 CALL libgint_add_set(libgint_handle)
671
672#else
673 mark_used(symm_fac)
674 mark_used(iatom)
675 mark_used(jatom)
676 mark_used(katom)
677 mark_used(latom)
678 mark_used(iset)
679 mark_used(jset)
680 mark_used(kset)
681 mark_used(lset)
682 mark_used(atomic_offset_ac)
683 mark_used(atomic_offset_ad)
684 mark_used(atomic_offset_bc)
685 mark_used(atomic_offset_bd)
686 mark_used(offset_ac_set)
687 mark_used(offset_ad_set)
688 mark_used(offset_bc_set)
689 mark_used(offset_bd_set)
690 mark_used(nsgfa)
691 mark_used(nsgfb)
692 mark_used(nsgfc)
693 mark_used(nsgfd)
694 mark_used(la_min)
695 mark_used(la_max)
696 mark_used(lb_min)
697 mark_used(lb_max)
698 mark_used(lc_min)
699 mark_used(lc_max)
700 mark_used(ld_min)
701 mark_used(ld_max)
702 mark_used(nsgfl_a)
703 mark_used(nsgfl_b)
704 mark_used(nsgfl_c)
705 mark_used(nsgfl_d)
706 cpabort("This CP2K executable has not been linked against the required library libGint.")
707#endif
708 END SUBROUTINE libgint_update_fock_matrix
709
710END MODULE libgint_wrapper
static GRID_HOST_DEVICE double fac(const int i)
Factorial function, e.g. fac(5) = 5! = 120.
Definition grid_common.h:57
Handles all functions related to the CELL.
Definition cell_types.F:15
Routines for optimizing load balance between processes in HFX calculations.
subroutine, public allocate_bra(bra, max_npgf, max_ncell)
Allocates all arrays within a Bra_t structure.
subroutine, public build_pair_list_pbc_pgf(npgfa, npgfb, bra, screen1, screen2, pgf, log10_pmax, log10_eps_schwarz, ra, rb, nelements, neighbor_cells, do_periodic)
Builds a screened list of primitives from centers A and B, intersecting with another shell.
Types and set/get functions for HFX.
Definition hfx_types.F:16
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_coulomb
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the LibGint-Library.
subroutine, public libgint_update_env(fac, memory_parameter, do_periodic, cell, actual_x_data, nneighbors, max_pgf, natom, kind_of, particle_set, basis_parameter)
Initialize and update the libGint computational environment. Must be called at least once after geo_c...
subroutine, public cp_libgint_init(actual_x_data)
Sets libGint internal enviroment, must be called at least once before libGint can be used.
subroutine, public libgint_update_fock_matrix(symm_fac, iatom, jatom, katom, latom, iset, jset, kset, lset, atomic_offset_ac, atomic_offset_ad, atomic_offset_bc, atomic_offset_bd, offset_ac_set, offset_ad_set, offset_bc_set, offset_bd_set, nsgfa, nsgfb, nsgfc, nsgfd, la_min, la_max, lb_min, lb_max, lc_min, lc_max, ld_min, ld_max, nsgfl_a, nsgfl_b, nsgfl_c, nsgfl_d)
The previous coulomb_4 function assigned an integral between primitive gaussian. Now we assign the ns...
subroutine, public libgint_coulomb4(iatom, jatom, katom, latom, iset, jset, kset, lset, ra, rb, rc, rd, npgfa, npgfb, npgfc, npgfd, potential_parameter, screen1, screen2, log10_pmax, log10_eps_schwarz, pgf1, pgf2, neighbor_cells, cell, do_periodic, screened)
Assign two-electron integrals of a quartet/shell to libGint.
Define the data structure for the particle information.
This module computes the basic integrals for the truncated coulomb operator.
Definition t_c_g0.F:58
real(kind=dp), dimension(:, :), allocatable, save, public c0
Definition t_c_g0.F:65
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
stores some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:473