1 | //
|
---|
2 | // clhf.cc --- implementation of the closed shell Hartree-Fock SCF class
|
---|
3 | //
|
---|
4 | // Copyright (C) 1996 Limit Point Systems, Inc.
|
---|
5 | //
|
---|
6 | // Author: Edward Seidl <seidl@janed.com>
|
---|
7 | // Maintainer: LPS
|
---|
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 __GNUC__
|
---|
29 | #pragma implementation
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <math.h>
|
---|
33 |
|
---|
34 | #include <util/misc/timer.h>
|
---|
35 | #include <util/misc/formio.h>
|
---|
36 | #include <util/state/stateio.h>
|
---|
37 |
|
---|
38 | #include <chemistry/qc/basis/petite.h>
|
---|
39 |
|
---|
40 | #include <chemistry/qc/scf/clhf.h>
|
---|
41 | #include <chemistry/qc/scf/lgbuild.h>
|
---|
42 | #include <chemistry/qc/scf/clhftmpl.h>
|
---|
43 |
|
---|
44 | using namespace std;
|
---|
45 | using namespace sc;
|
---|
46 |
|
---|
47 | ///////////////////////////////////////////////////////////////////////////
|
---|
48 | // CLHF
|
---|
49 |
|
---|
50 | static ClassDesc CLHF_cd(
|
---|
51 | typeid(CLHF),"CLHF",1,"public CLSCF",
|
---|
52 | 0, create<CLHF>, create<CLHF>);
|
---|
53 |
|
---|
54 | CLHF::CLHF(StateIn& s) :
|
---|
55 | SavableState(s),
|
---|
56 | CLSCF(s)
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 | CLHF::CLHF(const Ref<KeyVal>& keyval) :
|
---|
61 | CLSCF(keyval)
|
---|
62 | {
|
---|
63 | }
|
---|
64 |
|
---|
65 | CLHF::~CLHF()
|
---|
66 | {
|
---|
67 | }
|
---|
68 |
|
---|
69 | void
|
---|
70 | CLHF::save_data_state(StateOut& s)
|
---|
71 | {
|
---|
72 | CLSCF::save_data_state(s);
|
---|
73 | }
|
---|
74 |
|
---|
75 | int
|
---|
76 | CLHF::value_implemented() const
|
---|
77 | {
|
---|
78 | return 1;
|
---|
79 | }
|
---|
80 |
|
---|
81 | int
|
---|
82 | CLHF::gradient_implemented() const
|
---|
83 | {
|
---|
84 | return 1;
|
---|
85 | }
|
---|
86 |
|
---|
87 | void
|
---|
88 | CLHF::print(ostream&o) const
|
---|
89 | {
|
---|
90 | CLSCF::print(o);
|
---|
91 | }
|
---|
92 |
|
---|
93 | //////////////////////////////////////////////////////////////////////////////
|
---|
94 |
|
---|
95 | void
|
---|
96 | CLHF::ao_fock(double accuracy)
|
---|
97 | {
|
---|
98 | int i;
|
---|
99 | int nthread = threadgrp_->nthread();
|
---|
100 |
|
---|
101 | Ref<PetiteList> pl = integral()->petite_list(basis());
|
---|
102 |
|
---|
103 | // calculate G. First transform cl_dens_diff_ to the AO basis, then
|
---|
104 | // scale the off-diagonal elements by 2.0
|
---|
105 | tim_enter("setup");
|
---|
106 | RefSymmSCMatrix dd = cl_dens_diff_;
|
---|
107 | cl_dens_diff_ = pl->to_AO_basis(dd);
|
---|
108 | cl_dens_diff_->scale(2.0);
|
---|
109 | cl_dens_diff_->scale_diagonal(0.5);
|
---|
110 | tim_exit("setup");
|
---|
111 |
|
---|
112 | // now try to figure out the matrix specialization we're dealing with
|
---|
113 | // if we're using Local matrices, then there's just one subblock, or
|
---|
114 | // see if we can convert G and P to local matrices
|
---|
115 |
|
---|
116 | if (debug_>1) {
|
---|
117 | cl_gmat_.print("cl_gmat before build");
|
---|
118 | cl_dens_diff_.print("cl_dens_diff before build");
|
---|
119 | }
|
---|
120 |
|
---|
121 | if (local_ || local_dens_) {
|
---|
122 | // grab the data pointers from the G and P matrices
|
---|
123 | double *gmat, *pmat;
|
---|
124 | tim_enter("local data");
|
---|
125 | RefSymmSCMatrix gtmp = get_local_data(cl_gmat_, gmat, SCF::Accum);
|
---|
126 | RefSymmSCMatrix ptmp = get_local_data(cl_dens_diff_, pmat, SCF::Read);
|
---|
127 | tim_exit("local data");
|
---|
128 |
|
---|
129 | tim_enter("init pmax");
|
---|
130 | signed char * pmax = init_pmax(pmat);
|
---|
131 | tim_exit("init pmax");
|
---|
132 |
|
---|
133 | tim_enter("ao_gmat");
|
---|
134 | LocalGBuild<LocalCLHFContribution> **gblds =
|
---|
135 | new LocalGBuild<LocalCLHFContribution>*[nthread];
|
---|
136 | LocalCLHFContribution **conts = new LocalCLHFContribution*[nthread];
|
---|
137 |
|
---|
138 | double **gmats = new double*[nthread];
|
---|
139 | gmats[0] = gmat;
|
---|
140 |
|
---|
141 | Ref<GaussianBasisSet> bs = basis();
|
---|
142 | int ntri = i_offset(bs->nbasis());
|
---|
143 |
|
---|
144 | double gmat_accuracy = accuracy;
|
---|
145 | if (min_orthog_res() < 1.0) { gmat_accuracy *= min_orthog_res(); }
|
---|
146 |
|
---|
147 | for (i=0; i < nthread; i++) {
|
---|
148 | if (i) {
|
---|
149 | gmats[i] = new double[ntri];
|
---|
150 | memset(gmats[i], 0, sizeof(double)*ntri);
|
---|
151 | }
|
---|
152 | conts[i] = new LocalCLHFContribution(gmats[i], pmat);
|
---|
153 | gblds[i] = new LocalGBuild<LocalCLHFContribution>(*conts[i], tbis_[i],
|
---|
154 | pl, bs, scf_grp_, pmax, gmat_accuracy, nthread, i
|
---|
155 | );
|
---|
156 |
|
---|
157 | threadgrp_->add_thread(i, gblds[i]);
|
---|
158 | }
|
---|
159 |
|
---|
160 | tim_enter("start thread");
|
---|
161 | if (threadgrp_->start_threads() < 0) {
|
---|
162 | ExEnv::err0() << indent
|
---|
163 | << "CLHF: error starting threads" << endl;
|
---|
164 | abort();
|
---|
165 | }
|
---|
166 | tim_exit("start thread");
|
---|
167 |
|
---|
168 | tim_enter("stop thread");
|
---|
169 | if (threadgrp_->wait_threads() < 0) {
|
---|
170 | ExEnv::err0() << indent
|
---|
171 | << "CLHF: error waiting for threads" << endl;
|
---|
172 | abort();
|
---|
173 | }
|
---|
174 | tim_exit("stop thread");
|
---|
175 |
|
---|
176 | double tnint=0;
|
---|
177 | for (i=0; i < nthread; i++) {
|
---|
178 | tnint += gblds[i]->tnint;
|
---|
179 |
|
---|
180 | if (i) {
|
---|
181 | for (int j=0; j < ntri; j++)
|
---|
182 | gmat[j] += gmats[i][j];
|
---|
183 | delete[] gmats[i];
|
---|
184 | }
|
---|
185 |
|
---|
186 | delete gblds[i];
|
---|
187 | delete conts[i];
|
---|
188 | }
|
---|
189 |
|
---|
190 | delete[] gmats;
|
---|
191 | delete[] gblds;
|
---|
192 | delete[] conts;
|
---|
193 | delete[] pmax;
|
---|
194 |
|
---|
195 | scf_grp_->sum(&tnint, 1, 0, 0);
|
---|
196 | ExEnv::out0() << indent << scprintf("%20.0f integrals\n", tnint);
|
---|
197 |
|
---|
198 | tim_exit("ao_gmat");
|
---|
199 |
|
---|
200 | // if we're running on multiple processors, then sum the G matrix
|
---|
201 | tim_enter("sum");
|
---|
202 | if (scf_grp_->n() > 1)
|
---|
203 | scf_grp_->sum(gmat, i_offset(basis()->nbasis()));
|
---|
204 | tim_exit("sum");
|
---|
205 |
|
---|
206 | // if we're running on multiple processors, or we don't have local
|
---|
207 | // matrices, then accumulate gtmp back into G
|
---|
208 | tim_enter("accum");
|
---|
209 | if (!local_ || scf_grp_->n() > 1)
|
---|
210 | cl_gmat_->convert_accumulate(gtmp);
|
---|
211 | tim_exit("accum");
|
---|
212 | }
|
---|
213 |
|
---|
214 | // for now quit
|
---|
215 | else {
|
---|
216 | ExEnv::err0() << indent << "Cannot yet use anything but Local matrices\n";
|
---|
217 | abort();
|
---|
218 | }
|
---|
219 |
|
---|
220 | tim_enter("symm");
|
---|
221 | // get rid of AO delta P
|
---|
222 | cl_dens_diff_ = dd;
|
---|
223 | dd = cl_dens_diff_.clone();
|
---|
224 |
|
---|
225 | // now symmetrize the skeleton G matrix, placing the result in dd
|
---|
226 | RefSymmSCMatrix skel_gmat = cl_gmat_.copy();
|
---|
227 | skel_gmat.scale(1.0/(double)pl->order());
|
---|
228 | if (debug_>1) {
|
---|
229 | skel_gmat.print("skel_gmat before symmetrize");
|
---|
230 | }
|
---|
231 | pl->symmetrize(skel_gmat,dd);
|
---|
232 | if (debug_>1) {
|
---|
233 | dd.print("dd after symmetrize");
|
---|
234 | }
|
---|
235 | tim_exit("symm");
|
---|
236 |
|
---|
237 | // F = H+G
|
---|
238 | cl_fock_.result_noupdate().assign(hcore_);
|
---|
239 | cl_fock_.result_noupdate().accumulate(dd);
|
---|
240 | accumddh_->accum(cl_fock_.result_noupdate());
|
---|
241 | cl_fock_.computed()=1;
|
---|
242 | }
|
---|
243 |
|
---|
244 | /////////////////////////////////////////////////////////////////////////////
|
---|
245 |
|
---|
246 | void
|
---|
247 | CLHF::two_body_energy(double &ec, double &ex)
|
---|
248 | {
|
---|
249 | tim_enter("clhf e2");
|
---|
250 | ec = 0.0;
|
---|
251 | ex = 0.0;
|
---|
252 |
|
---|
253 | if (local_ || local_dens_) {
|
---|
254 | // grab the data pointers from the G and P matrices
|
---|
255 | double *pmat;
|
---|
256 | tim_enter("local data");
|
---|
257 | RefSymmSCMatrix dens = ao_density();
|
---|
258 | dens->scale(2.0);
|
---|
259 | dens->scale_diagonal(0.5);
|
---|
260 | RefSymmSCMatrix ptmp = get_local_data(dens, pmat, SCF::Read);
|
---|
261 | tim_exit("local data");
|
---|
262 |
|
---|
263 | // initialize the two electron integral classes
|
---|
264 | Ref<TwoBodyInt> tbi = integral()->electron_repulsion();
|
---|
265 | tbi->set_integral_storage(0);
|
---|
266 |
|
---|
267 | tim_enter("init pmax");
|
---|
268 | signed char * pmax = init_pmax(pmat);
|
---|
269 | tim_exit("init pmax");
|
---|
270 |
|
---|
271 | LocalCLHFEnergyContribution lclc(pmat);
|
---|
272 | Ref<PetiteList> pl = integral()->petite_list();
|
---|
273 | LocalGBuild<LocalCLHFEnergyContribution>
|
---|
274 | gb(lclc, tbi, pl, basis(), scf_grp_, pmax,
|
---|
275 | 1.e-20/*desired_value_accuracy()/100.0*/);
|
---|
276 | gb.run();
|
---|
277 |
|
---|
278 | delete[] pmax;
|
---|
279 |
|
---|
280 | ec = lclc.ec;
|
---|
281 | ex = lclc.ex;
|
---|
282 | scf_grp_->sum(&ec, 1, 0, 0);
|
---|
283 | scf_grp_->sum(&ex, 1, 0, 0);
|
---|
284 | }
|
---|
285 | else {
|
---|
286 | ExEnv::err0() << indent << "Cannot yet use anything but Local matrices\n";
|
---|
287 | abort();
|
---|
288 | }
|
---|
289 | tim_exit("clhf e2");
|
---|
290 | }
|
---|
291 |
|
---|
292 | /////////////////////////////////////////////////////////////////////////////
|
---|
293 |
|
---|
294 | void
|
---|
295 | CLHF::two_body_deriv(double * tbgrad)
|
---|
296 | {
|
---|
297 | two_body_deriv_hf(tbgrad, 1.0);
|
---|
298 | }
|
---|
299 |
|
---|
300 | /////////////////////////////////////////////////////////////////////////////
|
---|
301 |
|
---|
302 | // Local Variables:
|
---|
303 | // mode: c++
|
---|
304 | // c-file-style: "ETS"
|
---|
305 | // End:
|
---|