LCOV - code coverage report
Current view: top level - src - xc_write_output.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:24d69ee) Lines: 97.4 % 39 38
Test Date: 2026-09-03 07:32:15 Functions: 100.0 % 2 2

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief Writes information on XC functionals to output
      10              : ! **************************************************************************************************
      11              : MODULE xc_write_output
      12              : 
      13              :    USE input_constants,                 ONLY: xc_none
      14              :    USE input_cp2k_check,                ONLY: xc_functionals_expand
      15              :    USE input_section_types,             ONLY: section_vals_get_subs_vals,&
      16              :                                               section_vals_get_subs_vals2,&
      17              :                                               section_vals_type,&
      18              :                                               section_vals_val_get
      19              :    USE kinds,                           ONLY: default_string_length
      20              :    USE xc_derivatives,                  ONLY: xc_functional_get_info
      21              :    USE xc_libxc,                        ONLY: libxc_check_existence_in_libxc,&
      22              :                                               libxc_get_reference_length,&
      23              :                                               libxc_library_reference,&
      24              :                                               libxc_version_info
      25              : #include "./base/base_uses.f90"
      26              : 
      27              :    IMPLICIT NONE
      28              : 
      29              :    PRIVATE
      30              : 
      31              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xc_write_output'
      32              : 
      33              :    PUBLIC :: xc_write
      34              : 
      35              : CONTAINS
      36              : 
      37              : ! **************************************************************************************************
      38              : !> \brief ...
      39              : !> \param iounit ...
      40              : !> \param xc_section ...
      41              : !> \param lsd ...
      42              : ! **************************************************************************************************
      43         2006 :    SUBROUTINE xc_write(iounit, xc_section, lsd)
      44              :       INTEGER, INTENT(IN)                                :: iounit
      45              :       TYPE(section_vals_type), POINTER                   :: xc_section
      46              :       LOGICAL, INTENT(IN)                                :: lsd
      47              : 
      48              :       CHARACTER(LEN=2*default_string_length)             :: shortform
      49         2006 :       CHARACTER(LEN=:), ALLOCATABLE                      :: reference
      50              :       INTEGER                                            :: ifun, il, myfun
      51              :       LOGICAL                                            :: libxc_used
      52              :       TYPE(section_vals_type), POINTER                   :: xc_fun, xc_fun_section
      53              : 
      54         2006 :       IF (iounit > 0) THEN
      55              : 
      56              :          xc_fun_section => section_vals_get_subs_vals(xc_section, &
      57         2006 :                                                       "XC_FUNCTIONAL")
      58         2006 :          CALL section_vals_val_get(xc_fun_section, "_SECTION_PARAMETERS_", i_val=myfun)
      59         2006 :          IF (myfun /= xc_none) THEN
      60              : 
      61         1807 :             CALL xc_functionals_expand(xc_fun_section, xc_section)
      62              : 
      63              :             ! Announce LibXC before the functionals it provides, so that the
      64              :             ! version actually loaded and the citation it asks for are on record
      65              :             ! next to the numbers they produced.
      66         1807 :             libxc_used = .FALSE.
      67         1807 :             ifun = 0
      68              :             DO
      69         3823 :                ifun = ifun + 1
      70         3823 :                xc_fun => section_vals_get_subs_vals2(xc_fun_section, i_section=ifun)
      71         3823 :                IF (.NOT. ASSOCIATED(xc_fun)) EXIT
      72         3823 :                IF (libxc_check_existence_in_libxc(xc_fun)) libxc_used = .TRUE.
      73              :             END DO
      74         1807 :             IF (libxc_used) CALL xc_write_libxc_info(iounit)
      75              : 
      76         1807 :             ifun = 0
      77         2016 :             DO
      78         3823 :                ifun = ifun + 1
      79         3823 :                xc_fun => section_vals_get_subs_vals2(xc_fun_section, i_section=ifun)
      80         3823 :                IF (.NOT. ASSOCIATED(xc_fun)) EXIT
      81         2016 :                IF (libxc_check_existence_in_libxc(xc_fun)) THEN
      82           95 :                   ALLOCATE (CHARACTER(LEN=libxc_get_reference_length(xc_fun, lsd)) :: reference)
      83              :                ELSE
      84         1921 :                   ALLOCATE (CHARACTER(LEN=20*default_string_length) :: reference)
      85              :                END IF
      86         2016 :                CALL xc_functional_get_info(xc_fun, lsd=lsd, reference=reference, shortform=shortform)
      87              :                WRITE (iounit, fmt="(' FUNCTIONAL| ',a,':')") &
      88         2016 :                   TRIM(xc_fun%section%name)
      89         5887 :                DO il = 1, LEN_TRIM(reference), 67
      90         5887 :                   WRITE (iounit, fmt="(' FUNCTIONAL| ',a67)") reference(il:)
      91              :                END DO
      92         3823 :                DEALLOCATE (reference)
      93              :             END DO
      94              :          ELSE
      95          199 :             WRITE (iounit, fmt="(' FUNCTIONAL| NO EXCHANGE-CORRELATION FUNCTIONAL USED.')")
      96              :          END IF
      97              :       END IF
      98              : 
      99         2006 :    END SUBROUTINE xc_write
     100              : 
     101              : ! **************************************************************************************************
     102              : !> \brief Reports which LibXC is in use and how it asks to be cited.
     103              : !> \param iounit ...
     104              : !> \author S. Lehtola
     105              : !> \note The version is the one reported by the library at run time, which is what
     106              : !>       describes the numbers in this output. It can differ from the version CP2K
     107              : !>       was compiled against when the binary picks up another shared LibXC, and
     108              : !>       that mismatch is worth saying out loud.
     109              : ! **************************************************************************************************
     110           63 :    SUBROUTINE xc_write_libxc_info(iounit)
     111              :       INTEGER, INTENT(IN)                                :: iounit
     112              : 
     113              :       CHARACTER(LEN=10*default_string_length)            :: reference
     114              :       CHARACTER(LEN=default_string_length)               :: compiled_version, doi, version
     115              :       INTEGER                                            :: il
     116              : 
     117           63 :       CALL libxc_version_info(version, compiled_version)
     118           63 :       CALL libxc_library_reference(reference, doi)
     119              : 
     120           63 :       WRITE (iounit, fmt="(' FUNCTIONAL| LIBXC version ',a)") TRIM(version)
     121           63 :       IF (TRIM(version) /= TRIM(compiled_version)) THEN
     122            0 :          WRITE (iounit, fmt="(' FUNCTIONAL| LIBXC compiled against version ',a)") TRIM(compiled_version)
     123              :       END IF
     124          189 :       DO il = 1, LEN_TRIM(reference), 67
     125          189 :          WRITE (iounit, fmt="(' FUNCTIONAL| ',a67)") reference(il:)
     126              :       END DO
     127           63 :       WRITE (iounit, fmt="(' FUNCTIONAL| doi: ',a)") TRIM(doi)
     128              : 
     129           63 :    END SUBROUTINE xc_write_libxc_info
     130              : 
     131              : END MODULE xc_write_output
        

Generated by: LCOV version 2.0-1