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