LCOV - code coverage report
Current view: top level - src/71_wannier - m_wfd_wannier.F90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.8 % 31 30
Test Date: 2026-11-09 23:40:40 Functions: 100.0 % 1 1
Branches: 65.4 % 52 34

             Branch data     Line data    Source code
       1                 :             : !!****m*ABINIT/m_wfd_wannier
       2                 :             : !! NAME
       3                 :             : !!  m_wfd_wannier
       4                 :             : !!
       5                 :             : !! FUNCTION
       6                 :             : !!  The high level wfd_t inteface for building wannier functions
       7                 :             : !!
       8                 :             : !! COPYRIGHT
       9                 :             : !!  Copyright (C) 2005-2026 ABINIT group (hexu)
      10                 :             : !!  This file is distributed under the terms of the
      11                 :             : !!  GNU General Public License, see ~abinit/COPYING
      12                 :             : !!  or http://www.gnu.org/copyleft/gpl.txt .
      13                 :             : !!
      14                 :             : !! SOURCE
      15                 :             : !!
      16                 :             : 
      17                 :             : #if defined HAVE_CONFIG_H
      18                 :             : #include "config.h"
      19                 :             : #endif
      20                 :             : 
      21                 :             : #include "abi_common.h"
      22                 :             : 
      23                 :             : !===============================================================
      24                 :             : ! m_wfd_wannier
      25                 :             : !> @description: Wannier function from wfd_t
      26                 :             : !===============================================================
      27                 :             : 
      28                 :             : module m_wfd_wannier
      29                 :             : 
      30                 :             :   use defs_basis
      31                 :             :   use m_abicore
      32                 :             :   use m_errors
      33                 :             :   use m_xmpi
      34                 :             : 
      35                 :             :   use defs_abitypes,     only : mpi_type
      36                 :             :   use defs_datatypes,    only : pseudopotential_type
      37                 :             :   use m_dtset,           only : dataset_type
      38                 :             :   use m_hdr,             only : hdr_type
      39                 :             :   use m_wfd,             only : wfd_t
      40                 :             :   use m_crystal,         only : crystal_t
      41                 :             :   use m_pawang,          only : pawang_type
      42                 :             :   use m_pawrad,          only : pawrad_type
      43                 :             :   use m_pawtab,          only : pawtab_type
      44                 :             :   use m_pawcprj,         only : pawcprj_type
      45                 :             :   use m_dtfil,           only : datafiles_type
      46                 :             :   use m_abstract_wf,     only : abstract_wf, compute_iwav, write_cg_and_cprj, wann_ksetting_t, init_mywfc
      47                 :             :   use m_mlwfovlp,        only : mlwfovlp
      48                 :             :   use m_ebands,          only : ebands_t
      49                 :             : 
      50                 :             :   use defs_wannier90
      51                 :             : 
      52                 :             :   implicit none
      53                 :             :   private
      54                 :             :   public :: wfd_run_wannier
      55                 :             :   integer,  parameter :: master=0
      56                 :             : 
      57                 :             : contains
      58                 :             : 
      59                 :             : 
      60                 :             : !-----------------------------------------------------------------------------
      61                 :             : !> @brief The high level wfd_t inteface for building wannier functions
      62                 :             : !> @param[in] cryst: crystal_t type,  crystal structure
      63                 :             : !> @param[inout] ebands: ebands_t type,   eigenvalues and eigenvectors
      64                 :             : !> @param[inout] hdr: hdr_type type,   header
      65                 :             : !> @param[in] mpi_enreg: mpi_type type,   MPI information
      66                 :             : !> @param[in] ngfftc: integer,   FFT grid for coarse grid
      67                 :             : !> @param[in] ngfftf: integer,   FFT grid for fine grid
      68                 :             : !> @param[in] wfd: wfd_t type,   wavefunction data
      69                 :             : !> @param[in] dtset: dataset_type type,   dataset
      70                 :             : !> @param[in] dtfil: datafiles_type type,   datafiles
      71                 :             : !> @param[in] pawang: pawang_type type,   PAW angular momentum
      72                 :             : !> @param[in] pawrad: pawrad_type type,   PAW radial functions
      73                 :             : !> @param[in] pawtab: pawtab_type type,   PAW tabulated functions
      74                 :             : !> @param[in] psps: pseudopotential_type type,   pseudopotential
      75                 :             : !> @param[in] kg: real(dp),   FFT grid, shouldn't be used
      76                 :             : !> @param[in] cg: complex(dp),   wavefunction coefficients, shouldn't be used
      77                 :             : !> @param[in] cprj: complex(dp),   wavefunction coefficients, shouldn't be used
      78                 :             : !-----------------------------------------------------------------------------
      79                 :          19 :   subroutine wfd_run_wannier(cryst, ebands, hdr, mpi_enreg, &
      80   [ +  +  +  -  :          19 :         ngfftc, ngfftf,  wfd, dtset, dtfil,  pawang,  pawrad, pawtab, psps , kg, cg, cprj)
          -  +  +  +  +  
          -  -  +  -  +  
          +  +  +  -  -  
                +  -  + ]
      81                 :             : 
      82                 :             :     type(crystal_t), intent(in) :: cryst
      83                 :             :     type(ebands_t), intent(in) :: ebands
      84                 :             :     type(hdr_type), intent(in) :: hdr
      85                 :             :     integer, intent(in) :: ngfftc(18),ngfftf(18)
      86                 :             :     type(dataset_type), intent(in) :: dtset
      87                 :             :     type(datafiles_type),intent(in) :: dtfil
      88                 :             :     type(mpi_type), intent(inout) :: mpi_enreg
      89                 :             :     type(pseudopotential_type),intent(in) :: psps
      90                 :             :     type(pawang_type),intent(in) :: pawang
      91                 :             :     !type(pawrad_type),intent(in) :: pawrad(psps%ntypat*psps%usepaw)
      92                 :             :     type(pawrad_type),intent(in) :: pawrad(:)
      93                 :             :     !type(pawtab_type),intent(in) :: pawtab(psps%ntypat*psps%usepaw)
      94                 :             :     type(pawtab_type),intent(in) :: pawtab(:)
      95                 :             : 
      96                 :             :     type(wfd_t), optional, intent(inout) :: wfd
      97                 :             :     real(dp), optional, target, intent(in) :: cg(:, :)
      98                 :             :     integer, optional, target, intent(in) :: kg(:, :)
      99                 :             :     type(pawcprj_type), optional, target, intent(in) :: cprj(:, :)
     100                 :             :     class(abstract_wf), pointer :: mywfc
     101                 :             :     integer :: mgfftc
     102                 :             :     integer :: nfft
     103                 :             :     integer :: mcg, mcprj
     104                 :             :     !real(dp), pointer:: ptr_cg(:, :)=>null()
     105                 :             :     integer, pointer:: ptr_kg(:, :)=>null()
     106                 :             :     !type(pawcprj_type), pointer:: ptr_cprj(:, :)=>null()
     107                 :             :     integer :: mpw, nspinor, mband, mkmem, nsppol
     108                 :             :     ! TODO: anything todo with nkpt: fullBZ
     109                 :             :     ! TODO: ebands for fullBZ
     110                 :             :     ! TODO: mcprj
     111                 :             :     ! TODO: mgfftc: is it ngfft. NO
     112                 :             :     ! TODO: ngfft: is it ngfftc, or ngfftf
     113                 :             :     ! TODO: check mpw in wfd
     114                 :             :     ! TODO: mkmem: note: the mkmem in mpi_enreg is not used.
     115                 :             :     ! TODO: gather kg from wfd
     116                 :             :     ! TODO: mcg
     117                 :             :     ! TODO: mcprj
     118                 :          38 :     integer :: exclude_bands(hdr%mband, hdr%nsppol)
     119                 :             :     integer :: spaceComm, nprocs, rank, master
     120                 :             : 
     121                 :             :      ABI_UNUSED(ngfftf(1))
     122                 :             : 
     123                 :             :     !print *, "============================================================"
     124                 :             :     !print *, "Starting WFD Wannier"
     125                 :             :     !print *, "============================================================"
     126                 :             : 
     127                 :          19 :     spaceComm=MPI_enreg%comm_world
     128                 :          19 :     nprocs = MPI_enreg%nproc
     129                 :          19 :     rank= MPI_enreg%me
     130                 :          19 :     master=0
     131                 :             : 
     132                 :          19 :     mgfftc=dtset%mgfft
     133         [ +  + ]:         398 :     mpw=MAXVAL(hdr%npwarr)
     134                 :          19 :     nspinor=hdr%nspinor
     135                 :          19 :     mband=hdr%mband
     136                 :          19 :     nsppol = hdr%nsppol
     137                 :             :     !mcg=mpw*nspinor*mband* mkmem *nsppol
     138                 :             :     !mcprj = nspinor*mband* mkmem*nsppol
     139                 :             :     ! Is this correct for paw?
     140         [ +  + ]:          76 :     nfft=product(ngfftc(1:3))
     141         [ +  + ]:          19 :        if (present(cg)) then
     142                 :          14 :          mkmem= dtset%mkmem
     143                 :             :          call init_mywfc(mywfc=mywfc, ebands=ebands, cg=cg, cprj=cprj, &
     144                 :             :            &  cryst=cryst,dtset=dtset, &
     145                 :             :            & dtfil=dtfil, hdr=hdr, MPI_enreg=MPI_enreg, nprocs=nprocs, psps=psps, &
     146         [ -  + ]:          14 :            & pawtab=pawtab, rank=rank, comm=spaceComm)
     147                 :          14 :          ptr_kg => kg
     148                 :             :           ! call mlwfovlp(mywfc=mywfc, crystal=cryst, ebands=ebands, hdr=hdr, atindx1=cryst%atindx1  &
     149                 :             :           !      &,dtset=dtset,dtfil=dtfil, &
     150                 :             :           !      & eigen=ebands%eig,gprimd=cryst%gprimd,kg=ptr_kg,&
     151                 :             :           !      & mband=hdr%mband,mcg=mcg,mcprj=mcprj,mgfftc=mgfftc, &
     152                 :             :           !      & mkmem=mkmem,mpi_enreg=mpi_enreg,mpw=mpw,natom=cryst%natom,&
     153                 :             :           !      & nattyp=cryst%nattyp,nfft=nfft,ngfft=ngfftf,nkpt=hdr%nkpt,npwarr= hdr%npwarr , &
     154                 :             :           !      &nsppol=dtset%nsppol,ntypat=cryst%ntypat,occ=ebands%occ,&
     155                 :             :           !      &pawang=pawang,pawrad=pawrad,pawtab=pawtab,prtvol=dtset%prtvol,psps=psps, &
     156                 :             :           !      &rprimd=cryst%rprimd,ucvol=cryst%ucvol, xred=cryst%xred)
     157                 :             :        else
     158                 :             :            call init_mywfc(mywfc=mywfc, ebands=ebands, wfd=wfd, &
     159                 :             :              &  cryst=cryst,dtset=dtset, &
     160                 :             :              & dtfil=dtfil, hdr=hdr, MPI_enreg=MPI_enreg, nprocs=nprocs, psps=psps, &
     161                 :           5 :              & pawtab=pawtab, rank=rank, comm=spaceComm)
     162                 :             : 
     163                 :             :            ! TODO: distribute k
     164                 :           5 :            mkmem = mywfc%kset%my_nkpt
     165         [ +  + ]:         309 :            mpw=maxval(mywfc%hdr%npwarr)
     166                 :           5 :            mcg=mpw*nspinor*mband* mkmem *nsppol
     167                 :           5 :            mcprj = nspinor*mband* mkmem*nsppol
     168                 :             :            !block
     169                 :             :            !  integer :: ik
     170                 :             :            !  do ik =1, mkmem
     171                 :             :            !    print *, ik, ":", mywfc%ebands%kptns(:, ik)
     172                 :             :            !  end do
     173                 :             :            !end block
     174                 :             : 
     175         [ -  + ]:           5 :            if (present(kg)) then
     176                 :           0 :              ptr_kg=> kg
     177                 :             :            else
     178   [ -  +  +  -  :          15 :              ABI_MALLOC(ptr_kg, (3, mpw*mkmem))
          +  -  +  -  -  
                +  -  + ]
     179                 :           5 :              call mywfc%get_kgs(ptr_kg)
     180                 :             :            end if
     181                 :             :          end if
     182                 :             : 
     183                 :             :          call mlwfovlp(mywfc=mywfc, crystal=cryst, ebands=mywfc%ebands, hdr=mywfc%hdr, atindx1=cryst%atindx1  &
     184                 :             :                &,dtset=mywfc%dtset,dtfil=dtfil, &
     185                 :             :                & eigen=mywfc%ebands%eig,gprimd=cryst%gprimd,kg=ptr_kg,&
     186                 :             :                & mband=mywfc%hdr%mband,mcg=mcg,mcprj=mcprj,mgfftc=mgfftc, &
     187                 :             :                & mkmem=mkmem,mpi_enreg=mpi_enreg,mpw=mpw,natom=cryst%natom,&
     188                 :             :                & nattyp=cryst%nattyp,nfft=nfft,ngfft=ngfftc,nkpt=mywfc%hdr%nkpt,npwarr= mywfc%hdr%npwarr , &
     189                 :             :                &nsppol=dtset%nsppol,ntypat=cryst%ntypat,occ=mywfc%ebands%occ,&
     190                 :             :                &pawang=pawang,pawrad=pawrad,pawtab=pawtab,prtvol=dtset%prtvol,psps=psps, &
     191         [ -  + ]:          19 :                &rprimd=cryst%rprimd,ucvol=cryst%ucvol, xred=cryst%xred, exclude_bands=exclude_bands)
     192                 :             : 
     193         [ +  + ]:          19 :     if (.not. present(kg)) then
     194         [ -  + ]:           5 :        ABI_FREE(ptr_kg)
     195                 :             :     end if
     196                 :          19 :     nullify(ptr_kg)
     197                 :          19 :   end subroutine wfd_run_wannier
     198                 :             : 
     199                 :             : end module m_wfd_wannier
        

Generated by: LCOV version 2.3-1