1 #include "simint/boys/boys.h"
2 #include "simint/ostei/gen/ostei_generated.h"
3 #include "simint/vectorization/vectorization.h"
4 #include <math.h>
5 #include <string.h>
6 
7 
ostei_d_s_s_s(struct simint_multi_shellpair const P,struct simint_multi_shellpair const Q,double screen_tol,double * const restrict work,double * const restrict INT__d_s_s_s)8 int ostei_d_s_s_s(struct simint_multi_shellpair const P,
9                   struct simint_multi_shellpair const Q,
10                   double screen_tol,
11                   double * const restrict work,
12                   double * const restrict INT__d_s_s_s)
13 {
14 
15     SIMINT_ASSUME_ALIGN_DBL(work);
16     SIMINT_ASSUME_ALIGN_DBL(INT__d_s_s_s);
17     memset(INT__d_s_s_s, 0, P.nshell12_clip * Q.nshell12_clip * 6 * sizeof(double));
18 
19     int ab, cd, abcd;
20     int istart, jstart;
21     int iprimcd, nprim_icd, icd;
22     const int check_screen = (screen_tol > 0.0);
23     int i, j;
24     int n;
25     int not_screened;
26 
27     // partition workspace
28     SIMINT_DBLTYPE * const primwork = (SIMINT_DBLTYPE *)(work + SIMINT_NSHELL_SIMD*0);
29     SIMINT_DBLTYPE * const restrict PRIM_INT__s_s_s_s = primwork + 0;
30     SIMINT_DBLTYPE * const restrict PRIM_INT__p_s_s_s = primwork + 3;
31     SIMINT_DBLTYPE * const restrict PRIM_INT__d_s_s_s = primwork + 9;
32     double * const hrrwork = (double *)(primwork + 15);
33 
34 
35     // Create constants
36     const SIMINT_DBLTYPE const_1 = SIMINT_DBLSET1(1);
37     const SIMINT_DBLTYPE one_half = SIMINT_DBLSET1(0.5);
38 
39 
40     ////////////////////////////////////////
41     // Loop over shells and primitives
42     ////////////////////////////////////////
43 
44     abcd = 0;
45     istart = 0;
46     for(ab = 0; ab < P.nshell12_clip; ++ab)
47     {
48         const int iend = istart + P.nprim12[ab];
49 
50         cd = 0;
51         jstart = 0;
52 
53         for(cd = 0; cd < Q.nshell12_clip; cd += SIMINT_NSHELL_SIMD)
54         {
55             const int nshellbatch = ((cd + SIMINT_NSHELL_SIMD) > Q.nshell12_clip) ? Q.nshell12_clip - cd : SIMINT_NSHELL_SIMD;
56             int jend = jstart;
57             for(i = 0; i < nshellbatch; i++)
58                 jend += Q.nprim12[cd+i];
59 
60 
61             for(i = istart; i < iend; ++i)
62             {
63                 SIMINT_DBLTYPE bra_screen_max;  // only used if check_screen
64 
65                 if(check_screen)
66                 {
67                     // Skip this whole thing if always insignificant
68                     if((P.screen[i] * Q.screen_max) < screen_tol)
69                         continue;
70                     bra_screen_max = SIMINT_DBLSET1(P.screen[i]);
71                 }
72 
73                 icd = 0;
74                 iprimcd = 0;
75                 nprim_icd = Q.nprim12[cd];
76                 double * restrict PRIM_PTR_INT__d_s_s_s = INT__d_s_s_s + abcd * 6;
77 
78 
79 
80                 // Load these one per loop over i
81                 const SIMINT_DBLTYPE P_alpha = SIMINT_DBLSET1(P.alpha[i]);
82                 const SIMINT_DBLTYPE P_prefac = SIMINT_DBLSET1(P.prefac[i]);
83                 const SIMINT_DBLTYPE Pxyz[3] = { SIMINT_DBLSET1(P.x[i]), SIMINT_DBLSET1(P.y[i]), SIMINT_DBLSET1(P.z[i]) };
84 
85                 const SIMINT_DBLTYPE P_PA[3] = { SIMINT_DBLSET1(P.PA_x[i]), SIMINT_DBLSET1(P.PA_y[i]), SIMINT_DBLSET1(P.PA_z[i]) };
86 
87                 for(j = jstart; j < jend; j += SIMINT_SIMD_LEN)
88                 {
89                     // calculate the shell offsets
90                     // these are the offset from the shell pointed to by cd
91                     // for each element
92                     int shelloffsets[SIMINT_SIMD_LEN] = {0};
93                     int lastoffset = 0;
94                     const int nlane = ( ((j + SIMINT_SIMD_LEN) < jend) ? SIMINT_SIMD_LEN : (jend - j));
95 
96                     if((iprimcd + SIMINT_SIMD_LEN) >= nprim_icd)
97                     {
98                         // Handle if the first element of the vector is a new shell
99                         if(iprimcd >= nprim_icd && ((icd+1) < nshellbatch))
100                         {
101                             nprim_icd += Q.nprim12[cd + (++icd)];
102                             PRIM_PTR_INT__d_s_s_s += 6;
103                         }
104                         iprimcd++;
105                         for(n = 1; n < SIMINT_SIMD_LEN; ++n)
106                         {
107                             if(iprimcd >= nprim_icd && ((icd+1) < nshellbatch))
108                             {
109                                 shelloffsets[n] = shelloffsets[n-1] + 1;
110                                 lastoffset++;
111                                 nprim_icd += Q.nprim12[cd + (++icd)];
112                             }
113                             else
114                                 shelloffsets[n] = shelloffsets[n-1];
115                             iprimcd++;
116                         }
117                     }
118                     else
119                         iprimcd += SIMINT_SIMD_LEN;
120 
121                     // Do we have to compute this vector (or has it been screened out)?
122                     // (not_screened != 0 means we have to do this vector)
123                     if(check_screen)
124                     {
125                         const double vmax = vector_max(SIMINT_MUL(bra_screen_max, SIMINT_DBLLOAD(Q.screen, j)));
126                         if(vmax < screen_tol)
127                         {
128                             PRIM_PTR_INT__d_s_s_s += lastoffset*6;
129                             continue;
130                         }
131                     }
132 
133                     const SIMINT_DBLTYPE Q_alpha = SIMINT_DBLLOAD(Q.alpha, j);
134                     const SIMINT_DBLTYPE PQalpha_mul = SIMINT_MUL(P_alpha, Q_alpha);
135                     const SIMINT_DBLTYPE PQalpha_sum = SIMINT_ADD(P_alpha, Q_alpha);
136                     const SIMINT_DBLTYPE one_over_PQalpha_sum = SIMINT_DIV(const_1, PQalpha_sum);
137 
138 
139                     /* construct R2 = (Px - Qx)**2 + (Py - Qy)**2 + (Pz -Qz)**2 */
140                     SIMINT_DBLTYPE PQ[3];
141                     PQ[0] = SIMINT_SUB(Pxyz[0], SIMINT_DBLLOAD(Q.x, j));
142                     PQ[1] = SIMINT_SUB(Pxyz[1], SIMINT_DBLLOAD(Q.y, j));
143                     PQ[2] = SIMINT_SUB(Pxyz[2], SIMINT_DBLLOAD(Q.z, j));
144                     SIMINT_DBLTYPE R2 = SIMINT_MUL(PQ[0], PQ[0]);
145                     R2 = SIMINT_FMADD(PQ[1], PQ[1], R2);
146                     R2 = SIMINT_FMADD(PQ[2], PQ[2], R2);
147 
148                     const SIMINT_DBLTYPE alpha = SIMINT_MUL(PQalpha_mul, one_over_PQalpha_sum); // alpha from MEST
149                     const SIMINT_DBLTYPE one_over_p = SIMINT_DIV(const_1, P_alpha);
150                     const SIMINT_DBLTYPE one_over_q = SIMINT_DIV(const_1, Q_alpha);
151                     const SIMINT_DBLTYPE one_over_2p = SIMINT_MUL(one_half, one_over_p);
152                     const SIMINT_DBLTYPE one_over_2q = SIMINT_MUL(one_half, one_over_q);
153                     const SIMINT_DBLTYPE one_over_2pq = SIMINT_MUL(one_half, one_over_PQalpha_sum);
154 
155                     // NOTE: Minus sign!
156                     const SIMINT_DBLTYPE a_over_p = SIMINT_MUL(SIMINT_NEG(alpha), one_over_p);
157                     SIMINT_DBLTYPE aop_PQ[3];
158                     aop_PQ[0] = SIMINT_MUL(a_over_p, PQ[0]);
159                     aop_PQ[1] = SIMINT_MUL(a_over_p, PQ[1]);
160                     aop_PQ[2] = SIMINT_MUL(a_over_p, PQ[2]);
161 
162 
163                     //////////////////////////////////////////////
164                     // Fjt function section
165                     // Maximum v value: 2
166                     //////////////////////////////////////////////
167                     // The parameter to the Fjt function
168                     const SIMINT_DBLTYPE F_x = SIMINT_MUL(R2, alpha);
169 
170 
171                     const SIMINT_DBLTYPE Q_prefac = mask_load(nlane, Q.prefac + j);
172 
173 
174                     boys_F_split(PRIM_INT__s_s_s_s, F_x, 2);
175                     SIMINT_DBLTYPE prefac = SIMINT_SQRT(one_over_PQalpha_sum);
176                     prefac = SIMINT_MUL(SIMINT_MUL(P_prefac, Q_prefac), prefac);
177                     for(n = 0; n <= 2; n++)
178                         PRIM_INT__s_s_s_s[n] = SIMINT_MUL(PRIM_INT__s_s_s_s[n], prefac);
179 
180                     //////////////////////////////////////////////
181                     // Primitive integrals: Vertical recurrance
182                     //////////////////////////////////////////////
183 
184                     const SIMINT_DBLTYPE vrr_const_1_over_2p = one_over_2p;
185 
186 
187 
188                     // Forming PRIM_INT__p_s_s_s[2 * 3];
189                     for(n = 0; n < 2; ++n)  // loop over orders of auxiliary function
190                     {
191 
192                         PRIM_INT__p_s_s_s[n * 3 + 0] = SIMINT_MUL(P_PA[0], PRIM_INT__s_s_s_s[n * 1 + 0]);
193                         PRIM_INT__p_s_s_s[n * 3 + 0] = SIMINT_FMADD( aop_PQ[0], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__p_s_s_s[n * 3 + 0]);
194 
195                         PRIM_INT__p_s_s_s[n * 3 + 1] = SIMINT_MUL(P_PA[1], PRIM_INT__s_s_s_s[n * 1 + 0]);
196                         PRIM_INT__p_s_s_s[n * 3 + 1] = SIMINT_FMADD( aop_PQ[1], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__p_s_s_s[n * 3 + 1]);
197 
198                         PRIM_INT__p_s_s_s[n * 3 + 2] = SIMINT_MUL(P_PA[2], PRIM_INT__s_s_s_s[n * 1 + 0]);
199                         PRIM_INT__p_s_s_s[n * 3 + 2] = SIMINT_FMADD( aop_PQ[2], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__p_s_s_s[n * 3 + 2]);
200 
201                     }
202 
203 
204 
205                     // Forming PRIM_INT__d_s_s_s[1 * 6];
206                     for(n = 0; n < 1; ++n)  // loop over orders of auxiliary function
207                     {
208 
209                         PRIM_INT__d_s_s_s[n * 6 + 0] = SIMINT_MUL(P_PA[0], PRIM_INT__p_s_s_s[n * 3 + 0]);
210                         PRIM_INT__d_s_s_s[n * 6 + 0] = SIMINT_FMADD( aop_PQ[0], PRIM_INT__p_s_s_s[(n+1) * 3 + 0], PRIM_INT__d_s_s_s[n * 6 + 0]);
211                         PRIM_INT__d_s_s_s[n * 6 + 0] = SIMINT_FMADD( vrr_const_1_over_2p, SIMINT_FMADD(a_over_p, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_s_s[n * 1 + 0]), PRIM_INT__d_s_s_s[n * 6 + 0]);
212 
213                         PRIM_INT__d_s_s_s[n * 6 + 1] = SIMINT_MUL(P_PA[1], PRIM_INT__p_s_s_s[n * 3 + 0]);
214                         PRIM_INT__d_s_s_s[n * 6 + 1] = SIMINT_FMADD( aop_PQ[1], PRIM_INT__p_s_s_s[(n+1) * 3 + 0], PRIM_INT__d_s_s_s[n * 6 + 1]);
215 
216                         PRIM_INT__d_s_s_s[n * 6 + 2] = SIMINT_MUL(P_PA[2], PRIM_INT__p_s_s_s[n * 3 + 0]);
217                         PRIM_INT__d_s_s_s[n * 6 + 2] = SIMINT_FMADD( aop_PQ[2], PRIM_INT__p_s_s_s[(n+1) * 3 + 0], PRIM_INT__d_s_s_s[n * 6 + 2]);
218 
219                         PRIM_INT__d_s_s_s[n * 6 + 3] = SIMINT_MUL(P_PA[1], PRIM_INT__p_s_s_s[n * 3 + 1]);
220                         PRIM_INT__d_s_s_s[n * 6 + 3] = SIMINT_FMADD( aop_PQ[1], PRIM_INT__p_s_s_s[(n+1) * 3 + 1], PRIM_INT__d_s_s_s[n * 6 + 3]);
221                         PRIM_INT__d_s_s_s[n * 6 + 3] = SIMINT_FMADD( vrr_const_1_over_2p, SIMINT_FMADD(a_over_p, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_s_s[n * 1 + 0]), PRIM_INT__d_s_s_s[n * 6 + 3]);
222 
223                         PRIM_INT__d_s_s_s[n * 6 + 4] = SIMINT_MUL(P_PA[2], PRIM_INT__p_s_s_s[n * 3 + 1]);
224                         PRIM_INT__d_s_s_s[n * 6 + 4] = SIMINT_FMADD( aop_PQ[2], PRIM_INT__p_s_s_s[(n+1) * 3 + 1], PRIM_INT__d_s_s_s[n * 6 + 4]);
225 
226                         PRIM_INT__d_s_s_s[n * 6 + 5] = SIMINT_MUL(P_PA[2], PRIM_INT__p_s_s_s[n * 3 + 2]);
227                         PRIM_INT__d_s_s_s[n * 6 + 5] = SIMINT_FMADD( aop_PQ[2], PRIM_INT__p_s_s_s[(n+1) * 3 + 2], PRIM_INT__d_s_s_s[n * 6 + 5]);
228                         PRIM_INT__d_s_s_s[n * 6 + 5] = SIMINT_FMADD( vrr_const_1_over_2p, SIMINT_FMADD(a_over_p, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_s_s[n * 1 + 0]), PRIM_INT__d_s_s_s[n * 6 + 5]);
229 
230                     }
231 
232 
233 
234 
235                     ////////////////////////////////////
236                     // Accumulate contracted integrals
237                     ////////////////////////////////////
238                     if(lastoffset == 0)
239                     {
240                         contract_all(6, PRIM_INT__d_s_s_s, PRIM_PTR_INT__d_s_s_s);
241                     }
242                     else
243                     {
244                         contract(6, shelloffsets, PRIM_INT__d_s_s_s, PRIM_PTR_INT__d_s_s_s);
245                         PRIM_PTR_INT__d_s_s_s += lastoffset*6;
246                     }
247 
248                 }  // close loop over j
249             }  // close loop over i
250 
251             //Advance to the next batch
252             jstart = SIMINT_SIMD_ROUND(jend);
253             abcd += nshellbatch;
254 
255         }   // close loop cdbatch
256 
257         istart = iend;
258     }  // close loop over ab
259 
260     return P.nshell12_clip * Q.nshell12_clip;
261 }
262 
263