MPQC  2.3.1
pairiter.h
1 //
2 // pairiter.h
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 #ifndef _chemistry_qc_mbptr12_pairiter_h
29 #define _chemistry_qc_mbptr12_pairiter_h
30 
31 #ifdef __GNUC__
32 #pragma interface
33 #endif
34 
35 #include <stdexcept>
36 #include <chemistry/qc/mbptr12/moindexspace.h>
37 
38 namespace sc {
39 
41 class MOPairIter : public RefCount {
42 
43  protected:
44  bool i_eq_j_;
45  int ni_;
46  int nj_;
47  int i_;
48  int j_;
49  int nij_;
50  int ij_;
51 
52  public:
54  MOPairIter(const Ref<MOIndexSpace>& space_i, const Ref<MOIndexSpace>& space_j);
55  virtual ~MOPairIter();
56 
58  virtual void start(const int first_ij =0) =0;
60  virtual void next() =0;
62  virtual operator int() const =0;
63 
65  int ni() const { return ni_; }
67  int nj() const { return nj_; }
69  int i() const { return i_; }
71  int j() const { return j_; }
73  int nij() const { return nij_; }
75  int ij() const { return ij_; }
76 };
77 
78 
81 class SpatialMOPairIter : public MOPairIter {
82 
83 public:
85  SpatialMOPairIter(const Ref<MOIndexSpace>& space_i, const Ref<MOIndexSpace>& space_j) :
86  MOPairIter(space_i,space_j) {};
87  ~SpatialMOPairIter() {};
88 
90  virtual int nij_aa() const =0;
92  virtual int nij_ab() const =0;
95  virtual int ij_aa() const =0;
97  virtual int ij_ab() const =0;
99  virtual int ij_ba() const =0;
100 };
101 
106 
107  int nij_aa_;
108  int nij_ab_;
109  int ij_aa_;
110  int ij_ab_;
111  int ji_ab_;
112 
113  void init_ij(const int ij) {
114 
115  if (ij<0)
116  throw std::runtime_error("SpatialMOPairIter_eq::start() -- argument ij out of range");
117 
118  ij_ = 0;
119  const int renorm_ij = ij%nij_;
120 
121  i_ = (int)floor((sqrt(1.0+8.0*renorm_ij) - 1.0)/2.0);
122  const int i_off = i_*(i_+1)/2;
123  j_ = renorm_ij - i_off;
124 
125  ij_ab_ = i_*nj_ + j_;
126  ji_ab_ = j_*ni_ + i_;
127 
128  if (i_ != 0) {
129  const int i_off = i_*(i_-1)/2;
130  ij_aa_ = i_off + j_;
131  if (i_ == j_)
132  ij_aa_--;
133  }
134  else {
135  ij_aa_ = -1;
136  }
137  };
138 
139  void inc_ij() {
140  ij_++;
141  if (ij_ab_ == nij_ab_-1) {
142  i_ = 0;
143  j_ = 0;
144  ij_ab_ = 0;
145  ji_ab_ = 0;
146  ij_aa_ = -1;
147  }
148  else {
149  if (i_ == j_) {
150  i_++;
151  j_ = 0;
152  ji_ab_ = i_;
153  ij_ab_ = i_*nj_;
154  ij_aa_ += (i_ == j_) ? 0 : 1;
155  }
156  else {
157  j_++;
158  ji_ab_ += ni_;
159  ij_ab_++;
160  ij_aa_ += (i_ == j_) ? 0 : 1;
161  }
162  }
163  };
164 
165 public:
169 
171  void start(const int ij_offset=0)
172  {
173  ij_ = 0;
174  init_ij(ij_offset);
175  };
176 
178  void next() {
179  inc_ij();
180  };
182  operator int() const { return (nij_ > ij_);};
183 
185  int nij_aa() const { return nij_aa_; }
187  int nij_ab() const { return nij_ab_; }
190  int ij_aa() const { return (i_ == j_) ? -1 : ij_aa_; }
192  int ij_ab() const { return ij_ab_; }
194  int ij_ba() const { return ji_ab_; }
195 };
196 
197 
201 
202  int IJ_;
203 
204  void init_ij(const int ij) {
205 
206  if (ij<0)
207  throw std::runtime_error("SpatialMOPairIter_neq::start() -- argument ij out of range");
208 
209  IJ_ = 0;
210  const int renorm_ij = ij%nij_;
211 
212  i_ = renorm_ij/nj_;
213  j_ = renorm_ij - i_*nj_;
214 
215  IJ_ = i_*nj_ + j_;
216 
217  };
218 
219  void inc_ij() {
220  ij_++;
221  IJ_++;
222  if (IJ_ == nij_) {
223  i_ = 0;
224  j_ = 0;
225  IJ_ = 0;
226  }
227  else {
228  if (j_ == nj_-1) {
229  i_++;
230  j_ = 0;
231  }
232  else {
233  j_++;
234  }
235  }
236  };
237 
238 public:
240  SpatialMOPairIter_neq(const Ref<MOIndexSpace>& space1, const Ref<MOIndexSpace>& space2);
242 
244  void start(const int ij_offset=0)
245  {
246  ij_ = 0;
247  init_ij(ij_offset);
248  };
249 
251  void next() {
252  inc_ij();
253  };
255  operator int() const { return (nij_ > ij_);};
256 
258  int nij_aa() const { return nij_; }
260  int nij_ab() const { return nij_; }
262  int ij_aa() const { return IJ_; }
264  int ij_ab() const { return IJ_; }
266  int ij_ba() const { return IJ_; }
267 };
268 
269 
273 
274 public:
275  MOPairIterFactory() {}
276  ~MOPairIterFactory() {}
277 
281  RefSCDimension scdim_aa(const Ref<MOIndexSpace>& space1, const Ref<MOIndexSpace>& space2);
283  RefSCDimension scdim_ab(const Ref<MOIndexSpace>& space1, const Ref<MOIndexSpace>& space2);
284 };
285 
286 }
287 
288 #endif
289 
290 // Local Variables:
291 // mode: c++
292 // c-file-style: "ETS"
293 // End:
sc::MOPairIter::nj
int nj() const
Returns the number of functions in space j.
Definition: pairiter.h:67
sc::SpatialMOPairIter_eq::ij_ba
int ij_ba() const
Returns compound index ij for beta-alpha case.
Definition: pairiter.h:194
sc::MOPairIter
MOPairIter gives the ordering of orbital pairs.
Definition: pairiter.h:41
sc::Ref
A template class that maintains references counts.
Definition: ref.h:332
sc::SpatialMOPairIter_neq::ij_aa
int ij_aa() const
Returns compound index ij for alpha-alpha case.
Definition: pairiter.h:262
sc::MOPairIter::ij
int ij() const
Returns the current iteration.
Definition: pairiter.h:75
sc::SpatialMOPairIter_eq::SpatialMOPairIter_eq
SpatialMOPairIter_eq(const Ref< MOIndexSpace > &space1)
Initialize an iterator for the given MO spaces.
sc::SpatialMOPairIter::SpatialMOPairIter
SpatialMOPairIter(const Ref< MOIndexSpace > &space_i, const Ref< MOIndexSpace > &space_j)
Initialize a spatial pair iterator for the given MO spaces.
Definition: pairiter.h:85
sc::SpatialMOPairIter_eq::next
void next()
Move to the next pair.
Definition: pairiter.h:178
sc::MOPairIter::j
int j() const
Returns index j.
Definition: pairiter.h:71
sc::SpatialMOPairIter_neq
SpatialMOPairIter_neq gives the ordering of pairs of spatial orbitals from different spaces.
Definition: pairiter.h:200
sc::SpatialMOPairIter_neq::nij_ab
int nij_ab() const
Returns the number of functions in alpha-beta space.
Definition: pairiter.h:260
sc::SpatialMOPairIter::ij_aa
virtual int ij_aa() const =0
Returns compound index ij for alpha-alpha case.
sc::SpatialMOPairIter_neq::SpatialMOPairIter_neq
SpatialMOPairIter_neq(const Ref< MOIndexSpace > &space1, const Ref< MOIndexSpace > &space2)
Initialize an iterator for the given MO spaces.
sc::MOPairIter::start
virtual void start(const int first_ij=0)=0
Start the iteration.
sc::MOPairIterFactory::scdim_aa
RefSCDimension scdim_aa(const Ref< MOIndexSpace > &space1, const Ref< MOIndexSpace > &space2)
Constructs an appropriate RefSCDimension object for same-spin pair.
sc::SpatialMOPairIter_eq::start
void start(const int ij_offset=0)
Initialize the iterator assuming that iteration will start with pair ij_offset.
Definition: pairiter.h:171
sc::SpatialMOPairIter_neq::nij_aa
int nij_aa() const
Returns the number of functions in alpha-alpha space.
Definition: pairiter.h:258
sc::RefSCDimension
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition: dim.h:156
sc::SpatialMOPairIter_eq::ij_aa
int ij_aa() const
Returns compound index ij for alpha-alpha case.
Definition: pairiter.h:190
sc::MOPairIter::MOPairIter
MOPairIter(const Ref< MOIndexSpace > &space_i, const Ref< MOIndexSpace > &space_j)
Initialize an iterator for the given MO spaces.
sc::SpatialMOPairIter::ij_ab
virtual int ij_ab() const =0
Returns compound index ij for alpha-beta case.
sc::MOPairIter::next
virtual void next()=0
Move to the next pair.
sc::MOPairIter::i
int i() const
Returns index i.
Definition: pairiter.h:69
sc::SpatialMOPairIter_eq
SpatialMOPairIter_eq gives the ordering of same-spin and different-spin orbital pairs if both orbital...
Definition: pairiter.h:105
sc::SpatialMOPairIter_neq::ij_ab
int ij_ab() const
Returns compound index ij for alpha-beta case.
Definition: pairiter.h:264
sc::MOPairIter::ni
int ni() const
Returns the number of functions in space i.
Definition: pairiter.h:65
sc::MOPairIter::nij
int nij() const
Returns the number of pair combinations for this iterator.
Definition: pairiter.h:73
sc::MOPairIterFactory
This class produces MOPairIter objects.
Definition: pairiter.h:272
sc::SpatialMOPairIter
SpatialMOPairIter gives the ordering of pairs of spatial orbitals.
Definition: pairiter.h:81
sc::MOPairIterFactory::scdim_ab
RefSCDimension scdim_ab(const Ref< MOIndexSpace > &space1, const Ref< MOIndexSpace > &space2)
Constructs an appropriate RefSCDimension object for different-spin pair.
sc::SpatialMOPairIter::nij_aa
virtual int nij_aa() const =0
Returns the number of functions in alpha-alpha space.
sc::SpatialMOPairIter_eq::nij_aa
int nij_aa() const
Returns the number of functions in alpha-alpha space.
Definition: pairiter.h:185
sc::SpatialMOPairIter::ij_ba
virtual int ij_ba() const =0
Returns compound index ij for beta-alpha case.
sc::SpatialMOPairIter_neq::ij_ba
int ij_ba() const
Returns compound index ij for beta-alpha case.
Definition: pairiter.h:266
sc::RefCount
The base class for all reference counted objects.
Definition: ref.h:194
sc::MOPairIterFactory::mopairiter
Ref< SpatialMOPairIter > mopairiter(const Ref< MOIndexSpace > &space1, const Ref< MOIndexSpace > &space2)
Constructs an appropriate MOPairIter object.
sc::SpatialMOPairIter::nij_ab
virtual int nij_ab() const =0
Returns the number of functions in alpha-beta space.
sc::SpatialMOPairIter_neq::start
void start(const int ij_offset=0)
Initialize the iterator assuming that iteration will start with pair ij_offset.
Definition: pairiter.h:244
sc::SpatialMOPairIter_eq::ij_ab
int ij_ab() const
Returns compound index ij for alpha-beta case.
Definition: pairiter.h:192
sc::SpatialMOPairIter_eq::nij_ab
int nij_ab() const
Returns the number of functions in alpha-beta space.
Definition: pairiter.h:187
sc::SpatialMOPairIter_neq::next
void next()
Move to the next pair.
Definition: pairiter.h:251

Generated at Sun Jan 26 2020 23:33:04 for MPQC 2.3.1 using the documentation package Doxygen 1.8.16.