adding codes

This commit is contained in:
arjanberger10 2021-03-11 12:28:00 +01:00
parent 60551f3275
commit 6529dd050f
9 changed files with 937 additions and 0 deletions

47
1D_eta1_linear.f90 Normal file
View File

@ -0,0 +1,47 @@
program linear
implicit none
integer :: nelec
integer :: i,k
real*8 :: factor
real*8 :: zpe
real*8,allocatable :: cmat(:)
real*8,allocatable :: omega2(:)
write(6,*) "number of electrons"
read(5,*) nelec
allocate (cmat(nelec))
allocate (omega2(nelec))
factor=acos(-1d0)/nelec
cmat = 0d0
do i = 1, nelec
cmat(1) = cmat(1) + (1d0 + cos(factor*i))**2/sin(factor*i)**3
enddo
do i = 1, nelec-1
cmat(i+1) = -(1d0 + cos(factor*i))**2/sin(factor*i)**3
enddo
cmat = cmat*factor**3/8d0
factor = 2*acos(-1d0)/nelec
omega2 = 0d0
do k = 0, nelec-1
do i = 0, nelec-1
omega2(k+1) = omega2(k+1) + cmat(i+1)*cos(factor*k*i)
enddo
enddo
zpe=0d0
do k = 1, nelec
if (omega2(k)<0d0) cycle
zpe = zpe + sqrt(omega2(k))
enddo
zpe=zpe/nelec
print*,'zero-point energy (in Ry and Ha) =',zpe,zpe/2
deallocate(cmat,omega2)
end program linear

56
2D_eta0_square.f90 Normal file
View File

@ -0,0 +1,56 @@
program square
implicit none
integer :: nside,nsite,nelec
integer :: ix,iy,iz,i
real*16 :: factor,bbfac
real*16 :: uee,ubb,eta0,aux
real*16 :: start,finish
real*16,allocatable :: sin2(:)
open(unit=10,file='input')
read(10,*) nside
close(10)
call cpu_time(start)
nsite = nside
nelec = nside**2
bbfac = 1.139479116668307748953273191122493968q0
write(6,*) "total number of electrons",nelec
allocate(sin2(nsite))
factor=acos(-1q0)/nsite
do i = 0, nsite-1
sin2(i+1) = (sin(factor*i))**2
enddo
uee = 0q0
do ix = 0, nsite-1
do iy = 0, nsite-1
if (ix+iy==0) cycle
aux = sqrt(sin2(ix+1)+sin2(iy+1))
uee = uee + 1q0/aux
enddo
enddo
factor=sqrt(acos(-1q0))/(nsite*2q0)
uee=uee*factor
ubb = nelec*bbfac/nside
eta0 = uee - ubb
print*,'eta0 (in Ry and Ha) =', 2q0*eta0, eta0
print*, uee,ubb
deallocate(sin2)
call cpu_time(finish)
print '("Time = ",f12.3," seconds.")',finish-start
end program square

57
2D_eta0_triangle.f90 Normal file
View File

@ -0,0 +1,57 @@
program triangle
implicit none
integer :: nside,nsite,nelec
integer :: ix,iy,iz,i
real*16 :: factor,bbfac
real*16 :: uee,ubb,eta0,aux
real*16 :: start,finish
real*16,allocatable :: sin2(:)
open(unit=10,file='input')
read(10,*) nside
close(10)
call cpu_time(start)
nsite = 2*nside
nelec = nside**2*2
!bbfac = 0.7839363355057699q0
bbfac = 0.78393636789823211548q0
write(6,*) "total number of electrons",nelec
allocate(sin2(nsite))
factor=acos(-1q0)/nsite
do i = 0, nsite-1
sin2(i+1) = (sin(factor*i))**2
enddo
uee = 0q0
do ix = 0, nsite-1
do iy = 0, nsite-1
if (ix+iy==0) cycle
if (mod(ix+iy,2)==1) cycle
aux = sqrt(sin2(ix+1)+3q0*sin2(iy+1))
uee = uee + 1q0/aux
enddo
enddo
factor=sqrt(acos(-1q0)/2q0)*3q0**(0.25q0)/nsite
uee=uee*factor
ubb = nelec*bbfac/nside
eta0 = uee - ubb
print*,'eta0 (in Ry and Ha) =', 2q0*eta0, eta0
deallocate(sin2)
call cpu_time(finish)
print '("Time = ",f12.3," seconds.")',finish-start
end program triangle

188
2D_eta1_triangle.f90 Normal file
View File

@ -0,0 +1,188 @@
program triangle
implicit none
integer :: nside,nsite,nelec
integer :: ix,iy,kx,ky
integer :: i,k, ielec,kelec,info
real*8 :: start,finish
real*8 :: factor,height,factor2
real*8 :: zpe
real*8 :: denom1,denom2,numxy,fx,fy
real*8 :: work(8)
real*8,allocatable :: sin2(:),cos2(:)
real*8,allocatable :: cmat(:,:,:,:),cmatk(:,:,:,:)
real*8,allocatable :: caux1(:,:,:,:),caux2(:,:,:,:)
real*8,allocatable :: caux3(:,:,:,:),caux4(:,:,:,:)
real*8,allocatable :: omega2(:,:)
open(unit=10,file='input')
read(10,*) nside
close(10)
call cpu_time(start)
nsite = 2*nside
nelec = nside**2*2
write(6,*) "total number of electrons",nelec
allocate (cmat(2,2,nsite,nsite))
allocate (cmatk(2,2,nsite,nsite))
allocate (caux1(2,2,nsite,nsite))
allocate (caux2(2,2,nsite,nsite))
allocate (caux3(2,2,nsite,nsite))
allocate (caux4(2,2,nsite,nsite))
allocate (sin2(nsite))
allocate (cos2(nsite))
allocate (omega2(2,nelec))
factor=acos(-1d0)/nsite
height=2d0*sqrt(3d0)
do i = 0, nsite-1
sin2(i+1) = (sin(factor*i))**2
cos2(i+1) = (cos(factor*i))**2
enddo
!
! calculate C(0)
!
cmat = 0d0
do ix = 0, nsite-1
do iy = 0, nsite-1
if (ix+iy==0) cycle
if (mod(ix+iy,2)==1) cycle
denom1 = (sin2(ix+1)+0.25d0*height**2*sin2(iy+1))**1.5d0
denom2 = (sin2(ix+1)+0.25d0*height**2*sin2(iy+1))**2.5d0
numxy = 1.5d0*height*sin(factor*ix)*cos(factor*ix)*sin(factor*iy)*cos(factor*iy)
cmat(1,1,1,1) = cmat(1,1,1,1) + 3d0*sin2(ix+1)*cos2(ix+1)/denom2 + &
(sin2(ix+1) - cos2(ix+1))/denom1
cmat(2,2,1,1) = cmat(2,2,1,1) + 0.75d0*height**2*sin2(iy+1)*cos2(iy+1)/denom2 + &
(sin2(iy+1) - cos2(iy+1))/denom1
cmat(1,2,1,1) = cmat(1,2,1,1) + numxy/denom2
enddo
enddo
!
! calculate C(i) for i not equal to 0
!
do ix = 0, nsite-1
do iy = 0, nsite-1
if (ix+iy==0) cycle
if (mod(ix+iy,2)==1) cycle
denom1 = (sin2(ix+1)+0.25d0*height**2*sin2(iy+1))**1.5d0
denom2 = (sin2(ix+1)+0.25d0*height**2*sin2(iy+1))**2.5d0
numxy = -1.5d0*height*sin(factor*ix)*cos(factor*ix)*sin(factor*iy)*cos(factor*iy)
cmat(1,1,ix+1,iy+1) = -3d0*sin2(ix+1)*cos2(ix+1)/denom2 + &
(cos2(ix+1) - sin2(ix+1))/denom1
cmat(2,2,ix+1,iy+1) = -0.75d0*height**2*sin2(iy+1)*cos2(iy+1)/denom2 + &
(cos2(iy+1) - sin2(iy+1))/denom1
cmat(1,2,ix+1,iy+1) = numxy/denom2
enddo
enddo
cmat(2,1,:,:) = cmat(1,2,:,:)
cmat=cmat*(acos(-1d0)*height/nsite**2)**1.5d0
print*,'testje',cmat(1,1,1,1),cmat(2,2,1,1)
!
! calculate sum_{i} C_ab(i) cos(2pi k.i/2n) using index decoupling,
! i.e., cos (x + y) = cos(x)cos(y)-sin(x)sin(y)
!
factor = 2*acos(-1d0)/nsite
factor2 = 2*acos(-1d0)/(nside*sqrt(3d0))
caux1=0d0
caux2=0d0
do ix = 0, nsite-1
fx=factor*ix
do iy = 0, nsite-1
if (mod(ix+iy,2)==1) cycle
do kx = 0, nsite-1
caux1(:,:,kx+1,iy+1) = caux1(:,:,kx+1,iy+1) + cmat(:,:,ix+1,iy+1)*cos(kx*fx)
caux2(:,:,kx+1,iy+1) = caux2(:,:,kx+1,iy+1) + cmat(:,:,ix+1,iy+1)*sin(kx*fx)
enddo
enddo
enddo
caux3=0d0
caux4=0d0
do iy = 0, nsite-1
fy=factor*iy
do kx = 0, nsite-1
do ky = 0, nsite-1
if (mod(kx+ky,2)==1) cycle
caux3(:,:,kx+1,ky+1) = caux3(:,:,kx+1,ky+1) + caux1(:,:,kx+1,iy+1)*cos(ky*fy)
caux4(:,:,kx+1,ky+1) = caux4(:,:,kx+1,ky+1) + caux2(:,:,kx+1,iy+1)*sin(ky*fy)
enddo
enddo
enddo
cmatk = caux3-caux4
!!
!!debug : implementation without index decoupling
!!
!cmatk=0d0
!do ix = 0, nsite-1
! do iy = 0, nsite-1
! if (mod(ix+iy,2)==1) cycle
! do kx = 0, nsite-1
! do ky = 0, nsite-1
! if (mod(kx+ky,2)==1) cycle
!! print*,'testje2',kx,ky,cmat(1,1,ix+1,iy+1),cos(factor*(ix*kx+iy*ky))
! cmatk(:,:,kx+1,ky+1) = cmatk(:,:,kx+1,ky+1) + cmat(:,:,ix+1,iy+1)*cos(factor*(ix*kx+iy*ky))
!! cmatk(:,:,kx+1,ky+1) = cmatk(:,:,kx+1,ky+1) + cmat(:,:,ix+1,iy+1)*cos(factor*ix*kx+factor2*iy*(ky-kx))
!! cmatk(1,1,kx+1,ky+1) = cmatk(1,1,kx+1,ky+1) + cmat(1,1,ix+1,iy+1)*cos(factor*(ix*kx+iy*ky))
!! print*,'testje3',kx,ky,cmatk(1,1,kx+1,ky+1)
! enddo
! enddo
! enddo
!enddo
!do kx = 0, nsite-1
! do ky = 0, nsite-1
! if (mod(kx+ky,2)==1) cycle
! print*,'testje',kx,ky,cmatk(1,1,kx+1,ky+1),cmatk(2,2,kx+1,ky+1),cmatk(1,2,kx+1,ky+1),cmatk(2,1,kx+1,ky+1)
! enddo
!enddo
!
! diagonalize 2x2 matrices
!
omega2 = 0d0
kelec=1
do kx = 0, nsite-1
do ky = 0, nsite-1
if (mod(kx+ky,2)==1) cycle
call dsyev ("v","u", 2, cmatk(:,:,kx+1,ky+1), 2, omega2(:,kelec), work, 8, info)
kelec = kelec + 1
enddo
enddo
zpe=0d0
do kelec = 1, nelec
do i = 1, 2
! if (omega2(i,kelec)<0d0) print*,'warning',kelec,i,omega2(i,kelec)
! print*,omega2(i,kelec)
if (omega2(i,kelec)<0d0) cycle
zpe = zpe + sqrt(omega2(i,kelec))
enddo
enddo
zpe=zpe/nelec
print*,'zero-point energy (in Ry and Ha) =',zpe,zpe/2
deallocate(sin2,cos2,cmat,cmatk,omega2)
deallocate(caux1,caux2,caux3,caux4)
call cpu_time(finish)
print '("Time = ",f6.3," seconds.")',finish-start
end program triangle

60
3D_eta0_bcc.f90 Normal file
View File

@ -0,0 +1,60 @@
program bcc
implicit none
integer(kind=8) :: nside,nsite,nelec
integer(kind=8) :: ix,iy,iz,i
real*16 :: factor,bbfac
real*16 :: uee,ubb,eta0,aux
real*16 :: start,finish
real*16,allocatable :: sin2(:)
open(unit=10,file='input')
read(10,*) nside
close(10)
call cpu_time(start)
nsite = 2*nside
nelec = nside**3*2
bbfac = 1.4305055275019529822q0
write(6,*) "total number of electrons",nelec
allocate(sin2(nsite))
factor=acos(-1q0)/nsite
do i = 0, nsite-1
sin2(i+1) = (sin(factor*i))**2
enddo
uee = 0q0
do ix = 0, nsite-1
do iy = 0, nsite-1
do iz = 0, nsite-1
if (ix+iy+iz==0) cycle
if (mod(ix+iy,2)==1.or.mod(ix+iz,2)==1.or.mod(iy+iz,2)==1) cycle
aux = sqrt(sin2(ix+1)+sin2(iy+1)+sin2(iz+1))
uee = uee + 1q0/aux
enddo
enddo
enddo
uee=uee*acos(-1q0)/(2q0*nsite)
ubb = nelec*bbfac/nsite
eta0 = uee - ubb
factor=(acos(-1q0)/3q0)**(1q0/3q0)
eta0=eta0/factor
print*,'eta0 (in Ry and Ha) =', 2q0*eta0, eta0
deallocate(sin2)
call cpu_time(finish)
print '("Time = ",f12.3," seconds.")',finish-start
end program bcc

60
3D_eta0_fcc.f90 Normal file
View File

@ -0,0 +1,60 @@
program bcc
implicit none
integer(kind=8) :: nside,nsite,nelec
integer(kind=8) :: ix,iy,iz,i
real*16 :: factor,bbfac
real*16 :: uee,ubb,eta0,aux
real*16 :: start,finish
real*16,allocatable :: sin2(:)
open(unit=10,file='input')
read(10,*) nside
close(10)
call cpu_time(start)
nsite = 2*nside
nelec = nside**3*4
bbfac = 1.4305055275019529822q0
write(6,*) "total number of electrons",nelec
allocate(sin2(nsite))
factor=acos(-1q0)/nsite
do i = 0, nsite-1
sin2(i+1) = (sin(factor*i))**2
enddo
uee = 0q0
do ix = 0, nsite-1
do iy = 0, nsite-1
do iz = 0, nsite-1
if (ix+iy+iz==0) cycle
if (mod(ix+iy+iz,2)==1) cycle
aux = sqrt(sin2(ix+1)+sin2(iy+1)+sin2(iz+1))
uee = uee + 1q0/aux
enddo
enddo
enddo
uee=uee*acos(-1q0)/(2q0*nsite)
ubb = nelec*bbfac/nsite
eta0 = uee - ubb
factor=(acos(-1q0)/1.5q0)**(1q0/3q0)
eta0=eta0/factor
print*,'eta0 (in Ry and Ha) =', 2q0*eta0, eta0
deallocate(sin2)
call cpu_time(finish)
print '("Time = ",f12.3," seconds.")',finish-start
end program bcc

79
3D_eta0_hcp.f90 Normal file
View File

@ -0,0 +1,79 @@
program hcp
implicit none
integer(kind=8) :: nside,nsitexz,nsitey,nelec
integer(kind=8) :: ix,iy,iz,i
real*16 :: factorxz,factory,factor,bbfac,pi
real*16 :: uee,ubb,eta0,aux
real*16 :: start,finish
real*16,allocatable :: sin2xz(:),sin2y(:)
open(unit=10,file='input')
read(10,*) nside
close(10)
call cpu_time(start)
nsitexz = 2*nside
nsitey = 6*nside
nelec = nside**3*4
bbfac = 0.54063377545280790285q0
pi = acos(-1q0)
write(6,*) "total number of electrons",nelec
allocate(sin2xz(nsitexz))
allocate(sin2y(nsitey))
factorxz=acos(-1q0)/nsitexz
factory=acos(-1q0)/nsitey
do i = 0, nsitexz-1
sin2xz(i+1) = (sin(factorxz*i))**2
enddo
do i = 0, nsitey-1
sin2y(i+1) = (sin(factory*i))**2
enddo
uee = 0q0
do ix = 0, nsitexz-1
do iy = 0, nsitey-1
do iz = 0, nsitexz-1
if (ix+iy+iz==0) cycle
aux = sqrt(sin2xz(ix+1)+3q0*sin2y(iy+1)+8q0/3q0*sin2xz(iz+1))
if (mod(ix,2)==0.and.mod(iz,2)==0.and.mod(iy,6)==0) then
uee = uee + 1q0/aux
! print*,'testje1',ix,iy,iz,aux
endif
if (mod(ix,2)==1.and.mod(iz,2)==0.and.mod(iy+3,6)==0) then
uee = uee + 1q0/aux
! print*,'testje2',ix,iy,iz,aux
endif
if (mod(ix,2)==0.and.mod(iz,2)==1.and.mod(iy+4,6)==0) then
uee = uee + 1q0/aux
! print*,'testje3',ix,iy,iz,aux
endif
if (mod(ix,2)==1.and.mod(iz,2)==1.and.mod(iy+1,6)==0) then
uee = uee + 1q0/aux
! print*,'testje4',ix,iy,iz,aux
endif
enddo
enddo
enddo
factor=(3q0*pi**(2q0)*sqrt(2q0))**(1q0/3q0)/(2q0*nsitexz)
uee=uee*factor
ubb = nelec*bbfac/nside
eta0 = uee - ubb
print*,'eta0 (in Ry and Ha) =', 2q0*eta0, eta0
deallocate(sin2xz,sin2y)
call cpu_time(finish)
print '("Time = ",f12.3," seconds.")',finish-start
end program hcp

59
3D_eta0_sc.f90 Normal file
View File

@ -0,0 +1,59 @@
program sc
implicit none
integer(kind=8) :: nside,nsite,nelec
integer(kind=8) :: ix,iy,iz,i
real*16 :: factor,bbfac
real*16 :: uee,ubb,eta0,aux
real*16 :: start,finish
real*16,allocatable :: sin2(:)
open(unit=10,file='input')
read(10,*) nside
close(10)
call cpu_time(start)
nsite = nside
nelec = nside**3
bbfac = 1.4305055275019529822q0
write(6,*) "total number of electrons",nelec
allocate(sin2(nsite))
factor=acos(-1q0)/nsite
do i = 0, nsite-1
sin2(i+1) = (sin(factor*i))**2
enddo
uee = 0q0
do ix = 0, nsite-1
do iy = 0, nsite-1
do iz = 0, nsite-1
if (ix+iy+iz==0) cycle
aux = sqrt(sin2(ix+1)+sin2(iy+1)+sin2(iz+1))
uee = uee + 1q0/aux
enddo
enddo
enddo
uee=uee*acos(-1q0)/(2q0*nsite)
ubb = nelec*bbfac/nsite
eta0 = uee - ubb
factor=(4q0*acos(-1q0)/3q0)**(1q0/3q0)
eta0=eta0/factor
print*,'eta0 (in Ry and Ha) =', 2q0*eta0, eta0
deallocate(sin2)
call cpu_time(finish)
print '("Time = ",f12.3," seconds.")',finish-start
end program sc

331
3D_eta1_bcc.f90 Normal file
View File

@ -0,0 +1,331 @@
program bcc
implicit none
integer :: nside,nsite,nelec
integer :: ix,iy,iz,kx,ky,kz
integer :: i,k, ielec,kelec,info
real*8 :: start,finish
real*8 :: factor
real*8 :: zpe
real*8 :: denom1,denom2,numxy,numxz,numyz,fx,fy,fz
real*8 :: work(8)
real*8,allocatable :: sin2(:),cos2(:)
real*8,allocatable :: cmat(:,:,:,:,:)
real*8,allocatable :: caux(:,:,:,:,:)
real*8,allocatable :: cmatk(:,:,:,:,:)
real*8,allocatable :: omega2(:,:)
open(unit=10,file='input')
read(10,*) nside
close(10)
call cpu_time(start)
nsite = 2*nside
nelec = nside**3*2
write(6,*) "total number of electrons",nelec
allocate (cmat(3,3,nsite,nsite,nsite))
allocate (caux(3,3,nsite,nsite,nsite))
allocate (cmatk(3,3,nsite,nsite,nsite))
allocate (sin2(nsite))
allocate (cos2(nsite))
allocate (omega2(3,nelec))
factor=acos(-1d0)/nsite
do i = 0, nsite-1
sin2(i+1) = (sin(factor*i))**2
cos2(i+1) = (cos(factor*i))**2
enddo
!
! calculate C(0)
!
cmat = 0d0
do ix = 0, nsite-1
do iy = 0, nsite-1
do iz = 0, nsite-1
if (ix+iy+iz==0) cycle
if (mod(ix+iy,2)==1.or.mod(ix+iz,2)==1.or.mod(iy+iz,2)==1) cycle
denom1 = (sin2(ix+1)+sin2(iy+1)+sin2(iz+1))**(1.5d0)
denom2 = (sin2(ix+1)+sin2(iy+1)+sin2(iz+1))**(2.5d0)
cmat(1,1,1,1,1) = cmat(1,1,1,1,1) + 3d0*sin2(ix+1)*cos2(ix+1)/denom2 + (sin2(ix+1) - cos2(ix+1))/denom1
cmat(2,2,1,1,1) = cmat(2,2,1,1,1) + 3d0*sin2(iy+1)*cos2(iy+1)/denom2 + (sin2(iy+1) - cos2(iy+1))/denom1
cmat(3,3,1,1,1) = cmat(3,3,1,1,1) + 3d0*sin2(iz+1)*cos2(iz+1)/denom2 + (sin2(iz+1) - cos2(iz+1))/denom1
enddo
enddo
enddo
!
! calculate C(i) for i not equal to 0
!
do ix = 0, nsite-1
do iy = 0, nsite-1
do iz = 0, nsite-1
if (ix+iy+iz==0) cycle
if (mod(ix+iy,2)==1.or.mod(ix+iz,2)==1.or.mod(iy+iz,2)==1) cycle
denom1 = (sin2(ix+1)+sin2(iy+1)+sin2(iz+1))**1.5d0
denom2 = (sin2(ix+1)+sin2(iy+1)+sin2(iz+1))**2.5d0
numxy = -3d0*sin(factor*ix)*cos(factor*ix)*sin(factor*iy)*cos(factor*iy)
numxz = -3d0*sin(factor*ix)*cos(factor*ix)*sin(factor*iz)*cos(factor*iz)
numyz = -3d0*sin(factor*iy)*cos(factor*iy)*sin(factor*iz)*cos(factor*iz)
cmat(1,1,ix+1,iy+1,iz+1) = -3d0*sin2(ix+1)*cos2(ix+1)/denom2 + (cos2(ix+1) - sin2(ix+1))/denom1
cmat(2,2,ix+1,iy+1,iz+1) = -3d0*sin2(iy+1)*cos2(iy+1)/denom2 + (cos2(iy+1) - sin2(iy+1))/denom1
cmat(3,3,ix+1,iy+1,iz+1) = -3d0*sin2(iz+1)*cos2(iz+1)/denom2 + (cos2(iz+1) - sin2(iz+1))/denom1
cmat(1,2,ix+1,iy+1,iz+1) = numxy/denom2
cmat(1,3,ix+1,iy+1,iz+1) = numxz/denom2
cmat(2,3,ix+1,iy+1,iz+1) = numyz/denom2
enddo
enddo
enddo
cmat(2,1,:,:,:) = cmat(1,2,:,:,:)
cmat(3,1,:,:,:) = cmat(1,3,:,:,:)
cmat(3,2,:,:,:) = cmat(2,3,:,:,:)
factor = 3d0*(acos(-1d0))**2/nsite**3
do ix = 0, nsite-1
do iy = 0, nsite-1
do iz = 0, nsite-1
if (mod(ix+iy,2)==1.or.mod(ix+iz,2)==1.or.mod(iy+iz,2)==1) cycle
cmat(:,:,ix+1,iy+1,iz+1) = cmat(:,:,ix+1,iy+1,iz+1)*factor
enddo
enddo
enddo
!
! calculate sum_{i} C_ab(i) cos(2pi k.i/2n) using index decoupling,
! i.e., cos (x + y) = cos(x)cos(y)-sin(x)sin(y)
!
factor = 2*acos(-1d0)/nsite
caux=0d0
do ix = 0, nsite-1
fx=factor*ix
do iy = 0, nsite-1
do iz = 0, nsite-1
if (mod(ix+iy,2)==1.or.mod(ix+iz,2)==1.or.mod(iy+iz,2)==1) cycle
do kx = 0, nsite-1
caux(:,:,kx+1,iy+1,iz+1) = caux(:,:,kx+1,iy+1,iz+1) + cmat(:,:,ix+1,iy+1,iz+1)*cos(kx*fx)
enddo
enddo
enddo
enddo
cmat=0d0
do iy = 0, nsite-1
fy=factor*iy
do iz = 0, nsite-1
do kx = 0, nsite-1
do ky = 0, nsite-1
if (mod(iy+iz,2)==1.or.mod(kx+ky,2)==1) cycle
cmat(:,:,kx+1,ky+1,iz+1) = cmat(:,:,kx+1,ky+1,iz+1) + caux(:,:,kx+1,iy+1,iz+1)*cos(ky*fy)
enddo
enddo
enddo
enddo
cmatk=0d0
do iz = 0, nsite-1
fz=factor*iz
do kx = 0, nsite-1
do ky = 0, nsite-1
do kz = 0, nsite-1
if (mod(kx+ky,2)==1.or.mod(kx+kz,2)==1.or.mod(ky+kz,2)==1) cycle
cmatk(:,:,kx+1,ky+1,kz+1) = cmatk(:,:,kx+1,ky+1,kz+1) + cmat(:,:,kx+1,ky+1,iz+1)*cos(kz*fz)
enddo
enddo
enddo
enddo
cmat=0d0
do iy = 0, nsite-1
fy=factor*iy
do iz = 0, nsite-1
do kx = 0, nsite-1
do ky = 0, nsite-1
if (mod(iy+iz,2)==1.or.mod(kx+ky,2)==1) cycle
cmat(:,:,kx+1,ky+1,iz+1) = cmat(:,:,kx+1,ky+1,iz+1) + caux(:,:,kx+1,iy+1,iz+1)*sin(ky*fy)
enddo
enddo
enddo
enddo
do iz = 0, nsite-1
fz=factor*iz
do kx = 0, nsite-1
do ky = 0, nsite-1
do kz = 0, nsite-1
if (mod(kx+ky,2)==1.or.mod(kx+kz,2)==1.or.mod(ky+kz,2)==1) cycle
cmatk(:,:,kx+1,ky+1,kz+1) = cmatk(:,:,kx+1,ky+1,kz+1) - cmat(:,:,kx+1,ky+1,iz+1)*sin(kz*fz)
enddo
enddo
enddo
enddo
factor=acos(-1d0)/nsite
do i = 0, nsite-1
sin2(i+1) = (sin(factor*i))**2
cos2(i+1) = (cos(factor*i))**2
enddo
!
! calculate C(0)
!
cmat = 0d0
do ix = 0, nsite-1
do iy = 0, nsite-1
do iz = 0, nsite-1
if (ix+iy+iz==0) cycle
if (mod(ix+iy,2)==1.or.mod(ix+iz,2)==1.or.mod(iy+iz,2)==1) cycle
denom1 = (sin2(ix+1)+sin2(iy+1)+sin2(iz+1))**(1.5d0)
denom2 = (sin2(ix+1)+sin2(iy+1)+sin2(iz+1))**(2.5d0)
cmat(1,1,1,1,1) = cmat(1,1,1,1,1) + 3d0*sin2(ix+1)*cos2(ix+1)/denom2 + (sin2(ix+1) - cos2(ix+1))/denom1
cmat(2,2,1,1,1) = cmat(2,2,1,1,1) + 3d0*sin2(iy+1)*cos2(iy+1)/denom2 + (sin2(iy+1) - cos2(iy+1))/denom1
cmat(3,3,1,1,1) = cmat(3,3,1,1,1) + 3d0*sin2(iz+1)*cos2(iz+1)/denom2 + (sin2(iz+1) - cos2(iz+1))/denom1
enddo
enddo
enddo
!
! calculate C(i) for i not equal to 0
!
do ix = 0, nsite-1
do iy = 0, nsite-1
do iz = 0, nsite-1
if (ix+iy+iz==0) cycle
if (mod(ix+iy,2)==1.or.mod(ix+iz,2)==1.or.mod(iy+iz,2)==1) cycle
denom1 = (sin2(ix+1)+sin2(iy+1)+sin2(iz+1))**1.5d0
denom2 = (sin2(ix+1)+sin2(iy+1)+sin2(iz+1))**2.5d0
numxy = -3d0*sin(factor*ix)*cos(factor*ix)*sin(factor*iy)*cos(factor*iy)
numxz = -3d0*sin(factor*ix)*cos(factor*ix)*sin(factor*iz)*cos(factor*iz)
numyz = -3d0*sin(factor*iy)*cos(factor*iy)*sin(factor*iz)*cos(factor*iz)
cmat(1,1,ix+1,iy+1,iz+1) = -3d0*sin2(ix+1)*cos2(ix+1)/denom2 + (cos2(ix+1) - sin2(ix+1))/denom1
cmat(2,2,ix+1,iy+1,iz+1) = -3d0*sin2(iy+1)*cos2(iy+1)/denom2 + (cos2(iy+1) - sin2(iy+1))/denom1
cmat(3,3,ix+1,iy+1,iz+1) = -3d0*sin2(iz+1)*cos2(iz+1)/denom2 + (cos2(iz+1) - sin2(iz+1))/denom1
cmat(1,2,ix+1,iy+1,iz+1) = numxy/denom2
cmat(1,3,ix+1,iy+1,iz+1) = numxz/denom2
cmat(2,3,ix+1,iy+1,iz+1) = numyz/denom2
enddo
enddo
enddo
cmat(2,1,:,:,:) = cmat(1,2,:,:,:)
cmat(3,1,:,:,:) = cmat(1,3,:,:,:)
cmat(3,2,:,:,:) = cmat(2,3,:,:,:)
factor = 3d0*(acos(-1d0))**2/nsite**3
do ix = 0, nsite-1
do iy = 0, nsite-1
do iz = 0, nsite-1
if (mod(ix+iy,2)==1.or.mod(ix+iz,2)==1.or.mod(iy+iz,2)==1) cycle
cmat(:,:,ix+1,iy+1,iz+1) = cmat(:,:,ix+1,iy+1,iz+1)*factor
enddo
enddo
enddo
factor = 2*acos(-1d0)/nsite
caux=0d0
do ix = 0, nsite-1
fx=factor*ix
do iy = 0, nsite-1
do iz = 0, nsite-1
if (mod(ix+iy,2)==1.or.mod(ix+iz,2)==1.or.mod(iy+iz,2)==1) cycle
do kx = 0, nsite-1
caux(:,:,kx+1,iy+1,iz+1) = caux(:,:,kx+1,iy+1,iz+1) + cmat(:,:,ix+1,iy+1,iz+1)*sin(kx*fx)
enddo
enddo
enddo
enddo
cmat=0d0
do iy = 0, nsite-1
fy=factor*iy
do iz = 0, nsite-1
do kx = 0, nsite-1
do ky = 0, nsite-1
if (mod(iy+iz,2)==1.or.mod(kx+ky,2)==1) cycle
cmat(:,:,kx+1,ky+1,iz+1) = cmat(:,:,kx+1,ky+1,iz+1) + caux(:,:,kx+1,iy+1,iz+1)*sin(ky*fy)
enddo
enddo
enddo
enddo
do iz = 0, nsite-1
fz=factor*iz
do kx = 0, nsite-1
do ky = 0, nsite-1
do kz = 0, nsite-1
if (mod(kx+ky,2)==1.or.mod(kx+kz,2)==1.or.mod(ky+kz,2)==1) cycle
cmatk(:,:,kx+1,ky+1,kz+1) = cmatk(:,:,kx+1,ky+1,kz+1) - cmat(:,:,kx+1,ky+1,iz+1)*cos(kz*fz)
enddo
enddo
enddo
enddo
cmat=0d0
do iy = 0, nsite-1
fy=factor*iy
do iz = 0, nsite-1
do kx = 0, nsite-1
do ky = 0, nsite-1
if (mod(iy+iz,2)==1.or.mod(kx+ky,2)==1) cycle
cmat(:,:,kx+1,ky+1,iz+1) = cmat(:,:,kx+1,ky+1,iz+1) + caux(:,:,kx+1,iy+1,iz+1)*cos(ky*fy)
enddo
enddo
enddo
enddo
do iz = 0, nsite-1
fz=factor*iz
do kx = 0, nsite-1
do ky = 0, nsite-1
do kz = 0, nsite-1
if (mod(kx+ky,2)==1.or.mod(kx+kz,2)==1.or.mod(ky+kz,2)==1) cycle
cmatk(:,:,kx+1,ky+1,kz+1) = cmatk(:,:,kx+1,ky+1,kz+1) - cmat(:,:,kx+1,ky+1,iz+1)*sin(kz*fz)
enddo
enddo
enddo
enddo
!
! diagonalize 3x3 matrices
!
omega2 = 0d0
kelec=1
do kx = 0, nsite-1
do ky = 0, nsite-1
do kz = 0, nsite-1
if (mod(kx+ky,2)==1.or.mod(kx+kz,2)==1.or.mod(ky+kz,2)==1) cycle
call dsyev ("v","u", 3, cmatk(:,:,kx+1,ky+1,kz+1), 3, omega2(:,kelec), work, 8, info)
kelec = kelec + 1
enddo
enddo
enddo
zpe=0d0
do kelec = 1, nelec
do i = 1, 3
! if (omega2(i,kelec)<0d0) print*,'warning',kelec,i,omega2(i,kelec)
! print*,omega2(i,kelec)
if (omega2(i,kelec)<0d0) cycle
zpe = zpe + sqrt(omega2(i,kelec))
enddo
enddo
zpe=zpe/nelec
print*,'zero-point energy (in Ry and Ha) =',zpe,zpe/2
deallocate(sin2,cos2,omega2)
deallocate(cmat,caux,cmatk)
call cpu_time(finish)
print '("Time = ",f6.3," seconds.")',finish-start
end program bcc