Line data Source code
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: BSD-3-Clause */
6 : /*----------------------------------------------------------------------------*/
7 :
8 : #include <stdio.h>
9 : #include <stdlib.h>
10 :
11 : #include "../common/grid_common.h"
12 : #include "grid_ref_prepare_pab.h"
13 :
14 : /*******************************************************************************
15 : * \brief Cab matrix container to be passed through prepare_pab to cab_add.
16 : * \author Ole Schuett
17 : ******************************************************************************/
18 : typedef struct {
19 : double *data;
20 : const int n1;
21 : } cab_store;
22 :
23 : /*******************************************************************************
24 : * \brief Adds given value to matrix element cab[idx(b)][idx(a)].
25 : * \author Ole Schuett
26 : ******************************************************************************/
27 178826 : static inline void cab_add(cab_store *cab, const orbital a, const orbital b,
28 : const double value) {
29 178826 : cab->data[idx(b) * cab->n1 + idx(a)] += value;
30 178826 : }
31 :
32 : #include "../common/grid_prepare_pab.h"
33 :
34 : /*******************************************************************************
35 : * \brief Returns block size changes due to transformation grid_prepare_pab.
36 : * \author Ole Schuett
37 : ******************************************************************************/
38 10976 : void grid_ref_prepare_get_ldiffs(const enum grid_func func, int *la_min_diff,
39 : int *la_max_diff, int *lb_min_diff,
40 : int *lb_max_diff) {
41 10976 : const prepare_ldiffs ldiffs = prepare_get_ldiffs(func);
42 10976 : *la_min_diff = ldiffs.la_min_diff;
43 10976 : *la_max_diff = ldiffs.la_max_diff;
44 10976 : *lb_min_diff = ldiffs.lb_min_diff;
45 10976 : *lb_max_diff = ldiffs.lb_max_diff;
46 10976 : }
47 :
48 : /*******************************************************************************
49 : * \brief Selects and transforms a sub-block of the given density matrix block.
50 : * See grid_ref_prepare_pab.h for details.
51 : * \author Ole Schuett
52 : ******************************************************************************/
53 10976 : void grid_ref_prepare_pab(const enum grid_func func, const int o1, const int o2,
54 : const int la_max, const int la_min, const int lb_max,
55 : const int lb_min, const double zeta,
56 : const double zetb, const int n1, const int n2,
57 10976 : const double pab[n2][n1], const int n1_prep,
58 : const int n2_prep,
59 10976 : double pab_prep[n2_prep][n1_prep]) {
60 :
61 10976 : cab_store cab = {.data = (double *)pab_prep, .n1 = n1_prep};
62 :
63 33124 : for (int lxa = 0; lxa <= la_max; lxa++) {
64 66856 : for (int lxb = 0; lxb <= lb_max; lxb++) {
65 112390 : for (int lya = 0; lya <= la_max - lxa; lya++) {
66 170176 : for (int lyb = 0; lyb <= lb_max - lxb; lyb++) {
67 102494 : const int lza_start = imax(la_min - lxa - lya, 0);
68 237856 : for (int lza = lza_start; lza <= la_max - lxa - lya; lza++) {
69 135362 : const int lzb_start = imax(lb_min - lxb - lyb, 0);
70 314188 : for (int lzb = lzb_start; lzb <= lb_max - lxb - lyb; lzb++) {
71 178826 : const orbital a = {{lxa, lya, lza}};
72 178826 : const orbital b = {{lxb, lyb, lzb}};
73 178826 : const double pab_val = pab[o2 + idx(b)][o1 + idx(a)];
74 178826 : prepare_pab(func, a, b, zeta, zetb, pab_val, &cab);
75 : }
76 : }
77 : }
78 : }
79 : }
80 : }
81 10976 : }
82 :
83 : // EOF
|