1 //
2 // accum.cc
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.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 <util/state/stateio.h>
33 #include <chemistry/qc/wfn/accum.h>
34 #include <chemistry/qc/basis/integral.h>
35 
36 using namespace sc;
37 
38 ///////////////////////////////////////////////////////////////////////////
39 // AccumH
40 
41 static ClassDesc AccumH_cd(
42   typeid(AccumH),"AccumH",1,"public SavableState",
43   0, 0, 0);
44 
AccumH()45 AccumH::AccumH()
46 {
47 }
48 
AccumH(StateIn & s)49 AccumH::AccumH(StateIn&s) :
50   SavableState(s)
51 {
52   wfn_ << SavableState::restore_state(s);
53 }
54 
AccumH(const Ref<KeyVal> & keyval)55 AccumH::AccumH(const Ref<KeyVal>& keyval)
56 {
57   wfn_ << keyval->describedclassvalue("wavefunction");
58 }
59 
~AccumH()60 AccumH::~AccumH()
61 {
62 }
63 
64 void
save_data_state(StateOut & s)65 AccumH::save_data_state(StateOut& s)
66 {
67   SavableState::save_state(wfn_.pointer(),s);
68 }
69 
70 void
init(const Ref<Wavefunction> & w)71 AccumH::init(const Ref<Wavefunction>& w)
72 {
73   wfn_ = w;
74 }
75 
76 void
done()77 AccumH::done()
78 {
79   wfn_ = 0;
80 }
81 
82 void
print_summary()83 AccumH::print_summary()
84 {
85 }
86 
87 double
e()88 AccumH::e()
89 {
90   return 0.0;
91 }
92 
93 ///////////////////////////////////////////////////////////////////////////
94 // AccumHNull
95 
96 static ClassDesc AccumHNull_cd(
97   typeid(AccumHNull),"AccumHNull",1,"public AccumH",
98   create<AccumHNull>, create<AccumHNull>, create<AccumHNull>);
99 
AccumHNull()100 AccumHNull::AccumHNull()
101 {
102 }
103 
AccumHNull(StateIn & s)104 AccumHNull::AccumHNull(StateIn&s) :
105   SavableState(s),
106   AccumH(s)
107 {
108 }
109 
AccumHNull(const Ref<KeyVal> & keyval)110 AccumHNull::AccumHNull(const Ref<KeyVal>& keyval) :
111   AccumH(keyval)
112 {
113 }
114 
~AccumHNull()115 AccumHNull::~AccumHNull()
116 {
117 }
118 
119 void
save_data_state(StateOut & s)120 AccumHNull::save_data_state(StateOut& s)
121 {
122   AccumH::save_data_state(s);
123 }
124 
125 void
accum(const RefSymmSCMatrix & h)126 AccumHNull::accum(const RefSymmSCMatrix& h)
127 {
128 }
129 
130 /////////////////////////////////////////////////////////////////////////////
131 // SumAccumH
132 
133 static ClassDesc SumAccumH_cd(
134   typeid(SumAccumH),"SumAccumH",1,"public AccumH",
135   0, create<SumAccumH>, create<SumAccumH>);
136 
SumAccumH(StateIn & s)137 SumAccumH::SumAccumH(StateIn& s) :
138   SavableState(s),
139   AccumH(s)
140 {
141   s.get(n_);
142   accums_ = new Ref<AccumH>[n_];
143   for (int i=0; i < n_; i++)
144     accums_[i] << SavableState::restore_state(s);
145 }
146 
SumAccumH(const Ref<KeyVal> & keyval)147 SumAccumH::SumAccumH(const Ref<KeyVal>& keyval) :
148   AccumH(keyval)
149 {
150   n_ = keyval->count("accums");
151   accums_ = new Ref<AccumH>[n_];
152   for (int i=0; i < n_; i++)
153     accums_[i] << keyval->describedclassvalue("accums", i);
154 }
155 
~SumAccumH()156 SumAccumH::~SumAccumH()
157 {
158   if (accums_) {
159     delete[] accums_;
160     accums_=0;
161   }
162   n_=0;
163 }
164 
165 void
save_data_state(StateOut & s)166 SumAccumH::save_data_state(StateOut& s)
167 {
168   AccumH::save_data_state(s);
169   s.put(n_);
170   for (int i=0; i < n_; i++)
171     SavableState::save_state(accums_[i].pointer(),s);
172 }
173 
174 void
init(const Ref<Wavefunction> & w)175 SumAccumH::init(const Ref<Wavefunction>& w)
176 {
177   for (int i=0; i < n_; i++)
178     accums_[i]->init(w);
179 }
180 
181 void
accum(const RefSymmSCMatrix & h)182 SumAccumH::accum(const RefSymmSCMatrix& h)
183 {
184   for (int i=0; i < n_; i++)
185     accums_[i]->accum(h);
186 }
187 
188 void
done()189 SumAccumH::done()
190 {
191   for (int i=0; i < n_; i++)
192     accums_[i]->done();
193 }
194 
195 double
e()196 SumAccumH::e()
197 {
198   double te = 0.0;
199 
200   for (int i=0; i < n_; i++) {
201     te += accums_[i]->e();
202   }
203 
204   return te;
205 }
206 
207 /////////////////////////////////////////////////////////////////////////////
208 
209 // Local Variables:
210 // mode: c++
211 // c-file-style: "ETS"
212 // End:
213