LCOV - code coverage report
Current view: top level - mix - mixing_history.F90 (source / functions) Hit Total Coverage
Test: combined.info Lines: 52 62 83.9 %
Date: 2019-09-08 04:53:50 Functions: 5 6 83.3 %

          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_mixing_history
       7             :   USE m_types_mixvector
       8             :   IMPLICIT NONE
       9             :   PRIVATE
      10             :   INTEGER:: iter_stored=0
      11             :   TYPE(t_mixvector),ALLOCATABLE::sm_store(:),fsm_store(:)
      12             :   PUBLIC :: mixing_history,mixing_history_reset,mixing_history_store
      13             :   PUBLIC :: mixing_history_open,mixing_history_close,mixing_history_limit
      14             : CONTAINS
      15             :   
      16         322 :   SUBROUTINE mixing_history_open(mpi,maxiter)
      17             :     USE m_types,ONLY:t_mpi
      18             :     INTEGER,INTENT(IN)    :: maxiter
      19             :     TYPE(t_mpi),INTENT(in):: mpi
      20             :     
      21             :     CHARACTER(len=20):: filename
      22             :     LOGICAL          :: l_fileexist
      23             :     INTEGER          :: n
      24             : 
      25             : 
      26         642 :     IF (iter_stored>0) RETURN ! History in memory found, no need to do IO
      27          50 :     IF (mpi%isize>1) THEN
      28          50 :        WRITE(filename,'(a,i0)') "mixing_history.",mpi%irank
      29             :     ELSE
      30           0 :        filename="mixing_history"
      31             :     ENDIF
      32          50 :     INQUIRE(file=filename,exist=l_fileexist)
      33          50 :     IF (.NOT.l_fileexist) RETURN !No previous data
      34             : #ifdef __PGI
      35             :     PRINT *,"Warning PGI compiler does not support reading of history"
      36             : #else
      37           2 :     OPEN(888,file=filename,status='old',form='unformatted')
      38           2 :     READ(888) iter_stored
      39           2 :     IF (.NOT.ALLOCATED(sm_store)) ALLOCATE(sm_store(maxiter),fsm_store(maxiter))
      40          26 :     DO n=1,MIN(iter_stored,maxiter)
      41          24 :        READ(888) sm_store(n)
      42          26 :        READ(888) fsm_store(n)
      43             :     ENDDO
      44           2 :     CLOSE(888)
      45             : #endif    
      46             :   END SUBROUTINE mixing_history_open
      47             : 
      48          48 :   SUBROUTINE mixing_history_close(mpi)
      49             :     USE m_types,ONLY:t_mpi
      50             :     TYPE(t_mpi),INTENT(in):: mpi
      51             :     
      52             :     CHARACTER(len=20):: filename
      53             :     INTEGER          :: n
      54             : 
      55             : 
      56          50 :     IF (iter_stored==0) RETURN ! Nothing found to be stored
      57          46 :     IF (mpi%isize>1) THEN
      58          46 :        WRITE(filename,'(a,i0)') "mixing_history.",mpi%irank
      59             :     ELSE
      60           0 :        filename="mixing_history"
      61             :     ENDIF
      62          46 :     OPEN(888,file=filename,form='unformatted',status='replace')
      63          46 :     WRITE(888) iter_stored
      64         364 :     DO n=1,iter_stored
      65         318 :        WRITE(888) sm_store(n)
      66         364 :        WRITE(888) fsm_store(n)
      67             :     ENDDO
      68          46 :     CLOSE(888)
      69          46 :     DEALLOCATE(sm_store,fsm_store)
      70          46 :     iter_stored=0
      71             :   END SUBROUTINE mixing_history_close
      72             :     
      73             :   
      74         322 :   SUBROUTINE mixing_history(imix,maxiter,inden,outden,sm,fsm,it)
      75             :     USE m_types
      76             :     implicit none
      77             :     INTEGER,INTENT(in)::imix,maxiter
      78             :     type(t_potden),intent(inout)::inden,outden
      79             :     type(t_mixvector),ALLOCATABLE::sm(:),fsm(:)
      80             :     INTEGER,INTENT(out)::it
      81             : 
      82             :     INTEGER:: n
      83             : 
      84         322 :     if (.not.allocated(sm_store)) THEN
      85          48 :        allocate(sm_store(maxiter),fsm_store(maxiter))
      86             :     endif
      87         322 :     IF (iter_stored+1==maxiter.AND.imix<8) iter_stored=0 !This is a broyden method which has to 
      88             :                                                             !be reset as soon as maxiter is reached
      89         322 :     it=iter_stored+1
      90         322 :     allocate(sm(it),fsm(it))
      91         322 :     CALL sm(it)%alloc()
      92         322 :     CALL fsm(it)%alloc()
      93         322 :     CALL sm(it)%from_density(inDen)
      94         322 :     CALL fsm(it)%from_density(outDen)
      95             :     !store the difference fsm - sm in fsm
      96         322 :     fsm(it) = fsm(it) - sm(it)
      97        2808 :     do n=1,it-1 !Copy from storage
      98        2486 :        sm(n)=sm_store(n)
      99        2808 :        fsm(n)=fsm_store(n)
     100             :     ENDDO
     101         322 :     if(iter_stored<maxiter) THEN
     102         322 :        iter_stored=iter_stored+1
     103         322 :        sm_store(iter_stored)=sm(iter_stored)
     104         322 :        fsm_store(iter_stored)=fsm(iter_stored)
     105             :     else
     106           0 :        sm_store(:maxiter)=sm(2:maxiter+1)
     107           0 :        fsm_store(:maxiter)=fsm(2:maxiter+1)
     108             :     endif
     109         322 :   end subroutine mixing_history
     110             : 
     111           4 :   SUBROUTINE mixing_history_reset(mpi)
     112             :     USE m_types,ONLY:t_mpi
     113             :     IMPLICIT NONE
     114             :     TYPE(t_mpi),INTENT(in)::mpi
     115           4 :     iter_stored=0
     116           4 :     PRINT *, "Reset of history"
     117           4 :     IF (mpi%irank==0) CALL system('rm -f mixing_history*')
     118           4 :   END SUBROUTINE mixing_history_reset
     119             : 
     120           0 :   subroutine mixing_history_limit(len)
     121             :     IMPLICIT NONE
     122             :     INTEGER,INTENT(in)::len
     123             : 
     124           0 :     if (iter_stored>len) then
     125           0 :        fsm_store(:len)=fsm_store(iter_stored-len+1:iter_stored)
     126           0 :        sm_store(:len)=sm_store(iter_stored-len+1:iter_stored)
     127           0 :        iter_stored=len
     128             :     end if
     129           0 :   end subroutine mixing_history_limit
     130             :   
     131           6 :   SUBROUTINE mixing_history_store(fsm)
     132             :     IMPLICIT NONE
     133             :     TYPE(t_mixvector),INTENT(IN)::fsm
     134           6 :     IF (iter_stored>0) fsm_store(iter_stored)=fsm
     135           6 :   END SUBROUTINE mixing_history_store
     136             : end MODULE m_mixing_history

Generated by: LCOV version 1.13