TBTK
Need a break? Support the development by playing Polarity Puzzles
BasicState.h
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 
17 
24 #ifndef COM_DAFER45_TBTK_BASIC_STATE
25 #define COM_DAFER45_TBTK_BASIC_STATE
26 
27 #include "TBTK/AbstractState.h"
28 #include "TBTK/DefaultOperator.h"
29 #include "TBTK/Index.h"
30 #include "TBTK/IndexTree.h"
31 
32 #include <complex>
33 #include <tuple>
34 
35 namespace TBTK{
36 
37 class BasicState : public AbstractState{
38 public:
40  BasicState(const Index &index, const Index &unitCellIndex = {});
41 
43  virtual ~BasicState();
44 
46  virtual BasicState* clone() const;
47 
49  void addOverlap(
50  std::complex<double> overlap,
51  const Index &braIndex,
52  const Index &braRelativeUnitCell = {}
53  );
54 
56  void addMatrixElement(
57  std::complex<double> matrixElement,
58  const Index &bra,
59  const Index &braRelativeUnitCell = {}
60  );
61 
63  virtual std::complex<double> getOverlap(const AbstractState &bra) const;
64 
66  virtual std::complex<double> getMatrixElement(
67  const AbstractState &bra,
68  const AbstractOperator &o = DefaultOperator()
69  ) const;
70 private:
71  class Storage{
72  public:
76 // static constexpr unsigned int MAX_ELEMENTS_LINEAR_SEARCH = 50;
77 
81  std::vector<std::tuple<std::complex<double>, Index, Index>> overlaps;
82 
84  bool overlapsIsSorted;
85 
87 // IndexTree *overlapsIndexTree;
88 
90 // std::complex<double> *indexedOverlaps;
91 
95  std::vector<std::tuple<std::complex<double>, Index, Index>> matrixElements;
96 
98  bool matrixElementsIsSorted;
99 
101 // IndexTree *matrixElementsIndexTree;
102 
104 // std::complex<double> *indexedMatrixElements;
105 
107  Storage();
108 
110  ~Storage();
111 
113  void grab();
114 
117  bool release();
118 
120  void sortOverlaps();
121 
123  void sortMatrixElements();
124  private:
126  unsigned int referenceCounter;
127  };
128 
129  Storage *storage;
130 };
131 
132 inline void BasicState::Storage::grab(){
133  referenceCounter++;
134 }
135 
136 inline bool BasicState::Storage::release(){
137  referenceCounter--;
138  if(referenceCounter == 0)
139  return true;
140  else
141  return false;
142 }
143 
144 }; //End of namespace TBTK
145 
146 #endif
147 
Physical index.
Data structure for mapping physical indices to a linear index.
Definition: Boolean.h:32