-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheisen_chain.f90
177 lines (140 loc) · 3.3 KB
/
heisen_chain.f90
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
!-------------!
module system
!-------------!
integer :: nn
integer :: nst
real(8), allocatable :: mat(:,:)
real(8), allocatable :: vec(:,:)
real(8), allocatable :: enr(:)
real(8), allocatable :: spn(:)
real(8), allocatable :: mag(:)
end module system
!-----------------!
!================!
program hchain_0
!================!
use system; implicit none
open(10,file='read.in',status='old')
read(10,*)nn
close(10)
nst=2**nn
allocate(mat(0:nst-1,0:nst-1))
allocate(vec(0:nst-1,0:nst-1))
allocate(enr(0:nst-1))
allocate(spn(0:nst-1))
allocate(mag(0:nst-1))
call hamiltonian()
call diagonalize(nst,mat,vec,enr)
call spinsquared()
call transform(nst,mat,vec,spn)
spn(:)=0.5d0*abs(sqrt(1.d0+4.d0*spn(:))-1.d0)
call magnetization()
call writedata()
deallocate(mat)
deallocate(vec)
deallocate(enr)
deallocate(spn)
deallocate(mag)
end program hchain_0
!====================!
!----------------------!
subroutine writedata()
!----------------------!
use system; implicit none
integer :: i
open(10,file='eig.dat',status='unknown')
do i=0,nst-1
write(10,'(i5,3f18.10)')i,enr(i),spn(i),mag(i)
enddo
close(10)
end subroutine writedata
!------------------------!
!------------------------!
subroutine hamiltonian()
!------------------------!
use system; implicit none
integer :: i,j,a,b
mat(:,:)=0.d0
do a=0,nst-1
do i=0,nn-1
j=mod(i+1,nn)
if (btest(a,i).eqv.btest(a,j)) then
mat(a,a)=mat(a,a)+0.25d0
else
mat(a,a)=mat(a,a)-0.25d0
b=ieor(a,2**i+2**j)
mat(a,b)=mat(a,b)+0.5d0
endif
enddo
enddo
end subroutine hamiltonian
!--------------------------!
!------------------------!
subroutine spinsquared()
!------------------------!
use system; implicit none
integer :: i,j,a,b,m
mat(:,:)=0.d0
do a=0,nst-1
m=0
do i=0,nn-1
if (btest(a,i)) m=m+1
enddo
mat(a,a)=dfloat(m-nn/2)**2+0.5d0*dfloat(nn)
do i=0,nn-1
do j=i+1,nn-1
if (btest(a,i).neqv.btest(a,j)) then
b=ieor(a,2**i+2**j)
mat(a,b)=mat(a,b)+1.d0
endif
enddo
enddo
enddo
end subroutine spinsquared
!--------------------------!
!--------------------------!
subroutine magnetization()
!--------------------------!
use system; implicit none
integer :: i,j,a,b
integer, allocatable :: mz(:)
allocate(mz(0:nst-1))
do a=0,nst-1
mz(a)=0
do i=0,nn-1
if (btest(a,i)) mz(a)=mz(a)+1
enddo
enddo
do a=0,nst-1
mag(a)=0.d0
do b=0,nst-1
mag(a)=mag(a)+mz(b)*vec(b,a)**2
enddo
enddo
mag(:)=(mag(:)-nn/2)*0.5d0
deallocate(mz)
end subroutine magnetization
!----------------------------!
!-------------------------------------!
subroutine diagonalize(n,mat,vec,eig)
!-------------------------------------!
implicit none
integer :: n,info
real(8) :: mat(n,n),vec(n,n),eig(n),work(n*(3+n/2))
vec=mat
call dsyev('V','U',n,vec,n,eig,work,n*(3+n/2),info)
end subroutine diagonalize
!--------------------------!
!-----------------------------------!
subroutine transform(n,mat,vec,dia)
!-----------------------------------!
implicit none
integer :: i,n
real(8) :: mat(n,n),vec(n,n),dia(n)
mat=matmul(mat,vec)
mat=matmul(transpose(vec),mat)
do i=1,n
dia(i)=mat(i,i)
enddo
end subroutine transform
!------------------------!