From 6a5ed2af4ba250140bb2449f11e15872b22fbd6b Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Mon, 26 May 2025 16:22:52 -0600 Subject: [PATCH] add renieigbor option to fix set --- doc/src/Commands_fix.rst | 1 + doc/src/fix_set.rst | 36 ++++++++++++++++++++++++++++-------- doc/src/run.rst | 18 ++++++++++-------- src/fix_set.cpp | 23 +++++++++++++---------- src/fix_set.h | 2 ++ 5 files changed, 54 insertions(+), 26 deletions(-) diff --git a/doc/src/Commands_fix.rst b/doc/src/Commands_fix.rst index 35c3804969..0638cbe62e 100644 --- a/doc/src/Commands_fix.rst +++ b/doc/src/Commands_fix.rst @@ -216,6 +216,7 @@ OPT. * :doc:`rigid/small (o) ` * :doc:`rx (k) ` * :doc:`saed/vtk ` + * :doc:`set ` * :doc:`setforce (k) ` * :doc:`setforce/spin ` * :doc:`sgcmc ` diff --git a/doc/src/fix_set.rst b/doc/src/fix_set.rst index 44bc2f21d6..07c26b2923 100644 --- a/doc/src/fix_set.rst +++ b/doc/src/fix_set.rst @@ -8,11 +8,12 @@ Syntax .. code-block:: LAMMPS - fix ID group-ID set Nfreq set-args + fix ID group-ID set Nfreq rnflag set-args * ID, group-ID are documented in :doc:`fix ` command * set = style name of this fix command * Nfreq = reset per-atom properties every this many timesteps +* rnflag = 1 to reneighbor on next timestep, 0 to not * set-args = identical to args for the :doc:`set ` command Examples @@ -20,8 +21,8 @@ Examples .. code-block:: LAMMPS - fix 10 all set 1 group all i_dump v_new - fix 10 all set 1 group all i_dump v_turnoff + fix 10 all set 1 0 group all i_dump v_new + fix 10 all set 1 0 group all i_dump v_turnoff Description """"""""""" @@ -29,11 +30,30 @@ Description Reset one or more properties of one or more atoms once every *Nfreq* steps during a simulation. -The args following *Nfreq* are identical to those allowed for the -:doc:`set ` command, as in the examples above and below. +If the *rnflag* for reneighboring is set to 1, then a reneighboring +will be triggered on the next timestep (since the fix set operation +occurs at the end of the current timestep). This is important to do +if this command changes per-atom properties that need to be +communicated to ghost atoms. If this is not the case, an *rnflag* +setting of 0 can be used; reneighboring will only be triggered on +subsequent timesteps by the usual neighbor list criteria; see the +:doc:`neigh_modify ` command. + +Here are two examples where an *rnflag* setting of 1 are needed. If a +custom per-atom property is changed and the :doc:`fix property/atom +` command to create the property used the *ghost +yes* keyword. Or if per-atom charges are changed, all pair styles +which compute Coulombic interactions require charge values for ghost +atoms. In both these examples, the re-neighboring will trigger the +changes in the owned atom properties to be immediately communicated to +ghost atoms. + +The arguments following *Nfreq* and *rnflag* are identical to those +allowed for the :doc:`set ` command, as in the examples above and +below. Note that the group-ID setting for this command is ignored. The -syntax for the :doc:`set ` command allows selection of which +syntax for the :doc:`set ` arguments allows selection of which atoms have their properties reset. This command can only be used to reset an atom property using a @@ -68,7 +88,7 @@ be output every step for *twindow* timesteps. # variable start atom "vx > v_vthresh && i_dump == -1" variable new atom ternary(v_start,step,i_dump) - fix 3 all set 1 group all i_dump v_new + fix 3 all set 1 0 group all i_dump v_new # # dump command with thresh which enforces twindow # @@ -112,7 +132,7 @@ longer useful. variable turnon atom ternary(v_start,step,i_dump) variable stop atom "v_turnon >= 0 && (step-v_turnon) < v_twindow" variable turnoff atom ternary(v_stop,v_turnon,-1) - fix 3 all set 1 group all i_dump v_turnoff + fix 3 all set 1 0 group all i_dump v_turnoff # # dump command with thresh which enforces twindow # diff --git a/doc/src/run.rst b/doc/src/run.rst index c3dd171f6b..95e2f037db 100644 --- a/doc/src/run.rst +++ b/doc/src/run.rst @@ -103,14 +103,16 @@ must be done. .. note:: - If your input script changes the system between 2 runs, then the - initial setup must be performed to ensure the change is recognized by - all parts of the code that are affected. Examples are adding a - :doc:`fix ` or :doc:`dump ` or :doc:`compute `, changing - a :doc:`neighbor ` list parameter, or writing restart file - which can migrate atoms between processors. LAMMPS has no easy way to - check if this has happened, but it is an error to use the *pre no* - option in this case. + If your input script "changes" the system between 2 runs, then the + initial setup typically needs to be performed to ensure the change + is recognized by all parts of the code that are affected. Examples + are adding a :doc:`fix ` or :doc:`dump ` or + :doc:`compute `, changing a :doc:`neighbor ` + list parameter, using the :doc:`set ` command, or writing a + restart file via the :doc:`write_restart ` command, + which can migrate atoms between processors. LAMMPS has no easy way + to check if this has happened, but it is an error to use the *pre + no* option in these cases. If *post* is specified as "no", the full timing summary is skipped; only a one-line summary timing is printed. diff --git a/src/fix_set.cpp b/src/fix_set.cpp index 7c7245a9eb..cab303660b 100644 --- a/src/fix_set.cpp +++ b/src/fix_set.cpp @@ -16,6 +16,7 @@ #include "atom.h" #include "error.h" #include "set.h" +#include "update.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -26,27 +27,25 @@ enum{SETCOMMAND,FIXSET}; // also used in Set class FixSet::FixSet(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) { - if (narg < 7) error->all(FLERR, 1, "Illegal fix set command: need at least four arguments"); + if (narg < 8) error->all(FLERR, 1, "Illegal fix set command: need at least eight arguments"); nevery = utils::inumeric(FLERR, arg[3], false, lmp); if (nevery <= 0) error->all(FLERR, "Fix {} Nevery must be > 0", style); + reneighbor = utils::inumeric(FLERR, arg[4], false, lmp); + if (reneighbor = 0 || reneighbor > 1) + error->all(FLERR, "Fix {} rnflag must be 0/1", style); + // create instance of Set class set = new Set(lmp); // pass remaining args to Set class // only keywords which use per-atom variables are currently allowed - // NOTE: could also allow when set style = region, since atoms may move in/out of regions + // NOTE: could also allow when set style = region, + // since atoms may move in/out of regions - set->process_args(FIXSET,narg-4,&arg[4]); - - // NOTE: not sure if either of these options for fix set are needed or could be problematic - // could add ghost yes keyword/value to trigger - // ghost comm, e.g. if atom types are reset - // this could require an extract() method in Set to query what value(s) to comm - // could add reneigh yes keyword/value to trigger - // full reneighbor on next step, e.g. if xyz coords are reset + set->process_args(FIXSET,narg-5,&arg[5]); } /* ---------------------------------------------------------------------- */ @@ -79,5 +78,9 @@ void FixSet::end_of_step() // loop over list of actions to reset atom attributes set->invoke_actions(); + + // trigger reneighboring on next timestep if requested + + if (reneighbor) next_reneighbor = update->ntimestep + 1; } diff --git a/src/fix_set.h b/src/fix_set.h index f5d0aeb3f5..7328ebd144 100644 --- a/src/fix_set.h +++ b/src/fix_set.h @@ -32,6 +32,8 @@ class FixSet : public Fix { void end_of_step() override; private: + int reneighbor; + class Set *set; };