1 // clang-format off
2 /* ----------------------------------------------------------------------
3    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
4    https://www.lammps.org/, Sandia National Laboratories
5    Steve Plimpton, sjplimp@sandia.gov
6 
7    Copyright (2003) Sandia Corporation.  Under the terms of Contract
8    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
9    certain rights in this software.  This software is distributed under
10    the GNU General Public License.
11 
12    See the README file in the top-level LAMMPS directory.
13 ------------------------------------------------------------------------- */
14 
15 /* ----------------------------------------------------------------------
16    Contributing author: Mike Brown (SNL)
17 ------------------------------------------------------------------------- */
18 
19 #include "fix_event_tad.h"
20 #include "comm.h"
21 #include "error.h"
22 #include "update.h"
23 
24 using namespace LAMMPS_NS;
25 using namespace FixConst;
26 
27 /* ---------------------------------------------------------------------- */
28 
FixEventTAD(LAMMPS * lmp,int narg,char ** arg)29 FixEventTAD::FixEventTAD(LAMMPS *lmp, int narg, char **arg) :
30   FixEvent(lmp, narg, arg)
31 {
32   if (narg != 3) error->all(FLERR,"Illegal fix event command");
33 
34   restart_global = 1;
35 
36   event_number = 0;
37   event_timestep = update->ntimestep;
38   tlo = 0.0;
39   ebarrier = 0.0;
40 }
41 
42 /* ----------------------------------------------------------------------
43    save current atom coords as an event (via call to base class)
44    called when an event occurs in some replica
45    set event_timestep = when event occurred
46 ------------------------------------------------------------------------- */
47 
store_event_tad(bigint ntimestep)48 void FixEventTAD::store_event_tad(bigint ntimestep)
49 {
50   store_event();
51   event_timestep = ntimestep;
52 }
53 
54 /* ----------------------------------------------------------------------
55    pack entire state of Fix into one write
56 ------------------------------------------------------------------------- */
57 
write_restart(FILE * fp)58 void FixEventTAD::write_restart(FILE *fp)
59 {
60   int n = 0;
61   double list[4];
62   list[n++] = event_number;
63   list[n++] = event_timestep;
64   list[n++] = tlo;
65   list[n++] = ebarrier;
66 
67   if (comm->me == 0) {
68     int size = n * sizeof(double);
69     fwrite(&size,sizeof(int),1,fp);
70     fwrite(list,sizeof(double),n,fp);
71   }
72 }
73 
74 /* ----------------------------------------------------------------------
75    use state info from restart file to restart the Fix
76 ------------------------------------------------------------------------- */
77 
restart(char * buf)78 void FixEventTAD::restart(char *buf)
79 {
80   int n = 0;
81   double *list = (double *) buf;
82 
83   event_number = static_cast<int> (list[n++]);
84   event_timestep = static_cast<int> (list[n++]);
85   tlo = list[n++];
86   ebarrier = list[n++];
87 }
88