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_ATOM_H 15 #define LMP_ATOM_H 16 17 #include "pointers.h" 18 19 #include <map> 20 #include <set> 21 22 namespace LAMMPS_NS { 23 24 // forward declaration 25 26 class AtomVec; 27 28 class Atom : protected Pointers { 29 public: 30 char *atom_style; 31 AtomVec *avec; 32 enum { DOUBLE, INT, BIGINT }; 33 enum { GROW = 0, RESTART = 1, BORDER = 2 }; 34 enum { ATOMIC = 0, MOLECULAR = 1, TEMPLATE = 2 }; 35 enum { MAP_NONE = 0, MAP_ARRAY = 1, MAP_HASH = 2, MAP_YES = 3 }; 36 37 // atom counts 38 39 bigint natoms; // total # of atoms in system, could be 0 40 // natoms may not be current if atoms lost 41 int nlocal, nghost; // # of owned and ghost atoms on this proc 42 int nmax; // max # of owned+ghost in arrays on this proc 43 int tag_enable; // 0/1 if atom ID tags are defined 44 int molecular; // 0 = atomic, 1 = standard molecular system, 45 // 2 = molecule template system 46 bigint nellipsoids; // number of ellipsoids 47 bigint nlines; // number of lines 48 bigint ntris; // number of triangles 49 bigint nbodies; // number of bodies 50 51 // system properties 52 53 bigint nbonds, nangles, ndihedrals, nimpropers; 54 int ntypes, nbondtypes, nangletypes, ndihedraltypes, nimpropertypes; 55 int bond_per_atom, angle_per_atom, dihedral_per_atom, improper_per_atom; 56 int extra_bond_per_atom, extra_angle_per_atom; 57 int extra_dihedral_per_atom, extra_improper_per_atom; 58 59 int firstgroup; // store atoms in this group first, -1 if unset 60 int nfirst; // # of atoms in first group on this proc 61 char *firstgroupname; // group-ID to store first, null pointer if unset 62 63 // -------------------------------------------------------------------- 64 // 1st customization section: customize by adding new per-atom variable 65 // per-atom vectors and arrays 66 67 tagint *tag; 68 int *type, *mask; 69 imageint *image; 70 double **x, **v, **f; 71 72 // charged and dipolar particles 73 74 double *rmass; 75 double *q, **mu; 76 77 // finite-size particles 78 79 double *radius; 80 double **omega, **angmom, **torque; 81 int *ellipsoid, *line, *tri, *body; 82 83 // molecular systems 84 85 tagint *molecule; 86 int *molindex, *molatom; 87 88 int **nspecial; // 0,1,2 = cumulative # of 1-2,1-3,1-4 neighs 89 tagint **special; // IDs of 1-2,1-3,1-4 neighs of each atom 90 int maxspecial; // special[nlocal][maxspecial] 91 92 int *num_bond; 93 int **bond_type; 94 tagint **bond_atom; 95 96 int *num_angle; 97 int **angle_type; 98 tagint **angle_atom1, **angle_atom2, **angle_atom3; 99 100 int *num_dihedral; 101 int **dihedral_type; 102 tagint **dihedral_atom1, **dihedral_atom2, **dihedral_atom3, **dihedral_atom4; 103 104 int *num_improper; 105 int **improper_type; 106 tagint **improper_atom1, **improper_atom2, **improper_atom3, **improper_atom4; 107 108 // PERI package 109 110 double *vfrac, *s0; 111 double **x0; 112 113 // SPIN package 114 115 double **sp, **fm, **fm_long; 116 117 // EFF and AWPMD packages 118 119 int *spin; 120 double *eradius, *ervel, *erforce; 121 double *ervelforce; 122 double **cs, **csforce, **vforce; 123 int *etag; 124 125 // CG-DNA package 126 127 tagint *id5p; 128 129 // DPD-REACT package 130 131 double *uCond, *uMech, *uChem, *uCGnew, *uCG; 132 double *duChem; 133 double *dpdTheta; 134 int nspecies_dpd; 135 136 // MESO package 137 138 double **cc, **cc_flux; // cc = chemical concentration 139 double *edpd_temp, *edpd_flux; // temperature and heat flux 140 double *vest_temp; 141 double *edpd_cv; // heat capacity 142 int cc_species; 143 144 // MESONT package 145 146 double *length; 147 int *buckling; 148 tagint **bond_nt; 149 150 // MACHDYN package 151 152 double *contact_radius; 153 double **smd_data_9; 154 double **smd_stress; 155 double *eff_plastic_strain; 156 double *eff_plastic_strain_rate; 157 double *damage; 158 159 // SPH package 160 161 double *rho, *drho, *esph, *desph, *cv; 162 double **vest; 163 164 // DIELECTRIC package 165 166 double *area, *ed, *em, *epsilon, *curvature, *q_unscaled; 167 168 // end of customization section 169 // -------------------------------------------------------------------- 170 171 // -------------------------------------------------------------------- 172 // 2nd customization section: customize by adding new flags 173 // identical list as Atom::set_atomflag_defaults() 174 // most are existence flags for per-atom vectors and arrays 175 // 1 if variable is used, 0 if not 176 177 int sphere_flag, ellipsoid_flag, line_flag, tri_flag, body_flag; 178 int peri_flag, electron_flag; 179 int wavepacket_flag, sph_flag; 180 181 int molecule_flag, molindex_flag, molatom_flag; 182 int q_flag, mu_flag; 183 int rmass_flag, radius_flag, omega_flag, torque_flag, angmom_flag; 184 int vfrac_flag, spin_flag, eradius_flag, ervel_flag, erforce_flag; 185 int cs_flag, csforce_flag, vforce_flag, ervelforce_flag, etag_flag; 186 int rho_flag, esph_flag, cv_flag, vest_flag; 187 int dpd_flag, edpd_flag, tdpd_flag; 188 int mesont_flag; 189 190 // SPIN package 191 192 int sp_flag; 193 194 // MACHDYN package 195 196 int x0_flag; 197 int smd_flag, damage_flag; 198 int contact_radius_flag, smd_data_9_flag, smd_stress_flag; 199 int eff_plastic_strain_flag, eff_plastic_strain_rate_flag; 200 201 // Peridynamics scale factor, used by dump cfg 202 203 double pdscale; 204 205 // end of customization section 206 // -------------------------------------------------------------------- 207 208 // per-atom data struct describing all per-atom vectors/arrays 209 210 struct PerAtom { 211 char *name; 212 void *address; 213 void *address_length; 214 int *address_maxcols; 215 int datatype; 216 int cols; 217 int collength; 218 int threadflag; 219 }; 220 221 PerAtom *peratom; 222 int nperatom, maxperatom; 223 224 // custom vectors and arrays used by fix property/atom 225 226 int **ivector, ***iarray; 227 double **dvector, ***darray; 228 int *icols, *dcols; 229 char **ivname, **dvname, **ianame, **daname; 230 int nivector, ndvector, niarray, ndarray; 231 232 // molecule templates 233 // each template can be a set of consecutive molecules 234 // each with same ID (stored in molecules) 235 // 1st molecule in template stores nset = # in set 236 237 int nmolecule; 238 class Molecule **molecules; 239 240 // extra peratom info in restart file destined for fix & diag 241 242 double **extra; 243 244 // per-type arrays 245 246 double *mass; 247 int *mass_setflag; 248 249 // callback ptrs for atom arrays managed by fix classes 250 251 int nextra_grow, nextra_restart, nextra_border; // # of callbacks of each type 252 int *extra_grow, *extra_restart, *extra_border; // index of fix to callback to 253 int nextra_grow_max, nextra_restart_max; // size of callback lists 254 int nextra_border_max; 255 int nextra_store; 256 257 int map_style; // style of atom map: 0=none, 1=array, 2=hash 258 int map_user; // user requested map style: 259 // 0 = no request, 1=array, 2=hash, 3=yes 260 tagint map_tag_max; // max atom ID that map() is setup for 261 std::set<tagint> *unique_tags; // set to ensure that bodies have unique tags 262 263 // spatial sorting of atoms 264 265 int sortfreq; // sort atoms every this many steps, 0 = off 266 bigint nextsort; // next timestep to sort on 267 double userbinsize; // requested sort bin size 268 269 // indices of atoms with same ID 270 271 int *sametag; // sametag[I] = next atom with same ID, -1 if no more 272 273 // AtomVec factory types and map 274 275 typedef AtomVec *(*AtomVecCreator)(LAMMPS *); 276 typedef std::map<std::string, AtomVecCreator> AtomVecCreatorMap; 277 AtomVecCreatorMap *avec_map; 278 279 // -------------------------------------------------------------------- 280 // functions 281 282 Atom(class LAMMPS *); 283 virtual ~Atom(); 284 285 void settings(class Atom *); 286 void peratom_create(); 287 void add_peratom(const char *, void *, int, int, int threadflag = 0); 288 void add_peratom_change_columns(const char *, int); 289 void add_peratom_vary(const char *, void *, int, int *, void *, int collength = 0); 290 void create_avec(const std::string &, int, char **, int); 291 virtual AtomVec *new_avec(const std::string &, int, int &); 292 293 void init(); 294 void setup(); 295 296 AtomVec *style_match(const char *); 297 void modify_params(int, char **); 298 void tag_check(); 299 void tag_extend(); 300 int tag_consecutive(); 301 302 void bonus_check(); 303 304 int parse_data(const char *); 305 306 void deallocate_topology(); 307 308 void data_atoms(int, char *, tagint, tagint, int, int, double *); 309 void data_vels(int, char *, tagint); 310 void data_bonds(int, char *, int *, tagint, int); 311 void data_angles(int, char *, int *, tagint, int); 312 void data_dihedrals(int, char *, int *, tagint, int); 313 void data_impropers(int, char *, int *, tagint, int); 314 void data_bonus(int, char *, AtomVec *, tagint); 315 void data_bodies(int, char *, AtomVec *, tagint); 316 void data_fix_compute_variable(int, int); 317 318 virtual void allocate_type_arrays(); 319 void set_mass(const char *, int, const char *, int); 320 void set_mass(const char *, int, int, double); 321 void set_mass(const char *, int, int, char **); 322 void set_mass(double *); 323 void check_mass(const char *, int); 324 325 int radius_consistency(int, double &); 326 int shape_consistency(int, double &, double &, double &); 327 328 void add_molecule(int, char **); 329 int find_molecule(char *); 330 void add_molecule_atom(class Molecule *, int, int, tagint); 331 332 void first_reorder(); 333 virtual void sort(); 334 335 void add_callback(int); 336 void delete_callback(const char *, int); 337 void update_callback(int); 338 339 int find_custom(const char *, int &, int &); 340 virtual int add_custom(const char *, int, int); 341 virtual void remove_custom(int, int, int); 342 sync_modify(ExecutionSpace,unsigned int,unsigned int)343 virtual void sync_modify(ExecutionSpace, unsigned int, unsigned int) {} 344 345 void *extract(const char *); 346 int extract_datatype(const char *); 347 get_map_array()348 inline int *get_map_array() { return map_array; }; get_map_size()349 inline int get_map_size() { return map_tag_max + 1; }; get_max_same()350 inline int get_max_same() { return max_same; }; get_map_maxarray()351 inline int get_map_maxarray() { return map_maxarray + 1; }; 352 353 // NOTE: placeholder method until KOKKOS/AtomVec is refactored memcheck(const char *)354 int memcheck(const char *) { return 1; } 355 356 double memory_usage(); 357 358 // functions for global to local ID mapping 359 // map lookup function inlined for efficiency 360 // return -1 if no map defined 361 map(tagint global)362 inline int map(tagint global) 363 { 364 if (map_style == 1) 365 return map_array[global]; 366 else if (map_style == 2) 367 return map_find_hash(global); 368 else 369 return -1; 370 }; 371 372 virtual void map_init(int check = 1); 373 virtual void map_clear(); 374 virtual void map_set(); 375 void map_one(tagint, int); 376 int map_style_set(); 377 virtual void map_delete(); 378 int map_find_hash(tagint); 379 380 protected: 381 // global to local ID mapping 382 383 int *map_array; // direct map via array that holds map_tag_max 384 int map_maxarray; // allocated size of map_array (1 larger than this) 385 386 struct HashElem { // hashed map 387 tagint global; // key to search on = global ID 388 int local; // value associated with key = local index 389 int next; // next entry in this bucket, -1 if last 390 }; 391 int map_nhash; // # of entries hash table can hold 392 int map_nused; // # of actual entries in hash table 393 int map_free; // ptr to 1st unused entry in hash table 394 int map_nbucket; // # of hash buckets 395 int *map_bucket; // ptr to 1st entry in each bucket 396 HashElem *map_hash; // hash table 397 398 int max_same; // allocated size of sametag 399 400 // spatial sorting of atoms 401 402 int nbins; // # of sorting bins 403 int nbinx, nbiny, nbinz; // bins in each dimension 404 int maxbin; // max # of bins 405 int maxnext; // max size of next,permute 406 int *binhead; // 1st atom in each bin 407 int *next; // next atom in bin 408 int *permute; // permutation vector 409 double bininvx, bininvy, bininvz; // inverse actual bin sizes 410 double bboxlo[3], bboxhi[3]; // bounding box of my sub-domain 411 412 void set_atomflag_defaults(); 413 void setup_sort_bins(); 414 int next_prime(int); 415 416 private: 417 template <typename T> static AtomVec *avec_creator(LAMMPS *); 418 }; 419 420 } // namespace LAMMPS_NS 421 422 #endif 423 424 /* ERROR/WARNING messages: 425 426 E: Atom IDs must be used for molecular systems 427 428 Atom IDs are used to identify and find partner atoms in bonds. 429 430 E: Unrecognized atom style 431 432 The choice of atom style is unknown. 433 434 E: Could not find atom_modify first group ID 435 436 Self-explanatory. 437 438 E: Illegal ... command 439 440 Self-explanatory. Check the input script syntax and compare to the 441 documentation for the command. You can use -echo screen as a 442 command-line option when running LAMMPS to see the offending line. 443 444 E: Atom_modify id command after simulation box is defined 445 446 The atom_modify id command cannot be used after a read_data, 447 read_restart, or create_box command. 448 449 E: Atom_modify map command after simulation box is defined 450 451 The atom_modify map command cannot be used after a read_data, 452 read_restart, or create_box command. 453 454 E: Atom_modify sort and first options cannot be used together 455 456 Self-explanatory. 457 458 E: One or more Atom IDs is negative 459 460 Atom IDs must be positive integers. 461 462 E: One or more atom IDs is too big 463 464 The limit on atom IDs is set by the SMALLBIG, BIGBIG, SMALLSMALL 465 setting in your Makefile. See Section_start 2.2 of the manual for 466 more details. 467 468 E: One or more atom IDs is zero 469 470 Either all atoms IDs must be zero or none of them. 471 472 E: Non-zero atom IDs with atom_modify id = no 473 474 Self-explanatory. 475 476 E: All atom IDs = 0 but atom_modify id = yes 477 478 Self-explanatory. 479 480 E: Duplicate atom IDs exist 481 482 Self-explanatory. 483 484 E: New atom IDs exceed maximum allowed ID 485 486 See the setting for tagint in the src/lmptype.h file. 487 488 E: Incorrect atom format in data file 489 490 Number of values per atom line in the data file is not consistent with 491 the atom style. 492 493 E: Incorrect format of ... section in data file 494 495 Number or type of values per line in the given section of the data file 496 is not consistent with the requirements for this section. 497 498 E: Invalid atom type in Atoms section of data file 499 500 Atom types must range from 1 to specified # of types. 501 502 E: Incorrect velocity format in data file 503 504 Each atom style defines a format for the Velocity section 505 of the data file. The read-in lines do not match. 506 507 E: Invalid atom ID in Velocities section of data file 508 509 Atom IDs must be positive integers and within range of defined 510 atoms. 511 512 E: Invalid atom ID in Bonds section of data file 513 514 Atom IDs must be positive integers and within range of defined 515 atoms. 516 517 E: Invalid bond type in Bonds section of data file 518 519 Bond type must be positive integer and within range of specified bond 520 types. 521 522 E: Invalid atom ID in Angles section of data file 523 524 Atom IDs must be positive integers and within range of defined 525 atoms. 526 527 E: Invalid angle type in Angles section of data file 528 529 Angle type must be positive integer and within range of specified angle 530 types. 531 532 E: Invalid atom ID in Dihedrals section of data file 533 534 Atom IDs must be positive integers and within range of defined 535 atoms. 536 537 E: Invalid dihedral type in Dihedrals section of data file 538 539 Dihedral type must be positive integer and within range of specified 540 dihedral types. 541 542 E: Invalid atom ID in Impropers section of data file 543 544 Atom IDs must be positive integers and within range of defined 545 atoms. 546 547 E: Invalid improper type in Impropers section of data file 548 549 Improper type must be positive integer and within range of specified 550 improper types. 551 552 E: Incorrect bonus data format in data file 553 554 See the read_data doc page for a description of how various kinds of 555 bonus data must be formatted for certain atom styles. 556 557 E: Invalid atom ID in Bonus section of data file 558 559 Atom IDs must be positive integers and within range of defined 560 atoms. 561 562 E: Invalid atom ID in Bodies section of data file 563 564 Atom IDs must be positive integers and within range of defined 565 atoms. 566 567 E: Reuse of molecule template ID 568 569 The template IDs must be unique. 570 571 E: Atom sort did not operate correctly 572 573 This is an internal LAMMPS error. Please report it to the 574 developers. 575 576 E: Too many atom sorting bins 577 578 This is likely due to an immense simulation box that has blown up 579 to a large size. 580 581 U: Cannot set mass for this atom style 582 583 This atom style does not support mass settings for each atom type. 584 Instead they are defined on a per-atom basis in the data file. 585 586 U: Invalid mass line in data file 587 588 Self-explanatory. 589 590 U: Invalid type for mass set 591 592 Mass command must set a type from 1-N where N is the number of atom 593 types. 594 595 U: Invalid mass value 596 597 Self-explanatory. 598 599 U: All masses are not set 600 601 For atom styles that define masses for each atom type, all masses must 602 be set in the data file or by the mass command before running a 603 simulation. They must also be set before using the velocity 604 command. 605 606 */ 607