1 | //
|
---|
2 | // int1e.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/int1e.h>
|
---|
33 | #include <chemistry/qc/cints/macros.h>
|
---|
34 |
|
---|
35 | using namespace std;
|
---|
36 | using namespace sc;
|
---|
37 |
|
---|
38 | inline int max(int a,int b) { return (a > b) ? a : b;}
|
---|
39 | inline void fail()
|
---|
40 | {
|
---|
41 | ExEnv::errn() << scprintf("failing module:\n%s",__FILE__) << endl;
|
---|
42 | abort();
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | Int1eCints::Int1eCints(Integral *integral,
|
---|
47 | const Ref<GaussianBasisSet>&b1,
|
---|
48 | const Ref<GaussianBasisSet>&b2,
|
---|
49 | int order, bool need_overlap, bool need_coulomb,
|
---|
50 | int ntypes) :
|
---|
51 | integral_(integral), bs1_(b1), bs2_(b2), multipole_origin_(0),
|
---|
52 | EdotV_origin_(0), Q_origin_(0), need_overlap_(need_overlap),
|
---|
53 | need_coulomb_(need_coulomb), ntypes_(ntypes)
|
---|
54 | {
|
---|
55 | if (order > 0) {
|
---|
56 | // Complain here
|
---|
57 | }
|
---|
58 |
|
---|
59 | max_doublet_size_ = bs1_->max_nfunction_in_shell() * bs2_->max_nfunction_in_shell();
|
---|
60 | target_ints_buffer_ = new double[ntypes_*max_doublet_size_];
|
---|
61 |
|
---|
62 | max_cart_doublet_size_ = bs1_->max_ncartesian_in_shell() * bs2_->max_ncartesian_in_shell();
|
---|
63 | // These are target integrals in Cartesian basis and in by-contraction-doublets order
|
---|
64 | cart_ints_ = new double[ntypes_*max_cart_doublet_size_];
|
---|
65 | if (bs1_->has_pure() || bs2_->has_pure() || bs1_->max_ncontraction() != 1 || bs2_->max_ncontraction() != 1) {
|
---|
66 | // These are target integrals in spherical harmonics basis and in by-contraction-doublets order
|
---|
67 | sphharm_ints_ = new double[ntypes_*max_doublet_size_];
|
---|
68 | // compute how much space one contraction doublet may need
|
---|
69 | int nshell1 = bs1_->nshell();
|
---|
70 | int maxncart1 = 0;
|
---|
71 | for(int sh1=0; sh1<nshell1;sh1++) {
|
---|
72 | int maxncart = bs1_->shell(sh1).max_cartesian();
|
---|
73 | if (maxncart > maxncart1) maxncart1 = maxncart;
|
---|
74 | }
|
---|
75 | int nshell2 = bs2_->nshell();
|
---|
76 | int maxncart2 = 0;
|
---|
77 | for(int sh2=0; sh2<nshell2;sh2++) {
|
---|
78 | int maxncart = bs2_->shell(sh2).max_cartesian();
|
---|
79 | if (maxncart > maxncart2) maxncart2 = maxncart;
|
---|
80 | }
|
---|
81 | tformbuf_ = new double[ntypes_*maxncart1*maxncart2];
|
---|
82 | }
|
---|
83 | else {
|
---|
84 | sphharm_ints_ = 0;
|
---|
85 | tformbuf_ = 0;
|
---|
86 | }
|
---|
87 |
|
---|
88 | int max_am = max(bs1_->max_angular_momentum(),bs2_->max_angular_momentum());
|
---|
89 | if (need_overlap_) {
|
---|
90 | // Allocate OIXYZ
|
---|
91 | // max_am+1 - the range of exponents of x, y, and z
|
---|
92 | // 2 - to get kinetic energy integrals
|
---|
93 | // order - to allow for derivatives
|
---|
94 | OIX_ = init_block_(max_am+1+2+order,max_am+1+2+order);
|
---|
95 | OIY_ = init_block_(max_am+1+2+order,max_am+1+2+order);
|
---|
96 | OIZ_ = init_block_(max_am+1+2+order,max_am+1+2+order);
|
---|
97 | }
|
---|
98 |
|
---|
99 | if (need_coulomb_) {
|
---|
100 | Fm_Eval_ = new FJT(bs1_->max_angular_momentum() + bs2_->max_angular_momentum() + order);
|
---|
101 | indmax_ = (max_am+order)*(max_am+1+order)*(max_am+1+order)+1;
|
---|
102 | // Allocate AI0
|
---|
103 | AI0_ = init_box_(indmax_,indmax_,2*(max_am+order)+1);
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | Int1eCints::~Int1eCints()
|
---|
108 | {
|
---|
109 | delete[] cart_ints_;
|
---|
110 | if (sphharm_ints_) {
|
---|
111 | delete[] sphharm_ints_;
|
---|
112 | sphharm_ints_ = 0;
|
---|
113 | }
|
---|
114 | if (tformbuf_) {
|
---|
115 | delete[] tformbuf_;
|
---|
116 | tformbuf_ = 0;
|
---|
117 | }
|
---|
118 | if (need_coulomb_) {
|
---|
119 | free_box_(AI0_);
|
---|
120 | }
|
---|
121 | if (need_overlap_) {
|
---|
122 | free_block_(OIX_);
|
---|
123 | free_block_(OIY_);
|
---|
124 | free_block_(OIZ_);
|
---|
125 | }
|
---|
126 | delete[] target_ints_buffer_;
|
---|
127 | }
|
---|
128 |
|
---|
129 | void Int1eCints::set_multipole_origin(const Ref<DipoleData>& origin)
|
---|
130 | {
|
---|
131 | multipole_origin_ = origin;
|
---|
132 | }
|
---|
133 |
|
---|
134 | void Int1eCints::set_EdotV_origin(const Ref<EfieldDotVectorData>& origin)
|
---|
135 | {
|
---|
136 | EdotV_origin_ = origin;
|
---|
137 | }
|
---|
138 |
|
---|
139 | void Int1eCints::set_Q_origin(const Ref<PointChargeData>& origin)
|
---|
140 | {
|
---|
141 | Q_origin_ = origin;
|
---|
142 | }
|
---|
143 |
|
---|
144 | Ref<DipoleData>
|
---|
145 | Int1eCints::multipole_origin()
|
---|
146 | {
|
---|
147 | return multipole_origin_;
|
---|
148 | }
|
---|
149 |
|
---|
150 | Ref<EfieldDotVectorData>
|
---|
151 | Int1eCints::EdotV_origin()
|
---|
152 | {
|
---|
153 | return EdotV_origin_;
|
---|
154 | }
|
---|
155 |
|
---|
156 | Ref<PointChargeData>
|
---|
157 | Int1eCints::Q_origin()
|
---|
158 | {
|
---|
159 | return Q_origin_;
|
---|
160 | }
|
---|
161 |
|
---|
162 | void Int1eCints::zero_buffers_()
|
---|
163 | {
|
---|
164 | double *buf1 = cart_ints_;
|
---|
165 | for(int i=0; i<max_cart_doublet_size_; i++,buf1++) {
|
---|
166 | *buf1 = 0.0;
|
---|
167 | }
|
---|
168 | buf1 = target_ints_buffer_;
|
---|
169 | for(int i=0; i<max_doublet_size_; i++,buf1++) {
|
---|
170 | *buf1 = 0.0;
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | void Int1eCints::compute_doublet_info_(int sh1, int sh2)
|
---|
175 | {
|
---|
176 | int_shell1_ = &bs1_->shell(sh1);
|
---|
177 | int_shell2_ = &bs2_->shell(sh2);
|
---|
178 | int ctr1 = bs1_->shell_to_center(sh1);
|
---|
179 | int ctr2 = bs2_->shell_to_center(sh2);
|
---|
180 | doublet_info_.AB2 = 0.0;
|
---|
181 | for(int i=0; i<3; i++) {
|
---|
182 | doublet_info_.A[i] = bs1_->r(ctr1,i);
|
---|
183 | doublet_info_.B[i] = bs2_->r(ctr2,i);
|
---|
184 | doublet_info_.AB2 += (doublet_info_.A[i] - doublet_info_.B[i])*
|
---|
185 | (doublet_info_.A[i] - doublet_info_.B[i]);
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | void Int1eCints::sort_contrdoublets_to_shelldoublet_(double *source, double *target)
|
---|
190 | {
|
---|
191 | /*--- sort to the target ordering ---*/
|
---|
192 | double *source_ints_buf = source;
|
---|
193 | double *target_ints_buf = target;
|
---|
194 | int target_bf1_offset = 0;
|
---|
195 | int nbf2 = int_shell2_->nfunction();
|
---|
196 | for (int gc1=0; gc1<int_shell1_->ncontraction(); gc1++) {
|
---|
197 | int am1 = int_shell1_->am(gc1);
|
---|
198 | int tsize1 = int_shell1_->nfunction(gc1);
|
---|
199 | int target_bf2_offset = 0;
|
---|
200 | for (int gc2=0; gc2<int_shell2_->ncontraction(); gc2++) {
|
---|
201 | int am2 = int_shell2_->am(gc2);
|
---|
202 | int tsize2 = int_shell2_->nfunction(gc2);
|
---|
203 |
|
---|
204 | for(int bf1=0;bf1<tsize1;bf1++) {
|
---|
205 | double *target_ints_buf = target_ints_buffer_ + (target_bf1_offset+bf1)*nbf2 +
|
---|
206 | target_bf2_offset;
|
---|
207 | for(int bf2=0;bf2<tsize2;bf2++) {
|
---|
208 | *(target_ints_buf++) = *(source_ints_buf++);
|
---|
209 | }
|
---|
210 | }
|
---|
211 | target_bf2_offset += tsize2;
|
---|
212 | }
|
---|
213 | target_bf1_offset += tsize1;
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | void Int1eCints::zero_buffers_vec_(const int ntypes)
|
---|
218 | {
|
---|
219 | double *buf1 = cart_ints_;
|
---|
220 | const int ncints = ntypes * max_cart_doublet_size_;
|
---|
221 | for(int i=0; i<ncints; i++,buf1++) {
|
---|
222 | *buf1 = 0.0;
|
---|
223 | }
|
---|
224 | buf1 = target_ints_buffer_;
|
---|
225 | const int nints = ntypes * max_doublet_size_;
|
---|
226 | for(int i=0; i<nints; i++,buf1++) {
|
---|
227 | *buf1 = 0.0;
|
---|
228 | }
|
---|
229 | }
|
---|
230 |
|
---|
231 | void Int1eCints::sort_contrdoublets_to_shelldoublet_vec_(const int ntypes, double *source, double *target)
|
---|
232 | {
|
---|
233 | /*--- sort to the target ordering ---*/
|
---|
234 | double *source_ints_buf = source;
|
---|
235 | double *target_ints_buf = target;
|
---|
236 | int target_bf1_offset = 0;
|
---|
237 | int nbf2 = int_shell2_->nfunction();
|
---|
238 | for (int gc1=0; gc1<int_shell1_->ncontraction(); gc1++) {
|
---|
239 | int am1 = int_shell1_->am(gc1);
|
---|
240 | int tsize1 = int_shell1_->nfunction(gc1);
|
---|
241 | int target_bf2_offset = 0;
|
---|
242 | for (int gc2=0; gc2<int_shell2_->ncontraction(); gc2++) {
|
---|
243 | int am2 = int_shell2_->am(gc2);
|
---|
244 | int tsize2 = int_shell2_->nfunction(gc2);
|
---|
245 |
|
---|
246 | for(int bf1=0;bf1<tsize1;bf1++) {
|
---|
247 | double *target_ints_buf = target_ints_buffer_ + ((target_bf1_offset+bf1)*nbf2 +
|
---|
248 | target_bf2_offset)*ntypes;
|
---|
249 | for(int bf2=0;bf2<tsize2;bf2++) {
|
---|
250 | for(int type=0; type<ntypes; type++)
|
---|
251 | *(target_ints_buf++) = *(source_ints_buf++);
|
---|
252 | }
|
---|
253 | }
|
---|
254 | target_bf2_offset += tsize2;
|
---|
255 | }
|
---|
256 | target_bf1_offset += tsize1;
|
---|
257 | }
|
---|
258 | }
|
---|
259 |
|
---|
260 | double **Int1eCints::init_block_(int a, int b)
|
---|
261 | {
|
---|
262 | double **block = new double*[a];
|
---|
263 | block[0] = new double[a*b];
|
---|
264 | for(int i=1; i<a; i++)
|
---|
265 | block[i] = block[i-1] + b;
|
---|
266 |
|
---|
267 | return block;
|
---|
268 | }
|
---|
269 |
|
---|
270 | void Int1eCints::free_block_(double **block)
|
---|
271 | {
|
---|
272 | delete[] block[0];
|
---|
273 | delete[] block;
|
---|
274 | }
|
---|
275 |
|
---|
276 | double ***Int1eCints::init_box_(int a, int b, int c)
|
---|
277 | {
|
---|
278 | int i,j;
|
---|
279 |
|
---|
280 | double ***box = new double**[a];
|
---|
281 | box[0] = new double*[a*b];
|
---|
282 | for(i=1; i<a; i++)
|
---|
283 | box[i] = box[i-1] + b;
|
---|
284 |
|
---|
285 | box[0][0] = new double[a*b*c];
|
---|
286 | for(j=1; j<b; j++)
|
---|
287 | box[0][j] = box[0][j-1] + c;
|
---|
288 | for(i=1; i<a; i++) {
|
---|
289 | box[i][0] = box[i-1][b-1] + c;
|
---|
290 | for(j=1; j<b; j++)
|
---|
291 | box[i][j] = box[i][j-1] + c;
|
---|
292 | }
|
---|
293 |
|
---|
294 | return box;
|
---|
295 | }
|
---|
296 |
|
---|
297 | void Int1eCints::free_box_(double ***box)
|
---|
298 | {
|
---|
299 | delete[] box[0][0];
|
---|
300 | delete[] box[0];
|
---|
301 | delete[] box;
|
---|
302 | }
|
---|
303 |
|
---|
304 |
|
---|
305 | /////////////////////////////////////////////////////////////////////////////
|
---|
306 |
|
---|
307 | // Local Variables:
|
---|
308 | // mode: c++
|
---|
309 | // c-file-style: "CLJ"
|
---|
310 | // End:
|
---|