TBTK
Need a break? Support the development by playing Polarity Puzzles
HoppingAmplitude.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
24 #define COM_DAFER45_TBTK_HOPPING_AMPLITUDE
25 
26 #include "TBTK/Index.h"
27 #include "TBTK/Serializable.h"
28 
29 #include <complex>
30 #include <initializer_list>
31 #include <tuple>
32 #include <vector>
33 
34 namespace TBTK{
35 
38 
54 public:
58  public:
70  virtual std::complex<double> getHoppingAmplitude(
71  const Index &to,
72  const Index &from
73  ) const = 0;
74  };
75 
76  //TBTKFeature Core.HoppingAmplitude.Construction.1 2019-09-23
79 
80  //TBTKFeature Core.HoppingAmplitude.Construction.2 2019-09-23
91  std::complex<double> amplitude,
92  Index toIndex,
93  Index fromIndex
94  );
95 
96  //TBTKFeature Core.HoppingAmplitude.Construction.3 2019-09-23
110  const AmplitudeCallback &callback,
111  Index toIndex,
112  Index fromIndex
113  );
114 
115  //TBTKFeature Core.HoppingAmplitude.Copy.1 2019-09-23
116  //TBTKFeature Core.HoppingAmplitude.Copy.2 2019-09-23
121 
122  //TBTKFeature Core.HoppingAmplitude.Serialization.1 2019-09-23
131  const std::string &serialization,
132  Serializable::Mode mode
133  );
134 
135  //TBTKFeature Core.HoppingAmplitude.getHermitianConjugate.1 2019-09-23
136  //TBTKFeature Core.HoppingAmplitude.getHermitianConjugate.2 2019-09-23
141 
143  void print() const;
144 
145  //TBTKFeature Core.HoppingAmplitude.getAmplitude.1 2019-09-23
146  //TBTKFeature Core.HoppingAmplitude.getAmplitude.2 2019-09-23
150  std::complex<double> getAmplitude() const;
151 
152  //TBTKFeature Core.HoppingAmplitude.operatorAddition.1.C++ 2019-09-23
161  std::tuple<HoppingAmplitude, HoppingAmplitude> operator+(
162  const HermitianConjugate hc
163  );
164 
165  //TBTKFeature Core.HoppingAmplitude.getToIndex.1 2019-09-23
169  const Index& getToIndex() const;
170 
171  //TBTKFeature Core.HoppingAmplitude.getFromIndex.1 2019-09-23
175  const Index& getFromIndex() const;
176 
177  //TBTKFeature Core.HoppingAmplitude.getIsCallbackDependent.1 2019-09-23
178  //TBTKFeature Core.HoppingAmplitude.getIsCallbackDependent.2 2019-09-23
184  bool getIsCallbackDependent() const;
185 
186  //TBTKFeature Core.HoppingAmplitude.getAmplitudeCallback.1 2019-09-23
187  //TBTKFeature Core.HoppingAmplitude.getAmplitudeCallback.2 2019-09-23
197 
201  std::string toString() const;
202 
209  friend std::ostream& operator<<(
210  std::ostream &stream,
211  const HoppingAmplitude &hoppingAmplitude
212  );
213 
214  //TBTKFeature Core.HoppingAmplitude.Serialization.1 2019-09-23
223  std::string serialize(Serializable::Mode mode) const;
224 
228  unsigned int getSizeInBytes() const;
229 private:
232  std::complex<double> amplitude;
233 
236  const AmplitudeCallback *amplitudeCallback;
237 
239  Index fromIndex;
240 
242  Index toIndex;
243 
244 };
245 
246 inline std::complex<double> HoppingAmplitude::getAmplitude() const{
247  if(amplitudeCallback){
248  return amplitudeCallback->getHoppingAmplitude(
249  toIndex,
250  fromIndex
251  );
252  }
253  else{
254  return amplitude;
255  }
256 }
257 
258 inline std::tuple<HoppingAmplitude, HoppingAmplitude> HoppingAmplitude::operator+(
260 ){
261  return std::make_tuple(*this, this->getHermitianConjugate());
262 }
263 
264 inline const Index& HoppingAmplitude::getToIndex() const{
265  return toIndex;
266 }
267 
268 inline const Index& HoppingAmplitude::getFromIndex() const{
269  return fromIndex;
270 }
271 
273  if(amplitudeCallback == nullptr)
274  return false;
275  else
276  return true;
277 }
278 
281  if(amplitudeCallback != nullptr){
282  return *amplitudeCallback;
283  }
284  else{
285  TBTKExit(
286  "HoppingAmpliude::getAmplitudeCallback()",
287  "Tried to access AmplitudeCallback from a"
288  << " HoppingAmplitude without an AmplitudeCallback.",
289  ""
290  );
291  }
292 }
293 
294 inline std::string HoppingAmplitude::toString() const{
295  std::stringstream stream;
296  stream << "HoppingAmplitude:\n";
297  if(amplitudeCallback == nullptr){
298  stream << "\tIs callback dependent: False\n";
299  stream << "\tAmplitude: " << amplitude << "\n";
300  }
301  else{
302  stream << "\tIs callback dependent: True\n";
303  stream << "\tAmplitude: "
304  << amplitudeCallback->getHoppingAmplitude(
305  toIndex,
306  fromIndex
307  ) << "\n";
308  }
309  stream << "\tTo-Index: " << toIndex << "\n";
310  stream << "\tFrom-Index: " << fromIndex;
311 
312  return stream.str();
313 }
314 
315 inline std::ostream& operator<<(
316  std::ostream &stream,
317  const HoppingAmplitude &hoppingAmplitude
318 ){
319  stream << hoppingAmplitude.toString();
320 
321  return stream;
322 }
323 
324 inline unsigned int HoppingAmplitude::getSizeInBytes() const{
325  return sizeof(HoppingAmplitude)
326  - sizeof(fromIndex)
327  - sizeof(toIndex)
328  + fromIndex.getSizeInBytes()
329  + toIndex.getSizeInBytes();
330 }
331 
332 }; //End of namespace TBTK
333 
334 #endif
TBTK::HoppingAmplitude::HoppingAmplitude
HoppingAmplitude()
TBTK::HoppingAmplitude::serialize
std::string serialize(Serializable::Mode mode) const
TBTK::HermitianConjugate
HermitianConjugate
Enum used to indicate the Hermitian conjugate.
Definition: HoppingAmplitude.h:37
TBTK::HoppingAmplitude::toString
std::string toString() const
Definition: HoppingAmplitude.h:294
Index.h
Physical index.
TBTK::HoppingAmplitude::AmplitudeCallback
Definition: HoppingAmplitude.h:57
TBTK::HoppingAmplitude::print
void print() const
TBTK::Index::getSizeInBytes
unsigned int getSizeInBytes() const
Definition: Index.h:548
TBTK::HoppingAmplitude::getFromIndex
const Index & getFromIndex() const
Definition: HoppingAmplitude.h:268
TBTK::HoppingAmplitude::AmplitudeCallback::getHoppingAmplitude
virtual std::complex< double > getHoppingAmplitude(const Index &to, const Index &from) const =0
TBTK::HoppingAmplitude::getIsCallbackDependent
bool getIsCallbackDependent() const
Definition: HoppingAmplitude.h:272
TBTK::HoppingAmplitude::getToIndex
const Index & getToIndex() const
Definition: HoppingAmplitude.h:264
Serializable.h
Abstract base class for serializable objects.
TBTK::HoppingAmplitude::getHermitianConjugate
HoppingAmplitude getHermitianConjugate() const
TBTK::HoppingAmplitude
Hopping amplitude from state 'from' to state 'to'.
Definition: HoppingAmplitude.h:53
TBTK::HoppingAmplitude::operator<<
friend std::ostream & operator<<(std::ostream &stream, const HoppingAmplitude &hoppingAmplitude)
Definition: HoppingAmplitude.h:315
TBTK::operator<<
std::ostream & operator<<(std::ostream &stream, const HoppingAmplitude &hoppingAmplitude)
Definition: HoppingAmplitude.h:315
TBTK::HoppingAmplitude::getSizeInBytes
unsigned int getSizeInBytes() const
Definition: HoppingAmplitude.h:324
TBTK::Serializable::Mode
Mode
Definition: Serializable.h:47
TBTK::Index
Physical index.
Definition: Index.h:44
TBTK::HoppingAmplitude::operator+
std::tuple< HoppingAmplitude, HoppingAmplitude > operator+(const HermitianConjugate hc)
Definition: HoppingAmplitude.h:258
TBTK::HoppingAmplitude::getAmplitudeCallback
const AmplitudeCallback & getAmplitudeCallback() const
Definition: HoppingAmplitude.h:280
TBTK::HoppingAmplitude::getAmplitude
std::complex< double > getAmplitude() const
Definition: HoppingAmplitude.h:246