Commit be8b5d14 authored by Henning Janssen's avatar Henning Janssen

Added error message when density matrix (LDA+U) starts to make no sense after mixing

parent a984d6a3
......@@ -27,6 +27,7 @@ contains
use m_qfix
use m_types
use m_umix
use m_checkMMPmat
USE m_kerker
use m_pulay
use m_a_pulay
......@@ -155,14 +156,22 @@ contains
CALL mixvector_reset()
ENDIF
IF(atoms%n_hia>0) THEN
!For LDA+HIA we don't use any mixing of the density matrices we just pass it on
inDen%mmpMat(:,:,indStartHIA:indEndHIA,:) = outDen%mmpMat(:,:,indStartHIA:indEndHIA,:)
IF(atoms%n_u>0.AND.l_densitymatrix.AND.mpi%irank.EQ.0) THEN
!When the mixing of the density matrix is done together
!with the charge density depending on the mixing scheme
!it can become unstable
!Check whether the mixed density matrix makes sense
CALL checkMMPmat(1,atoms%n_u,atoms,input,inden%mmpMat)
ENDIF
IF (atoms%n_hia>0.AND.l_runhia) THEN
CALL mixing_history_reset(mpi)
CALL mixvector_reset()
IF(atoms%n_hia>0) THEN
!For LDA+HIA we don't use any mixing of the density matrices we just pass it on
inDen%mmpMat(:,:,indStartHIA:indEndHIA,:) = outDen%mmpMat(:,:,indStartHIA:indEndHIA,:)
IF(l_runhia) THEN
CALL mixing_history_reset(mpi)
CALL mixvector_reset()
ENDIF
ENDIF
if(iteration == 1 .and. xcpot%vx_is_MetaGGA()) then
......
......@@ -16,4 +16,5 @@ mix/a_pulay.F90
mix/potdis.f90
mix/stdmix.f90
mix/u_mix.f90
mix/checkMMPmat.f90
)
MODULE m_checkMMPmat
!Check whether the given density matrix makes sense (only diagonal)
USE m_types
USE m_juDFT
USE m_constants
IMPLICIT NONE
CONTAINS
SUBROUTINE checkMMPmat(indStart,indEnd,atoms,input,mmpmat)
INTEGER, INTENT(IN) :: indStart, indEnd
TYPE(t_atoms), INTENT(IN) :: atoms
TYPE(t_input), INTENT(IN) :: input
COMPLEX, INTENT(IN) :: mmpmat(-lmaxU_const:,-lmaxU_const:,:,:)
!which elements are considered to cause an error
REAL, PARAMETER :: lowBound = -0.01
REAL, PARAMETER :: highBound = 1.01 !Attention keep in mind jspins=1
LOGICAL l_err
INTEGER i_u,l,ispin,m
REAL spindeg
spindeg = 3-input%jspins
l_err = .FALSE.
DO i_u = indStart, indEnd
l = atoms%lda_u(i_u)%l
!Check the diagonal elements
DO ispin = 1, input%jspins
DO m = -l,l
IF(REAL(mmpmat(m,m,i_u,ispin)).LT.lowBound.OR. &
REAL(mmpmat(m,m,i_u,ispin)).GT.highBound*spindeg) THEN
l_err = .TRUE.
ENDIF
ENDDO
ENDDO
ENDDO
IF(l_err) THEN
WRITE(*,*) "-----------------------------------------------------------------"
WRITE(*,*) "Using the Quasi-Newton methods for mixing and LDA+U"
WRITE(*,*) "from the beginning of the SCF calculaion can be unstable."
WRITE(*,*) "You can reset the mixing_history, use straight mixing for "
WRITE(*,*) "the first iterations or use linear mixing for the density matrix"
WRITE(*,*) "-----------------------------------------------------------------"
CALL juDFT_error("Invalid elements in mmpmat", calledby="checkMMPmat")
ENDIF
END SUBROUTINE checkMMPmat
END MODULE m_checkMMPmat
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment