Unverified Commit 14321d1f authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

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

parent 558d2eb8
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -622,14 +622,16 @@ cylinder, x for a y-axis cylinder, and x for a z-axis cylinder.

**Output info:**

This compute calculates a per-atom vector, which can be accessed by
any command that uses per-atom values from a compute as input.  See
the :doc:`Howto output <Howto_output>` doc page for an overview of
This compute calculates a per-atom vector (the chunk ID), which can
be accessed by any command that uses per-atom values from a compute
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.

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
belonging to a chunk.
belonging to a chunk.  The scalar contains the value of *Nchunk*.

Restrictions
""""""""""""
+16 −0
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) :
  if (narg < 4) error->all(FLERR,"Illegal compute chunk/atom command");

  peratom_flag = 1;
  scalar_flag = 1;
  extscalar = 0;
  size_peratom_cols = 0;
  create_attribute = 1;

@@ -639,6 +641,20 @@ void ComputeChunkAtom::compute_peratom()
  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
   called by fix for duration of time it requires lock
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ class ComputeChunkAtom : public Compute {
  void init();
  void setup();
  void compute_peratom();
  double compute_scalar();
  void set_arrays(int);
  double memory_usage();