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 #ifdef FIX_CLASS
15 // clang-format off
16 FixStyle(hyper/local,FixHyperLocal);
17 // clang-format on
18 #else
19 
20 #ifndef LMP_FIX_HYPER_LOCAL_H
21 #define LMP_FIX_HYPER_LOCAL_H
22 
23 #include "fix_hyper.h"
24 
25 namespace LAMMPS_NS {
26 // forward declaration. struct HyperOneCoeff is defined in my_page.h
27 struct HyperOneCoeff;
28 
29 class FixHyperLocal : public FixHyper {
30  public:
31   FixHyperLocal(class LAMMPS *, int, char **);
32   ~FixHyperLocal();
33   int setmask();
34   void init();
35   void init_list(int, class NeighList *);
36   void setup_pre_neighbor();
37   void setup_pre_reverse(int, int);
38   void pre_neighbor();
39   void pre_reverse(int, int);
40   void min_pre_neighbor();
41   double compute_scalar();
42   double compute_vector(int);
43   double query(int);
44 
45   int pack_forward_comm(int, int *, double *, int, int *);
46   void unpack_forward_comm(int, int, double *);
47   int pack_reverse_comm(int, int, double *);
48   int pack_reverse_comm_size(int, int);
49   void unpack_reverse_comm(int, int *, double *);
50 
51   double memory_usage();
52 
53   // extra methods visible to callers
54 
55   void init_hyper();
56   void build_bond_list(int);
57 
58  private:
59   int me;
60 
61   // inputs and derived quantities
62 
63   double cutbond, qfactor, vmax, tequil, dcut;
64   double alpha_user;            // timescale to apply boostostat (time units)
65   double alpha;                 // unitless dt/alpha_user
66   double boost_target;          // target value of boost
67   int checkghost, checkbias;    // flags for optional stats
68   int checkbias_every;
69   int checkbias_flag;
70   int boundflag, resetfreq;    // bias coeff bounding and reset settings
71   double boundfrac;
72 
73   bigint groupatoms;    // # of atoms in fix group
74   double cutbondsq, dcutsq;
75   double beta, invvmax, invqfactorsq;
76 
77   // two DEBUG quantities
78   // double myboost;
79   // int overcount;
80 
81   // flags
82 
83   int setupflag;       // 1 during setup, 0 during run
84   int firstflag;       // set for first time bond_build takes place
85   int nostrainyet;     // 1 until maxstrain is first compute
86   bigint starttime;    // timestep when this fix was invoked
87   int commflag;        // flag for communication mode
88 
89   // bias coeff bounds and reset
90 
91   double bound_lower, bound_upper;
92   bigint lastreset;
93 
94   // stats
95 
96   int nbondbuild;           // # of rebuilds of bond list
97   double time_bondbuild;    // CPU time for bond builds
98 
99   bigint allbonds;       // current total # of bonds
100   int maxbondperatom;    // max # of bonds any atom ever has
101   int nevent;            // # of events that trigger bond rebuild
102   int nevent_atom;       // # of atoms that experienced an event
103 
104   bigint nnewbond;             // running tally of # of new bonds created
105   bigint nbias_running;        // running count of biased bonds
106   bigint nobias_running;       // ditto for bonds with bias = 0, b/c too long
107   bigint negstrain_running;    // ditto for bonds with negative strain
108 
109   double mybias;        // sum of bias potentials for biased bonds
110   double maxbondlen;    // cummulative max length of any bond
111   double maxdriftsq;    // max distance any bond atom drifts from quenched x
112 
113   double sumboost;                       // sum of all bond boosts at each timestep
114   double aveboost_running;               // cummulative sumboost/allbonds across steps
115   double aveboost_running_output;        // most recent output of ab_running
116   double sumbiascoeff;                   // sum of all bond bias coeffs at each timestep
117   double avebiascoeff_running;           // cummulative sumbiascoeff/allbonds across steps
118   double avebiascoeff_running_output;    // most recent output of abc_running
119   double minbiascoeff;                   // min bias coeff on this step for my bonds
120   double maxbiascoeff;                   // max bias coeff on this step for my bonds
121   double minbiascoeff_running;           // cummulative min bias coeff for any bond
122   double maxbiascoeff_running;           // cummulative max bias coeff for any bond
123 
124   double rmaxever, rmaxeverbig;
125   int ghost_toofar;       // # of ghost atoms not found in Dcut neigh list
126   int checkbias_count;    // count of too-close biased bonds
127 
128   // 2 neighbor lists
129 
130   class NeighList *listfull;    // full neigh list up to Dcut distance
131   class NeighList *listhalf;    // half neigh list up to pair distance
132                                 // both created only when bonds are rebuilt
133 
134   // list of my owned bonds and bias coeffs
135   // persists on a proc from one event until the next
136 
137   struct OneBond {     // single IJ bond, atom I is owner
138     int i, j;          // current local indices of 2 bond atoms
139     int iold, jold;    // local indices when bonds were formed
140     double r0;         // relaxed bond length
141   };
142 
143   OneBond *blist;       // list of owned bonds
144   double *biascoeff;    // bias coefficient Cij for each bond
145   int nblocal;          // # of owned bonds
146   int maxbond;          // allocated size of blist
147 
148   // old data from last timestep bonds were formed
149   // persists on a proc from one event until the next
150   // first set of vectors are maxlocal in length
151   // second set of vectors are maxall in length
152 
153   int nlocal_old;    // nlocal for old atoms
154   int nall_old;      // nlocal+nghost for old atoms
155   int maxlocal;      // allocated size of old local atom vecs
156   int maxall;        // allocated size of old all atom vecs
157 
158   int *numbond;             // # of bonds owned by old owned atoms
159   int *maxhalf;             // bond index for maxstrain bond of old atoms
160   int *eligible;            // 0/1 flag for bias on one of old atom's bonds
161   double *maxhalfstrain;    // strain value for maxstrain bond of old atoms
162 
163   int *old2now;      // o2n[i] = current local index of old atom I
164                      // may be -1 if ghost atom has drifted
165   tagint *tagold;    // IDs of atoms when bonds were formed
166                      // 0 if a ghost atom is not in Dcut neigh list
167   double **xold;     // coords of atoms when bonds were formed
168 
169   // vectors used to find maxstrain bonds within a local domain
170 
171   int maxatom;    // size of these vectors, nlocal + nghost
172 
173   double *maxstrain;           // max-strain of any bond atom I is part of
174                                //   for owned and ghost atoms
175   double *maxstrain_domain;    // max-strain of any neighbor atom J of atom I
176                                //   for owned and ghost atoms
177   tagint *biasflag;            // atoms in biased bonds marked with bond partner
178                                //   for owned and ghost atoms
179 
180   // list of biased bonds this proc owns
181 
182   int maxbias;    // allocated size of bias list
183   int nbias;      // # of biased bonds I own
184   int *bias;      // index of biased bonds in my bond list
185 
186   // data structs for persisting bias coeffs when bond list is reformed
187 
188   MyPage<HyperOneCoeff> *cpage;    // pages of OneCoeff datums for clist
189   HyperOneCoeff **clist;           // ptrs to vectors of bias coeffs for each atom
190   int *numcoeff;                   // # of bias coeffs per atom (one per bond)
191   int maxcoeff;                    // allocate sized of clist and numcoeff
192 
193   // extra timers
194 
195   //double timefirst,timesecond,timethird,timefourth;
196   //double timefifth,timesixth,timeseventh,timetotal;
197 
198   // private methods
199 
200   void grow_bond();
201 };
202 
203 }    // namespace LAMMPS_NS
204 
205 #endif
206 #endif
207 
208 /* ERROR/WARNING messages:
209 
210 E: Illegal ... command
211 
212 Self-explanatory.  Check the input script syntax and compare to the
213 documentation for the command.  You can use -echo screen as a
214 command-line option when running LAMMPS to see the offending line.
215 
216 */
217