implement -restart2info command line flag and document it

This commit is contained in:
Axel Kohlmeyer
2024-08-06 17:14:46 -04:00
parent 40b2b08f23
commit b7bb8083ed
5 changed files with 80 additions and 4 deletions

View File

@ -226,6 +226,20 @@ arguments of the "dump" command. See the
.B LAMMPS
manual for details on either of the two commands.
.TP
\fB\-r2info <restart file> <keyword> ...\fR or
\fB\-restart2info <restart file> <keyword> ...\fR
Write infomation about the <restart file> previously written by
.B LAMMPS
to the screen and immediately exit. Following <restart file>
argument, additional keywords for the
.B LAMMPS
"info" command may be added to increase the amount of information
written. By default "system" "group" "fix" "compute" are already
set. See the
.B LAMMPS
manual for details on either of the two commands.
.TP
.TP
\fB\-sc <file name>\fR or \fB\-screen <file name>\fR
Specify a file for
.B LAMMPS

View File

@ -22,6 +22,7 @@ letter abbreviation can be used:
* :ref:`-ro or -reorder <reorder>`
* :ref:`-r2data or -restart2data <restart2data>`
* :ref:`-r2dump or -restart2dump <restart2dump>`
* :ref:`-r2info or -restart2info <restart2info>`
* :ref:`-sc or -screen <screen>`
* :ref:`-sr or skiprun <skiprun>`
* :ref:`-sf or -suffix <suffix>`
@ -503,6 +504,36 @@ e.g. the *nfile* and *fileper* keywords. See the
----------
.. _restart2info:
**-restart2info restartfile keyword ...**
.. versionadded:: TBD
Write out some info about the restart file and and immediately exit. This
is the same operation as if the following 2-line input script were
run:
.. code-block:: LAMMPS
read_restart restartfile
info system group compute fix keyword ...
The specified restartfile name may contain the wild-card character "\*".
The restartfile name may also contain the wild-card character "%". The
meaning of these characters is explained on the :doc:`read_restart
<read_restart>` documentation. The use of "%" means that a parallel
restart file can be read. Note that a filename such as file.\* may need
to be enclosed in quotes or the "\*" character prefixed with a backslash
("\") to avoid shell expansion of the "\*" character.
The :doc:`info command <info>` is already followed by the most useful
keywords, but additional keywords like *coeffs* or *comm* may be
appended to write out more details about the information stored in the
restart file.
----------
.. _screen:
**-screen file**

View File

@ -47,6 +47,12 @@ Restart files are saved in binary format to enable exact restarts,
meaning that the trajectories of a restarted run will precisely match
those produced by the original run had it continued on.
Some information about a restart file can be gathered directly from the
command line when using LAMMPS with the :ref:`-restart2info
<restart2info>` command line flag. On Unix-like operating systems (like
Linux or macOS), one can also :ref:`configure the "file" command line
program <magic>` to display basic information about a restart file
The binary restart file format was not designed with backward, forward,
or cross-platform compatibility in mind, so the files are only expected
to be read correctly by the same LAMMPS executable on the same platform.

View File

@ -261,7 +261,7 @@ void Info::command(int narg, char **arg)
++idx;
}
} else {
error->warning(FLERR,"Ignoring unknown or incorrect info command flag");
error->warning(FLERR,"Ignoring unknown or incorrect info command flag: {}",arg[idx]);
++idx;
}
}

View File

@ -210,6 +210,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
int kokkosflag = 0;
int restart2data = 0;
int restart2dump = 0;
int restart2info = 0;
int restartremap = 0;
int citeflag = 1;
int citescreen = CiteMe::TERSE;
@ -383,6 +384,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
error->universe_all(FLERR,"Invalid command-line argument");
if (restart2dump)
error->universe_all(FLERR, "Cannot use both -restart2data and -restart2dump");
if (restart2info)
error->universe_all(FLERR, "Cannot use both -restart2data and -restart2info");
restart2data = 1;
restartfile = arg[iarg+1];
inflag = -1; // skip inflag check
@ -405,6 +408,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
error->universe_all(FLERR,"Invalid command-line argument");
if (restart2data)
error->universe_all(FLERR, "Cannot use both -restart2data and -restart2dump");
if (restart2info)
error->universe_all(FLERR, "Cannot use both -restart2dump and -restart2info");
restart2dump = 1;
restartfile = arg[iarg+1];
inflag = -1; // skip inflag check
@ -421,6 +426,23 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
while (iarg < narg && arg[iarg][0] != '-') iarg++;
wlast = iarg;
} else if (strcmp(arg[iarg],"-restart2info") == 0 ||
strcmp(arg[iarg],"-r2info") == 0) {
if (iarg+2 > narg)
error->universe_all(FLERR,"Invalid command-line argument");
if (restart2data)
error->universe_all(FLERR, "Cannot use both -restart2data and -restart2info");
if (restart2dump)
error->universe_all(FLERR, "Cannot use both -restart2dump and -restart2info");
restart2info = 1;
restartfile = arg[iarg+1];
inflag = -1; // skip inflag check
iarg += 2;
// delimit args for the write_data command
wfirst = iarg;
while (iarg < narg && arg[iarg][0] != '-') iarg++;
wlast = iarg;
} else if (strcmp(arg[iarg],"-screen") == 0 ||
strcmp(arg[iarg],"-sc") == 0) {
if (iarg+2 > narg)
@ -727,15 +749,17 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
// add args between wfirst and wlast to write_data or write_data command
// add "noinit" to write_data to prevent a system init
if (restart2data || restart2dump) {
if (restart2data || restart2dump || restart2info) {
std::string cmd = fmt::format("read_restart {}",restartfile);
if (restartremap) cmd += " remap\n";
input->one(cmd);
if (restart2data) cmd = "write_data ";
else cmd = "write_dump";
else if (restart2dump) cmd = "write_dump";
else cmd = "info system group compute fix";
for (iarg = wfirst; iarg < wlast; iarg++)
cmd += fmt::format(" {}", arg[iarg]);
cmd += " noinit";
if (restart2data || restart2dump)
cmd += " noinit";
input->one(cmd);
error->done(0);
}
@ -1260,6 +1284,7 @@ void _noopt LAMMPS::help()
"-restart2data rfile dfile ... : convert restart to data file (-r2data)\n"
"-restart2dump rfile dgroup dstyle dfile ... \n"
" : convert restart to dump file (-r2dump)\n"
"-restart2info rfile : print info about restart rfile (-r2info)\n"
"-reorder topology-specs : processor reordering (-r)\n"
"-screen none/filename : where to send screen output (-sc)\n"
"-skiprun : skip loops in run and minimize (-sr)\n"