(git:5e7fe52)
Loading...
Searching...
No Matches
coulomb_integral_interface.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 Common interface for two- and three-center Coulomb integrals.
10! **************************************************************************************************
12 USE ai_coulomb, ONLY: coulomb2,&
18 USE kinds, ONLY: dp
19 USE libint_2c_3c, ONLY: eri_2center,&
27 USE orbital_pointers, ONLY: ncoset
28#include "./base/base_uses.f90"
29
30 IMPLICIT NONE
31
32 PRIVATE
33
34 PUBLIC :: coulomb_integral_cleanup, &
39
41 PRIVATE
42 TYPE(cp_libint_t) :: lib_2c
43 TYPE(cp_libint_t) :: lib_3c
44 LOGICAL :: initialized_2c = .false.
45 LOGICAL :: initialized_3c = .false.
47
48CONTAINS
49
50! **************************************************************************************************
51!> \brief Initialize the engines needed by the requested Coulomb integral operations.
52!> \param context operation context containing the selected-library engines
53!> \param max_am_2c maximum angular momentum for the two-center operation
54!> \param max_am_3c maximum angular momentum for the three-center operation
55! **************************************************************************************************
56 SUBROUTINE coulomb_integral_init(context, max_am_2c, max_am_3c)
57 TYPE(coulomb_integral_context_type), INTENT(INOUT) :: context
58 INTEGER, INTENT(IN), OPTIONAL :: max_am_2c, max_am_3c
59
60 IF (PRESENT(max_am_2c)) THEN
61 SELECT CASE (active_integral_library%coulomb2_library)
62 CASE (library_libint)
63 CALL cp_libint_init_2eri(context%lib_2c, max_am_2c)
64 CALL cp_libint_set_contrdepth(context%lib_2c, 1)
65 CASE (library_native)
66 ! Nothing to do.
67 CASE DEFAULT
68 cpabort("Requested two-center Coulomb library is not implemented")
69 END SELECT
70 context%initialized_2c = .true.
71 END IF
72
73 IF (PRESENT(max_am_3c)) THEN
74 SELECT CASE (active_integral_library%coulomb3_library)
75 CASE (library_libint)
76 CALL cp_libint_init_3eri(context%lib_3c, max_am_3c)
77 CALL cp_libint_set_contrdepth(context%lib_3c, 1)
78 CASE (library_native)
79 ! Nothing to do.
80 CASE DEFAULT
81 cpabort("Requested three-center Coulomb library is not implemented")
82 END SELECT
83 context%initialized_3c = .true.
84 END IF
85 END SUBROUTINE coulomb_integral_init
86
87! **************************************************************************************************
88!> \brief Release the engines initialized in a Coulomb integral context.
89!> \param context operation context containing the selected-library engines
90! **************************************************************************************************
91 SUBROUTINE coulomb_integral_cleanup(context)
92 TYPE(coulomb_integral_context_type), INTENT(INOUT) :: context
93
94 IF (context%initialized_2c) THEN
95 SELECT CASE (active_integral_library%coulomb2_library)
96 CASE (library_libint)
97 CALL cp_libint_cleanup_2eri(context%lib_2c)
98 CASE (library_native)
99 ! Nothing to do.
100 CASE DEFAULT
101 cpabort("Requested two-center Coulomb library is not implemented")
102 END SELECT
103 context%initialized_2c = .false.
104 END IF
105
106 IF (context%initialized_3c) THEN
107 SELECT CASE (active_integral_library%coulomb3_library)
108 CASE (library_libint)
109 CALL cp_libint_cleanup_3eri(context%lib_3c)
110 CASE (library_native)
111 ! Nothing to do.
112 CASE DEFAULT
113 cpabort("Requested three-center Coulomb library is not implemented")
114 END SELECT
115 context%initialized_3c = .false.
116 END IF
117 END SUBROUTINE coulomb_integral_cleanup
118
119! **************************************************************************************************
120!> \brief Evaluate one uncontracted two-center Coulomb integral block.
121!> \param context operation context containing the selected-library engine
122!> \param la_min minimum angular momentum on center A
123!> \param la_max maximum angular momentum on center A
124!> \param lb_min minimum angular momentum on center B
125!> \param lb_max maximum angular momentum on center B
126!> \param npgfa number of primitive functions on center A
127!> \param npgfb number of primitive functions on center B
128!> \param zeta exponents on center A
129!> \param zetb exponents on center B
130!> \param rpgfa primitive radii on center A
131!> \param rpgfb primitive radii on center B
132!> \param ra position of center A
133!> \param rb position of center B
134!> \param hab uncontracted integral block
135!> \param potential_parameter Coulomb operator parameters
136! **************************************************************************************************
137 SUBROUTINE compute_coulomb_2c(context, la_min, la_max, lb_min, lb_max, npgfa, npgfb, zeta, zetb, rpgfa, rpgfb, &
138 ra, rb, hab, potential_parameter)
139 TYPE(coulomb_integral_context_type), INTENT(INOUT) :: context
140 INTEGER, INTENT(IN) :: la_min, la_max, lb_min, lb_max, npgfa, &
141 npgfb
142 REAL(dp), DIMENSION(npgfa), INTENT(IN) :: zeta
143 REAL(dp), DIMENSION(npgfb), INTENT(IN) :: zetb
144 REAL(dp), DIMENSION(npgfa), INTENT(IN) :: rpgfa
145 REAL(dp), DIMENSION(npgfb), INTENT(IN) :: rpgfb
146 REAL(dp), DIMENSION(3), INTENT(IN) :: ra, rb
147 REAL(dp), DIMENSION(:, :), INTENT(INOUT) :: hab
148 TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
149
150 INTEGER :: ncoa, ncob
151 REAL(dp) :: rab2
152 REAL(dp), ALLOCATABLE, DIMENSION(:) :: f_work
153 REAL(dp), ALLOCATABLE, DIMENSION(:, :, :) :: v_work
154
155 ncoa = npgfa*ncoset(la_max)
156 ncob = npgfb*ncoset(lb_max)
157 rab2 = (ra(1) - rb(1))**2 + (ra(2) - rb(2))**2 + (ra(3) - rb(3))**2
158
159 SELECT CASE (active_integral_library%coulomb2_library)
160 CASE (library_libint)
161 cpassert(context%initialized_2c)
162 CALL eri_2center(hab, la_min, la_max, npgfa, zeta, rpgfa, ra, &
163 lb_min, lb_max, npgfb, zetb, rpgfb, rb, sqrt(rab2), context%lib_2c, potential_parameter)
164 CASE (library_native)
165 ALLOCATE (f_work(0:la_max + lb_max + 2))
166 ALLOCATE (v_work(ncoa, ncob, la_max + lb_max + 1))
167
168 CALL coulomb2(la_max, npgfa, zeta, rpgfa, la_min, lb_max, npgfb, zetb, rpgfb, lb_min, &
169 rb - ra, rab2, hab, v_work, f_work, screening=.false.)
170
171 DEALLOCATE (v_work, f_work)
172 CASE DEFAULT
173 cpabort("Requested two-center Coulomb library is not implemented")
174 END SELECT
175 END SUBROUTINE compute_coulomb_2c
176
177! **************************************************************************************************
178!> \brief Evaluate one uncontracted three-center Coulomb integral block.
179!> \param context operation context containing the selected-library engine
180!> \param la_min minimum angular momentum on center A
181!> \param la_max maximum angular momentum on center A
182!> \param lb_min minimum angular momentum on center B
183!> \param lb_max maximum angular momentum on center B
184!> \param lc_min minimum angular momentum on center C
185!> \param lc_max maximum angular momentum on center C
186!> \param npgfa number of primitive functions on center A
187!> \param npgfb number of primitive functions on center B
188!> \param npgfc number of primitive functions on center C
189!> \param zeta exponents on center A
190!> \param zetb exponents on center B
191!> \param zetc exponents on center C
192!> \param rpgfa primitive radii on center A
193!> \param rpgfb primitive radii on center B
194!> \param rpgfc primitive radii on center C
195!> \param ra position of center A
196!> \param rb position of center B
197!> \param rc position of center C
198!> \param habc uncontracted integral block
199!> \param potential_parameter Coulomb operator parameters
200! **************************************************************************************************
201 SUBROUTINE compute_coulomb_3c(context, la_min, la_max, lb_min, lb_max, lc_min, lc_max, npgfa, npgfb, npgfc, &
202 zeta, zetb, zetc, rpgfa, rpgfb, rpgfc, ra, rb, rc, habc, potential_parameter)
203 TYPE(coulomb_integral_context_type), INTENT(INOUT) :: context
204 INTEGER, INTENT(IN) :: la_min, la_max, lb_min, lb_max, lc_min, &
205 lc_max, npgfa, npgfb, npgfc
206 REAL(dp), DIMENSION(npgfa), INTENT(IN) :: zeta
207 REAL(dp), DIMENSION(npgfb), INTENT(IN) :: zetb
208 REAL(dp), DIMENSION(npgfc), INTENT(IN) :: zetc
209 REAL(dp), DIMENSION(npgfa), INTENT(IN) :: rpgfa
210 REAL(dp), DIMENSION(npgfb), INTENT(IN) :: rpgfb
211 REAL(dp), DIMENSION(npgfc), INTENT(IN) :: rpgfc
212 REAL(dp), DIMENSION(3), INTENT(IN) :: ra, rb, rc
213 REAL(dp), DIMENSION(:, :, :), INTENT(INOUT) :: habc
214 TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
215
216 INTEGER :: kpgf, nc_end, nc_start, ncoa, ncob, ncoc
217 REAL(dp) :: rab2, rac2, rbc2
218 REAL(dp), ALLOCATABLE, DIMENSION(:) :: f_work, gccc, rpgfa_work, rpgfb_work, &
219 rpgfc_work
220 REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: vabc
221 REAL(dp), ALLOCATABLE, DIMENSION(:, :, :, :) :: v_work
222
223 ncoa = npgfa*ncoset(la_max)
224 ncob = npgfb*ncoset(lb_max)
225 ncoc = ncoset(lc_max)
226 rab2 = (rb(1) - ra(1))**2 + (rb(2) - ra(2))**2 + (rb(3) - ra(3))**2
227 rac2 = (rc(1) - ra(1))**2 + (rc(2) - ra(2))**2 + (rc(3) - ra(3))**2
228 rbc2 = (rc(1) - rb(1))**2 + (rc(2) - rb(2))**2 + (rc(3) - rb(3))**2
229
230 SELECT CASE (active_integral_library%coulomb3_library)
231 CASE (library_libint)
232 cpassert(context%initialized_3c)
233 CALL eri_3center(habc, la_min, la_max, npgfa, zeta, rpgfa, ra, &
234 lb_min, lb_max, npgfb, zetb, rpgfb, rb, &
235 lc_min, lc_max, npgfc, zetc, rpgfc, rc, &
236 sqrt(rab2), sqrt(rac2), sqrt(rbc2), context%lib_3c, potential_parameter)
237 CASE (library_native)
238 ALLOCATE (f_work(0:la_max + lb_max + lc_max + 2))
239 f_work(:) = 0.0_dp
240 ALLOCATE (v_work(ncoa, ncob, ncoc, la_max + lb_max + lc_max + 1))
241 v_work(:, :, :, :) = 0.0_dp
242
243 ! no screening
244 ALLOCATE (rpgfa_work(npgfa))
245 ALLOCATE (rpgfb_work(npgfb))
246 ALLOCATE (rpgfc_work(npgfc))
247 rpgfa_work(:) = 1.0e10_dp
248 rpgfb_work(:) = 1.0e10_dp
249 rpgfc_work(:) = 1.0e10_dp
250 ALLOCATE (gccc(ncoc))
251 gccc(:) = 0.0_dp
252 ALLOCATE (vabc(ncoa, ncob))
253 vabc(:, :) = 0.0_dp
254
255 ! coulomb3 handles a single primitive Gaussian on center C per call.
256 DO kpgf = 1, npgfc
257 ! Each primitive occupies an ncoc-wide block in the uncontracted array.
258 nc_start = (kpgf - 1)*ncoc + ncoset(lc_min - 1) + 1
259 nc_end = kpgf*ncoc
260
261 CALL coulomb3(la_max, npgfa, zeta(:), rpgfa_work(:), la_min, &
262 lb_max, npgfb, zetb(:), rpgfb_work(:), lb_min, &
263 lc_max, zetc(kpgf), rpgfc_work(kpgf), lc_min, &
264 gccc, rb - ra, rab2, rc - ra, rac2, rbc2, &
265 vabc, habc(:, :, nc_start:nc_end), v_work, f_work)
266 END DO
267
268 DEALLOCATE (v_work, f_work, rpgfa_work, rpgfb_work, rpgfc_work, gccc, vabc)
269 CASE DEFAULT
270 cpabort("Requested three-center Coulomb library is not implemented")
271 END SELECT
272 END SUBROUTINE compute_coulomb_3c
273
Calculation of Coulomb integrals over Cartesian Gaussian-type functions (electron repulsion integrals...
Definition ai_coulomb.F:41
subroutine, public coulomb2(la_max, npgfa, zeta, rpgfa, la_min, lc_max, npgfc, zetc, rpgfc, lc_min, rac, rac2, vac, v, f, screening)
Calculation of the primitive two-center Coulomb integrals over Cartesian Gaussian-type functions.
Definition ai_coulomb.F:85
subroutine, public coulomb3(la_max, npgfa, zeta, rpgfa, la_min, lb_max, npgfb, zetb, rpgfb, lb_min, lc_max, zetc, rpgfc, lc_min, gccc, rab, rab2, rac, rac2, rbc2, vabc, int_abc, v, f, maxder, vabc_plus)
Calculation of the primitive three-center Coulomb integrals over Cartesian Gaussian-type functions (e...
Definition ai_coulomb.F:433
Common interface for two- and three-center Coulomb integrals.
subroutine, public coulomb_integral_cleanup(context)
Release the engines initialized in a Coulomb integral context.
subroutine, public compute_coulomb_3c(context, la_min, la_max, lb_min, lb_max, lc_min, lc_max, npgfa, npgfb, npgfc, zeta, zetb, zetc, rpgfa, rpgfb, rpgfc, ra, rb, rc, habc, potential_parameter)
Evaluate one uncontracted three-center Coulomb integral block.
subroutine, public coulomb_integral_init(context, max_am_2c, max_am_3c)
Initialize the engines needed by the requested Coulomb integral operations.
subroutine, public compute_coulomb_2c(context, la_min, la_max, lb_min, lb_max, npgfa, npgfb, zeta, zetb, rpgfa, rpgfb, ra, rb, hab, potential_parameter)
Evaluate one uncontracted two-center Coulomb integral block.
Library choices for electronic integral APIs.
type(integral_library_type), save, public active_integral_library
integer, parameter, public library_native
integer, parameter, public library_libint
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_2center(int_ab, la_min, la_max, npgfa, zeta, rpgfa, ra, lb_min, lb_max, npgfb, zetb, rpgfb, rb, dab, lib, potential_parameter)
Computes the 2-center electron repulsion integrals (a|b) for a given set of cartesian gaussian orbita...
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...
Interface to the Libint-Library or a c++ wrapper.
subroutine, public cp_libint_init_2eri(lib, max_am)
subroutine, public cp_libint_init_3eri(lib, max_am)
subroutine, public cp_libint_cleanup_3eri(lib)
subroutine, public cp_libint_set_contrdepth(lib, contrdepth)
subroutine, public cp_libint_cleanup_2eri(lib)
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset