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
void generateHoppingAmplitudeSet(const HoppingAmplitude::AmplitudeCallback &hoppingAmplitudeCallback)
Definition: Model.h:315
Abstract base class for classes that can be written to a stream.
Definition: Streamable.h:30
The context for the single particle part of a Model.
Definition: SingleParticleContext.h:39
double getTemperature() const
Definition: Model.h:343
List of HoppingAmplitudes .
Definition: HoppingAmplitudeList.h:34
virtual bool isIncluded(const Index &index) const =0
OverlapAmplitudeSet & getOverlapAmplitudeSet()
Definition: SingleParticleContext.h:191
Definition: AbstractHoppingAmplitudeFilter.h:30
void generateOverlapAmplitudeSet(const OverlapAmplitude::AmplitudeCallback &overlapAmplitudeCallback)
Definition: Model.h:323
bool getIsConstructed()
Definition: Model.h:335
HoppingAmplitude container.
Definition: HoppingAmplitudeSet.h:50
int getBasisIndex(const Index &index) const
Definition: Model.h:331
OverlapAmplitude container.
Definition: OverlapAmplitudeSet.h:37
virtual AbstractHoppingAmplitudeFilter * clone() const =0
void add(HoppingAmplitude ha)
Definition: Model.h:307
Abstract Index filter.
Definition: OverlapAmplitude.h:41
Definition: Serializable.h:43
void createManyParticleContext()
Definition: Model.h:387
int getBasisSize() const
Definition: HoppingAmplitudeTree.h:496
const BasisStateSet & getBasisStateSet() const
Definition: Model.h:363
void setFilter(const AbstractHoppingAmplitudeFilter &hoppingAmplitudeFilter)
Definition: Model.h:395
Enum class for Fermi-Dirac and Bose-Einstein statistics.
virtual bool isIncluded(const HoppingAmplitude &hoppingAmplitude) const =0
Source amplitude for equations with a source term.
Definition: SourceAmplitude.h:40
void add(HoppingAmplitude ha)
ManyParticleContext * getManyParticleContext()
Definition: Model.h:391
Abstract HoppingAmplitude filter.
Geometry & getGeometry()
Definition: Model.h:379
Definition: HoppingAmplitude.h:57
Statistics getStatistics() const
Definition: SingleParticleContext.h:161
Geometry & getGeometry()
Definition: SingleParticleContext.h:200
const Index & getKetIndex() const
Definition: OverlapAmplitude.h:190
Definition: AbstractIndexFilter.h:30
BasisStateSet & getBasisStateSet()
Definition: SingleParticleContext.h:165
HoppingAmplitude container.
Model & operator<<(const AbstractState &basisState)
Definition: Model.h:419
unsigned int getSize() const
Definition: HoppingAmplitudeList.h:91
Definition: FileReader.h:50
const Index & getBraIndex() const
Definition: OverlapAmplitude.h:186
void setStatistics(Statistics statistics)
Definition: Model.h:355
void setStatistics(Statistics statistics)
Definition: SingleParticleContext.h:157
void add(const OverlapAmplitude &overlapAmplitude)
Definition: OverlapAmplitudeSet.h:234
int getBasisIndex(const Index &index) const
void construct()
virtual std::string toString() const
bool getIsConstructed() const
Definition: HoppingAmplitudeSet.h:382
Model & operator=(const Model &rhs)
The context for the single particle part of a Model.
Overlap amplitude between state &#39;bra&#39; and &#39;ket&#39;.
Definition: OverlapAmplitude.h:37
void add(const SourceAmplitude &sourceAmplitude)
Definition: SourceAmplitudeSet.h:238
Hopping amplitude from state &#39;from&#39; to state &#39;to&#39;.
Definition: HoppingAmplitude.h:53
void generateHoppingAmplitudeSet(const HoppingAmplitude::AmplitudeCallback &hoppingAmplitudeCallback)
SourceAmplitudeSet & getSourceAmplitudeSet()
Definition: SingleParticleContext.h:182
HoppingAmplitudeSet & getHoppingAmplitudeSet()
Definition: SingleParticleContext.h:173
SourceAmplitude container.
Definition: SourceAmplitudeSet.h:40
void addModel(const Model &model, const Index &subsytemIndex)
virtual ~Model()
Physical index.
Definition: Index.h:44
Definition: Boolean.h:32
void generateOverlapAmplitudeSet(const OverlapAmplitude::AmplitudeCallback &overlapAmplitudeCallback)
double getChemicalPotential() const
Definition: Model.h:351
Base class for classes that can communicate their status during execution.
std::string serialize(Mode mode) const
Contains geometric information about a Model.
Definition: Geometry.h:34
virtual AbstractIndexFilter * clone() const =0
Mode
Definition: Serializable.h:47
List of HoppingAmplitudes .
Statistics getStatistics() const
Definition: Model.h:359
int getBasisSize() const
Definition: Model.h:311
const SourceAmplitudeSet & getSourceAmplitudeSet() const
Definition: Model.h:371
const Index & getIndex() const
Definition: SourceAmplitude.h:146
Abstract base class for serializable objects.
Base class for classes that can communicate their status during execution.
Definition: Communicator.h:56
Definition: IndexBasedHoppingAmplitudeFilter.h:31
Container of Model related information.
Definition: Model.h:57
Contains geometric inforamtion about a Model.
const OverlapAmplitudeSet & getOverlapAmplitudeSet() const
Definition: Model.h:375
void setChemicalPotential(double chemicalPotential)
Definition: Model.h:347
const HoppingAmplitudeSet & getHoppingAmplitudeSet() const
Definition: Model.h:367
Statistics
Definition: Statistics.h:29
void setTemperature(double temperature)
Definition: Model.h:339