(git:899a4fa)
Loading...
Searching...
No Matches
ai_cartesian_operators.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 Coordinate and basis-center derivative ladders for Cartesian Gaussian integrals.
10!> Derivatives act on a basis function with the integral operator held fixed.
11!> Electronic-coordinate derivatives have the opposite sign.
12! **************************************************************************************************
14 USE kinds, ONLY: dp
15 USE mathlib, ONLY: binomial_gen
16 USE orbital_pointers, ONLY: coset, &
17 indco, &
18 ncoset
19#include "../base/base_uses.f90"
20
21 IMPLICIT NONE
22 PRIVATE
23
26
28 MODULE PROCEDURE cartesian_ladder_real, cartesian_ladder_complex
29 END INTERFACE cartesian_ladder
30
32 MODULE PROCEDURE apply_cartesian_operator_pair_real, apply_cartesian_operator_pair_complex
34
36 MODULE PROCEDURE apply_cartesian_1d_real, apply_cartesian_1d_complex
37 END INTERFACE apply_cartesian_1d
38
39CONTAINS
40
41! **************************************************************************************************
42!> \brief Construct base, raised, lowered and degree indices for a Cartesian ladder.
43!> \param lmax highest output shell or one-dimensional degree
44!> \param lmin lowest output shell (zero for one-dimensional tables)
45!> \param axis Cartesian axis, or zero for a one-dimensional table
46!> \param map rows contain base, raised, lowered and degree indices
47!> \param source_lmin optional lowest input shell; defaults to lmin for Cartesian blocks
48! **************************************************************************************************
49 SUBROUTINE cartesian_ladder_map(lmax, lmin, axis, map, source_lmin)
50 INTEGER, INTENT(IN) :: lmax, lmin, axis
51 INTEGER, DIMENSION(:, :), INTENT(OUT) :: map
52 INTEGER, INTENT(IN), OPTIONAL :: source_lmin
53
54 INTEGER :: i, ico, lowered(3), offset, power(3), &
55 raised(3), source_offset
56
57 IF (axis == 0) THEN
58 DO i = 0, lmax
59 map(:, i + 1) = [i + 1, i + 2, max(1, i), i]
60 END DO
61 ELSE
62 offset = ncoset(lmin - 1)
63 source_offset = offset
64 IF (PRESENT(source_lmin)) source_offset = ncoset(source_lmin - 1)
65 DO ico = offset + 1, ncoset(lmax)
66 power = indco(:, ico)
67 raised = power
68 lowered = power
69 raised(axis) = raised(axis) + 1
70 lowered(axis) = max(0, lowered(axis) - 1)
71 map(:, ico - offset) = [ico - source_offset, &
72 coset(raised(1), raised(2), raised(3)) - source_offset, &
73 max(1, coset(lowered(1), lowered(2), lowered(3)) - source_offset), power(axis)]
74 END DO
75 END IF
76 END SUBROUTINE cartesian_ladder_map
77
78! **************************************************************************************************
79!> \brief Apply one coordinate or basis-center derivative ladder to indexed integrals.
80!> \param source integral block including the raised functions
81!> \param values transformed integral block
82!> \param map base, raised, lowered and degree indices
83!> \param derivative select a basis-center derivative instead of coordinate multiplication
84!> \param exponent exponent of the differentiated Gaussian
85!> \param origin displacement of the Gaussian center from the coordinate reference point
86!> \param right apply the map to columns rather than rows
87! **************************************************************************************************
88 PURE SUBROUTINE cartesian_ladder_real (source, values, map, derivative, exponent, origin, right)
89 REAL (kind=dp), DIMENSION(:, :), INTENT(IN) :: source
90 REAL (kind=dp), DIMENSION(:, :), INTENT(OUT) :: values
91 INTEGER, DIMENSION(:, :), INTENT(IN) :: map
92 LOGICAL, INTENT(IN) :: derivative
93 REAL(kind=dp), INTENT(IN) :: exponent, origin
94 LOGICAL, INTENT(IN) :: right
95
96 INTEGER :: i, j, second_index
97 REAL(kind=dp) :: scale, second_scale(SIZE(map, 2))
98
99 IF (derivative) THEN
100 scale = 2.0_dp*exponent
101 second_scale = -real(map(4, :), dp)
102 second_index = 3
103 ELSE
104 scale = 1.0_dp
105 second_scale = origin
106 second_index = 1
107 END IF
108
109 ! Keep the first (contiguous) dimension innermost on both sides.
110 IF (right) THEN
111 DO j = 1, SIZE(map, 2)
112 DO i = 1, SIZE(values, 1)
113 values(i, j) = scale*source(i, map(2, j)) + &
114 second_scale(j)*source(i, map(second_index, j))
115 END DO
116 END DO
117 ELSE
118 DO j = 1, SIZE(values, 2)
119 DO i = 1, SIZE(map, 2)
120 values(i, j) = scale*source(map(2, i), j) + &
121 second_scale(i)*source(map(second_index, i), j)
122 END DO
123 END DO
124 END IF
125 END SUBROUTINE cartesian_ladder_real
126
127! **************************************************************************************************
128!> \brief Apply an ordered pair of coordinate or derivative ladders to integral blocks.
129!> Maps describe source-to-work and work-to-output transformations. The first result
130!> is reused for all requested second axes. On the same basis function the resulting
131!> operator product is O_first O_second: the second operator acts on the Gaussian first.
132!> A derivative represents minus the electronic gradient, equal to a basis-center
133!> derivative on an unmodified Gaussian. Exponents and supplied origins are fixed
134!> coefficients; total center derivatives of coordinate prefactors require their
135!> parameter dependence to be accounted for by the caller.
136!> \param source integral block including all required raised and lowered functions
137!> \param values transformed components in the order specified by components
138!> \param map_first first maps, indexed by map entry, output function and axis
139!> \param map_second second maps into work, with the same axis convention
140!> \param components first and second map-axis indices; use a single map axis for a 1D table
141!> \param derivative select a derivative instead of coordinate multiplication for each step
142!> \param exponents Gaussian exponents for the two steps, unused for coordinate multiplication
143!> \param right select columns instead of rows for each step
144!> \param work intermediate block, retained after the last requested first axis
145!> \param origin optional center-to-reference displacements indexed by map axis and step; defaults to zero
146! **************************************************************************************************
147 PURE SUBROUTINE apply_cartesian_operator_pair_real (source, values, map_first, map_second, &
148 components, derivative, exponents, right, work, origin)
149 REAL (kind=dp), DIMENSION(:, :), INTENT(IN) :: source
150 REAL (kind=dp), DIMENSION(:, :, :), INTENT(OUT) :: values
151 INTEGER, DIMENSION(:, :, :), INTENT(IN) :: map_first, map_second
152 INTEGER, DIMENSION(:, :), INTENT(IN) :: components
153 REAL(kind=dp), DIMENSION(2), INTENT(IN) :: exponents
154 LOGICAL, DIMENSION(2), INTENT(IN) :: derivative, right
155 REAL (kind=dp), DIMENSION(:, :), INTENT(INOUT) :: work
156 REAL(kind=dp), DIMENSION(3, 2), INTENT(IN), OPTIONAL :: origin
157
158 INTEGER :: axis, icomp
159 REAL(kind=dp) :: center(3, 2)
160
161 center = 0.0_dp
162 IF (PRESENT(origin)) center = origin
163 DO axis = 1, SIZE(map_first, 3)
164 IF (.NOT. any(components(1, :) == axis)) cycle
165 CALL cartesian_ladder(source, work, map_first(:, :, axis), &
166 derivative(1), exponents(1), center(axis, 1), right(1))
167 DO icomp = 1, SIZE(components, 2)
168 IF (components(1, icomp) /= axis) cycle
169 CALL cartesian_ladder(work, values(:, :, icomp), map_second(:, :, components(2, icomp)), &
170 derivative(2), exponents(2), center(components(2, icomp), 2), right(2))
171 END DO
172 END DO
173 END SUBROUTINE apply_cartesian_operator_pair_real
174! **************************************************************************************************
175!> \brief Apply one coordinate or basis-center derivative ladder to indexed integrals.
176!> \param source integral block including the raised functions
177!> \param values transformed integral block
178!> \param map base, raised, lowered and degree indices
179!> \param derivative select a basis-center derivative instead of coordinate multiplication
180!> \param exponent exponent of the differentiated Gaussian
181!> \param origin displacement of the Gaussian center from the coordinate reference point
182!> \param right apply the map to columns rather than rows
183! **************************************************************************************************
184 PURE SUBROUTINE cartesian_ladder_complex (source, values, map, derivative, exponent, origin, right)
185 COMPLEX (KIND=dp), DIMENSION(:, :), INTENT(IN) :: source
186 COMPLEX (KIND=dp), DIMENSION(:, :), INTENT(OUT) :: values
187 INTEGER, DIMENSION(:, :), INTENT(IN) :: map
188 LOGICAL, INTENT(IN) :: derivative
189 REAL(kind=dp), INTENT(IN) :: exponent, origin
190 LOGICAL, INTENT(IN) :: right
191
192 INTEGER :: i, j, second_index
193 REAL(kind=dp) :: scale, second_scale(SIZE(map, 2))
194
195 IF (derivative) THEN
196 scale = 2.0_dp*exponent
197 second_scale = -real(map(4, :), dp)
198 second_index = 3
199 ELSE
200 scale = 1.0_dp
201 second_scale = origin
202 second_index = 1
203 END IF
204
205 ! Keep the first (contiguous) dimension innermost on both sides.
206 IF (right) THEN
207 DO j = 1, SIZE(map, 2)
208 DO i = 1, SIZE(values, 1)
209 values(i, j) = scale*source(i, map(2, j)) + &
210 second_scale(j)*source(i, map(second_index, j))
211 END DO
212 END DO
213 ELSE
214 DO j = 1, SIZE(values, 2)
215 DO i = 1, SIZE(map, 2)
216 values(i, j) = scale*source(map(2, i), j) + &
217 second_scale(i)*source(map(second_index, i), j)
218 END DO
219 END DO
220 END IF
221 END SUBROUTINE cartesian_ladder_complex
222
223! **************************************************************************************************
224!> \brief Apply an ordered pair of coordinate or derivative ladders to integral blocks.
225!> Maps describe source-to-work and work-to-output transformations. The first result
226!> is reused for all requested second axes. On the same basis function the resulting
227!> operator product is O_first O_second: the second operator acts on the Gaussian first.
228!> A derivative represents minus the electronic gradient, equal to a basis-center
229!> derivative on an unmodified Gaussian. Exponents and supplied origins are fixed
230!> coefficients; total center derivatives of coordinate prefactors require their
231!> parameter dependence to be accounted for by the caller.
232!> \param source integral block including all required raised and lowered functions
233!> \param values transformed components in the order specified by components
234!> \param map_first first maps, indexed by map entry, output function and axis
235!> \param map_second second maps into work, with the same axis convention
236!> \param components first and second map-axis indices; use a single map axis for a 1D table
237!> \param derivative select a derivative instead of coordinate multiplication for each step
238!> \param exponents Gaussian exponents for the two steps, unused for coordinate multiplication
239!> \param right select columns instead of rows for each step
240!> \param work intermediate block, retained after the last requested first axis
241!> \param origin optional center-to-reference displacements indexed by map axis and step; defaults to zero
242! **************************************************************************************************
243 PURE SUBROUTINE apply_cartesian_operator_pair_complex (source, values, map_first, map_second, &
244 components, derivative, exponents, right, work, origin)
245 COMPLEX (KIND=dp), DIMENSION(:, :), INTENT(IN) :: source
246 COMPLEX (KIND=dp), DIMENSION(:, :, :), INTENT(OUT) :: values
247 INTEGER, DIMENSION(:, :, :), INTENT(IN) :: map_first, map_second
248 INTEGER, DIMENSION(:, :), INTENT(IN) :: components
249 REAL(kind=dp), DIMENSION(2), INTENT(IN) :: exponents
250 LOGICAL, DIMENSION(2), INTENT(IN) :: derivative, right
251 COMPLEX (KIND=dp), DIMENSION(:, :), INTENT(INOUT) :: work
252 REAL(kind=dp), DIMENSION(3, 2), INTENT(IN), OPTIONAL :: origin
253
254 INTEGER :: axis, icomp
255 REAL(kind=dp) :: center(3, 2)
256
257 center = 0.0_dp
258 IF (PRESENT(origin)) center = origin
259 DO axis = 1, SIZE(map_first, 3)
260 IF (.NOT. any(components(1, :) == axis)) cycle
261 CALL cartesian_ladder(source, work, map_first(:, :, axis), &
262 derivative(1), exponents(1), center(axis, 1), right(1))
263 DO icomp = 1, SIZE(components, 2)
264 IF (components(1, icomp) /= axis) cycle
265 CALL cartesian_ladder(work, values(:, :, icomp), map_second(:, :, components(2, icomp)), &
266 derivative(2), exponents(2), center(components(2, icomp), 2), right(2))
267 END DO
268 END DO
269 END SUBROUTINE apply_cartesian_operator_pair_complex
270
271! **************************************************************************************************
272!> \brief Apply a Cartesian operator on either side of a primitive integral block.
273!> The input includes one extra shell on both sides. Coordinate multiplication
274!> uses the supplied shell-range layout; derivative inputs extend the lowest
275!> shell by one on the selected side for lowering. Screened primitive blocks
276!> must be zero in the input, including their raised and lowered functions.
277!> \param la_max highest output shell on A
278!> \param la_min lowest output shell on A
279!> \param npgfa number of primitives on A
280!> \param lb_max highest output shell on B
281!> \param lb_min lowest output shell on B
282!> \param npgfb number of primitives on B
283!> \param ab input integral block with raised shells
284!> \param values three Cartesian components in the output shell-range layout
285!> \param right act on the ket rather than the bra
286!> \param derivative select a basis-center derivative
287!> \param exponents Gaussian exponents on the selected side, required for derivatives
288!> \param origin displacement of the selected center from the coordinate reference point
289! **************************************************************************************************
290 SUBROUTINE apply_cartesian_operator(la_max, la_min, npgfa, lb_max, lb_min, npgfb, &
291 ab, values, right, derivative, exponents, origin)
292 INTEGER, INTENT(IN) :: la_max, la_min, npgfa, lb_max, lb_min, &
293 npgfb
294 REAL(kind=dp), DIMENSION(:, :), INTENT(IN) :: ab
295 REAL(kind=dp), DIMENSION(:, :, :), INTENT(OUT) :: values
296 LOGICAL, INTENT(IN) :: right, derivative
297 REAL(kind=dp), DIMENSION(:), INTENT(IN), OPTIONAL :: exponents
298 REAL(kind=dp), DIMENSION(3), INTENT(IN), OPTIONAL :: origin
299
300 INTEGER :: axis, ia, iap, ib, ibp, ipgf, jpgf, n, &
301 na, nap, nb, nbp, source_min_a, &
302 source_min_b
303 INTEGER, ALLOCATABLE :: map(:, :, :)
304 LOGICAL :: valid_shape
305 REAL(kind=dp) :: center(3), exponent
306
307 na = ncoset(la_max) - ncoset(la_min - 1)
308 nb = ncoset(lb_max) - ncoset(lb_min - 1)
309 source_min_a = la_min
310 source_min_b = lb_min
311 IF (derivative) THEN
312 IF (right) THEN
313 source_min_b = max(0, lb_min - 1)
314 ELSE
315 source_min_a = max(0, la_min - 1)
316 END IF
317 END IF
318 nap = ncoset(la_max + 1) - ncoset(source_min_a - 1)
319 nbp = ncoset(lb_max + 1) - ncoset(source_min_b - 1)
320 IF (derivative) THEN
321 cpassert(PRESENT(exponents))
322 END IF
323 valid_shape = all(shape(ab) >= [nap*npgfa, nbp*npgfb])
324 cpassert(valid_shape)
325 valid_shape = all(shape(values) >= [na*npgfa, nb*npgfb, 3])
326 cpassert(valid_shape)
327 center = 0.0_dp
328 IF (PRESENT(origin)) center = origin
329 n = merge(nb, na, right)
330 ALLOCATE (map(4, n, 3))
331 DO axis = 1, 3
332 IF (right) THEN
333 CALL cartesian_ladder_map(lb_max, lb_min, axis, map(:, :, axis), source_min_b)
334 ELSE
335 CALL cartesian_ladder_map(la_max, la_min, axis, map(:, :, axis), source_min_a)
336 END IF
337 END DO
338
339 values = 0.0_dp
340 DO ipgf = 1, npgfa
341 ia = (ipgf - 1)*na
342 iap = (ipgf - 1)*nap
343 DO jpgf = 1, npgfb
344 ib = (jpgf - 1)*nb
345 ibp = (jpgf - 1)*nbp
346 exponent = 0.0_dp
347 IF (derivative) exponent = exponents(merge(jpgf, ipgf, right))
348 DO axis = 1, 3
349 CALL cartesian_ladder(ab(iap + 1:iap + nap, ibp + 1:ibp + nbp), &
350 values(ia + 1:ia + na, ib + 1:ib + nb, axis), map(:, :, axis), &
351 derivative, exponent, center(axis), right)
352 END DO
353 END DO
354 END DO
355 END SUBROUTINE apply_cartesian_operator
356
357! **************************************************************************************************
358!> \brief Apply the common ladder to separable one-dimensional integral tables.
359!> \param source input tables indexed by the degrees on A and B and the Cartesian axis
360!> \param values transformed tables; entries outside the requested range are untouched
361!> \param la_max highest output degree on A
362!> \param lb_max highest output degree on B
363!> \param right act on B rather than A
364!> \param derivative select a basis-center derivative
365!> \param exponent Gaussian exponent on the selected side
366!> \param origin displacement of that center from the coordinate reference point
367! **************************************************************************************************
368 SUBROUTINE apply_cartesian_1d_real (source, values, la_max, lb_max, right, derivative, exponent, origin)
369 REAL (KIND=dp), DIMENSION(0:, 0:, :), INTENT(IN) :: source
370 REAL (KIND=dp), DIMENSION(0:, 0:, :), INTENT(INOUT) :: values
371 INTEGER, INTENT(IN) :: la_max, lb_max
372 LOGICAL, INTENT(IN) :: right, derivative
373 REAL(KIND=dp), INTENT(IN) :: exponent, origin(3)
374
375 INTEGER :: axis, map(4, MERGE(lb_max, la_max, right) + 1)
376
377 CALL cartesian_ladder_map(merge(lb_max, la_max, right), 0, 0, map)
378 DO axis = 1, 3
379 CALL cartesian_ladder(source(:, :, axis), values(0:la_max, 0:lb_max, axis), map, &
380 derivative, exponent, origin(axis), right)
381 END DO
382 END SUBROUTINE apply_cartesian_1d_real
383! **************************************************************************************************
384!> \brief Apply the common ladder to separable one-dimensional integral tables.
385!> \param source input tables indexed by the degrees on A and B and the Cartesian axis
386!> \param values transformed tables; entries outside the requested range are untouched
387!> \param la_max highest output degree on A
388!> \param lb_max highest output degree on B
389!> \param right act on B rather than A
390!> \param derivative select a basis-center derivative
391!> \param exponent Gaussian exponent on the selected side
392!> \param origin displacement of that center from the coordinate reference point
393! **************************************************************************************************
394 SUBROUTINE apply_cartesian_1d_complex (source, values, la_max, lb_max, right, derivative, exponent, origin)
395 COMPLEX (KIND=dp), DIMENSION(0:, 0:, :), INTENT(IN) :: source
396 COMPLEX (KIND=dp), DIMENSION(0:, 0:, :), INTENT(INOUT) :: values
397 INTEGER, INTENT(IN) :: la_max, lb_max
398 LOGICAL, INTENT(IN) :: right, derivative
399 REAL(KIND=dp), INTENT(IN) :: exponent, origin(3)
400
401 INTEGER :: axis, map(4, MERGE(lb_max, la_max, right) + 1)
402
403 CALL cartesian_ladder_map(merge(lb_max, la_max, right), 0, 0, map)
404 DO axis = 1, 3
405 CALL cartesian_ladder(source(:, :, axis), values(0:la_max, 0:lb_max, axis), map, &
406 derivative, exponent, origin(axis), right)
407 END DO
408 END SUBROUTINE apply_cartesian_1d_complex
409
410! **************************************************************************************************
411!> \brief Form requested coordinate powers from separable Cartesian integral tables.
412!> Only requested powers are stored. With the origin on A, each power is a
413!> direct shift of the bra degree; other origins use the binomial expansion.
414!> \param source input tables with enough raised bra degrees for the largest power
415!> \param values tables indexed by bra degree, ket degree, requested power and axis
416!> \param la_max highest output degree on A
417!> \param lb_max highest output degree on B
418!> \param powers nonnegative coordinate powers to evaluate
419!> \param origin displacement of A from the coordinate reference point
420! **************************************************************************************************
421 SUBROUTINE cartesian_polynomial_1d(source, values, la_max, lb_max, powers, origin)
422 REAL(kind=dp), DIMENSION(0:, 0:, :), INTENT(IN) :: source
423 REAL(kind=dp), DIMENSION(0:, 0:, 0:, :), &
424 INTENT(OUT) :: values
425 INTEGER, INTENT(IN) :: la_max, lb_max, powers(0:)
426 REAL(kind=dp), INTENT(IN) :: origin(3)
427
428 INTEGER :: axis, i, k, p
429 REAL(kind=dp) :: coefficient
430
431 DO axis = 1, 3
432 DO i = 0, SIZE(powers) - 1
433 p = powers(i)
434 IF (abs(origin(axis)) <= 0.0_dp) THEN
435 values(:, :, i, axis) = source(p:p + la_max, 0:lb_max, axis)
436 ELSE
437 values(:, :, i, axis) = 0.0_dp
438 DO k = 0, p
439 coefficient = binomial_gen(real(p, dp), k)*origin(axis)**(p - k)
440 values(:, :, i, axis) = values(:, :, i, axis) + &
441 coefficient*source(k:k + la_max, 0:lb_max, axis)
442 END DO
443 END IF
444 END DO
445 END DO
446 END SUBROUTINE cartesian_polynomial_1d
447
448END MODULE ai_cartesian_operators
Coordinate and basis-center derivative ladders for Cartesian Gaussian integrals. Derivatives act on a...
subroutine, public cartesian_polynomial_1d(source, values, la_max, lb_max, powers, origin)
Form requested coordinate powers from separable Cartesian integral tables. Only requested powers are ...
subroutine, public cartesian_ladder_map(lmax, lmin, axis, map, source_lmin)
Construct base, raised, lowered and degree indices for a Cartesian ladder.
subroutine, public apply_cartesian_operator(la_max, la_min, npgfa, lb_max, lb_min, npgfb, ab, values, right, derivative, exponents, origin)
Apply a Cartesian operator on either side of a primitive integral block. The input includes one extra...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Collection of simple mathematical functions and subroutines.
Definition mathlib.F:15
elemental real(kind=dp) function, public binomial_gen(z, k)
The generalized binomial coefficient z over k for 0 <= k <= n is calculated. (z) z*(z-1)*....
Definition mathlib.F:240
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
integer, dimension(:, :, :), allocatable, public coset
integer, dimension(:, :), allocatable, public indco