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