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"
34 #include "TBTK/ManyBodyContext.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 
58  Model(const std::vector<unsigned int> &capacity);
59 
61  Model(const Model &model);
62 
64  Model(Model &&model);
65 
68  Model(const std::string &serialization, Mode mode);
69 
71  virtual ~Model();
72 
74  Model& operator=(const Model &model);
75 
77  Model& operator=(Model &&model);
78 
81 
84 
86  void addModel(const Model &model, const Index &subsytemIndex);
87 
90  int getBasisIndex(const Index &index) const;
91 
93  int getBasisSize() const;
94 
97  void construct();
98 
100  bool getIsConstructed();
101 
103  void sortHoppingAmplitudes();
104 
106  void constructCOO();
107 
109  void destructCOO();
110 
116  void reconstructCOO();
117 
119  void setTemperature(double temperature);
120 
122  double getTemperature() const;
123 
125  void setChemicalPotential(double chemicalPotential);
126 
128  double getChemicalPotential() const;
129 
131  void setStatistics(Statistics statistics);
132 
134  Statistics getStatistics() const;
135 
138 
140  void createGeometry(int dimensions, int numSpecifiers = 0);
141 
144 
146  const Geometry* getGeometry() const;
147 
149  void createManyBodyContext();
150 
153 
155  void setFilter(
156  const AbstractHoppingAmplitudeFilter &hoppingAmplitudeFilter
157  );
158 
160  void setFilter(
161  const AbstractIndexFilter &indexFilter
162  );
163 
164 // void saveEV(std::string path = "./", std::string filename = "EV.dat");
165 
167  Model& operator<<(const HoppingAmplitude& hoppingAmplitude);
168 
170  Model& operator<<(
171  const std::tuple<HoppingAmplitude, HoppingAmplitude> &hoppingAmplitudes
172  );
173 
175  Model& operator<<(const HoppingAmplitudeList& hoppingAmplitudeList);
176 
179  std::string serialize(Mode mode) const;
180 private:
182  double temperature;
183 
185  double chemicalPotential;
186 
188  SingleParticleContext *singleParticleContext;
189 
191  ManyBodyContext *manyBodyContext;
192 
194  AbstractHoppingAmplitudeFilter *hoppingAmplitudeFilter;
195 
197  friend class FileReader;
198 };
199 
201  singleParticleContext->addHoppingAmplitude(ha);
202 }
203 
206 ){
207  singleParticleContext->addHoppingAmplitudeAndHermitianConjugate(ha);
208 }
209 
210 inline int Model::getBasisSize() const{
211  return singleParticleContext->getBasisSize();
212 }
213 
214 inline int Model::getBasisIndex(const Index &index) const{
215  return singleParticleContext->getBasisIndex(index);
216 }
217 
219  return singleParticleContext->getIsConstructed();
220 }
221 
223  singleParticleContext->sortHoppingAmplitudes();
224 }
225 
226 inline void Model::constructCOO(){
227  singleParticleContext->constructCOO();
228 }
229 
230 inline void Model::destructCOO(){
231  singleParticleContext->destructCOO();
232 }
233 
234 inline void Model::reconstructCOO(){
235  singleParticleContext->reconstructCOO();
236 }
237 
238 inline void Model::setTemperature(double temperature){
239  this->temperature = temperature;
240 }
241 
242 inline double Model::getTemperature() const{
243  return temperature;
244 }
245 
246 inline void Model::setChemicalPotential(double chemicalPotential){
247  this->chemicalPotential = chemicalPotential;
248 }
249 
250 inline double Model::getChemicalPotential() const{
251  return chemicalPotential;
252 }
253 
254 inline void Model::setStatistics(Statistics statistics){
255  singleParticleContext->setStatistics(statistics);
256 }
257 
259  return singleParticleContext->getStatistics();
260 }
261 
263  return singleParticleContext->getHoppingAmplitudeSet();
264 }
265 
266 inline void Model::createGeometry(int dimensions, int numSpecifiers){
267  singleParticleContext->createGeometry(dimensions, numSpecifiers);
268 }
269 
271  return singleParticleContext->getGeometry();
272 }
273 
274 inline const Geometry* Model::getGeometry() const{
275  return singleParticleContext->getGeometry();
276 }
277 
279  manyBodyContext = new ManyBodyContext(singleParticleContext);
280 }
281 
283  return manyBodyContext;
284 }
285 
286 inline void Model::setFilter(
287  const AbstractHoppingAmplitudeFilter &hoppingAmplitudeFilter
288 ){
289  if(this->hoppingAmplitudeFilter != nullptr)
290  delete this->hoppingAmplitudeFilter;
291 
292  this->hoppingAmplitudeFilter = hoppingAmplitudeFilter.clone();
293 }
294 
295 inline void Model::setFilter(
296  const AbstractIndexFilter &indexFilter
297 ){
298  if(this->hoppingAmplitudeFilter != nullptr)
299  delete this->hoppingAmplitudeFilter;
300 
301  this->hoppingAmplitudeFilter = new IndexBasedHoppingAmplitudeFilter(
302  indexFilter
303  );
304 }
305 
306 inline Model& Model::operator<<(const HoppingAmplitude &hoppingAmplitude){
307  if(
308  hoppingAmplitudeFilter == nullptr
309  || hoppingAmplitudeFilter->isIncluded(hoppingAmplitude)
310  ){
311  addHoppingAmplitude(hoppingAmplitude);
312  }
313 
314  return *this;
315 }
316 
317 inline Model& Model::operator<<(const std::tuple<HoppingAmplitude, HoppingAmplitude> &hoppingAmplitudes){
318  if(
319  hoppingAmplitudeFilter == nullptr
320  ){
321  addHoppingAmplitude(std::get<0>(hoppingAmplitudes));
322  addHoppingAmplitude(std::get<1>(hoppingAmplitudes));
323  }
324  else{
325  if(
326  hoppingAmplitudeFilter->isIncluded(
327  std::get<0>(hoppingAmplitudes)
328  )
329  ){
330  addHoppingAmplitude(std::get<0>(hoppingAmplitudes));
331  }
332  if(
333  hoppingAmplitudeFilter->isIncluded(
334  std::get<1>(hoppingAmplitudes)
335  )
336  ){
337  addHoppingAmplitude(std::get<1>(hoppingAmplitudes));
338  }
339  }
340 
341  return *this;
342 }
343 
344 inline Model& Model::operator<<(const HoppingAmplitudeList &hoppingAmplitudeList){
345  for(unsigned int n = 0; n < hoppingAmplitudeList.getSize(); n++)
346  addHoppingAmplitude(hoppingAmplitudeList[n]);
347 
348  return *this;
349 }
350 
351 }; //End of namespace TBTK
352 
353 #endif
The context for the single particle part of a Model.
Definition: SingleParticleContext.h:36
unsigned int getSize() const
Definition: HoppingAmplitudeList.h:89
List of HoppingAmplitudes .
Definition: HoppingAmplitudeList.h:34
void constructCOO()
Definition: SingleParticleContext.h:169
Definition: AbstractHoppingAmplitudeFilter.h:30
void destructCOO()
Definition: SingleParticleContext.h:174
void createManyBodyContext()
Definition: Model.h:278
void reconstructCOO()
Definition: SingleParticleContext.h:178
int getBasisSize() const
Definition: SingleParticleContext.h:157
bool getIsConstructed()
Definition: Model.h:218
int getBasisIndex(const Index &index) const
Definition: SingleParticleContext.h:153
HoppingAmplitude container.
Definition: HoppingAmplitudeSet.h:49
Statistics getStatistics() const
Definition: Model.h:258
virtual AbstractHoppingAmplitudeFilter * clone() const =0
Abstract Index filter.
Definition: Serializable.h:40
void setFilter(const AbstractHoppingAmplitudeFilter &hoppingAmplitudeFilter)
Definition: Model.h:286
Enum class for Fermi-Dirac and Bose-Einstein statistics.
virtual bool isIncluded(const HoppingAmplitude &hoppingAmplitude) const =0
void addHoppingAmplitudeAndHermitianConjugate(HoppingAmplitude ha)
Definition: SingleParticleContext.h:147
Abstract HoppingAmplitude filter.
std::string serialize(Mode mode) const
Definition: AbstractIndexFilter.h:30
int getBasisIndex(const Index &index) const
Definition: Model.h:214
HoppingAmplitude container.
Many-body context.
Model & operator=(const Model &model)
Definition: FileReader.h:50
void destructCOO()
Definition: Model.h:230
void setStatistics(Statistics statistics)
Definition: Model.h:254
int getBasisSize() const
Definition: Model.h:210
void setStatistics(Statistics statistics)
Definition: SingleParticleContext.h:135
void createGeometry(int dimensions, int numSpecifiers=0)
void construct()
The context for the single particle part of a Model.
Geometry * getGeometry()
Definition: Model.h:270
const HoppingAmplitudeSet * getHoppingAmplitudeSet() const
Definition: SingleParticleContext.h:182
Hopping amplitude from state &#39;from&#39; to state &#39;to&#39;.
Definition: HoppingAmplitude.h:49
void reconstructCOO()
Definition: Model.h:234
void addHoppingAmplitude(HoppingAmplitude ha)
Definition: Model.h:200
void addModel(const Model &model, const Index &subsytemIndex)
virtual ~Model()
Flexible physical index.
Definition: Index.h:70
Definition: ModelFactory.h:35
Model & operator<<(const HoppingAmplitude &hoppingAmplitude)
Definition: Model.h:306
bool getIsConstructed() const
Definition: SingleParticleContext.h:161
Statistics getStatistics() const
Definition: SingleParticleContext.h:139
void constructCOO()
Definition: Model.h:226
Base class that communicate their current status during execution.
Contains geometric information about a Model.
Definition: Geometry.h:35
void addHoppingAmplitude(HoppingAmplitude ha)
Definition: SingleParticleContext.h:143
Mode
Definition: Serializable.h:44
void createGeometry(int dimensions, int numSpecifiers=0)
Definition: Model.h:266
void sortHoppingAmplitudes()
Definition: Model.h:222
List of HoppingAmplitudes .
const HoppingAmplitudeSet * getHoppingAmplitudeSet() const
Definition: Model.h:262
double getChemicalPotential() const
Definition: Model.h:250
ManyBodyContext * getManyBodyContext()
Definition: Model.h:282
Abstract base class for serializable objects.
Definition: Communicator.h:28
double getTemperature() const
Definition: Model.h:242
Definition: IndexBasedHoppingAmplitudeFilter.h:31
Container of Model related information.
Definition: Model.h:52
Definition: ManyBodyContext.h:38
void addHoppingAmplitudeAndHermitianConjugate(HoppingAmplitude ha)
Definition: Model.h:204
Contains geometric inforamtion about a Model.
Geometry * getGeometry()
Definition: SingleParticleContext.h:186
void setChemicalPotential(double chemicalPotential)
Definition: Model.h:246
Statistics
Definition: Statistics.h:29
void setTemperature(double temperature)
Definition: Model.h:238