fix bug in lammps_reset_box() no-box check and error out when atoms exist

This commit is contained in:
Axel Kohlmeyer 2021-05-13 12:40:33 -04:00
parent 36de1c4201
commit 0f7a41590d
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
2 changed files with 12 additions and 5 deletions

View File

@ -673,7 +673,8 @@ void lammps_extract_box(void *handle, double *boxlo, double *boxhi,
This function sets the simulation box dimensions (upper and lower bounds
and tilt factors) from the provided data and then re-initializes the box
information and all derived settings.
information and all derived settings. It may only be called before atoms
are created.
\endverbatim
*
@ -692,12 +693,16 @@ void lammps_reset_box(void *handle, double *boxlo, double *boxhi,
BEGIN_CAPTURE
{
// error if box does not exist
if ((lmp->domain->box_exist == 0)
&& (lmp->comm->me == 0)) {
lmp->error->warning(FLERR,"Calling lammps_reset_box without a box");
if (lmp->atom->natoms > 0)
lmp->error->all(FLERR,"Calling lammps_reset_box not supported when atoms exist");
// warn and do nothing if no box exists
if (lmp->domain->box_exist == 0) {
if (lmp->comm->me == 0)
lmp->error->warning(FLERR,"Ignoring call to lammps_reset_box without a box");
return;
}
domain->boxlo[0] = boxlo[0];
domain->boxlo[1] = boxlo[1];
domain->boxlo[2] = boxlo[2];

View File

@ -161,6 +161,8 @@ TEST_F(LibraryProperties, box)
boxhi[1] = 7.3;
xy = 0.1;
if (!verbose) ::testing::internal::CaptureStdout();
// lammps_reset_box() may only be called without atoms
lammps_command(lmp, "delete_atoms group all bond yes");
lammps_reset_box(lmp, boxlo, boxhi, xy, yz, xz);
if (!verbose) ::testing::internal::GetCapturedStdout();
lammps_extract_box(lmp, boxlo, boxhi, &xy, &yz, &xz, pflags, &boxflag);