cdngen.F90 5.76 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
MODULE m_cdngen
7

8 9 10 11 12 13
USE m_juDFT

CONTAINS

SUBROUTINE cdngen(eig_id,mpi,input,banddos,sliceplot,vacuum,&
                  dimension,kpts,atoms,sphhar,stars,sym,obsolete,&
14
                  enpara,cell,noco,vTot,results,oneD,coreSpecInput,&
15
                  archiveType,outDen)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

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

   USE m_constants
   USE m_prpqfftmap
   USE m_cdnval
   USE m_cdn_io
   USE m_wrtdop
   USE m_cdntot
   USE m_cdnovlp
   USE m_qfix
31
   USE m_genNewNocoInp
32 33
   USE m_types
   USE m_xmlOutput
34
   USE m_magMoms
35
   USE m_orbMagMoms
36
   USE m_cdncore
37 38
   USE m_doswrite
   USE m_Ekwritesl
39
#ifdef CPP_MPI
40
   USE m_mpi_bc_potden
41
#endif
42

43
   IMPLICIT NONE
44

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
   ! 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_obsolete),INTENT(IN)      :: obsolete
   TYPE(t_banddos),INTENT(IN)       :: banddos
   TYPE(t_sliceplot),INTENT(IN)     :: sliceplot
   TYPE(t_input),INTENT(IN)         :: input
   TYPE(t_vacuum),INTENT(IN)        :: vacuum
   TYPE(t_noco),INTENT(IN)          :: noco
   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
65
   TYPE(t_potden),INTENT(INOUT)     :: outDen
66 67

   !Scalar Arguments
68
   INTEGER, INTENT (IN)             :: eig_id, archiveType
69 70

   ! Local type instances
71 72
   TYPE(t_noco)          :: noco_new
   TYPE(t_regionCharges) :: regCharges
73
   TYPE(t_dos)           :: dos
74
   TYPE(t_moments)       :: moments
75 76
   TYPE(t_mcd)           :: mcd
   TYPE(t_slab)          :: slab
77
   TYPE(t_cdnvalKLoop)   :: cdnvalKLoop
78

79

80
   !Local Scalars
81 82
   REAL                  :: fix, qtot, dummy
   INTEGER               :: jspin, jspmax
83

84 85
   CALL regCharges%init(input,atoms)
   CALL dos%init(input,atoms,dimension,kpts,vacuum)
86
   CALL moments%init(input,atoms)
87

88
   IF (mpi%irank.EQ.0) CALL openXMLElementNoAttributes('valenceDensity')
89

90
   !In a non-collinear calcuation where the off-diagonal part of the
91 92
   !density matrix in the muffin-tins is calculated, the a- and
   !b-coef. for both spins are needed at once. Thus, cdnval is only
93
   !called once and both spin directions are calculated in a single run.
94 95 96
   jspmax = input%jspins
   IF (noco%l_mperp) jspmax = 1
   DO jspin = 1,jspmax
97
      CALL cdnvalKLoop%init(mpi,input,kpts,banddos,noco,results,jspin,sliceplot)
98
      CALL cdnval(eig_id,mpi,kpts,jspin,sliceplot,noco,input,banddos,cell,atoms,enpara,stars,vacuum,dimension,&
99
                  sphhar,sym,obsolete,vTot,oneD,coreSpecInput,cdnvalKLoop,outDen,regCharges,dos,results,moments,mcd,slab)
100 101
   END DO

102 103
   IF (mpi%irank.EQ.0) THEN
      IF (banddos%dos.or.banddos%vacdos.or.input%cdinf) THEN
104
         CALL timestart("cdngen: dos")
105 106 107 108
         CALL doswrite(eig_id,dimension,kpts,atoms,vacuum,input,banddos,sliceplot,noco,sym,cell,mcd,results,slab%nsld,oneD)
         IF (banddos%dos.AND.(banddos%ndir.EQ.-3)) THEN
            CALL Ek_write_sl(eig_id,dimension,kpts,atoms,vacuum,input,jspmax,sym,cell,slab)
         END IF
109
         CALL timestop("cdngen: dos")
110 111 112 113 114 115
      END IF
   END IF

   IF ((banddos%dos.OR.banddos%vacdos).AND.(banddos%ndir/=-2)) CALL juDFT_end("DOS OK",mpi%irank)
   IF (vacuum%nstm.EQ.3) CALL juDFT_end("VACWAVE OK",mpi%irank)

116
   IF (mpi%irank.EQ.0) THEN
117
      CALL cdntot(stars,atoms,sym,vacuum,input,cell,oneD,outDen,.TRUE.,qtot,dummy)
118 119 120
      CALL closeXMLElement('valenceDensity')
   END IF ! mpi%irank = 0

121 122
   IF (sliceplot%slice) THEN
      IF (mpi%irank.EQ.0) THEN
123
         CALL writeDensity(stars,vacuum,atoms,cell,sphhar,input,sym,oneD,archiveType,CDN_INPUT_DEN_const,&
124
                           0,-1.0,0.0,.FALSE.,outDen,'cdn_slice')
125
      END IF
126
      CALL juDFT_end("slice OK",mpi%irank)
127
   END IF
128

129 130 131
   CALL cdncore(results,mpi,dimension,oneD,input,vacuum,noco,sym,&
                stars,cell,sphhar,atoms,vTot,outDen,moments)

132 133
   CALL enpara%calcOutParams(input,atoms,vacuum,regCharges)

134 135
   IF (mpi%irank.EQ.0) THEN
      CALL openXMLElementNoAttributes('allElectronCharges')
136
      CALL qfix(stars,atoms,sym,vacuum,sphhar,input,cell,oneD,outDen,noco%l_noco,.TRUE.,.true.,fix)
137 138 139 140 141 142
      CALL closeXMLElement('allElectronCharges')

      IF (input%jspins.EQ.2) THEN
         noco_new = noco

         !Calculate and write out spin densities at the nucleus and magnetic moments in the spheres
143
         CALL magMoms(dimension,input,atoms,noco_new,vTot,moments)
144 145 146 147

         !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
148
            CALL genNewNocoInp(input,atoms,noco,noco_new)
149 150
         END IF

151
         IF (noco%l_soc) CALL orbMagMoms(dimension,atoms,noco,moments%clmom)
152 153 154
      END IF
   END IF ! mpi%irank.EQ.0

155 156 157 158 159
#ifdef CPP_MPI
   CALL mpi_bc_potden(mpi,stars,sphhar,atoms,input,vacuum,oneD,noco,outDen)
#endif

END SUBROUTINE cdngen
160

161
END MODULE m_cdngen