TBTK
HoppingAmplitudeTree.h
Go to the documentation of this file.
1 /* Copyright 2016 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_TREE_NODE
25 #define COM_DAFER45_TBTK_TREE_NODE
26 
27 #include "TBTK/HoppingAmplitude.h"
28 #include "TBTK/IndexTree.h"
29 #include "TBTK/Serializable.h"
30 
31 #include <vector>
32 
33 namespace TBTK{
34 
41 public:
44 
53  const std::vector<unsigned int> &capacity
54  );
55 
63  HoppingAmplitudeTree(const std::string &serialization, Mode mode);
64 
66  virtual ~HoppingAmplitudeTree();
67 
71  void add(HoppingAmplitude ha);
72 
77  int getBasisSize() const;
78 
97  const HoppingAmplitudeTree* getSubTree(const Index &subspace) const;
98 
123  bool isProperSubspace(const Index &subspace) const;
124 
129 
136  int getFirstIndexInSubspace(const Index &subspaceIndex) const;
137 
144  int getLastIndexInSubspace(const Index &subspaceIndex) const;
145 
153  const std::vector<HoppingAmplitude>* getHAs(Index index) const;
154 
163  int getBasisIndex(const Index &index) const;
164 
172  Index getPhysicalIndex(int basisIndex) const;
173 
176  void generateBasisIndices();
177 
187  std::vector<Index> getIndexList(const Index &pattern) const;
188 
190  void sort(HoppingAmplitudeTree *rootNode);
191 
194  void print();
195 
199  unsigned int getSizeInBytes() const;
200 
203  class Iterator{
204  public:
207 
209  std::vector<int> currentIndex;
210 
214 
216  Iterator(const Iterator &iterator);
217 
219  Iterator(Iterator &&iterator);
220 
222  Iterator(const HoppingAmplitudeTree *tree);
223 
225  Iterator& operator=(const Iterator &rhs);
226 
228  Iterator& operator=(Iterator &&rhs);
229 
231  void reset();
232 
234  void searchNextHA();
235 
237  const HoppingAmplitude* getHA() const;
238 
240  int getMinBasisIndex() const;
241 
243  int getMaxBasisIndex() const;
244 
246  int getNumBasisIndices() const;
247  private:
251  bool searchNext(
252  const HoppingAmplitudeTree *hoppingAmplitudeTree,
253  unsigned int subindex
254  );
255  };
256 
258  Iterator begin() const;
259 
265  virtual std::string serialize(Mode mode) const;
266 private:
268  int basisIndex;
269 
271  int basisSize;
272 
289  bool isPotentialBlockSeparator;
290 
294  std::vector<HoppingAmplitude> hoppingAmplitudes;
295 
298  std::vector<HoppingAmplitudeTree> children;
299 
302  static const HoppingAmplitudeTree emptyTree;
303 
306  void add(HoppingAmplitude &ha, unsigned int subindex);
307 
311  const Index &subspace,
312  unsigned int subindex
313  ) const;
314 
318  bool isProperSubspace(
319  const Index &subspace,
320  unsigned int subindex
321  ) const;
322 
326  void getBlockIndices(IndexTree &blockIndices, Index index) const;
327 
330  const std::vector<HoppingAmplitude>* getHAs(
331  Index index,
332  unsigned int subindex
333  ) const;
334 
337  int getBasisIndex(const Index &index, unsigned int subindex) const;
338 
342  void getPhysicalIndex(int basisIndex, std::vector<int> *indices) const;
343 
345  int getMinIndex() const;
346 
348  int getMaxIndex() const;
349 
353  int generateBasisIndices(int i);
354 
358  void print(unsigned int subindex);
359 
362  HoppingAmplitude getFirstHA() const;
363 };
364 
366  return basisSize;
367 }
368 
370  const Index &subspaceIndex
371 ) const{
372  TBTKAssert(
373  isProperSubspace(subspaceIndex),
374  "HoppingAmplitudeTree::getFirstIndexInSubspace()",
375  "The index " << subspaceIndex.toString() << " is not an Index"
376  << " of a proper subspace.",
377  ""
378  );
379 
380  const HoppingAmplitudeTree *subspace = getSubTree(subspaceIndex);
381 
382  return subspace->getMinIndex();
383 }
384 
386  const Index &subspaceIndex
387 ) const{
388  TBTKAssert(
389  isProperSubspace(subspaceIndex),
390  "HoppingAmplitudeTree::getLastIndexInSubspace()",
391  "The index " << subspaceIndex.toString() << " is not an Index"
392  << " of a proper subspace.",
393  ""
394  );
395 
396  const HoppingAmplitudeTree *subspace = getSubTree(subspaceIndex);
397 
398  return subspace->getMaxIndex();
399 }
400 
401 inline unsigned int HoppingAmplitudeTree::getSizeInBytes() const{
402  unsigned int size = 0;
403  for(unsigned int n = 0; n < hoppingAmplitudes.size(); n++)
404  size += hoppingAmplitudes[n].getSizeInBytes();
405  for(unsigned int n = 0; n < children.size(); n++)
406  size += children[n].getSizeInBytes();
407 
408  size += (
409  hoppingAmplitudes.capacity() - hoppingAmplitudes.size()
410  )*sizeof(HoppingAmplitude);
411 
412  size += (
413  children.capacity() - children.size()
414  )*sizeof(HoppingAmplitudeTree);
415 
416  return size + sizeof(HoppingAmplitudeTree);
417 }
418 
419 }; //End of namespace TBTK
420 
421 #endif
Node in tree used by HoppingAmplitudeSet to store HoppingAmplitudes .
Definition: HoppingAmplitudeTree.h:40
const HoppingAmplitudeTree * getSubTree(const Index &subspace) const
std::vector< Index > getIndexList(const Index &pattern) const
int getLastIndexInSubspace(const Index &subspaceIndex) const
Definition: HoppingAmplitudeTree.h:385
Hopping amplitude from state &#39;from&#39; to state &#39;to&#39;.
Definition: Serializable.h:40
int getFirstIndexInSubspace(const Index &subspaceIndex) const
Definition: HoppingAmplitudeTree.h:369
Data structure for mapping physical indices to a linear index.
Iterator(const Iterator &iterator)
void add(HoppingAmplitude ha)
int getBasisSize() const
Definition: HoppingAmplitudeTree.h:365
Iterator & operator=(const Iterator &rhs)
const HoppingAmplitudeTree * tree
Definition: HoppingAmplitudeTree.h:206
Index getPhysicalIndex(int basisIndex) const
std::vector< int > currentIndex
Definition: HoppingAmplitudeTree.h:209
Iterator begin() const
const HoppingAmplitude * getHA() const
Definition: HoppingAmplitudeTree.h:203
unsigned int getSizeInBytes() const
Definition: HoppingAmplitudeTree.h:401
const std::vector< HoppingAmplitude > * getHAs(Index index) const
Hopping amplitude from state &#39;from&#39; to state &#39;to&#39;.
Definition: HoppingAmplitude.h:49
bool isProperSubspace(const Index &subspace) const
Data structure for mapping physical indices to a linear index.
Definition: IndexTree.h:34
Flexible physical index.
Definition: Index.h:70
Definition: ModelFactory.h:35
void sort(HoppingAmplitudeTree *rootNode)
int currentHoppingAmplitude
Definition: HoppingAmplitudeTree.h:213
Mode
Definition: Serializable.h:44
virtual std::string serialize(Mode mode) const
IndexTree getSubspaceIndices() const
int getBasisIndex(const Index &index) const
Abstract base class for serializable objects.
std::string toString() const
Definition: Index.h:265