fleur_init.F90 13.8 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
Cleanup  
Daniel Wortmann committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
MODULE m_fleur_init
  IMPLICIT NONE
CONTAINS
  SUBROUTINE fleur_init(mpi,&
       input,field,DIMENSION,atoms,sphhar,cell,stars,sym,noco,vacuum,forcetheo,&
       sliceplot,banddos,enpara,xcpot,results,kpts,hybrid,&
       oneD,coreSpecInput,wann)
    USE m_types
    USE m_fleurinput_read_xml
    USE m_fleurinput_mpi_bc
    USE m_judft
    USE m_juDFT_init
    USE m_init_wannier_defaults
    USE m_postprocessInput
    USE m_gen_map
    USE m_dwigner
    !USE m_gen_bz
    USE m_ylm
24
    !USE m_InitParallelProcesses
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
25 26 27 28 29 30 31 32 33 34 35 36 37
    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
38 39 40 41 42 43 44 45
    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
46
#ifdef CPP_MPI
47
    !USE m_mpi_bc_all,  ONLY : mpi_bc_all
48
#ifndef CPP_OLDINTEL
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
49
    USE m_mpi_dist_forcetheorem
Daniel Wortmann's avatar
Daniel Wortmann committed
50
#endif
51
#endif
Daniel Wortmann's avatar
Daniel Wortmann committed
52
#ifdef CPP_HDF
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
53
    USE m_hdf_tools
54
#endif
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    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
    TYPE(t_dimension),INTENT(OUT):: DIMENSION
    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
    TYPE(t_hybrid)   ,INTENT(OUT):: hybrid
    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

    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 ..
90
    INTEGER    :: i,n,l,m1,m2,isym,iisym,numSpecies,pc,iAtom,iType,minneigd
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
91 92 93 94 95 96 97
    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
98

99
#ifdef CPP_MPI
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
100 101 102 103
    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)
104
#else
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
105
    mpi%irank=0 ; mpi%isize=1; mpi%mpi_comm=1
106
#endif
107

Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
108
    CALL check_command_line()
Daniel Wortmann's avatar
Daniel Wortmann committed
109
#ifdef CPP_HDF
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
110
    CALL hdf_init()
Daniel Wortmann's avatar
Daniel Wortmann committed
111
#endif
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
112 113 114 115 116 117 118 119 120 121
    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()
122
       !this should be removed, it deletes output of old inf file
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
123 124 125 126
       OPEN (16,status='SCRATCH')
    ENDIF

    ALLOCATE(t_xcpot_inbuild::xcpot)
127
    !Only PE==0 reads the input and does basic postprocessing
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
128
    IF (mpi%irank.EQ.0) THEN
129 130 131 132
      CALL fleurinput_read_xml(cell,sym,atoms,input,noco,vacuum,field,&
      sliceplot,banddos,hybrid,oneD,coreSpecInput,wann,&
      xcpot,forcetheo_data,kpts,enparaXML)
      call fleurinput_postprocess(Cell,Sym,Atoms,Input,Noco,Vacuum,&
133
      Banddos,Oned,Xcpot,Kpts)
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
134
    END IF
135 136 137 138
    !Distribute input to all PE
    CALL fleurinput_mpi_bc(Cell,Sym,Atoms,Input,Noco,Vacuum,Field,&
         Sliceplot,Banddos,Hybrid,Oned,Corespecinput,Wann,&
         Xcpot,Forcetheo_data,Kpts,Enparaxml,Mpi%Mpi_comm)
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
139

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    !Remaining init is done using all PE
    CALL ylmnorm_init(atoms%lmaxd)
    CALL enpara%init_enpara(atoms,input%jspins,input%film,enparaXML)
    CALL make_sphhar(atoms,sphhar,sym,cell,oneD)
    CALL make_stars(stars,sym,atoms,vacuum,sphhar,input,cell,xcpot,oneD,noco,mpi)
    call make_forcetheo(forcetheo_data,cell,sym,atoms,forcetheo)
    CALL lapw_dim(kpts,cell,input,noco,oneD,forcetheo,DIMENSION)
    call oned%init(atoms) !call again, because make_stars modified it :-)
    ! Store structure data
    CALL storeStructureIfNew(input,stars, atoms, cell, vacuum, oneD, sym, mpi,sphhar,noco)
    CALL prp_xcfft(stars,input,cell,xcpot)
    CALL convn(atoms,stars)
    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)
    ! Initialize missing hybrid functionals arrays
    ALLOCATE (hybrid%nindx(0:atoms%lmaxd,atoms%ntype))

    !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
Cleanup  
Daniel Wortmann committed
160 161 162 163 164 165


    IF (mpi%irank.EQ.0) THEN
       CALL w_inpXML(&
            atoms,vacuum,input,stars,sliceplot,forcetheo,banddos,&
            cell,sym,xcpot,noco,oneD,hybrid,kpts,enpara,&
166
            .TRUE.,[.TRUE.,.TRUE.,.TRUE.,.TRUE.])
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
167 168 169 170 171 172 173
    END IF
    !
    !--> determine more dimensions
    !
    DIMENSION%nbasfcn = DIMENSION%nvd + atoms%nat*atoms%nlod*(2*atoms%llod+1)
    DIMENSION%lmd     = atoms%lmaxd* (atoms%lmaxd+2)
    IF (noco%l_noco) DIMENSION%nbasfcn = 2*DIMENSION%nbasfcn
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    ! Generate missing general parameters

    minNeigd = MAX(5,NINT(0.75*input%zelec) + 1)
    IF (noco%l_soc.and.(.not.noco%l_noco)) minNeigd = 2 * minNeigd
    IF (noco%l_soc.and.noco%l_ss) minNeigd=(3*minNeigd)/2
    IF ((dimension%neigd.NE.-1).AND.(dimension%neigd.LT.minNeigd)) THEN
      IF (dimension%neigd>0) THEN
        WRITE(*,*) 'numbands is too small. Setting parameter to default value.'
        WRITE(*,*) 'changed numbands (dimension%neigd) to ',minNeigd
      ENDIF
      dimension%neigd = minNeigd
    END IF
    IF(dimension%neigd.EQ.-1) THEN
      dimension%neigd = dimension%nvd + atoms%nlotot
    END IF
    IF (noco%l_noco) dimension%neigd = 2*dimension%neigd
#ifdef CPP_MPI
    CALL MPI_BCAST(dimension%neigd,1,MPI_INTEGER,0,mpi%mpi_comm,ierr)
    CALL MPI_BCAST(dimension%nbasfcn,1,MPI_INTEGER,0,mpi%mpi_comm,ierr)
    CALL MPI_BCAST(dimension%nv2d,1,MPI_INTEGER,0,mpi%mpi_comm,ierr)
    CALL MPI_BCAST(dimension%nvd,1,MPI_INTEGER,0,mpi%mpi_comm,ierr)
#endif
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
196 197 198 199 200 201 202 203 204 205 206


    IF (mpi%irank.EQ.0) THEN
       CALL writeOutParameters(mpi,input,sym,stars,atoms,vacuum,kpts,&
            oneD,hybrid,cell,banddos,sliceplot,xcpot,&
            noco,DIMENSION,enpara,sphhar)
       CALL fleur_info(kpts)
       CALL deleteDensities()
    END IF

    !Finalize the MPI setup
207
    CALL setupMPI(kpts%nkpt,dimension%neigd,mpi)
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
208 209 210 211 212 213 214 215 216 217 218 219 220

    !Collect some usage info
    CALL add_usage_data("A-Types",atoms%ntype)
    CALL add_usage_data("Atoms",atoms%nat)
    CALL add_usage_data("Real",sym%invs.AND..NOT.noco%l_noco)
    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)
    CALL add_usage_data("PlaneWaves",DIMENSION%nvd)
    CALL add_usage_data("LOs",atoms%nlotot)
    CALL add_usage_data("nkpt", kpts%nkpt)

Daniel Wortmann's avatar
Daniel Wortmann committed
221
#ifdef CPP_GPU
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
222
    CALL add_usage_data("gpu_per_node",1)
Daniel Wortmann's avatar
Daniel Wortmann committed
223
#else
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
224
    CALL add_usage_data("gpu_per_node",0)
Daniel Wortmann's avatar
Daniel Wortmann committed
225
#endif
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354

    CALL results%init(DIMENSION,input,atoms,kpts,noco)

    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_hybrid()
      IF (xcpot%is_hybrid().OR.input%l_rdmft) THEN
         IF (input%film.OR.oneD%odi%d1) THEN
            CALL juDFT_error("2D film and 1D calculations not implemented for HF/EXX/PBE0/HSE", &
                 calledby ="fleur", hint="Use a supercell or a different functional")
         END IF

         !             IF( ANY( atoms%l_geo  ) )&
         !                  &     CALL juDFT_error("Forces not implemented for HF/PBE0/HSE ",&
         !                  &                    calledby ="fleur")

         !calculate whole Brilloun zone
         !CALL gen_bz(kpts,sym)
         CALL gen_map(atoms,sym,oneD,hybrid)

         ! calculate d_wgn
         ALLOCATE (hybrid%d_wgn2(-atoms%lmaxd:atoms%lmaxd,-atoms%lmaxd:atoms%lmaxd,0:atoms%lmaxd,sym%nsym))
         CALL d_wigner(sym%nop,sym%mrot,cell%bmat,atoms%lmaxd,hybrid%d_wgn2(:,:,1:,:sym%nop))
         hybrid%d_wgn2(:,:,0,:) = 1

         DO isym = sym%nop+1,sym%nsym
            iisym = isym - sym%nop
            DO l = 0,atoms%lmaxd
               DO m2 = -l,l
                  DO m1 = -l,-1
                     cdum                  = hybrid%d_wgn2( m1,m2,l,iisym)
                     hybrid%d_wgn2( m1,m2,l,isym) = hybrid%d_wgn2(-m1,m2,l,iisym)*(-1)**m1
                     hybrid%d_wgn2(-m1,m2,l,isym) = cdum                  *(-1)**m1
                  END DO
                  hybrid%d_wgn2(0,m2,l,isym) = hybrid%d_wgn2(0,m2,l,iisym)
               END DO
            END DO
         END DO
      ELSE
         hybrid%l_calhf = .FALSE.
         ALLOCATE(hybrid%map(0,0),hybrid%tvec(0,0,0),hybrid%d_wgn2(0,0,0,0))
         IF(input%l_rdmft) THEN
            hybrid%l_calhf = .FALSE.
         END IF
      ENDIF
    END SUBROUTINE init_hybrid

    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))
                     wann%param_alpha(iType,pc) = noco%alph(iType) + phi_add
                     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)

355
#ifdef CPP_MPI
Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
356 357 358
      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)
359 360
#endif

Daniel Wortmann's avatar
Cleanup  
Daniel Wortmann committed
361 362 363 364
      ! Initializations for Wannier functions (end)
    END SUBROUTINE init_wannier
  END SUBROUTINE fleur_init
END MODULE m_fleur_init