LCOV - code coverage report
Current view: top level - src/55_abiutil - m_builtin_tests.F90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 74.2 % 132 98
Test Date: 2026-11-09 12:18:26 Functions: 100.0 % 1 1
Branches: 81.7 % 82 67

             Branch data     Line data    Source code
       1                 :             : !!****m* ABINIT/m_builtin_tests
       2                 :             : !! NAME
       3                 :             : !!  m_builtin_tests
       4                 :             : !!
       5                 :             : !! FUNCTION
       6                 :             : !!
       7                 :             : !!
       8                 :             : !! COPYRIGHT
       9                 :             : !!  Copyright (C) 1998-2026 ABINIT group (DCA,XG,GMR)
      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                 :             : #if defined HAVE_CONFIG_H
      17                 :             : #include "config.h"
      18                 :             : #endif
      19                 :             : 
      20                 :             : #include "abi_common.h"
      21                 :             : 
      22                 :             : module m_builtin_tests
      23                 :             : 
      24                 :             :  use defs_basis
      25                 :             :  use m_errors
      26                 :             :  use m_abicore
      27                 :             : 
      28                 :             :  use m_io_tools,     only : open_file
      29                 :             : 
      30                 :             :  implicit none
      31                 :             : 
      32                 :             :  private
      33                 :             : !!***
      34                 :             : 
      35                 :             :  public :: testfi
      36                 :             : !!***
      37                 :             : 
      38                 :             : contains
      39                 :             : !!***
      40                 :             : 
      41                 :             : !!****f* ABINIT/testfi
      42                 :             : !!
      43                 :             : !! NAME
      44                 :             : !! testfi
      45                 :             : !!
      46                 :             : !! FUNCTION
      47                 :             : !! Routine "Final test" for generation of the test report in the status file:
      48                 :             : !! if it appears that the run was a "Built-in Test", then
      49                 :             : !! compare the final values of different quantities to the reference
      50                 :             : !! values, here hard-coded.
      51                 :             : !!
      52                 :             : !! INPUTS
      53                 :             : !!  builtintest=number of the builtintest, from the input file.
      54                 :             : !!  etotal=total energy (sum of 7 contributions) (hartree)
      55                 :             : !!  filstat=name of the status file
      56                 :             : !!  gred(3,natom)=symmetrized gradient of etotal with respect to tn
      57                 :             : !!  natom=number of atoms in cell.
      58                 :             : !!  strten(6)=components of the stress tensor (hartree/bohr^3)
      59                 :             : !!  xred(3,natom)=reduced atomic coordinates
      60                 :             : !!
      61                 :             : !! OUTPUT
      62                 :             : !!  (only writing)
      63                 :             : !!
      64                 :             : !! SOURCE
      65                 :             : 
      66                 :          12 : subroutine testfi(builtintest,etotal,filstat,gred,natom,strten,xred)
      67                 :             : 
      68                 :             : !Arguments ------------------------------------
      69                 :             : !scalars
      70                 :             :  integer,intent(in) :: builtintest,natom
      71                 :             :  real(dp),intent(in) :: etotal
      72                 :             :  character(len=fnlen),intent(in) :: filstat
      73                 :             : !arrays
      74                 :             :  real(dp),intent(in) :: gred(3,natom),strten(6),xred(3,natom)
      75                 :             : 
      76                 :             : !Local variables-------------------------------
      77                 :             :  character(len=fnlen) :: testname(7)='         '
      78                 :             :  character(len=*), parameter :: format01000="(a,d22.14,a,d12.4)"
      79                 :             :  character(len=500) :: msg
      80                 :             : !scalars
      81                 :             :  integer,parameter :: mtest=7
      82                 :             :  integer :: iatom,ii,problem,tok,temp_unit
      83                 :             :  real(dp) :: etot_mxdev,etot_ref,gred_mxdev,strten_mxdev,xred_mxdev
      84                 :             : !arrays
      85                 :             :  integer,parameter :: natom_test(mtest)=(/2,1,2,1,1,1,2/)
      86                 :             :  real(dp) :: gred_ref(3,2),strten_ref(6),xred_ref(3,2)
      87                 :             : 
      88                 :             : ! ***********************************************************************
      89                 :             : 
      90                 :          12 :  testname(1)='fast'
      91                 :          12 :  testname(2)='v1'
      92                 :          12 :  testname(3)='v5'
      93                 :          12 :  testname(4)='bigdft'
      94                 :          12 :  testname(5)='etsf_io'
      95                 :          12 :  testname(6)='libxc'
      96                 :          12 :  testname(7)='wannier90'
      97                 :             : 
      98                 :             : !---------------------------------------------------------
      99                 :             : 
     100                 :             : !Now, open the status file, and either delete it, or produce a report
     101         [ -  + ]:          12 :  if (open_file(filstat,msg,newunit=temp_unit,form='formatted',status='unknown') /= 0) then
     102                 :           0 :    ABI_ERROR(msg)
     103                 :             :  end if
     104                 :             : 
     105         [ -  + ]:          12 :  if(builtintest==0)then
     106                 :             : 
     107                 :           0 :    close (temp_unit,status='delete')
     108                 :             : 
     109                 :             :  else
     110                 :             : 
     111                 :             : !  Note: all processors have their own file, so no special attention must be paid to the parallel case.
     112                 :          12 :    write(temp_unit,*)
     113         [ +  - ]:          12 :    write(temp_unit,*)'Status file, reporting on built-in test ',trim(testname(builtintest))
     114                 :          12 :    write(temp_unit,*)
     115                 :             : 
     116                 :             : !  Define reference values, as well as maximum tolerable deviation
     117                 :             :    if(builtintest==1)then
     118                 :             : 
     119                 :           2 :      etot_ref=-1.05814441948188d+00
     120                 :           2 :      etot_mxdev=1.0d-9
     121         [ +  + ]:           8 :      xred_ref(1:3,1)=(/ -0.65048430042634D-01 , 0.0_dp , 0.0_dp /)
     122         [ +  + ]:           8 :      xred_ref(1:3,2)=(/  0.65048430042634D-01 , 0.0_dp , 0.0_dp /)
     123                 :             : !    xred(*,*) are reduced coordinates
     124                 :           2 :      xred_mxdev=1.0d-6
     125                 :           2 :      gred_ref(1:3,1:2)= 0.0_dp
     126                 :             : !    gred(*,*) are gradients with respect to reduced coordinates
     127                 :           2 :      gred_mxdev=5.0d-4
     128                 :             :      strten_ref(1:6)=(/ 0.149D-04  , 0.560D-04 , 0.560D-04 ,&
     129                 :           2 : &     0.0_dp , 0.0_dp , 0.0_dp /)
     130                 :           2 :      strten_mxdev=1.0d-5
     131                 :             : 
     132                 :             :    else if(builtintest==2)then
     133                 :             : 
     134                 :             : !    This value of etot is accurate to about 1.0d-12
     135                 :           2 :      etot_ref=-.70811958266295D+02
     136                 :             : !    Initialisation conditions might give fluctuations
     137                 :           2 :      etot_mxdev=3.0d-7
     138         [ +  + ]:           8 :      xred_ref(1:3,1)=(/ 0.0_dp , 0.0_dp , 0.0_dp /)
     139                 :           2 :      xred_mxdev=1.0d-12
     140         [ +  + ]:           8 :      gred_ref(1:3,1)=(/ 0.0_dp , 0.0_dp , 0.0_dp /)
     141                 :           2 :      gred_mxdev=1.0d-12
     142                 :             : !    This value of strten is accurate to at least 1.0d-8
     143         [ +  + ]:           8 :      strten_ref(1:3)= 5.09324870E-03
     144         [ +  + ]:           8 :      strten_ref(4:6)= 0.0_dp
     145                 :           2 :      strten_mxdev=1.0d-6
     146                 :             : 
     147                 :             :    else if(builtintest==3)then
     148                 :             : 
     149                 :           2 :      etot_ref=-.892746696311772D+01
     150                 :           2 :      etot_mxdev=1.0d-8
     151         [ +  + ]:           8 :      xred_ref(1:3,1)=(/ -0.125_dp , 0.0_dp , 0.0_dp /)
     152         [ +  + ]:           8 :      xred_ref(1:3,2)=(/  0.125_dp , 0.0_dp , 0.0_dp /)
     153                 :           2 :      xred_mxdev=1.0d-12
     154         [ +  + ]:           8 :      gred_ref(1:3,1)=(/ -.140263620278D+00 , 0.0_dp , 0.0_dp /)
     155         [ +  + ]:           8 :      gred_ref(1:3,2)=(/  .140013483725D+00 , 0.0_dp , 0.0_dp /)
     156                 :           2 :      gred_mxdev=1.0d-3
     157                 :           2 :      strten_ref(1:6)=(/  1.3949d-3 ,  1.3643d-3 , 1.3643d-3 ,.0_dp ,  .0_dp  ,  .0_dp    /)
     158                 :           2 :      strten_mxdev=1.0d-5
     159                 :             : 
     160                 :             : !    Bigdft
     161                 :             :    else if(builtintest==4)then
     162                 :             : 
     163                 :             : !    This value of etot is accurate to about 1.0d-12
     164                 :           0 :      etot_ref=-0.56231990141D+00
     165                 :             : !    Initialisation conditions might give fluctuations
     166                 :           0 :      etot_mxdev=3.0d-7
     167         [ #  # ]:           0 :      xred_ref(1:3,1)=(/ 0.5_dp , 0.5_dp , 0.5_dp /)
     168                 :           0 :      xred_mxdev=1.0d-12
     169         [ #  # ]:           0 :      gred_ref(1:3,1)=(/ 0.0_dp , 0.0_dp , 0.0_dp /)
     170                 :           0 :      gred_mxdev=1.0d-12
     171                 :           0 :      strten_ref(1)=-0.22537238382D-01
     172                 :           0 :      strten_ref(2)=-0.22536232141D-01
     173                 :           0 :      strten_ref(3)=-0.22529038043D-01
     174                 :           0 :      strten_ref(4)= 0.39104928264D-06
     175                 :           0 :      strten_ref(5)= 0.62823846408D-06
     176                 :           0 :      strten_ref(6)= 0.38414125548E-09
     177                 :           0 :      strten_mxdev=1.0d-7
     178                 :             : 
     179                 :             : !    ETSF_IO
     180                 :             :    else if(builtintest==5)then
     181                 :             : 
     182                 :             : !    This value of etot is accurate to about 1.0d-12
     183                 :           2 :      etot_ref=-0.33307825915795D+02
     184                 :             : !    Initialisation conditions might give fluctuations
     185                 :           2 :      etot_mxdev=3.0d-7
     186         [ +  + ]:           8 :      xred_ref(1:3,1)=(/ 0.0_dp , 0.0_dp , 0.0_dp /)
     187                 :           2 :      xred_mxdev=1.0d-12
     188         [ +  + ]:           8 :      gred_ref(1:3,1)=(/ 0.0_dp , -0.000000120877_dp , -0.000000164287_dp /)
     189                 :           2 :      gred_mxdev=1.0d-7
     190                 :             : !    This value of strten is accurate to at least 1.0d-8
     191                 :           2 :      strten_ref(1)= 0.13569940015175D-01
     192                 :           2 :      strten_ref(2)= 0.33822108610352D-01
     193                 :           2 :      strten_ref(3)= 0.37991262607028D-01
     194         [ +  + ]:           8 :      strten_ref(4:6)= 0.0_dp
     195                 :           2 :      strten_mxdev=1.0d-6
     196                 :             : 
     197                 :             : !    LibXC
     198                 :             :    else if(builtintest==6)then
     199                 :             : 
     200                 :             : !    etot_ref=-0.55196688523897D+01
     201                 :           2 :      etot_ref=-0.55198762022478D+01
     202                 :           2 :      etot_mxdev=5.0d-7
     203         [ +  + ]:           8 :      xred_ref(1:3,1)=(/ 0.0_dp , 0.0_dp , 0.0_dp /)
     204                 :           2 :      xred_mxdev=1.0d-12
     205         [ +  + ]:           8 :      gred_ref(1:3,1)=(/ 0.0_dp , 0.0_dp , 0.0_dp /)
     206                 :           2 :      gred_mxdev=1.0d-12
     207                 :             : !    strten_ref(1:3)= 0.13246699375127D-04
     208         [ +  + ]:           8 :      strten_ref(1:3)= 8.73600436E-06
     209         [ +  + ]:           8 :      strten_ref(4:6)= 0.0_dp
     210                 :           2 :      strten_mxdev=1.0d-8
     211                 :             : 
     212                 :             : !    Wannier90
     213                 :             :    else if(builtintest==7)then
     214                 :             : 
     215                 :             : !    This value of etot is accurate to about 1.0d-12
     216                 :           2 :      etot_ref=-0.10620085133544D+02
     217                 :             : !    Initialisation conditions might give fluctuations
     218                 :           2 :      etot_mxdev=3.0d-7
     219         [ +  + ]:           8 :      xred_ref(1:3,1)=(/ 0.0_dp , 0.0_dp , 0.0_dp /)
     220         [ +  + ]:           8 :      xred_ref(1:3,2)=(/ 0.25_dp , 0.25_dp , 0.25_dp /)
     221                 :           2 :      xred_mxdev=1.0d-12
     222         [ +  + ]:           8 :      gred_ref(1:3,1)=(/ 0.0_dp , 0.0_dp , 0.0_dp /)
     223         [ +  + ]:           8 :      gred_ref(1:3,2)=(/ 0.0_dp , 0.0_dp , 0.0_dp /)
     224                 :           2 :      gred_mxdev=1.0d-12
     225                 :             : !    This value of strten is accurate to at least 1.0d-8
     226         [ +  + ]:           8 :      strten_ref(1:3)=0.31413922197317D-03
     227         [ +  + ]:           8 :      strten_ref(4:6)= 0.0_dp
     228                 :           2 :      strten_mxdev=1.0d-6
     229                 :             : 
     230                 :             : !    End of the reference value set up, for different tests
     231                 :             :    end if
     232                 :             : 
     233                 :             : !  Compare reference and actual values
     234                 :             : 
     235                 :          12 :    problem=0
     236                 :             : 
     237                 :             : !  Take care of total energy
     238         [ -  + ]:          12 :    if(abs(etot_ref-etotal)>etot_mxdev)then
     239                 :           0 :      problem=1
     240                 :           0 :      write(temp_unit,'(a)')' Error for total energy : '
     241                 :           0 :      write(temp_unit,format01000)'        expected ',etot_ref,'  with maximum   deviation',etot_mxdev
     242                 :           0 :      write(temp_unit,format01000)'        computed ',etotal,'  with effective deviation',abs(etotal-etot_ref)
     243                 :             :    end if
     244                 :             : 
     245                 :             : !  Take care of nuclei positions
     246                 :          12 :    tok=1
     247         [ +  + ]:          30 :    do iatom=1,natom
     248         [ +  + ]:          84 :      do ii=1,3
     249         [ -  + ]:          72 :        if(abs(xred_ref(ii,iatom)-xred(ii,iatom))>xred_mxdev)then
     250                 :           0 :          tok=0
     251                 :           0 :          write(temp_unit, '(a,i1,a,i1,a)' )' Error for nuclei position xred(',ii,',',iatom,')'
     252                 :           0 :          write(temp_unit,format01000)'        expected ',xred_ref(ii,iatom),'  with maximum   deviation',xred_mxdev
     253                 :           0 :          write(temp_unit,format01000)'        computed ',xred(ii,iatom),'  with effective deviation',&
     254                 :           0 : &         abs( xred(ii,iatom)-xred_ref(ii,iatom) )
     255                 :             :        end if
     256                 :             :      end do
     257                 :             :    end do
     258         [ -  + ]:          12 :    if(tok==0)problem=1
     259                 :             : 
     260                 :             : !  Take care of forces
     261                 :          12 :    tok=1
     262         [ +  + ]:          30 :    do iatom=1,natom
     263         [ +  + ]:          84 :      do ii=1,3
     264         [ -  + ]:          54 :        if(abs(gred_ref(ii,iatom)-gred(ii,iatom))&
     265                 :          18 : &       >gred_mxdev)then
     266                 :           0 :          tok=0
     267                 :           0 :          write(temp_unit, '(a,i1,a,i1,a)' )' Error for gradients gred(',ii,',',iatom,')'
     268                 :           0 :          write(temp_unit,format01000)'        expected ',gred_ref(ii,iatom),'  with maximum   deviation',gred_mxdev
     269                 :           0 :          write(temp_unit,format01000)'        computed ',gred(ii,iatom),'  with effective deviation',&
     270                 :           0 : &         abs( gred(ii,iatom)-gred_ref(ii,iatom) )
     271                 :             :        end if
     272                 :             :      end do
     273                 :             :    end do
     274         [ -  + ]:          12 :    if(tok==0)problem=1
     275                 :             : 
     276                 :             : !  Take care of stress
     277                 :          12 :    tok=1
     278         [ +  + ]:          84 :    do ii=1,6
     279         [ -  + ]:          84 :      if(abs(strten_ref(ii)-strten(ii))>strten_mxdev)then
     280                 :           0 :        tok=0
     281                 :           0 :        write(temp_unit,'(a,i1,a)')' Error for stress strten(',ii,')'
     282                 :           0 :        write(temp_unit,format01000)'        expected ',strten_ref(ii),'  with maximum   deviation',strten_mxdev
     283                 :           0 :        write(temp_unit,format01000)'        computed ',strten(ii),'  with effective deviation',&
     284                 :           0 : &       abs( strten(ii)-strten_ref(ii) )
     285                 :             :      end if
     286                 :             :    end do
     287         [ +  - ]:          12 :    if(tok==0)problem=1
     288                 :             : 
     289         [ +  - ]:          12 :    if(problem==0)then
     290                 :          12 :      write(temp_unit,'(a)')' ==> The run finished cleanly.'
     291                 :          12 :      write(temp_unit,'(a,a)')'     Moreover, comparison of the total energy, and other (few) ',&
     292                 :          24 : &     'relevant quantities with reference values has been successful.'
     293                 :          12 :      write(temp_unit,'(a)')'     This does not mean that no problem is present, however. '
     294                 :          12 :      write(temp_unit,'(a)')'     Please run the complete set of ABINIT tests to gain a better confidence in your installation.'
     295                 :             :    end if
     296                 :             : 
     297                 :          12 :    write(temp_unit,*)
     298                 :             : 
     299                 :          12 :    close(temp_unit)
     300                 :             : 
     301                 :             :  end if !  End of the choice between produce a report, and produce no report
     302                 :             : 
     303                 :          12 : end subroutine testfi
     304                 :             : !!***
     305                 :             : 
     306                 :             : end module m_builtin_tests
     307                 :             : !!***
        

Generated by: LCOV version 2.3-1