-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.f90
167 lines (118 loc) · 4.67 KB
/
utility.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
module utilities
implicit none
public :: utility_recip_lattice
public :: utility_cart_to_frac
public :: utility_frac_to_cart
public :: utility_diag
public :: heavyside
public :: fermi_dirac
public :: trace
public :: gauss
external :: cheev
contains
function heavyside(x) result (hside)
real*8, intent(in) :: x
real*8 :: hside
if (x < 0) then
hside = 0.0
else if (x >= 1) then
hside = 1.0
end if
end function heavyside
function fermi_dirac(x,temp) result (fd)
use constants, only : kboltz
real*8, intent(in) :: x, temp
real*8 :: fd
fd = 1.0/(exp(x/(temp*kboltz)) + 1)
end function fermi_dirac
function gauss(x,x0,sigma) result (gaussfunc)
use constants, only : twopi
real*8, intent(in) :: x, x0, sigma
real*8 :: gaussfunc
if ((x-x0) > -6*sigma .and. (x-x0) < 6*sigma) then
gaussfunc = exp(-((x-x0)**2)/(2*sigma**2))/sqrt(twopi*sigma**2)
else
gaussfunc = 0.0
end if
end function gauss
function trace(A,N) result (tr)
integer , intent(in) :: N
complex*16 , intent(in) :: A(N,N)
complex*16 :: tr
integer :: i
tr = 0.0
do i = 1, N
tr = tr + A(i,i)
end do
end function trace
subroutine utility_recip_lattice (real_lat,recip_lat,volume) !
!==================================================================!
! !
!! Calculates the reciprical lattice vectors and the cell volume
! !
!===================================================================
implicit none
real*8, intent(in) :: real_lat (3, 3)
real*8, intent(out) :: recip_lat (3, 3)
real*8, intent(out) :: volume
recip_lat(1,1)=real_lat(2,2)*real_lat(3,3)-real_lat(3,2)*real_lat(2,3)
recip_lat(2,1)=real_lat(3,2)*real_lat(1,3)-real_lat(3,3)*real_lat(1,2)
recip_lat(3,1)=real_lat(1,2)*real_lat(2,3)-real_lat(2,2)*real_lat(1,3)
recip_lat(1,2)=real_lat(2,3)*real_lat(3,1)-real_lat(3,3)*real_lat(2,1)
recip_lat(2,2)=real_lat(3,3)*real_lat(1,1)-real_lat(1,3)*real_lat(3,1)
recip_lat(3,2)=real_lat(2,1)*real_lat(1,3)-real_lat(2,3)*real_lat(1,1)
recip_lat(1,3)=real_lat(2,1)*real_lat(3,2)-real_lat(3,1)*real_lat(2,2)
recip_lat(2,3)=real_lat(3,1)*real_lat(1,2)-real_lat(1,1)*real_lat(3,2)
recip_lat(3,3)=real_lat(2,2)*real_lat(1,1)-real_lat(2,1)*real_lat(1,2)
volume=real_lat(1,1)*recip_lat(1,1) + &
real_lat(2,1)*recip_lat(2,1) + &
real_lat(3,1)*recip_lat(3,1)
recip_lat=2.*acos(-1.0)*recip_lat/volume
volume=abs(volume)
end subroutine utility_recip_lattice
subroutine utility_cart_to_frac(cart,frac,recip_lat)
!==================================================================!
! !
!! Convert from Cartesian to fractional coordinates
! !
!===================================================================
implicit none
real*8, intent(in) :: recip_lat(3,3)
real*8, intent(out) :: frac(3)
real*8, intent(in) :: cart(3)
integer :: i
do i=1,3
frac(i)=recip_lat(i,1)*cart(1) + recip_lat(i,2)*cart(2) + recip_lat(i,3)*cart(3)
end do
frac=frac/(2.0*acos(-1.0))
end subroutine utility_cart_to_frac
subroutine utility_frac_to_cart(frac,cart,real_lat)
!==================================================================!
! !
!! Convert from fractional to Cartesian coordinates
! !
!===================================================================
implicit none
real*8, intent(in) :: real_lat(3,3)
real*8, intent(in) :: frac(3)
real*8, intent(out) :: cart(3)
integer :: i
do i=1,3
cart(i)=real_lat(i,1)*frac(1) + real_lat(i,2)*frac(2) + real_lat(i,3)*frac(3)
end do
return
end subroutine utility_frac_to_cart
subroutine utility_diag(MAT,EIG,N)
implicit none
integer, intent(in) :: N
integer :: INF, LWORK
integer, parameter :: LWMAX = 1000
real*8, dimension(N), intent(out) :: EIG
complex*16, dimension(N,N), intent(inout) :: MAT
complex*16 :: W(LWMAX)
real*8, dimension(3*N-2) :: RW
call zheev('V','U',N,MAT,N,EIG,W,-1,RW,INF)
LWORK = min(LWMAX, int(W(1)))
call zheev('V','U',N,MAT,N,EIG,W,LWORK,RW,INF)
end subroutine utility_diag
end module utilities