3
#include "build_libr12.h"
5
extern FILE *outfile, *hrr_header;
6
extern Libr12Params_t Params;
8
extern void punt(char *);
9
static int hash(int a[2][3], int b[2]);
11
int emit_hrr_t_build()
13
int new_am = Params.new_am;
14
int max_class_size = Params.max_class_size;
18
int ax,ay,az,bx,by,bz,cx,cy,cz,dx,dy,dz;
19
int t0, t1, t2, t3, t4;
22
int cp1dm1_num,cdm1_num;
32
int curr_count,curr_subfunction;
33
int num_subfunctions, subbatch_length;
35
static int io[] = {1,3,6,10,15,21,28,36,45,55,66,78,91,105,120,136,153};
36
static const char am_letter[] = "0pdfghiklmnoqrtuvwxyz";
38
char function_name[18];
39
char **subfunction_name;
41
for(lc=0;lc<=new_am;lc++) {
43
for(ld=1;ld<=ld_max;ld++) {
45
/*-----------------------
46
HRR on centers C and D
47
-----------------------*/
52
class_size = ((am_in[0]+1)*(am_in[0]+2)*(am_in[1]+1)*(am_in[1]+2))/4;
53
nl = (am_in[1]*(am_in[1]+1))/2;
54
cp1dm1_num = (am_in[0]+2)*(am_in[0]+3)*nl/2;
55
cdm1_num = (am_in[0]+1)*(am_in[0]+2)*nl/2;
57
/* Decide if the routine has to be split into several routines producing "subbatches" */
58
if (class_size > max_class_size) {
60
num_subfunctions = ceil((double)class_size/max_class_size);
61
subbatch_length = 1 + class_size/num_subfunctions;
67
sprintf(function_name,"t2hrr3_build_%c%c",am_letter[am_in[0]],am_letter[am_in[1]]);
69
subfunction_name = (char **) malloc (num_subfunctions*sizeof(char *));
70
for(i=0;i<num_subfunctions;i++) {
71
subfunction_name[i] = (char *) malloc(22*sizeof(char));
72
sprintf(subfunction_name[i],"_%s_%d",
76
sprintf(code_name,"%s.cc",function_name);
77
code = fopen(code_name,"w");
79
/* include the function into the hrr_header.h */
80
fprintf(hrr_header,"void %s(REALTYPE *, REALTYPE *, REALTYPE *, const REALTYPE *, const REALTYPE *, ",function_name);
81
fprintf(hrr_header,"const REALTYPE *, const REALTYPE *, const REALTYPE *, int, int);\n");
83
fprintf(code," /* This machine-generated function computes a quartet of [r12,T2]|%c%c) integrals */\n\n",
84
am_letter[am_in[0]],am_letter[am_in[1]]);
85
fprintf(code,"#include<libint/libint.h>\n\n");
87
for(i=0;i<num_subfunctions;i++) {
88
fprintf(code,"REALTYPE *%s(REALTYPE *, REALTYPE *, REALTYPE *, const REALTYPE *, const REALTYPE *, ",
90
fprintf(code,"const REALTYPE *, const REALTYPE *, const REALTYPE *, int, int);\n");
94
fprintf(code,"void %s(REALTYPE *CD, REALTYPE *AC, REALTYPE *vp, const REALTYPE *I0, const REALTYPE *I1, ",function_name);
95
fprintf(code,"const REALTYPE *I2, const REALTYPE *I3, const REALTYPE *I4, int la, int lb)\n{\n");
101
fprintf(code," const REALTYPE CD0 = CD[0];\n");
102
fprintf(code," const REALTYPE CD1 = CD[1];\n");
103
fprintf(code," const REALTYPE CD2 = CD[2];\n");
104
fprintf(code," const REALTYPE AC0 = AC[0];\n");
105
fprintf(code," const REALTYPE AC1 = AC[1];\n");
106
fprintf(code," const REALTYPE AC2 = AC[2];\n");
107
fprintf(code," static int io[] = { 1");
108
for(i=1;i<=new_am+1;i++)
109
fprintf(code,", %d",(i+1)*(i+2)/2);
110
fprintf(code,"};\n");
111
fprintf(code," int bcdm1_num = io[lb]*%d;\n\n",cdm1_num);
113
fprintf(code," int pa, qa, b;\n");
115
fprintf(code," for(pa=0;pa<=la;pa++)\n");
116
fprintf(code," for(qa=0;qa<=pa;qa++)\n");
117
fprintf(code," for(b=0;b<((lb+1)*(lb+2)/2);b++) {\n");
120
for(f=0;f<num_subfunctions;f++)
121
fprintf(code," vp = %s(CD, AC, vp, I0, I1, I2, I3, I4, pa, lb);\n",
122
subfunction_name[f]);
123
fprintf(code," I0 += %d;\n",cp1dm1_num);
124
fprintf(code," I1 += %d;\n",cdm1_num);
125
fprintf(code," I2 += %d;\n",cp1dm1_num);
126
fprintf(code," I3 += %d;\n",cdm1_num);
127
fprintf(code," I4 += %d;\n",cdm1_num);
128
fprintf(code," }\n}\n\n");
130
fprintf(code,"REALTYPE *%s(REALTYPE *CD, REALTYPE *AC, REALTYPE *vp, const REALTYPE *I0, const REALTYPE *I1, ",
131
subfunction_name[0]);
132
fprintf(code,"const REALTYPE *I2, const REALTYPE *I3, const REALTYPE *I4, int pa, int lb)\n{\n");
133
fprintf(code," const REALTYPE CD0 = CD[0];\n");
134
fprintf(code," const REALTYPE CD1 = CD[1];\n");
135
fprintf(code," const REALTYPE CD2 = CD[2];\n");
136
fprintf(code," const REALTYPE AC0 = AC[0];\n");
137
fprintf(code," const REALTYPE AC1 = AC[1];\n");
138
fprintf(code," const REALTYPE AC2 = AC[2];\n");
139
fprintf(code," static int io[] = { 1");
140
for(i=1;i<=new_am+1;i++)
141
fprintf(code,", %d",(i+1)*(i+2)/2);
142
fprintf(code,"};\n");
143
fprintf(code," int bcdm1_num = io[lb]*%d;\n\n",cdm1_num);
146
for(p = 0; p <= am_in[0]; p++){
147
am[0][0] = am_in[0] - p;
148
for(q = 0; q <= p; q++){
152
for(r = 0; r <= am_in[1]; r++){
153
am[1][0] = am_in[1] - r;
154
for(s = 0; s <= r; s++){
158
if (am[1][0]) /* build along x */
160
else if (am[1][1]) /* build along y */
162
else /*build along z */
179
fprintf(code," *(vp++) = I0[%d] + CD%d*I1[%d] + I2[%d] - AC%d*I4[%d] - ",t0,xyz,t1,t2,xyz,t4);
181
fprintf(code,"I3[%d];\n",t3);
183
fprintf(code,"I3[(pa+%d)*bcdm1_num+%d];\n",xyz,t3);
186
if (curr_count == subbatch_length && split == 1) {
189
fprintf(code," return vp;\n}\n\n");
190
fprintf(code,"REALTYPE *%s(REALTYPE *CD, REALTYPE *AC, REALTYPE *vp, const REALTYPE *I0, const REALTYPE *I1, ",
191
subfunction_name[curr_subfunction]);
192
fprintf(code,"const REALTYPE *I2, const REALTYPE *I3, const REALTYPE *I4, int pa, int lb)\n{\n");
193
fprintf(code," const REALTYPE CD0 = CD[0];\n");
194
fprintf(code," const REALTYPE CD1 = CD[1];\n");
195
fprintf(code," const REALTYPE CD2 = CD[2];\n");
196
fprintf(code," const REALTYPE AC0 = AC[0];\n");
197
fprintf(code," const REALTYPE AC1 = AC[1];\n");
198
fprintf(code," const REALTYPE AC2 = AC[2];\n");
199
fprintf(code," static int io[] = { 1");
200
for(i=1;i<=new_am+1;i++)
201
fprintf(code,", %d",(i+1)*(i+2)/2);
202
fprintf(code,"};\n");
203
fprintf(code," int bcdm1_num = io[lb]*%d;\n\n",cdm1_num);
210
fprintf(code," I0 += %d;\n",cp1dm1_num);
211
fprintf(code," I1 += %d;\n",cdm1_num);
212
fprintf(code," I2 += %d;\n",cp1dm1_num);
213
fprintf(code," I3 += %d;\n",cdm1_num);
214
fprintf(code," I4 += %d;\n",cdm1_num);
215
fprintf(code," }\n}\n");
218
fprintf(code," return vp;\n}\n");
221
printf("Done with %s\n",code_name);
225
/*-----------------------
226
HRR on centers A and B
227
-----------------------*/
233
class_size = ((am_in[0]+1)*(am_in[0]+2)*(am_in[1]+1)*(am_in[1]+2))/4;
235
/*--- Whether to split has been decided already ---*/
237
sprintf(function_name,"t1hrr1_build_%c%c",am_letter[am_in[0]],am_letter[am_in[1]]);
239
subfunction_name = (char **) malloc (num_subfunctions*sizeof(char *));
240
for(i=0;i<num_subfunctions;i++) {
241
subfunction_name[i] = (char *) malloc(22*sizeof(char));
242
sprintf(subfunction_name[i],"_%s_%d",
246
sprintf(code_name,"t1hrr1_build_%c%c.cc",am_letter[am_in[0]],am_letter[am_in[1]]);
247
code = fopen(code_name,"w");
249
/* include the function into the hrr_header.h */
250
fprintf(hrr_header,"void %s(REALTYPE *, REALTYPE *, REALTYPE *, const REALTYPE *, const REALTYPE *, ",function_name);
251
fprintf(hrr_header,"const REALTYPE *, const REALTYPE *, const REALTYPE *, int, int);\n");
253
fprintf(code," /* This machine-generated function computes a quartet of (%c%c|[r12,T1] integrals */\n\n",
254
am_letter[am_in[0]],am_letter[am_in[1]]);
255
fprintf(code,"#include<libint/libint.h>\n\n");
258
for(i=0;i<num_subfunctions;i++) {
259
fprintf(code,"REALTYPE *%s(REALTYPE *, REALTYPE *, REALTYPE *, const REALTYPE *, const REALTYPE *, ",
260
subfunction_name[i]);
261
fprintf(code,"const REALTYPE *, const REALTYPE *, const REALTYPE *, int, int);\n");
265
fprintf(code,"void %s(REALTYPE *AB, REALTYPE *AC, REALTYPE *vp, const REALTYPE *I0, const REALTYPE *I1, ",
267
fprintf(code,"const REALTYPE *I2, const REALTYPE *I3, const REALTYPE *I4, int lc, int ld)\n{\n");
269
curr_subfunction = 0;
273
fprintf(code," int cd, cd_num, c_num, cp1_num, d_num;\n");
274
fprintf(code," int pc, qc, d, ind_c, ind_cp1d;\n");
275
fprintf(code," const REALTYPE *i0, *i1, *i2, *i3, *i4;\n");
276
fprintf(code," const REALTYPE AB0 = AB[0];\n");
277
fprintf(code," const REALTYPE AB1 = AB[1];\n");
278
fprintf(code," const REALTYPE AB2 = AB[2];\n");
279
fprintf(code," const REALTYPE AC0 = AC[0];\n");
280
fprintf(code," const REALTYPE AC1 = AC[1];\n");
281
fprintf(code," const REALTYPE AC2 = AC[2];\n");
282
fprintf(code," static int io[] = { 1");
283
for(i=1;i<=new_am+1;i++)
284
fprintf(code,", %d",(i+1)*(i+2)/2);
285
fprintf(code,"};\n\n");
286
fprintf(code," c_num = io[lc];\n");
287
fprintf(code," cp1_num = io[lc+1];\n");
288
fprintf(code," d_num = io[ld];\n\n");
292
for(f=0;f<num_subfunctions;f++)
293
fprintf(code," vp = %s(AB, AC, vp, I0, I1, I2, I3, I4, lc, ld);\n",
294
subfunction_name[f]);
295
fprintf(code,"}\n\n");
297
fprintf(code,"REALTYPE *%s(REALTYPE *AB, REALTYPE *AC, REALTYPE *vp, const REALTYPE *I0, const REALTYPE *I1, ",
298
subfunction_name[0]);
299
fprintf(code,"const REALTYPE *I2, const REALTYPE *I3, const REALTYPE *I4, int lc, int ld)\n{\n");
300
fprintf(code," int cd, cd_num, c_num, cp1_num, d_num;\n");
301
fprintf(code," int pc, qc, d, ind_c, ind_cp1d;\n");
302
fprintf(code," const REALTYPE *i0, *i1, *i2, *i3, *i4;\n");
303
fprintf(code," const REALTYPE AB0 = AB[0];\n");
304
fprintf(code," const REALTYPE AB1 = AB[1];\n");
305
fprintf(code," const REALTYPE AB2 = AB[2];\n");
306
fprintf(code," const REALTYPE AC0 = AC[0];\n");
307
fprintf(code," const REALTYPE AC1 = AC[1];\n");
308
fprintf(code," const REALTYPE AC2 = AC[2];\n");
309
fprintf(code," static int io[] = { 1");
310
for(i=1;i<=new_am+1;i++)
311
fprintf(code,", %d",(i+1)*(i+2)/2);
312
fprintf(code,"};\n\n");
313
fprintf(code," c_num = io[lc];\n");
314
fprintf(code," cp1_num = io[lc+1];\n");
315
fprintf(code," d_num = io[ld];\n\n");
320
for(p = 0; p <= am_in[0]; p++){
321
am[0][0] = am_in[0] - p;
322
for(q = 0; q <= p; q++){
326
for(r = 0; r <= am_in[1]; r++){
327
am[1][0] = am_in[1] - r;
328
for(s = 0; s <= r; s++){
332
if (am[1][0]) /* build along x */
334
else if (am[1][1]) /* build along y */
336
else /* build along z */
354
fprintf(code," i0 = I0 + %d*(c_num*d_num);\n",t0);
355
fprintf(code," i2 = I2 + %d*(c_num*d_num);\n",t2);
358
fprintf(code," i0 = I0;\n");
359
fprintf(code," i2 = I2;\n");
362
fprintf(code," i1 = I1 + %d*(c_num*d_num);\n",t1);
363
fprintf(code," i4 = I4 + %d*(c_num*d_num);\n",t4);
364
fprintf(code," i3 = I3 + %d*(cp1_num*d_num);\n",t3);
367
fprintf(code," i1 = I1;\n");
368
fprintf(code," i3 = I3;\n");
369
fprintf(code," i4 = I4;\n");
373
fprintf(code," for(cd=0;cd<c_num*d_num;cd++)\n");
374
fprintf(code," *(vp++) = *(i0++) + AB0*(*(i1++)) + *(i2++) + AC0*(*(i4++)) - *(i3++);\n\n");
377
fprintf(code," ind_c = %d;\n",xyz);
378
fprintf(code," for(pc=0;pc<=lc;pc++) {\n");
379
fprintf(code," for(qc=0;qc<=pc;qc++) {\n");
380
fprintf(code," ind_cp1d = (ind_c + pc)*d_num;\n");
381
fprintf(code," for(d=0;d<d_num;d++) {\n");
382
fprintf(code," *(vp++) = *(i0++) + AB%d*(*(i1++)) + *(i2++) + AC%d*(*(i4++)) - i3[ind_cp1d];\n",
384
fprintf(code," ind_cp1d++;\n");
385
fprintf(code," }\n");
386
fprintf(code," ind_c++;\n");
387
fprintf(code," }\n");
388
fprintf(code," }\n\n");
392
if (curr_count == subbatch_length && split == 1) {
395
fprintf(code," return vp;\n}\n\n");
396
fprintf(code,"REALTYPE *%s(REALTYPE *AB, REALTYPE *AC, REALTYPE *vp, const REALTYPE *I0, const REALTYPE *I1, ",
397
subfunction_name[curr_subfunction]);
398
fprintf(code,"const REALTYPE *I2, const REALTYPE *I3, const REALTYPE *I4, int lc, int ld)\n{\n");
399
fprintf(code," int cd, cd_num, c_num, cp1_num, d_num;\n");
400
fprintf(code," int pc, qc, d, ind_c, ind_cp1d;\n");
401
fprintf(code," const REALTYPE *i0, *i1, *i2, *i3, *i4;\n");
402
fprintf(code," const REALTYPE AB0 = AB[0];\n");
403
fprintf(code," const REALTYPE AB1 = AB[1];\n");
404
fprintf(code," const REALTYPE AB2 = AB[2];\n");
405
fprintf(code," const REALTYPE AC0 = AC[0];\n");
406
fprintf(code," const REALTYPE AC1 = AC[1];\n");
407
fprintf(code," const REALTYPE AC2 = AC[2];\n");
408
fprintf(code," static int io[] = { 1");
409
for(i=1;i<=new_am+1;i++)
410
fprintf(code,", %d",(i+1)*(i+2)/2);
411
fprintf(code,"};\n\n");
412
fprintf(code," c_num = io[lc];\n");
413
fprintf(code," cp1_num = io[lc+1];\n");
414
fprintf(code," d_num = io[ld];\n\n");
421
fprintf(code," return vp;\n");
425
printf("Done with %s\n",code_name);
431
/*----------------------------------------------------------------------------------
432
hash(a,b) returns a number of the (a[0] a[1]) type product within a doublet.
433
a contains x y and z exponents of functions on centers A and B, and b contains
434
their angular momenta
435
----------------------------------------------------------------------------------*/
443
static int io[] = {0,1,3,6,10,15,21,28,36,45,55,66,78,91,105,120,136,153};
447
c[0]=i+io[i]-a[0][1];
451
c[1]=i+io[i]-a[1][1];
454
return c[0]*io[b[1]+1]+c[1];