28 #ifndef _chemistry_qc_scf_lbgbuild_h
29 #define _chemistry_qc_scf_lbgbuild_h
35 #include <chemistry/qc/scf/gbuild.h>
52 GBuild<T>(t), grp_(g), tbi_(tbi), integral_(ints), gbs_(bs), pmax(pm) {}
55 void build_gmat(
double accuracy) {
57 tim_set_default(
"quartet");
60 int tol = (int) (log(accuracy)/log(2.0));
62 int nproc = grp_->n();
72 const double *intbuf = tbi.
buffer();
79 for (i=0; i < gbs.
nshell(); i++) {
85 for (
int j=0; j <= i; j++) {
86 int oij = i_offset(i)+j;
95 grp_->recvt(2323, &from, 1);
96 grp_->sendt(from, 3232, inds, 4);
102 inds[0] = inds[1] = inds[2] = inds[3] = -1;
104 for (i=1; i < nproc; i++) {
106 grp_->recvt(2323, &from, 1);
107 grp_->sendt(from, 3232, inds, 4);
114 grp_->sendt(0, 2323, &me, 1);
115 grp_->recvt(3232, inds, 4);
124 int ni=gbs(i).nfunction();
126 int oij = i_offset(i)+j;
129 int nj=gbs(j).nfunction();
130 int pmaxij = pmax[oij];
132 for (
int k=0; k <= i; k++) {
134 int nk=gbs(k).nfunction();
136 int pmaxijk=pmaxij, ptmp;
137 if ((ptmp=pmax[i_offset(i)+k]-2) > pmaxijk) pmaxijk=ptmp;
138 if ((ptmp=pmax[ij_offset(j,k)]-2) > pmaxijk) pmaxijk=ptmp;
140 int okl = i_offset(k);
141 for (
int l=0; l <= (k==i?j:k); l++,okl++) {
143 int pmaxijkl = pmaxijk;
144 if ((ptmp=pmax[okl]) > pmaxijkl) pmaxijkl=ptmp;
145 if ((ptmp=pmax[i_offset(i)+l]-2) > pmaxijkl) pmaxijkl=ptmp;
146 if ((ptmp=pmax[ij_offset(j,l)]-2) > pmaxijkl) pmaxijkl=ptmp;
152 int qijkl = pl.in_p4(oij,okl,i,j,k,l);
162 int e13e24 = (i==k) && (j==l);
163 int e_any = e12||e34||e13e24;
166 int nl=gbs(l).nfunction();
172 for (I=0, ii=fi; I < ni; I++, ii++) {
173 for (J=0, jj=fj; J <= (e12 ? I : nj-1); J++, jj++) {
174 for (K=0, kk=fk; K <= (e13e24 ? I : nk-1); K++, kk++) {
176 int lend = (e34 ? ((e13e24)&&(K==I) ? J : K)
177 : ((e13e24)&&(K==I)) ? J : nl-1);
178 for (L=0, ll=fl; L <= lend; L++, ll++, index++) {
179 double pki_int = intbuf[index];
181 if ((pki_int>0?pki_int:-pki_int) < 1.0e-15)
198 if (ii == jj || kk == ll) {
199 ij = i_offset(ii)+jj;
200 kl = i_offset(kk)+ll;
201 val = (ij==kl) ? 0.5*pki_int : pki_int;
213 ij = i_offset(ii)+jj;
214 kl = i_offset(kk)+ll;
215 val = (ij==kl) ? 0.5*pki_int : pki_int;
226 ij = ij_offset(ii,ll);
227 kl = ij_offset(kk,jj);
228 val = (ij==kl) ? 0.5*pki_int : pki_int;
232 }
else if (ii == kk || jj == ll) {
240 ij = i_offset(ii)+jj;
241 kl = i_offset(kk)+ll;
242 val = (ij==kl) ? 0.5*pki_int : pki_int;
253 ij = ij_offset(ii,kk);
254 kl = ij_offset(jj,ll);
255 val = (ij==kl) ? 0.5*pki_int : pki_int;
265 ij = i_offset(ii)+jj;
266 kl = i_offset(kk)+ll;
267 val = (ij==kl) ? 0.5*pki_int : pki_int;
276 ij = ij_offset(ii,kk);
277 kl = ij_offset(jj,ll);
278 val = (ij==kl) ? 0.5*pki_int : pki_int;
282 if ((ii != jj) && (kk != ll)) {
292 ij = ij_offset(ii,ll);
293 kl = ij_offset(kk,jj);
307 contribution.cont4(i_offset(ii)+jj,i_offset(kk)+ll,pki_int);
316 contribution.cont3(ij_offset(ii,ll),ij_offset(kk,jj),pki_int);
318 }
else if (ii == kk || jj == ll) {
326 contribution.cont4(i_offset(ii)+jj,i_offset(kk)+ll,pki_int);
335 contribution.cont3(ij_offset(ii,kk),ij_offset(jj,ll),pki_int);
343 contribution.cont1(i_offset(ii)+jj,i_offset(kk)+ll,pki_int);
350 contribution.cont2(ij_offset(ii,kk),ij_offset(jj,ll),pki_int);
357 contribution.cont2(ij_offset(ii,ll),ij_offset(kk,jj),pki_int);
365 tnint += (double) ni*nj*nk*nl;
368 }
while (inds[0] > -1);
371 grp_->sum(&tnint, 1, 0, 0);