QNANO
CdaggerCdaggerCC_Iterator.h
1 #ifndef QNANO_NEW_CDAGGERCDAGGERCC_ITERATOR_DEFINED_H
2 #define QNANO_NEW_CDAGGERCDAGGERCC_ITERATOR_DEFINED_H
3 
4 #include "manybody/CdaggerC_Iterator.h"
5 #include <iostream>
6 #include <cstdlib>
7 
8 
24 protected:
25  CdaggerC_Iterator it_delta, it1, it2;
26  int delta_counter, rank;
27 
28  int n1, n2, m1, m2, n_max;
29  double sign;
30 
31 public:
32 
33  bool done()const{
34  return it2.done();
35  }
36  int get_n1()const{ return n1; }
37  int get_n2()const{ return n2; }
38  int get_m1()const{ return m1; }
39  int get_m2()const{ return m2; }
40  double get_sign()const{ return sign; }
41 
42  const Fermion_Index& get_fi()const{
43  if(delta_counter<rank)return it_delta.get_fi();
44  return it1.get_fi();
45  }
46 
47 
48  //checks if current state make sense. If not, calls operator++
49  CdaggerCdaggerCC_Iterator& adjust(){
50  if(delta_counter<rank){
51 
52  n2=m2=it_delta.get_fi()[delta_counter];
53 //std::cout<<"."<<it_delta.get_fi()<<" _n2: "<<n2<<std::endl;
54  if(n2==it_delta.get_n())return operator++();
55  sign=it_delta.get_sign();
56  n1=it_delta.get_n();
57  m1=it_delta.get_m();
58  // c^dagger c c^dagger c part
59  }else{
60  n2=it2.get_n();
61  m1=it2.get_m();
62  if(it1.done()){
63  ++it2;
64  if(it2.done())return *this;
65  it1.setup(it2.get_fi(),n_max);
66  n2=it2.get_n();
67  m1=it2.get_m();
68  }
69  n1=it1.get_n();
70  m2=it1.get_m();
71  sign=-it1.get_sign()*it2.get_sign();
72  if(m2==n2)return operator++();
73  }
74 
75  return *this;
76  }
77 
78  CdaggerCdaggerCC_Iterator& operator++(){
79  //first: treat special case where inner indices are the same
80  if(delta_counter<rank){
81  delta_counter++;
82  if(delta_counter>=rank){
83  ++it_delta;
84  delta_counter=0;
85  if(it_delta.done())delta_counter=rank;
86  }
87  }else{
88  ++it1;
89  }
90  return adjust();
91  }
92  CdaggerCdaggerCC_Iterator& operator++(int){
93  return operator++();
94  }
95 
96  CdaggerCdaggerCC_Iterator(const Fermion_Index &fi, int n_max_)
97  : n_max(n_max_){
98 
99  rank=fi.size();
100  if(rank<2)n_max=0;
101  it_delta.setup(fi,n_max);
102  it1.setup(fi,n_max);
103  it2.setup(fi,n_max);
104 
105  if(rank<2)return;
106 
107 
108  if(n_max<rank){
109  std::cerr<<"CdaggerCdaggerCC_Iterator::constructor: n_max<rank"<<std::endl;
110  exit(1);
111  }
112 
113  sign=it_delta.get_sign();
114  n1=it_delta.get_n();
115  m1=it_delta.get_m();
116  delta_counter=0;
117  n2=m2=0; //it_delta.get_fi()[0];
118  adjust();
119  }
120 };
121 
122 
123 #endif
Definition: Fermion_Index.h:19
Definition: CdaggerC_Iterator.h:6
Definition: CdaggerCdaggerCC_Iterator.h:23