~albertog/siesta/efield-2.5-jjunquera

« back to all changes in this revision

Viewing changes to Src/vmatsp.f

  • 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:
51
51
      use mesh, only: dxa, nsp, xdop, xdsp, cmesh, nmeshg, nsm
52
52
      use meshdscf
53
53
      use meshphi
 
54
      use alloc, only: re_alloc, de_alloc
54
55
 
55
56
      implicit none
56
57
 
61
62
      real(grid_p), intent(in)  ::  V(nsp,np,nspin)
62
63
      real(dp)
63
64
     .   dvol, Vs(nvmax,nspin), q(3)
64
 
      external
65
 
     .   memory, timer, ipack
 
65
      external memory, timer, ipack
66
66
 
67
67
C Internal variables and arrays
68
68
 
74
74
     .  is, isp, ispin, iu, iul, ix, j, jc, jl, nsd,
75
75
     .  last, lasta, lastop, maxloc, maxloc2, nc, nlocal, 
76
76
     .  nphiloc, nvmaxl, iii(3)
77
 
      integer, dimension(:), allocatable, save ::
78
 
     .  ilc, ilocal, iorb
79
 
      logical
80
 
     .  Parallel_Flag
 
77
 
 
78
      integer, pointer :: ilc(:), ilocal(:), iorb(:)
 
79
 
 
80
      logical Parallel_Flag
81
81
      real(dp)
82
82
     .  Vij1, Vij2, Vij3, Vij4, dxsp(3), phia(maxoa,nsp),
83
83
     .  r2cut(nsmax), r2sp, xr(3), Rdi(3), qRdi, cqRdi, sqRdi
84
 
      real(dp), dimension(:),   allocatable, save :: 
85
 
     .  VClocal, VClocal1, VClocal2, VClocal3, VClocal4    
86
 
      real(dp), dimension(:,:), allocatable, save :: 
87
 
     .  Clocal, Vlocal
88
 
      real(dp), dimension(:,:,:), allocatable, save ::
89
 
     .  VlocalSp
 
84
 
 
85
      real(dp), pointer :: VClocal(:), VClocal1(:),
 
86
     &                     VClocal2(:), VClocal3(:), VClocal4(:)
 
87
  
 
88
      real(dp), pointer :: Clocal(:,:), Vlocal(:,:)
 
89
      real(dp), pointer :: VlocalSp(:,:,:)
90
90
 
91
91
C  Start time counter
92
92
      call timer('vmatsp',1)
103
103
C  If spiral, the diagonal elements of Vlocal do not change
104
104
      nsd = 2
105
105
 
106
 
C  Allocate local memory
107
 
      allocate(ilocal(no))
108
 
      call memory('A','I',no,'vmatsp')
109
 
      allocate(ilc(maxloc2))
110
 
      call memory('A','I',maxloc2,'vmatsp')
111
 
      allocate(iorb(0:maxloc))
112
 
      call memory('A','I',maxloc+1,'vmatsp')
 
106
      !  Allocate local memory
 
107
      nullify ( ilocal )
 
108
      call re_alloc( ilocal, 1, no, name='ilocal', routine='vmatsp' )
 
109
 
 
110
      nullify ( ilc )
 
111
      call re_alloc( ilc, 1, maxloc2, name='ilc', routine='vmatsp' )
 
112
 
 
113
      nullify (iorb )
 
114
      call re_alloc( iorb, 0, maxloc, name='iorb', routine='vmatsp' )
 
115
 
113
116
      ijl = (maxloc+1)*(maxloc+2)/2
114
 
      allocate(Vlocal(ijl,nsd))
115
 
      call memory('A','D',ijl*nsd,'vmatsp')
116
 
      allocate(VlocalSp(0:maxloc,0:maxloc,nsd))
117
 
      call memory('A','D',(maxloc+1)*(maxloc+1)*nsd,'vmatsp')
118
 
      allocate(Clocal(nsp,maxloc2))
119
 
      call memory('A','D',nsp*maxloc2,'vmatsp')
120
 
      allocate(VClocal(nsp))
121
 
      call memory('A','D',nsp,'vmatsp')
122
 
      allocate(VClocal1(nsp))
123
 
      call memory('A','D',nsp,'vmatsp')
124
 
      allocate(VClocal2(nsp))
125
 
      call memory('A','D',nsp,'vmatsp')
126
 
      allocate(VClocal3(nsp))
127
 
      call memory('A','D',nsp,'vmatsp')
128
 
      allocate(VClocal4(nsp))
129
 
      call memory('A','D',nsp,'vmatsp')
 
117
 
 
118
      nullify( Vlocal )
 
119
      call re_alloc( Vlocal, 1, ijl, 1, nsd, name='Vlocal',
 
120
     &               routine='vmatsp' )
 
121
 
 
122
      nullify( VlocalSp )
 
123
      call re_alloc( VlocalSp, 0, maxloc, 0, maxloc, 1, nsd,
 
124
     &               name    = 'VlocalSp',
 
125
     &               routine = 'vmatsp' )
 
126
 
 
127
      nullify( Clocal )
 
128
      call re_alloc( Clocal, 1, nsp, 1, maxloc2, name='Clocal',
 
129
     &               routine='vmatsp' )
 
130
 
 
131
      nullify( VClocal )
 
132
      call re_alloc( VClocal, 1, nsp, name='VClocal', routine='vmatsp' )
 
133
 
 
134
      nullify( VClocal1 )
 
135
      call re_alloc( VClocal1, 1, nsp, name='VClocal1',
 
136
     &               routine = 'vmatsp' )
 
137
 
 
138
      nullify( VClocal2 )
 
139
      call re_alloc( VClocal2, 1, nsp, name='VClocal2',
 
140
     &               routine = 'vmatsp' )
 
141
 
 
142
      nullify( VClocal3 )
 
143
      call re_alloc( VClocal3, 1, nsp, name='VClocal3',
 
144
     &               routine = 'vmatsp' )
 
145
 
 
146
      nullify( VClocal4 )
 
147
      call re_alloc( VClocal4, 1, nsp, name='VClocal4',
 
148
     &               routine = 'vmatsp' )
130
149
 
131
150
      if (Parallel_Flag) then
132
151
        if (nrowsDscfL.gt.0) then
134
153
        else
135
154
          nvmaxl = 1
136
155
        endif
137
 
        allocate(DscfL(nvmaxl,nsd+2))
138
 
        call memory('A','D',nvmaxl*(nsd+2),'meshdscf')
 
156
        call re_alloc( DscfL, 1, nvmaxl, 1, nsd+2,
 
157
     &                 name='DscfL',  routine='vmatsp' )
139
158
        DscfL(1:nvmaxl,1:nsd+2) = 0.0_dp
140
159
      endif
141
160
 
464
483
        endif
465
484
      enddo
466
485
 
467
 
C  Free local memory
468
 
      call memory('D','D',size(Vlocal),'vmatsp')
469
 
      deallocate(Vlocal)
470
 
      call memory('D','D',size(VlocalSp),'vmatsp')
471
 
      deallocate(VlocalSp)
472
 
      call memory('D','I',size(iorb),'vmatsp')
473
 
      deallocate(iorb)
474
 
      call memory('D','I',size(ilocal),'vmatsp')
475
 
      deallocate(ilocal)
476
 
      call memory('D','I',size(ilc),'vmatsp')
477
 
      deallocate(ilc)
478
 
      call memory('D','D',size(Clocal),'vmatsp')
479
 
      deallocate(Clocal)
480
 
      call memory('D','D',size(VClocal),'vmatsp')
481
 
      deallocate(VClocal)
482
 
      call memory('D','D',size(VClocal1),'vmatsp')
483
 
      deallocate(VClocal1)
484
 
      call memory('D','D',size(VClocal2),'vmatsp')
485
 
      deallocate(VClocal2)
486
 
      call memory('D','D',size(VClocal3),'vmatsp')
487
 
      deallocate(VClocal3)
488
 
      call memory('D','D',size(VClocal4),'vmatsp')
489
 
      deallocate(VClocal4)
 
486
      !  Free local memory
 
487
 
 
488
      call de_alloc( Vlocal,  name='Vlocal' )
 
489
      call de_alloc( VlocalSp,  name='VlocalSp' )
 
490
      call de_alloc( iorb,  name='iorb' )
 
491
      call de_alloc( ilocal,  name='ilocal' )
 
492
      call de_alloc( ilc,  name='ilc' )
 
493
      call de_alloc( Clocal,  name='Clocal' )
 
494
      call de_alloc( VClocal,  name='VClocal' )
 
495
      call de_alloc( VClocal1,  name='VClocal1' )
 
496
      call de_alloc( VClocal2,  name='VClocal2' )
 
497
      call de_alloc( VClocal3,  name='VClocal3' )
 
498
      call de_alloc( VClocal4,  name='VClocal4' )
490
499
 
491
500
      if (Parallel_Flag) then
492
501
C Redistribute Hamiltonian from mesh to orbital based distribution
493
502
        call matrixMtoO( nvmaxl, nvmax, numVs, listVsptr, nuo, 
494
503
     .      nuotot, nspin, DscfL, Vs )
495
504
C Free memory 
496
 
        call memory('D','D',size(DscfL),'meshdscf')
497
 
        deallocate(DscfL)
 
505
        call de_alloc( DscfL,  name='DscfL' )
498
506
      endif
499
507
 
500
508
      call timer('vmatsp',2)