TBTK
Need a break? Support the development by playing Polarity Puzzles
Model.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_MODEL
24 #define COM_DAFER45_TBTK_MODEL
25 
28 #include "TBTK/Communicator.h"
29 #include "TBTK/Geometry.h"
32 #include "TBTK/IndexBasedHoppingAmplitudeFilter.h"
34 #include "TBTK/ManyParticleContext.h"
35 #include "TBTK/Serializable.h"
36 #include "TBTK/Statistics.h"
37 #include "TBTK/Streamable.h"
38 
39 #include <complex>
40 #include <fstream>
41 #include <string>
42 #include <tuple>
43 
44 namespace TBTK{
45 
46 class FileReader;
47 
57 class Model : public Serializable, public Communicator, public Streamable{
58 public:
60  Model();
61 
69  Model(const std::vector<unsigned int> &capacity);
70 
74  Model(const Model &model);
75 
79  Model(Model &&model);
80 
88  Model(const std::string &serialization, Mode mode);
89 
91  virtual ~Model();
92 
98  Model& operator=(const Model &rhs);
99 
105  Model& operator=(Model &&rhs);
106 
110  void add(HoppingAmplitude ha);
111 
117  void addModel(const Model &model, const Index &subsytemIndex);
118 
126  int getBasisIndex(const Index &index) const;
127 
132  int getBasisSize() const;
133 
140  &hoppingAmplitudeCallback
141  );
142 
149  &overlapAmplitudeCallback
150  );
151 
154  void construct();
155 
159  bool getIsConstructed();
160 
164  void setTemperature(double temperature);
165 
169  double getTemperature() const;
170 
174  void setChemicalPotential(double chemicalPotential);
175 
179  double getChemicalPotential() const;
180 
184  void setStatistics(Statistics statistics);
185 
189  Statistics getStatistics() const;
190 
194  const BasisStateSet& getBasisStateSet() const;
195 
200 
205 
210 
215 
219  const Geometry& getGeometry() const;
220 
223 
227  ManyParticleContext* getManyParticleContext();
228 
239  void setFilter(
240  const AbstractHoppingAmplitudeFilter &hoppingAmplitudeFilter
241  );
242 
252  void setFilter(
253  const AbstractIndexFilter &indexFilter
254  );
255 
257  Model& operator<<(const AbstractState &basisState);
258 
260  Model& operator<<(const HoppingAmplitude& hoppingAmplitude);
261 
263  Model& operator<<(
264  const std::tuple<HoppingAmplitude, HoppingAmplitude> &hoppingAmplitudes
265  );
266 
268  Model& operator<<(const HoppingAmplitudeList& hoppingAmplitudeList);
269 
271  Model& operator<<(const SourceAmplitude& sourceAmplitude);
272 
274  Model& operator<<(const OverlapAmplitude& overlapAmplitudeSet);
275 
279  virtual std::string toString() const;
280 
283  std::string serialize(Mode mode) const;
284 private:
286  double temperature;
287 
289  double chemicalPotential;
290 
292  SingleParticleContext singleParticleContext;
293 
295  ManyParticleContext *manyParticleContext;
296 
298  AbstractIndexFilter *indexFilter;
299 
301  AbstractHoppingAmplitudeFilter *hoppingAmplitudeFilter;
302 
304  friend class FileReader;
305 };
306 
307 inline void Model::add(HoppingAmplitude ha){
308  singleParticleContext.getHoppingAmplitudeSet().add(ha);
309 }
310 
311 inline int Model::getBasisSize() const{
312  return singleParticleContext.getHoppingAmplitudeSet().getBasisSize();
313 }
314 
316  const HoppingAmplitude::AmplitudeCallback &hoppingAmplitudeCallback
317 ){
318  singleParticleContext.generateHoppingAmplitudeSet(
319  hoppingAmplitudeCallback
320  );
321 }
322 
324  const OverlapAmplitude::AmplitudeCallback &overlapAmplitudeCallback
325 ){
326  singleParticleContext.generateOverlapAmplitudeSet(
327  overlapAmplitudeCallback
328  );
329 }
330 
331 inline int Model::getBasisIndex(const Index &index) const{
332  return singleParticleContext.getHoppingAmplitudeSet().getBasisIndex(index);
333 }
334 
336  return singleParticleContext.getHoppingAmplitudeSet().getIsConstructed();
337 }
338 
339 inline void Model::setTemperature(double temperature){
340  this->temperature = temperature;
341 }
342 
343 inline double Model::getTemperature() const{
344  return temperature;
345 }
346 
347 inline void Model::setChemicalPotential(double chemicalPotential){
348  this->chemicalPotential = chemicalPotential;
349 }
350 
351 inline double Model::getChemicalPotential() const{
352  return chemicalPotential;
353 }
354 
355 inline void Model::setStatistics(Statistics statistics){
356  singleParticleContext.setStatistics(statistics);
357 }
358 
360  return singleParticleContext.getStatistics();
361 }
362 
363 inline const BasisStateSet& Model::getBasisStateSet() const{
364  return singleParticleContext.getBasisStateSet();
365 }
366 
368  return singleParticleContext.getHoppingAmplitudeSet();
369 }
370 
372  return singleParticleContext.getSourceAmplitudeSet();
373 }
374 
376  return singleParticleContext.getOverlapAmplitudeSet();
377 }
378 
380  return singleParticleContext.getGeometry();
381 }
382 
383 inline const Geometry& Model::getGeometry() const{
384  return singleParticleContext.getGeometry();
385 }
386 
388  manyParticleContext = new ManyParticleContext(&singleParticleContext);
389 }
390 
391 inline ManyParticleContext* Model::getManyParticleContext(){
392  return manyParticleContext;
393 }
394 
395 inline void Model::setFilter(
396  const AbstractHoppingAmplitudeFilter &hoppingAmplitudeFilter
397 ){
398  if(this->hoppingAmplitudeFilter != nullptr)
399  delete this->hoppingAmplitudeFilter;
400 
401  this->hoppingAmplitudeFilter = hoppingAmplitudeFilter.clone();
402 }
403 
404 inline void Model::setFilter(
405  const AbstractIndexFilter &indexFilter
406 ){
407  if(this->indexFilter != nullptr)
408  delete this->indexFilter;
409  this->indexFilter = indexFilter.clone();
410 
411  if(this->hoppingAmplitudeFilter != nullptr)
412  delete this->hoppingAmplitudeFilter;
413 
414  this->hoppingAmplitudeFilter = new IndexBasedHoppingAmplitudeFilter(
415  indexFilter
416  );
417 }
418 
419 inline Model& Model::operator<<(const AbstractState &basisState){
420  singleParticleContext.getBasisStateSet().add(basisState);
421 
422  return *this;
423 }
424 
425 inline Model& Model::operator<<(const HoppingAmplitude &hoppingAmplitude){
426  if(
427  hoppingAmplitudeFilter == nullptr
428  || hoppingAmplitudeFilter->isIncluded(hoppingAmplitude)
429  ){
430  add(hoppingAmplitude);
431  }
432 
433  return *this;
434 }
435 
436 inline Model& Model::operator<<(const std::tuple<HoppingAmplitude, HoppingAmplitude> &hoppingAmplitudes){
437  if(
438  hoppingAmplitudeFilter == nullptr
439  ){
440  add(std::get<0>(hoppingAmplitudes));
441  add(std::get<1>(hoppingAmplitudes));
442  }
443  else{
444  if(
445  hoppingAmplitudeFilter->isIncluded(
446  std::get<0>(hoppingAmplitudes)
447  )
448  ){
449  add(std::get<0>(hoppingAmplitudes));
450  }
451  if(
452  hoppingAmplitudeFilter->isIncluded(
453  std::get<1>(hoppingAmplitudes)
454  )
455  ){
456  add(std::get<1>(hoppingAmplitudes));
457  }
458  }
459 
460  return *this;
461 }
462 
463 inline Model& Model::operator<<(const HoppingAmplitudeList &hoppingAmplitudeList){
464  for(unsigned int n = 0; n < hoppingAmplitudeList.getSize(); n++)
465  add(hoppingAmplitudeList[n]);
466 
467  return *this;
468 }
469 
470 inline Model& Model::operator<<(const SourceAmplitude &sourceAmplitude){
471  if(
472  indexFilter == nullptr
473  || indexFilter->isIncluded(sourceAmplitude.getIndex())
474  ){
475  singleParticleContext.getSourceAmplitudeSet().add(
476  sourceAmplitude
477  );
478  }
479 
480  return *this;
481 }
482 
483 inline Model& Model::operator<<(const OverlapAmplitude &overlapAmplitude){
484  if(
485  indexFilter == nullptr
486  || (
487  indexFilter->isIncluded(overlapAmplitude.getBraIndex())
488  && indexFilter->isIncluded(
489  overlapAmplitude.getKetIndex()
490  )
491  )
492  ){
493  singleParticleContext.getOverlapAmplitudeSet().add(
494  overlapAmplitude
495  );
496  }
497 
498  return *this;
499 }
500 
501 }; //End of namespace TBTK
502 
503 #endif
TBTK::Model::getChemicalPotential
double getChemicalPotential() const
Definition: Model.h:351
TBTK::Model::getSourceAmplitudeSet
const SourceAmplitudeSet & getSourceAmplitudeSet() const
Definition: Model.h:371
HoppingAmplitudeList.h
List of HoppingAmplitudes .
TBTK::HoppingAmplitudeList
List of HoppingAmplitudes .
Definition: HoppingAmplitudeList.h:34
SingleParticleContext.h
The context for the single particle part of a Model.
TBTK::OverlapAmplitude
Overlap amplitude between state 'bra' and 'ket'.
Definition: OverlapAmplitude.h:37
TBTK::Streamable
Definition: Streamable.h:30
TBTK::SourceAmplitudeSet
SourceAmplitude container.
Definition: SourceAmplitudeSet.h:40
TBTK::Model
Container of Model related information.
Definition: Model.h:57
TBTK::SingleParticleContext::getOverlapAmplitudeSet
OverlapAmplitudeSet & getOverlapAmplitudeSet()
Definition: SingleParticleContext.h:191
TBTK::OverlapAmplitude::getBraIndex
const Index & getBraIndex() const
Definition: OverlapAmplitude.h:186
TBTK::Statistics
Statistics
Definition: Statistics.h:29
TBTK::Model::setStatistics
void setStatistics(Statistics statistics)
Definition: Model.h:355
TBTK::OverlapAmplitudeSet::add
void add(const OverlapAmplitude &overlapAmplitude)
Definition: OverlapAmplitudeSet.h:234
TBTK::Model::getManyParticleContext
ManyParticleContext * getManyParticleContext()
Definition: Model.h:391
TBTK::SingleParticleContext::getHoppingAmplitudeSet
HoppingAmplitudeSet & getHoppingAmplitudeSet()
Definition: SingleParticleContext.h:173
AbstractHoppingAmplitudeFilter.h
Abstract HoppingAmplitude filter.
TBTK::Model::getBasisSize
int getBasisSize() const
Definition: Model.h:311
TBTK::Model::generateOverlapAmplitudeSet
void generateOverlapAmplitudeSet(const OverlapAmplitude::AmplitudeCallback &overlapAmplitudeCallback)
Definition: Model.h:323
Geometry.h
Contains geometric inforamtion about a Model.
TBTK::HoppingAmplitudeSet::add
void add(HoppingAmplitude ha)
TBTK::Model::serialize
std::string serialize(Mode mode) const
TBTK::HoppingAmplitude::AmplitudeCallback
Definition: HoppingAmplitude.h:57
TBTK::Model::getGeometry
Geometry & getGeometry()
Definition: Model.h:379
HoppingAmplitudeSet.h
HoppingAmplitude container.
TBTK::Model::getBasisIndex
int getBasisIndex(const Index &index) const
Definition: Model.h:331
TBTK::SingleParticleContext::getStatistics
Statistics getStatistics() const
Definition: SingleParticleContext.h:161
TBTK::Model::add
void add(HoppingAmplitude ha)
Definition: Model.h:307
TBTK::SingleParticleContext::getGeometry
Geometry & getGeometry()
Definition: SingleParticleContext.h:200
TBTK::Model::setChemicalPotential
void setChemicalPotential(double chemicalPotential)
Definition: Model.h:347
TBTK::Model::addModel
void addModel(const Model &model, const Index &subsytemIndex)
TBTK::Model::getStatistics
Statistics getStatistics() const
Definition: Model.h:359
TBTK::Model::operator<<
Model & operator<<(const AbstractState &basisState)
Definition: Model.h:419
TBTK::SourceAmplitudeSet::add
void add(const SourceAmplitude &sourceAmplitude)
Definition: SourceAmplitudeSet.h:238
TBTK::Model::getTemperature
double getTemperature() const
Definition: Model.h:343
TBTK::OverlapAmplitude::getKetIndex
const Index & getKetIndex() const
Definition: OverlapAmplitude.h:190
TBTK::HoppingAmplitudeSet
HoppingAmplitude container.
Definition: HoppingAmplitudeSet.h:50
TBTK::FileReader
Definition: FileReader.h:50
TBTK::Model::getOverlapAmplitudeSet
const OverlapAmplitudeSet & getOverlapAmplitudeSet() const
Definition: Model.h:375
TBTK::SingleParticleContext::generateHoppingAmplitudeSet
void generateHoppingAmplitudeSet(const HoppingAmplitude::AmplitudeCallback &hoppingAmplitudeCallback)
TBTK::SingleParticleContext::getBasisStateSet
BasisStateSet & getBasisStateSet()
Definition: SingleParticleContext.h:165
TBTK::OverlapAmplitude::AmplitudeCallback
Definition: OverlapAmplitude.h:41
TBTK::Model::generateHoppingAmplitudeSet
void generateHoppingAmplitudeSet(const HoppingAmplitude::AmplitudeCallback &hoppingAmplitudeCallback)
Definition: Model.h:315
TBTK::Serializable
Definition: Serializable.h:43
TBTK::HoppingAmplitudeSet::getBasisSize
int getBasisSize() const
Definition: HoppingAmplitudeTree.h:496
TBTK::Model::getHoppingAmplitudeSet
const HoppingAmplitudeSet & getHoppingAmplitudeSet() const
Definition: Model.h:367
TBTK::AbstractHoppingAmplitudeFilter::clone
virtual AbstractHoppingAmplitudeFilter * clone() const =0
TBTK::AbstractIndexFilter
Definition: AbstractIndexFilter.h:30
TBTK::SingleParticleContext::setStatistics
void setStatistics(Statistics statistics)
Definition: SingleParticleContext.h:157
AbstractIndexFilter.h
Abstract Index filter.
TBTK::AbstractIndexFilter::isIncluded
virtual bool isIncluded(const Index &index) const =0
TBTK::HoppingAmplitudeSet::getIsConstructed
bool getIsConstructed() const
Definition: HoppingAmplitudeSet.h:382
TBTK::SourceAmplitude
Source amplitude for equations with a source term.
Definition: SourceAmplitude.h:40
TBTK::AbstractHoppingAmplitudeFilter::isIncluded
virtual bool isIncluded(const HoppingAmplitude &hoppingAmplitude) const =0
TBTK::Geometry
Contains geometric information about a Model.
Definition: Geometry.h:34
TBTK::Model::toString
virtual std::string toString() const
Serializable.h
Abstract base class for serializable objects.
TBTK::Model::Model
Model()
Streamable.h
Abstract base class for classes that can be written to a stream.
TBTK::Model::setTemperature
void setTemperature(double temperature)
Definition: Model.h:339
TBTK::HoppingAmplitudeSet::getBasisIndex
int getBasisIndex(const Index &index) const
TBTK::Model::getBasisStateSet
const BasisStateSet & getBasisStateSet() const
Definition: Model.h:363
TBTK::Model::createManyParticleContext
void createManyParticleContext()
Definition: Model.h:387
TBTK::HoppingAmplitude
Hopping amplitude from state 'from' to state 'to'.
Definition: HoppingAmplitude.h:53
TBTK::SingleParticleContext::getSourceAmplitudeSet
SourceAmplitudeSet & getSourceAmplitudeSet()
Definition: SingleParticleContext.h:182
TBTK::Model::~Model
virtual ~Model()
TBTK::Model::getIsConstructed
bool getIsConstructed()
Definition: Model.h:335
Statistics.h
Enum class for Fermi-Dirac and Bose-Einstein statistics.
TBTK::Communicator
Base class for classes that can communicate their status during execution.
Definition: Communicator.h:56
Communicator.h
Base class for classes that can communicate their status during execution.
TBTK::SingleParticleContext::generateOverlapAmplitudeSet
void generateOverlapAmplitudeSet(const OverlapAmplitude::AmplitudeCallback &overlapAmplitudeCallback)
TBTK::Model::operator=
Model & operator=(const Model &rhs)
TBTK::OverlapAmplitudeSet
OverlapAmplitude container.
Definition: OverlapAmplitudeSet.h:37
TBTK::SingleParticleContext
The context for the single particle part of a Model.
Definition: SingleParticleContext.h:39
TBTK::Model::setFilter
void setFilter(const AbstractHoppingAmplitudeFilter &hoppingAmplitudeFilter)
Definition: Model.h:395
TBTK::Serializable::Mode
Mode
Definition: Serializable.h:47
TBTK::SourceAmplitude::getIndex
const Index & getIndex() const
Definition: SourceAmplitude.h:146
TBTK::AbstractHoppingAmplitudeFilter
Definition: AbstractHoppingAmplitudeFilter.h:30
TBTK::HoppingAmplitudeList::getSize
unsigned int getSize() const
Definition: HoppingAmplitudeList.h:91
TBTK::Index
Physical index.
Definition: Index.h:44
TBTK::IndexBasedHoppingAmplitudeFilter
Definition: IndexBasedHoppingAmplitudeFilter.h:31
TBTK::Model::construct
void construct()
TBTK::AbstractIndexFilter::clone
virtual AbstractIndexFilter * clone() const =0