| 1 | // | 
|---|
| 2 | // permute2e.cc | 
|---|
| 3 | // | 
|---|
| 4 | // Copyright (C) 2001 Edward Valeev | 
|---|
| 5 | // | 
|---|
| 6 | // Author: Edward Valeev <edward.valeev@chemistry.gatech.edu> | 
|---|
| 7 | // Maintainer: EV | 
|---|
| 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 __GNUG__ | 
|---|
| 29 | #pragma implementation | 
|---|
| 30 | #endif | 
|---|
| 31 |  | 
|---|
| 32 | #include <chemistry/qc/cints/int2e.h> | 
|---|
| 33 | #include <chemistry/qc/cints/macros.h> | 
|---|
| 34 | #ifdef DMALLOC | 
|---|
| 35 | #include <dmalloc.h> | 
|---|
| 36 | #endif | 
|---|
| 37 |  | 
|---|
| 38 | using namespace std; | 
|---|
| 39 | using namespace sc; | 
|---|
| 40 |  | 
|---|
| 41 | inline int max(int a,int b) { return (a > b) ? a : b;} | 
|---|
| 42 | inline void fail() | 
|---|
| 43 | { | 
|---|
| 44 | ExEnv::errn() << scprintf("failing module:\n%s",__FILE__) << endl; | 
|---|
| 45 | abort(); | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | void Int2eCints::sort_contrquartets_to_shellquartet_(double *source_ints_buf, double *target_ints_buf) | 
|---|
| 49 | { | 
|---|
| 50 | int target_bf1_offset = 0; | 
|---|
| 51 | int nbf2 = int_shell2_->nfunction(); | 
|---|
| 52 | int nbf3 = int_shell3_->nfunction(); | 
|---|
| 53 | int nbf4 = int_shell4_->nfunction(); | 
|---|
| 54 | int nbf234 = nbf2*nbf3*nbf4; | 
|---|
| 55 | int nbf34 = nbf3*nbf4; | 
|---|
| 56 | for (int gc1=0; gc1<int_shell1_->ncontraction(); gc1++) { | 
|---|
| 57 | int am1 = int_shell1_->am(gc1); | 
|---|
| 58 | int tsize1 = int_shell1_->nfunction(gc1); | 
|---|
| 59 |  | 
|---|
| 60 | int target_bf2_offset = 0; | 
|---|
| 61 | for (int gc2=0; gc2<int_shell2_->ncontraction(); gc2++) { | 
|---|
| 62 | int am2 = int_shell2_->am(gc2); | 
|---|
| 63 | int tsize2 = int_shell2_->nfunction(gc2); | 
|---|
| 64 |  | 
|---|
| 65 | int target_bf3_offset = 0; | 
|---|
| 66 | for (int gc3=0; gc3<int_shell3_->ncontraction(); gc3++) { | 
|---|
| 67 | int am3 = int_shell3_->am(gc3); | 
|---|
| 68 | int tsize3 = int_shell3_->nfunction(gc3); | 
|---|
| 69 |  | 
|---|
| 70 | int target_bf4_offset = 0; | 
|---|
| 71 | for (int gc4=0; gc4<int_shell4_->ncontraction(); gc4++) { | 
|---|
| 72 | int am4 = int_shell4_->am(gc4); | 
|---|
| 73 | int tsize4 = int_shell4_->nfunction(gc4); | 
|---|
| 74 |  | 
|---|
| 75 | double *target_offset = target_ints_buf + | 
|---|
| 76 | ((target_bf1_offset*nbf2 + | 
|---|
| 77 | target_bf2_offset)*nbf3 + | 
|---|
| 78 | target_bf3_offset)*nbf4 + | 
|---|
| 79 | target_bf4_offset; | 
|---|
| 80 | for (int bf1 = 0; bf1 < tsize1; bf1++, target_offset+=(nbf234-tsize2*nbf34)) { | 
|---|
| 81 | for (int bf2 = 0; bf2 < tsize2; bf2++, target_offset+=(nbf34-tsize3*nbf4)) { | 
|---|
| 82 | for (int bf3 = 0; bf3 < tsize3; bf3++, target_offset+=(nbf4-tsize4)) { | 
|---|
| 83 | for (int bf4 = 0; bf4 < tsize4; bf4++) { | 
|---|
| 84 |  | 
|---|
| 85 | *(target_offset++) = *(source_ints_buf++); | 
|---|
| 86 |  | 
|---|
| 87 | } | 
|---|
| 88 | } | 
|---|
| 89 | } | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | target_bf4_offset += tsize4; | 
|---|
| 93 | } | 
|---|
| 94 | target_bf3_offset += tsize3; | 
|---|
| 95 | } | 
|---|
| 96 | target_bf2_offset += tsize2; | 
|---|
| 97 | } | 
|---|
| 98 | target_bf1_offset += tsize1; | 
|---|
| 99 | } | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 |  | 
|---|
| 103 | //void Int2eCints::get_nonredundant_ints_(double *source, double *target, int e13e24, int e12, int e34) | 
|---|
| 104 | //{ | 
|---|
| 105 | //  if (e13e24 && e12 && e34) | 
|---|
| 106 | //    get_nonredundant_1111_(source,target); | 
|---|
| 107 | //  else if (e13e24) | 
|---|
| 108 | //    get_nonredundant_1212_(source,target); | 
|---|
| 109 | //  else | 
|---|
| 110 | //    get_nonredundant_1234_(source,target); | 
|---|
| 111 | //} | 
|---|
| 112 |  | 
|---|
| 113 |  | 
|---|
| 114 | // source can be safely same as target | 
|---|
| 115 |  | 
|---|
| 116 | void Int2eCints::get_nonredundant_ints_(double *source, double *target, int e13e24, int e12, int e34) | 
|---|
| 117 | { | 
|---|
| 118 | int i,j,k,l; | 
|---|
| 119 |  | 
|---|
| 120 | int nbf1 = int_shell1_->nfunction(); | 
|---|
| 121 | int nbf2 = int_shell2_->nfunction(); | 
|---|
| 122 | int nbf3 = int_shell3_->nfunction(); | 
|---|
| 123 | int nbf4 = int_shell4_->nfunction(); | 
|---|
| 124 |  | 
|---|
| 125 | double *redundant_ptr = source; | 
|---|
| 126 | double *nonredundant_ptr = target; | 
|---|
| 127 |  | 
|---|
| 128 | int nbf34 = nbf3*nbf4; | 
|---|
| 129 | for (i=0; i<nbf1; i++) { | 
|---|
| 130 | int jmax = e12 ? i : nbf2-1; | 
|---|
| 131 | for (j=0; j<=jmax; j++) { | 
|---|
| 132 | int kmax = e13e24 ? i : nbf3-1; | 
|---|
| 133 | for (k=0; k<=kmax; k++) { | 
|---|
| 134 | int lmax = e34 ? ( (e13e24&&(i==k)) ? j : k) : ( (e13e24&&(i==k)) ? j : nbf4-1); | 
|---|
| 135 | for (l=0; l<=lmax; l++) { | 
|---|
| 136 | *(nonredundant_ptr++) = redundant_ptr[l]; | 
|---|
| 137 | } | 
|---|
| 138 | redundant_ptr += nbf4; | 
|---|
| 139 | } | 
|---|
| 140 | redundant_ptr += (nbf3-(kmax+1))*nbf4; | 
|---|
| 141 | } | 
|---|
| 142 | redundant_ptr += (nbf2-(jmax+1))*nbf34; | 
|---|
| 143 | } | 
|---|
| 144 | } | 
|---|
| 145 |  | 
|---|
| 146 | void Int2eCints::permute_target_(double *s, double *t, int p13p24, int p12, int p34) | 
|---|
| 147 | { | 
|---|
| 148 | if (!p13p24) { | 
|---|
| 149 | if (p12) | 
|---|
| 150 | if (p34) | 
|---|
| 151 | permute_1234_to_2143_(s,t); | 
|---|
| 152 | else | 
|---|
| 153 | permute_1234_to_2134_(s,t); | 
|---|
| 154 | else | 
|---|
| 155 | permute_1234_to_1243_(s,t); | 
|---|
| 156 | } | 
|---|
| 157 | else { | 
|---|
| 158 | if (p12) | 
|---|
| 159 | if (p34) | 
|---|
| 160 | permute_1234_to_4321_(s,t); | 
|---|
| 161 | else | 
|---|
| 162 | permute_1234_to_4312_(s,t); | 
|---|
| 163 | else | 
|---|
| 164 | if (p34) | 
|---|
| 165 | permute_1234_to_3421_(s,t); | 
|---|
| 166 | else | 
|---|
| 167 | permute_1234_to_3412_(s,t); | 
|---|
| 168 | } | 
|---|
| 169 | } | 
|---|
| 170 |  | 
|---|
| 171 | void Int2eCints::permute_1234_to_1243_(double *source_ints_buf, double *target_ints_buf) | 
|---|
| 172 | { | 
|---|
| 173 | int nbf1 = int_shell1_->nfunction(); | 
|---|
| 174 | int nbf2 = int_shell2_->nfunction(); | 
|---|
| 175 | int nbf3 = int_shell4_->nfunction(); | 
|---|
| 176 | int nbf4 = int_shell3_->nfunction(); | 
|---|
| 177 | for (int bf1=0; bf1<nbf1; bf1++) { | 
|---|
| 178 | for (int bf2=0; bf2<nbf2; bf2++) { | 
|---|
| 179 | for (int bf4=0; bf4<nbf4; bf4++) { | 
|---|
| 180 | for (int bf3=0; bf3<nbf3; bf3++) { | 
|---|
| 181 | double *target_ints_ptr = target_ints_buf + ((bf1*nbf2 + bf2)*nbf3 + bf3)*nbf4 + bf4; | 
|---|
| 182 | *(target_ints_ptr) = *(source_ints_buf++); | 
|---|
| 183 | } | 
|---|
| 184 | } | 
|---|
| 185 | } | 
|---|
| 186 | } | 
|---|
| 187 | } | 
|---|
| 188 |  | 
|---|
| 189 | void Int2eCints::permute_1234_to_2134_(double *source_ints_buf, double *target_ints_buf) | 
|---|
| 190 | { | 
|---|
| 191 | int nbf1 = int_shell2_->nfunction(); | 
|---|
| 192 | int nbf2 = int_shell1_->nfunction(); | 
|---|
| 193 | int nbf3 = int_shell3_->nfunction(); | 
|---|
| 194 | int nbf4 = int_shell4_->nfunction(); | 
|---|
| 195 | for (int bf2=0; bf2<nbf2; bf2++) { | 
|---|
| 196 | for (int bf1=0; bf1<nbf1; bf1++) { | 
|---|
| 197 | for (int bf3=0; bf3<nbf3; bf3++) { | 
|---|
| 198 | for (int bf4=0; bf4<nbf4; bf4++) { | 
|---|
| 199 | double *target_ints_ptr = target_ints_buf + ((bf1*nbf2 + bf2)*nbf3 + bf3)*nbf4 + bf4; | 
|---|
| 200 | *(target_ints_ptr) = *(source_ints_buf++); | 
|---|
| 201 | } | 
|---|
| 202 | } | 
|---|
| 203 | } | 
|---|
| 204 | } | 
|---|
| 205 | } | 
|---|
| 206 |  | 
|---|
| 207 | void Int2eCints::permute_1234_to_2143_(double *source_ints_buf, double *target_ints_buf) | 
|---|
| 208 | { | 
|---|
| 209 | int nbf1 = int_shell2_->nfunction(); | 
|---|
| 210 | int nbf2 = int_shell1_->nfunction(); | 
|---|
| 211 | int nbf3 = int_shell4_->nfunction(); | 
|---|
| 212 | int nbf4 = int_shell3_->nfunction(); | 
|---|
| 213 | for (int bf2=0; bf2<nbf2; bf2++) { | 
|---|
| 214 | for (int bf1=0; bf1<nbf1; bf1++) { | 
|---|
| 215 | for (int bf4=0; bf4<nbf4; bf4++) { | 
|---|
| 216 | for (int bf3=0; bf3<nbf3; bf3++) { | 
|---|
| 217 | double *target_ints_ptr = target_ints_buf + ((bf1*nbf2 + bf2)*nbf3 + bf3)*nbf4 + bf4; | 
|---|
| 218 | *(target_ints_ptr) = *(source_ints_buf++); | 
|---|
| 219 | } | 
|---|
| 220 | } | 
|---|
| 221 | } | 
|---|
| 222 | } | 
|---|
| 223 | } | 
|---|
| 224 |  | 
|---|
| 225 | void Int2eCints::permute_1234_to_3412_(double *source_ints_buf, double *target_ints_buf) | 
|---|
| 226 | { | 
|---|
| 227 | int nbf1 = int_shell3_->nfunction(); | 
|---|
| 228 | int nbf2 = int_shell4_->nfunction(); | 
|---|
| 229 | int nbf3 = int_shell1_->nfunction(); | 
|---|
| 230 | int nbf4 = int_shell2_->nfunction(); | 
|---|
| 231 | for (int bf3=0; bf3<nbf3; bf3++) { | 
|---|
| 232 | for (int bf4=0; bf4<nbf4; bf4++) { | 
|---|
| 233 | for (int bf1=0; bf1<nbf1; bf1++) { | 
|---|
| 234 | for (int bf2=0; bf2<nbf2; bf2++) { | 
|---|
| 235 | double *target_ints_ptr = target_ints_buf + ((bf1*nbf2 + bf2)*nbf3 + bf3)*nbf4 + bf4; | 
|---|
| 236 | *(target_ints_ptr) = *(source_ints_buf++); | 
|---|
| 237 | } | 
|---|
| 238 | } | 
|---|
| 239 | } | 
|---|
| 240 | } | 
|---|
| 241 | } | 
|---|
| 242 |  | 
|---|
| 243 | void Int2eCints::permute_1234_to_4312_(double *source_ints_buf, double *target_ints_buf) | 
|---|
| 244 | { | 
|---|
| 245 | int nbf1 = int_shell4_->nfunction(); | 
|---|
| 246 | int nbf2 = int_shell3_->nfunction(); | 
|---|
| 247 | int nbf3 = int_shell1_->nfunction(); | 
|---|
| 248 | int nbf4 = int_shell2_->nfunction(); | 
|---|
| 249 | for (int bf3=0; bf3<nbf3; bf3++) { | 
|---|
| 250 | for (int bf4=0; bf4<nbf4; bf4++) { | 
|---|
| 251 | for (int bf2=0; bf2<nbf2; bf2++) { | 
|---|
| 252 | for (int bf1=0; bf1<nbf1; bf1++) { | 
|---|
| 253 | double *target_ints_ptr = target_ints_buf + ((bf1*nbf2 + bf2)*nbf3 + bf3)*nbf4 + bf4; | 
|---|
| 254 | *(target_ints_ptr) = *(source_ints_buf++); | 
|---|
| 255 | } | 
|---|
| 256 | } | 
|---|
| 257 | } | 
|---|
| 258 | } | 
|---|
| 259 | } | 
|---|
| 260 |  | 
|---|
| 261 | void Int2eCints::permute_1234_to_3421_(double *source_ints_buf, double *target_ints_buf) | 
|---|
| 262 | { | 
|---|
| 263 | int nbf1 = int_shell3_->nfunction(); | 
|---|
| 264 | int nbf2 = int_shell4_->nfunction(); | 
|---|
| 265 | int nbf3 = int_shell2_->nfunction(); | 
|---|
| 266 | int nbf4 = int_shell1_->nfunction(); | 
|---|
| 267 | for (int bf4=0; bf4<nbf4; bf4++) { | 
|---|
| 268 | for (int bf3=0; bf3<nbf3; bf3++) { | 
|---|
| 269 | for (int bf1=0; bf1<nbf1; bf1++) { | 
|---|
| 270 | for (int bf2=0; bf2<nbf2; bf2++) { | 
|---|
| 271 | double *target_ints_ptr = target_ints_buf + ((bf1*nbf2 + bf2)*nbf3 + bf3)*nbf4 + bf4; | 
|---|
| 272 | *(target_ints_ptr) = *(source_ints_buf++); | 
|---|
| 273 | } | 
|---|
| 274 | } | 
|---|
| 275 | } | 
|---|
| 276 | } | 
|---|
| 277 | } | 
|---|
| 278 |  | 
|---|
| 279 | void Int2eCints::permute_1234_to_4321_(double *source_ints_buf, double *target_ints_buf) | 
|---|
| 280 | { | 
|---|
| 281 | int nbf1 = int_shell4_->nfunction(); | 
|---|
| 282 | int nbf2 = int_shell3_->nfunction(); | 
|---|
| 283 | int nbf3 = int_shell2_->nfunction(); | 
|---|
| 284 | int nbf4 = int_shell1_->nfunction(); | 
|---|
| 285 | for (int bf4=0; bf4<nbf4; bf4++) { | 
|---|
| 286 | for (int bf3=0; bf3<nbf3; bf3++) { | 
|---|
| 287 | for (int bf2=0; bf2<nbf2; bf2++) { | 
|---|
| 288 | for (int bf1=0; bf1<nbf1; bf1++) { | 
|---|
| 289 | double *target_ints_ptr = target_ints_buf + ((bf1*nbf2 + bf2)*nbf3 + bf3)*nbf4 + bf4; | 
|---|
| 290 | *(target_ints_ptr) = *(source_ints_buf++); | 
|---|
| 291 | } | 
|---|
| 292 | } | 
|---|
| 293 | } | 
|---|
| 294 | } | 
|---|
| 295 | } | 
|---|
| 296 |  | 
|---|
| 297 |  | 
|---|
| 298 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 299 |  | 
|---|
| 300 | // Local Variables: | 
|---|
| 301 | // mode: c++ | 
|---|
| 302 | // c-file-style: "CLJ" | 
|---|
| 303 | // End: | 
|---|