From dd23db9369f9b705d23d51a3172a960053e051dc Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Mon, 16 Nov 2020 08:13:33 -0700 Subject: [PATCH] standardize flags for energy/virial computations in forces --- src/angle.cpp | 11 ++++++++++- src/bond.cpp | 10 +++++++++- src/compute_centroid_stress_atom.cpp | 4 ++-- src/dihedral.cpp | 11 ++++++++++- src/improper.cpp | 11 ++++++++++- src/integrate.cpp | 27 ++++++++++++--------------- src/kspace.cpp | 10 +++++++++- src/min.cpp | 9 +++++---- src/pair.cpp | 24 +++++++++++++++++++++--- src/pair.h | 8 ++++---- src/respa.cpp | 5 +++-- src/verlet.cpp | 9 +++++---- 12 files changed, 100 insertions(+), 39 deletions(-) diff --git a/src/angle.cpp b/src/angle.cpp index 97b2c4c3e1..1994a07c78 100644 --- a/src/angle.cpp +++ b/src/angle.cpp @@ -75,7 +75,16 @@ void Angle::init() /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set + vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ void Angle::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/bond.cpp b/src/bond.cpp index 1912d15aa7..ed8cc3dbd6 100644 --- a/src/bond.cpp +++ b/src/bond.cpp @@ -80,7 +80,15 @@ void Bond::init() /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM or VIRIAL_CENTROID bit of vflag set + vflag_either = 1 if vflag_global or vflag_atom is set ------------------------------------------------------------------------- */ void Bond::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index d17d402a3d..d4d602ee64 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -126,7 +126,7 @@ void ComputeCentroidStressAtom::init() // check if pair styles support centroid atom stress if (pairflag && force->pair) - if (force->pair->centroidstressflag & 4) + if (force->pair->centroidstressflag == CENTROID_NOTAVAIL) error->all(FLERR, "Pair style does not support compute centroid/stress/atom"); } @@ -178,7 +178,7 @@ void ComputeCentroidStressAtom::compute_peratom() // per-atom virial and per-atom centroid virial are the same for two-body // many-body pair styles not yet implemented if (pairflag && force->pair && force->pair->compute_flag) { - if (force->pair->centroidstressflag & 2) { + if (force->pair->centroidstressflag == CENTROID_AVAIL) { double **cvatom = force->pair->cvatom; for (i = 0; i < npair; i++) for (j = 0; j < 9; j++) diff --git a/src/dihedral.cpp b/src/dihedral.cpp index f778341bfa..f2d1a548c2 100644 --- a/src/dihedral.cpp +++ b/src/dihedral.cpp @@ -74,7 +74,16 @@ void Dihedral::init() /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set + vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ void Dihedral::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/improper.cpp b/src/improper.cpp index faf9e2fa52..4e481462cf 100644 --- a/src/improper.cpp +++ b/src/improper.cpp @@ -72,7 +72,16 @@ void Improper::init() /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set + vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set ------------------------------------------------------------------------- */ void Improper::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/integrate.cpp b/src/integrate.cpp index d4060e1a1d..e88182e9cf 100644 --- a/src/integrate.cpp +++ b/src/integrate.cpp @@ -111,21 +111,18 @@ void Integrate::ev_setup() /* ---------------------------------------------------------------------- set eflag,vflag for current iteration + based on computes that need energy/virial info on this timestep invoke matchstep() on all timestep-dependent computes to clear their arrays - eflag/vflag based on computes that need info on this ntimestep - eflag = 0 = no energy computation - eflag = 1 = global energy only - eflag = 2 = per-atom energy only - eflag = 3 = both global and per-atom energy - vflag = 0 = no virial computation (pressure) - vflag = 1 = global virial with pair portion via sum of pairwise interactions - vflag = 2 = global virial with pair portion via F dot r including ghosts - vflag = 4 = per-atom virial only - vflag = 5 or 6 = both global and per-atom virial - vflag = 8 = per-atom centroid virial only - vflag = 9 or 10 = both global and per-atom centroid virial - vflag = 12 = both per-atom virial and per-atom centroid virial - vflag = 13 or 14 = global, per-atom virial and per-atom centroid virial + eflag: set any or no bits + ENERGY_GLOBAL bit for global energy + ENERGY_ATOM bit for per-atom energy + vflag: set any or no bits, but GLOBAL/FDOTR bit cannot both be set + VIRIAL_PAIR bit for global virial as sum of pairwise terms + VIRIAL_FDOTR bit for global virial via F dot r + VIRIAL_ATOM bit for per-atom virial + VIRIAL_CENTROID bit for per-atom centroid virial + all force components (pair,bond,angle,...,kspace) use eflag/vflag + in their ev_setup() method to set local energy/virial flags ------------------------------------------------------------------------- */ void Integrate::ev_set(bigint ntimestep) @@ -136,7 +133,7 @@ void Integrate::ev_set(bigint ntimestep) int eflag_global = 0; for (i = 0; i < nelist_global; i++) if (elist_global[i]->matchstep(ntimestep)) flag = 1; - if (flag) eflag_global = 1; + if (flag) eflag_global = ENERGY_GLOBAL; flag = 0; int eflag_atom = 0; diff --git a/src/kspace.cpp b/src/kspace.cpp index 16668c137a..79fe10d849 100644 --- a/src/kspace.cpp +++ b/src/kspace.cpp @@ -214,7 +214,15 @@ void KSpace::pair_check() /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR or VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + vflag_either = 1 if vflag_global or vflag_atom is set ------------------------------------------------------------------------- */ void KSpace::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/min.cpp b/src/min.cpp index ac711d8900..1db5c8b239 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -144,11 +144,12 @@ void Min::init() requestor = nullptr; // virial_style: - // 1 if computed explicitly by pair->compute via sum over pair interactions - // 2 if computed implicitly by pair->virial_compute via sum over ghost atoms + // VIRIAL_PAIR if computed explicitly in pair via sum over pair interactions + // VIRIAL_FDOTR if computed implicitly in pair by + // virial_fdotr_compute() via sum over ghosts - if (force->newton_pair) virial_style = 2; - else virial_style = 1; + if (force->newton_pair) virial_style = VIRIAL_FDOTR; + else virial_style = VIRIAL_PAIR; // setup lists of computes for global and per-atom PE and pressure diff --git a/src/pair.cpp b/src/pair.cpp index eff9690c70..396f50b09a 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -74,9 +74,10 @@ Pair::Pair(LAMMPS *lmp) : Pointers(lmp) setflag = nullptr; cutsq = nullptr; - ewaldflag = pppmflag = msmflag = dispersionflag = tip4pflag = dipoleflag = spinflag = 0; + ewaldflag = pppmflag = msmflag = dispersionflag = + tip4pflag = dipoleflag = spinflag = 0; reinitflag = 1; - centroidstressflag = 4; + centroidstressflag = CENTROID_SAME; // pair_modify settings @@ -776,7 +777,24 @@ void Pair::del_tally_callback(Compute *ptr) /* ---------------------------------------------------------------------- setup for energy, virial computation - see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) + see integrate::ev_set() for bitwise settings of eflag/vflag + set the following flags, values are otherwise 0: + evflag = 1 if any bits of eflag or vflag are set + eflag_global = 1 if ENERGY_GLOBAL bit of eflag set + eflag_atom = 1 if ENERGY_ATOM bit of eflag set + eflag_either = 1 if eflag_global or eflag_atom is set + vflag_global = 1 if VIRIAL_PAIR bit of vflag set + vflag_global = 2 if VIRIAL_FDOTR bit of vflag set + vflag_atom = 1 if VIRIAL_PERATOM bit of vflag set + vflag_atom = 1 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag != CENTROID_AVAIL + cvflag_atom = 1 if VIRIAL_CENTROID bit of vflag set + and centroidstressflag = CENTROID_AVAIL + vflag_either = 1 if any of vflag_global, vflag_atom, cvflag_atom is set + centroidstressflag is set by the pair style to one of these values: + CENTROID_SAME = same as two-body stress + CENTROID_AVAIL = different and implemented + CENTROID_NOTAVAIL = different but not yet implemented ------------------------------------------------------------------------- */ void Pair::ev_setup(int eflag, int vflag, int alloc) diff --git a/src/pair.h b/src/pair.h index ace233539f..5f931cea54 100644 --- a/src/pair.h +++ b/src/pair.h @@ -68,10 +68,10 @@ class Pair : protected Pointers { int spinflag; // 1 if compatible with spin solver int reinitflag; // 1 if compatible with fix adapt and alike - int centroidstressflag; // compatibility with centroid atomic stress - // 1 if same as two-body atomic stress - // 2 if implemented and different from two-body - // 4 if not compatible/implemented + int centroidstressflag; // centroid atomic compared to two-body stress + // CENTROID_SAME = same as two-body stress + // CENTROID_AVAIL = different and implemented + // CENTROID_NOTAVAIL = different, not yet implemented int tail_flag; // pair_modify flag for LJ tail correction double etail,ptail; // energy/pressure tail corrections diff --git a/src/respa.cpp b/src/respa.cpp index dcabcb11ef..aebee0f6eb 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -311,9 +311,10 @@ void Respa::init() if (force->pair && force->pair->respa_enable == 0) error->all(FLERR,"Pair style does not support rRESPA inner/middle/outer"); - // virial_style = 1 (explicit) since never computed implicitly like Verlet + // virial_style = VIRIAL_PAIR (explicit) + // since never computed implicitly with virial_fdotr_compute() like Verlet - virial_style = 1; + virial_style = VIRIAL_PAIR; // setup lists of computes for global and per-atom PE and pressure diff --git a/src/verlet.cpp b/src/verlet.cpp index 3d20a771f4..5e53daafbb 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -54,11 +54,12 @@ void Verlet::init() error->warning(FLERR,"No fixes defined, atoms won't move"); // virial_style: - // 1 if computed explicitly by pair->compute via sum over pair interactions - // 2 if computed implicitly by pair->virial_fdotr_compute via sum over ghosts + // VIRIAL_PAIR if computed explicitly in pair via sum over pair interactions + // VIRIAL_FDOTR if computed implicitly in pair by + // virial_fdotr_compute() via sum over ghosts - if (force->newton_pair) virial_style = 2; - else virial_style = 1; + if (force->newton_pair) virial_style = VIRIAL_FDOTR; + else virial_style = VIRIAL_PAIR; // setup lists of computes for global and per-atom PE and pressure