mixing_history.F90 1.78 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
!--------------------------------------------------------------------------------
! 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.
!--------------------------------------------------------------------------------
MODULE m_mixing_history
  use m_types_mixvector
  implicit none
  integer:: iter_stored=0
  type(t_mixvector),allocatable::sm_store(:),fsm_store(:)
contains
  
Daniel Wortmann's avatar
Daniel Wortmann committed
13
  SUBROUTINE mixing_history(imix,maxiter,inden,outden,sm,fsm,it)
14 15
    use m_types
    implicit none
Daniel Wortmann's avatar
Daniel Wortmann committed
16
    INTEGER,INTENT(in)::imix,maxiter
17 18
    type(t_potden),intent(in)::inden,outden
    type(t_mixvector),ALLOCATABLE::sm(:),fsm(:)
Daniel Wortmann's avatar
Daniel Wortmann committed
19 20 21
    INTEGER,INTENT(out)::it

    INTEGER:: n
22 23 24 25

    if (.not.allocated(sm_store)) THEN
       allocate(sm_store(maxiter),fsm_store(maxiter))
    endif
Daniel Wortmann's avatar
Daniel Wortmann committed
26 27 28
    IF (iter_stored+1==maxiter.AND.imix.NE.9) iter_stored=0 !This is a broyden method which has to 
                                                            !be reset as soon as maxiter is reached
    it=MIN(iter_stored+1,maxiter)
29 30 31 32 33 34 35 36 37
    allocate(sm(it),fsm(it))
    CALL sm(it)%alloc()
    CALL fsm(it)%alloc()
    CALL sm(it)%from_density(inDen)
    CALL fsm(it)%from_density(outDen)
    !store the difference fsm - sm in fsm
    fsm(it) = fsm(it) - sm(it)
    do n=it-1,1,-1 !Copy from storage
       sm(n)=sm_store(n)
Daniel Wortmann's avatar
Daniel Wortmann committed
38
       fsm(n)=fsm_store(n)
39 40 41 42 43 44 45
    ENDDO
    if(iter_stored<maxiter) THEN
       iter_stored=iter_stored+1
       sm_store(:iter_stored)=sm(:iter_stored)
       fsm_store(:iter_stored)=fsm(:iter_stored)
    else
       sm_store(:maxiter-1)=sm(2:maxiter)
Daniel Wortmann's avatar
Daniel Wortmann committed
46
       fsm_store(:maxiter-1)=fsm(2:maxiter)
47 48 49 50
    endif
  end subroutine mixing_history

end MODULE m_mixing_history