MPQC  3.0.0-alpha
pairiter.h
1 //
2 // pairiter.h
3 //
4 // Copyright (C) 2004 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 _math_mmisc_pairiter_h
29 #define _math_mmisc_pairiter_h
30 
31 #include <stdexcept>
32 #include <cmath>
33 #include <util/ref/ref.h>
34 
35 namespace sc {
36 
38 class MOPairIter : public RefCount {
39  private:
41  static const int classdebug_ = 0;
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  int classdebug() const {
53  return classdebug_;
54  }
55 
56  public:
58  MOPairIter(unsigned int n_i, unsigned int n_j);
59  virtual ~MOPairIter();
60 
62  virtual void start(const int first_ij =0) =0;
64  virtual void next() =0;
66  virtual operator int() const =0;
67 
69  int ni() const { return ni_; }
71  int nj() const { return nj_; }
73  int i() const { return i_; }
75  int j() const { return j_; }
77  int nij() const { return nij_; }
79  int ij() const { return ij_; }
80 };
81 
82 
85 class SpatialMOPairIter : public MOPairIter {
86 
87 public:
89  SpatialMOPairIter(unsigned int n_i, unsigned int n_j) :
90  MOPairIter(n_i,n_j) {};
91  ~SpatialMOPairIter() {};
92 
94  virtual int nij_aa() const =0;
96  virtual int nij_ab() const =0;
99  virtual int ij_aa() const =0;
101  virtual int ij_ab() const =0;
103  virtual int ij_ba() const =0;
104 };
105 
110 
111  int nij_aa_;
112  int nij_ab_;
113  int ij_aa_;
114  int ij_ab_;
115  int ji_ab_;
116 
117  void init_ij(const int ij) {
118 
119  if (ij<0)
120  throw std::runtime_error("SpatialMOPairIter_eq::start() -- argument ij out of range");
121 
122  ij_ = 0;
123  const int renorm_ij = ij%nij_;
124 
125  i_ = (int)floor((sqrt(1.0+8.0*renorm_ij) - 1.0)/2.0);
126  const int i_off = i_*(i_+1)/2;
127  j_ = renorm_ij - i_off;
128 
129  ij_ab_ = i_*nj_ + j_;
130  ji_ab_ = j_*ni_ + i_;
131 
132  if (i_ != 0) {
133  const int i_off = i_*(i_-1)/2;
134  ij_aa_ = i_off + j_;
135  if (i_ == j_)
136  ij_aa_--;
137  }
138  else {
139  ij_aa_ = -1;
140  }
141  };
142 
143  void inc_ij() {
144  ij_++;
145  if (ij_ab_ == nij_ab_-1) {
146  i_ = 0;
147  j_ = 0;
148  ij_ab_ = 0;
149  ji_ab_ = 0;
150  ij_aa_ = -1;
151  }
152  else {
153  if (i_ == j_) {
154  i_++;
155  j_ = 0;
156  ji_ab_ = i_;
157  ij_ab_ = i_*nj_;
158  ij_aa_ += (i_ == j_) ? 0 : 1;
159  }
160  else {
161  j_++;
162  ji_ab_ += ni_;
163  ij_ab_++;
164  ij_aa_ += (i_ == j_) ? 0 : 1;
165  }
166  }
167  };
168 
169 public:
171  SpatialMOPairIter_eq(unsigned int n);
173 
175  void start(const int ij_offset=0)
176  {
177  ij_ = 0;
178  init_ij(ij_offset);
179  };
180 
182  void next() {
183  inc_ij();
184  };
186  operator int() const { return (nij_ > ij_);};
187 
189  int nij_aa() const { return nij_aa_; }
191  int nij_ab() const { return nij_ab_; }
194  int ij_aa() const { return (i_ == j_) ? -1 : ij_aa_; }
196  int ij_ab() const { return ij_ab_; }
198  int ij_ba() const { return ji_ab_; }
199 };
200 
201 
205 
206  int IJ_;
207 
208  void init_ij(const int ij) {
209 
210  if (ij<0)
211  throw std::runtime_error("SpatialMOPairIter_neq::start() -- argument ij out of range");
212 
213  IJ_ = 0;
214  const int renorm_ij = ij%nij_;
215 
216  i_ = renorm_ij/nj_;
217  j_ = renorm_ij - i_*nj_;
218 
219  IJ_ = i_*nj_ + j_;
220 
221  };
222 
223  void inc_ij() {
224  ij_++;
225  IJ_++;
226  if (IJ_ == nij_) {
227  i_ = 0;
228  j_ = 0;
229  IJ_ = 0;
230  }
231  else {
232  if (j_ == nj_-1) {
233  i_++;
234  j_ = 0;
235  }
236  else {
237  j_++;
238  }
239  }
240  };
241 
242 public:
244  SpatialMOPairIter_neq(unsigned int n_i, unsigned int n_j);
246 
248  void start(const int ij_offset=0)
249  {
250  ij_ = 0;
251  init_ij(ij_offset);
252  };
253 
255  void next() {
256  inc_ij();
257  };
259  operator int() const { return (nij_ > ij_);};
260 
262  int nij_aa() const { return nij_; }
264  int nij_ab() const { return nij_; }
266  int ij_aa() const { return IJ_; }
268  int ij_ab() const { return IJ_; }
270  int ij_ba() const { return IJ_; }
271 };
272 
277 {
278  public:
279  SpinMOPairIter(unsigned int n_i, unsigned int n_j, bool i_eq_j);
280  ~SpinMOPairIter();
281 
283  void start(const int first_ij=0);
285  void next();
287  operator int() const;
288 
289  private:
290  bool i_eq_j_;
291  int IJ_;
292 };
293 
294 #if 0
295 
299 class PureSpinPairIter : public MOPairIter
300 {
301  public:
303  PureSpinPairIter(const Ref<OrbitalSpace>& space,
304  const PureSpinCase2& S);
305  ~PureSpinPairIter();
306 
308  void start(const int first_ij=0);
310  void next();
312  operator int() const;
313 
314  private:
315  PureSpinCase2 spin_;
316  int IJ_;
317 };
318 #endif
319 
320 namespace fastpairiter {
321  enum PairSymm { Symm = 1, AntiSymm = -1, ASymm = 0};
328  template <PairSymm PSymm>
330  {
331  public:
332  MOPairIter(int nI, int nJ);
333  ~MOPairIter();
334 
336  void start();
338  void next();
340  operator int() const;
342  int ij() const { return IJ_; }
344  int i() const { return I_; }
346  int j() const { return J_; }
350  int ij(int i, int j) const;
351  int nij() const { return nIJ_; }
352 
353  private:
354  int nIJ_;
355  int IJ_;
356  int nI_;
357  int nJ_;
358  int I_;
359  int J_;
360  void init();
361  };
362 
364  template <PairSymm PSymm>
365  std::size_t npair(unsigned int nI, unsigned int nJ);
366 
367 } // namespace fastpairiter
368 
369 }
370 
371 #include <math/mmisc/pairiter.impl.h>
372 
373 #endif
374 
375 // Local Variables:
376 // mode: c++
377 // c-file-style: "ETS"
378 // End:
sc::fastpairiter::MOPairIter
SpinMOPairIter iterates over pairs of spinorbitals of spin case Spin12 This class differs from other ...
Definition: pairiter.h:329
sc::MOPairIter::nj
int nj() const
Returns the number of functions in space j.
Definition: pairiter.h:71
sc::SpatialMOPairIter_eq::ij_ba
int ij_ba() const
Returns compound index ij for beta-alpha case.
Definition: pairiter.h:198
sc::MOPairIter
MOPairIter gives the ordering of orbital pairs.
Definition: pairiter.h:38
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::SpatialMOPairIter_neq::ij_aa
int ij_aa() const
Returns compound index ij for alpha-alpha case.
Definition: pairiter.h:266
sc::MOPairIter::ij
int ij() const
Returns the current iteration.
Definition: pairiter.h:79
sc::SpatialMOPairIter_neq::SpatialMOPairIter_neq
SpatialMOPairIter_neq(unsigned int n_i, unsigned int n_j)
Initialize an iterator for the given MO spaces.
sc::SpatialMOPairIter_eq::SpatialMOPairIter_eq
SpatialMOPairIter_eq(unsigned int n)
Initialize an iterator for the given MO spaces.
sc::SpatialMOPairIter_eq::next
void next()
Move to the next pair.
Definition: pairiter.h:182
sc::MOPairIter::j
int j() const
Returns index j.
Definition: pairiter.h:75
sc::SpatialMOPairIter_neq
SpatialMOPairIter_neq gives the ordering of pairs of spatial orbitals from different spaces.
Definition: pairiter.h:204
sc::SpatialMOPairIter_neq::nij_ab
int nij_ab() const
Returns the number of functions in alpha-beta space.
Definition: pairiter.h:264
sc::SpatialMOPairIter::ij_aa
virtual int ij_aa() const =0
Returns compound index ij for alpha-alpha case.
sc::MOPairIter::start
virtual void start(const int first_ij=0)=0
Start the iteration.
sc::SpinMOPairIter::start
void start(const int first_ij=0)
Start the iteration.
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:175
sc::SpatialMOPairIter_neq::nij_aa
int nij_aa() const
Returns the number of functions in alpha-alpha space.
Definition: pairiter.h:262
sc::SpatialMOPairIter_eq::ij_aa
int ij_aa() const
Returns compound index ij for alpha-alpha case.
Definition: pairiter.h:194
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:73
sc::SpatialMOPairIter_eq
SpatialMOPairIter_eq gives the ordering of same-spin and different-spin orbital pairs if both orbital...
Definition: pairiter.h:109
sc::SpatialMOPairIter_neq::ij_ab
int ij_ab() const
Returns compound index ij for alpha-beta case.
Definition: pairiter.h:268
sc::fastpairiter::MOPairIter::ij
int ij() const
current composite index
Definition: pairiter.h:342
sc::SpatialMOPairIter::SpatialMOPairIter
SpatialMOPairIter(unsigned int n_i, unsigned int n_j)
Initialize a spatial pair iterator for the given MO spaces.
Definition: pairiter.h:89
sc::MOPairIter::ni
int ni() const
Returns the number of functions in space i.
Definition: pairiter.h:69
sc::SpinMOPairIter
SpinMOPairIter iterates over pairs of spinorbitals.
Definition: pairiter.h:276
sc::fastpairiter::MOPairIter::next
void next()
Move to the next pair.
sc::MOPairIter::nij
int nij() const
Returns the number of pair combinations for this iterator.
Definition: pairiter.h:77
sc::fastpairiter::MOPairIter::start
void start()
Start the iteration.
Definition: pairiter.impl.h:42
sc::SpatialMOPairIter
SpatialMOPairIter gives the ordering of pairs of spatial orbitals.
Definition: pairiter.h:85
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:189
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:270
sc::RefCount
The base class for all reference counted objects.
Definition: ref.h:192
sc::fastpairiter::MOPairIter::i
int i() const
current index 1
Definition: pairiter.h:344
sc::SpatialMOPairIter::nij_ab
virtual int nij_ab() const =0
Returns the number of functions in alpha-beta space.
sc::fastpairiter::MOPairIter::j
int j() const
current index 2
Definition: pairiter.h:346
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:248
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::SpatialMOPairIter_eq::ij_ab
int ij_ab() const
Returns compound index ij for alpha-beta case.
Definition: pairiter.h:196
sc::SpatialMOPairIter_eq::nij_ab
int nij_ab() const
Returns the number of functions in alpha-beta space.
Definition: pairiter.h:191
sc::SpatialMOPairIter_neq::next
void next()
Move to the next pair.
Definition: pairiter.h:255
sc::SpinMOPairIter::next
void next()
Move to the next pair.
sc::MOPairIter::MOPairIter
MOPairIter(unsigned int n_i, unsigned int n_j)
Initialize an iterator for the MO space dimensions.

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