LEVELS_mirror.F Source File


Source Code

!
! License-Identifier: GPL
!
! Copyright (C) 2024 The Yambo Team
!
! Authors (see AUTHORS file for details): AM, CA, DS
!
module levels_mirror_m
  implicit none
  integer, parameter :: idx_BndsRnXx       = 1
  integer, parameter :: idx_BndsRnXs       = 2
  integer, parameter :: idx_BndsRnXd       = 3
  integer, parameter :: idx_BndsRnXp       = 4
  integer, parameter :: idx_BndsRnXm       = 5
  integer, parameter :: idx_DipBands       = 6
  integer, parameter :: idx_BSEBands       = 7
  integer, parameter :: idx_RTBands        = 8
  integer, parameter :: idx_SCBands        = 9
  integer, parameter :: idx_NLBands        = 10
  integer, parameter :: idx_COLLBands      = 11
  integer, parameter :: idx_el_photon_corr = 12
  integer, parameter :: idx_QpntsRXd       = 13
  integer, parameter :: idx_QpntsRXs       = 14
  integer, parameter :: idx_QpntsRXx       = 15
  integer, parameter :: idx_BSEQptR        = 16
  !
  integer, parameter :: num_user_fields    = 16
  !
end module levels_mirror_m

subroutine LEVELS_get_user_fields(l_USER_field)
  use levels_mirror_m, ONLY: num_user_fields
  use parser_m,        ONLY: parser
  implicit none
  logical, intent(out) :: l_USER_field(num_user_fields)

  l_USER_field = .false.

  call parser('BndsRnXx', l_USER_field(1))
  call parser('BndsRnXs', l_USER_field(2))
  call parser('BndsRnXd', l_USER_field(3))
  call parser('BndsRnXp', l_USER_field(4))
  call parser('BndsRnXm', l_USER_field(5))
  call parser('DipBands', l_USER_field(6))
  call parser('BSEBands', l_USER_field(7))
  call parser('RTBands',  l_USER_field(8))
  call parser('SCBands',  l_USER_field(9))
  call parser('NLBands',  l_USER_field(10))
  call parser('COLLBands',l_USER_field(11))
  call parser('el_photon_corr',l_USER_field(12))
  if (l_USER_field(12)) call parser('life',l_USER_field(12))
  call parser('QpntsRXd',l_USER_field(13))
  call parser('QpntsRXs',l_USER_field(14))
  call parser('QpntsRXx',l_USER_field(15))
  call parser('BSEQptR', l_USER_field(16))
end subroutine LEVELS_get_user_fields

subroutine LEVELS_mirror_q(l_USER_field, X, Dip)
  use levels_mirror_m, ONLY: num_user_fields, idx_QpntsRXd, idx_QpntsRXs, idx_QpntsRXx, idx_BSEQptR
  use X_m,             ONLY: X_t
  use DIPOLES,         ONLY: DIPOLE_t
  use it_tools,        ONLY: runlevel_is_on
  use BS,              ONLY: BS_q
  implicit none
  logical, intent(in)           :: l_USER_field(num_user_fields)
  type(X_t), intent(in)         :: X(5)
  type(DIPOLE_t), intent(inout) :: Dip

  ! Q's
  !-----
  if (l_USER_field(idx_QpntsRXd).and.runlevel_is_on('optics')) Dip%iq=X(3)%iq
  if (l_USER_field(idx_QpntsRXd).and.runlevel_is_on('em1d')  ) Dip%iq=X(3)%iq
  if (l_USER_field(idx_QpntsRXd).and.runlevel_is_on('ppa')   ) Dip%iq=X(4)%iq
  if (l_USER_field(idx_QpntsRXd).and.runlevel_is_on('mpa')   ) Dip%iq=X(5)%iq
  if (l_USER_field(idx_QpntsRXs)                             ) Dip%iq=X(2)%iq
  if (l_USER_field(idx_QpntsRXx)                             ) Dip%iq=X(1)%iq
  if (l_USER_field(idx_BSEQptR)) then
    if(.not.(runlevel_is_on('ppa').or.runlevel_is_on('em1s').or.runlevel_is_on('mpa'))) Dip%iq=BS_q
  endif
end subroutine LEVELS_mirror_q

subroutine LEVELS_mirror_bands(E, X, Dip, l_USER_field)
  use levels_mirror_m, ONLY: num_user_fields, &
    idx_BndsRnXx, idx_BndsRnXs, idx_BndsRnXd, idx_BndsRnXp, idx_BndsRnXm, &
    idx_DipBands, idx_BSEBands, idx_RTBands, idx_SCBands, idx_NLBands, &
    idx_COLLBands, idx_el_photon_corr
  use electrons,     ONLY: levels
  use X_m,           ONLY: X_t
  use DIPOLES,       ONLY: DIPOLE_t
  use BS,            ONLY: BS_bands
  use QP_m,          ONLY: QP_n_G_bands
#if defined _SC 
  use SC,            ONLY: SC_bands,SC_bands_frozen
#endif
#if defined _RT || defined _QED || defined _NL
  use real_time,     ONLY: RT_bands,RT_bands_frozen
#endif
#if defined _SC || defined _RT || defined _QED || defined _NL
  use collision_ext, ONLY: COLL_bands,COLL_bands_frozen
  use hamiltonian,   ONLY: H_ref_bands,H_ref_bands_frozen
#endif
#if defined _NL
  use nl_optics,      ONLY: NL_bands,NL_bands_frozen
#endif

  implicit none

  type(levels)   :: E
  type(DIPOLE_t) :: Dip
  type(X_t)      :: X(5) 
  logical        :: l_USER_field(num_user_fields), dip_bands_defined

  integer :: i1, SCATT_bands(2), SCATT_hole_bands(2), DIP_bands(2)
  logical :: SCATT_bands_frozen(E%nb)

  ! Bands (Electronic levels)
  !---------------------------
  SCATT_bands = -1
  SCATT_bands_frozen = .false.
  do i1 = idx_RTBands, idx_el_photon_corr
    if (.not.(l_USER_field(i1))) cycle
    call set_scatt_bands(i1)
  enddo
  !
  ! Bands (Dipoles)
  !----------------
  DIP_bands = -1
  dip_bands_defined = .false.
  ! Start from input if present
  if (l_USER_field(idx_DipBands)) call def_dip_bands(Dip%ib)
  !
  ! Test scatt bands
  if( all((/SCATT_bands /= -1/))) call def_dip_bands(SCATT_bands)
  !
  ! Test other fields
  do i1 = idx_BndsRnXx, idx_BndsRnXm
    if (.not.(l_USER_field(i1))) cycle
    call def_dip_bands(X(i1)%ib)
  enddo
  !
  if (l_USER_field(idx_BSEBands)) call def_dip_bands(BS_bands)
#if defined _RT || defined _QED || defined _NL
  if (l_USER_field(idx_RTBands)) call def_dip_bands(RT_bands)
#endif
#if defined _NL
  if (l_USER_field(idx_NLBands)) call def_dip_bands(NL_bands)
#endif
  !
  ! Any negative bands?
  !---------------------
  call fix_me(SCATT_bands)
  call fix_me(DIP_bands)
  !
  ! Now MIRROR in related bands ranges
  !------------------------------------
#if defined _SC || defined _RT || defined _QED || defined _NL
  COLL_bands = SCATT_bands
  COLL_bands_frozen = SCATT_bands_frozen
  H_ref_bands = SCATT_bands     
  H_ref_bands_frozen = SCATT_bands_frozen
#endif
  Dip%ib = DIP_bands

contains

  subroutine set_scatt_bands(i1)
    integer, intent(in) :: i1
#if defined _RT || defined _QED || defined _NL
    if (i1 == idx_RTBands) then
      SCATT_bands = RT_bands
      SCATT_bands_frozen = RT_bands_frozen
    endif
#endif
#if defined _SC
    if (i1 == idx_SCBands) SCATT_bands = SC_bands
#endif
#if defined _NL
    if (i1 == idx_NLBands) then
      SCATT_bands = NL_bands
      SCATT_bands_frozen = NL_bands_frozen
    endif
#endif
#if defined _SC 
    if (i1 == idx_COLLBands) then
      SC_bands = COLL_bands
      SCATT_bands = COLL_bands
    endif
#endif
#if defined _RT || defined _QED || defined _NL
    if (i1 == idx_COLLBands) then
      RT_bands = COLL_bands
      RT_bands_frozen = COLL_bands_frozen
      SCATT_bands = COLL_bands
      SCATT_bands_frozen = COLL_bands_frozen
    endif
#endif
#if defined _QED
    if (i1 == idx_el_photon_corr) SCATT_bands = QP_n_G_bands
#endif
  end subroutine set_scatt_bands

  subroutine fix_me(bands)
    integer :: bands(2)
    if (bands(2)>E%nb) call error("Number of bands in input larger than bands available")
    if (bands(1)<=0) bands(1)=1
    if (bands(2)<=0) bands(2)=E%nb
  end subroutine fix_me

  subroutine def_dip_bands(bands_in)
    integer, intent(in) :: bands_in(2)
    if (dip_bands_defined) then
      DIP_bands(1) = min(DIP_bands(1), bands_in(1))
      DIP_bands(2) = max(DIP_bands(2), bands_in(2))
    else
      dip_bands_defined = .true.
      DIP_bands = bands_in
    endif
  end subroutine def_dip_bands

end subroutine LEVELS_mirror_bands
!
!
subroutine LEVELS_frozen(en)
 !
 use electrons,     ONLY:levels
 use BS,            ONLY:BS_bands,BS_bands_frozen,BS_bands_frozen_ch
#if defined _SC 
 use SC,            ONLY:SC_bands,SC_bands_frozen,SC_bands_frozen_ch
#endif
#if defined _RT || defined _QED || defined _NL
 use real_time,     ONLY:RT_bands,RT_bands_frozen,RT_bands_frozen_ch
#endif
#if defined _SC || defined _RT || defined _QED || defined _NL
 use collision_ext, ONLY:COLL_bands,COLL_bands_frozen,COLL_bands_frozen_ch
 use hamiltonian,   ONLY:H_ref_bands,H_ref_bands_frozen
#endif
#if defined _NL
 use nl_optics,      ONLY:NL_bands,NL_bands_frozen,NL_bands_frozen_ch
#endif
 !
 implicit none
 !
 type(levels), intent(in) :: en          
 !
 if(allocated(BS_bands_frozen)) deallocate(BS_bands_frozen)
 allocate(BS_bands_frozen(BS_bands(1):BS_bands(2)))
 call LEVELS_frozen_local(BS_bands,BS_bands_frozen,BS_bands_frozen_ch,"BSE",BS_bands(2)-BS_bands(1)+1)
 !
#if defined _SC || defined _RT || defined _NL
 if(allocated(H_ref_bands_frozen)) deallocate(H_ref_bands_frozen)
 allocate(H_ref_bands_frozen(en%nb))
 H_ref_bands_frozen=0
 if(allocated(COLL_bands_frozen)) deallocate(COLL_bands_frozen)
 allocate(COLL_bands_frozen(en%nb))
 call LEVELS_frozen_local((/1,COLL_bands(2)/),COLL_bands_frozen,COLL_bands_frozen_ch,"COLL",en%nb)
#endif
#if defined _RT
 if(allocated(RT_bands_frozen)) deallocate(RT_bands_frozen)
 allocate(RT_bands_frozen(en%nb))
 call LEVELS_frozen_local((/1,RT_bands(2)/),RT_bands_frozen,RT_bands_frozen_ch,"RT",en%nb)
#endif
#if defined _SC
 if(allocated(SC_bands_frozen)) deallocate(SC_bands_frozen)
 allocate(SC_bands_frozen(en%nb))
 call LEVELS_frozen_local((/1,SC_bands(2)/),SC_bands_frozen,SC_bands_frozen_ch,"SC",en%nb)
#endif
#if defined _NL
 if(allocated(NL_bands_frozen)) deallocate(NL_bands_frozen)
 allocate(NL_bands_frozen(en%nb))
 call LEVELS_frozen_local((/1,NL_bands(2)/),NL_bands_frozen,NL_bands_frozen_ch,"NL",en%nb)
#endif
 !
end subroutine LEVELS_frozen
!
!
subroutine LEVELS_frozen_local(TMP_bands,TMP_bands_frozen,TMP_bands_frozen_ch,TMP_kind,nb)
 !
 use pars,          ONLY:LP,schlen
 use parser_m,      ONLY:parser
 use stderr,        ONLY:STRING_split,intc
 !
 implicit none
 !
 integer,           intent(in)  :: TMP_bands(2),nb
 character(schlen), intent(in)  :: TMP_bands_frozen_ch
 character(*),      intent(in)  :: TMP_kind
 integer(LP),       intent(out) :: TMP_bands_frozen(nb)
 !
 integer :: ib1,ib2
 logical :: l_freeze_bands,started_frozen_range
 character(schlen) :: TMP_bands_frozen_list(nb)
 !
 TMP_bands_frozen=0
 !
 call parser(trim(TMP_kind)//'FrozenBands', l_freeze_bands)
 if (l_freeze_bands) then
   call STRING_split(TMP_bands_frozen_ch,TMP_bands_frozen_list)
   ib1=1
   started_frozen_range=.false.
   do ib2=TMP_bands(1),TMP_bands(2)
     !write(*,*) ib1,ib2,trim(intc(ib2))," ",trim(TMP_bands_frozen_list(ib1)),&
     !&                  trim(intc(ib2))==trim(TMP_bands_frozen_list(ib1)),started_frozen_range
     if( trim(TMP_bands_frozen_list(ib1)) == "-" ) then
       started_frozen_range=.true.
       ib1=ib1+1
     endif
     if( started_frozen_range) TMP_bands_frozen(ib2-TMP_bands(1)+1)=1
     if( .not. trim(intc(ib2))==trim(TMP_bands_frozen_list(ib1)) ) cycle
     TMP_bands_frozen(ib2-TMP_bands(1)+1)=1
     ib1=ib1+1
     started_frozen_range=.false.
   enddo
 endif
 !
end subroutine LEVELS_frozen_local

📚 Documentation Pages
⏱️ Real-Time
🔗 Code API