LCOV - code coverage report
Current view: top level - shared/common/src/28_numeric_noabirule - abi_xorthonormalize.f90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 57.1 % 35 20
Test Date: 2026-11-10 12:08:57 Functions: 66.7 % 3 2
Branches: 42.9 % 14 6

             Branch data     Line data    Source code
       1                 :             : !{\src2tex{textfont=tt}}
       2                 :             : !!****f* m_abi_linalg/abi_xorthonormalize
       3                 :             : !! NAME
       4                 :             : !!  abi_xorthonormalize
       5                 :             : !!
       6                 :             : !! FUNCTION
       7                 :             : !!  abi_xorthonormalize is the generic function for computing the
       8                 :             : !!  overlap of two complex wavefunctions (for a given number of bands)
       9                 :             : !!  and orthonormalizes it:
      10                 :             : !!
      11                 :             : !! COPYRIGHT
      12                 :             : !!  Copyright (C) 2001-2026 ABINIT group (LNguyen,FDahm (CS), FBottin, GZ, AR, MT)
      13                 :             : !!  This file is distributed under the terms of the
      14                 :             : !!  GNU General Public License, see ~abinit/COPYING
      15                 :             : !!  or http://www.gnu.org/copyleft/gpl.txt .
      16                 :             : !!
      17                 :             : !! SOURCE
      18                 :             : 
      19                 :             : !!***
      20                 :             : 
      21                 :             : !!****f* m_abi_linalg/xorthonormalize
      22                 :             : !! NAME
      23                 :             : !!  xorthonormalize
      24                 :             : !!
      25                 :             : !! FUNCTION
      26                 :             : !!  This routine computes the overlap of two complex wavefunctions (for a given number of bands)
      27                 :             : !!  and orthonormalizes it:
      28                 :             : !!      - Computes the products of two rectangular matrices
      29                 :             : !!         containing the wavefunctions psi and S.psi (where S is the
      30                 :             : !!         overlap (with the PAW terms if necessary)).
      31                 :             : !!      - Does a Cholesky decomposition of this overlap
      32                 :             : !!      - rotates the initial matrix blockvectorx by the triangular matrix to
      33                 :             : !!         have an orthonormal set of wavefunctions
      34                 :             : !!
      35                 :             : !! INPUTS
      36                 :             : !!  blockvectorbx = matrix of dimension (blocksize,vectsize)
      37                 :             : !!                  (e.g. block of overlap*wavefunction)
      38                 :             : !!  blocksize     = dimension of matrices (e.g number of bands)
      39                 :             : !!  spaceComm     = communicator used for MPI parallelization
      40                 :             : !!  vectsize      = dimension of matrices (e.g number of G vector)
      41                 :             : !!
      42                 :             : !! OUTPUT
      43                 :             : !!  sqgram        = Choleski decomposition of transpose(blockvector)*blockvectorx
      44                 :             : !!
      45                 :             : !! SIDE EFFECTS
      46                 :             : !!  blockvectorx  = on input, matrix of dimension (vectsize,blocksize)
      47                 :             : !!                  (e.g block of wavefunction)
      48                 :             : !!  blockvectorx  = on output, orthonormalized wavefunction.
      49                 :             : !!
      50                 :             : !!
      51                 :             : !! SOURCE
      52                 :             : 
      53                 :      115668 : subroutine xorthonormalize(blockvectorx,blockvectorbx,blocksize,spaceComm,sqgram,vectsize,&
      54                 :             : &                          x_cplx,timopt,tim_xortho) ! optional arguments
      55                 :             : 
      56                 :             : !Arguments ------------------------------------
      57                 :             : !scalars
      58                 :             :  integer,intent(in) :: blocksize,vectsize,spaceComm,x_cplx
      59                 :             :  integer, intent(in), optional :: timopt,tim_xortho
      60                 :             :  !arrays
      61                 :             :  real(dp),intent(in) :: blockvectorbx(vectsize,blocksize)
      62                 :             :  real(dp),intent(inout) :: blockvectorx(vectsize,blocksize)
      63                 :             :  real(dp),intent(out) :: sqgram(x_cplx*blocksize,blocksize)
      64                 :             : 
      65                 :             : !Local variables-------------------------------
      66                 :             :  real(dp) :: tsec(2)
      67                 :             :  integer  :: ierr,info
      68                 :             :  character(len=500) :: message
      69                 :             :  character, dimension(2) :: cparam
      70                 :             : 
      71                 :             :  ! *********************************************************************
      72                 :             : 
      73         [ +  - ]:       57834 :  if (present(tim_xortho).and.present(timopt)) then
      74         [ -  + ]:       57834 :    if(abs(timopt)==3) then
      75                 :           0 :      call timab(tim_xortho,1,tsec)
      76                 :             :    end if
      77                 :             :  end if
      78                 :             : 
      79                 :       57834 :  cparam(1)='t'
      80                 :       57834 :  cparam(2)='c'
      81                 :             : 
      82                 :             :  call abi_xgemm(cparam(x_cplx),'n',blocksize,blocksize,vectsize,cone,blockvectorx,&
      83                 :       57834 : &   vectsize,blockvectorbx,vectsize,czero,sqgram,blocksize,x_cplx=x_cplx)
      84                 :             : 
      85                 :       57834 :  call xmpi_sum(sqgram,spaceComm,ierr)
      86                 :             : 
      87                 :             :  !Cholesky factorization of sqgram (ouside upper Triangular of sqgram)
      88                 :       57834 :  call abi_xpotrf('u',blocksize,sqgram,blocksize,info,x_cplx=x_cplx)
      89                 :             : 
      90         [ -  + ]:       57834 :  if (info /= 0 )  then
      91                 :           0 :    write(message,'(a,i0)')'abi_xpotrf, info=',info
      92                 :           0 :    ABI_ERROR(message)
      93                 :             :  end if
      94                 :             : 
      95                 :             :  !Find X  X*sqgram=blockvectorx
      96                 :             :  call abi_xtrsm('r','u','n','n',vectsize,blocksize,cone,sqgram,blocksize,&
      97                 :       57834 : &   blockvectorx,vectsize,x_cplx=x_cplx)
      98                 :             : 
      99         [ +  - ]:       57834 :  if (present(tim_xortho).and.present(timopt)) then
     100         [ -  + ]:       57834 :    if(abs(timopt)==3) then
     101                 :           0 :      call timab(tim_xortho,2,tsec)
     102                 :             :    end if
     103                 :             :  end if
     104                 :             : 
     105                 :       57834 : end subroutine xorthonormalize
     106                 :             : !!***
     107                 :             : 
     108                 :             : !!****f* ABINIT/ortho_reim
     109                 :             : !! NAME
     110                 :             : !! ortho_reim
     111                 :             : !!
     112                 :             : !! FUNCTION
     113                 :             : !! This routine computes the overlap of two wavefunctions (for a given number of bands)
     114                 :             : !! and orthonormalizes it:
     115                 :             : !!      - Computes the products of two rectangular matrices
     116                 :             : !!         containing the wavefunctions psi and S.psi (where S is the
     117                 :             : !!         overlap (with the PAW terms if necessary)).
     118                 :             : !!      - Does a Cholesky decomposition of this overlap
     119                 :             : !!      - rotates the initial matrix blockvectorx by the triangular matrix to
     120                 :             : !!         have an orthonormal set of wavefunctions
     121                 :             : !!
     122                 :             : !! This version operates on arrays in which the real and the imaginary part
     123                 :             : !! are packed together (real parts first, them imaginary parts), used when istwfk=2
     124                 :             : !!
     125                 :             : !! INPUTS
     126                 :             : !!  blockvectorbx = matrix of dimension (blocksize,vectsize)
     127                 :             : !!                  (e.g. block of overlap*wavefunction)
     128                 :             : !!  blocksize     = dimension of matrices (e.g number of bands)
     129                 :             : !!  spaceComm     = communicator used for MPI parallelization
     130                 :             : !!  vectsize      = dimension of matrices (e.g number of G vector)
     131                 :             : !!
     132                 :             : !! OUTPUT
     133                 :             : !!  sqgram        = Choleski decomposition of transpose(blockvector)*blockvectorx
     134                 :             : !!
     135                 :             : !! SIDE EFFECTS
     136                 :             : !!  blockvectorx  = on input, matrix of dimension (vectsize,blocksize)
     137                 :             : !!                  (e.g block of wavefunction)
     138                 :             : !!  blockvectorx  = on output, orthonormalized wavefunction.
     139                 :             : !!
     140                 :             : !! SOURCE
     141                 :             : 
     142                 :           0 : subroutine ortho_reim(blockvectorx,blockvectorbx,blocksize,spaceComm,sqgram,vectsize)
     143                 :             : 
     144                 :             : !Arguments ------------------------------------
     145                 :             : !scalars
     146                 :             :  integer,intent(in) :: blocksize,vectsize,spaceComm
     147                 :             : !arrays
     148                 :             :  real(dp),intent(in) :: blockvectorbx(vectsize,blocksize)
     149                 :             :  real(dp),intent(inout) :: blockvectorx(vectsize,blocksize)
     150                 :             :  real(dp),intent(out) :: sqgram(blocksize,blocksize)
     151                 :             : 
     152                 :             : !Local variables-------------------------------
     153                 :             : !scalars
     154                 :             :  integer :: ierr,info
     155                 :             :  character(len=500) :: message
     156                 :             : 
     157                 :             : ! *********************************************************************
     158                 :             : 
     159                 :             :  call abi_xgemm('t','n',blocksize,blocksize,vectsize,cone,blockvectorx,&
     160                 :           0 : &   vectsize,blockvectorbx,vectsize,czero,sqgram,blocksize)
     161                 :             : 
     162                 :           0 :  call xmpi_sum(sqgram,spaceComm,ierr)
     163                 :             : 
     164                 :             :  !Cholesky factorization of sqgram (ouside upper Triangular of sqgram)
     165                 :           0 :  call abi_d2zpotrf('u',blocksize,sqgram,blocksize,info) !vz_d
     166                 :             : 
     167         [ #  # ]:           0 :  if (info /= 0 )  then
     168                 :           0 :    write(message,'(a,i0)')'dpotrf, info=',info
     169                 :           0 :    ABI_ERROR(message)
     170                 :             :  end if
     171                 :             : 
     172                 :             : !Find X  X*sqgram=blockvectorx
     173                 :           0 :  call abi_xtrsm('r','u','n','n',vectsize,blocksize,one,sqgram,blocksize,blockvectorx,vectsize)
     174                 :             : 
     175                 :           0 : end subroutine ortho_reim
     176                 :             : !!***
     177                 :             : 
     178                 :             : 
     179                 :             : !!****f* ABINIT/zorthonormalize
     180                 :             : !! NAME
     181                 :             : !! zorthonormalize
     182                 :             : !!
     183                 :             : !! FUNCTION
     184                 :             : !! This routine computes the overlap of two complex wavefunctions (for a given number of bands)
     185                 :             : !! and orthonormalizes it:
     186                 :             : !!      - Computes the products of two rectangular matrices
     187                 :             : !!         containing the wavefunctions psi and S.psi (where S is the
     188                 :             : !!         overlap (with the PAW terms if necessary)).
     189                 :             : !!      - Does a Cholesky decomposition of this overlap
     190                 :             : !!      - rotates the initial matrix blockvectorx by the triangular matrix to
     191                 :             : !!         have an orthonormal set of wavefunctions
     192                 :             : !!
     193                 :             : !! INPUTS
     194                 :             : !!  blockvectorbx = matrix of dimension (blocksize,vectsize)
     195                 :             : !!                  (e.g. block of overlap*wavefunction)
     196                 :             : !!  blocksize     = dimension of matrices (e.g number of bands)
     197                 :             : !!  spaceComm     = communicator used for MPI parallelization
     198                 :             : !!  vectsize      = dimension of matrices (e.g number of G vector)
     199                 :             : !!
     200                 :             : !! OUTPUT
     201                 :             : !!  sqgram        = Choleski decomposition of transpose(blockvector)*blockvectorx
     202                 :             : !!
     203                 :             : !! SIDE EFFECTS
     204                 :             : !!  blockvectorx  = on input, matrix of dimension (vectsize,blocksize)
     205                 :             : !!                  (e.g block of wavefunction)
     206                 :             : !!  blockvectorx  = on output, orthonormalized wavefunction.
     207                 :             : !!
     208                 :             : !!
     209                 :             : !! SOURCE
     210                 :             : 
     211                 :          32 : subroutine zorthonormalize(blockvectorx,blockvectorbx,blocksize,spaceComm,sqgram,vectsize)
     212                 :             : 
     213                 :             : !Arguments ------------------------------------
     214                 :             : !scalars
     215                 :             :  integer,intent(in) :: blocksize,spaceComm,vectsize
     216                 :             : !arrays
     217                 :             :  complex(dp),intent(in) :: blockvectorbx(vectsize,blocksize)
     218                 :             :  complex(dp),intent(inout) :: blockvectorx(vectsize,blocksize)
     219                 :             :  complex(dp),intent(out) :: sqgram(blocksize,blocksize)
     220                 :             : 
     221                 :             : !Local variables-------------------------------
     222                 :             : !scalars
     223                 :             :  integer :: ierr,info
     224                 :             :  character(len=500) :: message
     225                 :             : 
     226                 :             : ! *********************************************************************
     227                 :             : 
     228                 :             :  call abi_xgemm('c','n',blocksize,blocksize,vectsize,cone,blockvectorx,&
     229                 :          32 : & vectsize,blockvectorbx,vectsize,czero,sqgram,blocksize)
     230                 :             : 
     231                 :          32 :  call xmpi_sum(sqgram,spaceComm,ierr)
     232                 :             : 
     233                 :          32 :  call abi_xpotrf('u',blocksize,sqgram,blocksize,info)
     234                 :             : 
     235         [ -  + ]:          32 :  if (info /= 0 )  then
     236                 :           0 :    write(message,'(a,i0)')'zpotrf, info=',info
     237                 :           0 :    ABI_ERROR(message)
     238                 :             :  end if
     239                 :             : 
     240                 :          32 :  call abi_xtrsm('r','u','n','n',vectsize,blocksize,cone,sqgram,blocksize,blockvectorx,vectsize)
     241                 :             : 
     242                 :          32 : end subroutine zorthonormalize
     243                 :             : !!***
     244                 :             : 
        

Generated by: LCOV version 2.3-1