# tchftmpl.h

    00001
    00002 namespace sc {
    00003
    00004 class LocalTCContribution {
    00005   private:
    00006     double * const gmata;
    00007     double * const gmatb;
    00008     double * const kmata;
    00009     double * const kmatb;
    00010
    00011     double * const pmata;
    00012     double * const pmatb;
    00013     double * const opmata;
    00014     double * const opmatb;
    00015   public:
    00016     LocalTCContribution(double *ga, double *pa, double *gb, double *pb,
    00017                         double *ka, double *opa, double *kb, double *opb) :
    00018       gmata(ga), gmatb(gb), kmata(ka), kmatb(kb),
    00019       pmata(pa), pmatb(pb), opmata(opa), opmatb(opb) {}
    00020     ~LocalTCContribution() {}
    00021
    00022     void set_bound(double,double) {}
    00023
    00024     inline void cont1(int ij, int kl, double val) {
    00025       gmata[ij] += val*pmata[kl];
    00026       gmata[kl] += val*pmata[ij];
    00027
    00028       gmatb[ij] += val*pmatb[kl];
    00029       gmatb[kl] += val*pmatb[ij];
    00030     }
    00031
    00032     inline void cont2(int ij, int kl, double val) {
    00033       val *= 0.25;
    00034       gmata[ij] -= val*pmata[kl];
    00035       gmata[kl] -= val*pmata[ij];
    00036
    00037       gmatb[ij] -= val*pmatb[kl];
    00038       gmatb[kl] -= val*pmatb[ij];
    00039
    00040       kmata[ij] += val*opmata[kl];
    00041       kmata[kl] += val*opmata[ij];
    00042
    00043       kmatb[ij] += val*opmatb[kl];
    00044       kmatb[kl] += val*opmatb[ij];
    00045     }
    00046
    00047     inline void cont3(int ij, int kl, double val) {
    00048       val *= 0.5;
    00049       gmata[ij] -= val*pmata[kl];
    00050       gmata[kl] -= val*pmata[ij];
    00051
    00052       gmatb[ij] -= val*pmatb[kl];
    00053       gmatb[kl] -= val*pmatb[ij];
    00054
    00055       kmata[ij] += val*opmata[kl];
    00056       kmata[kl] += val*opmata[ij];
    00057
    00058       kmatb[ij] += val*opmatb[kl];
    00059       kmatb[kl] += val*opmatb[ij];
    00060     }
    00061
    00062     inline void cont4(int ij, int kl, double val) {
    00063       gmata[ij] += 0.75*val*pmata[kl];
    00064       gmata[kl] += 0.75*val*pmata[ij];
    00065
    00066       gmatb[ij] += 0.75*val*pmatb[kl];
    00067       gmatb[kl] += 0.75*val*pmatb[ij];
    00068
    00069       kmata[ij] += 0.25*val*opmata[kl];
    00070       kmata[kl] += 0.25*val*opmata[ij];
    00071
    00072       kmatb[ij] += 0.25*val*opmatb[kl];
    00073       kmatb[kl] += 0.25*val*opmatb[ij];
    00074     }
    00075
    00076     inline void cont5(int ij, int kl, double val) {
    00077       val *= 0.5;
    00078       gmata[ij] += val*pmata[kl];
    00079       gmata[kl] += val*pmata[ij];
    00080
    00081       gmatb[ij] += val*pmatb[kl];
    00082       gmatb[kl] += val*pmatb[ij];
    00083
    00084       kmata[ij] += val*opmata[kl];
    00085       kmata[kl] += val*opmata[ij];
    00086
    00087       kmatb[ij] += val*opmatb[kl];
    00088       kmatb[kl] += val*opmatb[ij];
    00089     }
    00090 };
    00091
    00092 class LocalTCEnergyContribution {
    00093   private:
    00094     double * const pmata;
    00095     double * const pmatb;
    00096     double * const opmata;
    00097     double * const opmatb;
    00098
    00099   public:
    00100     double eca;
    00101     double exa;
    00102     double ecb;
    00103     double exb;
    00104     double ecab;
    00105     double exab;
    00106
    00107     LocalTCEnergyContribution(double *pa, double *pb, double *opa, double *opb) :
    00108       pmata(pa), pmatb(pb), opmata(opa), opmatb(opb) {
    00109       exa=eca=0;
    00110       exb=ecb=0;
    00111       exab=ecab=0;
    00112     }
    00113     ~LocalTCEnergyContribution() {}
    00114
    00115     void set_bound(double,double) {};
    00116
    00117     inline void cont1(int ij, int kl, double val) {
    00118       eca += val*pmata[ij]*pmata[kl];
    00119       ecb += val*pmatb[ij]*pmatb[kl];
    00120       ecab += val*(pmata[ij]*pmatb[kl]-pmatb[ij]*pmata[kl]);
    00121     }
    00122
    00123     inline void cont2(int ij, int kl, double val) {
    00124       exa -= 0.25*val*pmata[ij]*pmata[kl];
    00125       exb -= 0.25*val*pmatb[ij]*pmatb[kl];
    00126       exab -= 0.25*val*(pmata[ij]*pmatb[kl]-pmatb[ij]*pmata[kl]);
    00127     }
    00128
    00129     inline void cont3(int ij, int kl, double val) {
    00130       exa -= 0.5*val*pmata[ij]*pmata[kl];
    00131       exb -= 0.5*val*pmatb[ij]*pmatb[kl];
    00132       exab -= 0.5*val*(pmata[ij]*pmatb[kl]-pmatb[ij]*pmata[kl]);
    00133     }
    00134
    00135     inline void cont4(int ij, int kl, double val) {
    00136       eca += val*pmata[ij]*pmata[kl];
    00137       ecb += val*pmatb[ij]*pmatb[kl];
    00138       ecab += val*(pmata[ij]*pmatb[kl]-pmatb[ij]*pmata[kl]);
    00139
    00140       exa -= 0.25*val*pmata[ij]*pmata[kl];
    00141       exb -= 0.25*val*pmatb[ij]*pmatb[kl];
    00142       exab -= 0.25*val*(pmata[ij]*pmatb[kl]-pmatb[ij]*pmata[kl]);
    00143     }
    00144
    00145     inline void cont5(int ij, int kl, double val) {
    00146       eca += val*pmata[ij]*pmata[kl];
    00147       ecb += val*pmatb[ij]*pmatb[kl];
    00148       ecab += val*(pmata[ij]*pmatb[kl]-pmatb[ij]*pmata[kl]);
    00149
    00150       exa -= 0.5*val*pmata[ij]*pmata[kl];
    00151       exb -= 0.5*val*pmatb[ij]*pmatb[kl];
    00152       exab -= 0.5*val*(pmata[ij]*pmatb[kl]-pmatb[ij]*pmata[kl]);
    00153     }
    00154 };
    00155
    00156 class LocalTCGradContribution {
    00157   private:
    00158     double * const pmat;
    00159     double * const pmata;
    00160     double * const pmatb;
    00161     double c1sq;
    00162     double c2sq;
    00163     double c1c2;
    00164
    00165   public:
    00166     LocalTCGradContribution(double *p, double *pa, double *pb,
    00167                             double c1, double c2) :
    00168       pmat(p), pmata(pa), pmatb(pb)
    00169     {
    00170       c1sq = c1*c1;
    00171       c2sq = c2*c2;
    00172       c1c2 = c1*c2;
    00173     }
    00174     ~LocalTCGradContribution() {}
    00175
    00176     inline double cont1(int ij, int kl) {
    00177       return pmat[ij]*pmat[kl] +
    00178         c1sq*(pmata[ij]*pmat[kl] + pmat[ij]*pmata[kl]) +
    00179         c2sq*(pmatb[ij]*pmat[kl] + pmat[ij]*pmatb[kl]) +
    00180         0.5*c1sq*pmata[ij]*pmata[kl] +
    00181         0.5*c2sq*pmatb[ij]*pmatb[kl];
    00182     }
    00183
    00184     inline double cont2(int ij, int kl) {
    00185       return pmat[ij]*pmat[kl] +
    00186         c1sq*(pmata[ij]*pmat[kl] + pmat[ij]*pmata[kl]) +
    00187         c2sq*(pmatb[ij]*pmat[kl] + pmat[ij]*pmatb[kl]) -
    00188         c1c2*(pmata[ij]*pmatb[kl] + pmatb[ij]*pmata[kl]);
    00189     }
    00190 };
    00191
    00192 }