| 1 | //
 | 
|---|
| 2 | // sointegral.cc --- implementation of the Integral class
 | 
|---|
| 3 | //
 | 
|---|
| 4 | // Copyright (C) 1998 Limit Point Systems, Inc.
 | 
|---|
| 5 | //
 | 
|---|
| 6 | // Author: Curtis Janssen <cljanss@limitpt.com>
 | 
|---|
| 7 | // Maintainer: LPS
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // This file is part of the SC Toolkit.
 | 
|---|
| 10 | //
 | 
|---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify
 | 
|---|
| 12 | // it under the terms of the GNU Library General Public License as published by
 | 
|---|
| 13 | // the Free Software Foundation; either version 2, or (at your option)
 | 
|---|
| 14 | // any later version.
 | 
|---|
| 15 | //
 | 
|---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful,
 | 
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 19 | // GNU Library General Public License for more details.
 | 
|---|
| 20 | //
 | 
|---|
| 21 | // You should have received a copy of the GNU Library General Public License
 | 
|---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
 | 
|---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 | 
|---|
| 24 | //
 | 
|---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7.
 | 
|---|
| 26 | //
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #ifdef __GNUC__
 | 
|---|
| 29 | #pragma implementation
 | 
|---|
| 30 | #endif
 | 
|---|
| 31 | 
 | 
|---|
| 32 | #include <util/misc/formio.h>
 | 
|---|
| 33 | #include <chemistry/qc/basis/sointegral.h>
 | 
|---|
| 34 | 
 | 
|---|
| 35 | using namespace std;
 | 
|---|
| 36 | using namespace sc;
 | 
|---|
| 37 | 
 | 
|---|
| 38 | #define DEBUG 0
 | 
|---|
| 39 | 
 | 
|---|
| 40 | /////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 41 | // OneBodySOInt
 | 
|---|
| 42 | 
 | 
|---|
| 43 | OneBodySOInt::OneBodySOInt(const Ref<OneBodyInt> &ob)
 | 
|---|
| 44 | {
 | 
|---|
| 45 |   ob_ = ob;
 | 
|---|
| 46 | 
 | 
|---|
| 47 |   b1_ = new SOBasis(ob->basis1(), ob->integral());
 | 
|---|
| 48 | 
 | 
|---|
| 49 |   if (ob->basis2() == ob->basis1()) b2_ = b1_;
 | 
|---|
| 50 |   else b2_ = new SOBasis(ob->basis2(), ob->integral());
 | 
|---|
| 51 | 
 | 
|---|
| 52 |   only_totally_symmetric_ = 0;
 | 
|---|
| 53 | 
 | 
|---|
| 54 |   buffer_ = new double[b1_->max_nfunction_in_shell()
 | 
|---|
| 55 |                       *b2_->max_nfunction_in_shell()];
 | 
|---|
| 56 | }
 | 
|---|
| 57 | 
 | 
|---|
| 58 | OneBodySOInt::~OneBodySOInt()
 | 
|---|
| 59 | {
 | 
|---|
| 60 |   delete[] buffer_;
 | 
|---|
| 61 | }
 | 
|---|
| 62 | 
 | 
|---|
| 63 | Ref<SOBasis>
 | 
|---|
| 64 | OneBodySOInt::basis() const
 | 
|---|
| 65 | {
 | 
|---|
| 66 |   return b1_;
 | 
|---|
| 67 | }
 | 
|---|
| 68 | 
 | 
|---|
| 69 | Ref<SOBasis>
 | 
|---|
| 70 | OneBodySOInt::basis1() const
 | 
|---|
| 71 | {
 | 
|---|
| 72 |   return b1_;
 | 
|---|
| 73 | }
 | 
|---|
| 74 | 
 | 
|---|
| 75 | Ref<SOBasis>
 | 
|---|
| 76 | OneBodySOInt::basis2() const
 | 
|---|
| 77 | {
 | 
|---|
| 78 |   return b2_;
 | 
|---|
| 79 | }
 | 
|---|
| 80 | 
 | 
|---|
| 81 | void
 | 
|---|
| 82 | OneBodySOInt::compute_shell(int ish, int jsh)
 | 
|---|
| 83 | {
 | 
|---|
| 84 |   const double *aobuf = ob_->buffer();
 | 
|---|
| 85 | 
 | 
|---|
| 86 |   const SOTransform &t1 = b1_->trans(ish);
 | 
|---|
| 87 |   const SOTransform &t2 = b2_->trans(jsh);
 | 
|---|
| 88 | 
 | 
|---|
| 89 |   int nso1 = b1_->nfunction(ish);
 | 
|---|
| 90 |   int nso2 = b2_->nfunction(jsh);
 | 
|---|
| 91 | 
 | 
|---|
| 92 |   memset(buffer_, 0, nso1*nso2*sizeof(double));
 | 
|---|
| 93 | 
 | 
|---|
| 94 |   int nao2 = b2_->naofunction(jsh);
 | 
|---|
| 95 | 
 | 
|---|
| 96 |   // loop through the AO shells that make up this SO shell
 | 
|---|
| 97 |   for (int i=0; i<t1.naoshell; i++) {
 | 
|---|
| 98 |     const SOTransformShell &s1 = t1.aoshell[i];
 | 
|---|
| 99 |     for (int j=0; j<t2.naoshell; j++) {
 | 
|---|
| 100 |       const SOTransformShell &s2 = t2.aoshell[j];
 | 
|---|
| 101 |       ob_->compute_shell(s1.aoshell, s2.aoshell);
 | 
|---|
| 102 |       for (int itr=0; itr<s1.nfunc; itr++) {
 | 
|---|
| 103 |         const SOTransformFunction &ifunc = s1.func[itr];
 | 
|---|
| 104 |         double icoef = ifunc.coef;
 | 
|---|
| 105 |         int iaofunc = ifunc.aofunc;
 | 
|---|
| 106 |         int isofunc = b1_->function_offset_within_shell(ish, ifunc.irrep)
 | 
|---|
| 107 |           + ifunc.sofunc;
 | 
|---|
| 108 |         int iaooff = iaofunc;
 | 
|---|
| 109 |         int isooff = isofunc;
 | 
|---|
| 110 |         for (int jtr=0; jtr<s2.nfunc; jtr++) {
 | 
|---|
| 111 |           const SOTransformFunction &jfunc = s2.func[jtr];
 | 
|---|
| 112 |           double jcoef = jfunc.coef * icoef;
 | 
|---|
| 113 |           int jaofunc = jfunc.aofunc;
 | 
|---|
| 114 |           int jsofunc = b2_->function_offset_within_shell(jsh, jfunc.irrep)
 | 
|---|
| 115 |             + jfunc.sofunc;
 | 
|---|
| 116 |           int jaooff = iaooff*nao2 + jaofunc;
 | 
|---|
| 117 |           int jsooff = isooff*nso2 + jsofunc;
 | 
|---|
| 118 |           buffer_[jsooff] += jcoef * aobuf[jaooff];
 | 
|---|
| 119 | #if DEBUG
 | 
|---|
| 120 |           if (fabs(aobuf[jaooff]*jcoef) > 1.0e-10) {
 | 
|---|
| 121 |             ExEnv::outn() <<"("<<isofunc
 | 
|---|
| 122 |                  <<"|"<<jsofunc
 | 
|---|
| 123 |                  <<") += "<<scprintf("%8.5f",jcoef)<<" * "
 | 
|---|
| 124 |                  <<"("<<iaofunc
 | 
|---|
| 125 |                  <<"|"<<jaofunc
 | 
|---|
| 126 |                  <<"): "
 | 
|---|
| 127 |                  <<scprintf("%8.5f -> %8.5f",
 | 
|---|
| 128 |                             aobuf[jaooff], buffer_[jsooff])
 | 
|---|
| 129 |                  << endl;
 | 
|---|
| 130 |           }
 | 
|---|
| 131 | #endif
 | 
|---|
| 132 |         }
 | 
|---|
| 133 |       }
 | 
|---|
| 134 |     }
 | 
|---|
| 135 |   }
 | 
|---|
| 136 | }
 | 
|---|
| 137 | 
 | 
|---|
| 138 | void
 | 
|---|
| 139 | OneBodySOInt::reinitialize()
 | 
|---|
| 140 | {
 | 
|---|
| 141 |   ob_->reinitialize();
 | 
|---|
| 142 | }
 | 
|---|
| 143 | 
 | 
|---|
| 144 | /////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 145 | // TwoBodySOInt
 | 
|---|
| 146 | 
 | 
|---|
| 147 | TwoBodySOInt::TwoBodySOInt(const Ref<TwoBodyInt> &tb)
 | 
|---|
| 148 | {
 | 
|---|
| 149 |   tb_ = tb;
 | 
|---|
| 150 | 
 | 
|---|
| 151 |   b1_ = new SOBasis(tb->basis1(), tb->integral());
 | 
|---|
| 152 | 
 | 
|---|
| 153 |   if (tb->basis2() == tb->basis1()) b2_ = b1_;
 | 
|---|
| 154 |   else b2_ = new SOBasis(tb->basis2(), tb->integral());
 | 
|---|
| 155 | 
 | 
|---|
| 156 |   if (tb->basis3() == tb->basis1()) b3_ = b1_;
 | 
|---|
| 157 |   else if (tb->basis3() == tb->basis2()) b3_ = b2_;
 | 
|---|
| 158 |   else b3_ = new SOBasis(tb->basis3(), tb->integral());
 | 
|---|
| 159 | 
 | 
|---|
| 160 |   if (tb->basis4() == tb->basis1()) b4_ = b1_;
 | 
|---|
| 161 |   else if (tb->basis4() == tb->basis2()) b4_ = b2_;
 | 
|---|
| 162 |   else if (tb->basis4() == tb->basis3()) b4_ = b3_;
 | 
|---|
| 163 |   else b4_ = new SOBasis(tb->basis4(), tb->integral());
 | 
|---|
| 164 | 
 | 
|---|
| 165 |   redundant_ = 1;
 | 
|---|
| 166 |   only_totally_symmetric_ = 0;
 | 
|---|
| 167 | 
 | 
|---|
| 168 |   buffer_ = new double[b1_->max_nfunction_in_shell()
 | 
|---|
| 169 |                       *b2_->max_nfunction_in_shell()
 | 
|---|
| 170 |                       *b3_->max_nfunction_in_shell()
 | 
|---|
| 171 |                       *b4_->max_nfunction_in_shell()];
 | 
|---|
| 172 | }
 | 
|---|
| 173 | 
 | 
|---|
| 174 | TwoBodySOInt::~TwoBodySOInt()
 | 
|---|
| 175 | {
 | 
|---|
| 176 |   delete[] buffer_;
 | 
|---|
| 177 | }
 | 
|---|
| 178 | 
 | 
|---|
| 179 | Ref<SOBasis>
 | 
|---|
| 180 | TwoBodySOInt::basis() const
 | 
|---|
| 181 | {
 | 
|---|
| 182 |   return b1_;
 | 
|---|
| 183 | }
 | 
|---|
| 184 | 
 | 
|---|
| 185 | Ref<SOBasis>
 | 
|---|
| 186 | TwoBodySOInt::basis1() const
 | 
|---|
| 187 | {
 | 
|---|
| 188 |   return b1_;
 | 
|---|
| 189 | }
 | 
|---|
| 190 | 
 | 
|---|
| 191 | Ref<SOBasis>
 | 
|---|
| 192 | TwoBodySOInt::basis2() const
 | 
|---|
| 193 | {
 | 
|---|
| 194 |   return b2_;
 | 
|---|
| 195 | }
 | 
|---|
| 196 | 
 | 
|---|
| 197 | Ref<SOBasis>
 | 
|---|
| 198 | TwoBodySOInt::basis3() const
 | 
|---|
| 199 | {
 | 
|---|
| 200 |   return b3_;
 | 
|---|
| 201 | }
 | 
|---|
| 202 | 
 | 
|---|
| 203 | Ref<SOBasis>
 | 
|---|
| 204 | TwoBodySOInt::basis4() const
 | 
|---|
| 205 | {
 | 
|---|
| 206 |   return b4_;
 | 
|---|
| 207 | }
 | 
|---|
| 208 | 
 | 
|---|
| 209 | void
 | 
|---|
| 210 | TwoBodySOInt::compute_shell(int ish, int jsh, int ksh, int lsh)
 | 
|---|
| 211 | {
 | 
|---|
| 212 |   tb_->set_redundant(1);
 | 
|---|
| 213 |   const double *aobuf = tb_->buffer();
 | 
|---|
| 214 | 
 | 
|---|
| 215 |   const SOTransform &t1 = b1_->trans(ish);
 | 
|---|
| 216 |   const SOTransform &t2 = b2_->trans(jsh);
 | 
|---|
| 217 |   const SOTransform &t3 = b3_->trans(ksh);
 | 
|---|
| 218 |   const SOTransform &t4 = b4_->trans(lsh);
 | 
|---|
| 219 | 
 | 
|---|
| 220 |   int nso1 = b1_->nfunction(ish);
 | 
|---|
| 221 |   int nso2 = b2_->nfunction(jsh);
 | 
|---|
| 222 |   int nso3 = b3_->nfunction(ksh);
 | 
|---|
| 223 |   int nso4 = b4_->nfunction(lsh);
 | 
|---|
| 224 | 
 | 
|---|
| 225 |   memset(buffer_, 0, nso1*nso2*nso3*nso4*sizeof(double));
 | 
|---|
| 226 | 
 | 
|---|
| 227 |   int nao2 = b2_->naofunction(jsh);
 | 
|---|
| 228 |   int nao3 = b3_->naofunction(ksh);
 | 
|---|
| 229 |   int nao4 = b4_->naofunction(lsh);
 | 
|---|
| 230 | 
 | 
|---|
| 231 |   // loop through the ao shells that make up this so shell
 | 
|---|
| 232 |   for (int i=0; i<t1.naoshell; i++) {
 | 
|---|
| 233 |     const SOTransformShell &s1 = t1.aoshell[i];
 | 
|---|
| 234 |     for (int j=0; j<t2.naoshell; j++) {
 | 
|---|
| 235 |       const SOTransformShell &s2 = t2.aoshell[j];
 | 
|---|
| 236 |       for (int k=0; k<t3.naoshell; k++) {
 | 
|---|
| 237 |         const SOTransformShell &s3 = t3.aoshell[k];
 | 
|---|
| 238 |         for (int l=0; l<t4.naoshell; l++) {
 | 
|---|
| 239 |           const SOTransformShell &s4 = t4.aoshell[l];
 | 
|---|
| 240 |           tb_->compute_shell(s1.aoshell, s2.aoshell, s3.aoshell, s4.aoshell);
 | 
|---|
| 241 |           for (int itr=0; itr<s1.nfunc; itr++) {
 | 
|---|
| 242 |             const SOTransformFunction &ifunc = s1.func[itr];
 | 
|---|
| 243 |             double icoef = ifunc.coef;
 | 
|---|
| 244 |             int iaofunc = ifunc.aofunc;
 | 
|---|
| 245 |             int isofunc = b1_->function_offset_within_shell(ish,
 | 
|---|
| 246 |                                                             ifunc.irrep)
 | 
|---|
| 247 |                           + ifunc.sofunc;
 | 
|---|
| 248 |             int iaooff = iaofunc;
 | 
|---|
| 249 |             int isooff = isofunc;
 | 
|---|
| 250 |             for (int jtr=0; jtr<s2.nfunc; jtr++) {
 | 
|---|
| 251 |               const SOTransformFunction &jfunc = s2.func[jtr];
 | 
|---|
| 252 |               double jcoef = jfunc.coef * icoef;
 | 
|---|
| 253 |               int jaofunc = jfunc.aofunc;
 | 
|---|
| 254 |               int jsofunc = b2_->function_offset_within_shell(jsh,
 | 
|---|
| 255 |                                                               jfunc.irrep)
 | 
|---|
| 256 |                             + jfunc.sofunc;
 | 
|---|
| 257 |               int jaooff = iaooff*nao2 + jaofunc;
 | 
|---|
| 258 |               int jsooff = isooff*nso2 + jsofunc;
 | 
|---|
| 259 |               for (int ktr=0; ktr<s3.nfunc; ktr++) {
 | 
|---|
| 260 |                 const SOTransformFunction &kfunc = s3.func[ktr];
 | 
|---|
| 261 |                 double kcoef = kfunc.coef * jcoef;
 | 
|---|
| 262 |                 int kaofunc = kfunc.aofunc;
 | 
|---|
| 263 |                 int ksofunc = b3_->function_offset_within_shell(ksh,
 | 
|---|
| 264 |                                                                 kfunc.irrep)
 | 
|---|
| 265 |                               + kfunc.sofunc;
 | 
|---|
| 266 |                 int kaooff = jaooff*nao3 + kaofunc;
 | 
|---|
| 267 |                 int ksooff = jsooff*nso3 + ksofunc;
 | 
|---|
| 268 |                 for (int ltr=0; ltr<s4.nfunc; ltr++) {
 | 
|---|
| 269 |                   const SOTransformFunction &lfunc = s4.func[ltr];
 | 
|---|
| 270 |                   double lcoef = lfunc.coef * kcoef;
 | 
|---|
| 271 |                   int laofunc = lfunc.aofunc;
 | 
|---|
| 272 |                   int lsofunc = b4_->function_offset_within_shell(lsh,
 | 
|---|
| 273 |                                                                   lfunc.irrep)
 | 
|---|
| 274 |                                 + lfunc.sofunc;
 | 
|---|
| 275 |                   int laooff = kaooff*nao4 + laofunc;
 | 
|---|
| 276 |                   int lsooff = ksooff*nso4 + lsofunc;
 | 
|---|
| 277 |                   buffer_[lsooff] += lcoef * aobuf[laooff];
 | 
|---|
| 278 | #if DEBUG
 | 
|---|
| 279 |                   if (fabs(aobuf[laooff]*lcoef) > 1.0e-10) {
 | 
|---|
| 280 |                       ExEnv::outn() <<"("<<isofunc<<jsofunc
 | 
|---|
| 281 |                            <<"|"<<ksofunc<<lsofunc
 | 
|---|
| 282 |                            <<") += "<<scprintf("%8.5f",lcoef)<<" * "
 | 
|---|
| 283 |                            <<"("<<iaofunc<<jaofunc
 | 
|---|
| 284 |                            <<"|"<<kaofunc<<laofunc
 | 
|---|
| 285 |                            <<"): "
 | 
|---|
| 286 |                            <<scprintf("%8.5f -> %8.5f",
 | 
|---|
| 287 |                                       aobuf[laooff], buffer_[lsooff])
 | 
|---|
| 288 |                            << endl;
 | 
|---|
| 289 |                     }
 | 
|---|
| 290 | #endif
 | 
|---|
| 291 |                   }
 | 
|---|
| 292 |                 }
 | 
|---|
| 293 |               }
 | 
|---|
| 294 |             }
 | 
|---|
| 295 |           }
 | 
|---|
| 296 |         }
 | 
|---|
| 297 |       }
 | 
|---|
| 298 |     }
 | 
|---|
| 299 | }
 | 
|---|
| 300 | 
 | 
|---|
| 301 | 
 | 
|---|
| 302 | /////////////////////////////////////////////////////////////////////////////
 | 
|---|
| 303 | 
 | 
|---|
| 304 | // Local Variables:
 | 
|---|
| 305 | // mode: c++
 | 
|---|
| 306 | // c-file-style: "CLJ-CONDENSED"
 | 
|---|
| 307 | // End:
 | 
|---|