28 #ifndef _chemistry_qc_scf_lbgbuild_h
29 #define _chemistry_qc_scf_lbgbuild_h
31 #include <chemistry/qc/scf/gbuild.h>
48 GBuild<T>(t), grp_(g), tbi_(tbi), integral_(ints), gbs_(bs), pmax(pm) {}
51 void build_gmat(
double accuracy) {
56 int tol = (int) (log(accuracy)/log(2.0));
58 int nproc = grp_->n();
68 const double *intbuf = tbi.
buffer();
75 for (i=0; i < gbs.
nshell(); i++) {
81 for (
int j=0; j <= i; j++) {
82 int oij = i_offset(i)+j;
91 grp_->recvt(2323, &from, 1);
92 grp_->sendt(from, 3232, inds, 4);
98 inds[0] = inds[1] = inds[2] = inds[3] = -1;
100 for (i=1; i < nproc; i++) {
102 grp_->recvt(2323, &from, 1);
103 grp_->sendt(from, 3232, inds, 4);
110 grp_->sendt(0, 2323, &me, 1);
111 grp_->recvt(3232, inds, 4);
120 int ni=gbs(i).nfunction();
122 int oij = i_offset(i)+j;
125 int nj=gbs(j).nfunction();
126 int pmaxij = pmax[oij];
128 for (
int k=0; k <= i; k++) {
130 int nk=gbs(k).nfunction();
132 int pmaxijk=pmaxij, ptmp;
133 if ((ptmp=pmax[i_offset(i)+k]-2) > pmaxijk) pmaxijk=ptmp;
134 if ((ptmp=pmax[ij_offset(j,k)]-2) > pmaxijk) pmaxijk=ptmp;
136 int okl = i_offset(k);
137 for (
int l=0; l <= (k==i?j:k); l++,okl++) {
139 int pmaxijkl = pmaxijk;
140 if ((ptmp=pmax[okl]) > pmaxijkl) pmaxijkl=ptmp;
141 if ((ptmp=pmax[i_offset(i)+l]-2) > pmaxijkl) pmaxijkl=ptmp;
142 if ((ptmp=pmax[ij_offset(j,l)]-2) > pmaxijkl) pmaxijkl=ptmp;
148 int qijkl = pl.in_p4(oij,okl,i,j,k,l);
158 int e13e24 = (i==k) && (j==l);
159 int e_any = e12||e34||e13e24;
162 int nl=gbs(l).nfunction();
168 for (I=0, ii=fi; I < ni; I++, ii++) {
169 for (J=0, jj=fj; J <= (e12 ? I : nj-1); J++, jj++) {
170 for (K=0, kk=fk; K <= (e13e24 ? I : nk-1); K++, kk++) {
172 int lend = (e34 ? ((e13e24)&&(K==I) ? J : K)
173 : ((e13e24)&&(K==I)) ? J : nl-1);
174 for (L=0, ll=fl; L <= lend; L++, ll++, index++) {
175 double pki_int = intbuf[index];
177 if ((pki_int>0?pki_int:-pki_int) < 1.0e-15)
194 if (ii == jj || kk == ll) {
195 ij = i_offset(ii)+jj;
196 kl = i_offset(kk)+ll;
197 val = (ij==kl) ? 0.5*pki_int : pki_int;
209 ij = i_offset(ii)+jj;
210 kl = i_offset(kk)+ll;
211 val = (ij==kl) ? 0.5*pki_int : pki_int;
222 ij = ij_offset(ii,ll);
223 kl = ij_offset(kk,jj);
224 val = (ij==kl) ? 0.5*pki_int : pki_int;
228 }
else if (ii == kk || jj == ll) {
236 ij = i_offset(ii)+jj;
237 kl = i_offset(kk)+ll;
238 val = (ij==kl) ? 0.5*pki_int : pki_int;
249 ij = ij_offset(ii,kk);
250 kl = ij_offset(jj,ll);
251 val = (ij==kl) ? 0.5*pki_int : pki_int;
261 ij = i_offset(ii)+jj;
262 kl = i_offset(kk)+ll;
263 val = (ij==kl) ? 0.5*pki_int : pki_int;
272 ij = ij_offset(ii,kk);
273 kl = ij_offset(jj,ll);
274 val = (ij==kl) ? 0.5*pki_int : pki_int;
278 if ((ii != jj) && (kk != ll)) {
288 ij = ij_offset(ii,ll);
289 kl = ij_offset(kk,jj);
303 contribution.cont4(i_offset(ii)+jj,i_offset(kk)+ll,pki_int);
312 contribution.cont3(ij_offset(ii,ll),ij_offset(kk,jj),pki_int);
314 }
else if (ii == kk || jj == ll) {
322 contribution.cont4(i_offset(ii)+jj,i_offset(kk)+ll,pki_int);
331 contribution.cont3(ij_offset(ii,kk),ij_offset(jj,ll),pki_int);
339 contribution.cont1(i_offset(ii)+jj,i_offset(kk)+ll,pki_int);
346 contribution.cont2(ij_offset(ii,kk),ij_offset(jj,ll),pki_int);
353 contribution.cont2(ij_offset(ii,ll),ij_offset(kk,jj),pki_int);
361 tnint += (double) ni*nj*nk*nl;
364 }
while (inds[0] > -1);
367 grp_->sum(&tnint, 1, 0, 0);