1 /* ----------------------------------------------------------------------
2     This is the
3 
4     ██╗     ██╗ ██████╗  ██████╗  ██████╗ ██╗  ██╗████████╗███████╗
5     ██║     ██║██╔════╝ ██╔════╝ ██╔════╝ ██║  ██║╚══██╔══╝██╔════╝
6     ██║     ██║██║  ███╗██║  ███╗██║  ███╗███████║   ██║   ███████╗
7     ██║     ██║██║   ██║██║   ██║██║   ██║██╔══██║   ██║   ╚════██║
8     ███████╗██║╚██████╔╝╚██████╔╝╚██████╔╝██║  ██║   ██║   ███████║
9     ╚══════╝╚═╝ ╚═════╝  ╚═════╝  ╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚══════╝®
10 
11     DEM simulation engine, released by
12     DCS Computing Gmbh, Linz, Austria
13     http://www.dcs-computing.com, office@dcs-computing.com
14 
15     LIGGGHTS® is part of CFDEM®project:
16     http://www.liggghts.com | http://www.cfdem.com
17 
18     Core developer and main author:
19     Christoph Kloss, christoph.kloss@dcs-computing.com
20 
21     LIGGGHTS® is open-source, distributed under the terms of the GNU Public
22     License, version 2 or later. It is distributed in the hope that it will
23     be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You should have
25     received a copy of the GNU General Public License along with LIGGGHTS®.
26     If not, see http://www.gnu.org/licenses . See also top-level README
27     and LICENSE files.
28 
29     LIGGGHTS® and CFDEM® are registered trade marks of DCS Computing GmbH,
30     the producer of the LIGGGHTS® software and the CFDEM®coupling software
31     See http://www.cfdem.com/terms-trademark-policy for details.
32 
33 -------------------------------------------------------------------------
34     Contributing author and copyright for this file:
35     This file is from LAMMPS, but has been modified. Copyright for
36     modification:
37 
38     Copyright 2012-     DCS Computing GmbH, Linz
39     Copyright 2009-2012 JKU Linz
40 
41     Copyright of original file:
42     LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
43     http://lammps.sandia.gov, Sandia National Laboratories
44     Steve Plimpton, sjplimp@sandia.gov
45 
46     Copyright (2003) Sandia Corporation.  Under the terms of Contract
47     DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
48     certain rights in this software.  This software is distributed under
49     the GNU General Public License.
50 ------------------------------------------------------------------------- */
51 
52 #ifndef LMP_FIX_H
53 #define LMP_FIX_H
54 
55 #include "pointers.h"
56 
57 namespace LAMMPS_NS {
58 
59 class Fix : protected Pointers {
60  public:
61   char *id,*style;
62   int igroup,groupbit;
63 
64   int restart_global;            // 1 if Fix saves global state, 0 if not
65   int restart_peratom;           // 1 if Fix saves peratom state, 0 if not
66   int restart_file;              // 1 if Fix writes own restart file, 0 if not
67   int force_reneighbor;          // 1 if Fix forces reneighboring, 0 if not
68   int box_change_size;           // 1 if Fix changes box size, 0 if not
69   int box_change_shape;          // 1 if Fix changes box shape, 0 if not
70   int box_change_domain;         // 1 if Fix changes proc sub-domains, 0 if not
71 
72   bigint next_reneighbor;        // next timestep to force a reneighboring
73   int thermo_energy;             // 1 if fix_modify enabled ThEng, 0 if not
74   int nevery;                    // how often to call an end_of_step fix
75   int rigid_flag;                // 1 if Fix integrates rigid bodies, 0 if not
76   int virial_flag;               // 1 if Fix contributes to virial, 0 if not
77   int no_change_box;             // 1 if cannot swap ortho <-> triclinic
78   int time_integrate;            // 1 if fix performs time integration, 0 if no
79   int time_depend;               // 1 if requires continuous timestepping
80   int create_attribute;          // 1 if fix stores attributes that need
81                                  //      setting when a new atom is created
82   int restart_pbc;               // 1 if fix moves atoms (except integrate)
83                                  //      so write_restart must remap to PBC
84   int wd_header;                 // # of header values fix writes to data file
85   int wd_section;                // # of sections fix writes to data file
86   int dynamic_group_allow;       // 1 if can be used with dynamic group, else 0
87   int cudable_comm;              // 1 if fix has CUDA-enabled communication
88 
89   int rad_mass_vary_flag;        // 1 if particle radius or mass varied by fix
90   int just_created;              // 1 if fix was just created
91                                  //   ie no run yet since creation
92 
93   int scalar_flag;               // 0/1 if compute_scalar() function exists
94   int vector_flag;               // 0/1 if compute_vector() function exists
95   int array_flag;                // 0/1 if compute_array() function exists
96   int size_vector;               // length of global vector
97   int size_array_rows;           // rows in global array
98   int size_array_cols;           // columns in global array
99   int global_freq;               // frequency s/v data is available at
100 
101   int peratom_flag;              // 0/1 if per-atom data is stored
102   int size_peratom_cols;         // 0 = vector, N = columns in peratom array
103   int peratom_freq;              // frequency per-atom data is available at
104 
105   int local_flag;                // 0/1 if local data is stored
106   int size_local_rows;           // rows in local vector or array
107   int size_local_cols;           // 0 = vector, N = columns in local array
108   int local_freq;                // frequency local data is available at
109 
110   int extscalar;            // 0/1 if global scalar is intensive/extensive
111   int extvector;            // 0/1/-1 if global vector is all int/ext/extlist
112   int *extlist;             // list of 0/1 int/ext for each vec component
113   int extarray;             // 0/1 if global array is intensive/extensive
114 
115   double *vector_atom;           // computed per-atom vector
116   double **array_atom;           // computed per-atom array
117   double *vector_local;          // computed local vector
118   double **array_local;          // computed local array
119 
120   int comm_forward;              // size of forward communication (0 if none)
121   int comm_reverse;              // size of reverse communication (0 if none)
122   int comm_border;               // size of border communication (0 if none)
123 
124   double virial[6];              // accumlated virial
125   double **vatom;                // accumulated per-atom virial
126 
127   int recent_restart;
128 
129   int restart_reset;             // 1 if restart just re-initialized fix
130 
131   char *accepts_restart_data_from_style;
132 
133   unsigned int datamask;
134   unsigned int datamask_ext;
135 
136   Fix(class LAMMPS *, int, char **);
137   virtual ~Fix();
138   void modify_params(int, char **);
139 
140   virtual int setmask() = 0;
141 
post_create_pre_restart()142   virtual void post_create_pre_restart() {}
post_create()143   virtual void post_create() {}
pre_delete(bool)144   virtual void pre_delete(bool) {}
box_extent(double & xlo,double & xhi,double & ylo,double & yhi,double & zlo,double & zhi)145   virtual void box_extent(double &xlo,double &xhi,double &ylo,double &yhi,double &zlo,double &zhi) {
146     UNUSED(xlo); UNUSED(xhi); UNUSED(ylo); UNUSED(yhi); UNUSED(zlo); UNUSED(zhi);
147   }
init()148   virtual void init() {}
init_list(int,class NeighList *)149   virtual void init_list(int, class NeighList *) {}
setup(int)150   virtual void setup(int) {}
setup_pre_exchange()151   virtual void setup_pre_exchange() {}
setup_pre_neighbor()152   virtual void setup_pre_neighbor() {}
setup_pre_force(int)153   virtual void setup_pre_force(int) {}
min_setup(int)154   virtual void min_setup(int) {}
pre_initial_integrate()155   virtual void pre_initial_integrate() {}
initial_integrate(int)156   virtual void initial_integrate(int) {}
post_integrate()157   virtual void post_integrate() {}
pre_exchange()158   virtual void pre_exchange() {}
pre_neighbor()159   virtual void pre_neighbor() {}
pre_force(int)160   virtual void pre_force(int) {}
post_force(int)161   virtual void post_force(int) {}
pre_final_integrate()162   virtual void pre_final_integrate() {}
final_integrate()163   virtual void final_integrate() {}
iterate_implicitly()164   virtual bool iterate_implicitly() {return false;}
end_of_step()165   virtual void end_of_step() {}
post_run()166   virtual void post_run() {}
167   virtual void write_restart(FILE *);
write_restart_file(char *)168   virtual void write_restart_file(char *) {}
restart(char *)169   virtual void restart(char *) {}
170 
grow_arrays(int)171   virtual void grow_arrays(int) {}
copy_arrays(int,int,int)172   virtual void copy_arrays(int, int, int) {}
pre_set_arrays()173   virtual void pre_set_arrays() {}
set_arrays(int)174   virtual void set_arrays(int) {}
update_arrays(int,int)175   virtual void update_arrays(int, int) {}
pack_border(int,int *,double *)176   virtual int pack_border(int, int *, double *) {return 0;}
unpack_border(int,int,double *)177   virtual int unpack_border(int, int, double *) {return 0;}
pack_exchange(int,double *)178   virtual int pack_exchange(int, double *) {return 0;}
unpack_exchange(int,double *)179   virtual int unpack_exchange(int, double *) {return 0;}
pack_restart(int,double *)180   virtual int pack_restart(int, double *) {return 0;}
unpack_restart(int,int)181   virtual void unpack_restart(int, int) {}
size_restart(int)182   virtual int size_restart(int) {return 0;}
maxsize_restart()183   virtual int maxsize_restart() {return 0;}
184 
setup_pre_force_respa(int,int)185   virtual void setup_pre_force_respa(int, int) {}
initial_integrate_respa(int,int,int)186   virtual void initial_integrate_respa(int, int, int) {}
post_integrate_respa(int,int)187   virtual void post_integrate_respa(int, int) {}
pre_force_respa(int,int,int)188   virtual void pre_force_respa(int, int, int) {}
post_force_respa(int,int,int)189   virtual void post_force_respa(int, int, int) {}
final_integrate_respa(int,int)190   virtual void final_integrate_respa(int, int) {}
191 
min_setup_pre_exchange()192   virtual void min_setup_pre_exchange() {}
min_setup_pre_neighbor()193   virtual void min_setup_pre_neighbor() {}
min_setup_pre_force(int)194   virtual void min_setup_pre_force(int) {}
min_pre_exchange()195   virtual void min_pre_exchange() {}
min_pre_neighbor()196   virtual void min_pre_neighbor() {}
min_pre_force(int)197   virtual void min_pre_force(int) {}
min_post_force(int)198   virtual void min_post_force(int) {}
199 
min_energy(double *)200   virtual double min_energy(double *) {return 0.0;}
min_store()201   virtual void min_store() {}
min_clearstore()202   virtual void min_clearstore() {}
min_pushstore()203   virtual void min_pushstore() {}
min_popstore()204   virtual void min_popstore() {}
min_reset_ref()205   virtual int min_reset_ref() {return 0;}
min_step(double,double *)206   virtual void min_step(double, double *) {}
max_alpha(double *)207   virtual double max_alpha(double *) {return 0.0;}
min_dof()208   virtual int min_dof() {return 0;}
209 
pack_comm(int,int *,double *,int,int *)210   virtual int pack_comm(int, int *, double *, int, int *) {return 0;}
unpack_comm(int,int,double *)211   virtual void unpack_comm(int, int, double *) {}
pack_reverse_comm(int,int,double *)212   virtual int pack_reverse_comm(int, int, double *) {return 0;}
unpack_reverse_comm(int,int *,double *)213   virtual void unpack_reverse_comm(int, int *, double *) {}
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() {}
reset_timestep(bigint)223   virtual void reset_timestep(bigint) {}
reset_timestep(bigint newstep,bigint oldstep)224   virtual void reset_timestep(bigint newstep,bigint oldstep)
225   { reset_timestep(newstep); }
226 
read_data_header(char *)227   virtual void read_data_header(char *) {}
read_data_section(char *,int,char *)228   virtual void read_data_section(char *, int, char *) {}
read_data_skip_lines(char *)229   virtual bigint read_data_skip_lines(char *) {return 0;}
230 
write_data_header(FILE *,int)231   virtual void write_data_header(FILE *, int) {}
write_data_section_size(int,int &,int &)232   virtual void write_data_section_size(int, int &, int &) {}
write_data_section_pack(int,double **)233   virtual void write_data_section_pack(int, double **) {}
write_data_section_keyword(int,FILE *)234   virtual void write_data_section_keyword(int, FILE *) {}
write_data_section(int,FILE *,int,double **,int)235   virtual void write_data_section(int, FILE *, int, double **, int) {}
236 
zero_momentum()237   virtual void zero_momentum() {}
zero_rotation()238   virtual void zero_rotation() {}
239 
modify_param(int,char **)240   virtual int modify_param(int, char **) {return 0;}
extract(const char *,int &)241   virtual void *extract(const char *, int &) {return NULL;}
242 
memory_usage()243   virtual double memory_usage() {return 0.0;}
244 
data_mask()245   virtual unsigned int data_mask() {return datamask;}
data_mask_ext()246   virtual unsigned int data_mask_ext() {return datamask_ext;}
247 
use_rad_for_cut_neigh_and_ghost()248   virtual bool use_rad_for_cut_neigh_and_ghost() {return true;}
min_rad(int)249   virtual double min_rad(int) {return 0.0;}
max_rad(int)250   virtual double max_rad(int) {return 0.0;}
min_type()251   virtual int min_type() {return 0;}
max_type()252   virtual int max_type() {return 0;}
extend_cut_ghost()253   virtual double extend_cut_ghost() {return 0.0;}
n_history_extra()254   virtual int n_history_extra() {return 0;}
history_args(char ** args)255   virtual bool history_args(char** args) { UNUSED(args); return false; }
256 
257   // Mesh creation routines
getCreateMeshTriCount()258   virtual int getCreateMeshTriCount()
259   { return 0; }
260 
getCreateMeshTriNode(const int i)261   virtual double * getCreateMeshTriNode(const int i)
262   { return NULL; }
263 
can_create_mesh()264   bool can_create_mesh()
265   { return can_create_mesh_; }
266 
getFieldList()267   virtual class IRegionNeighborFieldList* getFieldList() const
268   { return NULL; }
269 
270  protected:
271   int evflag;
272   int vflag_global,vflag_atom;
273   int maxvatom;
274   bool can_create_mesh_;
275 
276   void v_setup(int);
277   void v_tally(int, int *, double, double *);
278 
279  private:
280   // add timing functionality to all fixes
281   double recorded_time;
282   double previous_time;
283 
284  public:
reset_time_recording()285   inline void reset_time_recording() {
286     recorded_time = 0.0;
287   }
288 
get_recorded_time()289   inline double get_recorded_time() const {
290     return recorded_time;
291   }
292 
begin_time_recording()293   inline void begin_time_recording() {
294     previous_time = MPI_Wtime();
295   }
296 
end_time_recording()297   inline void end_time_recording() {
298     double delta_time = MPI_Wtime() - previous_time;
299     recorded_time += delta_time;
300   }
301 
302   union ubuf {
303     double   d;
304     int64_t  i;
ubuf(double arg)305     ubuf(double arg) : d(arg) {}
ubuf(int64_t arg)306     ubuf(int64_t arg) : i(arg) {}
ubuf(int arg)307     ubuf(int arg) : i(arg) {}
308   };
309 
get_vector_atom_int(int index)310   int get_vector_atom_int(int index) {
311     return ubuf(vector_atom[index]).i;
312   }
313 
set_vector_atom_int(int index,int value)314   void set_vector_atom_int(int index, int value) {
315     vector_atom[index] = ubuf(value).d;
316   }
317 };
318 
319 typedef void (Fix::*FixMethod)();
320 typedef void (Fix::*FixMethodWithVFlag)(int);
321 typedef void (Fix::*FixMethodRESPA2)(int,int);
322 typedef void (Fix::*FixMethodRESPA3)(int,int,int);
323 
324 namespace FixConst {
325   // PRE_INITIAL_INTEGRATE added at end of list
326   static const int INITIAL_INTEGRATE =       1<<0;
327   static const int POST_INTEGRATE =          1<<1;
328   static const int PRE_EXCHANGE =            1<<2;
329   static const int PRE_NEIGHBOR =            1<<3;
330   static const int PRE_FORCE =               1<<4;
331   static const int POST_FORCE =              1<<5;
332   static const int PRE_FINAL_INTEGRATE =     1<<6;
333   static const int FINAL_INTEGRATE =         1<<7;
334   static const int END_OF_STEP =             1<<8;
335   static const int THERMO_ENERGY =           1<<9;
336   static const int INITIAL_INTEGRATE_RESPA = 1<<10;
337   static const int POST_INTEGRATE_RESPA =    1<<11;
338   static const int PRE_FORCE_RESPA =         1<<12;
339   static const int POST_FORCE_RESPA =        1<<13;
340   static const int FINAL_INTEGRATE_RESPA =   1<<14;
341   static const int MIN_PRE_EXCHANGE =        1<<15;
342   static const int MIN_PRE_NEIGHBOR =        1<<16;
343   static const int MIN_PRE_FORCE =           1<<17;
344   static const int MIN_POST_FORCE =          1<<18;
345   static const int MIN_ENERGY =              1<<19;
346   static const int POST_RUN =                1<<20;
347   static const int ITERATE_IMPLICITLY =      1<<21;
348   static const int FIX_CONST_LAST =          1<<22;
349   static const int PRE_INITIAL_INTEGRATE =   1<<23;
350 }
351 
352 }
353 
354 #endif
355 
356 /* ERROR/WARNING messages:
357 
358 E: Fix ID must be alphanumeric or underscore characters
359 
360 Self-explanatory.
361 
362 E: Could not find fix group ID
363 
364 A group ID used in the fix command does not exist.
365 
366 E: Illegal ... command
367 
368 Self-explanatory.  Check the input script syntax and compare to the
369 documentation for the command.  You can use -echo screen as a
370 command-line option when running LAMMPS to see the offending line.
371 
372 */
373