LCOV - code coverage report
Current view: top level - src/62_wvl_wfs - m_wvl_psi.F90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 13 0
Test Date: 2026-09-20 18:56:22 Functions: 0.0 % 4 0

            Line data    Source code
       1              : !!****m* ABINIT/m_wvl_psi
       2              : !! NAME
       3              : !!  m_wvl_psi
       4              : !!
       5              : !! FUNCTION
       6              : !!
       7              : !! COPYRIGHT
       8              : !!  Copyright (C) 1998-2026 ABINIT group (DC, MT)
       9              : !!  This file is distributed under the terms of the
      10              : !!  GNU General Public License, see ~abinit/COPYING
      11              : !!  or http://www.gnu.org/copyleft/gpl.txt .
      12              : !!
      13              : !! SOURCE
      14              : 
      15              : #if defined HAVE_CONFIG_H
      16              : #include "config.h"
      17              : #endif
      18              : 
      19              : #include "abi_common.h"
      20              : 
      21              : module m_wvl_psi
      22              : 
      23              :   use defs_basis
      24              :   use defs_wvltypes
      25              :   use m_errors
      26              :   use m_xmpi
      27              :   use m_abicore
      28              :   use m_dtset
      29              : 
      30              :   use defs_datatypes, only : pseudopotential_type
      31              :   use defs_abitypes,  only : MPI_type
      32              :   use m_energies, only : energies_type
      33              :   use m_pawcprj,  only : pawcprj_type, pawcprj_alloc
      34              :   use m_abi2big,  only : wvl_vxc_abi2big, wvl_vtrial_abi2big
      35              : 
      36              :  implicit none
      37              : 
      38              :  private
      39              : !!***
      40              : 
      41              :  public :: wvl_hpsitopsi
      42              :  public :: wvl_psitohpsi
      43              :  public :: wvl_nl_gradient
      44              :  public :: wvl_tail_corrections
      45              : !!***
      46              : 
      47              : contains
      48              : !!***
      49              : 
      50              : !!****f* ABINIT/wvl_hpsitopsi
      51              : !! NAME
      52              : !! wvl_hpsitopsi
      53              : !!
      54              : !! FUNCTION
      55              : !! Heart of the wavelet resolution, compute new wavefunctions mixed witf previous
      56              : !! by computing the gradient of the wavefunctions knowing the external potential.
      57              : !!
      58              : !! INPUTS
      59              : !!  dtset <type(dataset_type)>=input variables.
      60              : !!  istep=id of the current iteration (first is 1).
      61              : !!  mpi_enreg=information about MPI parallelization
      62              : !!  proj <type(wvl_projector_type)>=projectors information for wavelets.
      63              : !!  vtrial(dtset%nfft)=external potential.
      64              : !!  xcart(3,natom)=cartesian atomic coordinates
      65              : !!
      66              : !! OUTPUT
      67              : !!
      68              : !! SIDE EFFECTS
      69              : !!  energies <type(energies_type)>=storage for energies computed here :
      70              : !!   | e_kinetic(OUT)=kinetic energy part of total energy
      71              : !!   | e_localpsp(OUT)=local pseudopotential part of total energy
      72              : !!   | e_nlpsp_vfock(OUT)=nonlocal psp + potential Fock ACE part of total energy
      73              : !!  residm=max value for gradient in the minimisation process.
      74              : !!  rhor(dtset%nfft)=electron density in r space
      75              : !!  wfs <type(wvl_projector_type)>=wavefunctions information for wavelets.
      76              : !!
      77              : !! SOURCE
      78              : 
      79              : 
      80            0 : subroutine wvl_hpsitopsi(cprj,dtset,energies,istep,mcprj,mpi_enreg,residm,wvl,xcart)
      81              : 
      82              : #if defined HAVE_BIGDFT
      83              :   use BigDFT_API, only : hpsitopsi, calculate_energy_and_gradient
      84              : #endif
      85              : 
      86              : !Arguments -------------------------------
      87              :   type(dataset_type), intent(in)         :: dtset
      88              :   type(energies_type), intent(inout)     :: energies
      89              :   integer, intent(in)                    :: istep,mcprj
      90              :   type(MPI_type), intent(in)             :: mpi_enreg
      91              :   real(dp), intent(inout)                :: residm
      92              :   type(wvl_data), intent(inout)          :: wvl
      93              :   !arrays
      94              :   real(dp), intent(in) :: xcart(3, dtset%natom)
      95              :   type(pawcprj_type),dimension(dtset%natom,mcprj),intent(inout)::cprj
      96              : 
      97              : !Local variables-------------------------------
      98              : #if defined HAVE_BIGDFT
      99              :   integer               :: iatom,icprj
     100              :   character(len = 500)  :: message
     101              :   real(dp), save        :: etotal_local
     102              :   integer, save         :: ids
     103              :   real(dp)              :: gnrm_zero
     104              :   integer               :: comm,me,nproc
     105              :   integer :: nlmn(dtset%natom)
     106              : #endif
     107              : 
     108              : 
     109              : ! *********************************************************************
     110              : 
     111              :  DBG_ENTER("COLL")
     112              : 
     113              : #if defined HAVE_BIGDFT
     114              : 
     115              :  if(wvl%wfs%ks%orthpar%methOrtho .ne. 0) then
     116              :    write(message,'(2a)') ch10,&
     117              : &   'wvl_hpsitopsi: the only orthogonalization method supported for PAW+WVL is Cholesky'
     118              :    ABI_ERROR(message)
     119              :  end if
     120              : 
     121              :  write(message, '(a,a)' ) ch10,&
     122              : & ' wvl_hpsitopsi: compute the new wavefunction from the trial potential.'
     123              :  call wrtout(std_out,message,'COLL')
     124              : 
     125              :  comm=mpi_enreg%comm_wvl
     126              :  me=xmpi_comm_rank(comm)
     127              :  nproc=xmpi_comm_size(comm)
     128              : 
     129              : !Initialisation of mixing parameter
     130              :  if (istep == 1) then
     131              :    etotal_local = real(1.d100, dp)
     132              :    ids          = dtset%nwfshist
     133              :  end if
     134              : 
     135              : !WARNING! e_hartree is taken from the previous iteration as e_xc
     136              : !Update physical values
     137              : 
     138              : !Precondition, minimise (DIIS or steepest descent) and ortho.
     139              : !Compute also the norm of the gradient.
     140              :  if(dtset%usepaw==1) then
     141              :    call calculate_energy_and_gradient(istep, me, nproc, wvl%wfs%GPU, dtset%wvl_nprccg, &
     142              : &   dtset%iscf, wvl%e%energs, wvl%wfs%ks, residm, gnrm_zero,wvl%descr%paw)
     143              :  else
     144              :    call calculate_energy_and_gradient(istep, me, nproc, wvl%wfs%GPU, dtset%wvl_nprccg, &
     145              : &   dtset%iscf, wvl%e%energs, wvl%wfs%ks, residm, gnrm_zero)
     146              :  end if
     147              :  etotal_local = wvl%wfs%ks%diis%energy
     148              : 
     149              :  if(dtset%usepaw==1) then
     150              :    call hpsitopsi(me, nproc, istep, ids, wvl%wfs%ks,&
     151              : &   wvl%descr%atoms,wvl%projectors%nlpsp,&
     152              : &   wvl%descr%paw,xcart,energies%e_nlpsp_vfock,wvl%projectors%G)
     153              :  else
     154              :    call hpsitopsi(me, nproc, istep, ids, wvl%wfs%ks,&
     155              : &   wvl%descr%atoms,wvl%projectors%nlpsp)
     156              :  end if
     157              : 
     158              :  if(dtset%usepaw==1) then
     159              : !  PENDING : cprj should not be copied'
     160              : 
     161              :    ! Cannot use pawcprj_copy because cprj and paw%cprj are not the same objects
     162              :    ! Get nlmn from bigdft cprj, and allocate our copy
     163              :    do iatom=1,dtset%natom
     164              :      nlmn(iatom) = wvl%descr%paw%cprj(iatom,1)%nlmn
     165              :    end do
     166              :    call pawcprj_alloc(cprj,mcprj,nlmn)
     167              : 
     168              :    do iatom=1,dtset%natom
     169              :      do icprj=1,mcprj
     170              :        cprj(iatom,icprj)%cp(:,:)= wvl%descr%paw%cprj(iatom,icprj)%cp(:,:)
     171              :      end do
     172              :    end do
     173              : 
     174              : 
     175              :  end if
     176              : 
     177              : #else
     178            0 :  BIGDFT_NOTENABLED_ERROR()
     179              :  if (.false.) write(std_out,*) dtset%nstep,energies%e_ewald,istep,mcprj,mpi_enreg%nproc,residm,&
     180              : & wvl%wfs%ks,xcart(1,1),cprj(1,1)%nlmn
     181              : #endif
     182              : 
     183              :  DBG_EXIT("COLL")
     184              : 
     185            0 : end subroutine wvl_hpsitopsi
     186              : !!***
     187              : 
     188              : !!****f* ABINIT/wvl_psitohpsi
     189              : !! NAME
     190              : !! wvl_psitohpsi
     191              : !!
     192              : !! FUNCTION
     193              : !! Compute new trial potential and calculate the hamiltionian application into hpsi.
     194              : !!
     195              : !! INPUTS
     196              : !!  mpi_enreg=information about MPI parallelization
     197              : !!
     198              : !! OUTPUT
     199              : !!  vxc(nfft,nspden)=exchange-correlation potential (hartree)
     200              : !!  vtrial(nfft,nspden)=new potential
     201              : !!
     202              : !! NOTES
     203              : !!
     204              : !! SOURCE
     205              : 
     206              : 
     207            0 : subroutine wvl_psitohpsi(alphamix,eexctX, eexcu, ehart, ekin_sum, epot_sum, eproj_sum, eSIC_DC, &
     208              :      & itrp, iter, iscf, me, natom, nfft, nproc, nspden, rpnrm, scf, &
     209            0 :      & vexcu, wvl, wvlbigdft, xcart, xcstr,vtrial,vxc)
     210              : 
     211              : #if defined HAVE_BIGDFT
     212              :  use BigDFT_API, only: psitohpsi, KS_POTENTIAL, total_energies
     213              : #endif
     214              : 
     215              : !Arguments-------------------------------
     216              : !scalars
     217              :  integer, intent(in) :: me, nproc, itrp, iter, iscf, natom, nfft, nspden
     218              :  real(dp), intent(in) :: alphamix
     219              :  real(dp), intent(out) :: rpnrm
     220              :  logical, intent(in) :: scf
     221              :  logical, intent(in) :: wvlbigdft
     222              :  type(wvl_data), intent(inout) :: wvl
     223              :  real(dp), intent(inout) :: eexctX,eSIC_DC,ehart,eexcu,vexcu, ekin_sum, epot_sum, eproj_sum
     224              :  real(dp), dimension(6), intent(out) :: xcstr
     225              :  real(dp), intent(inout) :: xcart(3, natom)
     226              : !arrays
     227              :  real(dp),intent(out), optional :: vxc(nfft,nspden)
     228              :  real(dp),intent(out), optional :: vtrial(nfft,nspden)
     229              : 
     230              : !Local variables-------------------------------
     231              : !scalars
     232              : #if defined HAVE_BIGDFT
     233              :  character(len=500) :: message
     234              :  integer :: linflag = 0
     235              :  character(len=3), parameter :: unblock_comms = "OFF"
     236              : #endif
     237              : 
     238              : ! *************************************************************************
     239              : 
     240              :  DBG_ENTER("COLL")
     241              : 
     242              : #if defined HAVE_BIGDFT
     243              : 
     244              :  if(wvl%descr%atoms%npspcode(1)==7) then
     245              :    call psitohpsi(me,nproc,wvl%descr%atoms,scf,wvl%den%denspot, &
     246              : &   itrp, iter, iscf, alphamix,&
     247              : &   wvl%projectors%nlpsp,xcart,linflag,unblock_comms, &
     248              : &   wvl%wfs%GPU,wvl%wfs%ks,wvl%e%energs,rpnrm,xcstr,&
     249              : &   wvl%projectors%G,wvl%descr%paw)
     250              :  else
     251              :    call psitohpsi(me,nproc,wvl%descr%atoms,scf,wvl%den%denspot, &
     252              : &   itrp, iter, iscf, alphamix,&
     253              : &   wvl%projectors%nlpsp,xcart,linflag,unblock_comms, &
     254              : &   wvl%wfs%GPU,wvl%wfs%ks,wvl%e%energs,rpnrm,xcstr)
     255              :  end if
     256              : 
     257              :  if(scf) then
     258              :    ehart     = wvl%e%energs%eh
     259              :    eexcu     = wvl%e%energs%exc
     260              :    vexcu     = wvl%e%energs%evxc
     261              :  end if
     262              :  eexctX    = wvl%e%energs%eexctX
     263              :  eSIC_DC   = wvl%e%energs%evsic
     264              :  ekin_sum  = wvl%e%energs%ekin
     265              :  eproj_sum = wvl%e%energs%eproj
     266              :  epot_sum  = wvl%e%energs%epot
     267              : 
     268              : !Correct local potential, since in BigDFT
     269              : !this variable contains more terms
     270              : !Do the following only if sumpion==.true. in psolver_rhohxc.
     271              : !For the moment it is set to false.
     272              : 
     273              :  epot_sum=epot_sum-real(2,dp)*wvl%e%energs%eh
     274              :  epot_sum=epot_sum-wvl%e%energs%evxc
     275              : 
     276              :  if(wvlbigdft) then
     277              :    call total_energies(wvl%e%energs, iter, me)
     278              :  end if
     279              : 
     280              : !Note: if evxc is not rested here,
     281              : !we have to rest this from etotal in prtene, afterscfcv and etotfor.
     282              : !check ABINIT-6.15.1.
     283              : 
     284              :  if(scf) then
     285              :    if (present(vxc)) then
     286              :      write(message, '(a,a,a,a)' ) ch10, ' wvl_psitohpsi : but why are you copying vxc :..o('
     287              :      call wrtout(std_out,message,'COLL')
     288              :      call wvl_vxc_abi2big(2,vxc,wvl%den)
     289              :    end if
     290              :    if (wvl%den%denspot%rhov_is == KS_POTENTIAL .and. present(vtrial)) then
     291              :      write(message, '(a,a,a,a)' ) ch10, ' wvl_psitohpsi : but why are you copying vtrial :..o('
     292              :      call wrtout(std_out,message,'COLL')
     293              :      call wvl_vtrial_abi2big(2,vtrial,wvl%den)
     294              :    end if
     295              :  end if
     296              : 
     297              : #else
     298            0 :  BIGDFT_NOTENABLED_ERROR()
     299              :  if (.false.) write(std_out,*) me,nproc,itrp,iter,iscf,natom,nfft,nspden,alphamix,rpnrm,scf,&
     300              : & wvlbigdft,wvl%wfs%ks,eexctX,eSIC_DC,ehart,eexcu,vexcu,ekin_sum,&
     301              : & epot_sum,eproj_sum,xcstr(1),xcart(1,1),vxc(1,1),vtrial(1,1)
     302              : #endif
     303              : 
     304              :  DBG_EXIT("COLL")
     305              : 
     306            0 : end subroutine wvl_psitohpsi
     307              : !!***
     308              : 
     309              : !!****f* ABINIT/wvl_nl_gradient
     310              : !! NAME
     311              : !! wvl_nl_gradient
     312              : !!
     313              : !! FUNCTION
     314              : !! Compute the non local part of the wavefunction gradient.
     315              : !!
     316              : !! INPUTS
     317              : !!
     318              : !! OUTPUT
     319              : !!
     320              : !! SIDE EFFECTS
     321              : !!
     322              : !! NOTES
     323              : !!
     324              : !! SOURCE
     325              : 
     326            0 : subroutine wvl_nl_gradient(grnl, mpi_enreg, natom, rprimd, wvl, xcart)
     327              : 
     328              : #if defined HAVE_BIGDFT
     329              :  use BigDFT_API, only: nonlocal_forces
     330              : #endif
     331              : 
     332              : !Arguments ------------------------------------
     333              : !scalars
     334              :  integer, intent(in) :: natom
     335              :  type(MPI_type),intent(in) :: mpi_enreg
     336              :  type(wvl_data),intent(inout) :: wvl
     337              : !arrays
     338              :  real(dp),intent(in) :: xcart(3,natom),rprimd(3,3)
     339              :  real(dp),intent(inout) :: grnl(3,natom)
     340              : 
     341              : !Local variables-------------------------------
     342              : #if defined HAVE_BIGDFT
     343              : !scalars
     344              :  integer :: ia,ierr,igeo,me,nproc,spaceComm
     345              :  character(len=500) :: message
     346              : !arrays
     347              :  real(dp),allocatable :: gxyz(:,:)
     348              :  real(dp)::strtens(6,4)
     349              : #endif
     350              : 
     351              : ! *************************************************************************
     352              : 
     353              : #if defined HAVE_BIGDFT
     354              : 
     355              : !Compute forces
     356              :  write(message, '(a,a)' ) ' wvl_nl_gradient(): compute non-local part to gradient.'
     357              :  call wrtout(std_out,message,'COLL')
     358              : 
     359              : !Nullify output arrays.
     360              :  grnl(:, :) = zero
     361              :  strtens(:,:)=zero
     362              : 
     363              :  ABI_MALLOC(gxyz,(3, natom))
     364              :  gxyz(:,:) = zero
     365              : 
     366              : !Add the nonlocal part of the forces to grtn (BigDFT routine)
     367              :  spaceComm=mpi_enreg%comm_wvl
     368              :  me=xmpi_comm_rank(spaceComm)
     369              :  nproc=xmpi_comm_size(spaceComm)
     370              :  call nonlocal_forces(wvl%descr%Glr, &
     371              : & wvl%descr%h(1), wvl%descr%h(2), wvl%descr%h(3), wvl%descr%atoms, &
     372              : & xcart, wvl%wfs%ks%orbs, wvl%projectors%nlpsp, wvl%wfs%ks%Lzd%Glr%wfd, &
     373              : & wvl%wfs%ks%psi, gxyz, .true.,strtens(1,2), &
     374              : & proj_G=wvl%projectors%G,paw=wvl%descr%paw)
     375              : 
     376              :  if (nproc > 1) then
     377              :    call xmpi_sum(gxyz, spaceComm, ierr)
     378              :  end if
     379              : 
     380              : !Forces should be in reduced coordinates.
     381              :  do ia = 1, natom, 1
     382              :    do igeo = 1, 3, 1
     383              :      grnl(igeo, ia) = - rprimd(1, igeo) * gxyz(1, ia) - &
     384              : &     rprimd(2, igeo) * gxyz(2, ia) - &
     385              : &     rprimd(3, igeo) * gxyz(3, ia)
     386              :    end do
     387              :  end do
     388              :  ABI_FREE(gxyz)
     389              : 
     390              : #else
     391            0 :  BIGDFT_NOTENABLED_ERROR()
     392              :  if (.false.) write(std_out,*) natom,mpi_enreg%nproc,wvl%wfs%ks,xcart(1,1),rprimd(1,1),grnl(1,1)
     393              : #endif
     394              : 
     395            0 : end subroutine wvl_nl_gradient
     396              : !!***
     397              : 
     398              : !!****f* ABINIT/wvl_tail_corrections
     399              : !! NAME
     400              : !! wvl_tail_corrections
     401              : !!
     402              : !! FUNCTION
     403              : !! Perform a minimization on the wavefunctions (especially the treatment
     404              : !! of the kinetic operator) with exponentialy decreasing functions on
     405              : !! boundaries.
     406              : !!
     407              : !! INPUTS
     408              : !!
     409              : !! OUTPUT
     410              : !!
     411              : !! SIDE EFFECTS
     412              : !!
     413              : !! NOTES
     414              : !!
     415              : !! SOURCE
     416              : 
     417            0 : subroutine wvl_tail_corrections(dtset, energies, etotal, mpi_enreg, psps, wvl, xcart)
     418              : 
     419              : #if defined HAVE_BIGDFT
     420              :   use BigDFT_API, only: CalculateTailCorrection
     421              : #endif
     422              : 
     423              : !Arguments ------------------------------------
     424              : !scalars
     425              :  real(dp),intent(out) :: etotal
     426              :  type(MPI_type),intent(in) :: mpi_enreg
     427              :  type(dataset_type),intent(in) :: dtset
     428              :  type(energies_type),intent(inout) :: energies
     429              :  type(pseudopotential_type),intent(in) :: psps
     430              :  type(wvl_data),intent(inout) :: wvl
     431              : !arrays
     432              :  real(dp),intent(in) :: xcart(3,dtset%natom)
     433              : 
     434              : !Local variables-------------------------------
     435              : #if defined HAVE_BIGDFT
     436              : !scalars
     437              :  integer :: ierr,me,nbuf,nproc,nsize,spaceComm
     438              :  real(dp) :: ekin_sum,epot_sum,eproj_sum
     439              :  logical :: parallel
     440              :  character(len=500) :: message
     441              : !arrays
     442              :  integer :: ntails(3)
     443              :  real(dp) :: atails(3)
     444              : #endif
     445              : 
     446              : ! *************************************************************************
     447              : 
     448              : #if defined HAVE_BIGDFT
     449              : 
     450              :  spaceComm=mpi_enreg%comm_wvl
     451              :  me=xmpi_comm_rank(spaceComm)
     452              :  nproc=xmpi_comm_size(spaceComm)
     453              :  parallel = (nproc > 1)
     454              : 
     455              : !Write a message with the total energy before tail corrections.
     456              :  etotal = energies%e_kinetic + energies%e_hartree + energies%e_xc + &
     457              : & energies%e_localpsp + energies%e_corepsp + energies%e_fock+&
     458              : & energies%e_entropy + energies%e_elecfield + energies%e_magfield+&
     459              : & energies%e_ewald + energies%e_chempot + energies%e_vdw_dftd
     460              :  if (dtset%usepaw==0) etotal = etotal + energies%e_nlpsp_vfock
     461              :  if (dtset%usepaw/=0) etotal = etotal + energies%paw%epaw
     462              :  write(message,'(a,2x,e19.12)') ' Total energy before tail correction', etotal
     463              :  call wrtout(std_out, message, 'COLL')
     464              : 
     465              : !Calculate kinetic energy correction due to boundary conditions
     466              :  nbuf = nint(dtset%tl_radius / dtset%wvl_hgrid)
     467              :  ntails = (/ wvl%descr%Glr%d%n1, wvl%descr%Glr%d%n2, wvl%descr%Glr%d%n3 /) + 2 * nbuf
     468              :  atails = real(ntails, dp) * dtset%wvl_hgrid
     469              :  write(message,'(a,a,i6,a,A,A,3F12.6,A,A,3I12,A)') ch10,&
     470              : & ' Tail requires ',nbuf,' additional grid points around cell.', ch10, &
     471              : & '  | new acell:', atails, ch10, &
     472              : & '  | new box size for wavelets:', ntails, ch10
     473              :  call wrtout(std_out,message,'COLL')
     474              :  call wrtout(ab_out,message,'COLL')
     475              : 
     476              : 
     477              : !Calculate energy correction due to finite size effects
     478              : !---reformat potential
     479              :  nsize = wvl%descr%Glr%d%n1i * wvl%descr%Glr%d%n2i
     480              :  ABI_MALLOC(wvl%den%denspot%pot_work, (nsize * wvl%descr%Glr%d%n3i * dtset%nsppol))
     481              : 
     482              :  if (parallel) then
     483              :    call xmpi_allgatherv(wvl%den%denspot%rhov, &
     484              : &   nsize * wvl%den%denspot%dpbox%nscatterarr(me, 2), &
     485              : &   wvl%den%denspot%pot_work, nsize * wvl%den%denspot%dpbox%ngatherarr(:,2), &
     486              : &   nsize * wvl%den%denspot%dpbox%ngatherarr(:,3),spaceComm,ierr)
     487              :  else
     488              :    call dcopy(wvl%descr%Glr%d%n1i * wvl%descr%Glr%d%n2i * &
     489              : &   wvl%descr%Glr%d%n3i * dtset%nsppol,wvl%den%denspot%rhov,1,wvl%den%denspot%pot_work,1)
     490              :  end if
     491              : 
     492              :  if(dtset%usepaw==1) then
     493              :    call CalculateTailCorrection(me, nproc, wvl%descr%atoms, dtset%tl_radius, &
     494              : &   wvl%wfs%ks%orbs, wvl%wfs%ks%lzd%Glr, wvl%projectors%nlpsp, dtset%tl_nprccg, &
     495              : &   wvl%den%denspot%pot_work, dtset%wvl_hgrid, xcart, psps%gth_params%radii_cf, &
     496              : &   dtset%wvl_crmult, dtset%wvl_frmult, dtset%nsppol, &
     497              : &   wvl%wfs%ks%psi, .false., ekin_sum, epot_sum, eproj_sum,&
     498              : &   wvl%projectors%G,wvl%descr%paw)
     499              :  else
     500              :    call CalculateTailCorrection(me, nproc, wvl%descr%atoms, dtset%tl_radius, &
     501              : &   wvl%wfs%ks%orbs, wvl%wfs%ks%lzd%Glr, wvl%projectors%nlpsp, dtset%tl_nprccg, &
     502              : &   wvl%den%denspot%pot_work, dtset%wvl_hgrid, xcart, psps%gth_params%radii_cf, &
     503              : &   dtset%wvl_crmult, dtset%wvl_frmult, dtset%nsppol, &
     504              : &   wvl%wfs%ks%psi, .false., ekin_sum, epot_sum, eproj_sum)
     505              :  end if
     506              : 
     507              :  ABI_FREE(wvl%den%denspot%pot_work)
     508              : 
     509              :  energies%e_kinetic = ekin_sum
     510              :  energies%e_localpsp = epot_sum - two * energies%e_hartree
     511              :  energies%e_nlpsp_vfock = eproj_sum
     512              :  energies%e_corepsp = zero
     513              :  energies%e_chempot = zero
     514              : #if defined HAVE_BIGDFT
     515              :  energies%e_localpsp = energies%e_localpsp - wvl%e%energs%evxc
     516              : #endif
     517              : 
     518              :  write(message,'(a,3(1x,e18.11))') ' ekin_sum,epot_sum,eproj_sum',  &
     519              :  ekin_sum,epot_sum,eproj_sum
     520              :  call wrtout(std_out, message, 'COLL')
     521              :  write(message,'(a,2(1x,e18.11))') ' ehart,eexcu', &
     522              : & energies%e_hartree,energies%e_xc
     523              :  call wrtout(std_out, message, 'COLL')
     524              : 
     525              :  etotal = energies%e_kinetic + energies%e_hartree + energies%e_xc + &
     526              : & energies%e_localpsp + energies%e_corepsp + energies%e_fock+&
     527              : & energies%e_entropy + energies%e_elecfield + energies%e_magfield+&
     528              : & energies%e_ewald + energies%e_vdw_dftd
     529              :  if (dtset%usepaw==0) etotal = etotal + energies%e_nlpsp_vfock
     530              :  if (dtset%usepaw/=0) etotal = etotal + energies%paw%epaw
     531              : 
     532              :  write(message,'(a,2x,e19.12)') ' Total energy with tail correction', etotal
     533              :  call wrtout(std_out, message, 'COLL')
     534              : 
     535              : !--- End if of tail calculation
     536              : 
     537              : #else
     538            0 :  BIGDFT_NOTENABLED_ERROR()
     539              :  if (.false.) write(std_out,*) etotal,mpi_enreg%nproc,dtset%nstep,energies%e_ewald,psps%npsp,&
     540              : & wvl%wfs%ks,xcart(1,1)
     541              : #endif
     542              : 
     543            0 : end subroutine wvl_tail_corrections
     544              : !!***
     545              : 
     546              : end module m_wvl_psi
     547              : !!***
        

Generated by: LCOV version 2.3-1