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