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:

## 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

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/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++){
<< 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)]

## ◆ Diagonalizer()

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

Constructs a Solver::Diagonalizer.

## ◆ 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
 state Eigenstate number $$n$$. index Physical 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
 state The 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
 maxIterations Maximum 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
 selfConsistencyCallback A 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:
TBTK::Model
Container of Model related information.
Definition: Model.h:57
Model.h
Container of Model related information.
TBTK::Solver::Diagonalizer
Solves a Model using diagonalization.
Definition: Diagonalizer.h:52
Streams.h
Streams for TBTK output.
TBTK::PropertyExtractor::Diagonalizer
Extracts physical properties from the Solver::Diagonalizer.
Definition: Diagonalizer.h:55
TBTK::Solver::Diagonalizer::run
void run()
Diagonalizer.h
Solves a Model using diagonalization.
TBTK::Initialize
void Initialize()
TBTK::Solver::Solver::setModel
virtual void setModel(Model &model)
Definition: Solver.h:69
TBTK::Solver::Diagonalizer::Diagonalizer
Diagonalizer()
TBTK::HoppingAmplitude
Hopping amplitude from state 'from' to state 'to'.
Definition: HoppingAmplitude.h:53
TBTK::Streams::out
static std::ostream out
Definition: Streams.h:70
TBTK::Communicator::setVerbose
void setVerbose(bool verbose)
Definition: Communicator.h:98
TBTK::Solver::Solver::getModel
Model & getModel()
Definition: Solver.h:73
TBTK.h
TBTK initialization.
TBTK::Model::construct
void construct()