replace Fix::box_change_xxx variables with Fix::box_change bitmask and add check to Domain::init()

This allows a more specific tracking of whether multiple fixes are
modifying the same box parameter and error out in that case.
This commit is contained in:
Axel Kohlmeyer
2020-02-08 15:12:26 -05:00
parent f0935feabe
commit 5f68f3006f
22 changed files with 108 additions and 41 deletions

View File

@ -106,6 +106,10 @@ FixRigidNH::FixRigidNH(LAMMPS *lmp, int narg, char **arg) :
p_period[0] != p_period[2]))
error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings");
if (p_flag[0]) box_change |= BOX_CHANGE_X;
if (p_flag[1]) box_change |= BOX_CHANGE_Y;
if (p_flag[2]) box_change |= BOX_CHANGE_Z;
if ((tstat_flag && t_period <= 0.0) ||
(p_flag[0] && p_period[0] <= 0.0) ||
(p_flag[1] && p_period[1] <= 0.0) ||

View File

@ -120,6 +120,10 @@ FixRigidNHSmall::FixRigidNHSmall(LAMMPS *lmp, int narg, char **arg) :
p_period[0] != p_period[2]))
error->all(FLERR,"Invalid fix rigid/small npt/nph command pressure settings");
if (p_flag[0]) box_change |= BOX_CHANGE_X;
if (p_flag[1]) box_change |= BOX_CHANGE_Y;
if (p_flag[2]) box_change |= BOX_CHANGE_Z;
if ((tstat_flag && t_period <= 0.0) ||
(p_flag[0] && p_period[0] <= 0.0) ||
(p_flag[1] && p_period[1] <= 0.0) ||

View File

@ -33,7 +33,6 @@ FixRigidNPH::FixRigidNPH(LAMMPS *lmp, int narg, char **arg) :
scalar_flag = 1;
restart_global = 1;
box_change_size = 1;
extscalar = 1;
// error checks

View File

@ -33,7 +33,6 @@ FixRigidNPHSmall::FixRigidNPHSmall(LAMMPS *lmp, int narg, char **arg) :
scalar_flag = 1;
restart_global = 1;
box_change_size = 1;
extscalar = 1;
// error checks

View File

@ -33,7 +33,6 @@ FixRigidNPT::FixRigidNPT(LAMMPS *lmp, int narg, char **arg) :
scalar_flag = 1;
restart_global = 1;
box_change_size = 1;
extscalar = 1;
// error checks

View File

@ -33,7 +33,6 @@ FixRigidNPTSmall::FixRigidNPTSmall(LAMMPS *lmp, int narg, char **arg) :
scalar_flag = 1;
restart_global = 1;
box_change_size = 1;
extscalar = 1;
// error checks

View File

@ -46,7 +46,6 @@ FixMSST::FixMSST(LAMMPS *lmp, int narg, char **arg) :
if (narg < 4) error->all(FLERR,"Illegal fix msst command");
restart_global = 1;
box_change_size = 1;
time_integrate = 1;
scalar_flag = 1;
vector_flag = 1;
@ -78,10 +77,16 @@ FixMSST::FixMSST(LAMMPS *lmp, int narg, char **arg) :
dftb = 0;
beta = 0.0;
if (strcmp(arg[3],"x") == 0) direction = 0;
else if (strcmp(arg[3],"y") == 0) direction = 1;
else if (strcmp(arg[3],"z") == 0) direction = 2;
else error->all(FLERR,"Illegal fix msst command");
if (strcmp(arg[3],"x") == 0) {
direction = 0;
box_change |= BOX_CHANGE_X;
} else if (strcmp(arg[3],"y") == 0) {
direction = 1;
box_change |= BOX_CHANGE_Y;
} else if (strcmp(arg[3],"z") == 0) {
direction = 2;
box_change |= BOX_CHANGE_Z;
} else error->all(FLERR,"Illegal fix msst command");
velocity = force->numeric(FLERR,arg[4]);
if (velocity < 0) error->all(FLERR,"Illegal fix msst command");

View File

@ -375,13 +375,16 @@ void FixSRD::init()
change_size = change_shape = deformflag = 0;
if (domain->nonperiodic == 2) change_size = 1;
Fix **fixes = modify->fix;
for (int i = 0; i < modify->nfix; i++) {
if (modify->fix[i]->box_change_size) change_size = 1;
if (modify->fix[i]->box_change_shape) change_shape = 1;
if (strcmp(modify->fix[i]->style,"deform") == 0) {
if (fixes[i]->box_change & BOX_CHANGE_SIZE) change_size = 1;
if (fixes[i]->box_change & BOX_CHANGE_SHAPE) change_shape = 1;
if (strcmp(fixes[i]->style,"deform") == 0) {
deformflag = 1;
FixDeform *deform = (FixDeform *) modify->fix[i];
if (deform->box_change_shape && deform->remapflag != Domain::V_REMAP)
if ((deform->box_change & BOX_CHANGE_SHAPE)
&& deform->remapflag != Domain::V_REMAP)
error->all(FLERR,"Using fix srd with inconsistent "
"fix deform remap option");
}

View File

@ -292,8 +292,12 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) :
if (p_flag[i]) pstat_flag = 1;
if (pstat_flag) {
if (p_flag[0] || p_flag[1] || p_flag[2]) box_change_size = 1;
if (p_flag[3] || p_flag[4] || p_flag[5]) box_change_shape = 1;
if (p_flag[0]) box_change |= BOX_CHANGE_X;
if (p_flag[1]) box_change |= BOX_CHANGE_Y;
if (p_flag[2]) box_change |= BOX_CHANGE_Z;
if (p_flag[3]) box_change |= BOX_CHANGE_YZ;
if (p_flag[4]) box_change |= BOX_CHANGE_XZ;
if (p_flag[5]) box_change |= BOX_CHANGE_XY;
no_change_box = 1;
if (allremap == 0) restart_pbc = 1;

View File

@ -492,8 +492,12 @@ FixNPTCauchy::FixNPTCauchy(LAMMPS *lmp, int narg, char **arg) :
if (p_flag[i]) pstat_flag = 1;
if (pstat_flag) {
if (p_flag[0] || p_flag[1] || p_flag[2]) box_change_size = 1;
if (p_flag[3] || p_flag[4] || p_flag[5]) box_change_shape = 1;
if (p_flag[0]) box_change |= BOX_CHANGE_X;
if (p_flag[1]) box_change |= BOX_CHANGE_Y;
if (p_flag[2]) box_change |= BOX_CHANGE_Z;
if (p_flag[3]) box_change |= BOX_CHANGE_YZ;
if (p_flag[4]) box_change |= BOX_CHANGE_XZ;
if (p_flag[5]) box_change |= BOX_CHANGE_XY;
no_change_box = 1;
if (allremap == 0) restart_pbc = 1;

View File

@ -33,7 +33,6 @@ FixRigidNPHOMP::FixRigidNPHOMP(LAMMPS *lmp, int narg, char **arg) :
scalar_flag = 1;
restart_global = 1;
box_change_size = 1;
extscalar = 1;
// error checks

View File

@ -33,7 +33,6 @@ FixRigidNPTOMP::FixRigidNPTOMP(LAMMPS *lmp, int narg, char **arg) :
scalar_flag = 1;
restart_global = 1;
box_change_size = 1;
extscalar = 1;
// error checks

View File

@ -45,13 +45,16 @@ FixQBMSST::FixQBMSST(LAMMPS *lmp, int narg, char **arg) :
{
if (narg < 5) error->all(FLERR,"Illegal fix qbmsst command");
if ( strcmp(arg[3],"x") == 0 )
if ( strcmp(arg[3],"x") == 0 ) {
direction = 0;
else if ( strcmp(arg[3],"y") == 0 )
box_change |= BOX_CHANGE_X;
} else if ( strcmp(arg[3],"y") == 0 ) {
direction = 1;
else if ( strcmp(arg[3],"z") == 0 )
box_change |= BOX_CHANGE_Y;
} else if ( strcmp(arg[3],"z") == 0 ) {
direction = 2;
else {
box_change |= BOX_CHANGE_Z;
} else {
error->all(FLERR,"Illegal fix qbmsst command");
}
velocity = atof(arg[4]);
@ -64,7 +67,6 @@ FixQBMSST::FixQBMSST(LAMMPS *lmp, int narg, char **arg) :
extvector = 0;
nevery = 1;
restart_global = 1;
box_change_size = 1;
time_integrate = 1;
scalar_flag = 1;
vector_flag = 1;

View File

@ -163,7 +163,7 @@ FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) :
// flag that I change the box here (in case of nvt)
box_change_shape = 1;
box_change |= BOX_CHANGE_SHAPE;
// initialize the UEFBox class which computes the box at each step

View File

@ -19,6 +19,7 @@
#include <mpi.h>
#include <cstring>
#include <cmath>
#include <string>
#include "style_region.h"
#include "atom.h"
#include "atom_vec.h"
@ -133,13 +134,39 @@ void Domain::init()
box_change_size = box_change_shape = box_change_domain = 0;
// flags for detecting, if multiple fixes try to change the
// same box size or shape parameter
int box_change_x=0, box_change_y=0, box_change_z=0;
int box_change_yz=0, box_change_xz=0, box_change_xy=0;
Fix **fixes = modify->fix;
if (nonperiodic == 2) box_change_size = 1;
for (int i = 0; i < modify->nfix; i++) {
if (modify->fix[i]->box_change_size) box_change_size = 1;
if (modify->fix[i]->box_change_shape) box_change_shape = 1;
if (modify->fix[i]->box_change_domain) box_change_domain = 1;
if (fixes[i]->box_change & Fix::BOX_CHANGE_SIZE) box_change_size = 1;
if (fixes[i]->box_change & Fix::BOX_CHANGE_SHAPE) box_change_shape = 1;
if (fixes[i]->box_change & Fix::BOX_CHANGE_DOMAIN) box_change_domain = 1;
if (fixes[i]->box_change & Fix::BOX_CHANGE_X) box_change_x++;
if (fixes[i]->box_change & Fix::BOX_CHANGE_Y) box_change_y++;
if (fixes[i]->box_change & Fix::BOX_CHANGE_Z) box_change_z++;
if (fixes[i]->box_change & Fix::BOX_CHANGE_YZ) box_change_yz++;
if (fixes[i]->box_change & Fix::BOX_CHANGE_XZ) box_change_xz++;
if (fixes[i]->box_change & Fix::BOX_CHANGE_XY) box_change_xy++;
}
std::string mesg = "Must not have multiple fixes change box parameter ";
#define CHECK_BOX_FIX_ERROR(par) \
if (box_change_ ## par > 1) error->all(FLERR,(mesg + #par).c_str())
CHECK_BOX_FIX_ERROR(x);
CHECK_BOX_FIX_ERROR(y);
CHECK_BOX_FIX_ERROR(z);
CHECK_BOX_FIX_ERROR(yz);
CHECK_BOX_FIX_ERROR(xz);
CHECK_BOX_FIX_ERROR(xy);
#undef CHECK_BOX_FIX_ERROR
box_change = 0;
if (box_change_size || box_change_shape || box_change_domain) box_change = 1;

View File

@ -58,7 +58,7 @@ Fix::Fix(LAMMPS *lmp, int /*narg*/, char **arg) :
restart_global = restart_peratom = restart_file = 0;
force_reneighbor = 0;
box_change_size = box_change_shape = box_change_domain = 0;
box_change = NO_BOX_CHANGE;
thermo_energy = 0;
thermo_virial = 0;
rigid_flag = 0;

View File

@ -30,9 +30,14 @@ class Fix : protected Pointers {
int restart_file; // 1 if Fix writes own restart file, 0 if not
int force_reneighbor; // 1 if Fix forces reneighboring, 0 if not
int box_change_size; // 1 if Fix changes box size, 0 if not
int box_change_shape; // 1 if Fix changes box shape, 0 if not
int box_change_domain; // 1 if Fix changes proc sub-domains, 0 if not
int box_change; // >0 if Fix changes box size, shape, or sub-domains, 0 if not
enum {
NO_BOX_CHANGE = 0, BOX_CHANGE_ANY = 1<<0, BOX_CHANGE_DOMAIN = 1<<1,
BOX_CHANGE_X = 1<<2, BOX_CHANGE_Y = 1<<3, BOX_CHANGE_Z = 1<<4,
BOX_CHANGE_YZ = 1<<5, BOX_CHANGE_XZ = 1<<6, BOX_CHANGE_XY = 1<<7,
BOX_CHANGE_SIZE = BOX_CHANGE_X | BOX_CHANGE_Y | BOX_CHANGE_Z,
BOX_CHANGE_SHAPE = BOX_CHANGE_YZ | BOX_CHANGE_XZ | BOX_CHANGE_XY
};
bigint next_reneighbor; // next timestep to force a reneighboring
int thermo_energy; // 1 if fix_modify enabled ThEng, 0 if not

View File

@ -39,7 +39,7 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) :
{
if (narg < 6) error->all(FLERR,"Illegal fix balance command");
box_change_domain = 1;
box_change = BOX_CHANGE_DOMAIN;
scalar_flag = 1;
extscalar = 0;
vector_flag = 1;

View File

@ -218,8 +218,13 @@ FixBoxRelax::FixBoxRelax(LAMMPS *lmp, int narg, char **arg) :
} else error->all(FLERR,"Illegal fix box/relax command");
}
if (p_flag[0] || p_flag[1] || p_flag[2]) box_change_size = 1;
if (p_flag[3] || p_flag[4] || p_flag[5]) box_change_shape = 1;
if (p_flag[0]) box_change |= BOX_CHANGE_X;
if (p_flag[1]) box_change |= BOX_CHANGE_Y;
if (p_flag[2]) box_change |= BOX_CHANGE_Z;
if (p_flag[3]) box_change |= BOX_CHANGE_YZ;
if (p_flag[4]) box_change |= BOX_CHANGE_XZ;
if (p_flag[5]) box_change |= BOX_CHANGE_XY;
if (allremap == 0) restart_pbc = 1;
// error checks

View File

@ -211,8 +211,12 @@ rfix(NULL), irregular(NULL), set(NULL)
if (set[i].style == NONE) dimflag[i] = 0;
else dimflag[i] = 1;
if (dimflag[0] || dimflag[1] || dimflag[2]) box_change_size = 1;
if (dimflag[3] || dimflag[4] || dimflag[5]) box_change_shape = 1;
if (dimflag[0]) box_change |= BOX_CHANGE_X;
if (dimflag[1]) box_change |= BOX_CHANGE_Y;
if (dimflag[2]) box_change |= BOX_CHANGE_Z;
if (dimflag[3]) box_change |= BOX_CHANGE_YZ;
if (dimflag[4]) box_change |= BOX_CHANGE_XZ;
if (dimflag[5]) box_change |= BOX_CHANGE_XY;
// no tensile deformation on shrink-wrapped dims
// b/c shrink wrap will change box-length

View File

@ -476,8 +476,12 @@ FixNH::FixNH(LAMMPS *lmp, int narg, char **arg) :
if (p_flag[i]) pstat_flag = 1;
if (pstat_flag) {
if (p_flag[0] || p_flag[1] || p_flag[2]) box_change_size = 1;
if (p_flag[3] || p_flag[4] || p_flag[5]) box_change_shape = 1;
if (p_flag[0]) box_change |= BOX_CHANGE_X;
if (p_flag[1]) box_change |= BOX_CHANGE_Y;
if (p_flag[2]) box_change |= BOX_CHANGE_Z;
if (p_flag[3]) box_change |= BOX_CHANGE_YZ;
if (p_flag[4]) box_change |= BOX_CHANGE_XZ;
if (p_flag[5]) box_change |= BOX_CHANGE_XY;
no_change_box = 1;
if (allremap == 0) restart_pbc = 1;

View File

@ -40,8 +40,6 @@ FixPressBerendsen::FixPressBerendsen(LAMMPS *lmp, int narg, char **arg) :
{
if (narg < 5) error->all(FLERR,"Illegal fix press/berendsen command");
box_change_size = 1;
// Berendsen barostat applied every step
nevery = 1;
@ -204,6 +202,10 @@ FixPressBerendsen::FixPressBerendsen(LAMMPS *lmp, int narg, char **arg) :
(p_flag[2] && p_period[2] <= 0.0))
error->all(FLERR,"Fix press/berendsen damping parameters must be > 0.0");
if (p_flag[0]) box_change |= BOX_CHANGE_X;
if (p_flag[1]) box_change |= BOX_CHANGE_Y;
if (p_flag[2]) box_change |= BOX_CHANGE_Z;
// pstyle = ISO if XYZ coupling or XY coupling in 2d -> 1 dof
// else pstyle = ANISO -> 3 dof