(git:374b731)
Loading...
Searching...
No Matches
pme_tools.F
Go to the documentation of this file.
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 Tools common both to PME and SPME
10!> \par History
11!> JGH (03-May-2001) : first correctly working version
12!> teo (Feb-2007) : Merging common routines to spme and pme
13!> \author JGH (21-Mar-2001)
14! **************************************************************************************************
16
19 USE cell_types, ONLY: cell_type,&
21 USE kinds, ONLY: dp
24#include "./base/base_uses.f90"
25
26 IMPLICIT NONE
27
28 PRIVATE
29 PUBLIC :: get_center, set_list
30
31 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pme_tools'
32
33CONTAINS
34
35! **************************************************************************************************
36!> \brief ...
37!> \param part ...
38!> \param npart ...
39!> \param center ...
40!> \param p1 ...
41!> \param rs ...
42!> \param ipart ...
43!> \param core_center ...
44! **************************************************************************************************
45 SUBROUTINE set_list(part, npart, center, p1, rs, ipart, core_center)
46
47 TYPE(particle_type), DIMENSION(:), INTENT(IN) :: part
48 INTEGER, INTENT(IN) :: npart
49 INTEGER, DIMENSION(:, :), INTENT(IN) :: center
50 INTEGER, INTENT(OUT) :: p1
51 TYPE(realspace_grid_type), INTENT(IN) :: rs
52 INTEGER, INTENT(INOUT) :: ipart
53 INTEGER, DIMENSION(:, :), OPTIONAL, POINTER :: core_center
54
55 INTEGER :: ndim, npos
56 INTEGER, DIMENSION(3) :: lb, ub
57 REAL(kind=dp) :: charge
58 TYPE(atomic_kind_type), POINTER :: atomic_kind
59
60 p1 = 0
61 lb = rs%lb_real
62 ub = rs%ub_real
63
64 DO
65 ipart = ipart + 1
66 IF (ipart > npart) EXIT
67 atomic_kind => part(ipart)%atomic_kind
68 CALL get_atomic_kind(atomic_kind=atomic_kind, qeff=charge)
69 IF (charge == 0.0_dp .AND. part(ipart)%shell_index == 0) cycle
70 IF (rs%desc%parallel) THEN
71 ! check if the rs grid is distributed or not
72 IF (all(rs%desc%group_dim == 1)) THEN
73 ndim = rs%desc%group_size
74 npos = rs%desc%my_pos
75 ! All processors work on the same grid
76 IF (mod(ipart, ndim) == npos) THEN
77 p1 = ipart
78 EXIT
79 END IF
80 ELSE
81 ! First check if this atom is on my grid
82 IF (part(ipart)%shell_index /= 0 .AND. PRESENT(core_center)) THEN
83 IF (in_slice(core_center(:, part(ipart)%shell_index), lb, ub)) THEN
84 p1 = ipart
85 END IF
86 ELSE
87 IF (in_slice(center(:, ipart), lb, ub)) THEN
88 p1 = ipart
89 EXIT
90 END IF
91 END IF
92 END IF
93 ELSE
94 p1 = ipart
95 EXIT
96 END IF
97 END DO
98
99 END SUBROUTINE set_list
100
101! **************************************************************************************************
102!> \brief ...
103!> \param pos ...
104!> \param lb ...
105!> \param ub ...
106!> \return ...
107! **************************************************************************************************
108 FUNCTION in_slice(pos, lb, ub) RESULT(internal)
109
110 INTEGER, DIMENSION(3), INTENT(IN) :: pos, lb, ub
111 LOGICAL :: internal
112
113 IF (all(pos >= lb) .AND. all(pos <= ub)) THEN
114 internal = .true.
115 ELSE
116 internal = .false.
117 END IF
118
119 END FUNCTION in_slice
120
121! **************************************************************************************************
122!> \brief ...
123!> \param part ...
124!> \param box ...
125!> \param center ...
126!> \param delta ...
127!> \param npts ...
128!> \param n ...
129! **************************************************************************************************
130 SUBROUTINE get_center(part, box, center, delta, npts, n)
131
132 TYPE(particle_type), DIMENSION(:), INTENT(IN) :: part
133 TYPE(cell_type), POINTER :: box
134 INTEGER, DIMENSION(:, :), INTENT(OUT) :: center
135 REAL(kind=dp), DIMENSION(:, :), INTENT(OUT) :: delta
136 INTEGER, DIMENSION(:), INTENT(IN) :: npts
137 INTEGER, INTENT(IN) :: n
138
139 INTEGER :: ipart, mp
140 REAL(kind=dp) :: rmp
141 REAL(kind=dp), DIMENSION(3) :: ca, gp, s
142
143 ! The pbc algorithm is sensitive to numeric noise and compiler optimization because of ANINT.
144 ! Therefore center and delta have to be computed simultaneously to ensure they are consistent.
145 mp = maxval(npts(:))
146 rmp = real(mp, kind=dp)
147 DO ipart = 1, SIZE(part)
148 ! compute the scaled coordinate of atom ipart
149 CALL real_to_scaled(s, part(ipart)%r, box)
150 s = s - anint(s)
151 ! find the continuous ``grid'' point
152 gp = real(npts, kind=dp)*s
153 ! find the closest grid point (on big grid)
154 IF (mod(n, 2) == 0) THEN
155 center(:, ipart) = int(gp + rmp) - mp
156 ca(:) = real(center(:, ipart), kind=dp) + 0.5_dp
157 ELSE
158 center(:, ipart) = nint(gp)
159 ca(:) = real(center(:, ipart), kind=dp)
160 END IF
161 center(:, ipart) = center(:, ipart) + npts(:)/2
162 center(:, ipart) = modulo(center(:, ipart), npts(:))
163 center(:, ipart) = center(:, ipart) - npts(:)/2
164 ! find the distance vector
165 delta(:, ipart) = gp - ca(:)
166 END DO
167
168 END SUBROUTINE get_center
169
170END MODULE pme_tools
171
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
Definition cell_types.F:486
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Define the data structure for the particle information.
Tools common both to PME and SPME.
Definition pme_tools.F:15
subroutine, public get_center(part, box, center, delta, npts, n)
...
Definition pme_tools.F:131
subroutine, public set_list(part, npart, center, p1, rs, ipart, core_center)
...
Definition pme_tools.F:46
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:55