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_s_s_h_s(struct simint_multi_shellpair const P,struct simint_multi_shellpair const Q,double screen_tol,double * const restrict work,double * const restrict INT__s_s_h_s)8 int ostei_s_s_h_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__s_s_h_s)
13 {
14 
15     SIMINT_ASSUME_ALIGN_DBL(work);
16     SIMINT_ASSUME_ALIGN_DBL(INT__s_s_h_s);
17     memset(INT__s_s_h_s, 0, P.nshell12_clip * Q.nshell12_clip * 21 * 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__s_s_p_s = primwork + 6;
31     SIMINT_DBLTYPE * const restrict PRIM_INT__s_s_d_s = primwork + 21;
32     SIMINT_DBLTYPE * const restrict PRIM_INT__s_s_f_s = primwork + 45;
33     SIMINT_DBLTYPE * const restrict PRIM_INT__s_s_g_s = primwork + 75;
34     SIMINT_DBLTYPE * const restrict PRIM_INT__s_s_h_s = primwork + 105;
35     double * const hrrwork = (double *)(primwork + 126);
36 
37 
38     // Create constants
39     const SIMINT_DBLTYPE const_1 = SIMINT_DBLSET1(1);
40     const SIMINT_DBLTYPE const_2 = SIMINT_DBLSET1(2);
41     const SIMINT_DBLTYPE const_3 = SIMINT_DBLSET1(3);
42     const SIMINT_DBLTYPE const_4 = SIMINT_DBLSET1(4);
43     const SIMINT_DBLTYPE one_half = SIMINT_DBLSET1(0.5);
44 
45 
46     ////////////////////////////////////////
47     // Loop over shells and primitives
48     ////////////////////////////////////////
49 
50     abcd = 0;
51     istart = 0;
52     for(ab = 0; ab < P.nshell12_clip; ++ab)
53     {
54         const int iend = istart + P.nprim12[ab];
55 
56         cd = 0;
57         jstart = 0;
58 
59         for(cd = 0; cd < Q.nshell12_clip; cd += SIMINT_NSHELL_SIMD)
60         {
61             const int nshellbatch = ((cd + SIMINT_NSHELL_SIMD) > Q.nshell12_clip) ? Q.nshell12_clip - cd : SIMINT_NSHELL_SIMD;
62             int jend = jstart;
63             for(i = 0; i < nshellbatch; i++)
64                 jend += Q.nprim12[cd+i];
65 
66 
67             for(i = istart; i < iend; ++i)
68             {
69                 SIMINT_DBLTYPE bra_screen_max;  // only used if check_screen
70 
71                 if(check_screen)
72                 {
73                     // Skip this whole thing if always insignificant
74                     if((P.screen[i] * Q.screen_max) < screen_tol)
75                         continue;
76                     bra_screen_max = SIMINT_DBLSET1(P.screen[i]);
77                 }
78 
79                 icd = 0;
80                 iprimcd = 0;
81                 nprim_icd = Q.nprim12[cd];
82                 double * restrict PRIM_PTR_INT__s_s_h_s = INT__s_s_h_s + abcd * 21;
83 
84 
85 
86                 // Load these one per loop over i
87                 const SIMINT_DBLTYPE P_alpha = SIMINT_DBLSET1(P.alpha[i]);
88                 const SIMINT_DBLTYPE P_prefac = SIMINT_DBLSET1(P.prefac[i]);
89                 const SIMINT_DBLTYPE Pxyz[3] = { SIMINT_DBLSET1(P.x[i]), SIMINT_DBLSET1(P.y[i]), SIMINT_DBLSET1(P.z[i]) };
90 
91 
92                 for(j = jstart; j < jend; j += SIMINT_SIMD_LEN)
93                 {
94                     // calculate the shell offsets
95                     // these are the offset from the shell pointed to by cd
96                     // for each element
97                     int shelloffsets[SIMINT_SIMD_LEN] = {0};
98                     int lastoffset = 0;
99                     const int nlane = ( ((j + SIMINT_SIMD_LEN) < jend) ? SIMINT_SIMD_LEN : (jend - j));
100 
101                     if((iprimcd + SIMINT_SIMD_LEN) >= nprim_icd)
102                     {
103                         // Handle if the first element of the vector is a new shell
104                         if(iprimcd >= nprim_icd && ((icd+1) < nshellbatch))
105                         {
106                             nprim_icd += Q.nprim12[cd + (++icd)];
107                             PRIM_PTR_INT__s_s_h_s += 21;
108                         }
109                         iprimcd++;
110                         for(n = 1; n < SIMINT_SIMD_LEN; ++n)
111                         {
112                             if(iprimcd >= nprim_icd && ((icd+1) < nshellbatch))
113                             {
114                                 shelloffsets[n] = shelloffsets[n-1] + 1;
115                                 lastoffset++;
116                                 nprim_icd += Q.nprim12[cd + (++icd)];
117                             }
118                             else
119                                 shelloffsets[n] = shelloffsets[n-1];
120                             iprimcd++;
121                         }
122                     }
123                     else
124                         iprimcd += SIMINT_SIMD_LEN;
125 
126                     // Do we have to compute this vector (or has it been screened out)?
127                     // (not_screened != 0 means we have to do this vector)
128                     if(check_screen)
129                     {
130                         const double vmax = vector_max(SIMINT_MUL(bra_screen_max, SIMINT_DBLLOAD(Q.screen, j)));
131                         if(vmax < screen_tol)
132                         {
133                             PRIM_PTR_INT__s_s_h_s += lastoffset*21;
134                             continue;
135                         }
136                     }
137 
138                     const SIMINT_DBLTYPE Q_alpha = SIMINT_DBLLOAD(Q.alpha, j);
139                     const SIMINT_DBLTYPE PQalpha_mul = SIMINT_MUL(P_alpha, Q_alpha);
140                     const SIMINT_DBLTYPE PQalpha_sum = SIMINT_ADD(P_alpha, Q_alpha);
141                     const SIMINT_DBLTYPE one_over_PQalpha_sum = SIMINT_DIV(const_1, PQalpha_sum);
142 
143 
144                     /* construct R2 = (Px - Qx)**2 + (Py - Qy)**2 + (Pz -Qz)**2 */
145                     SIMINT_DBLTYPE PQ[3];
146                     PQ[0] = SIMINT_SUB(Pxyz[0], SIMINT_DBLLOAD(Q.x, j));
147                     PQ[1] = SIMINT_SUB(Pxyz[1], SIMINT_DBLLOAD(Q.y, j));
148                     PQ[2] = SIMINT_SUB(Pxyz[2], SIMINT_DBLLOAD(Q.z, j));
149                     SIMINT_DBLTYPE R2 = SIMINT_MUL(PQ[0], PQ[0]);
150                     R2 = SIMINT_FMADD(PQ[1], PQ[1], R2);
151                     R2 = SIMINT_FMADD(PQ[2], PQ[2], R2);
152 
153                     const SIMINT_DBLTYPE alpha = SIMINT_MUL(PQalpha_mul, one_over_PQalpha_sum); // alpha from MEST
154                     const SIMINT_DBLTYPE one_over_p = SIMINT_DIV(const_1, P_alpha);
155                     const SIMINT_DBLTYPE one_over_q = SIMINT_DIV(const_1, Q_alpha);
156                     const SIMINT_DBLTYPE one_over_2p = SIMINT_MUL(one_half, one_over_p);
157                     const SIMINT_DBLTYPE one_over_2q = SIMINT_MUL(one_half, one_over_q);
158                     const SIMINT_DBLTYPE one_over_2pq = SIMINT_MUL(one_half, one_over_PQalpha_sum);
159                     const SIMINT_DBLTYPE Q_PA[3] = { SIMINT_DBLLOAD(Q.PA_x, j), SIMINT_DBLLOAD(Q.PA_y, j), SIMINT_DBLLOAD(Q.PA_z, j) };
160 
161                     SIMINT_DBLTYPE a_over_q = SIMINT_MUL(alpha, one_over_q);
162                     SIMINT_DBLTYPE aoq_PQ[3];
163                     aoq_PQ[0] = SIMINT_MUL(a_over_q, PQ[0]);
164                     aoq_PQ[1] = SIMINT_MUL(a_over_q, PQ[1]);
165                     aoq_PQ[2] = SIMINT_MUL(a_over_q, PQ[2]);
166                     // Put a minus sign here so we don't have to in RR routines
167                     a_over_q = SIMINT_NEG(a_over_q);
168 
169 
170                     //////////////////////////////////////////////
171                     // Fjt function section
172                     // Maximum v value: 5
173                     //////////////////////////////////////////////
174                     // The parameter to the Fjt function
175                     const SIMINT_DBLTYPE F_x = SIMINT_MUL(R2, alpha);
176 
177 
178                     const SIMINT_DBLTYPE Q_prefac = mask_load(nlane, Q.prefac + j);
179 
180 
181                     boys_F_split(PRIM_INT__s_s_s_s, F_x, 5);
182                     SIMINT_DBLTYPE prefac = SIMINT_SQRT(one_over_PQalpha_sum);
183                     prefac = SIMINT_MUL(SIMINT_MUL(P_prefac, Q_prefac), prefac);
184                     for(n = 0; n <= 5; n++)
185                         PRIM_INT__s_s_s_s[n] = SIMINT_MUL(PRIM_INT__s_s_s_s[n], prefac);
186 
187                     //////////////////////////////////////////////
188                     // Primitive integrals: Vertical recurrance
189                     //////////////////////////////////////////////
190 
191                     const SIMINT_DBLTYPE vrr_const_1_over_2q = one_over_2q;
192                     const SIMINT_DBLTYPE vrr_const_2_over_2q = SIMINT_MUL(const_2, one_over_2q);
193                     const SIMINT_DBLTYPE vrr_const_3_over_2q = SIMINT_MUL(const_3, one_over_2q);
194                     const SIMINT_DBLTYPE vrr_const_4_over_2q = SIMINT_MUL(const_4, one_over_2q);
195 
196 
197 
198                     // Forming PRIM_INT__s_s_p_s[5 * 3];
199                     for(n = 0; n < 5; ++n)  // loop over orders of auxiliary function
200                     {
201 
202                         PRIM_INT__s_s_p_s[n * 3 + 0] = SIMINT_MUL(Q_PA[0], PRIM_INT__s_s_s_s[n * 1 + 0]);
203                         PRIM_INT__s_s_p_s[n * 3 + 0] = SIMINT_FMADD( aoq_PQ[0], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_p_s[n * 3 + 0]);
204 
205                         PRIM_INT__s_s_p_s[n * 3 + 1] = SIMINT_MUL(Q_PA[1], PRIM_INT__s_s_s_s[n * 1 + 0]);
206                         PRIM_INT__s_s_p_s[n * 3 + 1] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_p_s[n * 3 + 1]);
207 
208                         PRIM_INT__s_s_p_s[n * 3 + 2] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_s_s[n * 1 + 0]);
209                         PRIM_INT__s_s_p_s[n * 3 + 2] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_p_s[n * 3 + 2]);
210 
211                     }
212 
213 
214 
215                     // Forming PRIM_INT__s_s_d_s[4 * 6];
216                     for(n = 0; n < 4; ++n)  // loop over orders of auxiliary function
217                     {
218 
219                         PRIM_INT__s_s_d_s[n * 6 + 0] = SIMINT_MUL(Q_PA[0], PRIM_INT__s_s_p_s[n * 3 + 0]);
220                         PRIM_INT__s_s_d_s[n * 6 + 0] = SIMINT_FMADD( aoq_PQ[0], PRIM_INT__s_s_p_s[(n+1) * 3 + 0], PRIM_INT__s_s_d_s[n * 6 + 0]);
221                         PRIM_INT__s_s_d_s[n * 6 + 0] = SIMINT_FMADD( vrr_const_1_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_s_s[n * 1 + 0]), PRIM_INT__s_s_d_s[n * 6 + 0]);
222 
223                         PRIM_INT__s_s_d_s[n * 6 + 3] = SIMINT_MUL(Q_PA[1], PRIM_INT__s_s_p_s[n * 3 + 1]);
224                         PRIM_INT__s_s_d_s[n * 6 + 3] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_s_p_s[(n+1) * 3 + 1], PRIM_INT__s_s_d_s[n * 6 + 3]);
225                         PRIM_INT__s_s_d_s[n * 6 + 3] = SIMINT_FMADD( vrr_const_1_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_s_s[n * 1 + 0]), PRIM_INT__s_s_d_s[n * 6 + 3]);
226 
227                         PRIM_INT__s_s_d_s[n * 6 + 5] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_p_s[n * 3 + 2]);
228                         PRIM_INT__s_s_d_s[n * 6 + 5] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_p_s[(n+1) * 3 + 2], PRIM_INT__s_s_d_s[n * 6 + 5]);
229                         PRIM_INT__s_s_d_s[n * 6 + 5] = SIMINT_FMADD( vrr_const_1_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_s_s[n * 1 + 0]), PRIM_INT__s_s_d_s[n * 6 + 5]);
230 
231                     }
232 
233 
234 
235                     // Forming PRIM_INT__s_s_f_s[3 * 10];
236                     for(n = 0; n < 3; ++n)  // loop over orders of auxiliary function
237                     {
238 
239                         PRIM_INT__s_s_f_s[n * 10 + 0] = SIMINT_MUL(Q_PA[0], PRIM_INT__s_s_d_s[n * 6 + 0]);
240                         PRIM_INT__s_s_f_s[n * 10 + 0] = SIMINT_FMADD( aoq_PQ[0], PRIM_INT__s_s_d_s[(n+1) * 6 + 0], PRIM_INT__s_s_f_s[n * 10 + 0]);
241                         PRIM_INT__s_s_f_s[n * 10 + 0] = SIMINT_FMADD( vrr_const_2_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_p_s[(n+1) * 3 + 0], PRIM_INT__s_s_p_s[n * 3 + 0]), PRIM_INT__s_s_f_s[n * 10 + 0]);
242 
243                         PRIM_INT__s_s_f_s[n * 10 + 1] = SIMINT_MUL(Q_PA[1], PRIM_INT__s_s_d_s[n * 6 + 0]);
244                         PRIM_INT__s_s_f_s[n * 10 + 1] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_s_d_s[(n+1) * 6 + 0], PRIM_INT__s_s_f_s[n * 10 + 1]);
245 
246                         PRIM_INT__s_s_f_s[n * 10 + 2] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_d_s[n * 6 + 0]);
247                         PRIM_INT__s_s_f_s[n * 10 + 2] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 0], PRIM_INT__s_s_f_s[n * 10 + 2]);
248 
249                         PRIM_INT__s_s_f_s[n * 10 + 6] = SIMINT_MUL(Q_PA[1], PRIM_INT__s_s_d_s[n * 6 + 3]);
250                         PRIM_INT__s_s_f_s[n * 10 + 6] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_s_d_s[(n+1) * 6 + 3], PRIM_INT__s_s_f_s[n * 10 + 6]);
251                         PRIM_INT__s_s_f_s[n * 10 + 6] = SIMINT_FMADD( vrr_const_2_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_p_s[(n+1) * 3 + 1], PRIM_INT__s_s_p_s[n * 3 + 1]), PRIM_INT__s_s_f_s[n * 10 + 6]);
252 
253                         PRIM_INT__s_s_f_s[n * 10 + 7] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_d_s[n * 6 + 3]);
254                         PRIM_INT__s_s_f_s[n * 10 + 7] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 3], PRIM_INT__s_s_f_s[n * 10 + 7]);
255 
256                         PRIM_INT__s_s_f_s[n * 10 + 9] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_d_s[n * 6 + 5]);
257                         PRIM_INT__s_s_f_s[n * 10 + 9] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 5], PRIM_INT__s_s_f_s[n * 10 + 9]);
258                         PRIM_INT__s_s_f_s[n * 10 + 9] = SIMINT_FMADD( vrr_const_2_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_p_s[(n+1) * 3 + 2], PRIM_INT__s_s_p_s[n * 3 + 2]), PRIM_INT__s_s_f_s[n * 10 + 9]);
259 
260                     }
261 
262 
263                     VRR_K_s_s_g_s(
264                             PRIM_INT__s_s_g_s,
265                             PRIM_INT__s_s_f_s,
266                             PRIM_INT__s_s_d_s,
267                             Q_PA,
268                             a_over_q,
269                             aoq_PQ,
270                             one_over_2q,
271                             2);
272 
273 
274                     VRR_K_s_s_h_s(
275                             PRIM_INT__s_s_h_s,
276                             PRIM_INT__s_s_g_s,
277                             PRIM_INT__s_s_f_s,
278                             Q_PA,
279                             a_over_q,
280                             aoq_PQ,
281                             one_over_2q,
282                             1);
283 
284 
285 
286 
287                     ////////////////////////////////////
288                     // Accumulate contracted integrals
289                     ////////////////////////////////////
290                     if(lastoffset == 0)
291                     {
292                         contract_all(21, PRIM_INT__s_s_h_s, PRIM_PTR_INT__s_s_h_s);
293                     }
294                     else
295                     {
296                         contract(21, shelloffsets, PRIM_INT__s_s_h_s, PRIM_PTR_INT__s_s_h_s);
297                         PRIM_PTR_INT__s_s_h_s += lastoffset*21;
298                     }
299 
300                 }  // close loop over j
301             }  // close loop over i
302 
303             //Advance to the next batch
304             jstart = SIMINT_SIMD_ROUND(jend);
305             abcd += nshellbatch;
306 
307         }   // close loop cdbatch
308 
309         istart = iend;
310     }  // close loop over ab
311 
312     return P.nshell12_clip * Q.nshell12_clip;
313 }
314 
ostei_s_s_s_h(struct simint_multi_shellpair const P,struct simint_multi_shellpair const Q,double screen_tol,double * const restrict work,double * const restrict INT__s_s_s_h)315 int ostei_s_s_s_h(struct simint_multi_shellpair const P,
316                   struct simint_multi_shellpair const Q,
317                   double screen_tol,
318                   double * const restrict work,
319                   double * const restrict INT__s_s_s_h)
320 {
321     double Q_AB[3*Q.nshell12];
322     struct simint_multi_shellpair Q_tmp = Q;
323     Q_tmp.PA_x = Q.PB_x;  Q_tmp.PA_y = Q.PB_y;  Q_tmp.PA_z = Q.PB_z;
324     Q_tmp.PB_x = Q.PA_x;  Q_tmp.PB_y = Q.PA_y;  Q_tmp.PB_z = Q.PA_z;
325     Q_tmp.AB_x = Q_AB;
326     Q_tmp.AB_y = Q_AB + Q.nshell12;
327     Q_tmp.AB_z = Q_AB + 2*Q.nshell12;
328 
329     for(int i = 0; i < Q.nshell12; i++)
330     {
331         Q_tmp.AB_x[i] = -Q.AB_x[i];
332         Q_tmp.AB_y[i] = -Q.AB_y[i];
333         Q_tmp.AB_z[i] = -Q.AB_z[i];
334     }
335 
336     int ret = ostei_s_s_h_s(P, Q_tmp, screen_tol, work, INT__s_s_s_h);
337 
338     return ret;
339 }
340 
341