cdngen.F90 8.78 KB
Newer Older
1 2 3 4 5
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------
6 7 8 9
MODULE m_cdngen
CONTAINS

SUBROUTINE cdngen(eig_id,mpi,input,banddos,sliceplot,vacuum,&
10
                  dimension,kpts,atoms,sphhar,stars,sym,&
11
                  enpara,cell,noco,vTot,results,oneD,coreSpecInput,&
12
                  archiveType, xcpot,outDen,EnergyDen)
13 14 15 16 17 18 19

   !*****************************************************
   !    Charge density generator
   !    calls cdnval to generate the valence charge and the
   !    core routines for the core contribution
   !*****************************************************

20
   USE m_types
21
   USE m_constants
22
   USE m_juDFT
23 24 25 26 27 28
   USE m_prpqfftmap
   USE m_cdnval
   USE m_cdn_io
   USE m_wrtdop
   USE m_cdntot
   USE m_qfix
29
   USE m_genNewNocoInp
30
   USE m_xmlOutput
31
   USE m_magMoms
32
   USE m_orbMagMoms
33
   USE m_cdncore
34 35
   USE m_doswrite
   USE m_Ekwritesl
36
   USE m_banddos_io
37
   USE m_metagga
38
   USE m_unfold_band_kpts
39
#ifdef CPP_MPI
40
   USE m_mpi_bc_potden
41
#endif
42

43
   IMPLICIT NONE
44

45 46 47 48
#ifdef CPP_MPI
   INCLUDE 'mpif.h'
#endif

49 50 51 52 53 54 55 56 57 58
   ! Type instance arguments
   TYPE(t_results),INTENT(INOUT)    :: results
   TYPE(t_mpi),INTENT(IN)           :: mpi
   TYPE(t_dimension),INTENT(IN)     :: dimension
   TYPE(t_oneD),INTENT(IN)          :: oneD
   TYPE(t_enpara),INTENT(INOUT)     :: enpara
   TYPE(t_banddos),INTENT(IN)       :: banddos
   TYPE(t_sliceplot),INTENT(IN)     :: sliceplot
   TYPE(t_input),INTENT(IN)         :: input
   TYPE(t_vacuum),INTENT(IN)        :: vacuum
59
   TYPE(t_noco),INTENT(INOUT)       :: noco
60 61 62 63 64 65 66 67
   TYPE(t_sym),INTENT(IN)           :: sym
   TYPE(t_stars),INTENT(IN)         :: stars
   TYPE(t_cell),INTENT(IN)          :: cell
   TYPE(t_kpts),INTENT(IN)          :: kpts
   TYPE(t_sphhar),INTENT(IN)        :: sphhar
   TYPE(t_atoms),INTENT(IN)         :: atoms
   TYPE(t_coreSpecInput),INTENT(IN) :: coreSpecInput
   TYPE(t_potden),INTENT(IN)        :: vTot
68 69
   CLASS(t_xcpot),INTENT(INOUT)     :: xcpot
   TYPE(t_potden),INTENT(INOUT)     :: outDen, EnergyDen
70 71

   !Scalar Arguments
72
   INTEGER, INTENT (IN)             :: eig_id, archiveType
73 74

   ! Local type instances
75
   TYPE(t_noco)          :: noco_new
Matthias Redies's avatar
Matthias Redies committed
76 77 78 79
   TYPE(t_regionCharges) :: regCharges, fake_regCharges
   TYPE(t_dos)           :: dos, fake_dos
   TYPE(t_moments)       :: moments, fake_moments
   TYPE(t_results)       :: fake_results
80 81
   TYPE(t_mcd)           :: mcd
   TYPE(t_slab)          :: slab
82
   TYPE(t_orbcomp)       :: orbcomp
83
   TYPE(t_cdnvalJob)     :: cdnvalJob
84
   TYPE(t_potden)        :: val_den, core_den
85

86

87
   !Local Scalars
88
   REAL                  :: fix, qtot, dummy,eFermiPrev
89
   INTEGER               :: jspin, jspmax, ierr
Matthias Redies's avatar
Matthias Redies committed
90
   INTEGER               :: dim_idx
91

92 93 94
#ifdef CPP_HDF
   INTEGER(HID_T)        :: banddosFile_id
#endif
95
   LOGICAL               :: l_error, perform_MetaGGA
96

97 98
   CALL regCharges%init(input,atoms)
   CALL dos%init(input,atoms,dimension,kpts,vacuum)
99
   CALL moments%init(input,atoms)
100 101 102
   CALL mcd%init1(banddos,dimension,input,atoms,kpts)
   CALL slab%init(banddos,dimension,atoms,cell,input,kpts)
   CALL orbcomp%init(input,banddos,dimension,atoms,kpts)
103

104 105
   CALL outDen%init(stars,    atoms, sphhar, vacuum, noco, input%jspins, POTDEN_TYPE_DEN)
   CALL EnergyDen%init(stars, atoms, sphhar, vacuum, noco, input%jspins, POTDEN_TYPE_EnergyDen)
106

Matthias Redies's avatar
Matthias Redies committed
107
   IF (mpi%irank == 0) CALL openXMLElementNoAttributes('valenceDensity')
108

109
   !In a non-collinear calcuation where the off-diagonal part of the
110 111
   !density matrix in the muffin-tins is calculated, the a- and
   !b-coef. for both spins are needed at once. Thus, cdnval is only
112
   !called once and both spin directions are calculated in a single run.
113
   results%force=0.0
114 115 116
   jspmax = input%jspins
   IF (noco%l_mperp) jspmax = 1
   DO jspin = 1,jspmax
117 118
      CALL cdnvalJob%init(mpi,input,kpts,noco,results,jspin)
      IF (sliceplot%slice) CALL cdnvalJob%select_slice(sliceplot,results,input,kpts,noco,jspin)
119
      CALL cdnval(eig_id,mpi,kpts,jspin,noco,input,banddos,cell,atoms,enpara,stars,vacuum,dimension,&
120
                  sphhar,sym,vTot,oneD,cdnvalJob,outDen,regCharges,dos,results,moments,coreSpecInput,mcd,slab,orbcomp)
121
   END DO
122
   call val_den%copyPotDen(outDen)
123

124 125
   ! calculate kinetic energy density for MetaGGAs
   if(xcpot%exc_is_metagga()) then
Matthias Redies's avatar
Matthias Redies committed
126
      CALL calc_EnergyDen(eig_id, mpi, kpts, noco, input, banddos, cell, atoms, enpara, stars,&
127
                             vacuum, DIMENSION, sphhar, sym, vTot, oneD, results, EnergyDen)
128 129
   endif

Matthias Redies's avatar
Matthias Redies committed
130
   IF (mpi%irank == 0) THEN
131
      IF (banddos%dos.or.banddos%vacdos.or.input%cdinf) THEN
132 133 134 135 136
         IF (banddos%unfoldband) THEN
            eFermiPrev = 0.0
            CALL readPrevEFermi(eFermiPrev,l_error)
            CALL write_band_sc(kpts,results,eFermiPrev)
         END IF
137
#ifdef CPP_HDF
138
         CALL openBandDOSFile(banddosFile_id,input,atoms,cell,kpts,banddos)
139 140
         CALL writeBandDOSData(banddosFile_id,input,atoms,cell,kpts,results,banddos,dos,vacuum)
         CALL closeBandDOSFile(banddosFile_id)
141
#endif
142
         CALL timestart("cdngen: dos")
143
         CALL doswrite(eig_id,dimension,kpts,atoms,vacuum,input,banddos,sliceplot,noco,sym,cell,dos,mcd,results,slab,orbcomp,oneD)
Matthias Redies's avatar
Matthias Redies committed
144
         IF (banddos%dos.AND.(banddos%ndir == -3)) THEN
145
            CALL Ek_write_sl(eig_id,dimension,kpts,atoms,vacuum,input,jspmax,sym,cell,dos,slab,orbcomp,results)
146
         END IF
147
         CALL timestop("cdngen: dos")
148 149 150 151
      END IF
   END IF

   IF ((banddos%dos.OR.banddos%vacdos).AND.(banddos%ndir/=-2)) CALL juDFT_end("DOS OK",mpi%irank)
Matthias Redies's avatar
Matthias Redies committed
152
   IF (vacuum%nstm == 3) CALL juDFT_end("VACWAVE OK",mpi%irank)
153

154
   IF (mpi%irank.EQ.0) THEN
Matthias Redies's avatar
Matthias Redies committed
155
      CALL cdntot(stars,atoms,sym,vacuum,input,cell,oneD,outDen,.TRUE.,qtot,dummy)
156 157 158
      CALL closeXMLElement('valenceDensity')
   END IF ! mpi%irank = 0

159
   IF (sliceplot%slice) THEN
Matthias Redies's avatar
Matthias Redies committed
160
      IF (mpi%irank == 0) THEN
161
         CALL writeDensity(stars,vacuum,atoms,cell,sphhar,input,sym,oneD,CDN_ARCHIVE_TYPE_CDN_const,CDN_INPUT_DEN_const,&
162
                           0,-1.0,0.0,.FALSE.,outDen,'cdn_slice')
163
      END IF
164
      CALL juDFT_end("slice OK",mpi%irank)
165
   END IF
166

Uliana Alekseeva's avatar
Uliana Alekseeva committed
167
   CALL timestart("cdngen: cdncore")
168 169 170 171 172 173 174
   if(xcpot%exc_is_MetaGGA()) then
      CALL cdncore(mpi,dimension,oneD,input,vacuum,noco,sym,&
                   stars,cell,sphhar,atoms,vTot,outDen,moments,results, EnergyDen)
   else
      CALL cdncore(mpi,dimension,oneD,input,vacuum,noco,sym,&
                   stars,cell,sphhar,atoms,vTot,outDen,moments,results)
   endif
175
   call core_den%subPotDen(outDen, val_den)
Uliana Alekseeva's avatar
Uliana Alekseeva committed
176
   CALL timestop("cdngen: cdncore")
177

178 179
   CALL enpara%calcOutParams(input,atoms,vacuum,regCharges)

Matthias Redies's avatar
Matthias Redies committed
180
   IF (mpi%irank == 0) THEN
181
      CALL openXMLElementNoAttributes('allElectronCharges')
182
      CALL qfix(mpi,stars,atoms,sym,vacuum,sphhar,input,cell,oneD,outDen,noco%l_noco,.TRUE.,.true.,fix)
183 184
      CALL closeXMLElement('allElectronCharges')

Matthias Redies's avatar
Matthias Redies committed
185
      IF (input%jspins == 2) THEN
186 187 188
         noco_new = noco

         !Calculate and write out spin densities at the nucleus and magnetic moments in the spheres
189
         CALL magMoms(dimension,input,atoms,noco_new,vTot,moments)
190

191 192
         noco = noco_new

193 194 195
         !Generate and save the new nocoinp file if the directions of the local
         !moments are relaxed or a constraint B-field is calculated.
         IF (ANY(noco%l_relax(:atoms%ntype)).OR.noco%l_constr) THEN
196
            CALL genNewNocoInp(input,atoms,noco,noco_new)
197 198
         END IF

199
         IF (noco%l_soc) CALL orbMagMoms(input,atoms,noco,moments%clmom)
200
         
201
      END IF
Matthias Redies's avatar
Matthias Redies committed
202
   END IF ! mpi%irank == 0
203
   
204 205 206
   perform_MetaGGA = ALLOCATED(EnergyDen%mt) &
                   .AND. (xcpot%exc_is_MetaGGA() .or. xcpot%vx_is_MetaGGA())
   if(perform_MetaGGA) then
207
      call set_kinED(mpi, sphhar, atoms, sym, core_den, val_den, xcpot, &
208 209
                     input, noco, stars, cell, outDen, EnergyDen, vTot)
   endif
210
#ifdef CPP_MPI
211 212 213 214 215 216 217 218 219 220 221 222
   CALL MPI_BCAST(noco%l_ss,1,MPI_LOGICAL,0,mpi%mpi_comm,ierr)
   CALL MPI_BCAST(noco%l_mperp,1,MPI_LOGICAL,0,mpi%mpi_comm,ierr)
   CALL MPI_BCAST(noco%l_constr,1,MPI_LOGICAL,0,mpi%mpi_comm,ierr)
   CALL MPI_BCAST(noco%mix_b,1,MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)

   CALL MPI_BCAST(noco%alphInit,atoms%ntype,MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
   CALL MPI_BCAST(noco%alph,atoms%ntype,MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
   CALL MPI_BCAST(noco%beta,atoms%ntype,MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
   CALL MPI_BCAST(noco%b_con,atoms%ntype*2,MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
   CALL MPI_BCAST(noco%l_relax,atoms%ntype,MPI_LOGICAL,0,mpi%mpi_comm,ierr)
   CALL MPI_BCAST(noco%qss,3,MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)

223 224 225 226
   CALL mpi_bc_potden(mpi,stars,sphhar,atoms,input,vacuum,oneD,noco,outDen)
#endif

END SUBROUTINE cdngen
227

228
END MODULE m_cdngen