Line data Source code
1 : /*----------------------------------------------------------------------------*/
2 : /* CP2K: A general program to perform molecular dynamics simulations */
3 : /* Copyright 2000-2025 CP2K developers group <https://cp2k.org> */
4 : /* */
5 : /* SPDX-License-Identifier: BSD-3-Clause */
6 : /*----------------------------------------------------------------------------*/
7 :
8 : #include <assert.h>
9 : #include <stdio.h>
10 : #include <stdlib.h>
11 :
12 : #include "../common/grid_common.h"
13 : #include "grid_cpu_prepare_pab.h"
14 :
15 : /*******************************************************************************
16 : * \brief Cab matrix container to be passed through prepare_pab to cab_add.
17 : * \author Ole Schuett
18 : ******************************************************************************/
19 : typedef struct {
20 : double *data;
21 : const int n1;
22 : } cab_store;
23 :
24 : /*******************************************************************************
25 : * \brief Adds given value to matrix element cab[idx(b)][idx(a)].
26 : * \author Ole Schuett
27 : ******************************************************************************/
28 1432608170 : static inline void cab_add(cab_store *cab, const orbital a, const orbital b,
29 : const double value) {
30 1432608170 : cab->data[idx(b) * cab->n1 + idx(a)] += value;
31 1432608170 : }
32 :
33 : #include "../common/grid_prepare_pab.h"
34 :
35 : /*******************************************************************************
36 : * \brief Returns block size changes due to transformation grid_prepare_pab.
37 : * \author Ole Schuett
38 : ******************************************************************************/
39 90380180 : void grid_cpu_prepare_get_ldiffs(const enum grid_func func, int *la_min_diff,
40 : int *la_max_diff, int *lb_min_diff,
41 : int *lb_max_diff) {
42 90380180 : const prepare_ldiffs ldiffs = prepare_get_ldiffs(func);
43 90380180 : *la_min_diff = ldiffs.la_min_diff;
44 90380180 : *la_max_diff = ldiffs.la_max_diff;
45 90380180 : *lb_min_diff = ldiffs.lb_min_diff;
46 90380180 : *lb_max_diff = ldiffs.lb_max_diff;
47 90380180 : }
48 :
49 : /*******************************************************************************
50 : * \brief Selects and transforms a sub-block of the given density matrix block.
51 : * See grid_cpu_prepare_pab.h for details.
52 : * \author Ole Schuett
53 : ******************************************************************************/
54 90380180 : void grid_cpu_prepare_pab(const enum grid_func func, const int o1, const int o2,
55 : const int la_max, const int la_min, const int lb_max,
56 : const int lb_min, const double zeta,
57 : const double zetb, const int n1, const int n2,
58 90380180 : const double pab[n2][n1], const int n1_prep,
59 : const int n2_prep,
60 90380180 : double pab_prep[n2_prep][n1_prep]) {
61 :
62 90380180 : cab_store cab = {.data = (double *)pab_prep, .n1 = n1_prep};
63 :
64 242440305 : for (int lxa = 0; lxa <= la_max; lxa++) {
65 427778818 : for (int lxb = 0; lxb <= lb_max; lxb++) {
66 702852605 : for (int lya = 0; lya <= la_max - lxa; lya++) {
67 1108213911 : for (int lyb = 0; lyb <= lb_max - lxb; lyb++) {
68 681079999 : const int lza_start = imax(la_min - lxa - lya, 0);
69 1579583762 : for (int lza = lza_start; lza <= la_max - lxa - lya; lza++) {
70 898503763 : const int lzb_start = imax(lb_min - lxb - lyb, 0);
71 2132869132 : for (int lzb = lzb_start; lzb <= lb_max - lxb - lyb; lzb++) {
72 1234365369 : const orbital a = {{lxa, lya, lza}};
73 1234365369 : const orbital b = {{lxb, lyb, lzb}};
74 1234365369 : const double pab_val = pab[o2 + idx(b)][o1 + idx(a)];
75 1234365369 : prepare_pab(func, a, b, zeta, zetb, pab_val, &cab);
76 : }
77 : }
78 : }
79 : }
80 : }
81 : }
82 90380180 : }
83 :
84 : // EOF
|