add 'append' keyword for appending to output file

This commit is contained in:
Axel Kohlmeyer
2024-03-17 15:34:32 -04:00
parent d97c7fffac
commit 505f7b3cb4
3 changed files with 24 additions and 14 deletions

View File

@ -31,7 +31,7 @@ Syntax
v_name = per-atom vector calculated by an atom-style variable with name v_name = per-atom vector calculated by an atom-style variable with name
* zero or more keyword/arg pairs may be appended * zero or more keyword/arg pairs may be appended
* keyword = *norm* or *ave* or *bias* or *adof* or *cdof* or *file* or *overwrite* or *format* or *title1* or *title2* or *title3* * keyword = *norm* or *ave* or *bias* or *adof* or *cdof* or *file* or *append* or *overwrite* or *format* or *title1* or *title2* or *title3*
.. parsed-literal:: .. parsed-literal::
@ -51,6 +51,8 @@ Syntax
dof_per_chunk = define this many degrees-of-freedom per chunk for temperature calculation dof_per_chunk = define this many degrees-of-freedom per chunk for temperature calculation
*file* arg = filename *file* arg = filename
filename = file to write results to filename = file to write results to
*append* arg = filename
filename = file to append results to
*overwrite* arg = none = overwrite output file with only latest output *overwrite* arg = none = overwrite output file with only latest output
*format* arg = string *format* arg = string
string = C-style format string string = C-style format string
@ -433,15 +435,21 @@ molecule.
---------- ----------
The *file* keyword allows a filename to be specified. Every .. versionadded:: TBD
:math:`N_\text{freq}` timesteps, a section of chunk info will be written to a new keyword *append*
text file in the following format. A line with the timestep and number of
chunks is written. Then one line per chunk is written, containing the chunk The *file* or *append* keywords allow a filename to be specified. If
ID :math:`(1-N_\text{chunk}),` an optional original ID value, optional *file* is used, then the filename is overwritten if it already exists.
coordinate values for chunks that represent spatial bins, the number of atoms If *append* is used, then the filename is appended to if it already
in the chunk, and one or more calculated values. More explanation of the exists, or created if it does not exist. Every :math:`N_\text{freq}`
optional values is given below. The number of values in each line timesteps, a section of chunk info will be written to a text file in the
corresponds to the number of values specified in the fix ave/chunk following format. A line with the timestep and number of chunks is
written. Then one line per chunk is written, containing the chunk ID
:math:`(1-N_\text{chunk}),` an optional original ID value, optional
coordinate values for chunks that represent spatial bins, the number of
atoms in the chunk, and one or more calculated values. More explanation
of the optional values is given below. The number of values in each
line corresponds to the number of values specified in the fix ave/chunk
command. The number of atoms and the value(s) are summed or average command. The number of atoms and the value(s) are summed or average
quantities, as explained above. quantities, as explained above.

View File

@ -46,7 +46,7 @@ Syntax
*file* arg = filename *file* arg = filename
filename = name of file to output histogram(s) to filename = name of file to output histogram(s) to
*append* arg = filename *append* arg = filename
filename = name of file to append time averages to filename = name of file to append histogram(s) to
*ave* args = *one* or *running* or *window* *ave* args = *one* or *running* or *window*
one = output a new average value every Nfreq steps one = output a new average value every Nfreq steps
running = output cumulative average of all previous Nfreq steps running = output cumulative average of all previous Nfreq steps

View File

@ -193,10 +193,12 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
cdof = utils::numeric(FLERR,arg[iarg+1],false,lmp); cdof = utils::numeric(FLERR,arg[iarg+1],false,lmp);
iarg += 2; iarg += 2;
} else if (strcmp(arg[iarg],"file") == 0) { } else if ((strcmp(arg[iarg],"file") == 0) || (strcmp(arg[iarg],"append") == 0)) {
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk file", error); if (iarg+2 > narg)
utils::missing_cmd_args(FLERR, std::string("fix ave/chunk ")+arg[iarg], error);
if (comm->me == 0) { if (comm->me == 0) {
fp = fopen(arg[iarg+1],"w"); if (strcmp(arg[iarg],"file") == 0) fp = fopen(arg[iarg+1],"w");
else fp = fopen(arg[iarg+1],"a");
if (fp == nullptr) if (fp == nullptr)
error->one(FLERR, "Cannot open fix ave/chunk file {}: {}", error->one(FLERR, "Cannot open fix ave/chunk file {}: {}",
arg[iarg+1], utils::getsyserror()); arg[iarg+1], utils::getsyserror());