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
38namespace sc {
39
41class 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
82
83public:
85 SpatialMOPairIter(const Ref<MOIndexSpace>& space_i, const Ref<MOIndexSpace>& space_j) :
86 MOPairIter(space_i,space_j) {};
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
165public:
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
238public:
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
285
286}
287
288#endif
289
290// Local Variables:
291// mode: c++
292// c-file-style: "ETS"
293// End:
This class produces MOPairIter objects.
Definition pairiter.h:272
Ref< SpatialMOPairIter > mopairiter(const Ref< MOIndexSpace > &space1, const Ref< MOIndexSpace > &space2)
Constructs an appropriate MOPairIter object.
RefSCDimension scdim_ab(const Ref< MOIndexSpace > &space1, const Ref< MOIndexSpace > &space2)
Constructs an appropriate RefSCDimension object for different-spin pair.
RefSCDimension scdim_aa(const Ref< MOIndexSpace > &space1, const Ref< MOIndexSpace > &space2)
Constructs an appropriate RefSCDimension object for same-spin pair.
MOPairIter gives the ordering of orbital pairs.
Definition pairiter.h:41
int nj() const
Returns the number of functions in space j.
Definition pairiter.h:67
int i() const
Returns index i.
Definition pairiter.h:69
MOPairIter(const Ref< MOIndexSpace > &space_i, const Ref< MOIndexSpace > &space_j)
Initialize an iterator for the given MO spaces.
virtual void next()=0
Move to the next pair.
virtual void start(const int first_ij=0)=0
Start the iteration.
int nij() const
Returns the number of pair combinations for this iterator.
Definition pairiter.h:73
int j() const
Returns index j.
Definition pairiter.h:71
int ni() const
Returns the number of functions in space i.
Definition pairiter.h:65
int ij() const
Returns the current iteration.
Definition pairiter.h:75
The base class for all reference counted objects.
Definition ref.h:194
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition dim.h:156
A template class that maintains references counts.
Definition ref.h:332
SpatialMOPairIter_eq gives the ordering of same-spin and different-spin orbital pairs if both orbital...
Definition pairiter.h:105
void next()
Move to the next pair.
Definition pairiter.h:178
int ij_aa() const
Returns compound index ij for alpha-alpha case.
Definition pairiter.h:190
int nij_ab() const
Returns the number of functions in alpha-beta space.
Definition pairiter.h:187
void start(const int ij_offset=0)
Initialize the iterator assuming that iteration will start with pair ij_offset.
Definition pairiter.h:171
SpatialMOPairIter_eq(const Ref< MOIndexSpace > &space1)
Initialize an iterator for the given MO spaces.
int ij_ab() const
Returns compound index ij for alpha-beta case.
Definition pairiter.h:192
int nij_aa() const
Returns the number of functions in alpha-alpha space.
Definition pairiter.h:185
int ij_ba() const
Returns compound index ij for beta-alpha case.
Definition pairiter.h:194
SpatialMOPairIter_neq gives the ordering of pairs of spatial orbitals from different spaces.
Definition pairiter.h:200
int ij_ab() const
Returns compound index ij for alpha-beta case.
Definition pairiter.h:264
void next()
Move to the next pair.
Definition pairiter.h:251
int ij_aa() const
Returns compound index ij for alpha-alpha case.
Definition pairiter.h:262
int ij_ba() const
Returns compound index ij for beta-alpha case.
Definition pairiter.h:266
int nij_ab() const
Returns the number of functions in alpha-beta space.
Definition pairiter.h:260
int nij_aa() const
Returns the number of functions in alpha-alpha space.
Definition pairiter.h:258
void start(const int ij_offset=0)
Initialize the iterator assuming that iteration will start with pair ij_offset.
Definition pairiter.h:244
SpatialMOPairIter_neq(const Ref< MOIndexSpace > &space1, const Ref< MOIndexSpace > &space2)
Initialize an iterator for the given MO spaces.
SpatialMOPairIter gives the ordering of pairs of spatial orbitals.
Definition pairiter.h:81
virtual int nij_ab() const =0
Returns the number of functions in alpha-beta space.
virtual int ij_ab() const =0
Returns compound index ij for alpha-beta case.
virtual int ij_ba() const =0
Returns compound index ij for beta-alpha case.
virtual int ij_aa() const =0
Returns compound index ij for alpha-alpha case.
virtual int nij_aa() const =0
Returns the number of functions in alpha-alpha space.
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

Generated at Thu Jul 18 2024 00:00:00 for MPQC 2.3.1 using the documentation package Doxygen 1.11.0.