1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
| module param implicit none integer, parameter :: dp = kind(1.0) integer num_wann,nrpts,hn parameter(hn = 4) real(dp) ones(hn,hn) real(dp),parameter::pi = 3.1415926535897 complex(dp),parameter::im = (0.,1.) real(dp) tsig,tpi,tsig2,tpi2,mu parameter(tsig = 2.0,tpi = tsig/1.56,tsig2 = tsig/7.0,tpi2 = tsig2/1.56) complex(dp),allocatable::HmnR(:,:,:) real(dp),allocatable::ndegen(:) real(dp),allocatable::irvec(:,:) integer,allocatable::BZklist(:,:) end module
program main use param implicit none complex(dp) Ham(hn,hn),temp1(hn,hn),temp2(hn),A1(4,4) real(dp) temp3(hn),A0(10,10) character(len = 20) char1,char2,char3 integer i1,i2
do i1 = 1,10 do i2 = 1,10 A0(i1,i2) = i1 + i2 end do end do char1 = "(" write(char2,"(I4)")10 char3 = "F8.4)" char2 = trim(char1)//trim(char2)//trim(char3) write(*,"(10F8.4)")A0 write(*,*)"--------------------------------------" write(*,char2)A0 call matset(0.3,0.2,Ham) write(*,*)Ham write(*,*)"-----------------------------------------" call diagonalize_complex_matrix(4,Ham,temp1,temp2) call diagonalize_Hermitian_matrix(4,Ham,temp1,temp3) write(*,*)temp2 write(*,*)temp3 call Matrix_Inv(4,Ham,temp1) write(*,*)matmul(Ham,temp1)
call diagonalize_real_matrix(4,A0,A1,temp2) write(*,*)temp2
stop end program main
subroutine matset(kx,ky,Ham) use param implicit none real(dp) kx,ky integer k0 complex(dp) Ham(hn,hn) complex(dp) h1(hn,hn),h2(hn,hn),h13,h14,h23,h24,hn11,hn22,hn12 h13 = 1.0/4*(tpi + 3.0 * tsig)*(exp(im*(ky/(2 * sqrt(3.0))- kx/2.0)) + exp(im*(ky/(2 * sqrt(3.0)) + kx/2.0)) ) + tpi*exp(-im * ky/sqrt(3.0)) h14 = -sqrt(3.0)/4 * (tpi - tsig) * (-1 + exp(im * kx)) * exp(-1.0/6.0 * im * (3.0 * kx - sqrt(3.0) * ky )) h23 = h14 h24 = 1.0/4 * (3.0 * tpi + tsig) * ( exp(im * (ky/(2 * sqrt(3.0)) - kx/2.0 ) ) + exp(im * (ky/(2 * sqrt(3.0)) + kx/2.0 ) )) + tsig * exp(-im * ky/sqrt(3.0)) hn11 = (3.0 * tpi2 + tsig2) * cos(kx/2.0) * cos(sqrt(3.0) * ky/2.0) + 2 * tsig2 * cos(kx) hn12 = sqrt(3.0) * (tpi2 - tsig2) * sin(kx/2.0) * sin(sqrt(3.0) * ky /2.0) hn22 = (tpi2 + 3.0 * tsig2) * cos(kx/2.0) * cos(sqrt(3.0) * ky / 2) + 2 * tpi2 * cos(kx)
do k0 = 1,hn ones(k0,k0) = 1 end do
H1(1,3) = h13 H1(3,1) = conjg( H1(1,3)) H1(1,4) = h14 H1(4,1) = conjg(H1(1,4)) H1(2,3) = h23 H1(3,2) = conjg(H1(2,3)) H1(2,4) = h24 H1(4,2) = conjg(H1(2,4)) H2(1,1) = hn11 H2(1,2) = hn12 H2(2,1) = conjg(H2(1,2)) H2(2,2) = hn22 H2(3,3) = hn11 H2(3,4) = hn12 H2(4,3) = conjg(H2(3,4)) H2(4,4) = hn22 Ham = 0.0 Ham = H1 + H2 - mu * ones return end subroutine
subroutine diagonalize_complex_matrix(matdim,matin,matout,mateigval) integer matdim,LDA,LDVL,LDVR,LWMAX,INFO,LWORK complex,intent(in)::matin(matdim,matdim) complex,intent(out)::matout(matdim,matdim) complex,intent(out)::mateigval(matdim) REAL,allocatable::RWORK(:) complex,allocatable::WORK(:) complex,allocatable::VL(:,:) complex,allocatable::VR(:,:) LDA = matdim LDVL = matdim LDVR = matdim LWMAX = 2 * matdim + matdim**2 allocate(RWORK(2 * matdim)) allocate(VL(LDVL,matdim)) allocate(VR(LDVR, matdim)) allocate(WORK(LWMAX)) matout = matin
LWORK = -1 call cgeev( 'V', 'N', matdim, matout, LDA, mateigval, VL, LDVL,VR, LDVR, WORK, LWORK, RWORK, INFO) LWORK = MIN( LWMAX, INT( WORK( 1 ) ) ) call cgeev( 'V', 'N', matdim, matout, LDA, mateigval, VL, LDVL,VR, LDVR, WORK, LWORK, RWORK, INFO ) IF( INFO.GT.0 ) THEN WRITE(*,*)'The algorithm failed to compute eigenvalues.' END IF matout = VL return end subroutine diagonalize_complex_matrix
subroutine Matrix_Inv(matdim,matin,matout) implicit none integer matdim,dp,info parameter(dp = kind(1.0)) complex(dp),intent(in) :: matin(matdim,matdim) complex(dp):: matout(size(matin,1),size(matin,2)) real(dp):: work2(size(matin,1)) integer::ipiv(size(matin,1)) matout = matin call CGETRF(matdim,matdim,matout,matdim,ipiv,info) if (info.ne.0) write(*,*)'Matrix is numerically singular!' call CGETRI(matdim,matout,matdim,ipiv,work2,matdim,info) if (info.ne.0) write(*,*)'Matrix inversion failed!' return end subroutine Matrix_Inv
subroutine diagonalize_Hermitian_matrix(matdim,matin,matout,mateigval) integer matdim integer lda0,lwmax0,lwork,lrwork,liwork,info complex matin(matdim,matdim),matout(matdim,matdim) real mateigval(matdim) complex,allocatable::work(:) real,allocatable::rwork(:) integer,allocatable::iwork(:) lda0 = matdim lwmax0 = 2 * matdim + matdim**2 allocate(work(lwmax0)) allocate(rwork(1 + 5 * matdim + 2 * matdim**2)) allocate(iwork(3 + 5 * matdim)) matout = matin lwork = -1 liwork = -1 lrwork = -1 call cheevd('V','U',matdim,matout,lda0,mateigval,work,lwork ,rwork,lrwork,iwork,liwork,info) lwork = min(2 * matdim + matdim**2, int( work( 1 ) ) ) lrwork = min(1 + 5 * matdim + 2 * matdim**2, int( rwork( 1 ) ) ) liwork = min(3 + 5 * matdim, iwork( 1 ) ) call cheevd('V','U',matdim,matout,lda0,mateigval,work,lwork,rwork,lrwork,iwork,liwork,info) if( info .GT. 0 ) then open(11,file = "mes.dat",status = "unknown") write(11,*)'The algorithm failed to compute eigenvalues.' close(11) end if return end subroutine diagonalize_Hermitian_matrix
subroutine diagonalize_real_matrix(matdim,matin,matout,mateigval) integer matdim,LDA,LDVL,LDVR,LWMAX,INFO,LWORK real,intent(in)::matin(matdim,matdim) real,intent(out)::matout(matdim,matdim) complex,intent(out)::mateigval(matdim) real valre(matdim),valim(matdim) real,allocatable::WORK(:) real,allocatable::VL(:,:) real,allocatable::VR(:,:) LDA = matdim LDVL = matdim LDVR = matdim LWMAX = 2 * matdim + matdim**2 allocate(VL(LDVL,matdim)) allocate(VR(LDVR, matdim)) allocate(WORK(LWMAX)) matout = matin
LWORK = -1 call sgeev( 'V', 'N', matdim, matout, LDA, valre,valim, VL, LDVL,VR, LDVR, WORK, LWORK, INFO) LWORK = MIN( LWMAX, INT( WORK( 1 ) ) ) call sgeev( 'V', 'N', matdim, matout, LDA, valre,valim, VL, LDVL,VR, LDVR, WORK, LWORK, INFO) IF( INFO.GT.0 ) THEN WRITE(*,*)'The algorithm failed to compute eigenvalues.' END IF do info = 1,matdim mateigval(info) = valre(info) + im * valim(info) end do end subroutine diagonalize_real_matrix
|