HubbardGPU
Hubbard diagonalisation on the GPU (and CPU)
 All Classes Files Functions Variables Typedefs Friends Macros
MomHamiltonian Class Reference

#include <ham-mom.h>

+ Inheritance diagram for MomHamiltonian:
+ Collaboration diagram for MomHamiltonian:

Public Member Functions

 MomHamiltonian (int L, int Nu, int Nd, double J, double U)
 
virtual ~MomHamiltonian ()
 
void BuildBase ()
 
void BuildFullHam ()
 
virtual void mvprod (double *x, double *y, double alpha) const
 
std::vector< double > ExactDiagonalizeFull (bool calc_eigenvectors)
 
virtual std::vector< std::pair
< int, double > > 
ExactMomDiagonalizeFull (bool calc_eigenvectors)
 
void GenerateData (double Ubegin, double Uend, double step, std::string filename)
 
std::string print_bin (myint num) const
 
virtual void BuildHam ()
 
int getL () const
 
int getNu () const
 
int getNd () const
 
int getDim () const
 
double getJ () const
 
double getU () const
 
void setU (double)
 
myint getBaseUp (unsigned int i) const
 
myint getBaseDown (unsigned int i) const
 
virtual double LanczosDiagonalize (int m=0)
 
virtual double arpackDiagonalize ()
 
void Print (bool list=false) const
 
void PrintBase () const
 
void PrintGroundstateVector () const
 
double MemoryNeededFull () const
 
double MemoryNeededLanczos () const
 
double MemoryNeededArpack () const
 
virtual void SaveToFile (const std::string filename) const
 

Static Public Member Functions

static int CalcDim (int L, int N)
 
static int CountBits (myint bits)
 
static std::string print_bin (myint num, int bitcount)
 

Protected Member Functions

double hopping (myint) const
 
int interaction (int, int, int, int) const
 
void SaveToFile (const std::string filename, double *data, int dim) const
 
int CalcSign (int i, int j, myint a) const
 

Static Protected Member Functions

static void Diagonalize (int dim, double *mat, double *eigs, bool calc_eigenvectors)
 

Protected Attributes

std::vector< std::vector
< std::pair< int, int > > > 
mombase
 
std::vector< std::unique_ptr
< double[]> > 
blockmat
 
int L
 Number of sites. More...
 
int Nu
 Number of up electrons. More...
 
int Nd
 Number of down electrons. More...
 
double J
 Hopping strength. More...
 
double U
 On site interaction strength. More...
 
double * ham
 Storage for the BareHamiltonian matrix. More...
 
int dim
 Dimension of the BareHamiltonian matrix. More...
 
myint Hb
 Hightest bit used. More...
 
int Hbc
 the location of the highest bit More...
 
std::vector< myintbaseUp
 vector to hold all bases ket's for up electrons More...
 
std::vector< myintbaseDown
 vector to hold all bases ket's for down electrons More...
 

Detailed Description

This is the main (base) class. It calculates the full MomHamiltonian matrix for 1D Hubbard. It can both exact diagonlize or use a Lanczos algorithm to calculate the groundstate energy.

Author
Ward Poelmans wpoel.nosp@m.y86@.nosp@m.gmail.nosp@m..com

Definition at line 33 of file ham-mom.h.

Constructor & Destructor Documentation

MomHamiltonian::MomHamiltonian ( int  L,
int  Nu,
int  Nd,
double  J,
double  U 
)

Constructor of the MomHamiltonian class

Parameters
LNumber of lattice sites
NuNumber of Up Electrons
NdNumber of Down Electrons
JThe hopping strengh
UThe onsite interaction strength

Definition at line 45 of file ham-mom.cpp.

MomHamiltonian::~MomHamiltonian ( )
virtual

Destructor of the MomHamiltonian class

Definition at line 52 of file ham-mom.cpp.

Member Function Documentation

double BareHamiltonian::arpackDiagonalize ( )
virtualinherited

Definition at line 436 of file bare-ham.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MomHamiltonian::BuildBase ( )
virtual

Builds all the up and down base kets in the momentum base Sort them so we have a block diagonal matrix according to total momentum

Reimplemented from BareHamiltonian.

Definition at line 60 of file ham-mom.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MomHamiltonian::BuildFullHam ( )
virtual

Builds the full MomHamiltonian matrix

Implements BareHamiltonian.

Definition at line 131 of file ham-mom.cpp.

+ Here is the call graph for this function:

void BareHamiltonian::BuildHam ( )
virtualinherited

This method is always present and should build the Hamiltonian, either full or sparse

Definition at line 165 of file bare-ham.cpp.

+ Here is the call graph for this function:

int BareHamiltonian::CalcDim ( int  L,
int  N 
)
staticinherited

Calculates the dimension for the up or down electron space. Basically, it calculates the N-combination out of L. This algorithm is not perfect, overflow can occur but should be no problem for our small problems.

Parameters
Lnumber of lattice sites
Nnumber of up or down electrons
Returns
the dimension of the up or down electron space

Definition at line 83 of file bare-ham.cpp.

+ Here is the caller graph for this function:

int BareHamiltonian::CalcSign ( int  i,
int  j,
myint  a 
) const
protectedinherited

Calculates the sign of the hop between site i and site j on ket a. Make sure that i < j!

Parameters
ithe first sp
jthe second sp
athe ket to use
Returns
the sign of the hop

Definition at line 178 of file bare-ham.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int BareHamiltonian::CountBits ( myint  bits)
staticinherited

Counts the number of bits set. It uses the builtin gcc function __buildtin_popcount. You must compile with -march=native and it will then generate a POPCNT instruction on platforms that support it. Otherwise it will be slow. Consider using a different method here if you don't have the POPCNT instruction: there are fast SSSE3 and SSE2 ways to do this(google is your friend).

Parameters
bitsthe myint of which to count the number of bits set
Returns
the number of bits set

Definition at line 106 of file bare-ham.cpp.

+ Here is the caller graph for this function:

void BareHamiltonian::Diagonalize ( int  dim,
double *  mat,
double *  eigs,
bool  calc_eigenvectors 
)
staticprotectedinherited

Helper for exact diagonalization: diagonalize the matrix given in mat with dimension dim, stores the eigenvalues in eigs and optionally the eigenvectors in mat

Parameters
dimthe dimension of the matrix
matthe actual matrix (size: dim*dim)
eigsarray of size dim to store eigenvalues
calc_eigenvectorswhether or not the calculate the eigenvectors

Definition at line 681 of file bare-ham.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< double > MomHamiltonian::ExactDiagonalizeFull ( bool  calc_eigenvectors)
virtual

Exactly calculates the eigenvalues of the matrix. Needs lapack.

Parameters
calc_eigenvectorsset to true to calculate the eigenvectors. The hamiltonian matrix is then overwritten by the vectors.
Returns
the vector of the sorted eigenvalues

Reimplemented from BareHamiltonian.

Definition at line 310 of file ham-mom.cpp.

+ Here is the call graph for this function:

std::vector< std::pair< int, double > > MomHamiltonian::ExactMomDiagonalizeFull ( bool  calc_eigenvectors)
virtual

Diagonalize the block diagonal matrix. Needs lapack. Differs from MomHamiltonian::ExactDiagonalizeFull that is diagonalize block per block and keeps the momentum associated with each eigenvalue.

Parameters
calc_eigenvectorsset to true to calculate the eigenvectors. The hamiltonian matrix is then overwritten by the vectors.
Returns
a vector of pairs. The first member of the pair is the momentum, the second is the eigenvalue. The vector is sorted to the eigenvalues.

Definition at line 338 of file ham-mom.cpp.

+ Here is the call graph for this function:

void MomHamiltonian::GenerateData ( double  Ubegin,
double  Uend,
double  step,
std::string  filename 
)

This methods calculates the eigenvalues for a range of U values. The interval is [Ubegin, Uend] with a stepsize of step. The resulting data is written to a file in the HDF5 file format.

Parameters
Ubeginthe startpoint for U
Uendthe endpoint for U. We demand Ubegin < Uend
stepthe stepsize to use for U
filenamethe name of the file write to written the eigenvalues to

Definition at line 374 of file ham-mom.cpp.

+ Here is the call graph for this function:

myint BareHamiltonian::getBaseDown ( unsigned int  i) const
inherited

Getter for the i base down ket

Parameters
ithe number of the base ket
Returns
the base ket

Definition at line 270 of file bare-ham.cpp.

+ Here is the caller graph for this function:

myint BareHamiltonian::getBaseUp ( unsigned int  i) const
inherited

Getter for the i base up ket

Parameters
ithe number of the base ket
Returns
the base ket

Definition at line 260 of file bare-ham.cpp.

+ Here is the caller graph for this function:

int BareHamiltonian::getDim ( ) const
inherited

Getter for the dimension of the BareHamiltonian matrix

Returns
dimension of the BareHamiltonian matrix

Definition at line 223 of file bare-ham.cpp.

+ Here is the caller graph for this function:

double BareHamiltonian::getJ ( ) const
inherited

Getter for the hopping strength

Returns
the hopping strength

Definition at line 232 of file bare-ham.cpp.

int BareHamiltonian::getL ( ) const
inherited

Getter for the number of lattice sites

Returns
the number of lattice sites

Definition at line 196 of file bare-ham.cpp.

int BareHamiltonian::getNd ( ) const
inherited

Getter for the number of down electrons

Returns
the number of down electrons

Definition at line 214 of file bare-ham.cpp.

int BareHamiltonian::getNu ( ) const
inherited

Getter for the number of up electrons

Returns
the number of up electrons

Definition at line 205 of file bare-ham.cpp.

double BareHamiltonian::getU ( ) const
inherited

Getter for the onsite interaction strength

Returns
the onsite interaction strength

Definition at line 241 of file bare-ham.cpp.

double MomHamiltonian::hopping ( myint  ket) const
protected

private method used to see if a hopping between state a and b is possible and with which sign. Only for 1D Hubbard.

Parameters
ketthe ket to use
Returns
matrix element of the hopping term between the ket and the bra. You still have to multiply this with the hopping strength J

Definition at line 262 of file ham-mom.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int MomHamiltonian::interaction ( int  a,
int  b,
int  c,
int  d 
) const
protected

private method to calculate the interaction between a 2 particle ket and bra

Parameters
athe first base vector of the bra
bthe second base vector of the bra
cthe first base vector of the ket
dthe second base vector of the ket
Returns
matrix element of the interaction term between the ket and the bra. You still have to multiply this with the interaction strength U and divide by the lattice length L

Definition at line 177 of file ham-mom.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double BareHamiltonian::LanczosDiagonalize ( int  m = 0)
virtualinherited

Calculates the lowest eigenvalue of the BareHamiltonian matrix using the lanczos algorithm. Needs lapack.

Parameters
man optional estimate for the lanczos space size
Returns
the lowest eigenvalue

Definition at line 313 of file bare-ham.cpp.

+ Here is the call graph for this function:

double BareHamiltonian::MemoryNeededArpack ( ) const
inherited

Calculates the amount of memory needed for the calculation if we use the arpack. It doesn't include the program code and stuff.

Returns
the amount of memory needed in bytes

Definition at line 643 of file bare-ham.cpp.

+ Here is the call graph for this function:

double BareHamiltonian::MemoryNeededFull ( ) const
inherited

Calculates the amount of memory needed for the calculation of all eigenvalues using the exact method. It doesn't include the program code and stuff.

Returns
the amount of memory needed in bytes

Definition at line 591 of file bare-ham.cpp.

+ Here is the call graph for this function:

double BareHamiltonian::MemoryNeededLanczos ( ) const
inherited

Calculates the amount of memory needed for the calculation if we use the lanczos method. It doesn't include the program code and stuff.

Returns
the amount of memory needed in bytes

Definition at line 617 of file bare-ham.cpp.

+ Here is the call graph for this function:

void MomHamiltonian::mvprod ( double *  x,
double *  y,
double  alpha 
) const
virtual

Matrix vector product with MomHamiltonian: y = ham*x + alpha*y

Parameters
xthe input vector
ythe output vector
alphathe scaling value

Implements BareHamiltonian.

Definition at line 285 of file ham-mom.cpp.

+ Here is the call graph for this function:

void BareHamiltonian::Print ( bool  list = false) const
inherited

Prints the full BareHamiltonian matrix to stdout

Definition at line 410 of file bare-ham.cpp.

std::string BareHamiltonian::print_bin ( myint  num) const
inherited

Print a int in binary form to a string. Prints a much as needed to represent the current system.

Parameters
numthe myint to print in binary form
Returns
a string with the binary representation of num

Definition at line 138 of file bare-ham.cpp.

+ Here is the caller graph for this function:

std::string BareHamiltonian::print_bin ( myint  num,
int  bitcount 
)
staticinherited

Print a int in binary form to a string. It only prints the bitcount least significant bits

Parameters
numthe myint to print in binary form
bitcountthe number of bits to print (starting from the LSB)
Returns
a string with the binary representation of num

Definition at line 118 of file bare-ham.cpp.

void BareHamiltonian::PrintBase ( ) const
inherited

Print the basis set used.

Definition at line 429 of file bare-ham.cpp.

+ Here is the call graph for this function:

void BareHamiltonian::PrintGroundstateVector ( ) const
inherited

Prints the groundstate in function of the basis vectors Only gives meanfull output after running BareHamiltonian::ExactDiagonalizeFull(true)

Definition at line 295 of file bare-ham.cpp.

+ Here is the call graph for this function:

void BareHamiltonian::SaveToFile ( const std::string  filename) const
virtualinherited

Save the hamiltonian matrix to a file in the HDF5 format

Parameters
filenamethe name of the file to write to

Definition at line 727 of file bare-ham.cpp.

+ Here is the caller graph for this function:

void BareHamiltonian::SaveToFile ( const std::string  filename,
double *  data,
int  dim 
) const
protectedinherited

Save a array to a file in the HDF5 format

Parameters
filenamethe name of the file to write to
dataa pointer to the array to write to a file
dimthe size of the array

Definition at line 741 of file bare-ham.cpp.

void BareHamiltonian::setU ( double  myU)
inherited

Set the value of U

Parameters
myUthe value of U

Definition at line 250 of file bare-ham.cpp.

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<myint> BareHamiltonian::baseDown
protectedinherited

vector to hold all bases ket's for down electrons

Definition at line 138 of file bare-ham.h.

std::vector<myint> BareHamiltonian::baseUp
protectedinherited

vector to hold all bases ket's for up electrons

Definition at line 136 of file bare-ham.h.

std::vector< std::unique_ptr<double []> > MomHamiltonian::blockmat
protected

Definition at line 57 of file ham-mom.h.

int BareHamiltonian::dim
protectedinherited

Dimension of the BareHamiltonian matrix.

Definition at line 128 of file bare-ham.h.

double* BareHamiltonian::ham
protectedinherited

Storage for the BareHamiltonian matrix.

Definition at line 126 of file bare-ham.h.

myint BareHamiltonian::Hb
protectedinherited

Hightest bit used.

Definition at line 131 of file bare-ham.h.

int BareHamiltonian::Hbc
protectedinherited

the location of the highest bit

Definition at line 133 of file bare-ham.h.

double BareHamiltonian::J
protectedinherited

Hopping strength.

Definition at line 122 of file bare-ham.h.

int BareHamiltonian::L
protectedinherited

Number of sites.

Definition at line 116 of file bare-ham.h.

std::vector< std::vector< std::pair<int,int> > > MomHamiltonian::mombase
protected

Definition at line 55 of file ham-mom.h.

int BareHamiltonian::Nd
protectedinherited

Number of down electrons.

Definition at line 120 of file bare-ham.h.

int BareHamiltonian::Nu
protectedinherited

Number of up electrons.

Definition at line 118 of file bare-ham.h.

double BareHamiltonian::U
protectedinherited

On site interaction strength.

Definition at line 124 of file bare-ham.h.


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