Commit 5a4e3145 authored by Miriam Hinzen's avatar Miriam Hinzen

Modify types_potden, vgen and mix (part 1)

in potden: introduce subroutines SpinsToChargeAndMagnetisation and ChargeAndMagnetisationToSpins
Writing preconditioned quantities to files is now substituted by passing types. This changes a lot.
parent 934aafd6
......@@ -75,7 +75,7 @@ CONTAINS
! Types, these variables contain a lot of data!
TYPE(t_input) :: input
TYPE(t_field) :: field
TYPE(t_field) :: field, field2
TYPE(t_dimension):: DIMENSION
TYPE(t_atoms) :: atoms
TYPE(t_sphhar) :: sphhar
......@@ -412,9 +412,12 @@ CONTAINS
CALL enpara%mix(mpi,atoms,vacuum,input,vTot%mt(:,0,:,:),vtot%vacz)
IF (mpi%irank.EQ.0) THEN
! ----> mix input and output densities
field2 = field
! ----> mix input and output densities
CALL timestart("mixing")
CALL mix(stars,atoms,sphhar,vacuum,input,sym,cell,noco,oneD,hybrid,archiveType,inDen,outDen,results)
CALL mix( field2, xcpot, dimension, obsolete, sliceplot, mpi, &
stars, atoms, sphhar, vacuum, input, sym, cell, noco, &
oneD, hybrid, archiveType, inDen, outDen, results )
CALL timestop("mixing")
WRITE (6,FMT=8130) it
......
......@@ -7,7 +7,7 @@ MODULE m_mix
!*************************************************************************
! mixing of charge densities or potentials:
! IMIX= 0 : linear mixing
! IMIX = 0 : linear mixing
! IMIX = 3 : BROYDEN'S FIRST METHOD
! IMIX = 5 : BROYDEN'S SECOND METHOD
! IMIX = 7 : GENERALIZED ANDERSEN METHOD
......@@ -15,8 +15,9 @@ MODULE m_mix
CONTAINS
SUBROUTINE mix(stars,atoms,sphhar,vacuum,input,sym,cell,noco,oneD,&
hybrid,archiveType,inDen,outDen,results)
SUBROUTINE mix( field, xcpot, dimension, obsolete, sliceplot, mpi, &
stars, atoms, sphhar, vacuum, input, sym, cell, noco, &
oneD, hybrid, archiveType, inDen, outDen, results )
#include"cpp_double.h"
......@@ -34,6 +35,7 @@ SUBROUTINE mix(stars,atoms,sphhar,vacuum,input,sym,cell,noco,oneD,&
USE m_types
USE m_xmlOutput
USE m_umix
use m_vgen
IMPLICIT NONE
......@@ -46,6 +48,12 @@ SUBROUTINE mix(stars,atoms,sphhar,vacuum,input,sym,cell,noco,oneD,&
TYPE(t_stars),INTENT(IN) :: stars
TYPE(t_cell),INTENT(IN) :: cell
TYPE(t_sphhar),INTENT(IN) :: sphhar
type(t_field), intent(inout) :: field
class(t_xcpot), intent(in) :: xcpot
type(t_dimension), intent(in) :: dimension
type(t_obsolete), intent(in) :: obsolete
type(t_sliceplot), intent(in) :: sliceplot
type(t_mpi), intent(in) :: mpi
TYPE(t_atoms),INTENT(INOUT) :: atoms !n_u is modified temporarily
TYPE(t_potden),INTENT(INOUT) :: outDen
TYPE(t_results),INTENT(INOUT) :: results
......@@ -54,7 +62,7 @@ SUBROUTINE mix(stars,atoms,sphhar,vacuum,input,sym,cell,noco,oneD,&
!Local Scalars
REAL fix,intfac,vacfac
INTEGER i,imap,js
INTEGER i,imap,js, n, lh
INTEGER mmap,mmaph,nmaph,nmap,mapmt,mapvac,mapvac2
INTEGER iofl,n_u_keep
LOGICAL l_exist,l_ldaU, l_densityMatrixPresent, l_pot
......@@ -65,6 +73,8 @@ SUBROUTINE mix(stars,atoms,sphhar,vacuum,input,sym,cell,noco,oneD,&
CHARACTER(LEN=20) :: attributes(2)
COMPLEX :: n_mmpTemp(-3:3,-3:3,MAX(1,atoms%n_u),input%jspins)
type(t_potden) :: resDen, resChM, vYukawa, vTot, vx
!External functions
REAL CPP_BLAS_sdot
EXTERNAL CPP_BLAS_sdot
......@@ -141,7 +151,6 @@ SUBROUTINE mix(stars,atoms,sphhar,vacuum,input,sym,cell,noco,oneD,&
END IF
!put input charge density into array sm
!(in the spin polarized case the arrays sm and fsm consist of spin up and spin down densities)
CALL brysh1(input,stars,atoms,sphhar,noco,vacuum,sym,oneD,&
intfac,vacfac,inDen,nmap,nmaph,mapmt,mapvac,mapvac2,sm)
......@@ -153,6 +162,30 @@ SUBROUTINE mix(stars,atoms,sphhar,vacuum,input,sym,cell,noco,oneD,&
!store the difference fsm - sm in fsm
fsm(:nmap) = fsm(:nmap) - sm(:nmap)
! preconditioning section
if( input%preconditioning_param /= 0 ) then
resDen = inDen
call brysh2( input, stars, atoms, sphhar, noco, vacuum, sym, fsm, oneD, resDen )
if( input%jspins == 2 ) call resDen%SpinsToChargeAndMagnetisation( resChM )
call vYukawa%init( stars, atoms, sphhar, vacuum, input%jspins, noco%l_noco, 1 )
call vTot%init( stars, atoms, sphhar, vacuum, input%jspins, noco%l_noco, 1 )
call vx%init( stars, atoms, sphhar, vacuum, input%jspins, .false., 1 )
call vgen( hybrid, field, input, xcpot, DIMENSION, atoms, sphhar, stars, vacuum, &
sym, obsolete, cell, oneD, sliceplot, mpi, results, noco, .false., inDen, vTot, vx, &
vYukawa )
resDen%pw(1:stars%ng3,1) = resDen%pw(1:stars%ng3,1) - input%preconditioning_param ** 2 / fpi_const * vYukawa%pw(1:stars%ng3,1)
do n = 1, atoms%ntype
do lh = 0, sphhar%nlhd
resDen%mt(1:atoms%jri(n),lh,n,1) = resDen%mt(1:atoms%jri(n),lh,n,1) &
- input%preconditioning_param ** 2 / fpi_const &
* vYukawa%mt(1:atoms%jri(n),lh,n,1) * atoms%rmsh(1:atoms%jri(n),n) ** 2
end do
end do
end if
! end of preconditioning section
if( input%jspins == 2 ) call resChM%ChargeAndMagnetisationToSpins( resDen )
l_pot = .FALSE.
! Apply metric w to fsm and store in fmMet: w |fsm>
CALL metric(cell,atoms,vacuum,sphhar,input,noco,stars,sym,oneD,&
......
......@@ -35,6 +35,8 @@ MODULE m_types_potden
GENERIC :: init=>init_potden_types,init_potden_simple
PROCEDURE :: copy_both_spin
PROCEDURE :: sum_both_spin
procedure :: SpinsToChargeAndMagnetisation
procedure :: ChargeAndMagnetisationToSpins
END TYPE t_potden
CONTAINS
......@@ -88,7 +90,39 @@ CONTAINS
IF (ALLOCATED(that%pw_w).AND.ALLOCATED(this%pw_w)) that%pw_w(:,2)=this%pw_w(:,1)
END IF
END SUBROUTINE copy_both_spin
subroutine SpinsToChargeAndMagnetisation( spins, charge_magn )
implicit none
class(t_potden), intent(in) :: spins
type(t_potden), intent(inout) :: charge_magn
charge_magn%mt(:,0:,:, 1) = spins%mt(:,0:,:, 1) + spins%mt(:,0:,:, 2)
charge_magn%mt(:,0:,:, 2) = spins%mt(:,0:,:, 1) - spins%mt(:,0:,:, 2)
charge_magn%pw(:, 1) = spins%pw(:, 1) + spins%pw(:, 2)
charge_magn%pw(:, 2) = spins%pw(:, 1) - spins%pw(:, 2)
charge_magn%vacz(:,:, 1) = spins%vacz(:,:, 1) + spins%vacz(:,:, 2)
charge_magn%vacz(:,:, 2) = spins%vacz(:,:, 1) - spins%vacz(:,:, 2)
charge_magn%vacxy(:,:,:,1) = spins%vacxy(:,:,:,1) + spins%vacxy(:,:,:,2)
charge_magn%vacxy(:,:,:,2) = spins%vacxy(:,:,:,1) - spins%vacxy(:,:,:,2)
end subroutine
subroutine ChargeAndMagnetisationToSpins( charge_magn, spins )
implicit none
class(t_potden), intent(in) :: charge_magn
type(t_potden), intent(inout) :: spins
spins%mt(:,0:,:, 1) = ( charge_magn%mt(:,0:,:, 1) + charge_magn%mt(:,0:,:, 2) ) / 2
spins%mt(:,0:,:, 2) = ( charge_magn%mt(:,0:,:, 1) - charge_magn%mt(:,0:,:, 2) ) / 2
spins%pw(:, 1) = ( charge_magn%pw(:, 1) + charge_magn%pw(:, 2) ) / 2
spins%pw(:, 2) = ( charge_magn%pw(:, 1) - charge_magn%pw(:, 2) ) / 2
spins%vacz(:,:, 1) = ( charge_magn%vacz(:,:, 1) + charge_magn%vacz(:,:, 2) ) / 2
spins%vacz(:,:, 2) = ( charge_magn%vacz(:,:, 1) - charge_magn%vacz(:,:, 2) ) / 2
spins%vacxy(:,:,:,1) = ( charge_magn%vacxy(:,:,:,1) + charge_magn%vacxy(:,:,:,2) ) / 2
spins%vacxy(:,:,:,2) = ( charge_magn%vacxy(:,:,:,1) - charge_magn%vacxy(:,:,:,2) ) / 2
end subroutine
SUBROUTINE init_potden_types(pd,stars,atoms,sphhar,vacuum,jspins,nocoExtraDim,potden_type)
USE m_judft
USE m_types_setup
......
......@@ -163,9 +163,14 @@ CONTAINS
ENDIF
ENDDO
ENDDO
ELSEIF (.NOT.input%film) THEN
vCoul%pw(1,ispin) = CMPLX(0.0,0.0)
vCoul%pw(2:stars%ng3,ispin)=fpi_const*psq(2:stars%ng3)/(stars%sk3(2:stars%ng3)*stars%sk3(2:stars%ng3))
else if ( .not. input%film ) then
if ( yukawa_residual ) then
vCoul%pw(1:stars%ng3,ispin) = fpi_const * psq(1:stars%ng3) / ( stars%sk3(1:stars%ng3) ** 2 + input%preconditioning_param ** 2 )
if( abs( real( psq(1) ) ) * cell%omtil < 0.01 ) vCoul%pw(1,ispin) = 0.0
else
vCoul%pw(1,ispin) = cmplx(0.0,0.0)
vCoul%pw(2:stars%ng3,ispin) = fpi_const * psq(2:stars%ng3) / ( stars%sk3(2:stars%ng3) * stars%sk3(2:stars%ng3) )
end if
END IF
CALL timestop("interstitial")
......@@ -182,6 +187,8 @@ CONTAINS
yukawa_residual, vCoul%mt(:,0:,:,ispin) )
CALL timestop( "MT-spheres" )
if( yukawa_residual ) return
IF (mpi%irank == 0) THEN
! ---> check continuity of coulomb potential
IF (input%vchk) THEN
......
......@@ -24,7 +24,10 @@ contains
! The integral is split in a part where r'=r_< and a part where r'=r_> and
! the integral from r to R is split in \int_0^R - \int_0^r. Resulting
! terms depending solely on R (not on r) are summarised in the variable
! termsR.
! termsR.
!
! More information and equations can be found in
! F. Tran, P. Blaha, Phys. Rev. B 83, 235118(2011)
!-------------------------------------------------------------------------
#include"cpp_double.h"
......
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