TBTK
SourceAmplitudeSet.h
Go to the documentation of this file.
1 /* Copyright 2018 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_SOURCE_AMPLITUDE_SET
24 #define COM_DAFER45_TBTK_SOURCE_AMPLITUDE_SET
25 
26 #include "TBTK/SourceAmplitude.h"
27 #include "TBTK/IdexedDataTree.h"
28 #include "TBTK/Serializable.h"
29 #include "TBTK/TBTKMacros.h"
30 
31 #include <vector>
32 
33 namespace TBTK{
34 
40 public:
43 
46  SourceAmplitudeSet(const std::string &serializeation, Mode mode);
47 
49  virtual ~SourceAmplitudeSet();
50 
55 
61  const std::vector<SourceAmplitude>& getSourceAmplitudes(
62  const Index &index
63  ) const;
64 
67  class Iterator{
68  public:
70  Iterator(const Iterator &iterator);
71 
73  Iterator(Iterator &&iterator);
74 
76  ~Iterator();
77 
79  Iterator& operator=(const Iterator &rhs);
80 
82  Iterator& operator=(Iterator &&rhs);
83 
85  void reset();
86 
88  void searchNext();
89 
91  const SourceAmplitude* getSourceAmplitude() const;
92 
94 // int getMinBasisIndex() const;
95 
97 // int getMaxBasisIndex() const;
98 
100 // int getNumBasisIndices() const;
101  private:
103  int current
104 
105  /***/
107 
110  friend class HoppingAmplitudeSet;
111 
114  Iterator(const HoppingAmplitudeTree *hoppingAmplitudeTree);
115  };
116 
120 
125  HoppingAmplitudeSet::Iterator getIterator(const Index &subspace) const;
126 
128  void print();
129 
154  void tabulate(
155  std::complex<double> **amplitudes,
156  int **indices,
157  int *numHoppingAmplitudes,
158  int *maxIndexSize
159  ) const;
160 
162  virtual std::string serialize(Mode mode) const;
163 
165  unsigned int getSizeInBytes() const;
166 private:
168  IndexedDataTree<SourceAmplitude> sourceAmplitudeTree;
169 };
170 
172  hoppingAmplitudeTree.add(ha);
173 }
174 
177 ){
178  hoppingAmplitudeTree.add(ha);
179  hoppingAmplitudeTree.add(ha.getHermitianConjugate());
180 }
181 
182 inline const std::vector<HoppingAmplitude>* HoppingAmplitudeSet::getHAs(
183  Index index
184 ) const{
185  return hoppingAmplitudeTree.getHAs(index);
186 }
187 
188 inline int HoppingAmplitudeSet::getBasisIndex(const Index &index) const{
189  return hoppingAmplitudeTree.getBasisIndex(index);
190 }
191 
192 inline Index HoppingAmplitudeSet::getPhysicalIndex(int basisIndex) const{
193  return hoppingAmplitudeTree.getPhysicalIndex(basisIndex);
194 }
195 
196 inline int HoppingAmplitudeSet::getBasisSize() const{
197  return hoppingAmplitudeTree.getBasisSize();
198 }
199 
200 inline bool HoppingAmplitudeSet::isProperSubspace(const Index &subspace){
201  return hoppingAmplitudeTree.isProperSubspace(subspace);
202 }
203 
205  return hoppingAmplitudeTree.getSubspaceIndices();
206 }
207 
208 inline void HoppingAmplitudeSet::construct(){
209  TBTKAssert(
210  !isConstructed,
211  "HoppingAmplitudeSet::construct()",
212  "HoppingAmplitudeSet is already constructed.",
213  ""
214  );
215 
216  hoppingAmplitudeTree.generateBasisIndices();
217  isConstructed = true;
218 }
219 
220 inline bool HoppingAmplitudeSet::getIsConstructed() const{
221  return isConstructed;
222 }
223 
224 inline std::vector<Index> HoppingAmplitudeSet::getIndexList(
225  const Index &pattern
226 ) const{
227  return hoppingAmplitudeTree.getIndexList(pattern);
228 }
229 
231  const Index &blockIndex
232 ) const{
233  return hoppingAmplitudeTree.getFirstIndexInSubspace(blockIndex);
234 }
235 
237  const Index &blockIndex
238 ) const{
239  return hoppingAmplitudeTree.getLastIndexInSubspace(blockIndex);
240 }
241 
242 inline void HoppingAmplitudeSet::sort(){
243  TBTKAssert(
244  isConstructed,
245  "HoppingAmplitudeSet::sort()",
246  "HoppingAmplitudeSet has to be constructed first.",
247  ""
248  );
249 
250  if(!isSorted){
251  hoppingAmplitudeTree.sort(&hoppingAmplitudeTree);
252  isSorted = true;
253  }
254 }
255 
256 inline const int* HoppingAmplitudeSet::getCOORowIndices() const{
257  return cooRowIndices;
258 }
259 
260 inline const int* HoppingAmplitudeSet::getCOOColIndices() const{
261  return cooColIndices;
262 }
263 
264 inline const std::complex<double>* HoppingAmplitudeSet::getCOOValues() const{
265  return cooValues;
266 }
267 
268 inline unsigned int HoppingAmplitudeSet::getSizeInBytes() const{
269  unsigned int size = sizeof(*this) - sizeof(hoppingAmplitudeTree);
270  size += hoppingAmplitudeTree.getSizeInBytes();
271  if(numMatrixElements > 0){
272  size += numMatrixElements*(
273  sizeof(*cooRowIndices)
274  + sizeof(*cooColIndices)
275  + sizeof(*cooValues)
276  );
277  }
278 
279  return size;
280 }
281 
282 }; //End of namespace TBTK
283 
284 #endif
bool isProperSubspace(const Index &subspace)
Definition: HoppingAmplitudeSet.h:314
unsigned int getSizeInBytes() const
Definition: HoppingAmplitudeSet.h:382
unsigned int getSizeInBytes() const
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
void tabulate(std::complex< double > **amplitudes, int **indices, int *numHoppingAmplitudes, int *maxIndexSize) const
int getBasisSize() const
Definition: HoppingAmplitudeSet.h:310
Iterator & operator=(const Iterator &rhs)
Precompiler macros.
Definition: Serializable.h:40
virtual std::string serialize(Mode mode) const
Source amplitude for equations with a source term.
Definition: SourceAmplitude.h:40
void addHoppingAmplitudeAndHermitianConjugate(HoppingAmplitude ha)
Definition: HoppingAmplitudeSet.h:289
const SourceAmplitude * getSourceAmplitude() const
Index getPhysicalIndex(int basisIndex) const
Definition: HoppingAmplitudeSet.h:306
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
const std::vector< SourceAmplitude > & getSourceAmplitudes(const Index &index) const
int getBasisIndex(const Index &index) const
Definition: HoppingAmplitudeSet.h:302
Definition: IndexedDataTree.h:38
Definition: SourceAmplitudeSet.h:67
Source amplitude for equations with a source term.
Hopping amplitude from state &#39;from&#39; to state &#39;to&#39;.
Definition: HoppingAmplitude.h:49
const int * getCOORowIndices() const
Definition: HoppingAmplitudeSet.h:370
SourceAmplitude container.
Definition: SourceAmplitudeSet.h:39
Iterator(const Iterator &iterator)
void addSourceAmplitude(SourceAmplitude ha)
Data structure for mapping physical indices to a linear index.
Definition: IndexTree.h:34
Flexible physical index.
Definition: Index.h:70
HoppingAmplitudeSet::Iterator getIterator() const
Definition: ModelFactory.h:35
std::vector< Index > getIndexList(const Index &pattern) const
Definition: HoppingAmplitudeSet.h:338
Mode
Definition: Serializable.h:44
Abstract base class for serializable objects.
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