MPQC  3.0.0-alpha
tbint_batch.h
1 //
2 // tbint_batch.h
3 //
4 // Copyright (C) 2010 Edward Valeev
5 //
6 // Author: Edward Valeev <evaleev@vt.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 #ifndef _mpqc_src_lib_chemistry_qc_basis_tbint_batch_h
29 #define _mpqc_src_lib_chemistry_qc_basis_tbint_batch_h
30 
31 #include <util/ref/ref.h>
32 #include <chemistry/qc/basis/gaussbas.h>
33 
34 namespace sc {
35 
36 namespace detail {
37 template <int NumCenters, typename T>
38 struct tuple {
39  T data[NumCenters];
40  T operator[](size_t i) const {
41  return data[i];
42  }
43  T& operator[](size_t i) {
44  return data[i];
45  }
46  T operator= (const tuple<NumCenters, T> t ) {
47  for(int i = 0; i < NumCenters; i++)
48  data[i] = t[i];
49  }
50 };
51 }
52 
54 template <int NDIM>
55 class IndexRangeIterator : public RefCount {
56  public:
58 
60  virtual void init() =0;
62  virtual bool in_range() const =0;
64  virtual void next() =0;
66  virtual const IntTuple& current() const =0;
67 };
68 
70 template <int NDIM>
72  public:
74 
76  TensorIndexRangeIterator(const IntTuple& start, const IntTuple& fence) :
77  start_(start), fence_(fence), in_range_(false) {
78  }
79 
80  void init() {
81  current_ = start_;
82  next_ = current_;
83  // if range is nonempty -- find next
84  if (is_nonempty()) {
85  in_range_ = true;
86  next();
87  }
88  }
89 
90  bool in_range() const {
91  return in_range_;
92  }
93 
94  void next() {
95  in_range_ = have_next_;
96  current_ = next_;
97  have_next_ = inc(next_);
98  }
99 
100  const IntTuple& current() const {
101  return current_;
102  }
103 
104  private:
105  // return true if can increment
106  bool inc(IntTuple & s) {
107  unsigned int d = NDIM - 1;
108  ++s[d];
109  while (s[d] >= fence_[d]) {
110  if (d == 0)
111  return false;
112  s[d] = start_[d];
113  --d;
114  ++s[d];
115  }
116  }
117  // return true if range is nonempty
118  bool is_nonempty() {
119  for (unsigned int d = 0; d < NDIM; ++d)
120  if (fence_[d] <= start_[d])
121  return false;
122  return true;
123  }
124 
125  IntTuple start_;
126  IntTuple fence_;
127  IntTuple current_;
128  IntTuple next_;
129  bool in_range_;
130  bool have_next_;
131 };
132 
136 template <unsigned int NumCenters>
137 class TwoBodyIntBatch:public RefCount {
138 
139 
140  public:
142 
143  //TwoBodyIntBatch(Integral *integral,
144  // const detail::tuple<NumCenters, Ref<GaussianBasisSet> >& bs); // breaks formatting in Eclipse
145  //TwoBodyIntBatch(Integral *i, const detail::tuple<NumCenters, Ref<GaussianBasisSet> >& b);
147  integral_(i) {
148  if (NumCenters > 0)
149  bs_[0] = i->basis1();
150  if (NumCenters > 1)
151  bs_[1] = i->basis2();
152  if (NumCenters > 2)
153  bs_[2] = i->basis3();
154  if (NumCenters > 3)
155  bs_[3] - i->basis4();
156  }
157 
158 
159  virtual ~TwoBodyIntBatch(){}
160 
163  template <typename Seed> void init(const Ref<IndexRangeIterator<NumCenters> >& n, Seed s = Seed());
164 
168  virtual bool next() = 0;
169 
171  virtual const std::vector<IntTuple>& current_batch() const = 0;
172 
177  virtual const double * buffer(TwoBodyOper::type type = TwoBodyOper::eri) const = 0;
179 
182  const Ref<GaussianBasisSet>& basis(unsigned int c = 0) const;
183 
187  virtual TwoBodyOperSet::type type() const =0;
188 
190  virtual const Ref<TwoBodyOperSetDescr>& descr() const =0;
191 
194  virtual void set_integral_storage(size_t storage) = 0;
195 
198  virtual bool cloneable() const = 0;
200 
203  virtual Ref<TwoBodyIntBatch> clone() = 0;
205 
207  Integral *integral() const {
208  return integral_;
209  }
210 
211 
212 
213  protected:
214  // this is who created me
215  Ref<Integral> integral_;
216  Ref<GaussianBasisSet> bs_[NumCenters];
217 
218 
219  std::vector<double> buffer_;
220  std::vector<IntTuple> shells_in_buffer_;
221  std::vector<IntTuple> start_;
222  std::vector<IntTuple> fence_;
223  size_t buf_cap_ ;
224 };
225 
226 template <int NumCenters> struct TwoBodyIntEvalType;
227 
229 template <int NumCenters>
230 class TwoBodyIntBatchGeneric:public TwoBodyIntBatch<NumCenters> {
231 
233  typedef typename SRange::IntTuple IntTuple;
234 
235  public:
236  typedef typename TwoBodyIntEvalType<NumCenters>::value TwoBodyIntEval;
237 
239  this->buffer_.clear();
240  }
241 
242  // TwoBodyIntBatchGeneric(Integral *i, const detail::tuple<NumCenters, Ref<GaussianBasisSet> >& b) :
244  TwoBodyIntBatch<NumCenters>(tbint->integral()), tbint_(tbint) {
245 
246  in_buf_ = tbint_->buffer();
247 
248  }
249 
250  bool cloneable() const {
251  return false;
252  }
253 
255  return new TwoBodyIntBatchGeneric<NumCenters>(this->tbint_->clone());
256  }
257 
259  return tbint_->type();
260  }
262  return tbint_->descr();
263  }
264 
265  void set_integral_storage(size_t storage) {
266  this->buf_cap_ = storage;
267  this->buffer_.reserve(storage);
268  this->shells_in_buffer_.reserve(storage); // this seems dumb; but no other way to guarantee enough room (all <ss|ss>?)
269  }
270 
271  const std::vector<IntTuple>& current_batch() const {
272  return this->shells_in_buffer_ ;
273  }
274 
275 
276  const std::vector<IntTuple>& start(){
277  return this->start_ ;
278  }
279 
280  const std::vector<IntTuple>& fence(){
281  return this->fence_ ;
282  }
283 
284  const double * buffer(TwoBodyOper::type type = TwoBodyOper::eri) const {
285  return in_buf_;
286  }
287 
288  template <unsigned int> void init(const Ref<IndexRangeIterator<NumCenters> >& i, int s = int()) {
289  //
290  int sp;
291  sr_(i);
292  sr_.start();
293  if (s) {
294  for (int sp = 0; sp < s, sr_.have_next(); sp++) {
295  sr_.next();
296  }
297  }
298  }
299 
300  bool next() {
301  return 0;
302  }
303 
304 
305  private:
306 
307  const Ref<TwoBodyIntEval> tbint_;
308  const Ref<SRange > sr_;
309  const double *in_buf_;
310  const Ref<GaussianBasisSet> basis_;
311 
312 };
313 
314 
315 
316 
317 } // end of namespace sc
318 
319 #endif // end of header guard
320 // Local Variables:
321 // mode: c++
322 // c-file-style: "CLJ-CONDENSED"
323 // End:
sc::TwoBodyIntBatch::buffer
virtual const double * buffer(TwoBodyOper::type type=TwoBodyOper::eri) const =0
The computed shell integrals will be put in the buffer returned by this member.
sc::TwoBodyIntBatch::current_batch
virtual const std::vector< IntTuple > & current_batch() const =0
returns the shell indices of the current batch
sc::TwoBodyIntBatch::init
void init(const Ref< IndexRangeIterator< NumCenters > > &n, Seed s=Seed())
prepare to iterate using seed s TODO JTF implement
sc::TwoBodyIntEval::clone
virtual Ref< TwoBodyIntEval > clone()
Returns a clone of this.
sc::TwoBodyIntBatch::basis
const Ref< GaussianBasisSet > & basis(unsigned int c=0) const
Return the basis set on center c TODO JTF implement.
sc::TensorIndexRangeIterator::in_range
bool in_range() const
returns false if there are no more
Definition: tbint_batch.h:90
sc::TensorIndexRangeIterator
TensorIndexRangeIterator is a direct product of shell ranges for each center.
Definition: tbint_batch.h:71
sc::TensorIndexRangeIterator::current
const IntTuple & current() const
current shell set
Definition: tbint_batch.h:100
sc::TwoBodyIntBatchGeneric::current_batch
const std::vector< IntTuple > & current_batch() const
returns the shell indices of the current batch
Definition: tbint_batch.h:271
sc::TwoBodyIntBatchGeneric::type
TwoBodyOperSet::type type() const
Returns the type of the operator set that this object computes.
Definition: tbint_batch.h:258
sc::TwoBodyOperSet::type
type
Definition: operator.h:344
sc::TwoBodyIntBatchGeneric::buffer
const double * buffer(TwoBodyOper::type type=TwoBodyOper::eri) const
The computed shell integrals will be put in the buffer returned by this member.
Definition: tbint_batch.h:284
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::TwoBodyIntEval::integral
Integral * integral() const
Return the integral factory that was used to create this object.
Definition: tbint.h:917
sc::IndexRangeIterator::current
virtual const IntTuple & current() const =0
current shell set
sc::TwoBodyIntBatchGeneric::cloneable
bool cloneable() const
Return true if the clone member can be called.
Definition: tbint_batch.h:250
sc::TwoBodyIntEval::type
virtual TwoBodyOperSet::type type() const =0
Returns the type of the operator set that this object computes.
sc::IndexRangeIterator::in_range
virtual bool in_range() const =0
returns false if there are no more
sc::TwoBodyIntBatch::type
virtual TwoBodyOperSet::type type() const =0
Returns the type of the operator set that this object computes.
sc::TensorIndexRangeIterator::TensorIndexRangeIterator
TensorIndexRangeIterator(const IntTuple &start, const IntTuple &fence)
Constructs a [start, fence) IndexRangeIterator.
Definition: tbint_batch.h:76
sc::IndexRangeIterator::init
virtual void init()=0
initialize the iterator
sc::TwoBodyIntEvalType
returns the type of the evaluator for evaluating this set of two-body integrals
Definition: integral.h:83
sc::TwoBodyIntBatchGeneric::set_integral_storage
void set_integral_storage(size_t storage)
This storage is used to cache computed integrals.
Definition: tbint_batch.h:265
sc::TwoBodyIntBatch::cloneable
virtual bool cloneable() const =0
Return true if the clone member can be called.
sc::TwoBodyIntBatch::integral
Integral * integral() const
Return the integral factory that was used to create this object.
Definition: tbint_batch.h:207
sc::TwoBodyIntBatchGeneric::next
bool next()
compute next batch, return true if have another may need to be split into have_next and next TODO JTF...
Definition: tbint_batch.h:300
sc::Integral
The Integral abstract class acts as a factory to provide objects that compute one and two electron in...
Definition: integral.h:111
sc::TensorIndexRangeIterator::next
void next()
update current
Definition: tbint_batch.h:94
sc::TwoBodyIntBatchGeneric::clone
Ref< TwoBodyIntBatch< NumCenters > > clone()
Returns a clone of this.
Definition: tbint_batch.h:254
sc::TwoBodyIntBatch::clone
virtual Ref< TwoBodyIntBatch > clone()=0
Returns a clone of this.
sc::TwoBodyOper::eri
two-body Coulomb
Definition: operator.h:319
sc::detail::tuple
Definition: tbint_batch.h:38
sc::TwoBodyIntEval::descr
virtual const Ref< TwoBodyOperSetDescr > & descr() const =0
return the operator set descriptor
sc::TensorIndexRangeIterator::init
void init()
initialize the iterator
Definition: tbint_batch.h:80
sc::TwoBodyIntBatch
This is an abstract base type for classes that compute integrals involving two electrons and 2 functi...
Definition: tbint_batch.h:137
sc::TwoBodyIntBatch::descr
virtual const Ref< TwoBodyOperSetDescr > & descr() const =0
return the operator set descriptor
sc::TwoBodyOper::type
type
types of known two-body operators
Definition: operator.h:318
sc::TwoBodyIntBatch::next
virtual bool next()=0
compute next batch, return true if have another may need to be split into have_next and next TODO JTF...
sc::RefCount
The base class for all reference counted objects.
Definition: ref.h:192
sc::IndexRangeIterator
This is an abstract range of indices.
Definition: tbint_batch.h:55
sc::TwoBodyIntBatchGeneric
This is a generic implementation of TwoBodyIntBatch in terms of a TwoBodyInt.
Definition: tbint_batch.h:230
sc::TwoBodyIntBatch::set_integral_storage
virtual void set_integral_storage(size_t storage)=0
This storage is used to cache computed integrals.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::TwoBodyIntEval::buffer
virtual const double * buffer(TwoBodyOper::type type=TwoBodyOper::eri) const
The computed shell integrals will be put in the buffer returned by this member.
sc::TwoBodyIntBatchGeneric::descr
const Ref< TwoBodyOperSetDescr > & descr() const
return the operator set descriptor
Definition: tbint_batch.h:261
sc::IndexRangeIterator::next
virtual void next()=0
update current

Generated at Sun Jan 26 2020 23:23:57 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.