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 : !> \brief Some auxiliary functions and subroutines needed for HFX calculations 10 : !> \par History 11 : !> 04.2008 created [Manuel Guidon] 12 : !> \author Manuel Guidon 13 : ! ************************************************************************************************** 14 : MODULE hfx_helpers 15 : #include "./base/base_uses.f90" 16 : IMPLICIT NONE 17 : PRIVATE 18 : 19 : PUBLIC :: count_cells_perd, & 20 : next_image_cell_perd 21 : 22 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'hfx_helpers' 23 : 24 : !*** 25 : 26 : CONTAINS 27 : 28 : ! ************************************************************************************************** 29 : !> \brief - Auxiliary function for creating periodic neighbor cells 30 : !> \param shell number of shells in each coordinate direction 31 : !> \param perd ... 32 : !> \return ... 33 : !> \par History 34 : !> 09.2007 created [Manuel Guidon] 35 : !> \author Manuel Guidon 36 : ! ************************************************************************************************** 37 2577 : FUNCTION count_cells_perd(shell, perd) 38 : INTEGER, INTENT(IN) :: shell, perd(3) 39 : INTEGER :: count_cells_perd 40 : 41 : INTEGER :: i, j, k 42 : 43 2577 : count_cells_perd = 0 44 5602 : DO i = -shell*perd(1), shell*perd(1) 45 10387 : DO j = -shell*perd(2), shell*perd(2) 46 19955 : DO k = -shell*perd(3), shell*perd(3) 47 16930 : IF ((i**2 + j**2 + k**2 == shell)) count_cells_perd = count_cells_perd + 1 48 : END DO 49 : END DO 50 : END DO 51 2577 : END FUNCTION count_cells_perd 52 : 53 : ! ************************************************************************************************** 54 : !> \brief - Auxiliary function for creating periodic neighbor cells 55 : !> \param m ... 56 : !> \param perd ... 57 : !> \par History 58 : !> 09.2007 created [Manuel Guidon] 59 : !> \author Manuel Guidon 60 : ! ************************************************************************************************** 61 3017 : SUBROUTINE next_image_cell_perd(m, perd) 62 : INTEGER :: m(3) 63 : INTEGER, INTENT(IN) :: perd(3) 64 : 65 : INTEGER :: i, j, k, shell 66 : LOGICAL :: found 67 : 68 3017 : found = .FALSE. 69 12068 : shell = SUM(m**2) 70 2431 : outer: DO 71 9173 : DO i = -shell*perd(1), shell*perd(1) 72 20797 : DO j = -shell*perd(2), shell*perd(2) 73 62797 : inner: DO k = -shell*perd(3), shell*perd(3) 74 47448 : IF (.NOT. (i**2 + j**2 + k**2 == shell)) CYCLE inner 75 8650 : IF (found) THEN 76 12068 : m = (/i, j, k/) 77 : EXIT outer 78 : END IF 79 66098 : IF (ALL(M .EQ. (/i, j, k/))) found = .TRUE. 80 : END DO inner 81 : END DO 82 : END DO 83 2431 : shell = shell + 1 84 : END DO outer 85 3017 : END SUBROUTINE next_image_cell_perd 86 : 87 : ! ************************************************************************************************** 88 : 89 : END MODULE hfx_helpers