(git:374b731)
Loading...
Searching...
No Matches
grid_cpu_prepare_pab.c
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2024 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"
14
15/*******************************************************************************
16 * \brief Cab matrix container to be passed through prepare_pab to cab_add.
17 * \author Ole Schuett
18 ******************************************************************************/
19typedef 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 ******************************************************************************/
28static inline void cab_add(cab_store *cab, const orbital a, const orbital b,
29 const double value) {
30 cab->data[idx(b) * cab->n1 + idx(a)] += value;
31}
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 ******************************************************************************/
39void 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 const prepare_ldiffs ldiffs = prepare_get_ldiffs(func);
43 *la_min_diff = ldiffs.la_min_diff;
44 *la_max_diff = ldiffs.la_max_diff;
45 *lb_min_diff = ldiffs.lb_min_diff;
46 *lb_max_diff = ldiffs.lb_max_diff;
47}
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 ******************************************************************************/
54void 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 const double pab[n2][n1], const int n1_prep,
59 const int n2_prep,
60 double pab_prep[n2_prep][n1_prep]) {
61
62 cab_store cab = {.data = (double *)pab_prep, .n1 = n1_prep};
63
64 for (int lxa = 0; lxa <= la_max; lxa++) {
65 for (int lxb = 0; lxb <= lb_max; lxb++) {
66 for (int lya = 0; lya <= la_max - lxa; lya++) {
67 for (int lyb = 0; lyb <= lb_max - lxb; lyb++) {
68 const int lza_start = imax(la_min - lxa - lya, 0);
69 for (int lza = lza_start; lza <= la_max - lxa - lya; lza++) {
70 const int lzb_start = imax(lb_min - lxb - lyb, 0);
71 for (int lzb = lzb_start; lzb <= lb_max - lxb - lyb; lzb++) {
72 const orbital a = {{lxa, lya, lza}};
73 const orbital b = {{lxb, lyb, lzb}};
74 const double pab_val = pab[o2 + idx(b)][o1 + idx(a)];
75 prepare_pab(func, a, b, zeta, zetb, pab_val, &cab);
76 }
77 }
78 }
79 }
80 }
81 }
82}
83
84// EOF
static int imax(int x, int y)
Returns the larger of two given integer (missing from the C standard)
static GRID_HOST_DEVICE int idx(const orbital a)
Return coset index of given orbital angular momentum.
grid_func
static void cab_add(cab_store *cab, const orbital a, const orbital b, const double value)
Adds given value to matrix element cab[idx(b)][idx(a)].
void grid_cpu_prepare_pab(const enum grid_func func, const int o1, const int o2, const int la_max, const int la_min, const int lb_max, const int lb_min, const double zeta, const double zetb, const int n1, const int n2, const double pab[n2][n1], const int n1_prep, const int n2_prep, double pab_prep[n2_prep][n1_prep])
Selects and transforms a sub-block of the given density matrix block. See grid_cpu_prepare_pab....
void grid_cpu_prepare_get_ldiffs(const enum grid_func func, int *la_min_diff, int *la_max_diff, int *lb_min_diff, int *lb_max_diff)
Returns block size changes due to transformation grid_prepare_pab.
static GRID_DEVICE void prepare_pab(const enum grid_func func, const orbital a, const orbital b, const double zeta, const double zetb, const double pab_val, cab_store *cab)
Transforms a given element of the density matrix according to func.
static prepare_ldiffs prepare_get_ldiffs(const enum grid_func func)
Returns difference in angular momentum range for given func.
Cab matrix container to be passed through get_force/virial to cab_get.
const double * data
Orbital angular momentum.
Differences in angular momentum.