Codes for constructing matrix of Hamiltonion of 2D square Tight-bonding model

Click For Summary
SUMMARY

This discussion focuses on constructing and diagonalizing the Hamiltonian matrix of a 2D square Tight-binding model using Fortran. The provided code utilizes LAPACK routines for diagonalization, specifically the dsyevd function. Users can compile the program with gfortran -llapack 2D.f90 or ifort -llapack 2D.f90. The code includes detailed comments explaining the construction of the Hamiltonian matrix and the extraction of eigenvalues after diagonalization.

PREREQUISITES
  • Fortran programming language
  • LAPACK library for linear algebra operations
  • Understanding of Hamiltonian mechanics in quantum physics
  • Matrix diagonalization techniques
NEXT STEPS
  • Learn how to implement LAPACK routines in other programming languages such as Python or C++.
  • Explore advanced topics in quantum mechanics related to Tight-binding models.
  • Study matrix construction techniques for different boundary conditions.
  • Investigate performance optimization techniques for large matrix diagonalization.
USEFUL FOR

Quantum physicists, computational scientists, and software developers interested in quantum mechanics simulations and matrix computations.

Sheldon Coope
Messages
2
Reaction score
0
Hello,
Does anyone know how to write codes for constructing the matrix of Hamiltonion of 2D square Tight-bonding model. Then diagonalize it.
Any language is OK. (Fortran is best)
 
Physics news on Phys.org
Hello,

This program shows the principle of diagonalizing a
matrix in fortran, using a 2D geometry. To compile, write
gfortran -llapack 2D.f90
then write ./a.out to run the program
Or ifort -llapack 2D.f90


Code:
module shared !every function and routine which
implicit none !includes the module shared can use its 
real*8, allocatable :: Hdiag(:,:),eigenvalues(:)  !variables
end module shared

program diag
use shared !now the program diag knows about Hdiag and eigenvalues
implicit none !this makes sure one has do define everything explicitly
integer :: nsize !size of the matrix to be diagonalized
integer :: i,j,icount,jcount,norb
integer :: i1,i2,j1,j2
real*8 :: v

norb = 5 !size of system

nsize = norb*norb !size of hamiltonian

allocate(Hdiag(nsize,nsize)) !This is the matrix to be diagonalized
allocate(eigenvalues(nsize)) !after diagonalization, this vector 
!contains the eigenvalues 

v = -1.0 !this is the hopping parameter

!Now we construct the hamiltonian, and we do that by first looping over
!j, and then i. This are non-periodic boundary conditions.
icount = 0
jcount = 0
do i1=1,norb
do j1=1,norb
   jcount = 0
   icount = icount + 1
   do i2=1,norb
   do j2=1,norb
      jcount = jcount + 1
      if (abs(i1-i2) + abs(j1-j2) == 1)Hdiag(icount,jcount) = v !if distance == 1, put hopping parameter = v
      write(11,*)'hop(',icount,jcount,')=',Hdiag(icount,jcount) !this prints the hamiltonian to disc 
   end do                                 
   end do
end do
end do

call diagonalize(nsize) !now Hdiag will be diagonalized.
!After diagonalization, Hdiag(:,:) will contain the eigenvectors,
!Where Hdiag(:,1) is the first eigenvector, Hdiag(:,2) the second and so on
!and eigenvalues(1) will contain the eigenvalue corresponding to 
!eigenvector 1, and so on.

do i=1,nsize
write(*,*)'eigenvalue:',i,eigenvalues(i) !writing eigenvalues to screen
end do
end program diag !program is finished



subroutine diagonalize(ndiag) !Diagonalizes the matrix Hdiag
use shared
implicit none
real*8,  allocatable :: work(:)
integer, allocatable :: iwork(:)
character job, uplo
external dsyevd
integer nmax, lda, lwork, liwork, info,ndiag
nmax=ndiag
lda=nmax
lwork=4*nmax*nmax+100
liwork=10*nmax
allocate(work(lwork),iwork(liwork))
job='v'
uplo='l'
call dsyevd(job,uplo,ndiag,Hdiag,lda,eigenvalues,work,lwork,iwork,liwork,info)
if (info > 0) then
   write (*,*) 'failure to converge.'
   stop
endif
deallocate(work,iwork)
return
end
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 33 ·
2
Replies
33
Views
3K
Replies
3
Views
6K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 14 ·
Replies
14
Views
2K
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K