~albertog/siesta/efield-2.5-jjunquera

« back to all changes in this revision

Viewing changes to Src/kpoint_grid.F90

  • Committer: Alberto Garcia
  • Date: 2007-11-21 11:45:49 UTC
  • mfrom: (192.1.67)
  • Revision ID: Arch-1:siesta@uam.es--2006%siesta-devel--reference--2.3--patch-1
Direct merge into master branch of initial BSC changes
The changes along the BSC branches, up to the end of the restructuring
of siesta.F and associated changes, have been merged into a direct
descendant of the main development line. The BSC work originally
started as a branch of siesta-devel--reference--2.1--patch-29. Development
along 2.1 continued, and a new continuation branch 2.3 has been created
specifically for this merge.

Main patches applied:

 * ref@bsc--2007/siesta-bsc--master--2.1--base-0
   tag of siesta@uam.es--2006/siesta-bsc--reference--2.1--patch-7

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-1
   Use of xalast in analysis routines. Exit of geometry loop

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-2
   Creation of a module to hold the siesta options

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-3
   New geometry module

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-4
   New stub module for sparse matrices

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-5
   More options for running tests

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-6
   Encapsulation of k-point handling

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-7
   Initialize iza in struct_init

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-8
   Siesta_todo slimming by M. Quero

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-9
   Fix import of no_l in born_charge

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-10
   Some conversions to Fortran90 by M. Quero

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-11
   Fourth session at the BSC

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-12
   Clarification of the scope of the stress variables

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-13
   Creation of siesta_forces

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-14
   Replacement of some allocatables by pointers and automatics

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-15
   New m_energies and m_steps modules. Back to old k-point behavior

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-16
   Merge of removal of integer and real variables from siesta_todo

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-17
   Fixes for troublesome bugs in reference code

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-18
   Final cleanup of siesta_todo

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-19
   Add character(len=*) routines to alloc.F90

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-20
   Pointers in fixed and setspatial. si2x1h test added to bsc-Makefile

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-21
   Re-organization of pulay module

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-22
   Reorganization of hsparse/xijorb calls with new neighbor module

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-23
   VPATH-aware compilation for multiple executable versions

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-24
   Allocatables to pointers  I

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-25
   Allocatables to pointers  II

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-26
   Allocatables to pointers III

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-27
   Allocatables to pointers IV -- new neighbor code + nspecies fix

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-28
   Explicit array-ness in calls in initatom and cellxc

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-29
   Fix wrong allocations in cellxc.F

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-30
   Explicit array extents in initatom.f

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-31
   Avoid shrinking of density-matrix arrays for extrapol.

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-32
   Fix typo in state_init.F

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-33
   Execute SCF loop when nscf=1

 * ref@bsc--2007/siesta-bsc--master--2.1--patch-34
   Clarify bounds of SCF loop in siesta_forces.

 * ref@bsc--2007/siesta-bsc--master--2.2--base-0
   tag of ref@bsc--2007/siesta-bsc--master--2.1--patch-31

 * ref@bsc--2007/siesta-bsc--master--2.3--base-0
   tag of ref@bsc--2007/siesta-bsc--master--2.2--base-0

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-1
   Prepare CHANGES file

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-2
   Merge patch-log for patch-30 from 2.1

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-3
   New treatment of fractional atoms in VCA. Bug fix in lmxo

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-4
   Re-enabling of kgrid update in variable-cell calculations

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-5
   Fix typo in state_init.F

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-6
   Merge filtering package by Eduardo Anglada

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-7
   Add graphite_c6_full test for more realistic vdW test

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-8
   Add patchlog for k-point fix

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-9
   Fix of zmatrix code to deal with degenerate case

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-10
   Units conversion in Util/Optical/optical.f. Scripts. Cosmetics

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-11
   Implementation of basis_enthalpy calculation. Zmatrix dependency

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-12
   Option to use fractional rc's for multiple zeta

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-13
   Sync vpath changes. Update siesta.tex

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-14
   Fix tag in MPI send/receive in mulliken

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-15
   Option to use fractional rc's for multiple zeta

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-16
   Merge of XML tester by Eduardo Anglada. Portability fixes

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-17
   Fix marenostrum-mpi.make. Syntax in compare_m.f90

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-18
   MareNostrum fixes. zdrot to blas. obj_setup. compare_m syntax

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-19
   Sync to bsc--2.1. Change banner in CHANGES to bsc--2.3

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-20
   Execute SCF loop when nscf=1

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-21
   Refinements of XML tester. New ioncat program

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-22
   Undef var in kgridinit, iohs MPI write, pdosg array bound, Origin shift

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-23
   Zmatrix optimization enhancements. Sign change in MM stress.

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-24
   Clarify bounds of SCF loop in siesta_forces.

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-25
   Avoid MP-grid permutations in trivial gamma case

 * ref@bsc--2007/siesta-bsc--master--2.3--patch-26
   Sync to reference--2.1

 * siesta@uam.es--2006/siesta-bsc--reference--2.1--base-0
   tag of siesta@uam.es--2006/siesta-devel--reference--2.1--patch-29

 * siesta@uam.es--2006/siesta-bsc--reference--2.1--patch-1
   First stage of siesta.F splitting at BSC

 * siesta@uam.es--2006/siesta-bsc--reference--2.1--patch-2
   Created struct_init for initial geometry setup. New test force_2

 * siesta@uam.es--2006/siesta-bsc--reference--2.1--patch-3
   Consolidate geometry updates at the end of loop

 * siesta@uam.es--2006/siesta-bsc--reference--2.1--patch-4
   Initialize vol2 correctly in m_check_supercell.f

 * siesta@uam.es--2006/siesta-bsc--reference--2.1--patch-5
   Kgrid setup streamlined. Bands. Proximity check. Hsparse allocation 

 * siesta@uam.es--2006/siesta-bsc--reference--2.1--patch-6
   Work by Manuel Quero before the meeting on Feb 7th

 * siesta@uam.es--2006/siesta-bsc--reference--2.1--patch-7
   Moved the Born-effective-charge code




Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
MODULE Kpoint_grid
 
2
!
 
3
! Contains data structures and routines to deal with the kpoint-grid
 
4
! for the self-consistent calculation
 
5
! Other uses (bands, optical, polarization) have their own structures.
 
6
!
 
7
  USE precision, only : dp
 
8
 
 
9
  implicit none
 
10
 
 
11
  private
 
12
  
 
13
  logical, public, save   :: scf_kgrid_first_time = .true.
 
14
  logical, public, save   :: gamma_scf
 
15
  integer, public, save   :: maxk              ! 
 
16
  integer, public, save   :: nkpnt             ! Total number of k-points
 
17
  real(dp)                :: eff_kgrid_cutoff  ! Effective kgrid_cutoff
 
18
 
 
19
  real(dp), pointer, public, save :: kweight(:) 
 
20
  real(dp), pointer, public, save :: kpoint(:,:)
 
21
 
 
22
  integer,  dimension(3,3), save  :: kscell = 0
 
23
  real(dp), dimension(3), save    :: kdispl = 0.0_dp
 
24
 
 
25
  logical, save     :: user_requested_mp = .false.
 
26
  logical, save     :: user_requested_cutoff = .false.
 
27
 
 
28
  logical, save     :: spiral = .false.
 
29
  logical, save     :: firm_displ = .false.
 
30
 
 
31
  public :: setup_kpoint_grid
 
32
 
 
33
  CONTAINS
 
34
 
 
35
  subroutine setup_Kpoint_grid( ucell )
 
36
  USE parallel, only  : Node
 
37
  USE fdf, only       : fdf_defined
 
38
  USE m_find_kgrid, only : find_kgrid
 
39
 
 
40
#ifdef MPI
 
41
  USE mpi_siesta
 
42
#endif
 
43
 
 
44
    implicit none
 
45
    real(dp) :: ucell(3,3)
 
46
 
 
47
#ifdef MPI
 
48
    integer :: MPIerror
 
49
#endif
 
50
 
 
51
    if (scf_kgrid_first_time) then
 
52
       nullify(kweight,kpoint)
 
53
       if (Node.eq.0) then
 
54
          spiral = fdf_defined('SpinSpiral')
 
55
       endif
 
56
#ifdef MPI
 
57
       call MPI_Bcast(spiral,1,MPI_logical,0,MPI_Comm_World,MPIerror)
 
58
#endif
 
59
       call setup_scf_kscell(ucell, firm_displ)
 
60
 
 
61
       scf_kgrid_first_time = .false.
 
62
 
 
63
    else
 
64
       if ( user_requested_mp    ) then
 
65
          ! no need to set up the kscell again
 
66
       else
 
67
          ! This was wrong in the old code
 
68
          call setup_scf_kscell(ucell, firm_displ)
 
69
       endif
 
70
    endif
 
71
 
 
72
    call find_kgrid(ucell,kscell,kdispl,firm_displ,     &
 
73
                    (.not. spiral),                    &
 
74
                    nkpnt,kpoint,kweight, eff_kgrid_cutoff)
 
75
 
 
76
    maxk = nkpnt
 
77
    gamma_scf =  (nkpnt == 1 .and.  &
 
78
                  dot_product(kpoint(:,1),kpoint(:,1)) < 1.0e-20_dp)
 
79
 
 
80
    if (Node .eq. 0) call siesta_write_k_points()
 
81
 
 
82
  end subroutine setup_Kpoint_grid
 
83
 
 
84
!--------------------------------------------------------------------
 
85
  subroutine setup_scf_kscell( cell, firm_displ )
 
86
 
 
87
! ***************** INPUT **********************************************
 
88
! real*8  cell(3,3)  : Unit cell vectors in real space cell(ixyz,ivec)
 
89
! ***************** OUTPUT *********************************************
 
90
! logical firm_displ   : User-specified displacements (firm)?
 
91
 
 
92
!   The relevant fdf labels are kgrid_cutoff and kgrid_Monkhorst_Pack.
 
93
!   If both are present, kgrid_Monkhorst_Pack has priority. If none is
 
94
!   present, the cutoff default is zero, producing only the gamma point.
 
95
!   Examples of fdf data specifications:
 
96
!     kgrid_cutoff  50. Bohr
 
97
!     %block kgrid_Monkhorst_Pack  # Defines kscell and kdispl
 
98
!     4  0  0   0.50               # (kscell(i,1),i=1,3), kdispl(1)
 
99
!     0  4  0   0.50               # (kscell(i,2),i=1,3), kdispl(2)
 
100
!     0  0  4   0.50               # (kscell(i,3),i=1,3), kdispl(3)
 
101
!     %endblock kgrid_Monkhorst_Pack
 
102
! **********************************************************************
 
103
 
 
104
!  Modules
 
105
 
 
106
      use precision,  only : dp
 
107
      use parallel,   only : Node
 
108
      use m_minvec,   only : minvec
 
109
      use fdf
 
110
#ifdef MPI
 
111
      use mpi_siesta
 
112
#endif
 
113
 
 
114
      implicit          none
 
115
 
 
116
! Passed variables
 
117
      real(dp), intent(in)   :: cell(3,3)
 
118
      logical, intent(out)   :: firm_displ
 
119
 
 
120
! Internal variables
 
121
      integer           i, iu, j,  factor(3,3), expansion_factor
 
122
#ifdef MPI
 
123
      integer           MPIerror
 
124
#endif
 
125
      real(dp)          scmin(3,3),  vmod, cutoff
 
126
      real(dp)          ctransf(3,3)
 
127
      logical           mp_input
 
128
 
 
129
      real(dp), parameter :: defcut = 0.0_dp
 
130
      integer, dimension(3,3), parameter :: unit_matrix =  &
 
131
                         reshape ((/1,0,0,0,1,0,0,0,1/), (/3,3/))
 
132
 
 
133
      if (Node.eq.0) then
 
134
 
 
135
         mp_input = fdf_block('kgrid_Monkhorst_Pack',iu)
 
136
         if ( mp_input ) then
 
137
            user_requested_mp = .true.
 
138
            do i = 1,3
 
139
               read(iu,*) (kscell(j,i),j=1,3), kdispl(i)
 
140
            enddo
 
141
            firm_displ = .true.
 
142
 
 
143
         else
 
144
 
 
145
            cutoff = fdf_physical('kgrid_cutoff',defcut,'Bohr')
 
146
            if (cutoff /= defcut) then
 
147
            !!  write(6,"(a,f10.5)") "Kgrid cutoff input: ", cutoff
 
148
               user_requested_cutoff = .true.
 
149
            endif
 
150
 
 
151
            kdispl(1:3) = 0.0_dp  ! Might be changed later
 
152
            firm_displ = .false.  ! In future we might add new options
 
153
                                  ! for user-specified displacements
 
154
            
 
155
            ! Find equivalent rounded unit-cell
 
156
            call minvec( cell, scmin, ctransf )
 
157
 
 
158
            expansion_factor = 1
 
159
            do j = 1,3
 
160
               factor(j,1:3) = 0
 
161
               vmod = sqrt(dot_product(scmin(1:3,j),scmin(1:3,j)))
 
162
               factor(j,j) = int(2.0_dp*cutoff/vmod) + 1
 
163
               expansion_factor = expansion_factor * factor(j,j)
 
164
            enddo
 
165
            ! Generate actual supercell skeleton
 
166
            kscell = matmul(ctransf, factor)
 
167
            ! Avoid confusing permutations
 
168
            if (expansion_factor == 1) then
 
169
               kscell = unit_matrix
 
170
            endif
 
171
         endif
 
172
      endif
 
173
 
 
174
#ifdef MPI
 
175
      call MPI_Bcast(kscell(1,1),9,MPI_integer,0,MPI_Comm_World, MPIerror)
 
176
      call MPI_Bcast(kdispl,3,MPI_double_precision,0,MPI_Comm_World, MPIerror)
 
177
      call MPI_Bcast(firm_displ,1,MPI_logical,0,MPI_Comm_World, MPIerror)
 
178
      call MPI_Bcast(user_requested_mp,1,MPI_logical,0,   &
 
179
                     MPI_Comm_World, MPIerror)
 
180
      call MPI_Bcast(user_requested_cutoff,1,MPI_logical,0,   &
 
181
                     MPI_Comm_World, MPIerror)
 
182
#endif
 
183
 
 
184
    end subroutine setup_scf_kscell
 
185
 
 
186
    subroutine siesta_write_k_points()
 
187
      USE siesta_options, only: writek
 
188
      USE units, only: Ang
 
189
      USE siesta_cml
 
190
 
 
191
      implicit none
 
192
 
 
193
      integer  :: ik, ix, i
 
194
      external :: iokp
 
195
 
 
196
      if ( writek ) then
 
197
         write(6,'(/,a)') 'siesta: k-point coordinates (Bohr**-1) and weights:'
 
198
         write(6,'(a,i4,3f12.6,3x,f12.6)')                          &
 
199
              ('siesta: ', ik, (kpoint(ix,ik),ix=1,3), kweight(ik), &
 
200
              ik=1,nkpnt)
 
201
         if (cml_p) then
 
202
            call cmlAddProperty(xf=mainXML, property=kpoint,    &
 
203
            dictref='siesta:kpoint')
 
204
            call cmlAddProperty(xf=mainXML, property=kweight,         &
 
205
                 dictref='siesta:kweight')
 
206
         endif
 
207
      else
 
208
         call iokp( nkpnt, kpoint, kweight )
 
209
      endif
 
210
      write(6,'(/a,i6)')  'siesta: k-grid: Number of k-points =', nkpnt
 
211
      write(6,'(a,f10.3,a)')  'siesta: k-grid: Cutoff (effective) =',  &
 
212
           eff_kgrid_cutoff/Ang, ' Ang'
 
213
      write(6,'(a)') 'siesta: k-grid: Supercell and displacements'
 
214
      write(6,'(a,3i4,3x,f8.3)') 'siesta: k-grid: ',        &
 
215
           (kscell(i,1),i=1,3), kdispl(1)
 
216
      write(6,'(a,3i4,3x,f8.3)') 'siesta: k-grid: ',        &
 
217
           (kscell(i,2),i=1,3), kdispl(2)
 
218
      write(6,'(a,3i4,3x,f8.3)') 'siesta: k-grid: ',        &
 
219
           (kscell(i,3),i=1,3), kdispl(3)
 
220
      if (cml_p) then
 
221
         call cmlStartPropertyList(mainXML, title='k-points')
 
222
         call cmlAddProperty(xf=mainXML, property=nkpnt,dictref='siesta:nkpnt')
 
223
         call cmlAddProperty(xf=mainXML, property=eff_kgrid_cutoff/Ang,     & 
 
224
              dictref='siesta:kcutof', units='siestaUnits:angstrom')
 
225
         call cmlEndPropertyList(mainXML)
 
226
         call cmlAddProperty(xf=mainXML, property=kscell,dictref='siesta:kscell')
 
227
         call cmlAddProperty(xf=mainXML, property=kdispl,dictref='siesta:kdispl')
 
228
      endif
 
229
    end subroutine siesta_write_k_points
 
230
 
 
231
END MODULE Kpoint_grid