LCOV - code coverage report
Current view: top level - main - mix.F90 (source / functions) Hit Total Coverage
Test: combined.info Lines: 55 77 71.4 %
Date: 2019-09-08 04:53:50 Functions: 1 1 100.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------
       2             : ! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
       3             : ! This file is part of FLEUR and available as free software under the conditions
       4             : ! of the MIT license as expressed in the LICENSE file in more detail.
       5             : !--------------------------------------------------------------------------------
       6             : MODULE m_mix
       7             : 
       8             :   !------------------------------------------------------------------------
       9             :   !  mixing of charge densities or potentials:
      10             :   !    IMIX = 0 : linear mixing                                     
      11             :   !    IMIX = 3 : Broyden's First method                            
      12             :   !    IMIX = 5 : Broyden's Second method                           
      13             :   !    IMIX = 7 : Generalized Anderson method                       
      14             :   !------------------------------------------------------------------------
      15             : 
      16             : contains
      17             : 
      18         322 :   SUBROUTINE mix_charge( field, DIMENSION,  mpi, l_writehistory,&
      19             :        stars, atoms, sphhar, vacuum, input, sym, cell, noco, &
      20             :        oneD, archiveType, xcpot, iteration, inDen, outDen, results )
      21             : 
      22             :     use m_juDFT
      23             :     use m_constants
      24             :     use m_cdn_io
      25             :     use m_stmix
      26             :     use m_broyden
      27             :     use m_qfix
      28             :     use m_types
      29             :     use m_umix
      30             :     USE m_kerker
      31             :     use m_pulay
      32             :     use m_a_pulay
      33             :     use m_types_mixvector
      34             :     USE m_distance
      35             :     use m_mixing_history
      36             :     implicit none
      37             : 
      38             :     type(t_oneD),      intent(in)    :: oneD
      39             :     type(t_input),     intent(in)    :: input
      40             :     type(t_vacuum),    intent(in)    :: vacuum
      41             :     type(t_noco),      intent(in)    :: noco
      42             :     type(t_sym),       intent(in)    :: sym
      43             :     TYPE(t_stars),TARGET,INTENT(in)  :: stars
      44             :     TYPE(t_cell),TARGET,INTENT(in)   :: cell
      45             :     TYPE(t_sphhar),TARGET,INTENT(in) :: sphhar
      46             :     type(t_field),     intent(inout) :: field
      47             :     type(t_dimension), intent(in)    :: dimension
      48             :     type(t_mpi),       intent(in)    :: mpi
      49             :     TYPE(t_atoms),TARGET,INTENT(in)  :: atoms 
      50             :     class(t_xcpot), intent(in)       :: xcpot
      51             :     type(t_potden),    intent(inout) :: outDen
      52             :     type(t_results),   intent(inout) :: results
      53             :     type(t_potden),    intent(inout) :: inDen
      54             :     integer,           intent(in)    :: archiveType, iteration
      55             :     LOGICAL,           INTENT(IN)    :: l_writehistory
      56             : 
      57             :     real                             :: fix
      58             :     type(t_potden)                   :: resDen, vYukawa
      59         644 :     TYPE(t_mixvector),ALLOCATABLE    :: sm(:), fsm(:)
      60         322 :     TYPE(t_mixvector)                :: fsm_mag
      61             :     LOGICAL                          :: l_densitymatrix
      62             :     INTEGER                          :: it,maxiter
      63             : 
      64             : 
      65         322 :     CALL timestart("Charge Density Mixing")
      66         322 :     l_densitymatrix=.FALSE.
      67         322 :     IF (atoms%n_u>0) THEN
      68          28 :        l_densitymatrix=.NOT.input%ldaulinmix
      69          28 :        IF (mpi%irank==0) CALL u_mix(input,atoms,inDen%mmpMat,outDen%mmpMat)
      70          28 :        IF (ALL(inDen%mmpMat==0.0)) THEN
      71           2 :           l_densitymatrix=.FALSE.
      72           2 :           inDen%mmpMat=outDen%mmpMat
      73           2 :           if (mpi%irank.ne.0) inden%mmpmat=0.0 
      74             :        ENDIF
      75             :     ENDIF
      76             : 
      77         322 :     CALL timestart("Reading of distances")
      78         322 :     CALL mixvector_init(mpi%mpi_comm,l_densitymatrix,oneD,input,vacuum,noco,sym,stars,cell,sphhar,atoms)
      79             : 
      80         322 :     CALL mixing_history_open(mpi,input%maxiter)
      81             : 
      82         322 :     maxiter=MERGE(1,input%maxiter,input%imix==0)
      83         322 :     CALL mixing_history(input%imix,maxiter,inden,outden,sm,fsm,it)
      84             : 
      85         322 :     CALL distance(mpi%irank,cell%vol,input%jspins,fsm(it),inDen,outDen,results,fsm_Mag)
      86         322 :     CALL timestop("Reading of distances")
      87             :  
      88             :     ! KERKER PRECONDITIONER
      89         322 :     IF( input%preconditioning_param /= 0 )  THEN 
      90           6 :        CALL timestart("Preconditioner")
      91             :        CALL kerker( field, DIMENSION, mpi, &
      92             :                     stars, atoms, sphhar, vacuum, input, sym, cell, noco, &
      93           6 :                     oneD, inDen, outDen, fsm(it) )
      94             :        !Store modified density in history
      95           6 :        CALL mixing_history_store(fsm(it))
      96           6 :        CALL timestop("Preconditioner")
      97             :     END IF
      98             :   
      99         322 :     CALL timestart("Mixing")
     100             :     !mixing of the densities
     101         322 :     SELECT CASE(input%imix)
     102             :     CASE(0)
     103           0 :        IF (mpi%irank==0) WRITE( 6, fmt='(a,f10.5,a,f10.5)' ) &
     104           0 :             'STRAIGHT MIXING: alpha=',input%alpha," spin-mixing=",MERGE(input%alpha*input%spinf,0.,input%jspins>1)
     105           0 :        CALL stmix(atoms,input,noco,fsm(it),fsm_mag,sm(it))
     106             :     CASE(3,5)
     107           0 :        CALL judft_error("Broyden 1/2 method not implemented")
     108             :     CASE(7)
     109         322 :        IF (mpi%irank==0) WRITE( 6, fmt='(a,f10.5,a,i0)' ) &
     110         161 :             'GENERALIZED ANDERSON MIXING: alpha=',input%alpha," History-length=",it-1
     111         322 :        Call broyden(input%alpha,fsm,sm)
     112             :     CASE(9)
     113           0 :        IF (mpi%irank==0) WRITE( 6, fmt='(a,f10.5,a,i0,a,i0)' ) &
     114           0 :             'PULAY MIXING: alpha=',input%alpha," History-length=",it-1,"/",input%maxiter
     115           0 :        CALL pulay(input%alpha,fsm,sm,0)
     116             :     CASE(11)
     117           0 :        IF (mpi%irank==0) WRITE( 6, fmt='(a,f10.5,a,i0,a,i0)' ) &
     118           0 :             'PERIODIC PULAY MIXING: alpha=',input%alpha," History-length=",it-1,"/",input%maxiter
     119           0 :        CALL pulay(input%alpha,fsm,sm,input%maxiter)
     120             :     CASE(13)
     121           0 :        IF (mpi%irank==0) WRITE( 6, fmt='(a,f10.5,a,i0,a,i0)' ) &
     122           0 :             'RESTARTED PULAY MIXING: alpha=',input%alpha," History-length=",it-1,"/",input%maxiter
     123           0 :        CALL pulay(input%alpha,fsm,sm,0)
     124           0 :        IF (it==input%maxiter) CALL mixing_history_limit(0) !Restarting Pulay 
     125             :     CASE(15)
     126           0 :        IF (mpi%irank==0) WRITE( 6, fmt='(a,f10.5,a,i0,a,i0)' ) &
     127           0 :             'ADAPTED PULAY MIXING: alpha=',input%alpha," History-length=",it-1,"/",input%maxiter
     128           0 :        CALL a_pulay(input%alpha,fsm,sm)
     129             :     CASE DEFAULT
     130         322 :        CALL judft_error("Unknown Mixing schema")
     131             :     END SELECT
     132         322 :     CALL timestop("Mixing")
     133             :    
     134             : 
     135         322 :     CALL timestart("Postprocessing")
     136             :     !extracte mixed density 
     137         322 :     inDen%pw=0.0;inDen%mt=0.0
     138         322 :     IF (ALLOCATED(inDen%vacz)) inden%vacz=0.0
     139         322 :     IF (ALLOCATED(inDen%vacxy)) inden%vacxy=0.0
     140         322 :     IF (ALLOCATED(inDen%mmpMat).AND.l_densitymatrix) inden%mmpMat=0.0
     141         322 :     CALL sm(it)%to_density(inDen)
     142         322 :     IF (atoms%n_u>0.AND..NOT.l_densitymatrix.AND..NOT.input%ldaulinmix) THEN
     143             :        !No density matrix was present 
     144             :        !but is now created...
     145           2 :        inden%mmpMAT=outden%mmpMat
     146           2 :        CALL mixing_history_reset(mpi)
     147           2 :        CALL mixvector_reset()
     148             :     ENDIF
     149             : 
     150         322 :     if(iteration == 1 .and. xcpot%vx_is_MetaGGA()) then 
     151           0 :        CALL mixing_history_reset(mpi)
     152           0 :        CALL mixvector_reset()
     153             :     endif
     154             : 
     155             :     !fix charge of the new density
     156         322 :     IF (mpi%irank==0) CALL qfix(mpi,stars,atoms,sym,vacuum, sphhar,input,cell,oneD,inDen,noco%l_noco,.FALSE.,.FALSE., fix)
     157             : 
     158             : 
     159             : 
     160         322 :     IF(vacuum%nvac.EQ.1) THEN
     161         240 :        inDen%vacz(:,2,:) = inDen%vacz(:,1,:)
     162         240 :        IF (sym%invs) THEN
     163         240 :           inDen%vacxy(:,:,2,:) = CONJG(inDen%vacxy(:,:,1,:))
     164             :        ELSE
     165           0 :           inDen%vacxy(:,:,2,:) = inDen%vacxy(:,:,1,:)
     166             :        END IF
     167             :     END IF
     168             : 
     169             : 
     170             :     !write out mixed density
     171         322 :     IF (mpi%irank==0) CALL writeDensity(stars,vacuum,atoms,cell,sphhar,input,sym,oneD,archiveType,CDN_INPUT_DEN_const,&
     172         161 :          1,results%last_distance,results%ef,.TRUE.,inDen)
     173             : 
     174             : #ifdef CPP_HDF
     175         322 :     IF (mpi%irank==0.and.judft_was_argument("-last_extra")) THEN
     176           0 :        CALL system("rm cdn_last.hdf")
     177             :        CALL writeDensity(stars,vacuum,atoms,cell,sphhar,input,sym,oneD,archiveType,CDN_INPUT_DEN_const,&
     178           0 :             1,results%last_distance,results%ef,.TRUE.,inDen,'cdn_last')
     179             : 
     180             :     END IF
     181             : #endif
     182             : 
     183         322 :     inDen%iter = inDen%iter + 1
     184             : 
     185         322 :     IF (l_writehistory.AND.input%imix.NE.0) CALL mixing_history_close(mpi)
     186             : 
     187         322 :     CALL timestop("Postprocessing")
     188             : 
     189         322 :     CALL timestop("Charge Density Mixing")
     190         322 :   END SUBROUTINE mix_charge
     191             :   
     192             : END MODULE m_mix

Generated by: LCOV version 1.13