1 | //
|
---|
2 | // compute_amps.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 <math/scmat/local.h>
|
---|
43 | #include <chemistry/molecule/molecule.h>
|
---|
44 | #include <chemistry/qc/basis/integral.h>
|
---|
45 | #include <chemistry/qc/mbptr12/blas.h>
|
---|
46 | #include <chemistry/qc/mbptr12/r12ia.h>
|
---|
47 | #include <chemistry/qc/mbptr12/vxb_eval_info.h>
|
---|
48 | #include <chemistry/qc/mbptr12/pairiter.h>
|
---|
49 | #include <chemistry/qc/mbptr12/r12int_eval.h>
|
---|
50 |
|
---|
51 | using namespace std;
|
---|
52 | using namespace sc;
|
---|
53 |
|
---|
54 | void
|
---|
55 | R12IntEval::compute_T2_vbsneqobs_()
|
---|
56 | {
|
---|
57 | Ref<TwoBodyMOIntsTransform> iajb_tform = get_tform_("(ia|jb)");
|
---|
58 | Ref<R12IntsAcc> ijab_acc = iajb_tform->ints_acc();
|
---|
59 | if (!ijab_acc->is_committed())
|
---|
60 | iajb_tform->compute();
|
---|
61 | if (!ijab_acc->is_active())
|
---|
62 | ijab_acc->activate();
|
---|
63 |
|
---|
64 | tim_enter("mp2 t2 amplitudes");
|
---|
65 |
|
---|
66 | Ref<MessageGrp> msg = r12info_->msg();
|
---|
67 | int me = msg->me();
|
---|
68 | int nproc = msg->n();
|
---|
69 | ExEnv::out0() << endl << indent
|
---|
70 | << "Entered MP2 T2 amplitude evaluator" << endl;
|
---|
71 | ExEnv::out0() << incindent;
|
---|
72 |
|
---|
73 | Ref<MOIndexSpace> act_occ_space = r12info_->act_occ_space();
|
---|
74 | Ref<MOIndexSpace> act_vir_space = r12info_->act_vir_space();
|
---|
75 | const int nactvir = act_vir_space->rank();
|
---|
76 | RefDiagSCMatrix act_occ_evals = act_occ_space->evals();
|
---|
77 | RefDiagSCMatrix act_vir_evals = act_vir_space->evals();
|
---|
78 |
|
---|
79 | SpatialMOPairIter_eq ij_iter(act_occ_space);
|
---|
80 | SpatialMOPairIter_eq ab_iter(act_vir_space);
|
---|
81 | int naa = ij_iter.nij_aa(); // Number of alpha-alpha pairs (i > j)
|
---|
82 | int nab = ij_iter.nij_ab(); // Number of alpha-beta pairs
|
---|
83 | if (debug_) {
|
---|
84 | ExEnv::out0() << indent << "naa = " << naa << endl;
|
---|
85 | ExEnv::out0() << indent << "nab = " << nab << endl;
|
---|
86 | }
|
---|
87 |
|
---|
88 | // Compute the number of tasks that have full access to the integrals
|
---|
89 | // and split the work among them
|
---|
90 | vector<int> proc_with_ints;
|
---|
91 | int nproc_with_ints = tasks_with_ints_(ijab_acc,proc_with_ints);
|
---|
92 |
|
---|
93 | //////////////////////////////////////////////////////////////
|
---|
94 | //
|
---|
95 | // Evaluation of the MP2 T2 amplitudes proceeds as follows:
|
---|
96 | //
|
---|
97 | // loop over batches of ij,
|
---|
98 | // load (ijxy)=(ix|jy) into memory
|
---|
99 | //
|
---|
100 | // loop over xy, 0<=x<nvir_act, 0<=y<nvir_act
|
---|
101 | // compute T2_aa[ij][xy] = [ (ijxy) - (ijyx) ] / denom
|
---|
102 | // compute T2_ab[ij][xy] = [ (ijxy) ] / denom
|
---|
103 | // end xy loop
|
---|
104 | // end ij loop
|
---|
105 | //
|
---|
106 | /////////////////////////////////////////////////////////////////////////////////
|
---|
107 |
|
---|
108 | for(ij_iter.start();int(ij_iter);ij_iter.next()) {
|
---|
109 |
|
---|
110 | const int ij = ij_iter.ij();
|
---|
111 | // Figure out if this task will handle this ij
|
---|
112 | int ij_proc = ij%nproc_with_ints;
|
---|
113 | if (ij_proc != proc_with_ints[me])
|
---|
114 | continue;
|
---|
115 | const int i = ij_iter.i();
|
---|
116 | const int j = ij_iter.j();
|
---|
117 | const int ij_aa = ij_iter.ij_aa();
|
---|
118 | const int ij_ab = ij_iter.ij_ab();
|
---|
119 | const int ji_ab = ij_iter.ij_ba();
|
---|
120 |
|
---|
121 | if (debug_)
|
---|
122 | ExEnv::outn() << indent << "task " << me << ": working on (i,j) = " << i << "," << j << " " << endl;
|
---|
123 |
|
---|
124 | // Get (|1/r12|) integrals
|
---|
125 | tim_enter("MO ints retrieve");
|
---|
126 | double *ijxy_buf_eri = ijab_acc->retrieve_pair_block(i,j,R12IntsAcc::eri);
|
---|
127 | tim_exit("MO ints retrieve");
|
---|
128 |
|
---|
129 | if (debug_)
|
---|
130 | ExEnv::outn() << indent << "task " << me << ": obtained ij blocks" << endl;
|
---|
131 |
|
---|
132 | // Compute MP2 energies
|
---|
133 | double T2_aa_ijab = 0.0;
|
---|
134 | double T2_ab_ijab = 0.0;
|
---|
135 |
|
---|
136 | for(ab_iter.start();int(ab_iter);ab_iter.next()) {
|
---|
137 |
|
---|
138 | const int a = ab_iter.i();
|
---|
139 | const int b = ab_iter.j();
|
---|
140 | const int ab_aa = ab_iter.ij_aa();
|
---|
141 | const int ab_ab = ab_iter.ij_ab();
|
---|
142 | const int ba_ab = ab_iter.ij_ba();
|
---|
143 |
|
---|
144 | const int ab_offset = a*nactvir + b;
|
---|
145 | const int ba_offset = b*nactvir + a;
|
---|
146 | const double oo_delta_ijab = -1.0/(-act_occ_evals(i)-act_occ_evals(j)+act_vir_evals(a)+act_vir_evals(b));
|
---|
147 | const double eri_iajb = ijxy_buf_eri[ab_offset];
|
---|
148 | const double eri_ibja = ijxy_buf_eri[ba_offset];
|
---|
149 | const double T2_ab_ijab = eri_iajb * oo_delta_ijab;
|
---|
150 | const double T2_ab_ijba = eri_ibja * oo_delta_ijab;
|
---|
151 | T2ab_.set_element(ij_ab,ab_ab,T2_ab_ijab);
|
---|
152 | T2ab_.set_element(ji_ab,ba_ab,T2_ab_ijab);
|
---|
153 | T2ab_.set_element(ji_ab,ab_ab,T2_ab_ijba);
|
---|
154 | T2ab_.set_element(ij_ab,ba_ab,T2_ab_ijba);
|
---|
155 |
|
---|
156 | if (ij_aa != -1 && ab_aa != -1) {
|
---|
157 | const double T2_aa_ijab = (eri_iajb - eri_ibja) * oo_delta_ijab;
|
---|
158 | T2aa_.set_element(ij_aa,ab_aa,T2_aa_ijab);
|
---|
159 | }
|
---|
160 |
|
---|
161 | }
|
---|
162 |
|
---|
163 | ijab_acc->release_pair_block(i,j,R12IntsAcc::eri);
|
---|
164 | }
|
---|
165 |
|
---|
166 | globally_sum_scmatrix_(T2aa_);
|
---|
167 | globally_sum_scmatrix_(T2ab_);
|
---|
168 |
|
---|
169 | ExEnv::out0() << decindent;
|
---|
170 | ExEnv::out0() << indent << "Exited MP2 T2 amplitude evaluator" << endl;
|
---|
171 | tim_exit("mp2 t2 amplitudes");
|
---|
172 | }
|
---|
173 |
|
---|
174 | void
|
---|
175 | R12IntEval::compute_R_vbsneqobs_(const Ref<TwoBodyMOIntsTransform>& ipjq_tform, RefSCMatrix& Raa, RefSCMatrix& Rab)
|
---|
176 | {
|
---|
177 | Ref<R12IntsAcc> ijpq_acc = ipjq_tform->ints_acc();
|
---|
178 | if (!ijpq_acc->is_committed())
|
---|
179 | ipjq_tform->compute();
|
---|
180 | if (!ijpq_acc->is_active())
|
---|
181 | ijpq_acc->activate();
|
---|
182 |
|
---|
183 | tim_enter("R intermediate");
|
---|
184 |
|
---|
185 | Ref<MessageGrp> msg = r12info_->msg();
|
---|
186 | int me = msg->me();
|
---|
187 | int nproc = msg->n();
|
---|
188 | ExEnv::out0() << endl << indent
|
---|
189 | << "Entered R intermediate evaluator" << endl;
|
---|
190 | ExEnv::out0() << incindent;
|
---|
191 |
|
---|
192 | Ref<MOIndexSpace> act_occ_space = r12info_->act_occ_space();
|
---|
193 | Ref<MOIndexSpace> space2 = ipjq_tform->space2();
|
---|
194 | Ref<MOIndexSpace> space4 = ipjq_tform->space4();
|
---|
195 | const int rank2 = space2->rank();
|
---|
196 | const int rank4 = space4->rank();
|
---|
197 |
|
---|
198 | MOPairIterFactory PIFactory;
|
---|
199 | Ref<SpatialMOPairIter> ij_iter = PIFactory.mopairiter(act_occ_space,act_occ_space);
|
---|
200 | Ref<SpatialMOPairIter> pq_iter = PIFactory.mopairiter(space2,space4);
|
---|
201 |
|
---|
202 | int nij_aa = ij_iter->nij_aa(); // Number of alpha-alpha pairs (i > j)
|
---|
203 | int nij_ab = ij_iter->nij_ab(); // Number of alpha-beta pairs
|
---|
204 | if (debug_) {
|
---|
205 | ExEnv::out0() << indent << "nij_aa = " << nij_aa << endl;
|
---|
206 | ExEnv::out0() << indent << "nij_ab = " << nij_ab << endl;
|
---|
207 | }
|
---|
208 |
|
---|
209 | // Compute the number of tasks that have full access to the integrals
|
---|
210 | // and split the work among them
|
---|
211 | vector<int> proc_with_ints;
|
---|
212 | int nproc_with_ints = tasks_with_ints_(ijpq_acc,proc_with_ints);
|
---|
213 |
|
---|
214 | for(ij_iter->start();int(*ij_iter.pointer());ij_iter->next()) {
|
---|
215 |
|
---|
216 | const int ij = ij_iter->ij();
|
---|
217 | // Figure out if this task will handle this ij
|
---|
218 | int ij_proc = ij%nproc_with_ints;
|
---|
219 | if (ij_proc != proc_with_ints[me])
|
---|
220 | continue;
|
---|
221 | const int i = ij_iter->i();
|
---|
222 | const int j = ij_iter->j();
|
---|
223 | const int ij_aa = ij_iter->ij_aa();
|
---|
224 | const int ij_ab = ij_iter->ij_ab();
|
---|
225 | const int ji_ab = ij_iter->ij_ba();
|
---|
226 |
|
---|
227 | if (debug_)
|
---|
228 | ExEnv::outn() << indent << "task " << me << ": working on (i,j) = " << i << "," << j << " " << endl;
|
---|
229 |
|
---|
230 | // Get (|1/r12|) integrals
|
---|
231 | tim_enter("MO ints retrieve");
|
---|
232 | double *ijxy_buf_r12 = ijpq_acc->retrieve_pair_block(i,j,R12IntsAcc::r12);
|
---|
233 | double *jixy_buf_r12 = ijpq_acc->retrieve_pair_block(j,i,R12IntsAcc::r12);
|
---|
234 | tim_exit("MO ints retrieve");
|
---|
235 |
|
---|
236 | if (debug_)
|
---|
237 | ExEnv::outn() << indent << "task " << me << ": obtained ij blocks" << endl;
|
---|
238 |
|
---|
239 | for(pq_iter->start();int(*pq_iter.pointer());pq_iter->next()) {
|
---|
240 |
|
---|
241 | const int p = pq_iter->i();
|
---|
242 | const int q = pq_iter->j();
|
---|
243 | const int pq_aa = pq_iter->ij_aa();
|
---|
244 | const int pq_ab = pq_iter->ij_ab();
|
---|
245 | const int pq_ba = pq_iter->ij_ba();
|
---|
246 |
|
---|
247 | const int pq_offset = p*rank4 + q;
|
---|
248 | const double r12_ipjq = ijxy_buf_r12[pq_offset];
|
---|
249 | const double r12_jpiq = jixy_buf_r12[pq_offset];
|
---|
250 | Rab.set_element(ij_ab,pq_ab,r12_ipjq);
|
---|
251 | Rab.set_element(ji_ab,pq_ba,r12_ipjq);
|
---|
252 | Rab.set_element(ij_ab,pq_ba,r12_jpiq);
|
---|
253 | Rab.set_element(ji_ab,pq_ab,r12_jpiq);
|
---|
254 |
|
---|
255 | if (ij_aa != -1 && pq_aa != -1) {
|
---|
256 | const double R_aa_ijpq = (r12_ipjq - r12_jpiq);
|
---|
257 | Raa.set_element(ij_aa,pq_aa,R_aa_ijpq);
|
---|
258 | }
|
---|
259 |
|
---|
260 | }
|
---|
261 |
|
---|
262 | ijpq_acc->release_pair_block(i,j,R12IntsAcc::r12);
|
---|
263 | ijpq_acc->release_pair_block(j,i,R12IntsAcc::r12);
|
---|
264 | }
|
---|
265 |
|
---|
266 | globally_sum_scmatrix_(Raa);
|
---|
267 | globally_sum_scmatrix_(Rab);
|
---|
268 |
|
---|
269 | ExEnv::out0() << decindent;
|
---|
270 | ExEnv::out0() << indent << "Exited R intermediate evaluator" << endl;
|
---|
271 | tim_exit("R intermediate");
|
---|
272 | }
|
---|
273 |
|
---|
274 | void
|
---|
275 | R12IntEval::compute_amps_()
|
---|
276 | {
|
---|
277 | if (Amps_.nonnull())
|
---|
278 | return;
|
---|
279 |
|
---|
280 | Ref<MOIndexSpace> act_vir_space = r12info_->act_vir_space();
|
---|
281 | Ref<MOIndexSpace> occ_space = r12info_->occ_space();
|
---|
282 | Ref<MOIndexSpace> ribs_space = r12info_->ribs_space();
|
---|
283 |
|
---|
284 | MOPairIterFactory PIFactory;
|
---|
285 | RefSCDimension ij_aa = dim_ij_aa_;
|
---|
286 | RefSCDimension ij_ab = dim_ij_ab_;
|
---|
287 | RefSCDimension vv_aa = PIFactory.scdim_aa(act_vir_space,act_vir_space);
|
---|
288 | RefSCDimension vv_ab = PIFactory.scdim_ab(act_vir_space,act_vir_space);
|
---|
289 | RefSCDimension oo_aa = PIFactory.scdim_aa(occ_space,occ_space);
|
---|
290 | RefSCDimension oo_ab = PIFactory.scdim_ab(occ_space,occ_space);
|
---|
291 | RefSCDimension ov_aa = PIFactory.scdim_aa(occ_space,act_vir_space);
|
---|
292 | RefSCDimension ov_ab = PIFactory.scdim_ab(occ_space,act_vir_space);
|
---|
293 | RefSCDimension ox_aa = PIFactory.scdim_aa(occ_space,ribs_space);
|
---|
294 | RefSCDimension ox_ab = PIFactory.scdim_ab(occ_space,ribs_space);
|
---|
295 | Ref<SCMatrixKit> kit = new LocalSCMatrixKit();
|
---|
296 |
|
---|
297 | RefSCMatrix T2_aa = kit->matrix(ij_aa,vv_aa);
|
---|
298 | RefSCMatrix T2_ab = kit->matrix(ij_ab,vv_ab);
|
---|
299 | RefSCMatrix Rvv_aa = kit->matrix(ij_aa,vv_aa);
|
---|
300 | RefSCMatrix Rvv_ab = kit->matrix(ij_ab,vv_ab);
|
---|
301 | RefSCMatrix Roo_aa = kit->matrix(ij_aa,oo_aa);
|
---|
302 | RefSCMatrix Roo_ab = kit->matrix(ij_ab,oo_ab);
|
---|
303 | RefSCMatrix Rvo_aa = kit->matrix(ij_aa,ov_aa);
|
---|
304 | RefSCMatrix Rvo_ab = kit->matrix(ij_ab,ov_ab);
|
---|
305 | RefSCMatrix Rxo_aa = kit->matrix(ij_aa,ox_aa);
|
---|
306 | RefSCMatrix Rxo_ab = kit->matrix(ij_ab,ox_ab);
|
---|
307 | compute_T2_vbsneqobs_();
|
---|
308 | compute_R_vbsneqobs_(get_tform_("(ia|jb)"),Rvv_aa,Rvv_ab);
|
---|
309 | compute_R_vbsneqobs_(get_tform_("(im|jn)"),Roo_aa,Roo_ab);
|
---|
310 | compute_R_vbsneqobs_(get_tform_("(im|ja)"),Rvo_aa,Rvo_ab);
|
---|
311 | compute_R_vbsneqobs_(get_tform_("(im|jy)"),Rxo_aa,Rxo_ab);
|
---|
312 |
|
---|
313 | Amps_ = new R12Amplitudes(T2_aa, T2_ab, Rvv_aa, Rvv_ab, Roo_aa, Roo_ab, Rvo_aa, Rvo_ab, Rxo_aa, Rxo_ab);
|
---|
314 | }
|
---|
315 |
|
---|
316 | Ref<R12Amplitudes>
|
---|
317 | R12IntEval::amps()
|
---|
318 | {
|
---|
319 | if (Amps_.null())
|
---|
320 | compute_amps_();
|
---|
321 | return Amps_;
|
---|
322 | }
|
---|
323 |
|
---|
324 | ////////////////////////////////////////////////////////////////////////////
|
---|
325 |
|
---|
326 | // Local Variables:
|
---|
327 | // mode: c++
|
---|
328 | // c-file-style: "CLJ-CONDENSED"
|
---|
329 | // End:
|
---|