Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2025 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 2817 : 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 2817 : count_cells_perd = 0
44 6082 : DO i = -shell*perd(1), shell*perd(1)
45 11107 : DO j = -shell*perd(2), shell*perd(2)
46 20675 : DO k = -shell*perd(3), shell*perd(3)
47 17410 : 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 2817 : 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 3257 : 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 3257 : found = .FALSE.
69 13028 : shell = SUM(m**2)
70 2671 : outer: DO
71 9893 : DO i = -shell*perd(1), shell*perd(1)
72 21997 : DO j = -shell*perd(2), shell*perd(2)
73 64957 : inner: DO k = -shell*perd(3), shell*perd(3)
74 48888 : IF (.NOT. (i**2 + j**2 + k**2 == shell)) CYCLE inner
75 9130 : IF (found) THEN
76 13028 : m = [i, j, k]
77 : EXIT outer
78 : END IF
79 68498 : IF (ALL(M == [i, j, k])) found = .TRUE.
80 : END DO inner
81 : END DO
82 : END DO
83 2671 : shell = shell + 1
84 : END DO outer
85 3257 : END SUBROUTINE next_image_cell_perd
86 :
87 : ! **************************************************************************************************
88 :
89 : END MODULE hfx_helpers
|