TBTK
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 
23 #ifndef COM_DAFER45_TBTK_BASIC_STATE
24 #define COM_DAFER45_TBTK_BASIC_STATE
25 
26 #include "TBTK/AbstractState.h"
27 #include "TBTK/DefaultOperator.h"
28 #include "TBTK/Index.h"
29 #include "TBTK/IndexTree.h"
30 
31 #include <complex>
32 #include <tuple>
33 
34 namespace TBTK{
35 
36 class BasicState : public AbstractState{
37 public:
39  BasicState(const Index &index, const Index &unitCellIndex = {});
40 
42  virtual ~BasicState();
43 
45  virtual BasicState* clone() const;
46 
48  void addOverlap(
49  std::complex<double> overlap,
50  const Index &braIndex,
51  const Index &braRelativeUnitCell = {}
52  );
53 
55  void addMatrixElement(
56  std::complex<double> matrixElement,
57  const Index &bra,
58  const Index &braRelativeUnitCell = {}
59  );
60 
62  virtual std::complex<double> getOverlap(const AbstractState &bra) const;
63 
65  virtual std::complex<double> getMatrixElement(
66  const AbstractState &bra,
68  ) const;
69 private:
70  class Storage{
71  public:
75 // static constexpr unsigned int MAX_ELEMENTS_LINEAR_SEARCH = 50;
76 
80  std::vector<std::tuple<std::complex<double>, Index, Index>> overlaps;
81 
83  bool overlapsIsSorted;
84 
86 // IndexTree *overlapsIndexTree;
87 
89 // std::complex<double> *indexedOverlaps;
90 
94  std::vector<std::tuple<std::complex<double>, Index, Index>> matrixElements;
95 
97  bool matrixElementsIsSorted;
98 
100 // IndexTree *matrixElementsIndexTree;
101 
103 // std::complex<double> *indexedMatrixElements;
104 
106  Storage();
107 
109  ~Storage();
110 
112  void grab();
113 
116  bool release();
117 
119  void sortOverlaps();
120 
122  void sortMatrixElements();
123  private:
125  unsigned int referenceCounter;
126  };
127 
128  Storage *storage;
129 };
130 
131 inline void BasicState::Storage::grab(){
132  referenceCounter++;
133 }
134 
135 inline bool BasicState::Storage::release(){
136  referenceCounter--;
137  if(referenceCounter == 0)
138  return true;
139  else
140  return false;
141 }
142 
143 }; //End of namespace TBTK
144 
145 #endif
Flexible physical index.
virtual ~BasicState()
Abstract state class from which other states inherit.
virtual BasicState * clone() const
void addMatrixElement(std::complex< double > matrixElement, const Index &bra, const Index &braRelativeUnitCell={})
Data structure for mapping physical indices to a linear index.
Definition: AbstractOperator.h:30
void addOverlap(std::complex< double > overlap, const Index &braIndex, const Index &braRelativeUnitCell={})
BasicState(const Index &index, const Index &unitCellIndex={})
virtual std::complex< double > getOverlap(const AbstractState &bra) const
Definition: AbstractState.h:37
Definition: BasicState.h:36
Flexible physical index.
Definition: Index.h:70
Definition: ModelFactory.h:35
virtual std::complex< double > getMatrixElement(const AbstractState &bra, const AbstractOperator &o=DefaultOperator()) const
Default (dummy) operator class for indicating default behavior.
Definition: DefaultOperator.h:30