implement set_time command
This commit is contained in:
@ -105,6 +105,7 @@ An alphabetic list of all general LAMMPS commands.
|
||||
* :doc:`run <run>`
|
||||
* :doc:`run_style <run_style>`
|
||||
* :doc:`set <set>`
|
||||
* :doc:`set_time <set_time>`
|
||||
* :doc:`shell <shell>`
|
||||
* :doc:`special_bonds <special_bonds>`
|
||||
* :doc:`suffix <suffix>`
|
||||
|
||||
@ -96,6 +96,7 @@ Commands
|
||||
run
|
||||
run_style
|
||||
set
|
||||
set_time
|
||||
shell
|
||||
special_bonds
|
||||
suffix
|
||||
|
||||
44
doc/src/set_time.rst
Normal file
44
doc/src/set_time.rst
Normal file
@ -0,0 +1,44 @@
|
||||
.. index:: set_time
|
||||
|
||||
set_time command
|
||||
================
|
||||
|
||||
Syntax
|
||||
""""""
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
set_time t
|
||||
|
||||
* t = current simulation time (time units)
|
||||
|
||||
Examples
|
||||
""""""""
|
||||
|
||||
.. code-block:: LAMMPS
|
||||
|
||||
time 0.0
|
||||
time 10.5
|
||||
|
||||
Description
|
||||
"""""""""""
|
||||
|
||||
Set the current accumulated simulation time for subsequent molecular
|
||||
dynamics simulations. See the :doc:`units <units>` command for the time
|
||||
units associated with each choice of units that LAMMPS supports.
|
||||
|
||||
|
||||
Restrictions
|
||||
""""""""""""
|
||||
none
|
||||
|
||||
Related commands
|
||||
""""""""""""""""
|
||||
|
||||
:doc:`reset_timestep <reset_timestep>`, :doc:`timestep <timestep>`,
|
||||
:doc:`fix dt/reset <fix_dt_reset>`, :doc:`units <units>`
|
||||
|
||||
Default
|
||||
"""""""
|
||||
|
||||
0.0 at the beginning of the first run.
|
||||
@ -773,6 +773,7 @@ int Input::execute_command()
|
||||
else if (!strcmp(command,"reset_timestep")) reset_timestep();
|
||||
else if (!strcmp(command,"restart")) restart();
|
||||
else if (!strcmp(command,"run_style")) run_style();
|
||||
else if (!strcmp(command,"set_time")) set_time();
|
||||
else if (!strcmp(command,"special_bonds")) special_bonds();
|
||||
else if (!strcmp(command,"suffix")) suffix();
|
||||
else if (!strcmp(command,"thermo")) thermo();
|
||||
@ -1772,6 +1773,16 @@ void Input::run_style()
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void Input::set_time()
|
||||
{
|
||||
if (narg != 1) error->all(FLERR,"Illegal set_time command");
|
||||
|
||||
update->atime = utils::numeric(FLERR,arg[0],false,lmp);
|
||||
update->atimestep = update->ntimestep;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void Input::special_bonds()
|
||||
{
|
||||
// store 1-3,1-4 and dihedral/extra flag values before change
|
||||
|
||||
@ -131,6 +131,7 @@ class Input : protected Pointers {
|
||||
void reset_timestep();
|
||||
void restart();
|
||||
void run_style();
|
||||
void set_time();
|
||||
void special_bonds();
|
||||
void suffix();
|
||||
void thermo();
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
#define MAGIC_STRING "LammpS RestartT"
|
||||
#define ENDIAN 0x0001
|
||||
#define ENDIANSWAP 0x1000
|
||||
#define FORMAT_REVISION 2
|
||||
#define FORMAT_REVISION 3
|
||||
|
||||
enum{VERSION,SMALLINT,TAGINT,BIGINT,
|
||||
UNITS,NTIMESTEP,DIMENSION,NPROCS,PROCGRID,
|
||||
@ -37,7 +37,8 @@ enum{VERSION,SMALLINT,TAGINT,BIGINT,
|
||||
COMM_MODE,COMM_CUTOFF,COMM_VEL,NO_PAIR,
|
||||
EXTRA_BOND_PER_ATOM,EXTRA_ANGLE_PER_ATOM,EXTRA_DIHEDRAL_PER_ATOM,
|
||||
EXTRA_IMPROPER_PER_ATOM,EXTRA_SPECIAL_PER_ATOM,ATOM_MAXSPECIAL,
|
||||
NELLIPSOIDS,NLINES,NTRIS,NBODIES};
|
||||
NELLIPSOIDS,NLINES,NTRIS,NBODIES,
|
||||
ATIME,ATIMESTEP};
|
||||
|
||||
#define LB_FACTOR 1.1
|
||||
|
||||
|
||||
@ -594,21 +594,18 @@ void ReadRestart::header()
|
||||
if (flag == VERSION) {
|
||||
char *version = read_string();
|
||||
if (me == 0)
|
||||
utils::logmesg(lmp," restart file = {}, LAMMPS = {}\n",
|
||||
version,lmp->version);
|
||||
utils::logmesg(lmp," restart file = {}, LAMMPS = {}\n", version, lmp->version);
|
||||
delete[] version;
|
||||
|
||||
// we have no forward compatibility, thus exit with error
|
||||
|
||||
if (revision > FORMAT_REVISION)
|
||||
error->all(FLERR,"Restart file format revision incompatible "
|
||||
"with current LAMMPS version");
|
||||
error->all(FLERR,"Restart file format revision incompatible with current LAMMPS version");
|
||||
|
||||
// warn when attempting to read older format revision
|
||||
|
||||
if ((me == 0) && (revision < FORMAT_REVISION))
|
||||
error->warning(FLERR,"Old restart file format revision. "
|
||||
"Switching to compatibility mode.");
|
||||
error->warning(FLERR,"Old restart file format revision. Switching to compatibility mode.");
|
||||
|
||||
// check lmptype.h sizes, error if different
|
||||
|
||||
@ -654,8 +651,8 @@ void ReadRestart::header()
|
||||
} else if (flag == NPROCS) {
|
||||
nprocs_file = read_int();
|
||||
if (nprocs_file != comm->nprocs && me == 0)
|
||||
error->warning(FLERR,"Restart file used different # of processors: "
|
||||
"{} vs. {}",nprocs_file,comm->nprocs);
|
||||
error->warning(FLERR,"Restart file used different # of processors: {} vs. {}",
|
||||
nprocs_file,comm->nprocs);
|
||||
|
||||
// don't set procgrid, warn if different
|
||||
|
||||
@ -681,16 +678,14 @@ void ReadRestart::header()
|
||||
int newton_pair_file = read_int();
|
||||
if (force->newton_pair != 1) {
|
||||
if (newton_pair_file != force->newton_pair && me == 0)
|
||||
error->warning(FLERR,
|
||||
"Restart file used different newton pair setting, "
|
||||
error->warning(FLERR, "Restart file used different newton pair setting, "
|
||||
"using input script value");
|
||||
}
|
||||
} else if (flag == NEWTON_BOND) {
|
||||
int newton_bond_file = read_int();
|
||||
if (force->newton_bond != 1) {
|
||||
if (newton_bond_file != force->newton_bond && me == 0)
|
||||
error->warning(FLERR,
|
||||
"Restart file used different newton bond setting, "
|
||||
error->warning(FLERR, "Restart file used different newton bond setting, "
|
||||
"using restart file value");
|
||||
}
|
||||
force->newton_bond = newton_bond_file;
|
||||
@ -721,8 +716,7 @@ void ReadRestart::header()
|
||||
boundary[2][0] != domain->boundary[2][0] ||
|
||||
boundary[2][1] != domain->boundary[2][1]) {
|
||||
if (me == 0)
|
||||
error->warning(FLERR,
|
||||
"Restart file used different boundary settings, "
|
||||
error->warning(FLERR, "Restart file used different boundary settings, "
|
||||
"using restart file values");
|
||||
}
|
||||
}
|
||||
@ -864,6 +858,13 @@ void ReadRestart::header()
|
||||
} else if (flag == NBODIES) {
|
||||
atom->nbodies = read_bigint();
|
||||
|
||||
} else if (flag == ATIMESTEP) {
|
||||
update->atimestep = read_bigint();
|
||||
} else if (flag == ATIME) {
|
||||
update->atime = read_double();
|
||||
|
||||
// set dimension from restart file
|
||||
|
||||
// for backward compatibility
|
||||
} else if (flag == EXTRA_SPECIAL_PER_ATOM) {
|
||||
force->special_extra = read_int();
|
||||
|
||||
@ -27,7 +27,7 @@ class Update : protected Pointers {
|
||||
bigint ntimestep; // current step (dynamics or min iterations)
|
||||
int nsteps; // # of steps to run (dynamics or min iter)
|
||||
int whichflag; // 0 for unset, 1 for dynamics, 2 for min
|
||||
double atime; // simulation time at atime_step
|
||||
double atime; // simulation time at atimestep
|
||||
bigint atimestep; // last timestep atime was updated
|
||||
bigint firststep, laststep; // 1st & last step of this run
|
||||
bigint beginstep, endstep; // 1st and last step of multiple runs
|
||||
|
||||
@ -118,8 +118,7 @@ void WriteRestart::command(int narg, char **arg)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void WriteRestart::multiproc_options(int multiproc_caller, int mpiioflag_caller,
|
||||
int narg, char **arg)
|
||||
void WriteRestart::multiproc_options(int multiproc_caller, int mpiioflag_caller, int narg, char **arg)
|
||||
{
|
||||
multiproc = multiproc_caller;
|
||||
mpiioflag = mpiioflag_caller;
|
||||
@ -127,14 +126,12 @@ void WriteRestart::multiproc_options(int multiproc_caller, int mpiioflag_caller,
|
||||
// error checks
|
||||
|
||||
if (multiproc && mpiioflag)
|
||||
error->all(FLERR,
|
||||
"Restart file MPI-IO output not allowed with % in filename");
|
||||
error->all(FLERR,"Restart file MPI-IO output not allowed with % in filename");
|
||||
|
||||
if (mpiioflag) {
|
||||
mpiio = new RestartMPIIO(lmp);
|
||||
if (!mpiio->mpiio_exists)
|
||||
error->all(FLERR,"Writing to MPI-IO filename when "
|
||||
"MPIIO package is not installed");
|
||||
error->all(FLERR,"Writing to MPI-IO filename when MPIIO package is not installed");
|
||||
}
|
||||
|
||||
// defaults for multiproc file writing
|
||||
@ -158,8 +155,7 @@ void WriteRestart::multiproc_options(int multiproc_caller, int mpiioflag_caller,
|
||||
if (strcmp(arg[iarg],"fileper") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal write_restart command");
|
||||
if (!multiproc)
|
||||
error->all(FLERR,"Cannot use write_restart fileper "
|
||||
"without % in restart file name");
|
||||
error->all(FLERR,"Cannot use write_restart fileper without % in restart file name");
|
||||
int nper = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
|
||||
if (nper <= 0) error->all(FLERR,"Illegal write_restart command");
|
||||
|
||||
@ -176,8 +172,7 @@ void WriteRestart::multiproc_options(int multiproc_caller, int mpiioflag_caller,
|
||||
} else if (strcmp(arg[iarg],"nfile") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal write_restart command");
|
||||
if (!multiproc)
|
||||
error->all(FLERR,"Cannot use write_restart nfile "
|
||||
"without % in restart file name");
|
||||
error->all(FLERR,"Cannot use write_restart nfile without % in restart file name");
|
||||
int nfile = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
|
||||
if (nfile <= 0) error->all(FLERR,"Illegal write_restart command");
|
||||
nfile = MIN(nfile,nprocs);
|
||||
@ -510,6 +505,11 @@ void WriteRestart::header()
|
||||
write_bigint(NTRIS,atom->ntris);
|
||||
write_bigint(NBODIES,atom->nbodies);
|
||||
|
||||
// write out current simulation time. added 3 May 2022
|
||||
|
||||
write_bigint(ATIMESTEP,update->atimestep);
|
||||
write_double(ATIME,update->atime);
|
||||
|
||||
// -1 flag signals end of header
|
||||
|
||||
int flag = -1;
|
||||
|
||||
@ -241,6 +241,40 @@ TEST_F(SimpleCommandsTest, ResetTimestep)
|
||||
TEST_FAILURE(".*ERROR: Expected integer .*", command("reset_timestep xxx"););
|
||||
}
|
||||
|
||||
TEST_F(SimpleCommandsTest, SetTime)
|
||||
{
|
||||
ASSERT_EQ(lmp->update->ntimestep, 0);
|
||||
ASSERT_EQ(lmp->update->atimestep, 0);
|
||||
ASSERT_DOUBLE_EQ(lmp->update->atime, 0.0);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("set_time 10.0");
|
||||
END_HIDE_OUTPUT();
|
||||
ASSERT_EQ(lmp->update->atimestep, 0);
|
||||
ASSERT_DOUBLE_EQ(lmp->update->atime, 10.0);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("reset_timestep 10");
|
||||
command("set_time 10.0");
|
||||
END_HIDE_OUTPUT();
|
||||
ASSERT_EQ(lmp->update->ntimestep, 10);
|
||||
ASSERT_EQ(lmp->update->atimestep, 10);
|
||||
ASSERT_DOUBLE_EQ(lmp->update->atime, 10.0);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("reset_timestep 0");
|
||||
command("set_time 10.0");
|
||||
command("reset_timestep 10");
|
||||
END_HIDE_OUTPUT();
|
||||
ASSERT_EQ(lmp->update->ntimestep, 10);
|
||||
ASSERT_EQ(lmp->update->atimestep, 10);
|
||||
ASSERT_DOUBLE_EQ(lmp->update->atime, 10.0 + lmp->update->dt * 10);
|
||||
|
||||
TEST_FAILURE(".*ERROR: Illegal set_time .*", command("set_time"););
|
||||
TEST_FAILURE(".*ERROR: Illegal set_time .*", command("set_time 10 10"););
|
||||
TEST_FAILURE(".*ERROR: Expected floating .*", command("set_time xxx"););
|
||||
}
|
||||
|
||||
TEST_F(SimpleCommandsTest, Suffix)
|
||||
{
|
||||
ASSERT_EQ(lmp->suffix_enable, 0);
|
||||
|
||||
Reference in New Issue
Block a user