LCOV - code coverage report
Current view: top level - src/56_recipspace - m_initylmg.F90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 167 167
Test Date: 2026-09-21 19:39:32 Functions: 100.0 % 2 2

            Line data    Source code
       1              : !!****m* ABINIT/m_initylmg
       2              : !! NAME
       3              : !!  m_initylmg
       4              : !!
       5              : !! FUNCTION
       6              : !! Calculate the real spherical harmonics Ylm (and gradients)
       7              : !! over a set of (reciprocal space) (k+G) vectors
       8              : !!
       9              : !! COPYRIGHT
      10              : !!  Copyright (C) 1998-2026 ABINIT group (FJ, MT)
      11              : !!  This file is distributed under the terms of the
      12              : !!  GNU General Public License, see ~abinit/COPYING
      13              : !!  or http://www.gnu.org/copyleft/gpl.txt .
      14              : !!
      15              : !! SOURCE
      16              : 
      17              : #if defined HAVE_CONFIG_H
      18              : #include "config.h"
      19              : #endif
      20              : 
      21              : #include "abi_common.h"
      22              : 
      23              : module m_initylmg
      24              : 
      25              :  use defs_basis
      26              :  use m_abicore
      27              :  use m_errors
      28              :  use m_xmpi
      29              : 
      30              :  use defs_abitypes,  only : MPI_type
      31              :  use m_paw_sphharm,  only : ass_leg_pol, plm_dtheta, plm_dphi, plm_coeff
      32              :  use m_mpinfo,       only : proc_distrb_cycle, destroy_mpi_enreg, initmpi_seq
      33              : 
      34              :  implicit none
      35              : 
      36              :  private
      37              : !!***
      38              : 
      39              :  public :: initylmg       ! Calculate real spherical harmonics Ylm (and gradients) for several k-points
      40              :  public :: initylmg_k     ! Simplified interface to compute Ylm for a single k-point.
      41              : !!***
      42              : 
      43              : contains
      44              : !!***
      45              : 
      46              : !!****f* ABINIT/initylmg
      47              : !! NAME
      48              : !! initylmg
      49              : !!
      50              : !! FUNCTION
      51              : !! Calculate the real spherical harmonics Ylm (and gradients)
      52              : !! over a set of (reciprocal space) (k+G) vectors
      53              : !!
      54              : !! INPUTS
      55              : !!  gprimd(3,3)=dimensional reciprocal space primitive translations (b^-1)
      56              : !!  kg(3,mpw)=integer coordinates of G vectors in basis sphere
      57              : !!  kptns(3,nkpt)=k points in terms of reciprocal translations
      58              : !!  mkmem =number of k points treated by this node
      59              : !!  mpi_enreg=information about MPI parallelization
      60              : !!  mpsang=1+maximum angular momentum for nonlocal pseudopotential
      61              : !!  mpw   =maximum number of planewaves in basis sphere (large number)
      62              : !!  nband(nkpt*nsppol)=number of bands at each k point
      63              : !!  nkpt  =number of k points
      64              : !!  npwarr(nkpt)=array holding npw for each k point
      65              : !!  nsppol=1 for unpolarized, 2 for polarized
      66              : !!  optder= 0=compute Ylm(K)
      67              : !!          1=compute Ylm(K) and dYlm/dKi
      68              : !!          2=compute Ylm(K), dYlm/dKi and d2Ylm/dKidKj
      69              : !!         -1=compute only dYlm/dKi
      70              : !!  rprimd(3,3)=dimensional primitive translations in real space (bohr)
      71              : !!
      72              : !! OUTPUT
      73              : !!  if (optder>=0)
      74              : !!    ylm(mpw*mkmem,mpsang*mpsang) = real spherical harmonics for each G and k point
      75              : !!  if (optder>=1 or optder==-1)
      76              : !!    ylm_gr(mpw*mkmem,1:3,mpsang*mpsang)= gradients of real
      77              : !!    spherical harmonics wrt (G+k) in reduced coordinates
      78              : !!  if (optder>=2)
      79              : !!    ylm_gr(mpw*mkmem,4:9,mpsang*mpsang)= second gradients of
      80              : !!    real spherical harmonics wrt (G+k) in reduced coordinates
      81              : !!
      82              : !! NOTES
      83              : !! Remember the expression of complex spherical harmonics:
      84              : !! $Y_{lm}(%theta ,%phi)=sqrt{{(2l+1) over (4 %pi)}
      85              : !! {fact(l-m) over fact(l+m)} } P_l^m(cos(%theta))
      86              : !! func e^{i m %phi}$
      87              : !! Remember the expression of real spherical harmonics as
      88              : !!   linear combination of complex spherical harmonics:
      89              : !! $Yr_{lm}(%theta ,%phi)=(Re{Y_{l-m}}+(-1)^m Re{Y_{lm}})/sqrt{2}
      90              : !! $Yr_{l-m}(%theta ,%phi)=(Im{Y_{l-m}}-(-1)^m Im{Y_{lm}})/sqrt{2}
      91              : !!
      92              : !! SOURCE
      93              : 
      94         8420 : subroutine initylmg(gprimd, kg, kptns, mkmem, mpi_enreg, mpsang, mpw, &
      95         8420 :                     nband, nkpt, npwarr, nsppol, optder, rprimd, ylm, ylm_gr)
      96              : 
      97              : !Arguments ------------------------------------
      98              : !scalars
      99              :  integer,intent(in) :: mkmem,mpsang,mpw,nkpt,nsppol,optder
     100              :  type(MPI_type),intent(in) :: mpi_enreg
     101              : !arrays
     102              :  integer,intent(in) :: kg(3,mpw*mkmem),nband(nkpt*nsppol)
     103              :  integer,intent(in) :: npwarr(nkpt)
     104              :  real(dp),intent(in) :: gprimd(3,3),kptns(3,nkpt),rprimd(3,3)
     105              :  real(dp),intent(out) :: ylm(mpw*mkmem,mpsang*mpsang)
     106              :  real(dp),intent(out) :: ylm_gr(mpw*mkmem,3+6*(optder/2),mpsang*mpsang)
     107              : 
     108              : !Local variables ------------------------------
     109              : !scalars
     110              :  integer :: dimgr,ia,ib,ii,ikg,ikpt,ilang,ipw
     111              :  integer :: jj,kk,l0,ll
     112              :  integer :: me_distrb,mm,npw_k
     113              :  real(dp),parameter :: tol=1.d-10
     114              :  real(dp) :: cphi,ctheta,fact,onem,rr,sphi,stheta,work1,work2
     115              :  real(dp) :: xx,ylmcst,ylmcst2
     116              :  real(dp) :: yy,zz
     117              :  !character(len=500) :: message
     118              : !arrays
     119              :  integer,parameter :: alpha(6)=(/1,2,3,3,3,2/)
     120              :  integer,parameter :: beta(6)=(/1,2,3,2,1,1/)
     121         8420 :  integer,allocatable :: kg_k(:,:)
     122        16840 :  real(dp) :: dphi(3),dtheta(3),iphase(mpsang-1),kpg(3)
     123        16840 :  real(dp) :: rphase(mpsang-1)
     124         8420 :  real(dp),allocatable :: blm(:,:)
     125         8420 :  real(dp),allocatable :: ylmgr2_cart(:,:,:),ylmgr2_tmp(:,:)
     126         8420 :  real(dp),allocatable :: ylmgr_cart(:,:)
     127         8420 :  real(dp),allocatable :: ylmgr_red(:,:)
     128              : 
     129              : !*****************************************************************
     130              : 
     131              : !Begin executable
     132         8420 :  me_distrb=mpi_enreg%me_kpt
     133              : !Initialisation of spherical harmonics (and gradients)
     134    145294222 :  if (optder>=0) ylm(:,:)  =zero
     135    433559355 :  if (optder/=0) ylm_gr(:,:,:)=zero
     136         8420 :  dimgr=3+6*(optder/2)
     137              : 
     138              : !Allocate some memory
     139         8420 :  if (optder/=0) then
     140         3679 :    ABI_MALLOC(ylmgr_cart,(3,2))
     141              :  end if
     142         8420 :  if (optder/=0.and.optder/=2) then
     143         2993 :    ABI_MALLOC(ylmgr_red,(3,2))
     144              :  end if
     145         8420 :  if (optder==2) then
     146          686 :    ABI_MALLOC(ylmgr2_cart,(3,3,2))
     147          686 :    ABI_MALLOC(ylmgr2_tmp,(3,3))
     148          686 :    ABI_MALLOC(ylmgr_red,(6,2))
     149         2058 :    ABI_MALLOC(blm,(5,mpsang*mpsang))
     150              :  end if
     151              : 
     152              : !Loop over k-points:
     153         8420 :  ikg=0
     154       170471 :  do ikpt=1,nkpt
     155              : 
     156       162051 :    if(proc_distrb_cycle(mpi_enreg%proc_distrb,ikpt,1,nband(ikpt),-1,me_distrb)) cycle
     157              : 
     158              : 
     159              : !  Get k+G-vectors, for this k-point:
     160       130749 :    npw_k=npwarr(ikpt)
     161       392247 :    ABI_MALLOC(kg_k,(3,npw_k))
     162     69962741 :    kg_k(:,1:npw_k)=kg(:,1+ikg:npw_k+ikg)
     163              : 
     164              : !  Special case for l=0
     165     17492381 :    if (optder>=0) ylm(1+ikg:npw_k+ikg,1)=1._dp/sqrt(four_pi)
     166     51696606 :    if (optder/=0) ylm_gr(1+ikg:npw_k+ikg,1:dimgr,1)=zero
     167              : 
     168       130749 :    if (mpsang>1) then
     169              : !    Loop over all k+G
     170     17564648 :      do ipw=1,npw_k
     171              : 
     172              : !      Load k+G
     173     17434112 :        kpg(1)=kptns(1,ikpt)+real(kg_k(1,ipw),dp)
     174     17434112 :        kpg(2)=kptns(2,ikpt)+real(kg_k(2,ipw),dp)
     175     17434112 :        kpg(3)=kptns(3,ikpt)+real(kg_k(3,ipw),dp)
     176              : 
     177              : !      Calculate module of k+G
     178     17434112 :        xx=gprimd(1,1)*kpg(1)+gprimd(1,2)*kpg(2)+gprimd(1,3)*kpg(3)
     179     17434112 :        yy=gprimd(2,1)*kpg(1)+gprimd(2,2)*kpg(2)+gprimd(2,3)*kpg(3)
     180     17434112 :        zz=gprimd(3,1)*kpg(1)+gprimd(3,2)*kpg(2)+gprimd(3,3)*kpg(3)
     181     17434112 :        rr=sqrt(xx**2+yy**2+zz**2)
     182              : 
     183              : !      Continue only for k+G<>0
     184     17564648 :        if (rr>tol) then
     185              : 
     186              : !        Determine theta and phi
     187     17433448 :          cphi=one
     188     17433448 :          sphi=zero
     189     17433448 :          ctheta=zz/rr
     190     17433448 :          stheta=sqrt(abs((one-ctheta)*(one+ctheta)))
     191     17433448 :          if (stheta>tol) then
     192     17419898 :            cphi=xx/(rr*stheta)
     193     17419898 :            sphi=yy/(rr*stheta)
     194              :          end if
     195     47692326 :          do mm=1,mpsang-1
     196     30258878 :            rphase(mm)=dreal(dcmplx(cphi,sphi)**mm)
     197     47692326 :            iphase(mm)=aimag(dcmplx(cphi,sphi)**mm)
     198              :          end do
     199              : 
     200              : !        Determine gradients of theta and phi
     201     17433448 :          if (optder/=0) then
     202      8985873 :            dtheta(1)=ctheta*cphi
     203      8985873 :            dtheta(2)=ctheta*sphi
     204      8985873 :            dtheta(3)=-stheta
     205      8985873 :            dphi(1)=-sphi
     206      8985873 :            dphi(2)=cphi
     207      8985873 :            dphi(3)=zero
     208              :          end if
     209              : 
     210              : !        COMPUTE Ylm(K)
     211              : !        ============================================
     212     17433448 :          if (optder>=0) then
     213              : !          Loop over angular momentum l
     214     47494006 :            do ilang=2,mpsang
     215     30156924 :              ll=ilang-1
     216     30156924 :              l0=ll**2+ll+1
     217     30156924 :              fact=1._dp/real(ll*(ll+1),dp)
     218     30156924 :              ylmcst=sqrt(real(2*ll+1,dp)/four_pi)
     219              : !            Special case m=0
     220     30156924 :              ylm(ikg+ipw,l0)=ylmcst*ass_leg_pol(ll,0,ctheta)
     221              : !            Compute for m>0
     222     30156924 :              onem=one
     223     93274342 :              do mm=1,ll
     224     45780336 :                onem=-onem
     225     45780336 :                work1=ylmcst*sqrt(fact)*onem*ass_leg_pol(ll,mm,ctheta)*sqrt(2._dp)
     226     45780336 :                ylm(ikg+ipw,l0+mm)=work1*rphase(mm)
     227     45780336 :                ylm(ikg+ipw,l0-mm)=work1*iphase(mm)
     228     75937260 :                if (mm/=ll) fact=fact/real((ll+mm+1)*(ll-mm),dp)
     229              :              end do ! End loop over m
     230              :            end do  ! End loop over l
     231              :          end if
     232              : 
     233              : !        COMPUTE dYlm/dKi
     234              : !        ============================================
     235     17433448 :          if (optder/=0) then
     236              : !          Loop over angular momentum l
     237     24006819 :            do ilang=2,mpsang
     238     15020946 :              ll=ilang-1
     239     15020946 :              l0=ll**2+ll+1
     240     15020946 :              fact=1._dp/real(ll*(ll+1),dp)
     241     15020946 :              ylmcst=sqrt(real(2*ll+1,dp)/four_pi)/rr
     242              : !            === Special case m=0 ===
     243              : !            1-compute gradients in cartesian coordinates
     244     15020946 :              work1=ylmcst*plm_dtheta(ll,0,ctheta)
     245     60083784 :              ylmgr_cart(1:3,1)=work1*dtheta(1:3)
     246              : !            2-Transfer gradients into reduced coordinates
     247     60083784 :              do ii=1,3
     248              :                ylmgr_red(ii,1)=(rprimd(1,ii)*ylmgr_cart(1,1)+&
     249              : &               rprimd(2,ii)*ylmgr_cart(2,1)+&
     250     60083784 : &               rprimd(3,ii)*ylmgr_cart(3,1))
     251              :              end do
     252              : !            3-Store gradients
     253     60083784 :              ylm_gr(ikg+ipw,1:3,l0) =ylmgr_red(1:3,1)
     254              : !            === Compute for m>0 ===
     255     15020946 :              onem=one
     256     45527535 :              do mm=1,ll
     257     21520716 :                onem=-onem
     258              : !              1-compute gradients in cartesian coordinates
     259     21520716 :                work1=ylmcst*sqrt(fact)*onem*plm_dtheta(ll,mm,ctheta)*sqrt(2._dp)
     260     21520716 :                work2=ylmcst*sqrt(fact)*onem*plm_dphi  (ll,mm,ctheta)*sqrt(2._dp)
     261     86082864 :                ylmgr_cart(1:3,1)=rphase(mm)*work1*dtheta(1:3)-iphase(mm)*work2*dphi(1:3)
     262     86082864 :                ylmgr_cart(1:3,2)=iphase(mm)*work1*dtheta(1:3)+rphase(mm)*work2*dphi(1:3)
     263              : !              2-Transfer gradients into reduced coordinates
     264     64562148 :                do kk=1,2
     265    193686444 :                  do ii=1,3
     266              :                    ylmgr_red(ii,kk)=(rprimd(1,ii)*ylmgr_cart(1,kk)+&
     267              : &                   rprimd(2,ii)*ylmgr_cart(2,kk)+&
     268    172165728 : &                   rprimd(3,ii)*ylmgr_cart(3,kk))
     269              :                  end do
     270              :                end do
     271              : !              3-Store gradients
     272     86082864 :                ylm_gr(ikg+ipw,1:3,l0+mm) =ylmgr_red(1:3,1)
     273     86082864 :                ylm_gr(ikg+ipw,1:3,l0-mm) =ylmgr_red(1:3,2)
     274     36541662 :                if (mm/=ll) fact=fact/real((ll+mm+1)*(ll-mm),dp)
     275              :              end do ! End loop over m
     276              :            end do  ! End loop over l
     277              :          end if
     278              : 
     279              : !        COMPUTE d2Ylm/dKidKj
     280              : !        ============================================
     281     17433448 :          if (optder==2) then
     282      4021783 :            call plm_coeff(blm,mpsang,ctheta)
     283              : !          Loop over angular momentum l
     284     11818557 :            do ilang=2,mpsang
     285      7796774 :              ll=ilang-1
     286      7796774 :              l0=ll**2+ll+1
     287      7796774 :              fact=1._dp/real(ll*(ll+1),dp)
     288      7796774 :              ylmcst=sqrt(real(2*ll+1,dp)/four_pi)/(rr**2)
     289              : !            === Special case m=0 ===
     290              : !            1-compute gradients in cartesian coordinates
     291      7796774 :              ylmgr2_cart(1,1,1)=ylmcst*(-blm(3,l0)*sphi*sphi+blm(4,l0)*cphi*cphi)
     292      7796774 :              ylmgr2_cart(2,2,1)=ylmcst*(-blm(3,l0)*cphi*cphi+blm(4,l0)*sphi*sphi)
     293      7796774 :              ylmgr2_cart(3,3,1)=ylmcst*blm(1,l0)
     294      7796774 :              ylmgr2_cart(3,1,1)=ylmcst*blm(2,l0)*cphi
     295      7796774 :              ylmgr2_cart(3,2,1)=ylmcst*blm(2,l0)*sphi
     296      7796774 :              ylmgr2_cart(2,1,1)=ylmcst*(blm(3,l0)+blm(4,l0))*sphi*cphi
     297      7796774 :              ylmgr2_cart(1,3,1)=ylmgr2_cart(3,1,1)
     298      7796774 :              ylmgr2_cart(1,2,1)=ylmgr2_cart(2,1,1)
     299      7796774 :              ylmgr2_cart(2,3,1)=ylmgr2_cart(3,2,1)
     300              : !            2-Transfer gradients into reduced coordinates
     301     31187096 :              do jj=1,3
     302    101358062 :                do ii=1,3
     303              :                  ylmgr2_tmp(ii,jj)=(rprimd(1,jj)*ylmgr2_cart(1,ii,1)+&
     304              : &                 rprimd(2,jj)*ylmgr2_cart(2,ii,1)+&
     305     93561288 : &                 rprimd(3,jj)*ylmgr2_cart(3,ii,1))
     306              :                end do
     307              :              end do
     308     54577418 :              do ii=1,6
     309     46780644 :                ia=alpha(ii);ib=beta(ii)
     310              :                ylmgr_red(ii,1)=(rprimd(1,ia)*ylmgr2_tmp(1,ib)+&
     311              : &               rprimd(2,ia)*ylmgr2_tmp(2,ib)+&
     312     54577418 : &               rprimd(3,ia)*ylmgr2_tmp(3,ib))
     313              :              end do
     314     54577418 :              ylm_gr(ikg+ipw,4:9,l0) =ylmgr_red(1:6,1)
     315              : !            === Compute for m>0 ===
     316      7796774 :              onem=one
     317     23720694 :              do mm=1,ll
     318     11902137 :                onem=-onem;ylmcst2=ylmcst*sqrt(fact)*sqrt(two)
     319              :                ylmgr2_cart(1,1,1)=ylmcst2*((-blm(3,l0+mm)*sphi*sphi+blm(4,l0+mm)*cphi*cphi)*rphase(mm)-&
     320     11902137 : &               blm(5,l0+mm)*2.d0*cphi*sphi*mm*iphase(mm))
     321              :                ylmgr2_cart(1,1,2)=ylmcst2*((-blm(3,l0+mm)*sphi*sphi+blm(4,l0+mm)*cphi*cphi)*iphase(mm)+&
     322     11902137 : &               blm(5,l0+mm)*2.d0*cphi*sphi*mm*rphase(mm))
     323              :                ylmgr2_cart(2,2,1)=ylmcst2*((-blm(3,l0+mm)*cphi*cphi+blm(4,l0+mm)*sphi*sphi)*rphase(mm)+&
     324     11902137 : &               blm(5,l0+mm)*2.d0*cphi*sphi*mm*iphase(mm))
     325              :                ylmgr2_cart(2,2,2)=ylmcst2*((-blm(3,l0+mm)*cphi*cphi+blm(4,l0+mm)*sphi*sphi)*iphase(mm)-&
     326     11902137 : &               blm(5,l0+mm)*2.d0*cphi*sphi*mm*rphase(mm))
     327     11902137 :                ylmgr2_cart(3,3,1)=ylmcst2*blm(1,l0+mm)*rphase(mm)
     328     11902137 :                ylmgr2_cart(3,3,2)=ylmcst2*blm(1,l0+mm)*iphase(mm)
     329              :                ylmgr2_cart(3,1,1)=ylmcst2*(blm(2,l0+mm)*cphi*rphase(mm)-&
     330     11902137 : &               mm*iphase(mm)*sphi*onem*plm_dtheta(ll,mm,ctheta))
     331              :                ylmgr2_cart(3,1,2)=ylmcst2*(blm(2,l0+mm)*cphi*iphase(mm)+&
     332     11902137 : &               mm*rphase(mm)*sphi*onem*plm_dtheta(ll,mm,ctheta))
     333              :                ylmgr2_cart(3,2,1)=ylmcst2*(blm(2,l0+mm)*sphi*rphase(mm)+&
     334     11902137 : &               mm*iphase(mm)*cphi*onem*plm_dtheta(ll,mm,ctheta))
     335              :                ylmgr2_cart(3,2,2)=ylmcst2*(blm(2,l0+mm)*sphi*iphase(mm)-&
     336     11902137 : &               mm*rphase(mm)*cphi*onem*plm_dtheta(ll,mm,ctheta))
     337              :                ylmgr2_cart(2,1,1)=ylmcst2*((blm(3,l0+mm)+blm(4,l0+mm))*sphi*cphi*rphase(mm)-&
     338     11902137 : &               blm(5,l0+mm)*(sphi*sphi-cphi*cphi)*mm*iphase(mm))
     339              :                ylmgr2_cart(2,1,2)=ylmcst2*((blm(3,l0+mm)+blm(4,l0+mm))*sphi*cphi*iphase(mm)+&
     340     11902137 : &               blm(5,l0+mm)*(sphi*sphi-cphi*cphi)*mm*rphase(mm))
     341     35706411 :                ylmgr2_cart(1,3,:)=ylmgr2_cart(3,1,:)
     342     35706411 :                ylmgr2_cart(1,2,:)=ylmgr2_cart(2,1,:)
     343     35706411 :                ylmgr2_cart(2,3,:)=ylmgr2_cart(3,2,:)
     344              : !              2-Transfer gradients into reduced coordinates
     345     35706411 :                do kk=1,2
     346     95217096 :                  do jj=1,3
     347    309455562 :                    do ii=1,3
     348              :                      ylmgr2_tmp(ii,jj)=(rprimd(1,jj)*ylmgr2_cart(1,ii,kk)+&
     349              : &                     rprimd(2,jj)*ylmgr2_cart(2,ii,kk)+&
     350    285651288 : &                     rprimd(3,jj)*ylmgr2_cart(3,ii,kk))
     351              :                    end do
     352              :                  end do
     353    178532055 :                  do ii=1,6
     354    142825644 :                    ia=alpha(ii);ib=beta(ii)
     355              :                    ylmgr_red(ii,kk)=(rprimd(1,ia)*ylmgr2_tmp(1,ib)+&
     356              : &                   rprimd(2,ia)*ylmgr2_tmp(2,ib)+&
     357    166629918 : &                   rprimd(3,ia)*ylmgr2_tmp(3,ib))
     358              :                  end do
     359              :                end do
     360     83314959 :                ylm_gr(ikg+ipw,4:9,l0+mm) =ylmgr_red(1:6,1)
     361     83314959 :                ylm_gr(ikg+ipw,4:9,l0-mm) =ylmgr_red(1:6,2)
     362     19698911 :                if (mm/=ll) fact=fact/real((ll+mm+1)*(ll-mm),dp)
     363              :              end do ! End loop over m
     364              :            end do  ! End loop over l
     365              :          end if
     366              : 
     367              : !        End condition r<>0
     368              :        end if
     369              : 
     370              : !      End loop over k+G
     371              :      end do
     372              : 
     373              : !    End condition l<>0
     374              :    end if
     375              : 
     376       130749 :    ABI_FREE(kg_k)
     377              : 
     378       170471 :    ikg=ikg+npw_k
     379              :  end do !  End Loop over k-points
     380              : 
     381              : !Release the temporary memory
     382              : !Allocate some memory
     383         8420 :  if (optder/=0) then
     384         3679 :    ABI_FREE(ylmgr_cart)
     385              :  end if
     386         8420 :  if (optder/=0.and.optder/=2) then
     387         2993 :    ABI_FREE(ylmgr_red)
     388              :  end if
     389         8420 :  if (optder==2) then
     390          686 :    ABI_FREE(ylmgr2_cart)
     391          686 :    ABI_FREE(ylmgr2_tmp)
     392          686 :    ABI_FREE(ylmgr_red)
     393          686 :    ABI_FREE(blm)
     394              :  end if
     395              : 
     396         8420 : end subroutine initylmg
     397              : !!***
     398              : 
     399              : !!****f* ABINIT/initylmg_k
     400              : !! NAME
     401              : !! initylmg_k
     402              : !!
     403              : !! FUNCTION
     404              : !! Simplified interface to compute Ylm for a single k-point.
     405              : !! See initylmg for the the meaning of the input variables.
     406              : !!
     407              : !! SOURCE
     408              : 
     409          951 : subroutine initylmg_k(npw_k, mpsang, optder, rprimd, gprimd, kpt, kg_k, ylm_k, ylm_gr_k)
     410              : 
     411              : !Arguments ------------------------------------
     412              : !scalars
     413              :  integer,intent(in) :: mpsang, npw_k, optder
     414              : !arrays
     415              :  real(dp),intent(in) :: kpt(3)
     416              :  integer,intent(in) :: kg_k(3,npw_k)
     417              :  real(dp),intent(in) :: gprimd(3,3), rprimd(3,3)
     418              :  real(dp),intent(out) :: ylm_k(npw_k, mpsang*mpsang)
     419              :  real(dp),intent(out) :: ylm_gr_k(npw_k, 3+6*(optder/2), mpsang*mpsang)
     420              : 
     421              : !Local variables ------------------------------
     422              : !scalars
     423              :  integer,parameter :: nkpt_1 = 1, nsppol_1 = 1
     424              :  integer :: npwarr__(nkpt_1), nband__(nkpt_1 * nsppol_1)
     425              :  real(dp) :: kptns__(3,nkpt_1)
     426          951 :  type(MPI_type) :: seq_mpi_enreg
     427              : !*****************************************************************
     428              : 
     429          951 :  call initmpi_seq(seq_mpi_enreg)
     430          951 :  npwarr__(1) = npw_k
     431          951 :  kptns__(:,1) = kpt
     432         1902 :  nband__ = 1 ! Not used in sequential
     433              : 
     434              :  call initylmg(gprimd, kg_k, kptns__, nkpt_1, seq_mpi_enreg, mpsang, npw_k, &
     435          951 :                nband__, nkpt_1, npwarr__, nsppol_1, optder, rprimd, ylm_k, ylm_gr_k)
     436              : 
     437          951 :  call destroy_mpi_enreg(seq_mpi_enreg)
     438              : 
     439          951 : end subroutine initylmg_k
     440              : !!***
     441              : 
     442              : end module m_initylmg
     443              : !!***
        

Generated by: LCOV version 2.3-1