LCOV - code coverage report
Current view: top level - src/pw_env - gaussian_gridlevels.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4dc10b3) Lines: 48 49 98.0 %
Date: 2024-11-21 06:45:46 Functions: 3 4 75.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \par History
      10             : !>      Code to return a gridlevel associated with a given gaussian exponent
      11             : !> \author Joost VandeVondele (27.02.02)
      12             : ! **************************************************************************************************
      13             : MODULE gaussian_gridlevels
      14             :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      15             :                                               cp_logger_type
      16             :    USE cp_output_handling,              ONLY: cp_print_key_finished_output,&
      17             :                                               cp_print_key_unit_nr
      18             :    USE input_section_types,             ONLY: section_vals_release,&
      19             :                                               section_vals_retain,&
      20             :                                               section_vals_type
      21             :    USE kinds,                           ONLY: dp,&
      22             :                                               int_8
      23             :    USE message_passing,                 ONLY: mp_comm_type,&
      24             :                                               mp_para_env_type
      25             : #include "../base/base_uses.f90"
      26             : 
      27             :    IMPLICIT NONE
      28             : 
      29             :    PRIVATE
      30             : 
      31             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gaussian_gridlevels'
      32             : 
      33             : ! **************************************************************************************************
      34             :    TYPE gridlevel_info_type
      35             :       INTEGER                         :: ngrid_levels = 0
      36             :       REAL(KIND=dp), POINTER, DIMENSION(:) :: cutoff => NULL()
      37             :       INTEGER(KIND=int_8), POINTER, DIMENSION(:) :: count => NULL()
      38             :       INTEGER(KIND=int_8)                         :: total_count = 0_int_8
      39             :       REAL(KIND=dp)                  :: rel_cutoff = 0.0_dp
      40             :       TYPE(section_vals_type), POINTER :: print_section => NULL()
      41             :    END TYPE gridlevel_info_type
      42             : 
      43             :    PUBLIC :: gridlevel_info_type
      44             :    PUBLIC :: gaussian_gridlevel
      45             :    PUBLIC :: init_gaussian_gridlevel
      46             :    PUBLIC :: destroy_gaussian_gridlevel
      47             : 
      48             : CONTAINS
      49             : 
      50             : ! **************************************************************************************************
      51             : !> \brief ...
      52             : !> \param gridlevel_info ...
      53             : !> \param ngrid_levels ...
      54             : !> \param cutoff ...
      55             : !> \param rel_cutoff ...
      56             : !> \param print_section ...
      57             : ! **************************************************************************************************
      58        8772 :    SUBROUTINE init_gaussian_gridlevel(gridlevel_info, ngrid_levels, cutoff, rel_cutoff, print_section)
      59             :       TYPE(gridlevel_info_type), INTENT(OUT)             :: gridlevel_info
      60             :       INTEGER, INTENT(IN)                                :: ngrid_levels
      61             :       REAL(KIND=dp), DIMENSION(ngrid_levels), INTENT(IN) :: cutoff
      62             :       REAL(KIND=dp), INTENT(IN)                          :: rel_cutoff
      63             :       TYPE(section_vals_type), INTENT(IN), TARGET        :: print_section
      64             : 
      65             :       INTEGER                                            :: i
      66             : 
      67       26316 :       ALLOCATE (gridlevel_info%cutoff(ngrid_levels))
      68       26316 :       ALLOCATE (gridlevel_info%count(ngrid_levels))
      69        8772 :       gridlevel_info%ngrid_levels = ngrid_levels
      70        8772 :       gridlevel_info%rel_cutoff = rel_cutoff
      71       37272 :       DO i = 1, ngrid_levels
      72       28500 :          gridlevel_info%cutoff(i) = cutoff(i)
      73       37272 :          gridlevel_info%count(i) = 0
      74             :       END DO
      75        8772 :       gridlevel_info%print_section => print_section
      76        8772 :       CALL section_vals_retain(gridlevel_info%print_section)
      77        8772 :    END SUBROUTINE init_gaussian_gridlevel
      78             : 
      79             : ! **************************************************************************************************
      80             : !> \brief ...
      81             : !> \param gridlevel_info ...
      82             : !> \param para_env ...
      83             : ! **************************************************************************************************
      84        8772 :    SUBROUTINE destroy_gaussian_gridlevel(gridlevel_info, para_env)
      85             :       TYPE(gridlevel_info_type), INTENT(INOUT)           :: gridlevel_info
      86             :       TYPE(mp_para_env_type), INTENT(IN), OPTIONAL       :: para_env
      87             : 
      88             :       INTEGER                                            :: i, output_unit
      89             :       LOGICAL                                            :: do_io
      90             :       TYPE(cp_logger_type), POINTER                      :: logger
      91             :       TYPE(mp_comm_type)                                 :: group
      92             : 
      93        8772 :       NULLIFY (logger)
      94       17544 :       logger => cp_get_default_logger()
      95        8772 :       IF (PRESENT(para_env)) THEN
      96        1003 :          group = para_env
      97             :          do_io = .FALSE. !subgroups completely mess up the output file
      98             :       ELSE
      99        7769 :          group = logger%para_env
     100             :          do_io = .TRUE.
     101             :       END IF
     102             : 
     103             :       IF (do_io) THEN
     104             : 
     105        7769 :          CALL group%sum(gridlevel_info%total_count)
     106       56745 :          CALL group%sum(gridlevel_info%count)
     107             : 
     108             :          output_unit = cp_print_key_unit_nr(logger, gridlevel_info%print_section, &
     109        7769 :                                             "", extension=".Log")
     110             : 
     111        7769 :          IF (output_unit > 0) THEN
     112        1844 :             WRITE (output_unit, '(/,T2,A,A)') "----------------------------------------", &
     113        3688 :                "---------------------------------------"
     114        1844 :             WRITE (output_unit, '(T2,A,T35,A,T77,A)') "----", "MULTIGRID INFO", "----"
     115        1844 :             WRITE (output_unit, '(T2,A,A)') "----------------------------------------", &
     116        3688 :                "---------------------------------------"
     117        1844 :             IF (gridlevel_info%ngrid_levels > 1) THEN
     118        6407 :                DO i = 1, gridlevel_info%ngrid_levels
     119        5158 :                   WRITE (output_unit, '(T2,A,I4,A,I14,9x,A,F12.2)') "count for grid     ", i, ": ", &
     120       11565 :                      gridlevel_info%count(i), " cutoff [a.u.]    ", gridlevel_info%cutoff(i)
     121             :                END DO
     122        1249 :                WRITE (output_unit, '(T2,A,I14)') "total gridlevel count  : ", &
     123        2498 :                   gridlevel_info%total_count
     124             :             ELSE
     125         595 :                WRITE (output_unit, '(T2,A,I14,T51,A,F12.2)') "total grid count     :", &
     126        1190 :                   gridlevel_info%count(1), " cutoff [a.u.]    ", gridlevel_info%cutoff(1)
     127             :             END IF
     128             :          END IF
     129             : 
     130        7769 :          CALL cp_print_key_finished_output(output_unit, logger, gridlevel_info%print_section, "")
     131             :       END IF
     132             : 
     133        8772 :       DEALLOCATE (gridlevel_info%cutoff)
     134             : 
     135        8772 :       CALL section_vals_release(gridlevel_info%print_section)
     136             : 
     137        8772 :       DEALLOCATE (gridlevel_info%count)
     138             : 
     139        8772 :    END SUBROUTINE destroy_gaussian_gridlevel
     140             : 
     141             : ! **************************************************************************************************
     142             : !> \brief ...
     143             : !> \param gridlevel_info ...
     144             : !> \param exponent ...
     145             : !> \return ...
     146             : ! **************************************************************************************************
     147    38680420 :    FUNCTION gaussian_gridlevel(gridlevel_info, exponent) RESULT(gridlevel)
     148             :       TYPE(gridlevel_info_type), INTENT(INOUT)           :: gridlevel_info
     149             :       REAL(KIND=dp), INTENT(IN)                          :: exponent
     150             :       INTEGER                                            :: gridlevel
     151             : 
     152             :       INTEGER                                            :: i
     153             :       REAL(KIND=dp)                                      :: needed_cutoff
     154             : 
     155    38680420 :       gridlevel = 1
     156    38680420 :       needed_cutoff = ABS(exponent)*gridlevel_info%rel_cutoff
     157   179395902 :       DO i = 1, gridlevel_info%ngrid_levels
     158   179395902 :          IF ((gridlevel_info%cutoff(i) + 1E-6_dp) .GE. needed_cutoff) THEN
     159    37764256 :             gridlevel = i
     160             :          END IF
     161             :       END DO
     162    38680420 : !$OMP ATOMIC
     163             :       gridlevel_info%total_count = gridlevel_info%total_count + 1
     164    38680420 : !$OMP ATOMIC
     165             :       gridlevel_info%count(gridlevel) = gridlevel_info%count(gridlevel) + 1
     166             : 
     167    38680420 :    END FUNCTION gaussian_gridlevel
     168             : 
     169           0 : END MODULE gaussian_gridlevels

Generated by: LCOV version 1.15