add option to compute chunk/atom to access the number of chunks as a global scalar

This commit is contained in:
Axel Kohlmeyer
2020-07-03 22:19:44 -04:00
parent 558d2eb84f
commit 14321d1fa0
3 changed files with 23 additions and 4 deletions

View File

@ -622,14 +622,16 @@ cylinder, x for a y-axis cylinder, and x for a z-axis cylinder.
**Output info:** **Output info:**
This compute calculates a per-atom vector, which can be accessed by This compute calculates a per-atom vector (the chunk ID), which can
any command that uses per-atom values from a compute as input. See be accessed by any command that uses per-atom values from a compute
the :doc:`Howto output <Howto_output>` doc page for an overview of as input. It also calculates a global scalar (the number of chunks),
which can be similarly accessed everywhere outside of a per-atom context.
See the :doc:`Howto output <Howto_output>` doc page for an overview of
LAMMPS output options. LAMMPS output options.
The per-atom vector values are unitless chunk IDs, ranging from 1 to The per-atom vector values are unitless chunk IDs, ranging from 1 to
*Nchunk* (inclusive) for atoms assigned to chunks, and 0 for atoms not *Nchunk* (inclusive) for atoms assigned to chunks, and 0 for atoms not
belonging to a chunk. belonging to a chunk. The scalar contains the value of *Nchunk*.
Restrictions Restrictions
"""""""""""" """"""""""""

View File

@ -64,6 +64,8 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
if (narg < 4) error->all(FLERR,"Illegal compute chunk/atom command"); if (narg < 4) error->all(FLERR,"Illegal compute chunk/atom command");
peratom_flag = 1; peratom_flag = 1;
scalar_flag = 1;
extscalar = 0;
size_peratom_cols = 0; size_peratom_cols = 0;
create_attribute = 1; create_attribute = 1;
@ -639,6 +641,20 @@ void ComputeChunkAtom::compute_peratom()
for (int i = 0; i < nlocal; i++) chunk[i] = ichunk[i]; for (int i = 0; i < nlocal; i++) chunk[i] = ichunk[i];
} }
/* ----------------------------------------------------------------------
to return the number of chunks, we first need to make certain
that compute_peratom() has been called.
------------------------------------------------------------------------- */
double ComputeChunkAtom::compute_scalar()
{
if (invoked_peratom != update->ntimestep)
compute_peratom();
invoked_scalar = update->ntimestep;
return (scalar = nchunk);
}
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
set lock, so that nchunk will not change from startstep to stopstep set lock, so that nchunk will not change from startstep to stopstep
called by fix for duration of time it requires lock called by fix for duration of time it requires lock

View File

@ -39,6 +39,7 @@ class ComputeChunkAtom : public Compute {
void init(); void init();
void setup(); void setup();
void compute_peratom(); void compute_peratom();
double compute_scalar();
void set_arrays(int); void set_arrays(int);
double memory_usage(); double memory_usage();