TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::Solver::Diagonalizer Class Reference

Solves a Model using diagonalization. More...

#include <Diagonalizer.h>

Inheritance diagram for TBTK::Solver::Diagonalizer:
TBTK::Solver::Solver TBTK::Communicator

Classes

class  SelfConsistencyCallback
 

Public Member Functions

 Diagonalizer ()
 
void setSelfConsistencyCallback (SelfConsistencyCallback &selfConsistencyCallback)
 
void setMaxIterations (int maxIterations)
 
void run ()
 
const CArray< double > & getEigenValues ()
 
CArray< double > & getEigenValuesRW ()
 
const CArray< std::complex< double > > & getEigenVectors ()
 
CArray< std::complex< double > > & getEigenVectorsRW ()
 
const double getEigenValue (int state)
 
const std::complex< double > getAmplitude (int state, const Index &index)
 
- Public Member Functions inherited from TBTK::Solver::Solver
 Solver ()
 
virtual ~Solver ()
 
virtual void setModel (Model &model)
 
ModelgetModel ()
 
const ModelgetModel () const
 
- Public Member Functions inherited from TBTK::Communicator
 Communicator (bool verbose)
 
void setVerbose (bool verbose)
 
bool getVerbose () const
 

Additional Inherited Members

- Static Public Member Functions inherited from TBTK::Communicator
static void setGlobalVerbose (bool globalVerbose)
 
static bool getGlobalVerbose ()
 

Detailed Description

Solves a Model using diagonalization.

Solves a Model by Diagonalizing the Hamiltonian. Use PropertyExtractor::Diagonalizer to extract Properties.

Scaling behavior:
Time: \(O(h^3)\)
Space: \(O(h^2)\)

Here \(h\) is the size of the Hilbert space basis.

Example

#include "TBTK/Model.h"
#include "TBTK/PropertyExtractor/Diagonalizer.h"
#include "TBTK/Solver/Diagonalizer.h"
#include "TBTK/Streams.h"
#include "TBTK/TBTK.h"
using namespace TBTK;
int main(){
Model model;
model << HoppingAmplitude(1, {0}, {1});
model << HoppingAmplitude(1, {1}, {0});
model.construct();
solver.setVerbose(true);
solver.setModel(model);
solver.run();
Streams::out << "--- Results ----\n";
PropertyExtractor::Diagonalizer propertyExtractor(solver);
for(int n = 0; n < solver.getModel().getBasisSize(); n++){
Streams::out
<< propertyExtractor.getEigenValue(n) << "\t["
<< propertyExtractor.getAmplitude(n, {0}) << "\t"
<< propertyExtractor.getAmplitude(n, {1}) << "]\n";
}
}

Output

Initializing Diagonalizer
Basis size: 2
Running Diagonalizer
.
--- Results ----
-1 [(-0.707107,0) (0.707107,0)]
1 [(0.707107,0) (0.707107,0)]

Constructor & Destructor Documentation

◆ Diagonalizer()

TBTK::Solver::Diagonalizer::Diagonalizer ( )

Constructs a Solver::Diagonalizer.

Member Function Documentation

◆ getAmplitude()

const std::complex< double > TBTK::Solver::Diagonalizer::getAmplitude ( int  state,
const Index index 
)
inline

Get amplitude for given eigenvector \(n\) and physical index \(x\): \(\Psi_{n}(x)\).

Parameters
stateEigenstate number \(n\).
indexPhysical index \(x\).
Returns
The amplitude \(\Psi_{n}(x)\).

◆ getEigenValue()

const double TBTK::Solver::Diagonalizer::getEigenValue ( int  state)
inline

Get eigenvalue for a specific state.

Parameters
stateThe state number, ordered in accending order.
Returns
The eigenvalue for the given state.

◆ getEigenValues()

const CArray< double > & TBTK::Solver::Diagonalizer::getEigenValues ( )
inline

Get eigenvalues. Eigenvalues are ordered in accending order.

Returns
A pointer to the internal storage for the eigenvalues.

◆ getEigenValuesRW()

CArray< double > & TBTK::Solver::Diagonalizer::getEigenValuesRW ( )
inline

Get eigenvalues. Eigenvalues are ordered in accending order. Same as getEigenValues(), but with write access. Use with caution.

Returns
A pointer to the internal storage for the eigenvalues.

◆ getEigenVectors()

const CArray< std::complex< double > > & TBTK::Solver::Diagonalizer::getEigenVectors ( )
inline

Get eigenvectors. The eigenvectors are stored successively in memory, with the eigenvector corresponding to the smallest eigenvalue occupying the 'basisSize' first positions, the second occupying the next 'basisSize' elements, and so forth, where 'basisSize' is the basis size of the Model.

Returns
A pointer to the internal storage for the eigenvectors.

◆ getEigenVectorsRW()

CArray< std::complex< double > > & TBTK::Solver::Diagonalizer::getEigenVectorsRW ( )
inline

Get eigenvectors. The eigenvectors are stored successively in memory, with the eigenvector corresponding to the smallest eigenvalue occupying the 'basisSize' first positions, the second occupying the next 'basisSize' elements, and so forth, where 'basisSize' is the basis size of the Model. Same as getEigenVectors(), but with write access. Use with caution.

Returns
A pointer to the internal storage for the eigenvectors.

◆ run()

void TBTK::Solver::Diagonalizer::run ( )

Run calculations. Diagonalizes ones if no self-consistency callback have been set, or otherwise multiple times until self-consistencey or maximum number of iterations has been reached.

◆ setMaxIterations()

void TBTK::Solver::Diagonalizer::setMaxIterations ( int  maxIterations)
inline

Set the maximum number of iterations for the self-consistency loop. Only used if Diagonalizer::setSelfConsistencyCallback() has been called with a non-nullptr argument. If the self-consistency callback does not return true, maxIterations determines the maximum number of times it is called.

Parameters
maxIterationsMaximum number of iterations to use in a self-consistent callculation.

◆ setSelfConsistencyCallback()

void TBTK::Solver::Diagonalizer::setSelfConsistencyCallback ( SelfConsistencyCallback selfConsistencyCallback)
inline

Set SelfConsistencyCallback. If never called, the self-consistency loop will not be run.

Parameters
selfConsistencyCallbackA SelfConsistencyCallback that will be called after the Model has been diagonalized. The callback should calculate relevant quantities, modify the Model if necessary, and return false if further iteration is necessary. If true is returned, self-consistency is considered to be reached and the iteration stops.

The documentation for this class was generated from the following file: