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_FIX_H
15 #define LMP_FIX_H
16 
17 #include "pointers.h"    // IWYU pragma: export
18 
19 namespace LAMMPS_NS {
20 
21 class Fix : protected Pointers {
22  public:
23   static int instance_total;    // # of Fix classes ever instantiated
24 
25   char *id, *style;
26   int igroup, groupbit;
27 
28   int restart_global;      // 1 if Fix saves global state, 0 if not
29   int restart_peratom;     // 1 if Fix saves peratom state, 0 if not
30   int restart_file;        // 1 if Fix writes own restart file, 0 if not
31   int force_reneighbor;    // 1 if Fix forces reneighboring, 0 if not
32 
33   int box_change;    // >0 if Fix changes box size, shape, or sub-domains, 0 if not
34   // clang-format off
35   enum {
36     NO_BOX_CHANGE     = 0,
37     BOX_CHANGE_ANY    = 1 << 0,
38     BOX_CHANGE_DOMAIN = 1 << 1,
39     BOX_CHANGE_X      = 1 << 2,
40     BOX_CHANGE_Y      = 1 << 3,
41     BOX_CHANGE_Z      = 1 << 4,
42     BOX_CHANGE_YZ     = 1 << 5,
43     BOX_CHANGE_XZ     = 1 << 6,
44     BOX_CHANGE_XY     = 1 << 7,
45     BOX_CHANGE_SIZE   = BOX_CHANGE_X  | BOX_CHANGE_Y  | BOX_CHANGE_Z,
46     BOX_CHANGE_SHAPE  = BOX_CHANGE_YZ | BOX_CHANGE_XZ | BOX_CHANGE_XY
47   };
48   // clang-format on
49 
50   bigint next_reneighbor;      // next timestep to force a reneighboring
51   int nevery;                  // how often to call an end_of_step fix
52   int thermo_energy;           // 1 if fix_modify energy enabled, 0 if not
53   int thermo_virial;           // 1 if fix_modify virial enabled, 0 if not
54   int energy_global_flag;      // 1 if contributes to global eng
55   int energy_peratom_flag;     // 1 if contributes to peratom eng
56   int virial_global_flag;      // 1 if contributes to global virial
57   int virial_peratom_flag;     // 1 if contributes to peratom virial
58   int ecouple_flag;            // 1 if thermostat fix outputs cumulative
59                                //      reservoir energy via compute_scalar()
60   int time_integrate;          // 1 if performs time integration, 0 if no
61   int rigid_flag;              // 1 if integrates rigid bodies, 0 if not
62   int no_change_box;           // 1 if cannot swap ortho <-> triclinic
63   int time_depend;             // 1 if requires continuous timestepping
64   int create_attribute;        // 1 if fix stores attributes that need
65                                //      setting when a new atom is created
66   int restart_pbc;             // 1 if fix moves atoms (except integrate)
67                                //      so write_restart must remap to PBC
68   int wd_header;               // # of header values fix writes to data file
69   int wd_section;              // # of sections fix writes to data file
70   int dynamic_group_allow;     // 1 if can be used with dynamic group, else 0
71   int dof_flag;                // 1 if has dof() method (not min_dof())
72   int special_alter_flag;      // 1 if has special_alter() meth for spec lists
73   int enforce2d_flag;          // 1 if has enforce2d method
74   int respa_level_support;     // 1 if fix supports fix_modify respa
75   int respa_level;             // which respa level to apply fix (1-Nrespa)
76   int maxexchange;             // max # of per-atom values for Comm::exchange()
77   int maxexchange_dynamic;     // 1 if fix sets maxexchange dynamically
78   int pre_exchange_migrate;    // 1 if fix migrates atoms in pre_exchange()
79   int stores_ids;              // 1 if fix stores atom IDs
80 
81   int scalar_flag;                 // 0/1 if compute_scalar() function exists
82   int vector_flag;                 // 0/1 if compute_vector() function exists
83   int array_flag;                  // 0/1 if compute_array() function exists
84   int size_vector;                 // length of global vector
85   int size_array_rows;             // rows in global array
86   int size_array_cols;             // columns in global array
87   int size_vector_variable;        // 1 if vec length is unknown in advance
88   int size_array_rows_variable;    // 1 if array rows is unknown in advance
89   int global_freq;                 // frequency s/v data is available at
90 
91   int peratom_flag;         // 0/1 if per-atom data is stored
92   int size_peratom_cols;    // 0 = vector, N = columns in peratom array
93   int peratom_freq;         // frequency per-atom data is available at
94 
95   int local_flag;         // 0/1 if local data is stored
96   int size_local_rows;    // rows in local vector or array
97   int size_local_cols;    // 0 = vector, N = columns in local array
98   int local_freq;         // frequency local data is available at
99 
100   int extscalar;    // 0/1 if global scalar is intensive/extensive
101   int extvector;    // 0/1/-1 if global vector is all int/ext/extlist
102   int *extlist;     // list of 0/1 int/ext for each vec component
103   int extarray;     // 0/1 if global array is intensive/extensive
104 
105   double *vector_atom;     // computed per-atom vector
106   double **array_atom;     // computed per-atom array
107   double *vector_local;    // computed local vector
108   double **array_local;    // computed local array
109 
110   int comm_forward;    // size of forward communication (0 if none)
111   int comm_reverse;    // size of reverse communication (0 if none)
112   int comm_border;     // size of border communication (0 if none)
113 
114   double virial[6];          // virial for this timestep
115   double *eatom, **vatom;    // per-atom energy/virial for this timestep
116 
117   int centroidstressflag;    // centroid stress compared to two-body stress
118                              // CENTROID_SAME = same as two-body stress
119                              // CENTROID_AVAIL = different and implemented
120                              // CENTROID_NOTAVAIL = different, not yet implemented
121 
122   int restart_reset;    // 1 if restart just re-initialized fix
123 
124   // KOKKOS host/device flag and data masks
125 
126   int kokkosable;             // 1 if Kokkos fix
127   int forward_comm_device;    // 1 if forward comm on Device
128   ExecutionSpace execution_space;
129   unsigned int datamask_read, datamask_modify;
130 
131   Fix(class LAMMPS *, int, char **);
132   virtual ~Fix();
133   void modify_params(int, char **);
134 
135   virtual int setmask() = 0;
136 
post_constructor()137   virtual void post_constructor() {}
init()138   virtual void init() {}
init_list(int,class NeighList *)139   virtual void init_list(int, class NeighList *) {}
setup(int)140   virtual void setup(int) {}
setup_pre_exchange()141   virtual void setup_pre_exchange() {}
setup_pre_neighbor()142   virtual void setup_pre_neighbor() {}
setup_post_neighbor()143   virtual void setup_post_neighbor() {}
setup_pre_force(int)144   virtual void setup_pre_force(int) {}
setup_pre_reverse(int,int)145   virtual void setup_pre_reverse(int, int) {}
min_setup(int)146   virtual void min_setup(int) {}
initial_integrate(int)147   virtual void initial_integrate(int) {}
post_integrate()148   virtual void post_integrate() {}
pre_exchange()149   virtual void pre_exchange() {}
pre_neighbor()150   virtual void pre_neighbor() {}
post_neighbor()151   virtual void post_neighbor() {}
pre_force(int)152   virtual void pre_force(int) {}
pre_reverse(int,int)153   virtual void pre_reverse(int, int) {}
post_force(int)154   virtual void post_force(int) {}
final_integrate()155   virtual void final_integrate() {}
end_of_step()156   virtual void end_of_step() {}
post_run()157   virtual void post_run() {}
write_restart(FILE *)158   virtual void write_restart(FILE *) {}
write_restart_file(const char *)159   virtual void write_restart_file(const char *) {}
restart(char *)160   virtual void restart(char *) {}
161 
grow_arrays(int)162   virtual void grow_arrays(int) {}
copy_arrays(int,int,int)163   virtual void copy_arrays(int, int, int) {}
set_arrays(int)164   virtual void set_arrays(int) {}
update_arrays(int,int)165   virtual void update_arrays(int, int) {}
166   virtual void set_molecule(int, tagint, int, double *, double *, double *);
clear_bonus()167   virtual void clear_bonus() {}
168 
pack_border(int,int *,double *)169   virtual int pack_border(int, int *, double *) { return 0; }
unpack_border(int,int,double *)170   virtual int unpack_border(int, int, double *) { return 0; }
pack_exchange(int,double *)171   virtual int pack_exchange(int, double *) { return 0; }
unpack_exchange(int,double *)172   virtual int unpack_exchange(int, double *) { return 0; }
pack_restart(int,double *)173   virtual int pack_restart(int, double *) { return 0; }
unpack_restart(int,int)174   virtual void unpack_restart(int, int) {}
size_restart(int)175   virtual int size_restart(int) { return 0; }
maxsize_restart()176   virtual int maxsize_restart() { return 0; }
177 
setup_pre_force_respa(int,int)178   virtual void setup_pre_force_respa(int, int) {}
initial_integrate_respa(int,int,int)179   virtual void initial_integrate_respa(int, int, int) {}
post_integrate_respa(int,int)180   virtual void post_integrate_respa(int, int) {}
pre_force_respa(int,int,int)181   virtual void pre_force_respa(int, int, int) {}
post_force_respa(int,int,int)182   virtual void post_force_respa(int, int, int) {}
final_integrate_respa(int,int)183   virtual void final_integrate_respa(int, int) {}
184 
min_pre_exchange()185   virtual void min_pre_exchange() {}
min_pre_neighbor()186   virtual void min_pre_neighbor() {}
min_post_neighbor()187   virtual void min_post_neighbor() {}
min_pre_force(int)188   virtual void min_pre_force(int) {}
min_pre_reverse(int,int)189   virtual void min_pre_reverse(int, int) {}
min_post_force(int)190   virtual void min_post_force(int) {}
191 
min_energy(double *)192   virtual double min_energy(double *) { return 0.0; }
min_store()193   virtual void min_store() {}
min_clearstore()194   virtual void min_clearstore() {}
min_pushstore()195   virtual void min_pushstore() {}
min_popstore()196   virtual void min_popstore() {}
min_reset_ref()197   virtual int min_reset_ref() { return 0; }
min_step(double,double *)198   virtual void min_step(double, double *) {}
max_alpha(double *)199   virtual double max_alpha(double *) { return 0.0; }
min_dof()200   virtual int min_dof() { return 0; }
201 
pack_forward_comm(int,int *,double *,int,int *)202   virtual int pack_forward_comm(int, int *, double *, int, int *) { return 0; }
unpack_forward_comm(int,int,double *)203   virtual void unpack_forward_comm(int, int, double *) {}
pack_reverse_comm_size(int,int)204   virtual int pack_reverse_comm_size(int, int) { return 0; }
pack_reverse_comm(int,int,double *)205   virtual int pack_reverse_comm(int, int, double *) { return 0; }
unpack_reverse_comm(int,int *,double *)206   virtual void unpack_reverse_comm(int, int *, double *) {}
207 
pack_forward_grid(int,void *,int,int *)208   virtual void pack_forward_grid(int, void *, int, int *){};
unpack_forward_grid(int,void *,int,int *)209   virtual void unpack_forward_grid(int, void *, int, int *){};
pack_reverse_grid(int,void *,int,int *)210   virtual void pack_reverse_grid(int, void *, int, int *){};
unpack_reverse_grid(int,void *,int,int *)211   virtual void unpack_reverse_grid(int, void *, int, int *){};
pack_gather_grid(int,void *)212   virtual void pack_gather_grid(int, void *){};
unpack_gather_grid(int,void *,void *,int,int,int,int,int,int)213   virtual void unpack_gather_grid(int, void *, void *, int, int, int, int, int, int){};
214 
compute_scalar()215   virtual double compute_scalar() { return 0.0; }
compute_vector(int)216   virtual double compute_vector(int) { return 0.0; }
compute_array(int,int)217   virtual double compute_array(int, int) { return 0.0; }
218 
dof(int)219   virtual int dof(int) { return 0; }
deform(int)220   virtual void deform(int) {}
reset_target(double)221   virtual void reset_target(double) {}
reset_dt()222   virtual void reset_dt() {}
enforce2d()223   virtual void enforce2d() {}
224 
read_data_header(char *)225   virtual void read_data_header(char *) {}
read_data_section(char *,int,char *,tagint)226   virtual void read_data_section(char *, int, char *, tagint) {}
read_data_skip_lines(char *)227   virtual bigint read_data_skip_lines(char *) { return 0; }
228 
write_data_header(FILE *,int)229   virtual void write_data_header(FILE *, int) {}
write_data_section_size(int,int &,int &)230   virtual void write_data_section_size(int, int &, int &) {}
write_data_section_pack(int,double **)231   virtual void write_data_section_pack(int, double **) {}
write_data_section_keyword(int,FILE *)232   virtual void write_data_section_keyword(int, FILE *) {}
write_data_section(int,FILE *,int,double **,int)233   virtual void write_data_section(int, FILE *, int, double **, int) {}
234 
zero_momentum()235   virtual void zero_momentum() {}
zero_rotation()236   virtual void zero_rotation() {}
237 
rebuild_special()238   virtual void rebuild_special() {}
239 
image(int * &,double ** &)240   virtual int image(int *&, double **&) { return 0; }
241 
modify_param(int,char **)242   virtual int modify_param(int, char **) { return 0; }
extract(const char *,int &)243   virtual void *extract(const char *, int &) { return nullptr; }
244 
memory_usage()245   virtual double memory_usage() { return 0.0; }
246 
247  protected:
248   int instance_me;    // which Fix class instantiation I am
249 
250   int evflag;
251   int eflag_either, eflag_global, eflag_atom;
252   int vflag_either, vflag_global, vflag_atom;
253   int maxeatom, maxvatom;
254 
255   int copymode;    // if set, do not deallocate during destruction
256                    // required when classes are used as functors by Kokkos
257 
258   int dynamic;    // recount atoms for temperature computes
259 
ev_init(int eflag,int vflag)260   void ev_init(int eflag, int vflag)
261   {
262     if ((eflag && thermo_energy) || (vflag && thermo_virial))
263       ev_setup(eflag, vflag);
264     else
265       evflag = eflag_either = eflag_global = eflag_atom = vflag_either = vflag_global = vflag_atom =
266           0;
267   }
268   void ev_setup(int, int);
269   void ev_tally(int, int *, double, double, double *);
270 
v_init(int vflag)271   void v_init(int vflag)
272   {
273     if (vflag && thermo_virial)
274       v_setup(vflag);
275     else
276       evflag = vflag_either = vflag_global = vflag_atom = 0;
277   }
278   void v_setup(int);
279   void v_tally(int, int *, double, double *);
280   void v_tally(int, double *);
281   void v_tally(int, int, double);
282 };
283 
284 namespace FixConst {
285   enum {
286     INITIAL_INTEGRATE = 1 << 0,
287     POST_INTEGRATE = 1 << 1,
288     PRE_EXCHANGE = 1 << 2,
289     PRE_NEIGHBOR = 1 << 3,
290     POST_NEIGHBOR = 1 << 4,
291     PRE_FORCE = 1 << 5,
292     PRE_REVERSE = 1 << 6,
293     POST_FORCE = 1 << 7,
294     FINAL_INTEGRATE = 1 << 8,
295     END_OF_STEP = 1 << 9,
296     POST_RUN = 1 << 10,
297     INITIAL_INTEGRATE_RESPA = 1 << 11,
298     POST_INTEGRATE_RESPA = 1 << 12,
299     PRE_FORCE_RESPA = 1 << 13,
300     POST_FORCE_RESPA = 1 << 14,
301     FINAL_INTEGRATE_RESPA = 1 << 15,
302     MIN_PRE_EXCHANGE = 1 << 16,
303     MIN_PRE_NEIGHBOR = 1 << 17,
304     MIN_POST_NEIGHBOR = 1 << 18,
305     MIN_PRE_FORCE = 1 << 19,
306     MIN_PRE_REVERSE = 1 << 20,
307     MIN_POST_FORCE = 1 << 21,
308     MIN_ENERGY = 1 << 22
309   };
310 }
311 
312 }    // namespace LAMMPS_NS
313 
314 #endif
315 
316 /* ERROR/WARNING messages:
317 
318 E: Fix ID must be alphanumeric or underscore characters
319 
320 Self-explanatory.
321 
322 E: Could not find fix group ID
323 
324 A group ID used in the fix command does not exist.
325 
326 E: Illegal ... command
327 
328 Self-explanatory.  Check the input script syntax and compare to the
329 documentation for the command.  You can use -echo screen as a
330 command-line option when running LAMMPS to see the offending line.
331 
332 */
333