(git:e5b1968)
Loading...
Searching...
No Matches
fist_neighbor_list_control.F
Go to the documentation of this file.
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!> \par History
10!> Harald Forbert (Dec-2000): Changes for multiple linked lists
11!> linklist_internal_data_type
12!> 07.02.2005: using real coordinates for r_last_update; cleaned (MK)
13!> \author CJM,MK
14! **************************************************************************************************
16
19 USE cell_methods, ONLY: cell_create
20 USE cell_types, ONLY: cell_clone,&
22 cell_type,&
23 pbc,&
40 USE kinds, ONLY: dp
45 gal_type,&
51#include "./base/base_uses.f90"
52
53 IMPLICIT NONE
54
55 PRIVATE
56
57 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'fist_neighbor_list_control'
58
59 PUBLIC :: list_control
60
61!***
62
63CONTAINS
64
65! to decide whether the neighbor list is to be updated or not
66! based on a displacement criterion;
67! if any particle has moved by 0.5*verlet_skin from the previous
68! list update, then the list routine is called.
69
70! **************************************************************************************************
71!> \brief ...
72!> \param atomic_kind_set ...
73!> \param particle_set ...
74!> \param local_particles ...
75!> \param cell ...
76!> \param fist_nonbond_env ...
77!> \param para_env ...
78!> \param mm_section ...
79!> \param shell_particle_set ...
80!> \param core_particle_set ...
81!> \param force_update ...
82!> \param exclusions ...
83! **************************************************************************************************
84 SUBROUTINE list_control(atomic_kind_set, particle_set, local_particles, &
85 cell, fist_nonbond_env, para_env, mm_section, shell_particle_set, &
86 core_particle_set, force_update, exclusions)
87
88 TYPE(atomic_kind_type), POINTER :: atomic_kind_set(:)
89 TYPE(particle_type), POINTER :: particle_set(:)
90 TYPE(distribution_1d_type), POINTER :: local_particles
91 TYPE(cell_type), POINTER :: cell
92 TYPE(fist_nonbond_env_type), POINTER :: fist_nonbond_env
93 TYPE(mp_para_env_type), POINTER :: para_env
94 TYPE(section_vals_type), POINTER :: mm_section
95 TYPE(particle_type), OPTIONAL, POINTER :: shell_particle_set(:), &
96 core_particle_set(:)
97 LOGICAL, INTENT(IN), OPTIONAL :: force_update
98 TYPE(exclusion_type), DIMENSION(:), OPTIONAL :: exclusions
99
100 CHARACTER(LEN=*), PARAMETER :: routinen = 'list_control'
101
102 INTEGER :: counter, handle, ikind, iparticle, iparticle_kind, iparticle_local, ishell, &
103 jkind, last_update, nparticle, nparticle_kind, nparticle_local, nshell, num_update, &
104 output_unit
105 LOGICAL :: build_from_scratch, geo_check, &
106 shell_adiabatic, shell_present, &
107 update_neighbor_lists
108 LOGICAL, DIMENSION(:, :), POINTER :: full_nl
109 REAL(kind=dp) :: aup, dr2, dr2_max, ei_scale14, lup, &
110 vdw_scale14, verlet_skin
111 REAL(kind=dp), DIMENSION(3) :: dr, rab, rab_last_update, s, s2r
112 REAL(kind=dp), DIMENSION(:, :), POINTER :: rlist_cut, rlist_lowsq
113 TYPE(cell_type), POINTER :: cell_last_update
114 TYPE(cp_logger_type), POINTER :: logger
115 TYPE(fist_neighbor_type), POINTER :: nonbonded
116 TYPE(pair_potential_pp_type), POINTER :: potparm
117 TYPE(pos_type), DIMENSION(:), POINTER :: r_last_update, r_last_update_pbc, &
118 rcore_last_update_pbc, &
119 rshell_last_update_pbc
120
121 CALL timeset(routinen, handle)
122 NULLIFY (logger)
123 logger => cp_get_default_logger()
124
125 ! *** Assigning local pointers ***
126 CALL fist_nonbond_env_get(fist_nonbond_env, &
127 nonbonded=nonbonded, &
128 rlist_cut=rlist_cut, &
129 rlist_lowsq=rlist_lowsq, &
130 aup=aup, &
131 lup=lup, &
132 ei_scale14=ei_scale14, &
133 vdw_scale14=vdw_scale14, &
134 counter=counter, &
135 r_last_update=r_last_update, &
136 r_last_update_pbc=r_last_update_pbc, &
137 rshell_last_update_pbc=rshell_last_update_pbc, &
138 rcore_last_update_pbc=rcore_last_update_pbc, &
139 cell_last_update=cell_last_update, &
140 num_update=num_update, &
141 potparm=potparm, &
142 last_update=last_update)
143
144 nparticle = SIZE(particle_set)
145 nparticle_kind = SIZE(atomic_kind_set)
146 nshell = 0
147 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
148 shell_present=shell_present, shell_adiabatic=shell_adiabatic)
149 IF (shell_present) THEN
150 nshell = SIZE(shell_particle_set)
151 END IF
152
153 ! *** Check, if the neighbor lists have to be built or updated ***
154 update_neighbor_lists = .false.
155 CALL section_vals_val_get(mm_section, "NEIGHBOR_LISTS%NEIGHBOR_LISTS_FROM_SCRATCH", &
156 l_val=build_from_scratch)
157 CALL section_vals_val_get(mm_section, "NEIGHBOR_LISTS%GEO_CHECK", &
158 l_val=geo_check)
159 IF (ASSOCIATED(r_last_update)) THEN
160 ! Determine the maximum of the squared displacement, compared to
161 ! r_last_update.
162 CALL section_vals_val_get(mm_section, "NEIGHBOR_LISTS%VERLET_SKIN", &
163 r_val=verlet_skin)
164 dr2_max = 0.0_dp
165 DO iparticle_kind = 1, nparticle_kind
166 nparticle_local = local_particles%n_el(iparticle_kind)
167 DO iparticle_local = 1, nparticle_local
168 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
169 s2r = r_last_update(iparticle)%r
170 s = particle_set(iparticle)%r(:)
171 dr(:) = s2r - s
172 dr2 = dr(1)*dr(1) + dr(2)*dr(2) + dr(3)*dr(3)
173 dr2_max = max(dr2_max, dr2)
174 END DO
175 END DO
176
177 CALL para_env%max(dr2_max)
178
179 ! If the maximum distplacement is too large, ...
180 IF (dr2_max > 0.25_dp*verlet_skin**2 .OR. build_from_scratch) THEN
181 DO iparticle = 1, nparticle
182 r_last_update(iparticle)%r = particle_set(iparticle)%r(:)
183 END DO
184 update_neighbor_lists = .true.
185 END IF
186 ELSE
187 ! There is no r_last_update to compare with. Neighbor lists from scratch.
188 ALLOCATE (r_last_update(nparticle))
189 DO iparticle = 1, nparticle
190 r_last_update(iparticle)%r = particle_set(iparticle)%r(:)
191 END DO
192
193 update_neighbor_lists = .true.
194 build_from_scratch = .true.
195 END IF
196 ! Force Update
197 IF (PRESENT(force_update)) THEN
198 IF (force_update) update_neighbor_lists = .true.
199 END IF
200
201 ! Allocate the r_last_update_pbc, rshell_last_update_pbc, rcore_last_update_pbc
202 IF (.NOT. ASSOCIATED(r_last_update_pbc)) THEN
203 ALLOCATE (r_last_update_pbc(nparticle))
204 END IF
205 IF (shell_present .AND. .NOT. ASSOCIATED(rshell_last_update_pbc)) THEN
206 ALLOCATE (rshell_last_update_pbc(nshell))
207 END IF
208 IF (shell_present .AND. .NOT. ASSOCIATED(rcore_last_update_pbc)) THEN
209 ALLOCATE (rcore_last_update_pbc(nshell))
210 END IF
211
212 ! update the neighbor lists
213 IF (update_neighbor_lists) THEN
214 ! determine which pairs of atom kinds need full neighbor lists. Full
215 ! means that atom a is in the neighbor list of atom b and vice versa.
216 ALLOCATE (full_nl(nparticle_kind, nparticle_kind))
217 IF (ASSOCIATED(potparm)) THEN
218 DO ikind = 1, nparticle_kind
219 DO jkind = ikind, nparticle_kind
220 full_nl(ikind, jkind) = .false.
221 IF (any(potparm%pot(ikind, jkind)%pot%type == tersoff_type)) THEN
222 full_nl(ikind, jkind) = .true.
223 END IF
224 IF (any(potparm%pot(ikind, jkind)%pot%type == siepmann_type)) THEN
225 full_nl(ikind, jkind) = .true.
226 END IF
227 IF (any(potparm%pot(ikind, jkind)%pot%type == gal_type)) THEN
228 full_nl(ikind, jkind) = .true.
229 END IF
230 IF (any(potparm%pot(ikind, jkind)%pot%type == gal21_type)) THEN
231 full_nl(ikind, jkind) = .true.
232 END IF
233 IF (any(potparm%pot(ikind, jkind)%pot%type == nequip_type)) THEN
234 full_nl(ikind, jkind) = .true.
235 END IF
236 IF (any(potparm%pot(ikind, jkind)%pot%type == allegro_type)) THEN
237 full_nl(ikind, jkind) = .true.
238 END IF
239 IF (any(potparm%pot(ikind, jkind)%pot%type == ace_type)) THEN
240 full_nl(ikind, jkind) = .true.
241 END IF
242 full_nl(jkind, ikind) = full_nl(ikind, jkind)
243 END DO
244 END DO
245 ELSE
246 full_nl = .false.
247 END IF
248 CALL build_fist_neighbor_lists(atomic_kind_set, particle_set, &
249 local_particles, cell, rlist_cut, rlist_lowsq, ei_scale14, &
250 vdw_scale14, nonbonded, para_env, &
251 build_from_scratch=build_from_scratch, geo_check=geo_check, &
252 mm_section=mm_section, full_nl=full_nl, &
253 exclusions=exclusions)
254
255 CALL cell_release(cell_last_update)
256 CALL cell_create(cell_last_update)
257 CALL cell_clone(cell, cell_last_update)
258
259 IF (counter > 0) THEN
260 num_update = num_update + 1
261 lup = counter + 1 - last_update
262 last_update = counter + 1
263 aup = aup + (lup - aup)/real(num_update, kind=dp)
264 ELSE
265 num_update = 0
266 lup = 0
267 last_update = 1
268 aup = 0.0_dp
269 END IF
270
271 CALL fist_nonbond_env_set(fist_nonbond_env, &
272 lup=lup, &
273 aup=aup, &
274 r_last_update=r_last_update, &
275 r_last_update_pbc=r_last_update_pbc, &
276 rshell_last_update_pbc=rshell_last_update_pbc, &
277 rcore_last_update_pbc=rcore_last_update_pbc, &
278 nonbonded=nonbonded, &
279 num_update=num_update, &
280 last_update=last_update, &
281 cell_last_update=cell_last_update)
282
283 output_unit = cp_print_key_unit_nr(logger, mm_section, "PRINT%NEIGHBOR_LISTS", &
284 extension=".mmLog")
285 IF (output_unit > 0) THEN
286 WRITE (unit=output_unit, &
287 fmt="(/,T2,A,/,T52,A,/,A,T31,A,T49,2(1X,F15.2),/,T2,A,/)") &
288 repeat("*", 79), "INSTANTANEOUS AVERAGES", &
289 " LIST UPDATES[steps]", "= ", lup, aup, repeat("*", 79)
290 END IF
291 CALL cp_print_key_finished_output(output_unit, logger, mm_section, &
292 "PRINT%NEIGHBOR_LISTS")
293 DEALLOCATE (full_nl)
294 END IF
295
296 ! Store particle positions after the last update, translated to the
297 ! primitive cell, in r_last_update_pbc.
298 DO iparticle = 1, nparticle
299 ! The pbc algorithm is sensitive to numeric noise and compiler optimization because of ANINT.
300 ! Therefore we need to call here exactly the same routine as in build_neighbor_lists.
301 rab_last_update = pbc(r_last_update(iparticle)%r, cell_last_update) - r_last_update(iparticle)%r
302 CALL real_to_scaled(s, rab_last_update, cell_last_update)
303 CALL scaled_to_real(rab, s, cell)
304
305 r_last_update_pbc(iparticle)%r = particle_set(iparticle)%r + rab
306 ! Use the same translation for core and shell.
307 ishell = particle_set(iparticle)%shell_index
308 IF (ishell /= 0) THEN
309 rshell_last_update_pbc(ishell)%r = rab + shell_particle_set(ishell)%r(:)
310 IF (shell_adiabatic) THEN
311 rcore_last_update_pbc(ishell)%r = rab + core_particle_set(ishell)%r(:)
312 ELSE
313 rcore_last_update_pbc(ishell)%r = r_last_update_pbc(iparticle)%r(:)
314 END IF
315 END IF
316 END DO
317
318 counter = counter + 1
319 CALL fist_nonbond_env_set(fist_nonbond_env, counter=counter)
320 CALL timestop(handle)
321
322 END SUBROUTINE list_control
323
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
Handles all functions related to the CELL.
subroutine, public cell_create(cell, hmat, periodic, tag)
allocates and initializes a cell
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public scaled_to_real(r, s, cell)
Transform scaled cell coordinates real coordinates. r=h*s.
Definition cell_types.F:516
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
Definition cell_types.F:486
subroutine, public cell_release(cell)
releases the given cell (see doc/ReferenceCounting.html)
Definition cell_types.F:559
subroutine, public cell_clone(cell_in, cell_out, tag)
Clone cell variable.
Definition cell_types.F:107
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
an exclusion type
subroutine, public list_control(atomic_kind_set, particle_set, local_particles, cell, fist_nonbond_env, para_env, mm_section, shell_particle_set, core_particle_set, force_update, exclusions)
...
Define the neighbor list data types and the corresponding functionality.
Generate the atomic neighbor lists for FIST.
subroutine, public build_fist_neighbor_lists(atomic_kind_set, particle_set, local_particles, cell, r_max, r_minsq, ei_scale14, vdw_scale14, nonbonded, para_env, build_from_scratch, geo_check, mm_section, full_nl, exclusions)
...
subroutine, public fist_nonbond_env_get(fist_nonbond_env, potparm14, potparm, nonbonded, rlist_cut, rlist_lowsq, aup, lup, ei_scale14, vdw_scale14, shift_cutoff, do_electrostatics, r_last_update, r_last_update_pbc, rshell_last_update_pbc, rcore_last_update_pbc, cell_last_update, num_update, last_update, counter, natom_types, long_range_correction, ij_kind_full_fac, eam_data, quip_data, nequip_data, allegro_data, deepmd_data, ace_data, charges)
sets a fist_nonbond_env
subroutine, public fist_nonbond_env_set(fist_nonbond_env, potparm14, potparm, rlist_cut, rlist_lowsq, nonbonded, aup, lup, ei_scale14, vdw_scale14, shift_cutoff, do_electrostatics, r_last_update, r_last_update_pbc, rshell_last_update_pbc, rcore_last_update_pbc, cell_last_update, num_update, last_update, counter, natom_types, long_range_correction, eam_data, quip_data, nequip_data, allegro_data, deepmd_data, ace_data, charges)
sets a fist_nonbond_env
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
integer, parameter, public allegro_type
integer, parameter, public gal_type
integer, parameter, public nequip_type
integer, parameter, public siepmann_type
integer, parameter, public ace_type
integer, parameter, public gal21_type
integer, parameter, public tersoff_type
Define the data structure for the particle information.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
type of a logger, at the moment it contains just a print level starting at which level it should be l...
structure to store local (to a processor) ordered lists of integers.
A type used to store lists of exclusions and onfos.
stores all the informations relevant to an mpi environment