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_PAIR_H
15 #define LMP_PAIR_H
16 
17 #include "pointers.h"    // IWYU pragma: export
18 
19 namespace LAMMPS_NS {
20 
21 class Pair : protected Pointers {
22   friend class AngleSDK;
23   friend class AngleSDKOMP;
24   friend class BondQuartic;
25   friend class BondQuarticOMP;
26   friend class DihedralCharmm;
27   friend class DihedralCharmmOMP;
28   friend class FixGPU;
29   friend class FixIntel;
30   friend class FixOMP;
31   friend class FixQEq;
32   friend class PairHybrid;
33   friend class PairHybridScaled;
34   friend class ThrOMP;
35   friend class Info;
36 
37  public:
38   static int instance_total;    // # of Pair classes ever instantiated
39 
40   double eng_vdwl, eng_coul;    // accumulated energies
41   double virial[6];             // accumulated virial: xx,yy,zz,xy,xz,yz
42   double *eatom, **vatom;       // accumulated per-atom energy/virial
43   double **cvatom;              // accumulated per-atom centroid virial
44 
45   double cutforce;    // max cutoff for all atom pairs
46   double **cutsq;     // cutoff sq for each atom pair
47   int **setflag;      // 0/1 = whether each i,j has been set
48 
49   int comm_forward;        // size of forward communication (0 if none)
50   int comm_reverse;        // size of reverse communication (0 if none)
51   int comm_reverse_off;    // size of reverse comm even if newton off
52 
53   int single_enable;              // 1 if single() routine exists
54   int single_hessian_enable;      // 1 if single_hessian() routine exists
55   int restartinfo;                // 1 if pair style writes restart info
56   int respa_enable;               // 1 if inner/middle/outer rRESPA routines
57   int one_coeff;                  // 1 if allows only one coeff * * call
58   int manybody_flag;              // 1 if a manybody potential
59   int unit_convert_flag;          // value != 0 indicates support for unit conversion.
60   int no_virial_fdotr_compute;    // 1 if does not invoke virial_fdotr_compute()
61   int writedata;                  // 1 if writes coeffs to data file
62   int finitecutflag;              // 1 if cut depends on finite atom size
63   int ghostneigh;                 // 1 if pair style needs neighbors of ghosts
64   double **cutghost;              // cutoff for each ghost pair
65 
66   int ewaldflag;         // 1 if compatible with Ewald solver
67   int pppmflag;          // 1 if compatible with PPPM solver
68   int msmflag;           // 1 if compatible with MSM solver
69   int dispersionflag;    // 1 if compatible with LJ/dispersion solver
70   int tip4pflag;         // 1 if compatible with TIP4P solver
71   int dipoleflag;        // 1 if compatible with dipole solver
72   int spinflag;          // 1 if compatible with spin solver
73   int reinitflag;        // 1 if compatible with fix adapt and alike
74 
75   int centroidstressflag;    // centroid stress compared to two-body stress
76                              // CENTROID_SAME = same as two-body stress
77                              // CENTROID_AVAIL = different and implemented
78                              // CENTROID_NOTAVAIL = different, not yet implemented
79 
80   int tail_flag;          // pair_modify flag for LJ tail correction
81   double etail, ptail;    // energy/pressure tail corrections
82   double etail_ij, ptail_ij;
83 
84   int evflag;    // energy,virial settings
85   int eflag_either, eflag_global, eflag_atom;
86   int vflag_either, vflag_global, vflag_atom, cvflag_atom;
87 
88   int ncoultablebits;    // size of Coulomb table, accessed by KSpace
89   int ndisptablebits;    // size of dispersion table
90   double tabinnersq;
91   double tabinnerdispsq;
92   double *rtable, *drtable, *ftable, *dftable, *ctable, *dctable;
93   double *etable, *detable, *ptable, *dptable, *vtable, *dvtable;
94   double *rdisptable, *drdisptable, *fdisptable, *dfdisptable;
95   double *edisptable, *dedisptable;
96   int ncoulshiftbits, ncoulmask;
97   int ndispshiftbits, ndispmask;
98 
99   int nextra;         // # of extra quantities pair style calculates
100   double *pvector;    // vector of extra pair quantities
101 
102   int single_extra;    // number of extra single values calculated
103   double *svector;     // vector of extra single quantities
104 
105   class NeighList *list;        // standard neighbor list used by most pairs
106   class NeighList *listhalf;    // half list used by some pairs
107   class NeighList *listfull;    // full list used by some pairs
108 
109   int allocated;       // 0/1 = whether arrays are allocated
110                        //       public so external driver can check
111   int compute_flag;    // 0 if skip compute()
112   int mixed_flag;      // 1 if all itype != jtype coeffs are from mixing
113 
114   enum { GEOMETRIC, ARITHMETIC, SIXTHPOWER };    // mixing options
115 
116   int beyond_contact, nondefault_history_transfer;    // for granular styles
117 
118   // KOKKOS host/device flag and data masks
119 
120   ExecutionSpace execution_space;
121   unsigned int datamask_read, datamask_modify;
122   int kokkosable;    // 1 if Kokkos pair
123 
124   Pair(class LAMMPS *);
125   virtual ~Pair();
126 
127   // top-level Pair methods
128 
129   void init();
130   virtual void reinit();
setup()131   virtual void setup() {}
132   double mix_energy(double, double, double, double);
133   double mix_distance(double, double);
134   void write_file(int, char **);
135   void init_bitmap(double, double, int, int &, int &, int &, int &);
136   virtual void modify_params(int, char **);
137   void compute_dummy(int, int);
138 
139   // need to be public, so can be called by pair_style reaxc
140 
141   void ev_tally(int, int, int, int, double, double, double, double, double, double);
142   void ev_tally3(int, int, int, double, double, double *, double *, double *, double *);
143   void v_tally2_newton(int, double *, double *);
144   void v_tally3(int, int, int, double *, double *, double *, double *);
145   void v_tally4(int, int, int, int, double *, double *, double *, double *, double *, double *);
146 
147   // general child-class methods
148 
149   virtual void compute(int, int) = 0;
compute_inner()150   virtual void compute_inner() {}
compute_middle()151   virtual void compute_middle() {}
compute_outer(int,int)152   virtual void compute_outer(int, int) {}
153 
single(int,int,int,int,double,double,double,double & fforce)154   virtual double single(int, int, int, int, double, double, double, double &fforce)
155   {
156     fforce = 0.0;
157     return 0.0;
158   }
159 
160   void hessian_twobody(double fforce, double dfac, double delr[3], double phiTensor[6]);
161 
single_hessian(int,int,int,int,double,double[3],double,double,double & fforce,double d2u[6])162   virtual double single_hessian(int, int, int, int, double, double[3], double, double,
163                                 double &fforce, double d2u[6])
164   {
165     fforce = 0.0;
166     for (int i = 0; i < 6; i++) d2u[i] = 0;
167     return 0.0;
168   }
169 
170   virtual void settings(int, char **) = 0;
171   virtual void coeff(int, char **) = 0;
172 
173   virtual void init_style();
174   virtual void init_list(int, class NeighList *);
init_one(int,int)175   virtual double init_one(int, int) { return 0.0; }
176 
177   virtual void init_tables(double, double *);
178   virtual void init_tables_disp(double);
179   virtual void free_tables();
180   virtual void free_disp_tables();
181 
182   virtual void write_restart(FILE *);
183   virtual void read_restart(FILE *);
write_restart_settings(FILE *)184   virtual void write_restart_settings(FILE *) {}
read_restart_settings(FILE *)185   virtual void read_restart_settings(FILE *) {}
write_data(FILE *)186   virtual void write_data(FILE *) {}
write_data_all(FILE *)187   virtual void write_data_all(FILE *) {}
188 
pack_forward_comm(int,int *,double *,int,int *)189   virtual int pack_forward_comm(int, int *, double *, int, int *) { return 0; }
unpack_forward_comm(int,int,double *)190   virtual void unpack_forward_comm(int, int, double *) {}
pack_reverse_comm(int,int,double *)191   virtual int pack_reverse_comm(int, int, double *) { return 0; }
unpack_reverse_comm(int,int *,double *)192   virtual void unpack_reverse_comm(int, int *, double *) {}
193   virtual double memory_usage();
194 
set_copymode(int value)195   void set_copymode(int value) { copymode = value; }
196 
197   // specific child-class methods for certain Pair styles
198 
extract(const char *,int &)199   virtual void *extract(const char *, int &) { return nullptr; }
swap_eam(double *,double **)200   virtual void swap_eam(double *, double **) {}
reset_dt()201   virtual void reset_dt() {}
min_xf_pointers(int,double **,double **)202   virtual void min_xf_pointers(int, double **, double **) {}
min_xf_get(int)203   virtual void min_xf_get(int) {}
min_x_set(int)204   virtual void min_x_set(int) {}
transfer_history(double *,double *)205   virtual void transfer_history(double *, double *) {}
atom2cut(int)206   virtual double atom2cut(int) { return 0.0; }
radii2cut(double,double)207   virtual double radii2cut(double, double) { return 0.0; }
208 
209   // management of callbacks to be run from ev_tally()
210 
211  protected:
212   int num_tally_compute;
213   class Compute **list_tally_compute;
214 
215  public:
216   virtual void add_tally_callback(class Compute *);
217   virtual void del_tally_callback(class Compute *);
218 
219  protected:
220   int instance_me;      // which Pair class instantiation I am
221   int special_lj[4];    // copied from force->special_lj for Kokkos
222   int suffix_flag;      // suffix compatibility flag
223 
224   // pair_modify settings
225   int offset_flag, mix_flag;    // flags for offset and mixing
226   double tabinner;              // inner cutoff for Coulomb table
227   double tabinner_disp;         // inner cutoff for dispersion table
228 
229  protected:
230   // for mapping of elements to atom types and parameters
231   // mostly used for manybody potentials
232   int nelements;        // # of unique elements
233   char **elements;      // names of unique elements
234   int *elem1param;      // mapping from elements to parameters
235   int **elem2param;     // mapping from element pairs to parameters
236   int ***elem3param;    // mapping from element triplets to parameters
237   int *map;             // mapping from atom types to elements
238   int nparams;          // # of stored parameter sets
239   int maxparam;         // max # of parameter sets
240   void map_element2type(int, char **, bool update_setflag = true);
241 
242  public:
243   // custom data type for accessing Coulomb tables
244 
245   typedef union {
246     int i;
247     float f;
248   } union_int_float_t;
249 
250   // Accessor for the INTEL package to determine virial calc for hybrid
251 
fdotr_is_set()252   inline int fdotr_is_set() const { return vflag_fdotr; }
253 
254  protected:
255   int vflag_fdotr;
256   int maxeatom, maxvatom, maxcvatom;
257 
258   int copymode;    // if set, do not deallocate during destruction
259                    // required when classes are used as functors by Kokkos
260 
261   void ev_init(int eflag, int vflag, int alloc = 1)
262   {
263     if (eflag || vflag)
264       ev_setup(eflag, vflag, alloc);
265     else
266       ev_unset();
267   }
268   virtual void ev_setup(int, int, int alloc = 1);
269   void ev_unset();
270   void ev_tally_full(int, double, double, double, double, double, double);
271   void ev_tally_xyz_full(int, double, double, double, double, double, double, double, double);
272   void ev_tally4(int, int, int, int, double, double *, double *, double *, double *, double *,
273                  double *);
274   void ev_tally_tip4p(int, int *, double *, double, double);
275   void ev_tally_xyz(int, int, int, int, double, double, double, double, double, double, double,
276                     double);
277   void v_tally2(int, int, double, double *);
278   void v_tally_tensor(int, int, int, int, double, double, double, double, double, double);
279   void virial_fdotr_compute();
280 
sbmask(int j)281   inline int sbmask(int j) const { return j >> SBBITS & 3; }
282 };
283 
284 }    // namespace LAMMPS_NS
285 
286 #endif
287 
288 /* ERROR/WARNING messages:
289 
290 E: Illegal ... command
291 
292 Self-explanatory.  Check the input script syntax and compare to the
293 documentation for the command.  You can use -echo screen as a
294 command-line option when running LAMMPS to see the offending line.
295 
296 E: Too many total bits for bitmapped lookup table
297 
298 Table size specified via pair_modify command is too large.  Note that
299 a value of N generates a 2^N size table.
300 
301 E: Cannot have both pair_modify shift and tail set to yes
302 
303 These 2 options are contradictory.
304 
305 E: Cannot use pair tail corrections with 2d simulations
306 
307 The correction factors are only currently defined for 3d systems.
308 
309 W: Using pair tail corrections with non-periodic system
310 
311 This is probably a bogus thing to do, since tail corrections are
312 computed by integrating the density of a periodic system out to
313 infinity.
314 
315 W: Using pair tail corrections with pair_modify compute no
316 
317 The tail corrections will thus not be computed.
318 
319 W: Using pair potential shift with pair_modify compute no
320 
321 The shift effects will thus not be computed.
322 
323 W: Using a manybody potential with bonds/angles/dihedrals and special_bond exclusions
324 
325 This is likely not what you want to do.  The exclusion settings will
326 eliminate neighbors in the neighbor list, which the manybody potential
327 needs to calculated its terms correctly.
328 
329 E: All pair coeffs are not set
330 
331 All pair coefficients must be set in the data file or by the
332 pair_coeff command before running a simulation.
333 
334 E: Fix adapt interface to this pair style not supported
335 
336 New coding for the pair style would need to be done.
337 
338 E: Pair style requires a KSpace style
339 
340 No kspace style is defined.
341 
342 E: BUG: restartinfo=1 but no restart support in pair style
343 
344 The pair style has a bug, where it does not support reading
345 and writing information to a restart file, but does not set
346 the member variable restartinfo to 0 as required in that case.
347 
348 E: Cannot yet use compute tally with Kokkos
349 
350 This feature is not yet supported.
351 
352 E: Pair style does not support pair_write
353 
354 The pair style does not have a single() function, so it can
355 not be invoked by pair write.
356 
357 E: Invalid atom types in pair_write command
358 
359 Atom types must range from 1 to Ntypes inclusive.
360 
361 E: Invalid style in pair_write command
362 
363 Self-explanatory.  Check the input script.
364 
365 E: Invalid cutoffs in pair_write command
366 
367 Inner cutoff must be larger than 0.0 and less than outer cutoff.
368 
369 E: Cannot open pair_write file
370 
371 The specified output file for pair energies and forces cannot be
372 opened.  Check that the path and name are correct.
373 
374 E: Bitmapped lookup tables require int/float be same size
375 
376 Cannot use pair tables on this machine, because of word sizes.  Use
377 the pair_modify command with table 0 instead.
378 
379 W: Table inner cutoff >= outer cutoff
380 
381 You specified an inner cutoff for a Coulombic table that is longer
382 than the global cutoff.  Probably not what you wanted.
383 
384 E: Too many exponent bits for lookup table
385 
386 Table size specified via pair_modify command does not work with your
387 machine's floating point representation.
388 
389 E: Too many mantissa bits for lookup table
390 
391 Table size specified via pair_modify command does not work with your
392 machine's floating point representation.
393 
394 E: Too few bits for lookup table
395 
396 Table size specified via pair_modify command does not work with your
397 machine's floating point representation.
398 
399 */
400