1 /* -*- c++ -*- ---------------------------------------------------------- 2 LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator 3 https://www.lammps.org/, Sandia National Laboratories 4 Steve Plimpton, sjplimp@sandia.gov 5 6 Copyright (2003) Sandia Corporation. Under the terms of Contract 7 DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains 8 certain rights in this software. This software is distributed under 9 the GNU General Public License. 10 11 See the README file in the top-level LAMMPS directory. 12 ------------------------------------------------------------------------- */ 13 14 #ifndef LMP_NEIGHBOR_H 15 #define LMP_NEIGHBOR_H 16 17 #include "pointers.h" 18 19 namespace LAMMPS_NS { 20 21 class Neighbor : protected Pointers { 22 public: 23 enum { NSQ, BIN, MULTI_OLD, MULTI }; 24 int style; // 0,1,2,3 = nsq, bin, multi/old, multi 25 int every; // build every this many steps 26 int delay; // delay build for this many steps 27 int dist_check; // 0 = always build, 1 = only if 1/2 dist 28 int ago; // how many steps ago neighboring occurred 29 int pgsize; // size of neighbor page 30 int oneatom; // max # of neighbors for one atom 31 int includegroup; // only build pairwise lists for this group 32 int build_once; // 1 if only build lists once per run 33 34 double skin; // skin distance 35 double cutneighmin; // min neighbor cutoff for all type pairs 36 double cutneighmax; // max neighbor cutoff for all type pairs 37 double cutneighmaxsq; // cutneighmax squared 38 double **cutneighsq; // neighbor cutneigh sq for each type pair 39 double **cutneighghostsq; // cutneigh sq for each ghost type pair 40 double *cuttype; // for each type, max neigh cut w/ others 41 double *cuttypesq; // cuttype squared 42 double cut_inner_sq; // outer cutoff for inner neighbor list 43 double cut_middle_sq; // outer cutoff for middle neighbor list 44 double cut_middle_inside_sq; // inner cutoff for middle neighbor list 45 46 int binsizeflag; // user-chosen bin size 47 double binsize_user; // set externally by some accelerator pkgs 48 49 bigint ncalls; // # of times build has been called 50 bigint ndanger; // # of dangerous builds 51 bigint lastcall; // timestep of last neighbor::build() call 52 53 // geometry and static info, used by other Neigh classes 54 55 double *bboxlo, *bboxhi; // ptrs to full domain bounding box 56 // different for orthog vs triclinic 57 58 // exclusion info, used by NeighPair 59 60 int exclude; // 0 if no type/group exclusions, 1 if yes 61 62 int nex_type; // # of entries in type exclusion list 63 int *ex1_type, *ex2_type; // pairs of types to exclude 64 int **ex_type; // 2d array of excluded type pairs 65 66 int nex_group; // # of entries in group exclusion list 67 int *ex1_group, *ex2_group; // pairs of group #'s to exclude 68 int *ex1_bit, *ex2_bit; // pairs of group bits to exclude 69 70 int nex_mol; // # of entries in molecule exclusion list 71 int *ex_mol_group; // molecule group #'s to exclude 72 int *ex_mol_bit; // molecule group bits to exclude 73 int *ex_mol_intra; // 0 = exclude if in 2 molecules (inter) 74 // 1 = exclude if in same molecule (intra) 75 76 // special info, used by NeighPair 77 78 int special_flag[4]; // flags for 1-2, 1-3, 1-4 neighbors 79 80 // cluster setting, used by NeighTopo 81 82 int cluster_check; // 1 if check bond/angle/etc satisfies minimg 83 84 // pairwise neighbor lists and corresponding requests 85 86 int nlist; // # of pairwise neighbor lists 87 int nrequest; // # of requests, same as nlist 88 int old_nrequest; // # of requests for previous run 89 90 class NeighList **lists; 91 class NeighRequest **requests; // from Pair,Fix,Compute,Command classes 92 class NeighRequest **old_requests; // copy of requests to compare to 93 94 // data from topology neighbor lists 95 96 int nbondlist; // list of bonds to compute 97 int **bondlist; 98 int nanglelist; // list of angles to compute 99 int **anglelist; 100 int ndihedrallist; // list of dihedrals to compute 101 int **dihedrallist; 102 int nimproperlist; // list of impropers to compute 103 int **improperlist; 104 105 // optional type grouping for multi 106 107 int custom_collection_flag; // 1 if custom collections are defined for multi 108 int interval_collection_flag; // 1 if custom collections use intervals 109 int finite_cut_flag; // 1 if multi considers finite atom size 110 int ncollections; // # of custom collections 111 int nmax_collection; // maximum atoms stored in collection array 112 int *type2collection; // ntype array mapping types to custom collections 113 double *collection2cut; // ncollection array with upper bounds on cutoff intervals 114 double **cutcollectionsq; // cutoffs for each combination of collections 115 int *collection; // local per-atom array to store collection id 116 117 // public methods 118 119 Neighbor(class LAMMPS *); 120 virtual ~Neighbor(); 121 virtual void init(); 122 int request(void *, int instance = 0); 123 int decide(); // decide whether to build or not 124 virtual int check_distance(); // check max distance moved since last build 125 void setup_bins(); // setup bins based on box and cutoff 126 virtual void build(int); // build all perpetual neighbor lists 127 virtual void build_topology(); // pairwise topology neighbor lists 128 void build_one(class NeighList *list, int preflag = 0); 129 // create a one-time pairwise neigh list 130 void set(int, char **); // set neighbor style and skin distance 131 void reset_timestep(bigint); // reset of timestep counter 132 void modify_params(int, char **); // modify params that control builds 133 void modify_params(const std::string &); // convenience overload 134 135 void exclusion_group_group_delete(int, int); // rm a group-group exclusion 136 int exclude_setting(); // return exclude value to accelerator pkg 137 class NeighRequest *find_request(void *); // find a neighbor request 138 int any_full(); // Check if any old requests had full neighbor lists 139 void build_collection(int); // build peratom collection array starting at the given index 140 141 double memory_usage(); 142 143 bigint last_setup_bins; // step of last neighbor::setup_bins() call 144 145 protected: 146 int me, nprocs; 147 int firsttime; // flag for calling init_styles() only once 148 149 int dimension; // 2/3 for 2d/3d 150 int triclinic; // 0 if domain is orthog, 1 if triclinic 151 int newton_pair; // 0 if newton off for pairwise, 1 if on 152 153 int must_check; // 1 if must check other classes to reneigh 154 int restart_check; // 1 if restart enabled, 0 if no 155 int fix_check; // # of fixes that induce reneigh 156 int *fixchecklist; // which fixes to check 157 158 double triggersq; // trigger = build when atom moves this dist 159 160 double **xhold; // atom coords at last neighbor build 161 int maxhold; // size of xhold array 162 163 int boxcheck; // 1 if need to store box size 164 double boxlo_hold[3], boxhi_hold[3]; // box size at last neighbor build 165 double corners_hold[8][3]; // box corners at last neighbor build 166 double (*corners)[3]; // ptr to 8 corners of triclinic box 167 168 double inner[2], middle[2]; // rRESPA cutoffs for extra lists 169 170 int old_style, old_triclinic; // previous run info 171 int old_pgsize, old_oneatom; // used to avoid re-creating neigh lists 172 173 int nstencil_perpetual; // # of perpetual NeighStencil classes 174 int npair_perpetual; // #x of perpetual NeighPair classes 175 int *slist; // indices of them in neigh_stencil 176 int *plist; // indices of them in neigh_pair 177 178 int maxex_type; // max # in exclusion type list 179 int maxex_group; // max # in exclusion group list 180 int maxex_mol; // max # in exclusion molecule list 181 182 int maxatom; // max size of atom-based NeighList arrays 183 int maxrequest; // max size of NeighRequest list 184 185 // info for other Neigh classes: NBin,NStencil,NPair,NTopo 186 187 int nbin, nstencil; 188 int nbclass, nsclass, npclass; 189 int bondwhich, anglewhich, dihedralwhich, improperwhich; 190 191 typedef class NBin *(*BinCreator)(class LAMMPS *); 192 BinCreator *binclass; 193 char **binnames; 194 int *binmasks; 195 class NBin **neigh_bin; 196 197 typedef class NStencil *(*StencilCreator)(class LAMMPS *); 198 StencilCreator *stencilclass; 199 char **stencilnames; 200 int *stencilmasks; 201 class NStencil **neigh_stencil; 202 203 typedef class NPair *(*PairCreator)(class LAMMPS *); 204 PairCreator *pairclass; 205 char **pairnames; 206 int *pairmasks; 207 class NPair **neigh_pair; 208 209 class NTopo *neigh_bond; 210 class NTopo *neigh_angle; 211 class NTopo *neigh_dihedral; 212 class NTopo *neigh_improper; 213 214 // internal methods 215 // including creator methods for Nbin,Nstencil,Npair instances 216 217 void init_styles(); 218 int init_pair(); 219 virtual void init_topology(); 220 221 void morph_unique(); 222 void morph_skip(); 223 void morph_granular(); 224 void morph_halffull(); 225 void morph_copy(); 226 227 void print_pairwise_info(); 228 void requests_new2old(); 229 230 int choose_bin(class NeighRequest *); 231 int choose_stencil(class NeighRequest *); 232 int choose_pair(class NeighRequest *); 233 234 template <typename T> static NBin *bin_creator(class LAMMPS *); 235 template <typename T> static NStencil *stencil_creator(class LAMMPS *); 236 template <typename T> static NPair *pair_creator(class LAMMPS *); 237 238 // dummy functions provided by NeighborKokkos, called in init() 239 // otherwise NeighborKokkos would have to overwrite init() 240 241 int copymode; 242 init_cutneighsq_kokkos(int)243 virtual void init_cutneighsq_kokkos(int) {} create_kokkos_list(int)244 virtual void create_kokkos_list(int) {} init_ex_type_kokkos(int)245 virtual void init_ex_type_kokkos(int) {} init_ex_bit_kokkos()246 virtual void init_ex_bit_kokkos() {} init_ex_mol_bit_kokkos()247 virtual void init_ex_mol_bit_kokkos() {} grow_ex_mol_intra_kokkos()248 virtual void grow_ex_mol_intra_kokkos() {} set_binsize_kokkos()249 virtual void set_binsize_kokkos() {} 250 }; 251 252 namespace NeighConst { 253 enum { 254 NB_INTEL = 1 << 0, 255 NB_KOKKOS_DEVICE = 1 << 1, 256 NB_KOKKOS_HOST = 1 << 2, 257 NB_SSA = 1 << 3, 258 NB_STANDARD = 1 << 4, 259 NB_MULTI = 1 << 5 260 }; 261 262 enum { 263 NS_BIN = 1 << 0, 264 NS_MULTI = 1 << 1, 265 NS_HALF = 1 << 2, 266 NS_FULL = 1 << 3, 267 NS_2D = 1 << 4, 268 NS_3D = 1 << 5, 269 NS_ORTHO = 1 << 6, 270 NS_TRI = 1 << 7, 271 NS_GHOST = 1 << 8, 272 NS_SSA = 1 << 9, 273 NS_MULTI_OLD = 1 << 10 274 }; 275 276 enum { 277 NP_NSQ = 1 << 0, 278 NP_BIN = 1 << 1, 279 NP_MULTI = 1 << 2, 280 NP_HALF = 1 << 3, 281 NP_FULL = 1 << 4, 282 NP_ORTHO = 1 << 5, 283 NP_TRI = 1 << 6, 284 NP_ATOMONLY = 1 << 7, 285 NP_MOLONLY = 1 << 8, 286 NP_NEWTON = 1 << 9, 287 NP_NEWTOFF = 1 << 10, 288 NP_GHOST = 1 << 11, 289 NP_SIZE = 1 << 12, 290 NP_ONESIDE = 1 << 13, 291 NP_RESPA = 1 << 14, 292 NP_BOND = 1 << 15, 293 NP_OMP = 1 << 16, 294 NP_INTEL = 1 << 17, 295 NP_KOKKOS_DEVICE = 1 << 18, 296 NP_KOKKOS_HOST = 1 << 19, 297 NP_SSA = 1 << 20, 298 NP_COPY = 1 << 21, 299 NP_SKIP = 1 << 22, 300 NP_HALF_FULL = 1 << 23, 301 NP_OFF2ON = 1 << 24, 302 NP_MULTI_OLD = 1 << 25 303 }; 304 } // namespace NeighConst 305 306 } // namespace LAMMPS_NS 307 308 #endif 309 310 /* ERROR/WARNING messages: 311 312 E: Neighbor delay must be 0 or multiple of every setting 313 314 The delay and every parameters set via the neigh_modify command are 315 inconsistent. If the delay setting is non-zero, then it must be a 316 multiple of the every setting. 317 318 E: Neighbor page size must be >= 10x the one atom setting 319 320 This is required to prevent wasting too much memory. 321 322 E: Invalid atom type in neighbor exclusion list 323 324 Atom types must range from 1 to Ntypes inclusive. 325 326 W: Neighbor exclusions used with KSpace solver may give inconsistent Coulombic energies 327 328 This is because excluding specific pair interactions also excludes 329 them from long-range interactions which may not be the desired effect. 330 The special_bonds command handles this consistently by insuring 331 excluded (or weighted) 1-2, 1-3, 1-4 interactions are treated 332 consistently by both the short-range pair style and the long-range 333 solver. This is not done for exclusions of charged atom pairs via the 334 neigh_modify exclude command. 335 336 E: Cannot request an occasional binned neighbor list with ghost info 337 338 UNDOCUMENTED 339 340 E: Requested neighbor bin option does not exist 341 342 UNDOCUMENTED 343 344 E: Requested neighbor stencil method does not exist 345 346 UNDOCUMENTED 347 348 E: Requested neighbor pair method does not exist 349 350 UNDOCUMENTED 351 352 E: Could not assign bin method to neighbor stencil 353 354 UNDOCUMENTED 355 356 E: Could not assign bin method to neighbor pair 357 358 UNDOCUMENTED 359 360 E: Could not assign stencil method to neighbor pair 361 362 UNDOCUMENTED 363 364 E: Neighbor include group not allowed with ghost neighbors 365 366 This is a current restriction within LAMMPS. 367 368 E: Too many local+ghost atoms for neighbor list 369 370 The number of nlocal + nghost atoms on a processor 371 is limited by the size of a 32-bit integer with 2 bits 372 removed for masking 1-2, 1-3, 1-4 neighbors. 373 374 E: Trying to build an occasional neighbor list before initialization completed 375 376 This is not allowed. Source code caller needs to be modified. 377 378 E: Neighbor build one invoked on perpetual list 379 380 UNDOCUMENTED 381 382 E: Illegal ... command 383 384 Self-explanatory. Check the input script syntax and compare to the 385 documentation for the command. You can use -echo screen as a 386 command-line option when running LAMMPS to see the offending line. 387 388 E: Invalid group ID in neigh_modify command 389 390 A group ID used in the neigh_modify command does not exist. 391 392 E: Neigh_modify include group != atom_modify first group 393 394 Self-explanatory. 395 396 E: Neigh_modify exclude molecule requires atom attribute molecule 397 398 Self-explanatory. 399 400 E: Unable to find group-group exclusion 401 402 UNDOCUMENTED 403 404 U: Neighbor multi not yet enabled for ghost neighbors 405 406 This is a current restriction within LAMMPS. 407 408 U: Neighbor multi not yet enabled for granular 409 410 Self-explanatory. 411 412 U: Neighbor multi not yet enabled for rRESPA 413 414 Self-explanatory. 415 416 U: Domain too large for neighbor bins 417 418 The domain has become extremely large so that neighbor bins cannot be 419 used. Most likely, one or more atoms have been blown out of the 420 simulation box to a great distance. 421 422 U: Cannot use neighbor bins - box size << cutoff 423 424 Too many neighbor bins will be created. This typically happens when 425 the simulation box is very small in some dimension, compared to the 426 neighbor cutoff. Use the "nsq" style instead of "bin" style. 427 428 U: Too many neighbor bins 429 430 This is likely due to an immense simulation box that has blown up 431 to a large size. 432 433 */ 434