| 1 | // | 
|---|
| 2 | // eri.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 <util/misc/formio.h> | 
|---|
| 33 | #include <chemistry/qc/basis/integral.h> | 
|---|
| 34 | #include <chemistry/qc/cints/eri.h> | 
|---|
| 35 | #ifdef DMALLOC | 
|---|
| 36 | #include <dmalloc.h> | 
|---|
| 37 | #endif | 
|---|
| 38 |  | 
|---|
| 39 | #define STORE_PAIR_DATA 1 | 
|---|
| 40 |  | 
|---|
| 41 | using namespace std; | 
|---|
| 42 | using namespace sc; | 
|---|
| 43 |  | 
|---|
| 44 | // This global object initializes the static interface of libint | 
|---|
| 45 | LibintStaticInterface LibintStaticInitializer; | 
|---|
| 46 |  | 
|---|
| 47 | inline int max(int a,int b) { return (a > b) ? a : b;} | 
|---|
| 48 | inline void fail() | 
|---|
| 49 | { | 
|---|
| 50 | ExEnv::errn() << scprintf("failing module:\n%s",__FILE__) << endl; | 
|---|
| 51 | abort(); | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 | EriCints::EriCints(Integral *integral, | 
|---|
| 55 | const Ref<GaussianBasisSet>& b1, | 
|---|
| 56 | const Ref<GaussianBasisSet>& b2, | 
|---|
| 57 | const Ref<GaussianBasisSet>& b3, | 
|---|
| 58 | const Ref<GaussianBasisSet>& b4, | 
|---|
| 59 | size_t storage) : | 
|---|
| 60 | Int2eCints(integral,b1,b2,b3,b4,storage) | 
|---|
| 61 | { | 
|---|
| 62 | // The static part of Libint's interface is automatically initialized in libint.cc | 
|---|
| 63 | int l1 = bs1_->max_angular_momentum(); | 
|---|
| 64 | int l2 = bs2_->max_angular_momentum(); | 
|---|
| 65 | int l3 = bs3_->max_angular_momentum(); | 
|---|
| 66 | int l4 = bs4_->max_angular_momentum(); | 
|---|
| 67 | int lmax = max(max(l1,l2),max(l3,l4)); | 
|---|
| 68 | if (lmax + 1 > LIBINT_MAX_AM) { | 
|---|
| 69 | ExEnv::errn() << scprintf("libint: the maximum angular momentum of the basis\n"); | 
|---|
| 70 | ExEnv::errn() << scprintf("is too high - need to recompile libint\n"); | 
|---|
| 71 | fail(); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | /*--- Initialize storage ---*/ | 
|---|
| 75 | int max_num_prim_comb = bs1_->max_nprimitive_in_shell()* | 
|---|
| 76 | bs2_->max_nprimitive_in_shell()* | 
|---|
| 77 | bs3_->max_nprimitive_in_shell()* | 
|---|
| 78 | bs4_->max_nprimitive_in_shell(); | 
|---|
| 79 | int max_cart_target_size = bs1_->max_ncartesian_in_shell()*bs2_->max_ncartesian_in_shell()* | 
|---|
| 80 | bs3_->max_ncartesian_in_shell()*bs4_->max_ncartesian_in_shell(); | 
|---|
| 81 | int max_target_size = bs1_->max_nfunction_in_shell()*bs2_->max_nfunction_in_shell()* | 
|---|
| 82 | bs3_->max_nfunction_in_shell()*bs4_->max_nfunction_in_shell(); | 
|---|
| 83 | size_t storage_needed = libint_storage_required(lmax,max_num_prim_comb)*sizeof(REALTYPE) + | 
|---|
| 84 | (max_target_size+max_cart_target_size)*sizeof(double); | 
|---|
| 85 | init_libint(&Libint_,lmax,max_num_prim_comb); | 
|---|
| 86 | target_ints_buffer_ = new double[max_target_size]; | 
|---|
| 87 | cart_ints_ = new double[max_cart_target_size]; | 
|---|
| 88 | if (bs1_->has_pure() || bs2_->has_pure() || bs3_->has_pure() || bs4_->has_pure() || | 
|---|
| 89 | bs1_->max_ncontraction() != 1 || bs2_->max_ncontraction() != 1 || | 
|---|
| 90 | bs3_->max_ncontraction() != 1 || bs4_->max_ncontraction() != 1) { | 
|---|
| 91 | sphharm_ints_ = new double[max_target_size]; | 
|---|
| 92 | storage_needed += max_target_size*sizeof(double); | 
|---|
| 93 | } | 
|---|
| 94 | else { | 
|---|
| 95 | sphharm_ints_ = 0; | 
|---|
| 96 | } | 
|---|
| 97 | if (l1 || l2 || l3 || l4) { | 
|---|
| 98 | perm_ints_ = new double[max_target_size]; | 
|---|
| 99 | storage_needed += max_target_size*sizeof(double); | 
|---|
| 100 | } | 
|---|
| 101 | else | 
|---|
| 102 | perm_ints_ = 0; | 
|---|
| 103 |  | 
|---|
| 104 | // See if can store primitive-pair data | 
|---|
| 105 | size_t primitive_pair_storage_estimate = (bs1_->nprimitive()*bs2_->nprimitive() + | 
|---|
| 106 | bs3_->nprimitive()*bs4_->nprimitive())*sizeof(prim_pair_t); | 
|---|
| 107 | //  ExEnv::errn() << scprintf("need %d bytes to store primitive pair data\n",primitive_pair_storage_estimate); | 
|---|
| 108 | #if STORE_PAIR_DATA | 
|---|
| 109 | shell_pairs12_ = new ShellPairsCints(bs1_,bs2_); | 
|---|
| 110 | if ( (bs1_ == bs3_ && bs2_ == bs4_) /*|| | 
|---|
| 111 | // if this is (ab|ba) case -- should i try to save storage? | 
|---|
| 112 | (bs1_ == bs4_ && bs2_ == bs3_)*/ ) | 
|---|
| 113 | shell_pairs34_ = new ShellPairsCints(shell_pairs12_); | 
|---|
| 114 | else | 
|---|
| 115 | shell_pairs34_ = new ShellPairsCints(bs3_,bs4_); | 
|---|
| 116 | storage_needed += primitive_pair_storage_estimate; | 
|---|
| 117 | #endif | 
|---|
| 118 |  | 
|---|
| 119 | storage_used_ = storage_needed; | 
|---|
| 120 | // Check if storage_ > storage_needed | 
|---|
| 121 | check_storage_(); | 
|---|
| 122 |  | 
|---|
| 123 | int mmax = bs1_->max_angular_momentum() + | 
|---|
| 124 | bs2_->max_angular_momentum() + | 
|---|
| 125 | bs3_->max_angular_momentum() + | 
|---|
| 126 | bs4_->max_angular_momentum(); | 
|---|
| 127 | Fm_Eval_ = new FJT(mmax); | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 | EriCints::~EriCints() | 
|---|
| 132 | { | 
|---|
| 133 | free_libint(&Libint_); | 
|---|
| 134 | delete[] target_ints_buffer_; | 
|---|
| 135 | delete[] cart_ints_; | 
|---|
| 136 | if (sphharm_ints_) | 
|---|
| 137 | delete[] sphharm_ints_; | 
|---|
| 138 | if (perm_ints_) | 
|---|
| 139 | delete[] perm_ints_; | 
|---|
| 140 | #ifdef DMALLOC | 
|---|
| 141 | dmalloc_shutdown(); | 
|---|
| 142 | #endif | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 | size_t | 
|---|
| 146 | EriCints::storage_required(const Ref<GaussianBasisSet>& b1, | 
|---|
| 147 | const Ref<GaussianBasisSet>& b2, | 
|---|
| 148 | const Ref<GaussianBasisSet>& b3, | 
|---|
| 149 | const Ref<GaussianBasisSet>& b4) | 
|---|
| 150 | { | 
|---|
| 151 | Ref<GaussianBasisSet> bs1 = b1; | 
|---|
| 152 | Ref<GaussianBasisSet> bs2 = b2; | 
|---|
| 153 | Ref<GaussianBasisSet> bs3 = b3; | 
|---|
| 154 | Ref<GaussianBasisSet> bs4 = b4; | 
|---|
| 155 |  | 
|---|
| 156 | if (bs2.null()) | 
|---|
| 157 | bs2 = bs1; | 
|---|
| 158 | if (bs3.null()) | 
|---|
| 159 | bs3 = bs1; | 
|---|
| 160 | if (bs4.null()) | 
|---|
| 161 | bs4 = bs1; | 
|---|
| 162 |  | 
|---|
| 163 | int l1 = bs1->max_angular_momentum(); | 
|---|
| 164 | int l2 = bs2->max_angular_momentum(); | 
|---|
| 165 | int l3 = bs3->max_angular_momentum(); | 
|---|
| 166 | int l4 = bs4->max_angular_momentum(); | 
|---|
| 167 | int lmax = max(max(l1,l2),max(l3,l4)); | 
|---|
| 168 |  | 
|---|
| 169 | size_t storage_required = storage_required_(bs1,bs2,bs3,bs4); | 
|---|
| 170 |  | 
|---|
| 171 | int max_num_prim_comb = bs1->max_nprimitive_in_shell()* | 
|---|
| 172 | bs2->max_nprimitive_in_shell()* | 
|---|
| 173 | bs3->max_nprimitive_in_shell()* | 
|---|
| 174 | bs4->max_nprimitive_in_shell(); | 
|---|
| 175 | int max_cart_target_size = bs1->max_ncartesian_in_shell()*bs2->max_ncartesian_in_shell()* | 
|---|
| 176 | bs3->max_ncartesian_in_shell()*bs4->max_ncartesian_in_shell(); | 
|---|
| 177 | int max_target_size = bs1->max_nfunction_in_shell()*bs2->max_nfunction_in_shell()* | 
|---|
| 178 | bs3->max_nfunction_in_shell()*bs4->max_nfunction_in_shell(); | 
|---|
| 179 |  | 
|---|
| 180 | storage_required += libint_storage_required(lmax,max_num_prim_comb)*sizeof(REALTYPE) + | 
|---|
| 181 | (max_target_size+max_cart_target_size)*sizeof(double); | 
|---|
| 182 |  | 
|---|
| 183 | if (bs1->has_pure() || bs2->has_pure() || bs3->has_pure() || bs4->has_pure() || | 
|---|
| 184 | bs1->max_ncontraction() != 1 || bs2->max_ncontraction() != 1 || | 
|---|
| 185 | bs3->max_ncontraction() != 1 || bs4->max_ncontraction() != 1) { | 
|---|
| 186 | storage_required += max_target_size*sizeof(double); | 
|---|
| 187 | } | 
|---|
| 188 |  | 
|---|
| 189 | if (l1 || l2 || l3 || l4) { | 
|---|
| 190 | storage_required += max_target_size*sizeof(double); | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 | // See if can store primitive-pair data | 
|---|
| 194 | size_t primitive_pair_storage_estimate = (bs1->nprimitive()*bs2->nprimitive() + | 
|---|
| 195 | bs3->nprimitive()*bs4->nprimitive())*sizeof(prim_pair_t); | 
|---|
| 196 | #if STORE_PAIR_DATA | 
|---|
| 197 | storage_required += primitive_pair_storage_estimate; | 
|---|
| 198 | #endif | 
|---|
| 199 |  | 
|---|
| 200 | return storage_required; | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 |  | 
|---|
| 204 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 205 |  | 
|---|
| 206 | // Local Variables: | 
|---|
| 207 | // mode: c++ | 
|---|
| 208 | // c-file-style: "CLJ-CONDENSED" | 
|---|
| 209 | // End: | 
|---|