Debian Codegraph @

docs/source/c_example.rst

raw
1 Collocation Example
2 ===================
3
4 Single Basis Functions
5 ----------------------
6
7 A collocation grid between a single basis and a Cartesian grid can be computed
8 with the :c:func:`~gg_collocation` function. For example, we will use a grid
9 starting at the origin along the ``z`` axis and a ``S`` shell at the origin:
10
11 .. code-block:: C
12
13 #include <stdio.h>
14 #include "gau2grid.h"
15
16 int main() {
17 // Generate grid
18 long int npoints = 5;
19 double xyz[15] = {0, 0, 0, 0, 0, // x components
20 0, 0, 0, 0, 0, // y components
21 0, 1, 2, 3, 4}; // z components
22 long int xyz_stride = 1; // This is a contiguous format
23
24 // Gaussian data
25 int nprim = 1;
26 double coef[1] = {1};
27 double exp[1] = {1};
28 double center[3] = {0, 0, 0};
29 int order = GG_CARTESIAN_CCA; // Use cartesian components
30
31 double s_output[5] = {0};
32 gg_collocation(0, // The angular momentum
33 npoints, xyz, xyz_stride, // Grid data
34 nprim, coef, exp, center, order, // Gaussian data
35 s_output); // Output
36
37 // Print output to stdout
38 for (int i = 0; i < npoints; i += 1) {
39 printf("%lf ", s_output[i]);
40 }
41 printf("\n");
42 }
43
44 The resulting output should be:
45
46 .. code-block:: bash
47
48 1.000000 0.367879 0.018316 0.000123 0.000000
49
50 For higher angular momentum functions that output size should ``ncomponents x
51 npoints`` in size. Where each component is on a unique row or the ``X``
52 component starts at position ``0``, the ``Y`` component starts at position
53 ``5``, and the ``Z`` component starts at position ``10`` as out grid is of
54 length ``5``. See :ref:`Gaussian Component Orders <gpo_order>` for more details or order output.
55
56 The xyz input shape can either be organized contiguously in each dimension like
57 the above or packed in a xyz, xyz, ... fashion. If the ``xyz_stride`` is not 1,
58 the shape refers to the strides per row. For example, if the data is packed as
59 xyzw, xyzw, ... (where w could be a DFT grid weight) the ``xyz_stride`` should
60 be 4.
61
62 .. code-block:: C
63
64 long int xyz_stride = 3;
65 double xyz[15] = {0, 0, 0,
66 0, 0, 1,
67 0, 0, 2,
68 0, 0, 3,
69 0, 0, 4}; // xyz, xyz, ... format
70
71
72 gg_collocation(0, // The angular momentum
73 npoints, xyz, xyz_stride, // Grid data
74 nprim, coef, exp, center, order, // Gaussian data
75 s_output); // Output
76
77 Multiple Basis Functions
78 ------------------------
79
80 Often collocation matrices are computed for multiple basis functions at once.
81 The below is an example of usage:
82
83 .. code-block:: C
84
85 #include <stdio.h>
86 #include "gau2grid.h"
87
88 int main() {
89 // Generate grid
90 long int npoints = 5;
91 double xyz[15] = {0, 0, 0, 0, 0, // x components
92 0, 0, 0, 0, 0, // y components
93 0, 1, 2, 3, 4}; // z components
94 long int xyz_stride = 1;
95
96 // Gaussian data
97 int nprim = 1;
98 double coef[1] = {1};
99 double exp[1] = {1};
100 double center[3] = {0, 0, 0};
101 int order = GG_SPHERICAL_GAUSSIAN; // Use spherical components
102 int spherical = 1; // True because spherical
103
104 // Size ncomponents * npoints, (1 + 3 + 5) * 5
105 double output[45] = {0};
106 int row = 0;
107 for (int L = 0; L < 3; L++) {
108 gg_collocation(L, // The angular momentum
109 npoints, xyz, xyz_stride, // Grid data
110 nprim, coef, exp, center, order, // Gaussian data
111 output + (row * npoints)); // Output, shift pointer
112
113 row += gg_ncomponents(L, spherical); // Increment rows skipped
114 }
115
116 // Print out by row
117 for (int i = 0; i < row; i += 1) {
118 for (int j = 0; j < npoints; j += 1) {
119 printf("%lf ", output[i * npoints + j]);
120 }
121 printf("\n");
122 }
123 }
124
125 The resulting output should be:
126
127 .. code-block:: bash
128
129 1.000000 0.367879 0.018316 0.000123 0.000000 // S
130 0.000000 0.367879 0.036631 0.000370 0.000000 // P_0
131 0.000000 0.000000 0.000000 0.000000 0.000000 // P^+_0
132 0.000000 0.000000 0.000000 0.000000 0.000000 // P^-_0
133 0.000000 0.367879 0.073263 0.001111 0.000002 // D_0
134 0.000000 0.000000 0.000000 0.000000 0.000000 // D^+_1
135 0.000000 0.000000 0.000000 0.000000 0.000000 // D^-_1
136 0.000000 0.000000 0.000000 0.000000 0.000000 // D^+_2
137 0.000000 0.000000 0.000000 0.000000 0.000000 // D^-_2