Unverified Commit f9b873db authored by Axel Kohlmeyer's avatar Axel Kohlmeyer Committed by GitHub
Browse files

Merge pull request #2032 from akohlmey/change-box-image-flags

Reset image flag(s) when changing from periodic to non-periodic
parents 72ff0dd8 73ec2d81
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -299,6 +299,12 @@ match what is stored in the restart file. So if you wish to change
them, you should use the change_box command after the read_restart
command.

.. note::

   Changing a periodic boundary to a non-periodic one will also
   cause the image flag for that dimension to be reset to 0 for
   all atoms.  LAMMPS will print a warning message, if that happens.

----------

The *ortho* and *triclinic* keywords convert the simulation box to be
+24 −0
Original line number Diff line number Diff line
@@ -1874,6 +1874,12 @@ void Domain::set_boundary(int narg, char **arg, int flag)
  if (boundary[2][0] == 0) zperiodic = 1;
  else zperiodic = 0;

  // record if we changed a periodic boundary to a non-periodic one
  int pflag=0;
  if ((periodicity[0] && !xperiodic)
      || (periodicity[1] && !yperiodic)
      || (periodicity[2] && !zperiodic)) pflag = 1;

  periodicity[0] = xperiodic;
  periodicity[1] = yperiodic;
  periodicity[2] = zperiodic;
@@ -1885,6 +1891,24 @@ void Domain::set_boundary(int narg, char **arg, int flag)
        boundary[1][0] >= 2 || boundary[1][1] >= 2 ||
        boundary[2][0] >= 2 || boundary[2][1] >= 2) nonperiodic = 2;
  }
  if (pflag) {
    pflag = 0;
    for (int i=0; i < atom->nlocal; ++i) {
      int xbox = (atom->image[i] & IMGMASK) - IMGMAX;
      int ybox = (atom->image[i] >> IMGBITS & IMGMASK) - IMGMAX;
      int zbox = (atom->image[i] >> IMG2BITS) - IMGMAX;
      if (!xperiodic) { xbox = 0; pflag = 1; }
      if (!yperiodic) { ybox = 0; pflag = 1; }
      if (!zperiodic) { zbox = 0; pflag = 1; }
      atom->image[i] = ((imageint) (xbox + IMGMAX) & IMGMASK) |
        (((imageint) (ybox + IMGMAX) & IMGMASK) << IMGBITS) |
        (((imageint) (zbox + IMGMAX) & IMGMASK) << IMG2BITS);
    }
    int flag_all;
    MPI_Allreduce(&flag,&flag_all, 1, MPI_INT, MPI_SUM, world);
    if ((flag_all > 0) && (comm->me == 0))
      error->warning(FLERR,"Reset image flags for non-periodic boundary");
  }
}

/* ----------------------------------------------------------------------