TBTK
TimeEvolver.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_TIME_EVOLVER
24 #define COM_DAFER45_TBTK_TIME_EVOLVER
25 
26 #include "TBTK/Solver/Diagonalizer.h"
27 #include "TBTK/Model.h"
28 #include "TBTK/UnitHandler.h"
29 
30 #include <complex>
31 #include <vector>
32 
33 namespace TBTK{
34 namespace Solver{
35 
37 class TimeEvolver : public Solver{
38 public:
40  TimeEvolver();
41 
43  virtual ~TimeEvolver();
44 
49  void run();
50 
52  void setCallback(bool (*callback)(TimeEvolver *timeEvolver));
53 
55  void setMaxSCIterations(int maxIterations);
56 
58  void setNumTimeSteps(int numTimeSteps);
59 
61  void setTimeStep(double dt);
62 
70  void setNumberOfParticles(int numberOfParticles);
71 
74 
77  void fixParticleNumber(bool particleNumberIsFixed);
78 
80  double getOccupancy(int state);
81 
85 
87  double getEigenValue(int state);
88 
93  const std::complex<double> getAmplitude(int state, const Index &index);
94 
108  enum class DecayMode{None, Instantly, Interpolate, Custom};
109 
111  void setDecayMode(DecayMode decayMode);
112 
113  class DecayHandler{
114  public:
115  virtual void decay(
116  TimeEvolver *timeEvolver,
117  double *occupancy,
118  double *eigenValues,
119  std::complex<double> **eigenVectorsMap
120  ) = 0;
121  private:
122  };
123 
125  void setDecayHandler(DecayHandler *decayHandler);
126 
129  int getCurrentTimeStep();
130 
134  void setOrthogonalityCheckInterval(int orthogonalityCheckInterval);
135 
137  double getOrthogonalityError();
138 private:
142  Diagonalizer dSolver;
143 
145  double *eigenValues;
146 
148  std::complex<double> *eigenVectors;
149 
154  std::complex<double> **eigenVectorsMap;
155 
157  double* occupancy;
158 
160  int numberOfParticles;
161 
164  bool particleNumberIsFixed;
165 
167  DecayMode decayMode;
168 
170  DecayHandler *decayHandler;
171 
174  bool (*callback)(TimeEvolver *timeEvolver);
175 
177  int numTimeSteps;
178 
180  double dt;
181 
183  int currentTimeStep;
184 
188  static std::vector<TimeEvolver*> timeEvolvers;
189 
193  static std::vector<Diagonalizer*> dSolvers;
194 
200  static bool selfConsistencyCallback(Diagonalizer &dSolver);
201 
204  void onDiagonalizationFinished();
205 
208  void sort();
209 
211  void updateOccupancy();
212 
214  void decayInstantly();
215 
217  void decayInterpolate();
218 
221  double orthogonalityError;
222 
225  int orthogonalityCheckInterval;
226 
228  void calculateOrthogonalityError();
229 };
230 
232  bool (*callback)(TimeEvolver *timeEvolver)
233 ){
234  this->callback = callback;
235 }
236 
237 inline void TimeEvolver::setMaxSCIterations(int maxIterations){
238  dSolver.setMaxIterations(maxIterations);
239 }
240 
241 inline void TimeEvolver::setNumTimeSteps(int numTimeSteps){
242  this->numTimeSteps = numTimeSteps;
243 }
244 
245 inline void TimeEvolver::setTimeStep(double dt){
246  this->dt = dt;
247 }
248 
249 inline void TimeEvolver::setNumberOfParticles(int numberOfParticles){
250  this->numberOfParticles = numberOfParticles;
251 }
252 
254  return numberOfParticles;
255 }
256 
257 inline void TimeEvolver::fixParticleNumber(bool particleNumberIsFixed){
258  this->particleNumberIsFixed = particleNumberIsFixed;
259 }
260 
262  return &dSolver;
263 }
264 
265 inline double TimeEvolver::getEigenValue(int state){
266  return eigenValues[state];
267 }
268 
269 inline double TimeEvolver::getOccupancy(int state){
270  return occupancy[state];
271 }
272 
273 inline const std::complex<double> TimeEvolver::getAmplitude(
274  int state,
275  const Index &index
276 ){
277  return eigenVectorsMap[state][getModel().getBasisIndex(index)];
278 }
279 
280 inline void TimeEvolver::setDecayMode(DecayMode decayMode){
281  this->decayMode = decayMode;
282 }
283 
284 inline void TimeEvolver::setDecayHandler(DecayHandler *decayHandler){
285  this->decayHandler = decayHandler;
286 }
287 
288 inline int TimeEvolver::getCurrentTimeStep(){
289  return currentTimeStep;
290 }
291 
292 inline void TimeEvolver::setOrthogonalityCheckInterval(
293  int orthogonalityCheckInterval
294 ){
295  this->orthogonalityCheckInterval = orthogonalityCheckInterval;
296 }
297 
298 inline double TimeEvolver::getOrthogonalityError(){
299  return orthogonalityError;
300 }
301 
302 }; //End of namespace Solver
303 }; //End of namespace TBTK
304 
305 #endif
Base class for Solvers.
Definition: Solver.h:32
Model & getModel()
Definition: Solver.h:57
void setTimeStep(double dt)
Definition: TimeEvolver.h:245
double getOccupancy(int state)
Definition: TimeEvolver.h:269
void setMaxSCIterations(int maxIterations)
Definition: TimeEvolver.h:237
void fixParticleNumber(bool particleNumberIsFixed)
Definition: TimeEvolver.h:257
Handles conversions between different units.
Container of Model related information.
int getNumberOfParticles()
Definition: TimeEvolver.h:253
int getBasisIndex(const Index &index) const
Definition: Model.h:214
Solves a Model using diagonalization.
Definition: Diagonalizer.h:42
double getEigenValue(int state)
Definition: TimeEvolver.h:265
Time evloves a ground state.
Definition: TimeEvolver.h:37
void setCallback(bool(*callback)(TimeEvolver *timeEvolver))
Definition: TimeEvolver.h:231
Flexible physical index.
Definition: Index.h:70
Definition: ModelFactory.h:35
void setNumTimeSteps(int numTimeSteps)
Definition: TimeEvolver.h:241
void setNumberOfParticles(int numberOfParticles)
Definition: TimeEvolver.h:249
Diagonalizer * getDiagonalizer()
Definition: TimeEvolver.h:261