1 | //
|
---|
2 | // ebc_contribs.cc
|
---|
3 | //
|
---|
4 | // Copyright (C) 2004 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 | #include <stdexcept>
|
---|
29 | #include <stdlib.h>
|
---|
30 | #include <string.h>
|
---|
31 | #include <math.h>
|
---|
32 | #include <limits.h>
|
---|
33 |
|
---|
34 | #include <scconfig.h>
|
---|
35 | #include <util/misc/formio.h>
|
---|
36 | #include <util/misc/timer.h>
|
---|
37 | #include <util/class/class.h>
|
---|
38 | #include <util/state/state.h>
|
---|
39 | #include <util/state/state_text.h>
|
---|
40 | #include <util/state/state_bin.h>
|
---|
41 | #include <math/scmat/matrix.h>
|
---|
42 | #include <chemistry/molecule/molecule.h>
|
---|
43 | #include <chemistry/qc/basis/integral.h>
|
---|
44 | #include <chemistry/qc/mbptr12/blas.h>
|
---|
45 | #include <chemistry/qc/mbptr12/r12ia.h>
|
---|
46 | #include <chemistry/qc/mbptr12/vxb_eval_info.h>
|
---|
47 | #include <chemistry/qc/mbptr12/pairiter.h>
|
---|
48 | #include <chemistry/qc/mbptr12/r12int_eval.h>
|
---|
49 | #include <chemistry/qc/mbptr12/print_scmat_norms.h>
|
---|
50 |
|
---|
51 | using namespace std;
|
---|
52 | using namespace sc;
|
---|
53 |
|
---|
54 | #define TEST_T2 0
|
---|
55 | #define TEST_A 0
|
---|
56 | // if set to 1 then use f+k rather than f to compute A
|
---|
57 | #define A_DIRECT_EXCLUDE_K 0
|
---|
58 |
|
---|
59 | //
|
---|
60 | // these are for testing purposes only
|
---|
61 | //
|
---|
62 | // use the commutator form A
|
---|
63 | #define USE_A_COMM_IN_B_EBC 0
|
---|
64 | #define ACOMM_INCLUDE_TR_ONLY 0
|
---|
65 | #define ACOMM_INCLUDE_R_ONLY 0
|
---|
66 |
|
---|
67 | void
|
---|
68 | R12IntEval::compute_T2_()
|
---|
69 | {
|
---|
70 | if (evaluated_)
|
---|
71 | return;
|
---|
72 |
|
---|
73 | Ref<TwoBodyMOIntsTransform> ipjq_tform = get_tform_("(ip|jq)");
|
---|
74 | Ref<R12IntsAcc> ijpq_acc = ipjq_tform->ints_acc();
|
---|
75 | if (!ijpq_acc->is_committed())
|
---|
76 | ipjq_tform->compute();
|
---|
77 | if (!ijpq_acc->is_active())
|
---|
78 | ijpq_acc->activate();
|
---|
79 |
|
---|
80 | tim_enter("mp2 t2 amplitudes");
|
---|
81 |
|
---|
82 | ExEnv::out0() << endl << indent
|
---|
83 | << "Entered MP2 T2 amplitude evaluator" << endl;
|
---|
84 | ExEnv::out0() << incindent;
|
---|
85 |
|
---|
86 | Ref<MessageGrp> msg = r12info_->msg();
|
---|
87 | int me = msg->me();
|
---|
88 | int nproc = msg->n();
|
---|
89 |
|
---|
90 | const int noso = r12info_->mo_space()->rank();
|
---|
91 | const int nocc = r12info_->nocc();
|
---|
92 | const int nfzv = r12info_->nfzv();
|
---|
93 | Ref<MOIndexSpace> mo_space = r12info_->obs_space();
|
---|
94 | Ref<MOIndexSpace> act_occ_space = r12info_->act_occ_space();
|
---|
95 | Ref<MOIndexSpace> act_vir_space = r12info_->act_vir_space();
|
---|
96 |
|
---|
97 | SpatialMOPairIter_eq ij_iter(act_occ_space);
|
---|
98 | SpatialMOPairIter_eq ab_iter(act_vir_space);
|
---|
99 | int naa = ij_iter.nij_aa(); // Number of alpha-alpha pairs (i > j)
|
---|
100 | int nab = ij_iter.nij_ab(); // Number of alpha-beta pairs
|
---|
101 | if (debug_) {
|
---|
102 | ExEnv::out0() << indent << "naa = " << naa << endl;
|
---|
103 | ExEnv::out0() << indent << "nab = " << nab << endl;
|
---|
104 | }
|
---|
105 |
|
---|
106 | // Compute the number of tasks that have full access to the integrals
|
---|
107 | // and split the work among them
|
---|
108 | vector<int> proc_with_ints;
|
---|
109 | int nproc_with_ints = tasks_with_ints_(ijpq_acc,proc_with_ints);
|
---|
110 |
|
---|
111 | //////////////////////////////////////////////////////////////
|
---|
112 | //
|
---|
113 | // Evaluation of the MP2 T2 amplitudes proceeds as follows:
|
---|
114 | //
|
---|
115 | // loop over batches of ij,
|
---|
116 | // load (ijxy)=(ix|jy) into memory
|
---|
117 | //
|
---|
118 | // loop over xy, 0<=x<nvir_act, 0<=y<nvir_act
|
---|
119 | // compute T2_aa[ij][xy] = [ (ijxy) - (ijyx) ] / denom
|
---|
120 | // compute T2_ab[ij][xy] = [ (ijxy) ] / denom
|
---|
121 | // end xy loop
|
---|
122 | // end ij loop
|
---|
123 | //
|
---|
124 | /////////////////////////////////////////////////////////////////////////////////
|
---|
125 |
|
---|
126 | for(ij_iter.start();int(ij_iter);ij_iter.next()) {
|
---|
127 |
|
---|
128 | const int ij = ij_iter.ij();
|
---|
129 | // Figure out if this task will handle this ij
|
---|
130 | int ij_proc = ij%nproc_with_ints;
|
---|
131 | if (ij_proc != proc_with_ints[me])
|
---|
132 | continue;
|
---|
133 | const int i = ij_iter.i();
|
---|
134 | const int j = ij_iter.j();
|
---|
135 | const int ij_aa = ij_iter.ij_aa();
|
---|
136 | const int ij_ab = ij_iter.ij_ab();
|
---|
137 | const int ji_ab = ij_iter.ij_ba();
|
---|
138 |
|
---|
139 | if (debug_)
|
---|
140 | ExEnv::outn() << indent << "task " << me << ": working on (i,j) = " << i << "," << j << " " << endl;
|
---|
141 |
|
---|
142 | // Get (|1/r12|) integrals
|
---|
143 | tim_enter("MO ints retrieve");
|
---|
144 | double *ijxy_buf_eri = ijpq_acc->retrieve_pair_block(i,j,R12IntsAcc::eri);
|
---|
145 | tim_exit("MO ints retrieve");
|
---|
146 |
|
---|
147 | if (debug_)
|
---|
148 | ExEnv::outn() << indent << "task " << me << ": obtained ij blocks" << endl;
|
---|
149 |
|
---|
150 | // Compute MP2 energies
|
---|
151 | RefDiagSCMatrix act_occ_evals = r12info_->act_occ_space()->evals();
|
---|
152 | RefDiagSCMatrix all_evals = r12info_->obs_space()->evals();
|
---|
153 | double T2_aa_ijab = 0.0;
|
---|
154 | double T2_ab_ijab = 0.0;
|
---|
155 |
|
---|
156 | for(ab_iter.start();int(ab_iter);ab_iter.next()) {
|
---|
157 |
|
---|
158 | const int a = ab_iter.i();
|
---|
159 | const int b = ab_iter.j();
|
---|
160 | const int ab_aa = ab_iter.ij_aa();
|
---|
161 | const int ab_ab = ab_iter.ij_ab();
|
---|
162 | const int ba_ab = ab_iter.ij_ba();
|
---|
163 |
|
---|
164 | const int aa = a + nocc;
|
---|
165 | const int bb = b + nocc;
|
---|
166 |
|
---|
167 | const int ab_offset = aa*noso+bb;
|
---|
168 | const int ba_offset = bb*noso+aa;
|
---|
169 | #if TEST_T2
|
---|
170 | const double oo_delta_ijab = -1.0/sqrt(-act_occ_evals(i)-act_occ_evals(j)+all_evals(aa)+all_evals(bb));
|
---|
171 | #else
|
---|
172 | const double oo_delta_ijab = -1.0/(-act_occ_evals(i)-act_occ_evals(j)+all_evals(aa)+all_evals(bb));
|
---|
173 | #endif
|
---|
174 | const double eri_iajb = ijxy_buf_eri[ab_offset];
|
---|
175 | const double eri_ibja = ijxy_buf_eri[ba_offset];
|
---|
176 | const double T2_ab_ijab = eri_iajb * oo_delta_ijab;
|
---|
177 | const double T2_ab_ijba = eri_ibja * oo_delta_ijab;
|
---|
178 | T2ab_.set_element(ij_ab,ab_ab,T2_ab_ijab);
|
---|
179 | T2ab_.set_element(ji_ab,ba_ab,T2_ab_ijab);
|
---|
180 | T2ab_.set_element(ji_ab,ab_ab,T2_ab_ijba);
|
---|
181 | T2ab_.set_element(ij_ab,ba_ab,T2_ab_ijba);
|
---|
182 |
|
---|
183 | if (ij_aa != -1 && ab_aa != -1) {
|
---|
184 | const double T2_aa_ijab = (eri_iajb - eri_ibja) * oo_delta_ijab;
|
---|
185 | T2aa_.set_element(ij_aa,ab_aa,T2_aa_ijab);
|
---|
186 | }
|
---|
187 |
|
---|
188 | }
|
---|
189 |
|
---|
190 | ijpq_acc->release_pair_block(i,j,R12IntsAcc::eri);
|
---|
191 | }
|
---|
192 |
|
---|
193 | globally_sum_intermeds_();
|
---|
194 |
|
---|
195 | #if TEST_T2
|
---|
196 | // As a test -- compute MP2 energies
|
---|
197 | RefSCMatrix emp2pair_aa = T2aa_*T2aa_.t();
|
---|
198 | RefSCMatrix emp2pair_ab = T2ab_*T2ab_.t();
|
---|
199 | emp2pair_aa.scale(-2.0);
|
---|
200 | emp2pair_ab.scale(-1.0);
|
---|
201 | emp2pair_aa.print("Alpha-alpha MP2 energies");
|
---|
202 | emp2pair_ab.print("Alpha-beta MP2 energies");
|
---|
203 | #endif
|
---|
204 |
|
---|
205 | ExEnv::out0() << decindent;
|
---|
206 | ExEnv::out0() << indent << "Exited MP2 T2 amplitude evaluator" << endl;
|
---|
207 |
|
---|
208 | tim_exit("mp2 t2 amplitudes");
|
---|
209 | }
|
---|
210 |
|
---|
211 |
|
---|
212 | void
|
---|
213 | R12IntEval::compute_R_()
|
---|
214 | {
|
---|
215 | if (evaluated_)
|
---|
216 | return;
|
---|
217 |
|
---|
218 | // This functions assumes that virtuals are expanded in the same basis
|
---|
219 | // as the occupied orbitals
|
---|
220 | if (!r12info_->basis_vir()->equiv(r12info_->basis()))
|
---|
221 | throw std::runtime_error("R12IntEval::compute_R_() -- should not be called when the basis set for virtuals \
|
---|
222 | differs from the basis set for occupieds");
|
---|
223 |
|
---|
224 | Ref<TwoBodyMOIntsTransform> ipjq_tform = get_tform_("(ip|jq)");
|
---|
225 | Ref<R12IntsAcc> ijpq_acc = ipjq_tform->ints_acc();
|
---|
226 | if (!ijpq_acc->is_committed())
|
---|
227 | ipjq_tform->compute();
|
---|
228 | if (!ijpq_acc->is_active())
|
---|
229 | ijpq_acc->activate();
|
---|
230 |
|
---|
231 | tim_enter("R intermediate");
|
---|
232 |
|
---|
233 | Ref<MessageGrp> msg = r12info_->msg();
|
---|
234 | int me = msg->me();
|
---|
235 | int nproc = msg->n();
|
---|
236 | ExEnv::out0() << endl << indent
|
---|
237 | << "Entered R amplitude evaluator" << endl;
|
---|
238 | ExEnv::out0() << incindent;
|
---|
239 |
|
---|
240 | const int noso = r12info_->mo_space()->rank();
|
---|
241 | const int nocc = r12info_->nocc();
|
---|
242 | const int nfzv = r12info_->nfzv();
|
---|
243 | Ref<MOIndexSpace> mo_space = r12info_->obs_space();
|
---|
244 | Ref<MOIndexSpace> act_occ_space = r12info_->act_occ_space();
|
---|
245 | Ref<MOIndexSpace> act_vir_space = r12info_->act_vir_space();
|
---|
246 |
|
---|
247 | SpatialMOPairIter_eq ij_iter(act_occ_space);
|
---|
248 | SpatialMOPairIter_eq ab_iter(act_vir_space);
|
---|
249 | int naa = ij_iter.nij_aa(); // Number of alpha-alpha pairs (i > j)
|
---|
250 | int nab = ij_iter.nij_ab(); // Number of alpha-beta pairs
|
---|
251 | if (debug_) {
|
---|
252 | ExEnv::out0() << indent << "naa = " << naa << endl;
|
---|
253 | ExEnv::out0() << indent << "nab = " << nab << endl;
|
---|
254 | }
|
---|
255 |
|
---|
256 | // Compute the number of tasks that have full access to the integrals
|
---|
257 | // and split the work among them
|
---|
258 | vector<int> proc_with_ints;
|
---|
259 | int nproc_with_ints = tasks_with_ints_(ijpq_acc,proc_with_ints);
|
---|
260 |
|
---|
261 | for(ij_iter.start();int(ij_iter);ij_iter.next()) {
|
---|
262 |
|
---|
263 | const int ij = ij_iter.ij();
|
---|
264 | // Figure out if this task will handle this ij
|
---|
265 | int ij_proc = ij%nproc_with_ints;
|
---|
266 | if (ij_proc != proc_with_ints[me])
|
---|
267 | continue;
|
---|
268 | const int i = ij_iter.i();
|
---|
269 | const int j = ij_iter.j();
|
---|
270 | const int ij_aa = ij_iter.ij_aa();
|
---|
271 | const int ij_ab = ij_iter.ij_ab();
|
---|
272 | const int ji_ab = ij_iter.ij_ba();
|
---|
273 |
|
---|
274 | if (debug_)
|
---|
275 | ExEnv::outn() << indent << "task " << me << ": working on (i,j) = " << i << "," << j << " " << endl;
|
---|
276 |
|
---|
277 | // Get (|1/r12|) integrals
|
---|
278 | tim_enter("MO ints retrieve");
|
---|
279 | double *ijxy_buf_r12 = ijpq_acc->retrieve_pair_block(i,j,R12IntsAcc::r12);
|
---|
280 | tim_exit("MO ints retrieve");
|
---|
281 |
|
---|
282 | if (debug_)
|
---|
283 | ExEnv::outn() << indent << "task " << me << ": obtained ij blocks" << endl;
|
---|
284 |
|
---|
285 | // Compute MP2 energies
|
---|
286 | RefDiagSCMatrix act_occ_evals = r12info_->act_occ_space()->evals();
|
---|
287 | RefDiagSCMatrix all_evals = r12info_->obs_space()->evals();
|
---|
288 | double R_aa_ijab = 0.0;
|
---|
289 | double R_ab_ijab = 0.0;
|
---|
290 |
|
---|
291 | for(ab_iter.start();int(ab_iter);ab_iter.next()) {
|
---|
292 |
|
---|
293 | const int a = ab_iter.i();
|
---|
294 | const int b = ab_iter.j();
|
---|
295 | const int ab_aa = ab_iter.ij_aa();
|
---|
296 | const int ab_ab = ab_iter.ij_ab();
|
---|
297 | const int ba_ab = ab_iter.ij_ba();
|
---|
298 |
|
---|
299 | const int aa = a + nocc;
|
---|
300 | const int bb = b + nocc;
|
---|
301 |
|
---|
302 | const int ab_offset = aa*noso+bb;
|
---|
303 | const int ba_offset = bb*noso+aa;
|
---|
304 | const double r12_iajb = ijxy_buf_r12[ab_offset];
|
---|
305 | const double r12_ibja = ijxy_buf_r12[ba_offset];
|
---|
306 | Rab_.set_element(ij_ab,ab_ab,r12_iajb);
|
---|
307 | Rab_.set_element(ji_ab,ba_ab,r12_iajb);
|
---|
308 | Rab_.set_element(ji_ab,ab_ab,r12_ibja);
|
---|
309 | Rab_.set_element(ij_ab,ba_ab,r12_ibja);
|
---|
310 |
|
---|
311 | if (ij_aa != -1 && ab_aa != -1) {
|
---|
312 | const double R_aa_ijab = (r12_iajb - r12_ibja);
|
---|
313 | Raa_.set_element(ij_aa,ab_aa,R_aa_ijab);
|
---|
314 | }
|
---|
315 |
|
---|
316 | }
|
---|
317 |
|
---|
318 | ijpq_acc->release_pair_block(i,j,R12IntsAcc::r12);
|
---|
319 | }
|
---|
320 |
|
---|
321 | globally_sum_intermeds_();
|
---|
322 |
|
---|
323 | ExEnv::out0() << decindent;
|
---|
324 | ExEnv::out0() << indent << "Exited R amplitude evaluator" << endl;
|
---|
325 |
|
---|
326 | tim_exit("R intermediate");
|
---|
327 | }
|
---|
328 |
|
---|
329 |
|
---|
330 | void
|
---|
331 | R12IntEval::compute_A_simple_()
|
---|
332 | {
|
---|
333 | if (abs_method_ == LinearR12::ABS_ABS || abs_method_ == LinearR12::ABS_ABSPlus)
|
---|
334 | throw std::runtime_error("R12IntEval::compute_A_simple_() -- A intermediate can only be computed using a CABS (or CABS+) approach");
|
---|
335 |
|
---|
336 | if (evaluated_)
|
---|
337 | return;
|
---|
338 |
|
---|
339 | tim_enter("A intermediate");
|
---|
340 |
|
---|
341 | const int num_te_types = 2;
|
---|
342 |
|
---|
343 | Ref<MessageGrp> msg = r12info_->msg();
|
---|
344 | int me = msg->me();
|
---|
345 | int nproc = msg->n();
|
---|
346 | ExEnv::out0() << endl << indent
|
---|
347 | << "Entered A intermediate evaluator" << endl;
|
---|
348 | ExEnv::out0() << incindent;
|
---|
349 |
|
---|
350 | const int noso = r12info_->mo_space()->rank();
|
---|
351 | const int nocc = r12info_->nocc();
|
---|
352 | const int nfzv = r12info_->nfzv();
|
---|
353 | const int nvir_act = noso - nocc - nfzv;
|
---|
354 | Ref<MOIndexSpace> act_occ_space = r12info_->act_occ_space();
|
---|
355 | Ref<MOIndexSpace> mo_space = r12info_->obs_space();
|
---|
356 | Ref<MOIndexSpace> act_vir_space = r12info_->act_vir_space();
|
---|
357 |
|
---|
358 | // compute the Fock matrix between the complement and virtuals and
|
---|
359 | // create the new Fock-weighted space
|
---|
360 | Ref<MOIndexSpace> ribs_space = r12info_->ribs_space();
|
---|
361 | #if A_DIRECT_EXCLUDE_K
|
---|
362 | RefSCMatrix F_ri_v = fock_(r12info_->occ_space(),ribs_space,act_vir_space,1.0,0.0);
|
---|
363 | #else
|
---|
364 | RefSCMatrix F_ri_v = fock_(r12info_->occ_space(),ribs_space,act_vir_space);
|
---|
365 | #endif
|
---|
366 | if (debug_ > 1)
|
---|
367 | F_ri_v.print("Fock matrix (RI-BS/act.virt.)");
|
---|
368 | if (debug_ > 0)
|
---|
369 | print_scmat_norms(F_ri_v,"Fock matrix (RI-BS/act.virt.)");
|
---|
370 |
|
---|
371 | Ref<MOIndexSpace> act_fvir_space = new MOIndexSpace("Fock-weighted active unoccupied MOs sorted by energy",
|
---|
372 | act_vir_space, ribs_space->coefs()*F_ri_v, ribs_space->basis());
|
---|
373 |
|
---|
374 | // Do the AO->MO transform
|
---|
375 | Ref<MOIntsTransformFactory> tfactory = r12info_->tfactory();
|
---|
376 | tfactory->set_spaces(act_occ_space,act_vir_space,
|
---|
377 | act_occ_space,act_fvir_space);
|
---|
378 | Ref<TwoBodyMOIntsTransform> iajBf_tform = tfactory->twobody_transform_13("(ia|jB_f)");
|
---|
379 | iajBf_tform->set_num_te_types(num_te_types);
|
---|
380 | iajBf_tform->compute();
|
---|
381 | Ref<R12IntsAcc> ijaBf_acc = iajBf_tform->ints_acc();
|
---|
382 |
|
---|
383 | SpatialMOPairIter_eq ij_iter(act_occ_space);
|
---|
384 | SpatialMOPairIter_eq ab_iter(act_vir_space);
|
---|
385 | int naa = ij_iter.nij_aa(); // Number of alpha-alpha pairs (i > j)
|
---|
386 | int nab = ij_iter.nij_ab(); // Number of alpha-beta pairs
|
---|
387 | if (debug_) {
|
---|
388 | ExEnv::out0() << indent << "naa = " << naa << endl;
|
---|
389 | ExEnv::out0() << indent << "nab = " << nab << endl;
|
---|
390 | }
|
---|
391 |
|
---|
392 | // Compute the number of tasks that have full access to the integrals
|
---|
393 | // and split the work among them
|
---|
394 | vector<int> proc_with_ints;
|
---|
395 | int nproc_with_ints = tasks_with_ints_(ijaBf_acc,proc_with_ints);
|
---|
396 |
|
---|
397 | //////////////////////////////////////////////////////////////
|
---|
398 | //
|
---|
399 | // Evaluation of A intermedates proceeds as follows:
|
---|
400 | //
|
---|
401 | // loop over batches of ij,
|
---|
402 | // load (ijxy)=(ix|jy) into memory
|
---|
403 | //
|
---|
404 | // loop over xy, 0<=x<nvir_act, 0<=y<nvir_act
|
---|
405 | // compute T2_aa[ij][xy] = [ (ijxy) - (ijyx) ] / denom
|
---|
406 | // compute T2_ab[ij][xy] = [ (ijxy) ] / denom
|
---|
407 | // end xy loop
|
---|
408 | // end ij loop
|
---|
409 | //
|
---|
410 | /////////////////////////////////////////////////////////////////////////////////
|
---|
411 |
|
---|
412 | for(ij_iter.start();int(ij_iter);ij_iter.next()) {
|
---|
413 |
|
---|
414 | const int ij = ij_iter.ij();
|
---|
415 | // Figure out if this task will handle this ij
|
---|
416 | int ij_proc = ij%nproc_with_ints;
|
---|
417 | if (ij_proc != proc_with_ints[me])
|
---|
418 | continue;
|
---|
419 | const int i = ij_iter.i();
|
---|
420 | const int j = ij_iter.j();
|
---|
421 | const int ij_aa = ij_iter.ij_aa();
|
---|
422 | const int ij_ab = ij_iter.ij_ab();
|
---|
423 | const int ji_ab = ij_iter.ij_ba();
|
---|
424 |
|
---|
425 | if (debug_)
|
---|
426 | ExEnv::outn() << indent << "task " << me << ": working on (i,j) = " << i << "," << j << " " << endl;
|
---|
427 |
|
---|
428 | // Get (|r12|) integrals
|
---|
429 | tim_enter("MO ints retrieve");
|
---|
430 | double *ijaBf_buf_r12 = ijaBf_acc->retrieve_pair_block(i,j,R12IntsAcc::r12);
|
---|
431 | double *jiaBf_buf_r12 = ijaBf_acc->retrieve_pair_block(j,i,R12IntsAcc::r12);
|
---|
432 | tim_exit("MO ints retrieve");
|
---|
433 |
|
---|
434 | if (debug_)
|
---|
435 | ExEnv::outn() << indent << "task " << me << ": obtained ij blocks" << endl;
|
---|
436 |
|
---|
437 | // Compute contributions to A
|
---|
438 | for(ab_iter.start();int(ab_iter);ab_iter.next()) {
|
---|
439 |
|
---|
440 | const int a = ab_iter.i();
|
---|
441 | const int b = ab_iter.j();
|
---|
442 | const int ab_aa = ab_iter.ij_aa();
|
---|
443 | const int ab_ab = ab_iter.ij_ab();
|
---|
444 | const int ba_ab = ab_iter.ij_ba();
|
---|
445 |
|
---|
446 | const int ab_offset = a*nvir_act+b;
|
---|
447 | const int ba_offset = b*nvir_act+a;
|
---|
448 |
|
---|
449 | const double r12_iajBf = ijaBf_buf_r12[ab_offset];
|
---|
450 | const double r12_jaiBf = jiaBf_buf_r12[ab_offset];
|
---|
451 | const double r12_ibjAf = ijaBf_buf_r12[ba_offset];
|
---|
452 | const double r12_jbiAf = jiaBf_buf_r12[ba_offset];
|
---|
453 |
|
---|
454 | const double A_ab_ijab = 0.5*(r12_jbiAf + r12_iajBf);
|
---|
455 | const double A_ab_ijba = 0.5*(r12_ibjAf + r12_jaiBf);
|
---|
456 | Aab_.set_element(ij_ab,ab_ab,A_ab_ijab);
|
---|
457 | Aab_.set_element(ji_ab,ba_ab,A_ab_ijab);
|
---|
458 | Aab_.set_element(ji_ab,ab_ab,A_ab_ijba);
|
---|
459 | Aab_.set_element(ij_ab,ba_ab,A_ab_ijba);
|
---|
460 |
|
---|
461 | if (ij_aa != -1 && ab_aa != -1) {
|
---|
462 | const double A_aa_ijab = 0.5*(r12_jbiAf - r12_ibjAf + r12_iajBf - r12_jaiBf);
|
---|
463 | Aaa_.set_element(ij_aa,ab_aa,A_aa_ijab);
|
---|
464 | }
|
---|
465 |
|
---|
466 | }
|
---|
467 |
|
---|
468 | ijaBf_acc->release_pair_block(i,j,R12IntsAcc::r12);
|
---|
469 | ijaBf_acc->release_pair_block(j,i,R12IntsAcc::r12);
|
---|
470 | }
|
---|
471 |
|
---|
472 | globally_sum_intermeds_();
|
---|
473 |
|
---|
474 | #if TEST_A
|
---|
475 | Aaa_.print("Alpha-alpha A intermediate");
|
---|
476 | Aab_.print("Alpha-beta A intermediate");
|
---|
477 | #endif
|
---|
478 |
|
---|
479 | ExEnv::out0() << decindent;
|
---|
480 | ExEnv::out0() << indent << "Exited A intermediate evaluator" << endl;
|
---|
481 |
|
---|
482 | tim_exit("A intermediate");
|
---|
483 | }
|
---|
484 |
|
---|
485 | void
|
---|
486 | R12IntEval::compute_A_via_commutator_()
|
---|
487 | {
|
---|
488 | if (evaluated_)
|
---|
489 | return;
|
---|
490 |
|
---|
491 | // This functions assumes that virtuals are expanded in the same basis
|
---|
492 | // as the occupied orbitals
|
---|
493 | if (!r12info_->basis_vir()->equiv(r12info_->basis()))
|
---|
494 | throw std::runtime_error("R12IntEval::compute_A_via_commutator_() -- should not be called when the basis set for virtuals \
|
---|
495 | differs from the basis set for occupieds");
|
---|
496 |
|
---|
497 | Ref<TwoBodyMOIntsTransform> ipjq_tform = get_tform_("(ip|jq)");
|
---|
498 | Ref<R12IntsAcc> ijpq_acc = ipjq_tform->ints_acc();
|
---|
499 | if (!ijpq_acc->is_committed())
|
---|
500 | ipjq_tform->compute();
|
---|
501 | if (!ijpq_acc->is_active())
|
---|
502 | ijpq_acc->activate();
|
---|
503 |
|
---|
504 | tim_enter("A intermediate via [T,r]");
|
---|
505 |
|
---|
506 | Ref<MessageGrp> msg = r12info_->msg();
|
---|
507 | int me = msg->me();
|
---|
508 | int nproc = msg->n();
|
---|
509 | ExEnv::out0() << endl << indent
|
---|
510 | << "Entered A amplitude (via [T,r]) evaluator" << endl;
|
---|
511 | ExEnv::out0() << incindent;
|
---|
512 |
|
---|
513 | const int noso = r12info_->mo_space()->rank();
|
---|
514 | const int nocc = r12info_->nocc();
|
---|
515 | const int nfzv = r12info_->nfzv();
|
---|
516 | Ref<MOIndexSpace> mo_space = r12info_->obs_space();
|
---|
517 | Ref<MOIndexSpace> act_occ_space = r12info_->act_occ_space();
|
---|
518 | Ref<MOIndexSpace> act_vir_space = r12info_->act_vir_space();
|
---|
519 |
|
---|
520 | SpatialMOPairIter_eq ij_iter(act_occ_space);
|
---|
521 | SpatialMOPairIter_eq ab_iter(act_vir_space);
|
---|
522 | int naa = ij_iter.nij_aa(); // Number of alpha-alpha pairs (i > j)
|
---|
523 | int nab = ij_iter.nij_ab(); // Number of alpha-beta pairs
|
---|
524 | if (debug_) {
|
---|
525 | ExEnv::out0() << indent << "naa = " << naa << endl;
|
---|
526 | ExEnv::out0() << indent << "nab = " << nab << endl;
|
---|
527 | }
|
---|
528 |
|
---|
529 | // Compute the number of tasks that have full access to the integrals
|
---|
530 | // and split the work among them
|
---|
531 | vector<int> proc_with_ints;
|
---|
532 | int nproc_with_ints = tasks_with_ints_(ijpq_acc,proc_with_ints);
|
---|
533 |
|
---|
534 | for(ij_iter.start();int(ij_iter);ij_iter.next()) {
|
---|
535 |
|
---|
536 | const int ij = ij_iter.ij();
|
---|
537 | // Figure out if this task will handle this ij
|
---|
538 | int ij_proc = ij%nproc_with_ints;
|
---|
539 | if (ij_proc != proc_with_ints[me])
|
---|
540 | continue;
|
---|
541 | const int i = ij_iter.i();
|
---|
542 | const int j = ij_iter.j();
|
---|
543 | const int ij_aa = ij_iter.ij_aa();
|
---|
544 | const int ij_ab = ij_iter.ij_ab();
|
---|
545 | const int ji_ab = ij_iter.ij_ba();
|
---|
546 |
|
---|
547 | if (debug_)
|
---|
548 | ExEnv::outn() << indent << "task " << me << ": working on (i,j) = " << i << "," << j << " " << endl;
|
---|
549 |
|
---|
550 | // Get (|1/r12|) integrals
|
---|
551 | tim_enter("MO ints retrieve");
|
---|
552 | double *ijxy_buf_r12 = ijpq_acc->retrieve_pair_block(i,j,R12IntsAcc::r12);
|
---|
553 | double *ijxy_buf_r12t1 = ijpq_acc->retrieve_pair_block(i,j,R12IntsAcc::r12t1);
|
---|
554 | double *jixy_buf_r12t1 = ijpq_acc->retrieve_pair_block(j,i,R12IntsAcc::r12t1);
|
---|
555 | tim_exit("MO ints retrieve");
|
---|
556 |
|
---|
557 | if (debug_)
|
---|
558 | ExEnv::outn() << indent << "task " << me << ": obtained ij blocks" << endl;
|
---|
559 |
|
---|
560 | RefDiagSCMatrix act_occ_evals = r12info_->act_occ_space()->evals();
|
---|
561 | RefDiagSCMatrix all_evals = r12info_->obs_space()->evals();
|
---|
562 | double R_aa_ijab = 0.0;
|
---|
563 | double R_ab_ijab = 0.0;
|
---|
564 | double TR_aa_ijab = 0.0;
|
---|
565 | double TR_ab_ijab = 0.0;
|
---|
566 |
|
---|
567 | for(ab_iter.start();int(ab_iter);ab_iter.next()) {
|
---|
568 |
|
---|
569 | const int a = ab_iter.i();
|
---|
570 | const int b = ab_iter.j();
|
---|
571 | const int ab_aa = ab_iter.ij_aa();
|
---|
572 | const int ab_ab = ab_iter.ij_ab();
|
---|
573 | const int ba_ab = ab_iter.ij_ba();
|
---|
574 |
|
---|
575 | const int aa = a + nocc;
|
---|
576 | const int bb = b + nocc;
|
---|
577 |
|
---|
578 | const int ab_offset = aa*noso+bb;
|
---|
579 | const int ba_offset = bb*noso+aa;
|
---|
580 | const double r12_iajb = ijxy_buf_r12[ab_offset];
|
---|
581 | const double r12_ibja = ijxy_buf_r12[ba_offset];
|
---|
582 | const double t1r12_iajb = -ijxy_buf_r12t1[ab_offset];
|
---|
583 | const double t1r12_ibja = -ijxy_buf_r12t1[ba_offset];
|
---|
584 | const double t2r12_iajb = -jixy_buf_r12t1[ba_offset];
|
---|
585 | const double t2r12_ibja = -jixy_buf_r12t1[ab_offset];
|
---|
586 | #if ACOMM_INCLUDE_TR_ONLY
|
---|
587 | double Aab_ij_ab = 0.5 * ( -(t1r12_iajb + t2r12_iajb) );
|
---|
588 | double Aab_ij_ba = 0.5 * ( -(t1r12_ibja + t2r12_ibja) );
|
---|
589 | #elif ACOMM_INCLUDE_R_ONLY
|
---|
590 | double Aab_ij_ab = 0.5 * ( r12_iajb );
|
---|
591 | double Aab_ij_ba = 0.5 * ( r12_ibja );
|
---|
592 | #else
|
---|
593 | double Aab_ij_ab = 0.5 * ( -(t1r12_iajb + t2r12_iajb) - (all_evals(aa) + all_evals(bb) -
|
---|
594 | act_occ_evals(i) - act_occ_evals(j))*r12_iajb );
|
---|
595 | double Aab_ij_ba = 0.5 * ( -(t1r12_ibja + t2r12_ibja) - (all_evals(aa) + all_evals(bb) -
|
---|
596 | act_occ_evals(i) - act_occ_evals(j))*r12_ibja );
|
---|
597 | #endif
|
---|
598 | Ac_ab_.set_element(ij_ab,ab_ab,Aab_ij_ab);
|
---|
599 | Ac_ab_.set_element(ji_ab,ba_ab,Aab_ij_ab);
|
---|
600 | Ac_ab_.set_element(ji_ab,ab_ab,Aab_ij_ba);
|
---|
601 | Ac_ab_.set_element(ij_ab,ba_ab,Aab_ij_ba);
|
---|
602 |
|
---|
603 | if (ij_aa != -1 && ab_aa != -1) {
|
---|
604 | Ac_aa_.set_element(ij_aa,ab_aa,Aab_ij_ab - Aab_ij_ba);
|
---|
605 | }
|
---|
606 |
|
---|
607 | }
|
---|
608 |
|
---|
609 | ijpq_acc->release_pair_block(i,j,R12IntsAcc::r12);
|
---|
610 | ijpq_acc->release_pair_block(i,j,R12IntsAcc::r12t1);
|
---|
611 | ijpq_acc->release_pair_block(j,i,R12IntsAcc::r12t1);
|
---|
612 | }
|
---|
613 |
|
---|
614 | globally_sum_intermeds_();
|
---|
615 |
|
---|
616 | #if TEST_A
|
---|
617 | Ac_aa_.print("Alpha-alpha A intermediate");
|
---|
618 | Ac_ab_.print("Alpha-beta A intermediate");
|
---|
619 | #endif
|
---|
620 |
|
---|
621 | ExEnv::out0() << decindent;
|
---|
622 | ExEnv::out0() << indent << "Exited A amplitude (via [T,r]) evaluator" << endl;
|
---|
623 |
|
---|
624 | tim_exit("A intermediate via [T,r]");
|
---|
625 | }
|
---|
626 |
|
---|
627 |
|
---|
628 | void
|
---|
629 | R12IntEval::AT2_contrib_to_V_()
|
---|
630 | {
|
---|
631 | if (evaluated_)
|
---|
632 | return;
|
---|
633 | if (r12info_->msg()->me() == 0) {
|
---|
634 | RefSCMatrix Vaa = Aaa_*T2aa_.t();
|
---|
635 | Vaa_.accumulate(Vaa);
|
---|
636 | RefSCMatrix Vab = Aab_*T2ab_.t();
|
---|
637 | Vab_.accumulate(Vab);
|
---|
638 | if (debug_ > 0) {
|
---|
639 | print_scmat_norms(Vaa,"Alpha-alpha AT2 contribution to V");
|
---|
640 | print_scmat_norms(Vab,"Alpha-beta AT2 contribution to V");
|
---|
641 | }
|
---|
642 | }
|
---|
643 | globally_sum_intermeds_();
|
---|
644 | }
|
---|
645 |
|
---|
646 | void
|
---|
647 | R12IntEval::AR_contrib_to_B_()
|
---|
648 | {
|
---|
649 | if (evaluated_)
|
---|
650 | return;
|
---|
651 | if (r12info_->msg()->me() == 0) {
|
---|
652 | #if USE_A_COMM_IN_B_EBC
|
---|
653 | RefSCMatrix AR_aa = Ac_aa_*Raa_.t();
|
---|
654 | RefSCMatrix AR_ab = Ac_ab_*Rab_.t();
|
---|
655 | double scale = -0.5;
|
---|
656 | #else
|
---|
657 | RefSCMatrix AR_aa = Aaa_*Raa_.t();
|
---|
658 | RefSCMatrix AR_ab = Aab_*Rab_.t();
|
---|
659 | double scale = -0.5;
|
---|
660 | #endif
|
---|
661 | RefSCMatrix Baa = Baa_.clone(); Baa.assign(0.0);
|
---|
662 | RefSCMatrix Bab = Bab_.clone(); Bab.assign(0.0);
|
---|
663 | AR_aa.scale(scale); Baa.accumulate(AR_aa);
|
---|
664 | RefSCMatrix AR_aa_t = AR_aa.t();
|
---|
665 | Baa.accumulate(AR_aa_t);
|
---|
666 | AR_ab.scale(scale); Bab.accumulate(AR_ab);
|
---|
667 | RefSCMatrix AR_ab_t = AR_ab.t();
|
---|
668 | Bab.accumulate(AR_ab_t);
|
---|
669 | if (debug_ > 1) {
|
---|
670 | Baa.print("Alpha-alpha B^{EBC} contribution");
|
---|
671 | Bab.print("Alpha-beta B^{EBC} contribution");
|
---|
672 | }
|
---|
673 | Baa_.accumulate(Baa);
|
---|
674 | Bab_.accumulate(Bab);
|
---|
675 | if (debug_ > 0) {
|
---|
676 | print_scmat_norms(Baa,"Alpha-alpha AR contribution to B");
|
---|
677 | print_scmat_norms(Bab,"Alpha-beta AR contribution to B");
|
---|
678 | }
|
---|
679 | }
|
---|
680 | globally_sum_intermeds_();
|
---|
681 | }
|
---|
682 |
|
---|
683 | ////////////////////////////////////////////////////////////////////////////
|
---|
684 |
|
---|
685 | // Local Variables:
|
---|
686 | // mode: c++
|
---|
687 | // c-file-style: "CLJ-CONDENSED"
|
---|
688 | // End:
|
---|