TBTK
HoppingAmplitudeSet.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 
23 #ifndef COM_DAFER45_TBTK_HOPPING_AMPLITUDE_SET
24 #define COM_DAFER45_TBTK_HOPPING_AMPLITUDE_SET
25 
26 #include "TBTK/HoppingAmplitude.h"
28 #include "TBTK/IndexTree.h"
29 #include "TBTK/Serializable.h"
30 #include "TBTK/Streams.h"
31 #include "TBTK/TBTKMacros.h"
32 
33 #include <complex>
34 #include <vector>
35 
36 namespace TBTK{
37 
50 public:
53 
56  HoppingAmplitudeSet(const std::vector<unsigned int> &capacity);
57 
59  HoppingAmplitudeSet(const HoppingAmplitudeSet &hoppingAmplitudeSet);
60 
62  HoppingAmplitudeSet(HoppingAmplitudeSet &&hoppingAmplitudeSet);
63 
66  HoppingAmplitudeSet(const std::string &serializeation, Mode mode);
67 
69  virtual ~HoppingAmplitudeSet();
70 
73 
76 
81 
86 
91  const std::vector<HoppingAmplitude>* getHAs(Index index) const;
92 
96  int getBasisIndex(const Index &index) const;
97 
99  Index getPhysicalIndex(int basisIndex) const;
100 
102  int getBasisSize() const;
103 
107  bool isProperSubspace(const Index &subspace);
108 
111 
114  void construct();
115 
117  bool getIsConstructed() const;
118 
120  std::vector<Index> getIndexList(const Index &pattern) const;
121 
123  int getFirstIndexInBlock(const Index &blockIndex) const;
124 
126  int getLastIndexInBlock(const Index &blockIndex) const;
127 
129  void sort();
130 
132  void constructCOO();
133 
135  void destructCOO();
136 
143  void reconstructCOO();
144 
148  int getNumMatrixElements() const;
149 
151  const int* getCOORowIndices() const;
152 
154  const int* getCOOColIndices() const;
155 
157  const std::complex<double>* getCOOValues() const;
158 
161  class Iterator{
162  public:
164  Iterator(const Iterator &iterator);
165 
167  Iterator(Iterator &&iterator);
168 
170  ~Iterator();
171 
173  Iterator& operator=(const Iterator &rhs);
174 
176  Iterator& operator=(Iterator &&rhs);
177 
179  void reset();
180 
182  void searchNextHA();
183 
185  const HoppingAmplitude* getHA() const;
186 
188  int getMinBasisIndex() const;
189 
191  int getMaxBasisIndex() const;
192 
194  int getNumBasisIndices() const;
195  private:
198  friend class HoppingAmplitudeSet;
199 
202  Iterator(const HoppingAmplitudeTree *hoppingAmplitudeTree);
203 
207  };
208 
212 
217  HoppingAmplitudeSet::Iterator getIterator(const Index &subspace) const;
218 
220  void print();
221 
246  void tabulate(
247  std::complex<double> **amplitudes,
248  int **indices,
249  int *numHoppingAmplitudes,
250  int *maxIndexSize
251  ) const;
252 
254  virtual std::string serialize(Mode mode) const;
255 
257  unsigned int getSizeInBytes() const;
258 private:
261  HoppingAmplitudeTree hoppingAmplitudeTree;
262 
265  bool isConstructed;
266 
269  bool isSorted;
270 
273  int numMatrixElements;
274 
276  int *cooRowIndices;
277 
279  int *cooColIndices;
280 
282  std::complex<double> *cooValues;
283 };
284 
286  hoppingAmplitudeTree.add(ha);
287 }
288 
291 ){
292  hoppingAmplitudeTree.add(ha);
293  hoppingAmplitudeTree.add(ha.getHermitianConjugate());
294 }
295 
296 inline const std::vector<HoppingAmplitude>* HoppingAmplitudeSet::getHAs(
297  Index index
298 ) const{
299  return hoppingAmplitudeTree.getHAs(index);
300 }
301 
302 inline int HoppingAmplitudeSet::getBasisIndex(const Index &index) const{
303  return hoppingAmplitudeTree.getBasisIndex(index);
304 }
305 
306 inline Index HoppingAmplitudeSet::getPhysicalIndex(int basisIndex) const{
307  return hoppingAmplitudeTree.getPhysicalIndex(basisIndex);
308 }
309 
311  return hoppingAmplitudeTree.getBasisSize();
312 }
313 
314 inline bool HoppingAmplitudeSet::isProperSubspace(const Index &subspace){
315  return hoppingAmplitudeTree.isProperSubspace(subspace);
316 }
317 
319  return hoppingAmplitudeTree.getSubspaceIndices();
320 }
321 
323  TBTKAssert(
324  !isConstructed,
325  "HoppingAmplitudeSet::construct()",
326  "HoppingAmplitudeSet is already constructed.",
327  ""
328  );
329 
330  hoppingAmplitudeTree.generateBasisIndices();
331  isConstructed = true;
332 }
333 
335  return isConstructed;
336 }
337 
338 inline std::vector<Index> HoppingAmplitudeSet::getIndexList(
339  const Index &pattern
340 ) const{
341  return hoppingAmplitudeTree.getIndexList(pattern);
342 }
343 
345  const Index &blockIndex
346 ) const{
347  return hoppingAmplitudeTree.getFirstIndexInSubspace(blockIndex);
348 }
349 
351  const Index &blockIndex
352 ) const{
353  return hoppingAmplitudeTree.getLastIndexInSubspace(blockIndex);
354 }
355 
357  TBTKAssert(
358  isConstructed,
359  "HoppingAmplitudeSet::sort()",
360  "HoppingAmplitudeSet has to be constructed first.",
361  ""
362  );
363 
364  if(!isSorted){
365  hoppingAmplitudeTree.sort(&hoppingAmplitudeTree);
366  isSorted = true;
367  }
368 }
369 
370 inline const int* HoppingAmplitudeSet::getCOORowIndices() const{
371  return cooRowIndices;
372 }
373 
374 inline const int* HoppingAmplitudeSet::getCOOColIndices() const{
375  return cooColIndices;
376 }
377 
378 inline const std::complex<double>* HoppingAmplitudeSet::getCOOValues() const{
379  return cooValues;
380 }
381 
382 inline unsigned int HoppingAmplitudeSet::getSizeInBytes() const{
383  unsigned int size = sizeof(*this) - sizeof(hoppingAmplitudeTree);
384  size += hoppingAmplitudeTree.getSizeInBytes();
385  if(numMatrixElements > 0){
386  size += numMatrixElements*(
387  sizeof(*cooRowIndices)
388  + sizeof(*cooColIndices)
389  + sizeof(*cooValues)
390  );
391  }
392 
393  return size;
394 }
395 
396 }; //End of namespace TBTK
397 
398 #endif
bool isProperSubspace(const Index &subspace)
Definition: HoppingAmplitudeSet.h:314
Node in tree used by HoppingAmplitudeSet to store HoppingAmplitudes .
void tabulate(std::complex< double > **amplitudes, int **indices, int *numHoppingAmplitudes, int *maxIndexSize) const
unsigned int getSizeInBytes() const
Definition: HoppingAmplitudeSet.h:382
Node in tree used by HoppingAmplitudeSet to store HoppingAmplitudes .
Definition: HoppingAmplitudeTree.h:40
int getLastIndexInBlock(const Index &blockIndex) const
Definition: HoppingAmplitudeSet.h:350
const int * getCOOColIndices() const
Definition: HoppingAmplitudeSet.h:374
const std::vector< HoppingAmplitude > * getHAs(Index index) const
Definition: HoppingAmplitudeSet.h:296
HoppingAmplitude container.
Definition: HoppingAmplitudeSet.h:49
void addHoppingAmplitude(HoppingAmplitude ha)
Definition: HoppingAmplitudeSet.h:285
int getBasisSize() const
Definition: HoppingAmplitudeSet.h:310
Hopping amplitude from state &#39;from&#39; to state &#39;to&#39;.
Precompiler macros.
const HoppingAmplitude * getHA() const
Definition: Serializable.h:40
Data structure for mapping physical indices to a linear index.
void addHoppingAmplitudeAndHermitianConjugate(HoppingAmplitude ha)
Definition: HoppingAmplitudeSet.h:289
Iterator(const Iterator &iterator)
Iterator & operator=(const Iterator &rhs)
Index getPhysicalIndex(int basisIndex) const
Definition: HoppingAmplitudeSet.h:306
HoppingAmplitudeSet & operator=(const HoppingAmplitudeSet &rhs)
const std::complex< double > * getCOOValues() const
Definition: HoppingAmplitudeSet.h:378
void sort()
Definition: HoppingAmplitudeSet.h:356
bool getIsConstructed() const
Definition: HoppingAmplitudeSet.h:334
Definition: HoppingAmplitudeSet.h:161
Definition: HoppingAmplitudeTree.h:203
int getBasisIndex(const Index &index) const
Definition: HoppingAmplitudeSet.h:302
Hopping amplitude from state &#39;from&#39; to state &#39;to&#39;.
Definition: HoppingAmplitude.h:49
const int * getCOORowIndices() const
Definition: HoppingAmplitudeSet.h:370
HoppingAmplitudeSet::Iterator getIterator() const
virtual std::string serialize(Mode mode) 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
int getNumMatrixElements() const
std::vector< Index > getIndexList(const Index &pattern) const
Definition: HoppingAmplitudeSet.h:338
Mode
Definition: Serializable.h:44
Abstract base class for serializable objects.
Streams for TBTK output.
IndexTree getSubspaceIndices() const
Definition: HoppingAmplitudeSet.h:318
void construct()
Definition: HoppingAmplitudeSet.h:322
HoppingAmplitude getHermitianConjugate() const
int getFirstIndexInBlock(const Index &blockIndex) const
Definition: HoppingAmplitudeSet.h:344