TBTK
LadderOperator.h
1 #ifndef COM_DAFER45_TBTK_LADDER_OPERATOR
2 #define COM_DAFER45_TBTK_LADDER_OPERATOR
3 
4 #include "TBTK/FockState.h"
6 #include "TBTK/Statistics.h"
7 
8 namespace TBTK{
9 
10 template<typename BIT_REGISTER>
11 class LadderOperator{
12 public:
14  enum class Type {Creation, Annihilation};
15 
18 
21  Type type,
22  Statistics statistics,
23  const HoppingAmplitudeSet *hoppingAmplitudeSet,
24  unsigned int state,
25  unsigned int numBitsPerState,
26  unsigned int maxOccupation,
27  const FockState<BIT_REGISTER> &templateState,
28  const BIT_REGISTER &fermionMask
29  );
30 
33 
35  Type getType() const;
36 
38  const Index getPhysicalIndex() const;
39 
41  unsigned int getState() const;
42 
44  unsigned int getNumParticles(
45  const FockState<BIT_REGISTER> &fockState
46  ) const;
47 
50 private:
52  Type type;
53 
55  Statistics statistics;
56 
58  const HoppingAmplitudeSet *hoppingAmplitudeSet;
59 
61  unsigned int state;
62 
64  BIT_REGISTER stateMask;
65 
67  BIT_REGISTER leastSignificantBit;
68 
70  unsigned int leastSignificantBitIndex;
71 
73  BIT_REGISTER maxOccupation;
74 
77  BIT_REGISTER moreSignificantFermionMask;
78 };
79 
80 template<typename BIT_REGISTER>
82 }
83 
84 template<typename BIT_REGISTER>
86  Type type,
87  Statistics statistics,
88  const HoppingAmplitudeSet *hoppingAmplitudeSet,
89  unsigned int state,
90  unsigned int numBitsPerState,
91  unsigned int maxOccupation,
92  const FockState<BIT_REGISTER> &templateState,
93  const BIT_REGISTER &fermionMask
94 ) :
95  stateMask(templateState.bitRegister),
96  leastSignificantBit(templateState.bitRegister),
97  maxOccupation(templateState.bitRegister),
98  moreSignificantFermionMask(fermionMask)
99 {
100  this->type = type;
101  this->statistics = statistics;
102  this->hoppingAmplitudeSet = hoppingAmplitudeSet;
103  this->state = state;
104 
105  leastSignificantBitIndex = state*numBitsPerState;
106 
107  for(unsigned int n = 0; n < stateMask.getNumBits(); n++){
108  if(n >= leastSignificantBitIndex && n < leastSignificantBitIndex + numBitsPerState)
109  stateMask.setBit(n, 1);
110  else
111  stateMask.setBit(n, 0);
112 
113  if(n == leastSignificantBitIndex)
114  leastSignificantBit.setBit(n, 1);
115  else
116  leastSignificantBit.setBit(n, 0);
117  }
118 
119  this->maxOccupation = maxOccupation;
120  this->maxOccupation = (this->maxOccupation << leastSignificantBitIndex);
121 
122  for(unsigned int n = 0; n < moreSignificantFermionMask.getNumBits(); n++){
123  this->moreSignificantFermionMask.setBit(n, false);
124  if(leastSignificantBit.getBit(n))
125  break;
126  }
127 }
128 
129 template<typename BIT_REGISTER>
131 }
132 
133 template<typename BIT_REGISTER>
135  return type;
136 }
137 
138 template<typename BIT_REGISTER>
140  return hoppingAmplitudeSet->getPhysicalIndex(state);
141 }
142 
143 template<typename BIT_REGISTER>
145  return state;
146 }
147 
148 template<typename BIT_REGISTER>
150  const FockState<BIT_REGISTER> &fockState
151 ) const{
152  return ((fockState.getBitRegister() & stateMask) >> leastSignificantBitIndex).toUnsignedInt();
153 }
154 
155 template<typename BIT_REGISTER>
158 ) const{
159  switch(type){
160  case Type::Creation:
161  if((rhs.bitRegister & stateMask) == maxOccupation){
162  rhs.bitRegister.setMostSignificantBit();
163  break;
164  }
165  rhs.bitRegister += leastSignificantBit;
166  break;
167  case Type::Annihilation:
168  if(!(rhs.bitRegister & stateMask).toBool()){
169  rhs.bitRegister.setMostSignificantBit();
170  break;
171  }
172  rhs.bitRegister -= leastSignificantBit;
173  break;
174  default:
175  TBTKExit(
176  "LadderOperator<BIT_REGISTER>::operator*()",
177  "This should never happen.",
178  "Contact the developer."
179  );
180  }
181 
182  switch(statistics){
183  case Statistics::FermiDirac:
184  rhs.prefactor *= pow(-1, (rhs.bitRegister & moreSignificantFermionMask).getNumOneBits());
185  break;
186  case Statistics::BoseEinstein:
187  break;
188  default:
189  TBTKExit(
190  "LadderOperator<BIT_REGISTER>::operator*()",
191  "This should never happen.",
192  "Contact the developer."
193  );
194  }
195 
196  return rhs;
197 }
198 
199 }; //End of namespace TBTK
200 
201 #endif
unsigned int getState() const
Definition: LadderOperator.h:144
Type getType() const
Definition: LadderOperator.h:134
Type
Definition: LadderOperator.h:14
HoppingAmplitude container.
Definition: HoppingAmplitudeSet.h:50
Enum class for Fermi-Dirac and Bose-Einstein statistics.
FockState< BIT_REGISTER > & operator*(FockState< BIT_REGISTER > &rhs) const
Definition: LadderOperator.h:156
const Index getPhysicalIndex() const
Definition: LadderOperator.h:139
~LadderOperator()
Definition: LadderOperator.h:130
Index getPhysicalIndex(int basisIndex) const
LadderOperator()
Definition: LadderOperator.h:81
HoppingAmplitude container.
const BIT_REGISTER & getBitRegister() const
Definition: FockState.h:107
unsigned int getNumParticles(const FockState< BIT_REGISTER > &fockState) const
Definition: LadderOperator.h:149
FockState.
Flexible physical index.
Definition: Index.h:69
Definition: ModelFactory.h:35
Definition: FockState.h:37
Statistics
Definition: Statistics.h:29