25 #ifndef COM_DAFER45_TBTK_FOCK_SPACE
26 #define COM_DAFER45_TBTK_FOCK_SPACE
30 #include "TBTK/FockState.h"
31 #include "TBTK/FockStateMap/DefaultMap.h"
32 #include "TBTK/FockStateMap/FockStateMap.h"
33 #include "TBTK/FockStateMap/LookupTableMap.h"
34 #include "TBTK/FockStateRuleSet.h"
35 #include "TBTK/FockStateRule/FockStateRule.h"
36 #include "TBTK/FockStateRule/WrapperRule.h"
38 #include "TBTK/LadderOperator.h"
44 template<
typename BIT_REGISTER>
52 const HoppingAmplitudeSet *hoppingAmplitudeSet,
53 Statistics statistics,
54 unsigned int maxParticlesPerState
58 FockSpace(
const FockSpace &fockSpace);
64 FockSpace& operator=(
const FockSpace &rhs);
67 LadderOperator<BIT_REGISTER>
const*
const* getOperators()
const;
70 FockState<BIT_REGISTER> getVacuumState()
const;
73 unsigned int getNumFermions(
74 const FockState<BIT_REGISTER> &fockState
79 unsigned int getNumParticles(
80 const FockState<BIT_REGISTER> &fockState,
86 unsigned int getSumParticles(
87 const FockState<BIT_REGISTER> &fockState,
92 FockStateMap::FockStateMap<BIT_REGISTER>* createFockStateMap(
97 FockStateMap::FockStateMap<BIT_REGISTER>* createFockStateMap(
98 const FockStateRule::FockStateRule &rule
102 FockStateMap::FockStateMap<BIT_REGISTER>* createFockStateMap(
103 std::initializer_list<const FockStateRule::WrapperRule> rules
107 FockStateMap::FockStateMap<BIT_REGISTER>* createFockStateMap(
108 std::vector<FockStateRule::WrapperRule> rules
112 FockStateMap::FockStateMap<BIT_REGISTER>* createFockStateMap(
113 const FockStateRuleSet &rules
117 const HoppingAmplitudeSet* getHoppingAmplitudeSet()
const;
123 unsigned int exponentialDimension;
126 const HoppingAmplitudeSet *hoppingAmplitudeSet;
129 FockState<BIT_REGISTER> *vacuumState;
132 LadderOperator<BIT_REGISTER> **operators;
135 unsigned int (*stateMapCallback)(
136 const FockState<BIT_REGISTER> &fockState
144 template<
typename BIT_REGISTER>
145 FockSpace<BIT_REGISTER>::FockSpace(){
146 hoppingAmplitudeSet =
nullptr;
147 vacuumState =
nullptr;
152 template<
typename BIT_REGISTER>
153 FockSpace<BIT_REGISTER>::FockSpace(
const FockSpace &fockSpace){
154 statistics = fockSpace.statistics;
155 exponentialDimension = fockSpace.exponentialDimension;
156 hoppingAmplitudeSet = fockSpace.hoppingAmplitudeSet;
157 if(fockSpace.vacuumState ==
nullptr)
158 vacuumState =
nullptr;
160 vacuumState =
new FockState<BIT_REGISTER>(*fockSpace.vacuumState);
161 if(fockSpace.operators ==
nullptr){
165 operators =
new LadderOperator<BIT_REGISTER>*[
166 hoppingAmplitudeSet->getBasisSize()
170 n < hoppingAmplitudeSet->getBasisSize();
173 operators[n] =
new LadderOperator<BIT_REGISTER>[2];
174 for(
unsigned int c = 0; c < 2; c++)
175 operators[n][c] = fockSpace.operators[n][c];
180 template<
typename BIT_REGISTER>
181 FockSpace<BIT_REGISTER>::~FockSpace(){
182 if(operators !=
nullptr){
183 for(
int n = 0; n < hoppingAmplitudeSet->getBasisSize(); n++)
184 delete [] operators[n];
189 template<
typename BIT_REGISTER>
190 FockSpace<BIT_REGISTER>& FockSpace<BIT_REGISTER>::operator=(
194 statistics = rhs.statistics;
195 exponentialDimension = rhs.exponentialDimension;
196 if(vacuumState !=
nullptr)
198 if(rhs.vacuumState ==
nullptr){
199 vacuumState =
nullptr;
203 =
new FockState<BIT_REGISTER>(*rhs.vacuumState);
206 if(operators !=
nullptr){
209 n < hoppingAmplitudeSet->getBasisSize();
216 hoppingAmplitudeSet = rhs.hoppingAmplitudeSet;
217 if(rhs.operators ==
nullptr){
221 operators =
new LadderOperator<BIT_REGISTER>*[
222 hoppingAmplitudeSet->getBasisSize()
226 n < hoppingAmplitudeSet->getBasisSize();
230 =
new LadderOperator<BIT_REGISTER>[2];
231 for(
unsigned int c = 0; c < 2; c++)
232 operators[n][c] = rhs.operators[n][c];
240 template<
typename BIT_REGISTER>
241 LadderOperator<BIT_REGISTER>
const*
const* FockSpace<BIT_REGISTER>::getOperators(
246 template<
typename BIT_REGISTER>
247 FockState<BIT_REGISTER> FockSpace<BIT_REGISTER>::getVacuumState()
const{
251 template<
typename BIT_REGISTER>
252 unsigned int FockSpace<BIT_REGISTER>::getNumFermions(
const FockState<BIT_REGISTER> &fockState)
const{
254 case Statistics::FermiDirac:
255 return fockState.bitRegister.getNumOneBits();
256 case Statistics::BoseEinstein:
260 "FockSpace<BIT_REGISTER>::getNumFermions()",
261 "This should never happen.",
262 "Contact the developer."
267 template<
typename BIT_REGISTER>
268 unsigned int FockSpace<BIT_REGISTER>::getNumParticles(
269 const FockState<BIT_REGISTER> &fockState,
272 return operators[hoppingAmplitudeSet->getBasisIndex(index)][0].getNumParticles(fockState);
275 template<
typename BIT_REGISTER>
276 unsigned int FockSpace<BIT_REGISTER>::getSumParticles(
277 const FockState<BIT_REGISTER> &fockState,
280 if(pattern.isPatternIndex()){
281 std::vector<Index> indexList = hoppingAmplitudeSet->getIndexList(pattern);
283 unsigned int numParticles = 0;
284 for(
unsigned int n = 0; n < indexList.size(); n++){
285 numParticles += getNumParticles(
294 return getNumParticles(fockState, pattern);
298 template<
typename BIT_REGISTER>
299 FockStateMap::FockStateMap<BIT_REGISTER>* FockSpace<BIT_REGISTER>::createFockStateMap(
int numParticles)
const{
300 if(numParticles < 0){
301 FockStateMap::DefaultMap<BIT_REGISTER> *fockStateMap =
new FockStateMap::DefaultMap<BIT_REGISTER>(
308 FockStateMap::LookupTableMap<BIT_REGISTER> *fockStateMap =
new FockStateMap::LookupTableMap<BIT_REGISTER>(
312 FockState<BIT_REGISTER> fockState = getVacuumState();
313 for(
unsigned int n = 0; n < (
unsigned int)(1 << exponentialDimension); n++){
314 if(fockState.getBitRegister().getNumOneBits() == (
unsigned int)numParticles)
315 fockStateMap->addState(fockState);
317 fockState.getBitRegister()++;
324 template<
typename BIT_REGISTER>
325 FockStateMap::FockStateMap<BIT_REGISTER>* FockSpace<BIT_REGISTER>::createFockStateMap(
const FockStateRule::FockStateRule &rule)
const{
326 FockStateRuleSet fockStateRuleSet;
327 fockStateRuleSet.addFockStateRule(rule);
328 return createFockStateMap(fockStateRuleSet);
331 template<
typename BIT_REGISTER>
332 FockStateMap::FockStateMap<BIT_REGISTER>* FockSpace<BIT_REGISTER>::createFockStateMap(
333 std::initializer_list<const FockStateRule::WrapperRule> rules
335 FockStateRuleSet fockStateRuleSet;
336 for(
unsigned int n = 0; n < rules.size(); n++)
337 fockStateRuleSet.addFockStateRule(*(rules.begin()+n));
338 return createFockStateMap(fockStateRuleSet);
341 template<
typename BIT_REGISTER>
342 FockStateMap::FockStateMap<BIT_REGISTER>* FockSpace<BIT_REGISTER>::createFockStateMap(
343 std::vector<FockStateRule::WrapperRule> rules
345 FockStateRuleSet fockStateRuleSet;
346 for(
unsigned int n = 0; n < rules.size(); n++)
347 fockStateRuleSet.addFockStateRule(rules.at(n));
348 return createFockStateMap(fockStateRuleSet);
351 template<
typename BIT_REGISTER>
352 FockStateMap::FockStateMap<BIT_REGISTER>* FockSpace<BIT_REGISTER>::createFockStateMap(
353 const FockStateRuleSet &rules
355 FockStateMap::LookupTableMap<BIT_REGISTER> *fockStateMap =
new FockStateMap::LookupTableMap<BIT_REGISTER>(
359 if(rules.getSize() == 0){
360 FockStateMap::DefaultMap<BIT_REGISTER> *fockStateMap =
new FockStateMap::DefaultMap<BIT_REGISTER>(
367 if(exponentialDimension > 31){
370 "FockSpace::createFockStateMap()",
371 "FockSpaces with more than 31 states not yet supported using lookup table.",
379 FockState<BIT_REGISTER> fockState = getVacuumState();
380 for(
unsigned int n = 0; n < (
unsigned int)(1 << exponentialDimension); n++){
381 if(rules.isSatisfied(*
this, fockState))
382 fockStateMap->addState(fockState);
384 fockState.getBitRegister()++;
391 template<
typename BIT_REGISTER>
392 const HoppingAmplitudeSet* FockSpace<BIT_REGISTER>::getHoppingAmplitudeSet()
const{
393 return hoppingAmplitudeSet;