LCOV - code coverage report
Current view: top level - src/pw_env - gaussian_gridlevels.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4b1dd74) Lines: 49 51 96.1 %
Date: 2021-10-23 21:08:55 Functions: 3 4 75.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2021 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 cp_para_types,                   ONLY: cp_para_env_type
      19             :    USE input_section_types,             ONLY: section_vals_release,&
      20             :                                               section_vals_retain,&
      21             :                                               section_vals_type
      22             :    USE kinds,                           ONLY: dp,&
      23             :                                               int_8
      24             :    USE message_passing,                 ONLY: mp_sum
      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
      36             :       REAL(KIND=dp), POINTER, DIMENSION(:) :: cutoff
      37             :       INTEGER(KIND=int_8), POINTER, DIMENSION(:) :: count
      38             :       INTEGER(KIND=int_8)                         :: total_count
      39             :       REAL(KIND=dp)                  :: rel_cutoff
      40             :       TYPE(section_vals_type), POINTER :: print_section
      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        7014 :    SUBROUTINE init_gaussian_gridlevel(gridlevel_info, ngrid_levels, cutoff, rel_cutoff, print_section)
      59             :       TYPE(gridlevel_info_type)                          :: gridlevel_info
      60             :       INTEGER                                            :: ngrid_levels
      61             :       REAL(KIND=dp), DIMENSION(:), POINTER               :: cutoff
      62             :       REAL(KIND=dp)                                      :: rel_cutoff
      63             :       TYPE(section_vals_type), POINTER                   :: print_section
      64             : 
      65             :       INTEGER                                            :: i
      66             : 
      67       21042 :       ALLOCATE (gridlevel_info%cutoff(ngrid_levels))
      68       21042 :       ALLOCATE (gridlevel_info%count(ngrid_levels))
      69        7014 :       gridlevel_info%ngrid_levels = ngrid_levels
      70        7014 :       gridlevel_info%rel_cutoff = rel_cutoff
      71        7014 :       gridlevel_info%total_count = 0
      72       28888 :       DO i = 1, ngrid_levels
      73       21874 :          gridlevel_info%cutoff(i) = cutoff(i)
      74       28888 :          gridlevel_info%count(i) = 0
      75             :       ENDDO
      76        7014 :       gridlevel_info%print_section => print_section
      77        7014 :       CALL section_vals_retain(print_section)
      78        7014 :    END SUBROUTINE init_gaussian_gridlevel
      79             : 
      80             : ! **************************************************************************************************
      81             : !> \brief ...
      82             : !> \param gridlevel_info ...
      83             : !> \param para_env ...
      84             : ! **************************************************************************************************
      85        7014 :    SUBROUTINE destroy_gaussian_gridlevel(gridlevel_info, para_env)
      86             :       TYPE(gridlevel_info_type)                          :: gridlevel_info
      87             :       TYPE(cp_para_env_type), OPTIONAL, POINTER          :: para_env
      88             : 
      89             :       INTEGER                                            :: group, i, output_unit
      90             :       TYPE(cp_logger_type), POINTER                      :: logger
      91             : 
      92        7014 :       NULLIFY (logger)
      93        7014 :       logger => cp_get_default_logger()
      94        7014 :       IF (PRESENT(para_env)) THEN
      95           0 :          group = para_env%group
      96             :       ELSE
      97        7014 :          group = logger%para_env%group
      98             :       END IF
      99             :       output_unit = cp_print_key_unit_nr(logger, gridlevel_info%print_section, &
     100        7014 :                                          "", extension=".Log")
     101             : 
     102        7014 :       CALL mp_sum(gridlevel_info%total_count, group)
     103        7014 :       CALL mp_sum(gridlevel_info%count, group)
     104        7014 :       IF (output_unit > 0) THEN
     105        1668 :          WRITE (output_unit, '(/,T2,A,A)') "----------------------------------------", &
     106        3336 :             "---------------------------------------"
     107        1668 :          WRITE (output_unit, '(T2,A,T35,A,T77,A)') "----", "MULTIGRID INFO", "----"
     108        1668 :          WRITE (output_unit, '(T2,A,A)') "----------------------------------------", &
     109        3336 :             "---------------------------------------"
     110        1668 :          IF (gridlevel_info%ngrid_levels > 1) THEN
     111        5490 :             DO i = 1, gridlevel_info%ngrid_levels
     112        4423 :                WRITE (output_unit, '(T2,A,I4,A,I14,9x,A,F12.2)') "count for grid     ", i, ": ", &
     113        9913 :                   gridlevel_info%count(i), " cutoff [a.u.]    ", gridlevel_info%cutoff(i)
     114             :             END DO
     115        1067 :             WRITE (output_unit, '(T2,A,I14)') "total gridlevel count  : ", &
     116        2134 :                gridlevel_info%total_count
     117             :          ELSE
     118         601 :             WRITE (output_unit, '(T2,A,I14,T51,A,F12.2)') "total grid count     :", &
     119        1202 :                gridlevel_info%count(1), " cutoff [a.u.]    ", gridlevel_info%cutoff(1)
     120             :          END IF
     121             :       END IF
     122             : 
     123        7014 :       DEALLOCATE (gridlevel_info%cutoff)
     124             : 
     125             :       CALL cp_print_key_finished_output(output_unit, logger, gridlevel_info%print_section, &
     126        7014 :                                         "")
     127             : 
     128        7014 :       CALL section_vals_release(gridlevel_info%print_section)
     129             : 
     130        7014 :       DEALLOCATE (gridlevel_info%count)
     131             : 
     132        7014 :    END SUBROUTINE destroy_gaussian_gridlevel
     133             : 
     134             : ! **************************************************************************************************
     135             : !> \brief ...
     136             : !> \param gridlevel_info ...
     137             : !> \param exponent ...
     138             : !> \return ...
     139             : ! **************************************************************************************************
     140    31527387 :    FUNCTION gaussian_gridlevel(gridlevel_info, exponent) RESULT(gridlevel)
     141             :       TYPE(gridlevel_info_type), INTENT(INOUT)           :: gridlevel_info
     142             :       REAL(KIND=dp)                                      :: exponent
     143             :       INTEGER                                            :: gridlevel
     144             : 
     145             :       INTEGER                                            :: i
     146             :       REAL(KIND=dp)                                      :: needed_cutoff
     147             : 
     148    31527387 :       gridlevel = 1
     149    31527387 :       needed_cutoff = ABS(exponent)*gridlevel_info%rel_cutoff
     150   143053330 :       DO i = 1, gridlevel_info%ngrid_levels
     151   143053330 :          IF ((gridlevel_info%cutoff(i) + 1E-6_dp) .GE. needed_cutoff) THEN
     152    29372762 :             gridlevel = i
     153             :          ENDIF
     154             :       ENDDO
     155    31527387 :       !$OMP CRITICAL(add_counts)
     156    31527387 :       gridlevel_info%total_count = gridlevel_info%total_count + 1
     157    31527387 :       gridlevel_info%count(gridlevel) = gridlevel_info%count(gridlevel) + 1
     158             :       !$OMP END CRITICAL(add_counts)
     159             : 
     160    31527387 :    END FUNCTION gaussian_gridlevel
     161             : 
     162           0 : END MODULE gaussian_gridlevels

Generated by: LCOV version 1.15