TBTK
Need a break? Support the development by playing Polarity Puzzles
OverlapAmplitude.h
Go to the documentation of this file.
1 /* Copyright 2019 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_OVERLAP_AMPLITUDE
24 #define COM_DAFER45_TBTK_OVERLAP_AMPLITUDE
25 
26 #include "TBTK/Index.h"
28 #include "TBTK/Serializable.h"
29 
30 #include <complex>
31 #include <initializer_list>
32 #include <vector>
33 
34 namespace TBTK{
35 
38 public:
42  public:
54  virtual std::complex<double> getOverlapAmplitude(
55  const Index &braIndex,
56  const Index &ketIndex
57  ) const = 0;
58  };
59 
62 
70  std::complex<double> amplitude,
71  const Index &braIndex,
72  const Index &ketIndex
73  );
74 
85  const AmplitudeCallback &amplitudeCallback,
86  const Index &braIndex,
87  const Index &ketIndex
88  );
89 
98  const std::string &serializeation,
100  );
101 
105  std::complex<double> getAmplitude() const;
106 
110  const Index& getBraIndex() const;
111 
115  const Index& getKetIndex() const;
116 
122  bool getIsCallbackDependent() const;
123 
133 
137  std::string toString() const;
138 
147  std::string serialize(Serializable::Mode mode) const;
148 
152  unsigned int getSizeInBytes() const;
153 private:
156  std::complex<double> amplitude;
157 
160  const AmplitudeCallback *amplitudeCallback;
161 
163  Index braIndex;
164 
166  Index ketIndex;
167 
168 };
169 
171  amplitudeCallback = nullptr;
172 }
173 
174 inline std::complex<double> OverlapAmplitude::getAmplitude() const{
175  if(amplitudeCallback){
176  return amplitudeCallback->getOverlapAmplitude(
177  braIndex,
178  ketIndex
179  );
180  }
181  else{
182  return amplitude;
183  }
184 }
185 
186 inline const Index& OverlapAmplitude::getBraIndex() const{
187  return braIndex;
188 }
189 
190 inline const Index& OverlapAmplitude::getKetIndex() const{
191  return ketIndex;
192 }
193 
195  if(amplitudeCallback == nullptr)
196  return false;
197  else
198  return true;
199 }
200 
203  if(amplitudeCallback != nullptr){
204  return *amplitudeCallback;
205  }
206  else{
207  TBTKExit(
208  "OverlapAmplitude::getAmplitudeCallback()",
209  "Tried to access AmplitudeCallback from an"
210  << " OverlapAmplitude without an AmplitudeCallback.",
211  ""
212  );
213  }
214 }
215 
216 inline std::string OverlapAmplitude::toString() const{
217  std::string str;
218  str += "("
219  + std::to_string(real(amplitude))
220  + ", " + std::to_string(imag(amplitude))
221  + ")"
222  + ", " + braIndex.toString()
223  + ", " + ketIndex.toString();
224 
225  return str;
226 }
227 
228 inline unsigned int OverlapAmplitude::getSizeInBytes() const{
229  return sizeof(OverlapAmplitude)
230  - sizeof(braIndex)
231  - sizeof(ketIndex)
232  + braIndex.getSizeInBytes()
233  + ketIndex.getSizeInBytes();
234 }
235 
236 }; //End of namespace TBTK
237 
238 #endif
TBTK::OverlapAmplitude
Overlap amplitude between state 'bra' and 'ket'.
Definition: OverlapAmplitude.h:37
TBTK::OverlapAmplitude::getIsCallbackDependent
bool getIsCallbackDependent() const
Definition: OverlapAmplitude.h:194
TBTK::OverlapAmplitude::getBraIndex
const Index & getBraIndex() const
Definition: OverlapAmplitude.h:186
TBTK::Index::toString
std::string toString() const
Definition: Index.h:349
Index.h
Physical index.
TBTK::OverlapAmplitude::toString
std::string toString() const
Definition: OverlapAmplitude.h:216
TBTK::Index::getSizeInBytes
unsigned int getSizeInBytes() const
Definition: Index.h:548
TBTK::OverlapAmplitude::getKetIndex
const Index & getKetIndex() const
Definition: OverlapAmplitude.h:190
TBTK::OverlapAmplitude::OverlapAmplitude
OverlapAmplitude()
Definition: OverlapAmplitude.h:170
TBTK::OverlapAmplitude::AmplitudeCallback
Definition: OverlapAmplitude.h:41
Serializable.h
Abstract base class for serializable objects.
TBTK::OverlapAmplitude::getAmplitude
std::complex< double > getAmplitude() const
Definition: OverlapAmplitude.h:174
PseudoSerializable.h
Base class for psudo-serializable objects.
TBTK::OverlapAmplitude::AmplitudeCallback::getOverlapAmplitude
virtual std::complex< double > getOverlapAmplitude(const Index &braIndex, const Index &ketIndex) const =0
TBTK::Serializable::Mode
Mode
Definition: Serializable.h:47
TBTK::OverlapAmplitude::getAmplitudeCallback
const AmplitudeCallback & getAmplitudeCallback() const
Definition: OverlapAmplitude.h:202
TBTK::PseudoSerializable
Definition: PseudoSerializable.h:31
TBTK::Index
Physical index.
Definition: Index.h:44
TBTK::OverlapAmplitude::getSizeInBytes
unsigned int getSizeInBytes() const
Definition: OverlapAmplitude.h:228
TBTK::OverlapAmplitude::serialize
std::string serialize(Serializable::Mode mode) const