From 14321d1fa0590ce737ae50e8667eb1ab6670bd8d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 3 Jul 2020 22:19:44 -0400 Subject: [PATCH 1/3] add option to compute chunk/atom to access the number of chunks as a global scalar --- doc/src/compute_chunk_atom.rst | 10 ++++++---- src/compute_chunk_atom.cpp | 16 ++++++++++++++++ src/compute_chunk_atom.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/doc/src/compute_chunk_atom.rst b/doc/src/compute_chunk_atom.rst index 2ea12fb90c..a3d915b8a4 100644 --- a/doc/src/compute_chunk_atom.rst +++ b/doc/src/compute_chunk_atom.rst @@ -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 ` 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 ` 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 """""""""""" diff --git a/src/compute_chunk_atom.cpp b/src/compute_chunk_atom.cpp index f7e2db69b9..c8e4269b56 100644 --- a/src/compute_chunk_atom.cpp +++ b/src/compute_chunk_atom.cpp @@ -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 diff --git a/src/compute_chunk_atom.h b/src/compute_chunk_atom.h index 5f7e165f98..98a3ea9a2b 100644 --- a/src/compute_chunk_atom.h +++ b/src/compute_chunk_atom.h @@ -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(); From 022252dde06a7d501f2eaa960fe81be6e344424b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 6 Jul 2020 11:13:23 -0400 Subject: [PATCH 2/3] add a paragraph to the output howto explaining how ambiguity is resolved --- doc/src/Howto_output.rst | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/doc/src/Howto_output.rst b/doc/src/Howto_output.rst index 04e73c2272..01e71aab64 100644 --- a/doc/src/Howto_output.rst +++ b/doc/src/Howto_output.rst @@ -3,13 +3,15 @@ Output from LAMMPS (thermo, dumps, computes, fixes, variables) There are four basic kinds of LAMMPS output: -* :doc:`Thermodynamic output `, which is a list - of quantities printed every few timesteps to the screen and logfile. +* :doc:`Thermodynamic output `, which is a list of + quantities printed every few timesteps to the screen and logfile. * :doc:`Dump files `, which contain snapshots of atoms and various per-atom values and are written at a specified frequency. -* Certain fixes can output user-specified quantities to files: :doc:`fix ave/time ` for time averaging, :doc:`fix ave/chunk ` for spatial or other averaging, and :doc:`fix print ` for single-line output of - :doc:`variables `. Fix print can also output to the - screen. +* Certain fixes can output user-specified quantities to files: + :doc:`fix ave/time ` for time averaging, + :doc:`fix ave/chunk ` for spatial or other averaging, and + :doc:`fix print ` for single-line output of + :doc:`variables `. Fix print can also output to the screen. * :doc:`Restart files `. A simulation prints one set of thermodynamic output and (optionally) @@ -81,6 +83,25 @@ the dimension twice (array -> scalar). Thus a command that uses scalar values as input can typically also process elements of a vector or array. +.. _disambiguation: + +Disambiguation +-------------- + +Some computes and fixes produce multiple kinds of data, e.g. a global +scalar and a global vector, or a global scalar and a per-atom vector +(i.e. one value per atom). Usually the context in which those are used +determines which datum is accessed. Example: if a compute provides both +a global scalar and a per-atom vector, the former will be used when +using ``c_ID`` in an equal-style variable, while the latter will be +referenced as ``c_ID`` in an atom-style variable. While atom-style +variables are otherwise also able to access global scalars, access to +the global scalar of the compute is not directly possible in this case. +This is resolved through first defining an equal-style variable that +accesses the scalar property and then access that equal-style variable +in the atom-style variable, which then may then also access the per-atom +property. + .. _thermo: Thermodynamic output From 47d77530e27f04077c66f9e67eeb80638ec2627c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 6 Jul 2020 11:45:16 -0400 Subject: [PATCH 3/3] updated as requested by @sjplimp --- doc/src/Howto_output.rst | 46 +++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/doc/src/Howto_output.rst b/doc/src/Howto_output.rst index 01e71aab64..61afce17ae 100644 --- a/doc/src/Howto_output.rst +++ b/doc/src/Howto_output.rst @@ -43,7 +43,7 @@ to output and the kind of data they operate on and produce: .. _global: Global/per-atom/local data ---------------------------------------- +-------------------------- Various output-related commands work with three different styles of data: global, per-atom, or local. A global datum is one or more @@ -56,7 +56,7 @@ bond distances. .. _scalar: Scalar/vector/array data -------------------------------------- +------------------------ Global, per-atom, and local datums can each come in three kinds: a single scalar value, a vector of values, or a 2d array of values. The @@ -88,24 +88,22 @@ or array. Disambiguation -------------- -Some computes and fixes produce multiple kinds of data, e.g. a global -scalar and a global vector, or a global scalar and a per-atom vector -(i.e. one value per atom). Usually the context in which those are used -determines which datum is accessed. Example: if a compute provides both -a global scalar and a per-atom vector, the former will be used when -using ``c_ID`` in an equal-style variable, while the latter will be -referenced as ``c_ID`` in an atom-style variable. While atom-style -variables are otherwise also able to access global scalars, access to -the global scalar of the compute is not directly possible in this case. -This is resolved through first defining an equal-style variable that -accesses the scalar property and then access that equal-style variable -in the atom-style variable, which then may then also access the per-atom -property. +Some computes and fixes produce data in multiple styles, e.g. a global +scalar and a per-atom vector. Usually the context in which the input +script references the data determines which style is meant. Example: if +a compute provides both a global scalar and a per-atom vector, the +former will be accessed by using ``c_ID`` in an equal-style variable, +while the latter will be accessed by using ``c_ID`` in an atom-style +variable. Note that atom-style variable formulas can also access global +scalars, but in this case it is not possible to do directly because of +the ambiguity. Instead, an equal-style variable can be defined which +accesses the global scalar, and that variable used in the atom-style +variable formula in place of ``c_ID``. .. _thermo: Thermodynamic output ---------------------------------- +-------------------- The frequency and format of thermodynamic output is set by the :doc:`thermo `, :doc:`thermo_style `, and @@ -133,7 +131,7 @@ intensive result. .. _dump: Dump file output ---------------------------- +---------------- Dump file output is specified by the :doc:`dump ` and :doc:`dump_modify ` commands. There are several @@ -159,7 +157,7 @@ command. .. _fixoutput: Fixes that write output files ---------------------------------------------- +----------------------------- Several fixes take various quantities as input and can write output files: :doc:`fix ave/time `, :doc:`fix ave/chunk `, :doc:`fix ave/histo `, @@ -213,7 +211,7 @@ from normal thermodynamic or dump file output. .. _computeoutput: Computes that process output quantities ------------------------------------------------------------ +--------------------------------------- The :doc:`compute reduce ` and :doc:`compute reduce/region ` commands take one or more per-atom or local vector quantities as inputs and "reduce" them (sum, min, max, @@ -240,7 +238,7 @@ output commands. .. _fixprocoutput: Fixes that process output quantities --------------------------------------------------------- +------------------------------------ The :doc:`fix vector ` command can create global vectors as output from global scalars as input, accumulating them one element at @@ -265,7 +263,7 @@ The output of this fix can be used as input to other output commands. .. _compute: Computes that generate values to output ------------------------------------------------------ +--------------------------------------- Every :doc:`compute ` in LAMMPS produces either global or per-atom or local values. The values can be scalars or vectors or @@ -278,7 +276,7 @@ without the word "atom" or "local" produce global values. .. _fix: Fixes that generate values to output ----------------------------------------------- +------------------------------------ Some :doc:`fixes ` in LAMMPS produces either global or per-atom or local values which can be accessed by other commands. The values can @@ -290,7 +288,7 @@ describes them. .. _variable: Variables that generate values to output -------------------------------------------------------- +---------------------------------------- :doc:`Variables ` defined in an input script can store one or more strings. But equal-style, vector-style, and atom-style or @@ -305,7 +303,7 @@ commands described in this section. .. _table: Summary table of output options and data flow between commands --------------------------------------------------------------------------- +-------------------------------------------------------------- This table summarizes the various commands that can be used for generating output from LAMMPS. Each command produces output data of