24 #ifndef COM_DAFER45_TBTK_LADDER_OPERATOR
25 #define COM_DAFER45_TBTK_LADDER_OPERATOR
27 #include "TBTK/FockState.h"
33 template<
typename BIT_REGISTER>
37 enum class Type {Creation, Annihilation};
45 Statistics statistics,
46 const HoppingAmplitudeSet *hoppingAmplitudeSet,
48 unsigned int numBitsPerState,
49 unsigned int maxOccupation,
50 const FockState<BIT_REGISTER> &templateState,
51 const BIT_REGISTER &fermionMask
61 const Index getPhysicalIndex()
const;
64 unsigned int getState()
const;
67 unsigned int getNumParticles(
68 const FockState<BIT_REGISTER> &fockState
72 FockState<BIT_REGISTER>&
operator*(FockState<BIT_REGISTER> &rhs)
const;
81 const HoppingAmplitudeSet *hoppingAmplitudeSet;
87 BIT_REGISTER stateMask;
90 BIT_REGISTER leastSignificantBit;
93 unsigned int leastSignificantBitIndex;
96 BIT_REGISTER maxOccupation;
100 BIT_REGISTER moreSignificantFermionMask;
103 template<
typename BIT_REGISTER>
104 LadderOperator<BIT_REGISTER>::LadderOperator(){
107 template<
typename BIT_REGISTER>
108 LadderOperator<BIT_REGISTER>::LadderOperator(
110 Statistics statistics,
111 const HoppingAmplitudeSet *hoppingAmplitudeSet,
113 unsigned int numBitsPerState,
114 unsigned int maxOccupation,
115 const FockState<BIT_REGISTER> &templateState,
116 const BIT_REGISTER &fermionMask
118 stateMask(templateState.bitRegister),
119 leastSignificantBit(templateState.bitRegister),
120 maxOccupation(templateState.bitRegister),
121 moreSignificantFermionMask(fermionMask)
124 this->statistics = statistics;
125 this->hoppingAmplitudeSet = hoppingAmplitudeSet;
128 leastSignificantBitIndex = state*numBitsPerState;
130 for(
unsigned int n = 0; n < stateMask.getNumBits(); n++){
131 if(n >= leastSignificantBitIndex && n < leastSignificantBitIndex + numBitsPerState)
132 stateMask.setBit(n, 1);
134 stateMask.setBit(n, 0);
136 if(n == leastSignificantBitIndex)
137 leastSignificantBit.setBit(n, 1);
139 leastSignificantBit.setBit(n, 0);
142 this->maxOccupation = maxOccupation;
143 this->maxOccupation = (this->maxOccupation << leastSignificantBitIndex);
145 for(
unsigned int n = 0; n < moreSignificantFermionMask.getNumBits(); n++){
146 this->moreSignificantFermionMask.setBit(n,
false);
147 if(leastSignificantBit.getBit(n))
152 template<
typename BIT_REGISTER>
153 LadderOperator<BIT_REGISTER>::~LadderOperator(){
156 template<
typename BIT_REGISTER>
157 typename LadderOperator<BIT_REGISTER>::Type LadderOperator<BIT_REGISTER>::getType()
const{
161 template<
typename BIT_REGISTER>
162 const Index LadderOperator<BIT_REGISTER>::getPhysicalIndex()
const{
163 return hoppingAmplitudeSet->getPhysicalIndex(state);
166 template<
typename BIT_REGISTER>
167 unsigned int LadderOperator<BIT_REGISTER>::getState()
const{
171 template<
typename BIT_REGISTER>
172 unsigned int LadderOperator<BIT_REGISTER>::getNumParticles(
173 const FockState<BIT_REGISTER> &fockState
175 return ((fockState.getBitRegister() & stateMask) >> leastSignificantBitIndex).toUnsignedInt();
178 template<
typename BIT_REGISTER>
179 FockState<BIT_REGISTER>& LadderOperator<BIT_REGISTER>::operator*(
180 FockState<BIT_REGISTER> &rhs
184 if((rhs.bitRegister & stateMask) == maxOccupation){
185 rhs.bitRegister.setMostSignificantBit();
188 rhs.bitRegister += leastSignificantBit;
190 case Type::Annihilation:
191 if(!(rhs.bitRegister & stateMask).toBool()){
192 rhs.bitRegister.setMostSignificantBit();
195 rhs.bitRegister -= leastSignificantBit;
199 "LadderOperator<BIT_REGISTER>::operator*()",
200 "This should never happen.",
201 "Contact the developer."
206 case Statistics::FermiDirac:
207 rhs.prefactor *=
pow(-1, (rhs.bitRegister & moreSignificantFermionMask).getNumOneBits());
209 case Statistics::BoseEinstein:
213 "LadderOperator<BIT_REGISTER>::operator*()",
214 "This should never happen.",
215 "Contact the developer."