TBTK
FockSpace.h
1 /* Copyright 2017 Kristofer Bj√∂rnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
24 #ifndef COM_DAFER45_TBTK_FOCK_SPACE
25 #define COM_DAFER45_TBTK_FOCK_SPACE
26 
27 #include "TBTK/BitRegister.h"
28 #include "TBTK/DefaultMap.h"
30 #include "TBTK/FockState.h"
31 #include "TBTK/FockStateMap.h"
32 #include "TBTK/FockStateRule.h"
33 #include "TBTK/FockStateRuleSet.h"
35 #include "TBTK/LadderOperator.h"
36 #include "TBTK/LookupTableMap.h"
37 //#include "Model.h"
38 #include "TBTK/Statistics.h"
39 #include "TBTK/WrapperRule.h"
40 
41 namespace TBTK{
42 
43 template<typename BIT_REGISTER>
44 class FockSpace{
45 public:
47  FockSpace(
48  const HoppingAmplitudeSet *hoppingAmplitudeSet,
49  Statistics statistics,
50  unsigned int maxParticlesPerState
51  );
52 
54  ~FockSpace();
55 
58 
61 
63  unsigned int getNumFermions(
64  const FockState<BIT_REGISTER> &fockState
65  ) const;
66 
69  unsigned int getNumParticles(
70  const FockState<BIT_REGISTER> &fockState,
71  const Index &index
72  ) const;
73 
76  unsigned int getSumParticles(
77  const FockState<BIT_REGISTER> &fockState,
78  const Index &pattern
79  ) const;
80 
83  int numParticles
84  ) const;
85 
89  ) const;
90 
93  std::initializer_list<const FockStateRule::WrapperRule> rules
94  ) const;
95 
98  std::vector<FockStateRule::WrapperRule> rules
99  ) const;
100 
103  const FockStateRuleSet &rules
104  ) const;
105 
108 private:
110  Statistics statistics;
111 
113  unsigned int exponentialDimension;
114 
116  const HoppingAmplitudeSet *hoppingAmplitudeSet;
117 
119  FockState<BIT_REGISTER> *vacuumState;
120 
122  LadderOperator<BIT_REGISTER> **operators;
123 
125  unsigned int (*stateMapCallback)(
126  const FockState<BIT_REGISTER> &fockState
127  );
128 
132 };
133 
134 template<typename BIT_REGISTER>
136  for(int n = 0; n < hoppingAmplitudeSet->getBasisSize(); n++)
137  delete [] operators[n];
138  delete [] operators;
139 }
140 
141 template<typename BIT_REGISTER>
143  return operators;
144 }
145 
146 template<typename BIT_REGISTER>
148  return *vacuumState;
149 }
150 
151 template<typename BIT_REGISTER>
153  switch(statistics){
154  case Statistics::FermiDirac:
155  return fockState.bitRegister.getNumOneBits();
156  case Statistics::BoseEinstein:
157  return 0;
158  default:
159  TBTKExit(
160  "FockSpace<BIT_REGISTER>::getNumFermions()",
161  "This should never happen.",
162  "Contact the developer."
163  );
164  }
165 }
166 
167 template<typename BIT_REGISTER>
169  const FockState<BIT_REGISTER> &fockState,
170  const Index &index
171 ) const{
172  return operators[hoppingAmplitudeSet->getBasisIndex(index)][0].getNumParticles(fockState);
173 }
174 
175 template<typename BIT_REGISTER>
177  const FockState<BIT_REGISTER> &fockState,
178  const Index &pattern
179 ) const{
180  if(pattern.isPatternIndex()){
181  std::vector<Index> indexList = hoppingAmplitudeSet->getIndexList(pattern);
182 
183  unsigned int numParticles = 0;
184  for(unsigned int n = 0; n < indexList.size(); n++){
185  numParticles += getNumParticles(
186  fockState,
187  indexList.at(n)
188  );
189  }
190 
191  return numParticles;
192  }
193  else{
194  return getNumParticles(fockState, pattern);
195  }
196 }
197 
198 template<typename BIT_REGISTER>
200  if(numParticles < 0){
202  exponentialDimension
203  );
204 
205  return fockStateMap;
206  }
207  else{
209  exponentialDimension
210  );
211 
213  for(unsigned int n = 0; n < (unsigned int)(1 << exponentialDimension); n++){
214  if(fockState.getBitRegister().getNumOneBits() == (unsigned int)numParticles)
215  fockStateMap->addState(fockState);
216 
217  fockState.getBitRegister()++;
218  }
219 
220  return fockStateMap;
221  }
222 }
223 
224 template<typename BIT_REGISTER>
226  FockStateRuleSet fockStateRuleSet;
227  fockStateRuleSet.addFockStateRule(rule);
228  return createFockStateMap(fockStateRuleSet);
229 }
230 
231 template<typename BIT_REGISTER>
233  std::initializer_list<const FockStateRule::WrapperRule> rules
234 ) const{
235  FockStateRuleSet fockStateRuleSet;
236  for(unsigned int n = 0; n < rules.size(); n++)
237  fockStateRuleSet.addFockStateRule(*(rules.begin()+n));
238  return createFockStateMap(fockStateRuleSet);
239 }
240 
241 template<typename BIT_REGISTER>
243  std::vector<FockStateRule::WrapperRule> rules
244 ) const{
245  FockStateRuleSet fockStateRuleSet;
246  for(unsigned int n = 0; n < rules.size(); n++)
247  fockStateRuleSet.addFockStateRule(rules.at(n));
248  return createFockStateMap(fockStateRuleSet);
249 }
250 
251 template<typename BIT_REGISTER>
253  const FockStateRuleSet &rules
254 ) const{
256  exponentialDimension
257  );
258 
259  if(rules.getSize() == 0){
261  exponentialDimension
262  );
263 
264  return fockStateMap;
265  }
266  else{
267  if(exponentialDimension > 31){
268  //See comment bellow
269  TBTKExit(
270  "FockSpace::createFockStateMap()",
271  "FockSpaces with more than 31 states not yet supported using lookup table.",
272  ""
273  );
274  }
275 
276  //This loop is very slow for large exponential dimension and a
277  //better method should be implemented that can take advantage
278  //of the FockStateRules more directly.
280  for(unsigned int n = 0; n < (unsigned int)(1 << exponentialDimension); n++){
281  if(rules.isSatisfied(*this, fockState))
282  fockStateMap->addState(fockState);
283 
284  fockState.getBitRegister()++;
285  }
286  }
287 
288  return fockStateMap;
289 }
290 
291 template<typename BIT_REGISTER>
293  return hoppingAmplitudeSet;
294 }
295 
296 }; //End of namespace TBTK
297 
298 #endif
FockStateMap::FockStateMap< BIT_REGISTER > * createFockStateMap(int numParticles) const
Definition: FockSpace.h:199
Definition: FockSpace.h:44
HoppingAmplitude container.
Definition: HoppingAmplitudeSet.h:49
Register of bits.
unsigned int getNumFermions(const FockState< BIT_REGISTER > &fockState) const
Definition: FockSpace.h:152
int getBasisSize() const
Definition: HoppingAmplitudeSet.h:310
FockStateMap.
Enum class for Fermi-Dirac and Bose-Einstein statistics.
unsigned int getSumParticles(const FockState< BIT_REGISTER > &fockState, const Index &pattern) const
Definition: FockSpace.h:176
const HoppingAmplitudeSet * getHoppingAmplitudeSet() const
Definition: FockSpace.h:292
void addState(const FockState< BIT_REGISTER > &fockState)
Definition: LookupTableMap.h:107
FockSpace(const HoppingAmplitudeSet *hoppingAmplitudeSet, Statistics statistics, unsigned int maxParticlesPerState)
Definition: FockStateMap.h:32
void addFockStateRule(const FockStateRule::WrapperRule &fockStateRule)
Definition: FockStateRuleSet.h:89
HoppingAmplitude container.
const BIT_REGISTER & getBitRegister() const
Definition: FockState.h:107
Definition: DefaultMap.h:34
Definition: FockState.h:34
DefaultMap.
~FockSpace()
Definition: FockSpace.h:135
int getBasisIndex(const Index &index) const
Definition: HoppingAmplitudeSet.h:302
Register of bits.
LookupTableMap.
Definition: LookupTableMap.h:34
FockStateRule.
Definition: FockStateRule.h:40
unsigned int getSize() const
Definition: FockStateRuleSet.h:99
FockStateRuleSet.
FockState.
Flexible physical index.
Definition: Index.h:70
Definition: ModelFactory.h:35
unsigned int getNumParticles(const FockState< BIT_REGISTER > &fockState, const Index &index) const
Definition: FockSpace.h:168
bool isSatisfied(const FockSpace< BitRegister > &fockSpace, const FockState< BitRegister > &fockState) const
Definition: FockState.h:37
std::vector< Index > getIndexList(const Index &pattern) const
Definition: HoppingAmplitudeSet.h:338
FockState< BIT_REGISTER > getVacuumState() const
Definition: FockSpace.h:147
WrapperRule.
LadderOperator< BIT_REGISTER > ** getOperators() const
Definition: FockSpace.h:142
Definition: FockStateRuleSet.h:33
bool isPatternIndex() const
Definition: Index.h:368
Statistics
Definition: Statistics.h:29