-
Notifications
You must be signed in to change notification settings - Fork 12
/
create_hcp.f90
executable file
·124 lines (99 loc) · 3.96 KB
/
create_hcp.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
!begin rubric
!****************************************************************************** *
!* Original Author: Mark Gilbert *
!* copyright, 2015 (first version), 2018 (first git repository), UKAEA *
!******************************************************************************
!end rubric
SUBROUTINE create_hcp()
use configs
IMPLICIT NONE
integer :: islx
integer :: isly,islz
INTEGER, allocatable :: id(:)
integer :: ijk
REAL (KIND=DBL) :: ww(3),pi
pi=atan2(0._DBL,-1._DBL)
!assume same number of units in each direction
! i.e. not square in hcp case
islx=box_nunits
isly=islx
islz=islx
!WRITE(*,*) islx,latt,lx
lx(1)=REAL(islx,DBL)*latt
lx(2)=REAL(isly,DBL)*latt*cos(pi/6.0_DBL)
lx(3)=REAL(islz,DBL)*latt*sqrt(3.0_DBL)
natoms=2*islx*isly*islz
!WRITE(*,*) natoms
!WRITE(*,*) islx,latt,lx
allocate(id(natoms),x(natoms,3),xe(natoms,3))
ijk=0
do i=0,islx-1
do j=0,isly-1
do k=0,islz-1
ijk=ijk+1
id(ijk)=ijk
x(ijk,1)=latt*REAL(i,DBL)-latt*(REAL(j,DBL))*sin(pi/6._DBL)
x(ijk,2)=latt*REAL(j,DBL)*cos(pi/6._DBL)
x(ijk,3)=latt*sqrt(3.0_DBL)*REAL(k,DBL)
!3/1/2020 - in a hcpb lattice, the x coordinates with the
! above definition will be negative for large j (see bk 15)
! since this is a perfect box, we should shift as required
IF (x(ijk,1).LT.0._DBL) THEN
x(ijk,1)=x(ijk,1)+lx(1)
END IF
! tests
!CALL define_atom_position_hcp(ijk,ww)
!write(111,*) ijk,i,j,k,x(ijk,:)
! in a hcp lattice there is only one more atom in each unit cell:
! at (2/3,1/3,0.5)
ijk=ijk+1
id(ijk)=ijk
x(ijk,1)=latt*(REAL(i,DBL)+2._DBL/3._DBL)-&
latt*(REAL(j,DBL)+1._DBL/3._DBL)*sin(pi/6._DBL)
x(ijk,2)=latt*(REAL(j,DBL)+1._DBL/3._DBL)*cos(pi/6._DBL)
x(ijk,3)=latt*sqrt(3.0_DBL)*(REAL(k,DBL)+0.5_DBL)
IF (x(ijk,1).LT.0._DBL) THEN
x(ijk,1)=x(ijk,1)+lx(1)
END IF
end do
end do
end do
END SUBROUTINE create_hcp
SUBROUTINE define_atom_position_hcp(nn,xx)
use configs
IMPLICIT NONE
integer, INTENT(in) :: nn ! atom number
integer :: isly,islz,islx
REAL (KIND=DBL), intent(out) :: xx(3)
REAL (KIND=DBL) :: pi
integer :: ijk
pi=atan2(0._DBL,-1._DBL)
islx=box_nunits
isly=islx
islz=islx
IF (nn>natoms) THEN
PRINT *,'atom id outside of bounds, quiting',nn,natoms
STOP
END IF
!WRITE(*,*) natoms
!WRITE(*,*) islx,latt,lx
!natoms=2*islx*isly*islz
ijk=nn
IF(mod(nn,2)==0) ijk=nn-1
i=INT(REAL(ijk,DBL)/(2._DBL*REAL(isly,DBL)*REAL(islz,DBL)))
j=INT((REAL(ijk,DBL)-REAL(i,DBL)*2._DBL*REAL(isly,DBL)*REAL(islz,DBL))/ &
(2._DBL*REAL(islz,DBL)))
k=INT((REAL(ijk,DBL)-REAL(i,DBL)*2._DBL*REAL(isly,DBL)*REAL(islz,DBL)-&
REAL(j,DBL)*2._DBL*REAL(islz,DBL))/2._DBL)
xx(1)=latt*(REAL(i,DBL)+REAL(mod(nn-1,2),DBL)*2._DBL/3._DBL)-&
latt*(REAL(j,DBL)+REAL(mod(nn-1,2),DBL)*1_DBL/3._DBL)*sin(pi/6._DBL)
xx(2)=latt*(REAL(j,DBL)+REAL(mod(nn-1,2),DBL)*1._DBL/3._DBL)*cos(pi/6._DBL)
xx(3)=latt*sqrt(3.0_DBL)*(REAL(k,DBL)+REAL(mod(nn-1,2),DBL)*0.5_DBL)
!3/1/2020 - in a hcp lattice, the x coordinates with the
! above definition will be negative for large j (see bk 15)
! since this is a perfect box, we should shift as required
IF (xx(1).LT.0._DBL) THEN
xx(1)=xx(1)+lx(1)
END IF
END SUBROUTINE define_atom_position_hcp