Skip to content

Commit

Permalink
Merge pull request #1162 from lammps/restart2dump
Browse files Browse the repository at this point in the history
added -restart2dump command-line option
  • Loading branch information
akohlmey committed Oct 19, 2018
2 parents f542590 + 01c3ab5 commit 15de096
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 58 deletions.
102 changes: 73 additions & 29 deletions doc/src/Run_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ letter abbreviation can be used:
"-p or -partition"_#partition
"-pl or -plog"_#plog
"-ps or -pscreen"_#pscreen
"-r or -restart"_#restart
"-ro or -reorder"_#reorder
"-r2data or -restart2data"_#restart2data
"-r2dump or -restart2dump"_#restart2dump
"-sc or -screen"_#screen
"-sf or -suffix"_#suffix
"-v or -var"_#var :ul
Expand Down Expand Up @@ -280,34 +281,6 @@ specified by the -screen command-line option.

:line

[-restart restartfile {remap} datafile keyword value ...] :link(restart)

Convert the restart file into a data file and immediately exit. This
is the same operation as if the following 2-line input script were
run:

read_restart restartfile {remap}
write_data datafile keyword value ... :pre

Note that the specified restartfile and datafile can have wild-card
characters ("*",%") as described by the
"read_restart"_read_restart.html and "write_data"_write_data.html
commands. But a filename such as file.* will need to be enclosed in
quotes to avoid shell expansion of the "*" character.

Note that following restartfile, the optional flag {remap} can be
used. This has the same effect as adding it to the
"read_restart"_read_restart.html command, as explained on its doc
page. This is only useful if the reading of the restart file triggers
an error that atoms have been lost. In that case, use of the remap
flag should allow the data file to still be produced.

Also note that following datafile, the same optional keyword/value
pairs can be listed as used by the "write_data"_write_data.html
command.

:line

[-reorder] :link(reorder)

This option has 2 forms:
Expand Down Expand Up @@ -381,6 +354,77 @@ the LAMMPS simulation domain.

:line

[-restart2data restartfile (remap) datafile keyword value ...] :link(restart2data)

Convert the restart file into a data file and immediately exit. This
is the same operation as if the following 2-line input script were
run:

read_restart restartfile (remap)
write_data datafile keyword value ... :pre

Note that the specified restartfile and/or datafile can have the
wild-card character "*". The restartfile can also have the wild-card
character "%". The meaning of these characters is explained on the
"read_restart"_read_restart.html and "write_data"_write_data.html doc
pages. The use of "%" means that a parallel restart file can be read.
Note that a filename such as file.* will need to be enclosed in quotes
to avoid shell expansion of the "*" character.

Note that following restartfile, the optional word "remap" can be
used. This has the effect of adding it to the
"read_restart"_read_restart.html command, as explained on its doc
page. This is useful if reading the restart file triggers an error
that atoms have been lost. In that case, use of the remap flag should
allow the data file to still be produced.

The syntax following restartfile (or remap), namely

datafile keyword value ... :pre

is identical to the arguments of the "write_data"_write_data.html
command. See its doc page for details. This includes its
optional keyword/value settings.

:line

[-restart2dump restartfile {remap} group-ID dumpstyle dumpfile arg1 arg2 ...] :link(restart2dump)

Convert the restart file into a dump file and immediately exit. This
is the same operation as if the following 2-line input script were
run:

read_restart restartfile (remap)
write_dump group-ID dumpstyle dumpfile arg1 arg2 ... :pre

Note that the specified restartfile and dumpfile can have wild-card
characters ("*","%") as explained on the
"read_restart"_read_restart.html and "write_dump"_write_dump.html doc
pages. The use of "%" means that a parallel restart file and/or
parallel dump file can be read and/or written. Note that a filename
such as file.* will need to be enclosed in quotes to avoid shell
expansion of the "*" character.

Note that following restartfile, the optional word "remap" can be
used. This has the effect as adding it to the
"read_restart"_read_restart.html command, as explained on its doc
page. This is useful if reading the restart file triggers an error
that atoms have been lost. In that case, use of the remap flag should
allow the dump file to still be produced.

The syntax following restartfile (or remap), namely

group-ID dumpstyle dumpfile arg1 arg2 ... :pre

is identical to the arguments of the "write_dump"_write_dump.html
command. See its doc page for details. This includes what per-atom
fields are written to the dump file and optional dump_modify settings,
including ones that affect how parallel dump files are written, e.g.
the {nfile} and {fileper} keywords. See the
"dump_modify"_dump_modify.html doc page for details.

:line

[-screen file] :link(screen)

Specify a file for LAMMPS to write its screen information to. In
Expand Down
87 changes: 58 additions & 29 deletions src/lammps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator)
int partscreenflag = 0;
int partlogflag = 0;
int kokkosflag = 0;
int restartflag = 0;
int restartremapflag = 0;
int restart2data = 0;
int restart2dump = 0;
int restartremap = 0;
int citeflag = 1;
int helpflag = 0;

Expand All @@ -132,9 +133,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator)
else exename = NULL;
packargs = NULL;
num_package = 0;
char *rfile = NULL;
char *dfile = NULL;
int wdfirst,wdlast;
char *restartfile = NULL;
int wfirst,wlast;
int kkfirst,kklast;

int npack = 0;
Expand Down Expand Up @@ -248,26 +248,49 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator)
universe->reorder(arg[iarg+1],arg[iarg+2]);
iarg += 3;

} else if (strcmp(arg[iarg],"-restart") == 0 ||
strcmp(arg[iarg],"-r") == 0) {
} else if (strcmp(arg[iarg],"-restart2data") == 0 ||
strcmp(arg[iarg],"-r2data") == 0) {
if (iarg+3 > narg)
error->universe_all(FLERR,"Invalid command-line argument");
restartflag = 1;
rfile = arg[iarg+1];
dfile = arg[iarg+2];
if (restart2dump)
error->universe_all(FLERR,
"Cannot use both -restart2data and -restart2dump");
restart2data = 1;
restartfile = arg[iarg+1];
// check for restart remap flag
if (strcmp(dfile,"remap") == 0) {
if (strcmp(arg[iarg+2],"remap") == 0) {
if (iarg+4 > narg)
error->universe_all(FLERR,"Invalid command-line argument");
restartremapflag = 1;
dfile = arg[iarg+3];
restartremap = 1;
iarg++;
}
iarg += 3;
// delimit any extra args for the write_data command
wdfirst = iarg;
iarg += 2;
// delimit args for the write_data command
wfirst = iarg;
while (iarg < narg && arg[iarg][0] != '-') iarg++;
wdlast = iarg;
wlast = iarg;

} else if (strcmp(arg[iarg],"-restart2dump") == 0 ||
strcmp(arg[iarg],"-r2dump") == 0) {
if (iarg+3 > narg)
error->universe_all(FLERR,"Invalid command-line argument");
if (restart2data)
error->universe_all(FLERR,
"Cannot use both -restart2data and -restart2dump");
restart2dump = 1;
restartfile = arg[iarg+1];
// check for restart remap flag
if (strcmp(arg[iarg+2],"remap") == 0) {
if (iarg+4 > narg)
error->universe_all(FLERR,"Invalid command-line argument");
restartremap = 1;
iarg++;
}
iarg += 2;
// delimit args for the write_dump command
wfirst = iarg;
while (iarg < narg && arg[iarg][0] != '-') iarg++;
wlast = iarg;

} else if (strcmp(arg[iarg],"-screen") == 0 ||
strcmp(arg[iarg],"-sc") == 0) {
Expand Down Expand Up @@ -547,6 +570,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator)
input = new Input(this,narg,arg);

// copy package cmdline arguments

if (npack > 0) {
num_package = npack;
packargs = new char**[npack];
Expand All @@ -573,19 +597,22 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator)
error->done(0);
}

// if restartflag set, invoke 2 commands and quit
// add args between wdfirst and wdlast to write_data command
// also add "noinit" to prevent write_data from doing system init
// if either restart conversion option was used, invoke 2 commands and quit
// add args between wfirst and wlast to write_data or write_data command
// add "noinit" to write_data to prevent a system init
// write_dump will just give a warning message about no init

if (restartflag) {
char cmd[128];
snprintf(cmd,128,"read_restart %s\n",rfile);
if (restartremapflag) strcat(cmd," remap\n");
if (restart2data || restart2dump) {
char cmd[256];
snprintf(cmd,248,"read_restart %s\n",restartfile);
if (restartremap) strcat(cmd," remap\n");
input->one(cmd);
snprintf(cmd,128,"write_data %s",dfile);
for (iarg = wdfirst; iarg < wdlast; iarg++)
sprintf(&cmd[strlen(cmd)]," %s",arg[iarg]);
strcat(cmd," noinit\n");
if (restart2data) strcpy(cmd,"write_data");
else strcpy(cmd,"write_dump");
for (iarg = wfirst; iarg < wlast; iarg++)
snprintf(&cmd[strlen(cmd)],246-strlen(cmd)," %s",arg[iarg]);
if (restart2data) strcat(cmd," noinit\n");
else strcat(cmd,"\n");
input->one(cmd);
error->done(0);
}
Expand Down Expand Up @@ -885,7 +912,9 @@ void LAMMPS::help()
"-partition size1 size2 ... : assign partition sizes (-p)\n"
"-plog basename : basename for partition logs (-pl)\n"
"-pscreen basename : basename for partition screens (-ps)\n"
"-restart rfile dfile ... : convert restart to data file (-r)\n"
"-restart2data rfile dfile ... : convert restart to data file (-r2data)\n"
"-restart2dump rfile dgroup dstyle dfile ... \n"
" : convert restart to dump file (-r2dump)\n"
"-reorder topology-specs : processor reordering (-r)\n"
"-screen none/filename : where to send screen output (-sc)\n"
"-suffix gpu/intel/opt/omp : style suffix to apply (-sf)\n"
Expand Down

0 comments on commit 15de096

Please sign in to comment.