TBTK
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"
35 #include "TBTK/Serializable.h"
36 #include "TBTK/Statistics.h"
37 
38 #include <complex>
39 #include <fstream>
40 #include <string>
41 #include <tuple>
42 
43 namespace TBTK{
44 
45 class FileReader;
46 
52 class Model : public Serializable, public Communicator{
53 public:
55  Model();
56 
64  Model(const std::vector<unsigned int> &capacity);
65 
69  Model(const Model &model);
70 
74  Model(Model &&model);
75 
83  Model(const std::string &serialization, Mode mode);
84 
86  virtual ~Model();
87 
93  Model& operator=(const Model &rhs);
94 
100  Model& operator=(Model &&rhs);
101 
105  void add(HoppingAmplitude ha);
106 
112  void addModel(const Model &model, const Index &subsytemIndex);
113 
121  int getBasisIndex(const Index &index) const;
122 
127  int getBasisSize() const;
128 
131  void construct();
132 
136  bool getIsConstructed();
137 
139  void sortHoppingAmplitudes();
140 
142  void constructCOO();
143 
145  void destructCOO();
146 
152  void reconstructCOO();
153 
157  void setTemperature(double temperature);
158 
162  double getTemperature() const;
163 
167  void setChemicalPotential(double chemicalPotential);
168 
172  double getChemicalPotential() const;
173 
177  void setStatistics(Statistics statistics);
178 
182  Statistics getStatistics() const;
183 
188 
193 
201  void createGeometry(int dimensions, int numSpecifiers = 0);
202 
207 
211  const Geometry* getGeometry() const;
212 
215 
220 
231  void setFilter(
232  const AbstractHoppingAmplitudeFilter &hoppingAmplitudeFilter
233  );
234 
244  void setFilter(
245  const AbstractIndexFilter &indexFilter
246  );
247 
249  Model& operator<<(const HoppingAmplitude& hoppingAmplitude);
250 
252  Model& operator<<(
253  const std::tuple<HoppingAmplitude, HoppingAmplitude> &hoppingAmplitudes
254  );
255 
257  Model& operator<<(const HoppingAmplitudeList& hoppingAmplitudeList);
258 
260  Model& operator<<(const SourceAmplitude& sourceAmplitude);
261 
264  std::string serialize(Mode mode) const;
265 private:
267  double temperature;
268 
270  double chemicalPotential;
271 
273  SingleParticleContext *singleParticleContext;
274 
276  ManyParticleContext *manyParticleContext;
277 
279  AbstractIndexFilter *indexFilter;
280 
282  AbstractHoppingAmplitudeFilter *hoppingAmplitudeFilter;
283 
285  friend class FileReader;
286 };
287 
288 inline void Model::add(HoppingAmplitude ha){
289  singleParticleContext->getHoppingAmplitudeSet().add(ha);
290 }
291 
292 inline int Model::getBasisSize() const{
293  return singleParticleContext->getHoppingAmplitudeSet().getBasisSize();
294 }
295 
296 inline int Model::getBasisIndex(const Index &index) const{
297  return singleParticleContext->getHoppingAmplitudeSet().getBasisIndex(index);
298 }
299 
301  return singleParticleContext->getHoppingAmplitudeSet().getIsConstructed();
302 }
303 
305  singleParticleContext->sortHoppingAmplitudes();
306 }
307 
308 inline void Model::constructCOO(){
309  singleParticleContext->constructCOO();
310 }
311 
312 inline void Model::destructCOO(){
313  singleParticleContext->getHoppingAmplitudeSet().destructCOO();
314 }
315 
316 inline void Model::reconstructCOO(){
317  singleParticleContext->getHoppingAmplitudeSet().reconstructCOO();
318 }
319 
320 inline void Model::setTemperature(double temperature){
321  this->temperature = temperature;
322 }
323 
324 inline double Model::getTemperature() const{
325  return temperature;
326 }
327 
328 inline void Model::setChemicalPotential(double chemicalPotential){
329  this->chemicalPotential = chemicalPotential;
330 }
331 
332 inline double Model::getChemicalPotential() const{
333  return chemicalPotential;
334 }
335 
336 inline void Model::setStatistics(Statistics statistics){
337  singleParticleContext->setStatistics(statistics);
338 }
339 
341  return singleParticleContext->getStatistics();
342 }
343 
345  return singleParticleContext->getHoppingAmplitudeSet();
346 }
347 
349  return singleParticleContext->getSourceAmplitudeSet();
350 }
351 
352 inline void Model::createGeometry(int dimensions, int numSpecifiers){
353  singleParticleContext->createGeometry(dimensions, numSpecifiers);
354 }
355 
357  return singleParticleContext->getGeometry();
358 }
359 
360 inline const Geometry* Model::getGeometry() const{
361  return singleParticleContext->getGeometry();
362 }
363 
365  manyParticleContext = new ManyParticleContext(singleParticleContext);
366 }
367 
369  return manyParticleContext;
370 }
371 
372 inline void Model::setFilter(
373  const AbstractHoppingAmplitudeFilter &hoppingAmplitudeFilter
374 ){
375  if(this->hoppingAmplitudeFilter != nullptr)
376  delete this->hoppingAmplitudeFilter;
377 
378  this->hoppingAmplitudeFilter = hoppingAmplitudeFilter.clone();
379 }
380 
381 inline void Model::setFilter(
382  const AbstractIndexFilter &indexFilter
383 ){
384  if(this->indexFilter != nullptr)
385  delete this->indexFilter;
386  this->indexFilter = indexFilter.clone();
387 
388  if(this->hoppingAmplitudeFilter != nullptr)
389  delete this->hoppingAmplitudeFilter;
390 
391  this->hoppingAmplitudeFilter = new IndexBasedHoppingAmplitudeFilter(
392  indexFilter
393  );
394 }
395 
396 inline Model& Model::operator<<(const HoppingAmplitude &hoppingAmplitude){
397  if(
398  hoppingAmplitudeFilter == nullptr
399  || hoppingAmplitudeFilter->isIncluded(hoppingAmplitude)
400  ){
401  add(hoppingAmplitude);
402  }
403 
404  return *this;
405 }
406 
407 inline Model& Model::operator<<(const std::tuple<HoppingAmplitude, HoppingAmplitude> &hoppingAmplitudes){
408  if(
409  hoppingAmplitudeFilter == nullptr
410  ){
411  add(std::get<0>(hoppingAmplitudes));
412  add(std::get<1>(hoppingAmplitudes));
413  }
414  else{
415  if(
416  hoppingAmplitudeFilter->isIncluded(
417  std::get<0>(hoppingAmplitudes)
418  )
419  ){
420  add(std::get<0>(hoppingAmplitudes));
421  }
422  if(
423  hoppingAmplitudeFilter->isIncluded(
424  std::get<1>(hoppingAmplitudes)
425  )
426  ){
427  add(std::get<1>(hoppingAmplitudes));
428  }
429  }
430 
431  return *this;
432 }
433 
434 inline Model& Model::operator<<(const HoppingAmplitudeList &hoppingAmplitudeList){
435  for(unsigned int n = 0; n < hoppingAmplitudeList.getSize(); n++)
436  add(hoppingAmplitudeList[n]);
437 
438  return *this;
439 }
440 
441 inline Model& Model::operator<<(const SourceAmplitude &sourceAmplitude){
442  if(
443  indexFilter == nullptr
444  || indexFilter->isIncluded(sourceAmplitude.getIndex())
445  ){
446  singleParticleContext->getSourceAmplitudeSet().add(
447  sourceAmplitude
448  );
449  }
450 
451  return *this;
452 }
453 
454 }; //End of namespace TBTK
455 
456 #endif
Many-particle context.
The context for the single particle part of a Model.
Definition: SingleParticleContext.h:37
unsigned int getSize() const
Definition: HoppingAmplitudeList.h:91
List of HoppingAmplitudes .
Definition: HoppingAmplitudeList.h:34
void constructCOO()
Definition: SingleParticleContext.h:141
virtual bool isIncluded(const Index &index) const =0
Definition: AbstractHoppingAmplitudeFilter.h:30
bool getIsConstructed()
Definition: Model.h:300
HoppingAmplitude container.
Definition: HoppingAmplitudeSet.h:50
Statistics getStatistics() const
Definition: Model.h:340
virtual AbstractHoppingAmplitudeFilter * clone() const =0
void add(HoppingAmplitude ha)
Definition: Model.h:288
Abstract Index filter.
Definition: Serializable.h:40
void createManyParticleContext()
Definition: Model.h:364
void setFilter(const AbstractHoppingAmplitudeFilter &hoppingAmplitudeFilter)
Definition: Model.h:372
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)
const SourceAmplitudeSet & getSourceAmplitudeSet() const
Definition: Model.h:348
int getBasisSize() const
Definition: HoppingAmplitudeTree.h:483
ManyParticleContext * getManyParticleContext()
Definition: Model.h:368
Abstract HoppingAmplitude filter.
std::string serialize(Mode mode) const
Definition: AbstractIndexFilter.h:30
Definition: ManyParticleContext.h:38
const HoppingAmplitudeSet & getHoppingAmplitudeSet() const
Definition: Model.h:344
int getBasisIndex(const Index &index) const
Definition: Model.h:296
HoppingAmplitude container.
Definition: FileReader.h:50
void destructCOO()
Definition: Model.h:312
void setStatistics(Statistics statistics)
Definition: Model.h:336
int getBasisSize() const
Definition: Model.h:292
void setStatistics(Statistics statistics)
Definition: SingleParticleContext.h:129
void createGeometry(int dimensions, int numSpecifiers=0)
bool getIsConstructed() const
Definition: HoppingAmplitudeSet.h:453
void construct()
Model & operator=(const Model &rhs)
The context for the single particle part of a Model.
Geometry * getGeometry()
Definition: Model.h:356
void add(const SourceAmplitude &sourceAmplitude)
Definition: SourceAmplitudeSet.h:237
Hopping amplitude from state &#39;from&#39; to state &#39;to&#39;.
Definition: HoppingAmplitude.h:49
SourceAmplitudeSet & getSourceAmplitudeSet()
Definition: SingleParticleContext.h:155
HoppingAmplitudeSet & getHoppingAmplitudeSet()
Definition: SingleParticleContext.h:146
SourceAmplitude container.
Definition: SourceAmplitudeSet.h:39
void reconstructCOO()
Definition: Model.h:316
const Index & getIndex() const
Definition: SourceAmplitude.h:129
void addModel(const Model &model, const Index &subsytemIndex)
virtual ~Model()
Flexible physical index.
Definition: Index.h:69
Definition: ModelFactory.h:35
Model & operator<<(const HoppingAmplitude &hoppingAmplitude)
Definition: Model.h:396
Statistics getStatistics() const
Definition: SingleParticleContext.h:133
void constructCOO()
Definition: Model.h:308
Base class that communicate their current status during execution.
Contains geometric information about a Model.
Definition: Geometry.h:35
virtual AbstractIndexFilter * clone() const =0
Mode
Definition: Serializable.h:44
void createGeometry(int dimensions, int numSpecifiers=0)
Definition: Model.h:352
void sortHoppingAmplitudes()
Definition: Model.h:304
List of HoppingAmplitudes .
int getBasisIndex(const Index &index) const
double getChemicalPotential() const
Definition: Model.h:332
Abstract base class for serializable objects.
Definition: Communicator.h:28
double getTemperature() const
Definition: Model.h:324
Definition: IndexBasedHoppingAmplitudeFilter.h:31
Container of Model related information.
Definition: Model.h:52
Contains geometric inforamtion about a Model.
Geometry * getGeometry()
Definition: SingleParticleContext.h:164
void setChemicalPotential(double chemicalPotential)
Definition: Model.h:328
Statistics
Definition: Statistics.h:29
void setTemperature(double temperature)
Definition: Model.h:320