/* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. Created from fix_ave_atom.cpp by Bartosz Liedke b.liedke@hzdr.de ------------------------------------------------------------------------- */ #include "stdlib.h" #include "string.h" #include "fix_resetflag_atom.h" #include "atom.h" #include "domain.h" #include "update.h" #include "modify.h" #include "compute.h" #include "input.h" #include "variable.h" #include "memory.h" #include "error.h" #include "force.h" using namespace LAMMPS_NS; using namespace FixConst; /* ---------------------------------------------------------------------- */ FixResetFlagAtom::FixResetFlagAtom(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) { if (narg < 3) error->all(FLERR,"Illegal fix resetflag/atom command"); peratom_freq = force->inumeric(FLERR,arg[3]); nrepeat = 1; nevery = peratom_freq; // nvalid = next step on which end_of_step does something irepeat = 0; nvalid = nextvalid(); } /* ---------------------------------------------------------------------- */ FixResetFlagAtom::~FixResetFlagAtom() { // unregister callback to this fix from Atom class atom->delete_callback(id,0); } /* ---------------------------------------------------------------------- */ int FixResetFlagAtom::setmask() { int mask = 0; mask |= END_OF_STEP; return mask; } /* ---------------------------------------------------------------------- */ void FixResetFlagAtom::init() { // need to reset nvalid if nvalid < ntimestep b/c minimize was performed if (nvalid < update->ntimestep) { irepeat = 0; nvalid = nextvalid(); } } /* ---------------------------------------------------------------------- only does something if nvalid = current timestep ------------------------------------------------------------------------- */ void FixResetFlagAtom::setup(int vflag) { end_of_step(); } /* ---------------------------------------------------------------------- */ void FixResetFlagAtom::end_of_step() { int i; // skip if not step which requires doing something bigint ntimestep = update->ntimestep; if (ntimestep != nvalid) return; int nlocal = atom->nlocal; int *mask = atom->mask; // here it goes through each atom and resets the image flag for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) atom->image[i] = ( (tagint) IMGMAX & IMGMASK) | (( (tagint) IMGMAX & IMGMASK) << IMGBITS) | (( (tagint) IMGMAX & IMGMASK) << IMG2BITS); irepeat = 0; nvalid = ntimestep+peratom_freq; } /* ---------------------------------------------------------------------- calculate nvalid = next step on which end_of_step does something ------------------------------------------------------------------------- */ bigint FixResetFlagAtom::nextvalid() { bigint nvalid = (update->ntimestep/peratom_freq)*peratom_freq + peratom_freq; if (nvalid-peratom_freq == update->ntimestep ) nvalid = update->ntimestep; if (nvalid < update->ntimestep) nvalid += peratom_freq; return nvalid; } /* ---------------------------------------------------------------------- */ void FixResetFlagAtom::reset_timestep(bigint ntimestep) { if (ntimestep > nvalid) error->all(FLERR,"Fix resetflag/atom missed timestep"); }