fleur_init.F90 11.4 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.
!--------------------------------------------------------------------------------
Daniel Wortmann's avatar
Daniel Wortmann committed
6 7 8 9
MODULE m_fleur_init
  IMPLICIT NONE
CONTAINS
  SUBROUTINE fleur_init(mpi,&
10
       input,field,atoms, sphhar,cell,stars,sym,noco,nococonv,vacuum,forcetheo,&
Matthias Redies's avatar
Matthias Redies committed
11
       sliceplot,banddos,enpara,xcpot,results,kpts,mpinp,hybinp,&
12
       oneD,coreSpecInput,gfinp,hub1inp,wann)
Daniel Wortmann's avatar
Daniel Wortmann committed
13 14 15
    USE m_types
    USE m_fleurinput_read_xml
    USE m_fleurinput_mpi_bc
Matthias Redies's avatar
Matthias Redies committed
16
    USE m_types_mpinp
Daniel Wortmann's avatar
Daniel Wortmann committed
17 18 19 20 21
    USE m_judft
    USE m_juDFT_init
    USE m_init_wannier_defaults
    USE m_dwigner
    USE m_ylm
22
    !USE m_InitParallelProcesses
Daniel Wortmann's avatar
Daniel Wortmann committed
23 24 25 26 27 28 29 30 31 32 33 34 35
    USE m_xmlOutput
    USE m_constants
    USE m_winpXML
    USE m_writeOutParameters
    USE m_setupMPI
    USE m_cdn_io
    USE m_fleur_info
    USE m_mixing_history
    USE m_checks
    USE m_writeOutHeader
    !USE m_fleur_init_old
    USE m_types_xcpot_inbuild
    USE m_mpi_bc_xcpot
36 37 38 39 40 41 42 43
    USE m_prpxcfft
    use m_make_stars
    use m_make_sphhar
    USE m_convn
    USE m_efield
    USE m_fleurinput_postprocess
    use m_make_forcetheo
    use m_lapwdim
44
    use m_gaunt, only: gaunt_init
45
#ifdef CPP_MPI
46
    !USE m_mpi_bc_all,  ONLY : mpi_bc_all
47
#ifndef CPP_OLDINTEL
Daniel Wortmann's avatar
Daniel Wortmann committed
48
    USE m_mpi_dist_forcetheorem
Daniel Wortmann's avatar
Daniel Wortmann committed
49
#endif
50
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
51
#ifdef CPP_HDF
Daniel Wortmann's avatar
Daniel Wortmann committed
52
    USE m_hdf_tools
53
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
54 55 56 57 58
    IMPLICIT NONE
    !     Types, these variables contain a lot of data!
    TYPE(t_mpi)    ,INTENT(INOUT):: mpi
    TYPE(t_input)    ,INTENT(OUT):: input
    TYPE(t_field),    INTENT(OUT) :: field
59

Daniel Wortmann's avatar
Daniel Wortmann committed
60 61 62 63 64 65 66 67 68 69 70 71 72
    TYPE(t_atoms)    ,INTENT(OUT):: atoms
    TYPE(t_sphhar)   ,INTENT(OUT):: sphhar
    TYPE(t_cell)     ,INTENT(OUT):: cell
    TYPE(t_stars)    ,INTENT(OUT):: stars
    TYPE(t_sym)      ,INTENT(OUT):: sym
    TYPE(t_noco)     ,INTENT(OUT):: noco
    TYPE(t_vacuum)   ,INTENT(OUT):: vacuum
    TYPE(t_sliceplot),INTENT(OUT):: sliceplot
    TYPE(t_banddos)  ,INTENT(OUT):: banddos
    TYPE(t_enpara)   ,INTENT(OUT):: enpara
    CLASS(t_xcpot),ALLOCATABLE,INTENT(OUT):: xcpot
    TYPE(t_results)  ,INTENT(OUT):: results
    TYPE(t_kpts)     ,INTENT(OUT):: kpts
Matthias Redies's avatar
Matthias Redies committed
73
    TYPE(t_mpinp)    ,INTENT(OUT):: mpinp
Matthias Redies's avatar
Matthias Redies committed
74
    TYPE(t_hybinp)   ,INTENT(OUT):: hybinp
Daniel Wortmann's avatar
Daniel Wortmann committed
75 76 77 78
    TYPE(t_oneD)     ,INTENT(OUT):: oneD
    TYPE(t_coreSpecInput),INTENT(OUT) :: coreSpecInput
    TYPE(t_wann)     ,INTENT(OUT):: wann
    CLASS(t_forcetheo),ALLOCATABLE,INTENT(OUT)::forcetheo
79 80
    TYPE(t_gfinp)    ,INTENT(OUT):: gfinp
    TYPE(t_hub1inp)  ,INTENT(OUT):: hub1inp
81
    TYPE(t_nococonv), INTENT(OUT):: nococonv
Daniel Wortmann's avatar
Daniel Wortmann committed
82 83 84 85 86 87 88 89 90 91
    type(t_enparaXML)::enparaXML
    TYPE(t_forcetheo_data)::forcetheo_data


    INTEGER, ALLOCATABLE          :: xmlElectronStates(:,:)
    INTEGER, ALLOCATABLE          :: atomTypeSpecies(:)
    INTEGER, ALLOCATABLE          :: speciesRepAtomType(:)
    REAL, ALLOCATABLE             :: xmlCoreOccs(:,:,:)
    LOGICAL, ALLOCATABLE          :: xmlPrintCoreStates(:,:)
    !     .. Local Scalars ..
92
    INTEGER    :: i,n,l,m1,m2,isym,iisym,numSpecies,pc,iAtom,iType,minneigd
Daniel Wortmann's avatar
Daniel Wortmann committed
93 94 95 96 97 98 99
    COMPLEX    :: cdum
    CHARACTER(len=4)              :: namex
    CHARACTER(len=12)             :: relcor, tempNumberString
    CHARACTER(LEN=20)             :: filename
    REAL                          :: a1(3),a2(3),a3(3)
    REAL                          :: dtild, phi_add
    LOGICAL                       :: l_found, l_kpts, l_exist, l_krla
100

101
#ifdef CPP_MPI
Daniel Wortmann's avatar
Daniel Wortmann committed
102 103 104 105
    INCLUDE 'mpif.h'
    INTEGER ierr(3)
    CALL MPI_COMM_RANK (mpi%mpi_comm,mpi%irank,ierr)
    CALL MPI_COMM_SIZE (mpi%mpi_comm,mpi%isize,ierr)
106
#else
Daniel Wortmann's avatar
Daniel Wortmann committed
107
    mpi%irank=0 ; mpi%isize=1; mpi%mpi_comm=1
108
#endif
109

Daniel Wortmann's avatar
Daniel Wortmann committed
110
    CALL check_command_line()
Daniel Wortmann's avatar
Daniel Wortmann committed
111
#ifdef CPP_HDF
Daniel Wortmann's avatar
Daniel Wortmann committed
112
    CALL hdf_init()
Daniel Wortmann's avatar
Daniel Wortmann committed
113
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
114 115 116 117 118 119 120 121 122 123
    IF (mpi%irank.EQ.0) THEN
       CALL startFleur_XMLOutput()
       IF (judft_was_argument("-info")) THEN
          CLOSE(6)
          OPEN (6,status='SCRATCH')
       ELSE
          IF (.not.judft_was_argument("-no_out")) &
               OPEN (6,file='out',form='formatted',status='unknown')
       ENDIF
       CALL writeOutHeader()
124
       !this should be removed, it deletes output of old inf file
Daniel Wortmann's avatar
Daniel Wortmann committed
125 126 127 128
       OPEN (16,status='SCRATCH')
    ENDIF

    ALLOCATE(t_xcpot_inbuild::xcpot)
129
    !Only PE==0 reads the input and does basic postprocessing
Daniel Wortmann's avatar
Daniel Wortmann committed
130
    IF (mpi%irank.EQ.0) THEN
131
      CALL fleurinput_read_xml(cell,sym,atoms,input,noco,vacuum,field,&
Matthias Redies's avatar
Matthias Redies committed
132
                              sliceplot,banddos,mpinp,hybinp,oneD,coreSpecInput,&
133
                              wann,xcpot,forcetheo_data,kpts,enparaXML,gfinp,hub1inp)
134
      call fleurinput_postprocess(Cell,Sym,Atoms,Input,Noco,Vacuum,&
135
      Banddos,Oned,Xcpot,Kpts,gfinp)
Daniel Wortmann's avatar
Daniel Wortmann committed
136
    END IF
137 138
    !Distribute input to all PE
    CALL fleurinput_mpi_bc(Cell,Sym,Atoms,Input,Noco,Vacuum,Field,&
Matthias Redies's avatar
Matthias Redies committed
139
         Sliceplot,Banddos,mpinp,hybinp,Oned,Corespecinput,Wann,&
140
         Xcpot,Forcetheo_data,Kpts,Enparaxml,gfinp,hub1inp,Mpi%Mpi_comm)
141
    !Remaining init is done using all PE
142 143
    call nococonv%init(noco)
    call nococonv%init_ss(noco,atoms)
Matthias Redies's avatar
Matthias Redies committed
144
    CALL ylmnorm_init(max(atoms%lmaxd, 2*hybinp%lexp))
145
    CALL gaunt_init(atoms%lmaxd+1)
146
    CALL enpara%init_enpara(atoms,input%jspins,input%film,enparaXML)
147
    CALL make_sphhar(mpi%irank==0,atoms,sphhar,sym,cell,oneD)
148 149
    CALL make_stars(stars,sym,atoms,vacuum,sphhar,input,cell,xcpot,oneD,noco,mpi)
    call make_forcetheo(forcetheo_data,cell,sym,atoms,forcetheo)
150
    call lapw_dim(kpts,cell,input,noco,nococonv,oneD,forcetheo,atoms)
Matthias Redies's avatar
Matthias Redies committed
151
    call input%init(noco,hybinp%l_hybrid,lapw_dim_nbasfcn)
152
    call oned%init(atoms) !call again, because make_stars modified it :-)
Matthias Redies's avatar
Matthias Redies committed
153
    call kpts%init(cell, sym, input%film)
Matthias Redies's avatar
Matthias Redies committed
154
    call hybinp%init(atoms, cell, input, oneD, sym, xcpot)
155 156 157
    ! Store structure data
    CALL storeStructureIfNew(input,stars, atoms, cell, vacuum, oneD, sym, mpi,sphhar,noco)
    CALL prp_xcfft(stars,input,cell,xcpot)
Daniel Wortmann's avatar
Daniel Wortmann committed
158
    CALL convn(mpi%irank==0,atoms,stars)
159 160
    if (mpi%irank==0) CALL e_field(atoms,stars,sym,vacuum,cell,input,field%efield)
    if (mpi%isize>1) call field%mpi_bc(mpi%mpi_comm,0)
161

162 163 164
    !At some point this should be enabled for noco as well
    IF (.not.noco%l_noco) &
    CALL transform_by_moving_atoms(mpi,stars,atoms,vacuum, cell, sym, sphhar,input,oned,noco)
Daniel Wortmann's avatar
Daniel Wortmann committed
165 166 167 168 169


    IF (mpi%irank.EQ.0) THEN
       CALL w_inpXML(&
            atoms,vacuum,input,stars,sliceplot,forcetheo,banddos,&
Matthias Redies's avatar
Matthias Redies committed
170
            cell,sym,xcpot,noco,oneD,mpinp,hybinp,kpts,enpara,&
171
            .TRUE.,[.TRUE.,.TRUE.,.TRUE.,.TRUE.])
Daniel Wortmann's avatar
Daniel Wortmann committed
172 173 174 175
    END IF
    !
    !--> determine more dimensions
    !
176

Daniel Wortmann's avatar
Daniel Wortmann committed
177 178 179 180


    IF (mpi%irank.EQ.0) THEN
       CALL writeOutParameters(mpi,input,sym,stars,atoms,vacuum,kpts,&
Matthias Redies's avatar
Matthias Redies committed
181
            oneD,hybinp,cell,banddos,sliceplot,xcpot,&
182
            noco,enpara,sphhar)
Daniel Wortmann's avatar
Daniel Wortmann committed
183 184 185 186 187
       CALL fleur_info(kpts)
       CALL deleteDensities()
    END IF

    !Finalize the MPI setup
188
    CALL setupMPI(kpts%nkpt,input%neig,mpi)
Daniel Wortmann's avatar
Daniel Wortmann committed
189 190 191 192

    !Collect some usage info
    CALL add_usage_data("A-Types",atoms%ntype)
    CALL add_usage_data("Atoms",atoms%nat)
193 194
    CALL add_usage_data("Real",sym%invs.AND..NOT.noco%l_noco&
                        .AND..NOT.(noco%l_soc.AND.atoms%n_u+atoms%n_hia.GT.0))
Daniel Wortmann's avatar
Daniel Wortmann committed
195 196 197 198
    CALL add_usage_data("Spins",input%jspins)
    CALL add_usage_data("Noco",noco%l_noco)
    CALL add_usage_data("SOC",noco%l_soc)
    CALL add_usage_data("SpinSpiral",noco%l_ss)
199
    CALL add_usage_data("PlaneWaves",lapw_dim_nvd)
Daniel Wortmann's avatar
Daniel Wortmann committed
200 201 202
    CALL add_usage_data("LOs",atoms%nlotot)
    CALL add_usage_data("nkpt", kpts%nkpt)

203
#ifdef CPP_GPU
Daniel Wortmann's avatar
Daniel Wortmann committed
204
    CALL add_usage_data("gpu_per_node",1)
205
#else
Daniel Wortmann's avatar
Daniel Wortmann committed
206
    CALL add_usage_data("gpu_per_node",0)
207
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
208

209
    CALL results%init(input,atoms,kpts,noco)
Daniel Wortmann's avatar
Daniel Wortmann committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276

    IF (mpi%irank.EQ.0) THEN
       IF(input%gw.NE.0) CALL mixing_history_reset(mpi)
       CALL setStartingDensity(noco%l_noco)
    END IF

    !new check mode will only run the init-part of FLEUR
    IF (judft_was_argument("-check")) CALL judft_end("Check-mode done",mpi%irank)
  CONTAINS
    SUBROUTINE init_wannier()
      ! Initializations for Wannier functions (start)
      IF (mpi%irank.EQ.0) THEN
         wann%l_gwf = wann%l_ms.OR.wann%l_sgwf.OR.wann%l_socgwf

         IF(wann%l_gwf) THEN
            WRITE(*,*)'running HDWF-extension of FLEUR code'
            WRITE(*,*)'with l_sgwf =',wann%l_sgwf,' and l_socgwf =',wann%l_socgwf

            IF(wann%l_socgwf.AND. .NOT.noco%l_soc) THEN
               CALL juDFT_error("set l_soc=T if l_socgwf=T",calledby="fleur_init")
            END IF

            IF((wann%l_ms.OR.wann%l_sgwf).AND..NOT.(noco%l_noco.AND.noco%l_ss)) THEN
               CALL juDFT_error("set l_noco=l_ss=T for l_sgwf.or.l_ms",calledby="fleur_init")
            END IF

            IF((wann%l_ms.OR.wann%l_sgwf).AND.wann%l_socgwf) THEN
               CALL juDFT_error("(l_ms.or.l_sgwf).and.l_socgwf",calledby="fleur_init")
            END IF

            INQUIRE(FILE=wann%param_file,EXIST=l_exist)
            IF(.NOT.l_exist) THEN
               CALL juDFT_error("where is param_file"//TRIM(wann%param_file)//"?",calledby="fleur_init")
            END IF
            OPEN (113,file=wann%param_file,status='old')
            READ (113,*) wann%nparampts,wann%scale_param
            CLOSE(113)
         ELSE
            wann%nparampts=1
            wann%scale_param=1.0
         END IF
      END IF

      ALLOCATE (wann%param_vec(3,wann%nparampts))
      ALLOCATE (wann%param_alpha(atoms%ntype,wann%nparampts))

      IF(mpi%irank.EQ.0) THEN
         IF(wann%l_gwf) THEN
            OPEN(113,file=wann%param_file,status='old')
            READ(113,*)!header
            WRITE(6,*) 'parameter points for HDWFs generation:'
            IF(wann%l_sgwf.OR.wann%l_ms) THEN
               WRITE(6,*)'      q1       ','      q2       ','      q3'
            ELSE IF(wann%l_socgwf) THEN
               WRITE(6,*)'      --       ','     phi       ','    theta'
            END IF

            DO pc = 1, wann%nparampts
               READ(113,'(3(f14.10,1x))') wann%param_vec(1,pc), wann%param_vec(2,pc), wann%param_vec(3,pc)
               wann%param_vec(:,pc) = wann%param_vec(:,pc) / wann%scale_param
               WRITE(6,'(3(f14.10,1x))') wann%param_vec(1,pc), wann%param_vec(2,pc), wann%param_vec(3,pc)
               IF(wann%l_sgwf.OR.wann%l_ms) THEN
                  iAtom = 1
                  DO iType = 1, atoms%ntype
                     phi_add = tpi_const*(wann%param_vec(1,pc)*atoms%taual(1,iAtom) +&
                          wann%param_vec(2,pc)*atoms%taual(2,iAtom) +&
                          wann%param_vec(3,pc)*atoms%taual(3,iAtom))
277
                     wann%param_alpha(iType,pc) = nococonv%alph(iType) + phi_add
Daniel Wortmann's avatar
Daniel Wortmann committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
                     iAtom = iAtom + atoms%neq(iType)
                  END DO
               END IF
            END DO

            IF(ANY(wann%param_vec(1,:).NE.wann%param_vec(1,1))) wann%l_dim(1)=.TRUE.
            IF(ANY(wann%param_vec(2,:).NE.wann%param_vec(2,1))) wann%l_dim(2)=.TRUE.
            IF(ANY(wann%param_vec(3,:).NE.wann%param_vec(3,1))) wann%l_dim(3)=.TRUE.

            CLOSE(113)

            IF(wann%l_dim(1).AND.wann%l_socgwf) THEN
               CALL juDFT_error("do not specify 1st component if l_socgwf",calledby="fleur_init")
            END IF
         END IF!(wann%l_gwf)
      END IF!(mpi%irank.EQ.0)

295
#ifdef CPP_MPI
Daniel Wortmann's avatar
Daniel Wortmann committed
296 297 298
      CALL MPI_BCAST(wann%param_vec,3*wann%nparampts,MPI_DOUBLE_PRECISION,0,MPI_COMM_WORLD,ierr)
      CALL MPI_BCAST(wann%param_alpha,atoms%ntype*wann%nparampts,MPI_DOUBLE_PRECISION,0,MPI_COMM_WORLD,ierr)
      CALL MPI_BCAST(wann%l_dim,3,MPI_LOGICAL,0,MPI_COMM_WORLD,ierr)
299 300
#endif

Daniel Wortmann's avatar
Daniel Wortmann committed
301 302 303 304
      ! Initializations for Wannier functions (end)
    END SUBROUTINE init_wannier
  END SUBROUTINE fleur_init
END MODULE m_fleur_init