The Elk Code
genhvec.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2010 Alexey I. Baranov.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 subroutine genhvec
7 use modmain
8 use modpw
9 implicit none
10 ! local variables
11 logical lsym(48)
12 integer ih,jh,kh,lh,k
13 integer i1,i2,i3,iv(3)
14 integer nsym,isym,sym(3,3,48)
15 real(8) v1(3),v2(3),v3(3)
16 ! allocatable arrays
17 integer, allocatable :: idx(:),ivh_(:,:)
18 real(8), allocatable :: vhc_(:,:),hc_(:)
19 ! find the H-vector grid sizes
21 ! allocate global H-vector arrays
22 if (allocated(ivh)) deallocate(ivh)
23 allocate(ivh(3,nhtot))
24 if (allocated(mulh)) deallocate(mulh)
25 allocate(mulh(nhtot))
26 if (allocated(vhc)) deallocate(vhc)
27 allocate(vhc(3,nhtot))
28 if (allocated(hc)) deallocate(hc)
29 allocate(hc(nhtot))
30 ! allocate local arrays
31 allocate(idx(nhtot),ivh_(3,nhtot))
32 allocate(vhc_(3,nhtot),hc_(nhtot))
33 ih=0
34 do i1=inthv(1,1),inthv(2,1)
35  v1(1:3)=dble(i1)*bvec(1:3,1)
36  do i2=inthv(1,2),inthv(2,2)
37  v2(1:3)=v1(1:3)+dble(i2)*bvec(1:3,2)
38  do i3=inthv(1,3),inthv(2,3)
39  v3(1:3)=v2(1:3)+dble(i3)*bvec(1:3,3)
40  ih=ih+1
41 ! map from H-vector to (i1,i2,i3) index
42  ivh_(1,ih)=i1; ivh_(2,ih)=i2; ivh_(3,ih)=i3
43 ! H-vector in Cartesian coordinates
44  vhc_(1:3,ih)=v3(1:3)
45 ! length of each H-vector
46  hc_(ih)=sqrt(v3(1)**2+v3(2)**2+v3(3)**2)
47  end do
48  end do
49 end do
50 ! sort by vector length
51 call sortidx(nhtot,hc_,idx)
52 ! reorder arrays
53 ivh(1:3,1:nhtot)=ivh_(1:3,idx(1:nhtot))
54 hc(1:nhtot)=hc_(idx(1:nhtot))
55 vhc(1:3,1:nhtot)=vhc_(1:3,idx(1:nhtot))
56 ! find the number of vectors with H < hmaxvr
57 nhvec=1
58 do ih=2,nhtot
59  if (hc(ih) > hmaxvr) then
60  nhvec=ih-1
61  exit
62  end if
63 end do
64 ! find the subgroup of symmorphic, non-magnetic symmetries
65 lsym(:)=.false.
66 do isym=1,nsymcrys
67  if (tv0symc(isym).and.(lspnsymc(isym) == 1)) lsym(lsplsymc(isym))=.true.
68 end do
69 nsym=0
70 do isym=1,nsymlat
71  if (lsym(isym)) then
72  nsym=nsym+1
73  sym(:,:,nsym)=symlat(:,:,isym)
74  end if
75 end do
76 if (reduceh) then
77 ! find the subgroup of symmorphic, non-magnetic symmetries
78  lsym(:)=.false.
79  do isym=1,nsymcrys
80  if (tv0symc(isym).and.(lspnsymc(isym) == 1)) lsym(lsplsymc(isym))=.true.
81  end do
82  nsym=0
83  do isym=1,nsymlat
84  if (lsym(isym)) then
85  nsym=nsym+1
86  sym(:,:,nsym)=symlat(:,:,isym)
87  end if
88  end do
89 else
90 ! use only the identity element if no reduction is required
91  nsym=1
92 end if
93 ! reduce the H-vector set with the symmetries if required
94 if (nsym > 1) then
95  ivh_(1:3,1:nhvec)=ivh(1:3,1:nhvec)
96  hc_(1:nhvec)=hc(1:nhvec)
97  vhc_(1:3,1:nhvec)=vhc(1:3,1:nhvec)
98  kh=0
99  lh=nhvec
100  do ih=1,nhvec
101  do isym=1,nsym
102  call i3mtv(sym(:,:,isym),ivh_(:,ih),iv(:))
103  do jh=1,kh
104  k=abs(ivh(1,jh)-iv(1))+abs(ivh(2,jh)-iv(2))+abs(ivh(3,jh)-iv(3))
105  if (k == 0) then
106  ivh(1:3,lh)=ivh_(1:3,ih)
107  hc(lh)=hc_(ih)
108  vhc(1:3,lh)=vhc_(1:3,ih)
109  lh=lh-1
110  mulh(jh)=mulh(jh)+1
111  goto 10
112  end if
113  end do
114  end do
115  kh=kh+1
116  ivh(1:3,kh)=ivh_(1:3,ih)
117  hc(kh)=hc_(ih)
118  vhc(1:3,kh)=vhc_(1:3,ih)
119  mulh(kh)=1
120 10 continue
121  end do
122  nhvec=kh
123 else
124  mulh(:)=1
125 end if
126 deallocate(idx,ivh_,vhc_,hc_)
127 end subroutine
128 
integer, dimension(maxsymcrys) lspnsymc
Definition: modmain.f90:366
integer npfftg
Definition: modmain.f90:404
subroutine genhvec
Definition: genhvec.f90:7
integer nsymcrys
Definition: modmain.f90:358
integer, dimension(3, 3, 48) symlat
Definition: modmain.f90:344
pure subroutine i3mtv(a, x, y)
Definition: i3mtv.f90:10
logical, dimension(maxsymcrys) tv0symc
Definition: modmain.f90:362
real(8) hmaxvr
Definition: modpw.f90:14
subroutine gridsize(avec, gmaxvr, npfft, ngridg, ngtot, intgv)
Definition: gridsize.f90:10
real(8), dimension(:,:), allocatable vhc
Definition: modpw.f90:28
integer, dimension(maxsymcrys) lsplsymc
Definition: modmain.f90:364
integer nsymlat
Definition: modmain.f90:342
logical reduceh
Definition: modpw.f90:12
real(8), dimension(3, 3) avec
Definition: modmain.f90:12
integer nhtot
Definition: modpw.f90:18
pure subroutine sortidx(n, x, idx)
Definition: sortidx.f90:10
integer, dimension(:), allocatable mulh
Definition: modpw.f90:26
real(8), dimension(3, 3) bvec
Definition: modmain.f90:16
integer, dimension(2, 3) inthv
Definition: modpw.f90:20
real(8), dimension(:), allocatable hc
Definition: modpw.f90:30
Definition: modpw.f90:6
integer, dimension(:,:), allocatable ivh
Definition: modpw.f90:24
integer, dimension(3) ngridh
Definition: modpw.f90:16
integer nhvec
Definition: modpw.f90:22